commit c09b92a592fa025decce6593e3ab546f5724babb Author: Lee Rowlands Date: Thu Oct 25 16:55:27 2012 +1000 Adds first attempt at comments on user tests diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentUserTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentUserTest.php new file mode 100644 index 0000000..b18f752 --- /dev/null +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentUserTest.php @@ -0,0 +1,443 @@ +admin_user = $this->drupalCreateUser(array( + 'administer content types', + 'administer comments', + 'skip comment approval', + 'post comments', + 'access comments', + 'access content', + 'administer users' + )); + $this->web_user = $this->drupalCreateUser(array( + 'access comments', + 'post comments', + 'create article content', + 'edit own comments', + 'post comments', + 'skip comment approval', + 'access content', + )); + + // Create comment field on user bundle. + comment_add_default_comment_field('user', 'user', 'comment', COMMENT_ENTITY_OPEN); + } + + /** + * Posts a comment. + * + * @param Drupal\node\User|null $account + * User to post comment on or NULL to post to the previusly loaded page. + * @param $comment + * Comment body. + * @param $subject + * Comment subject. + * @param $contact + * Set to NULL for no contact info, TRUE to ignore success checking, and + * array of values to set contact info. + */ + function postComment($account, $comment, $subject = '', $contact = NULL) { + $langcode = LANGUAGE_NOT_SPECIFIED; + $edit = array(); + $edit['comment_body[' . $langcode . '][0][value]'] = $comment; + + $instance = field_info_instance('user', 'comment', 'user'); + $preview_mode = $instance['settings']['comment']['comment_preview']; + $subject_mode = $instance['settings']['comment']['comment_subject_field']; + + // Must get the page before we test for fields. + if ($node !== NULL) { + $this->drupalGet('comment/reply/user/' . $user->uid . '/comment'); + } + + if ($subject_mode == TRUE) { + $edit['subject'] = $subject; + } + else { + $this->assertNoFieldByName('subject', '', 'Subject field not found.'); + } + + if ($contact !== NULL && is_array($contact)) { + $edit += $contact; + } + switch ($preview_mode) { + case DRUPAL_REQUIRED: + // Preview required so no save button should be found. + $this->assertNoFieldByName('op', t('Save'), 'Save button not found.'); + $this->drupalPost(NULL, $edit, t('Preview')); + // Don't break here so that we can test post-preview field presence and + // function below. + case DRUPAL_OPTIONAL: + $this->assertFieldByName('op', t('Preview'), 'Preview button found.'); + $this->assertFieldByName('op', t('Save'), 'Save button found.'); + $this->drupalPost(NULL, $edit, t('Save')); + break; + + case DRUPAL_DISABLED: + $this->assertNoFieldByName('op', t('Preview'), 'Preview button not found.'); + $this->assertFieldByName('op', t('Save'), 'Save button found.'); + $this->drupalPost(NULL, $edit, t('Save')); + break; + } + $match = array(); + // Get comment ID + preg_match('/#comment-([0-9]+)/', $this->getURL(), $match); + + // Get comment. + if ($contact !== TRUE) { // If true then attempting to find error message. + if ($subject) { + $this->assertText($subject, 'Comment subject posted.'); + } + $this->assertText($comment, 'Comment body posted.'); + $this->assertTrue((!empty($match) && !empty($match[1])), 'Comment id found.'); + } + + if (isset($match[1])) { + return entity_create('comment', array('id' => $match[1], 'subject' => $subject, 'comment' => $comment)); + } + } + + /** + * Checks current page for specified comment. + * + * @param Drupal\comment\Comment $comment + * The comment object. + * @param boolean $reply + * Boolean indicating whether the comment is a reply to another comment. + * + * @return boolean + * Boolean indicating whether the comment was found. + */ + function commentExists(Comment $comment = NULL, $reply = FALSE) { + if ($comment) { + $regex = '/' . ($reply ? '
(.*?)' : ''); + $regex .= 'subject . '(.*?)'; // Match subject. + $regex .= $comment->comment . '(.*?)'; // Match comment. + $regex .= '/s'; + + return (boolean)preg_match($regex, $this->drupalGetContent()); + } + else { + return FALSE; + } + } + + /** + * Deletes a comment. + * + * @param Drupal\comment\Comment $comment + * Comment to delete. + */ + function deleteComment(Comment $comment) { + $this->drupalPost('comment/' . $comment->id . '/delete', array(), t('Delete')); + $this->assertText(t('The comment and all its replies have been deleted.'), 'Comment deleted.'); + } + + /** + * Sets the value governing whether the subject field should be enabled. + * + * @param boolean $enabled + * Boolean specifying whether the subject field should be enabled. + */ + function setCommentSubject($enabled) { + $this->setCommentSettings('comment_subject_field', ($enabled ? '1' : '0'), 'Comment subject ' . ($enabled ? 'enabled' : 'disabled') . '.'); + } + + /** + * Sets the value governing the previewing mode for the comment form. + * + * @param int $mode + * The preview mode: DRUPAL_DISABLED, DRUPAL_OPTIONAL or DRUPAL_REQUIRED. + */ + function setCommentPreview($mode) { + switch ($mode) { + case DRUPAL_DISABLED: + $mode_text = 'disabled'; + break; + + case DRUPAL_OPTIONAL: + $mode_text = 'optional'; + break; + + case DRUPAL_REQUIRED: + $mode_text = 'required'; + break; + } + $this->setCommentSettings('comment_preview', $mode, format_string('Comment preview @mode_text.', array('@mode_text' => $mode_text))); + } + + /** + * Sets the value governing whether the comment form is on its own page. + * + * @param boolean $enabled + * TRUE if the comment form should be displayed on the same page as the + * comments; FALSE if it should be displayed on its own page. + */ + function setCommentForm($enabled) { + $this->setCommentSettings('comment_form_location', ($enabled ? COMMENT_FORM_BELOW : COMMENT_FORM_SEPARATE_PAGE), 'Comment controls ' . ($enabled ? 'enabled' : 'disabled') . '.'); + } + + /** + * Sets the value governing restrictions on anonymous comments. + * + * @param integer $level + * The level of the contact information allowed for anonymous comments: + * - 0: No contact information allowed. + * - 1: Contact information allowed but not required. + * - 2: Contact information required. + */ + function setCommentAnonymous($level) { + $this->setCommentSettings('comment_anonymous', $level, format_string('Anonymous commenting set to level @level.', array('@level' => $level))); + } + + /** + * Sets the value specifying the default number of comments per page. + * + * @param integer $comments + * Comments per page value. + */ + function setCommentsPerPage($number) { + $this->setCommentSettings('comment_default_per_page', $number, format_string('Number of comments per page set to @number.', array('@number' => $number))); + } + + /** + * Sets a comment settings variable for the article content type. + * + * @param string $name + * Name of variable. + * @param string $value + * Value of variable. + * @param string $message + * Status message to display. + */ + function setCommentSettings($name, $value, $message) { + $instance = field_info_instance('node', 'comment', 'article'); + $instance['settings']['comment'][$name] = $value; + field_update_instance($instance); + // Display status message. + $this->pass($message); + } + + /** + * Checks whether the commenter's contact information is displayed. + * + * @return boolean + * Contact info is available. + */ + function commentContactInfoAvailable() { + return preg_match('/(input).*?(name="name").*?(input).*?(name="mail").*?(input).*?(name="homepage")/s', $this->drupalGetContent()); + } + + /** + * Performs the specified operation on the specified comment. + * + * @param object $comment + * Comment to perform operation on. + * @param string $operation + * Operation to perform. + * @param boolean $aproval + * Operation is found on approval page. + */ + function performCommentOperation($comment, $operation, $approval = FALSE) { + $edit = array(); + $edit['operation'] = $operation; + $edit['comments[' . $comment->id . ']'] = TRUE; + $this->drupalPost('admin/content/comment' . ($approval ? '/approval' : ''), $edit, t('Update')); + + if ($operation == 'delete') { + $this->drupalPost(NULL, array(), t('Delete comments')); + $this->assertRaw(format_plural(1, 'Deleted 1 comment.', 'Deleted @count comments.'), format_string('Operation "@operation" was performed on comment.', array('@operation' => $operation))); + } + else { + $this->assertText(t('The update has been performed.'), format_string('Operation "@operation" was performed on comment.', array('@operation' => $operation))); + } + } + + /** + * Gets the comment ID for an unapproved comment. + * + * @param string $subject + * Comment subject to find. + * + * @return integer + * Comment id. + */ + function getUnapprovedComment($subject) { + $this->drupalGet('admin/content/comment/approval'); + preg_match('/href="(.*?)#comment-([^"]+)"(.*?)>(' . $subject . ')/', $this->drupalGetContent(), $match); + + return $match[2]; + } + + /** + * Tests anonymous comment functionality. + */ + function testCommentUser() { + $this->drupalLogin($this->admin_user); + $this->setCommentAnonymous('0'); // Ensure that doesn't require contact info. + $this->drupalLogout(); + + // Post anonymous comment without contact info. + $anonymous_comment1 = $this->postComment($this->web_user, $this->randomName(), $this->randomName()); + $this->assertTrue($this->commentExists($anonymous_comment1), 'Anonymous comment without contact info found.'); + + // Allow contact info. + $this->drupalLogin($this->admin_user); + $this->setCommentAnonymous('1'); + + // Attempt to edit anonymous comment. + $this->drupalGet('comment/' . $anonymous_comment1->id . '/edit'); + $edited_comment = $this->postComment(NULL, $this->randomName(), $this->randomName()); + $this->assertTrue($this->commentExists($edited_comment, FALSE), 'Modified reply found.'); + $this->drupalLogout(); + + // Post anonymous comment with contact info (optional). + $this->drupalGet('comment/reply/user/' . $this->web_user->uid . '/comment'); + $this->assertTrue($this->commentContactInfoAvailable(), 'Contact information available.'); + + $anonymous_comment2 = $this->postComment($this->web_user, $this->randomName(), $this->randomName()); + $this->assertTrue($this->commentExists($anonymous_comment2), 'Anonymous comment with contact info (optional) found.'); + + // Ensure anonymous users cannot post in the name of registered users. + $langcode = LANGUAGE_NOT_SPECIFIED; + $edit = array( + 'name' => $this->admin_user->name, + 'mail' => $this->randomName() . '@example.com', + 'subject' => $this->randomName(), + "comment_body[$langcode][0][value]" => $this->randomName(), + ); + $this->drupalPost('comment/reply/user/' . $this->web_user->uid . '/comment', $edit, t('Save')); + $this->assertText(t('The name you used belongs to a registered user.')); + + // Require contact info. + $this->drupalLogin($this->admin_user); + $this->setCommentAnonymous('2'); + $this->drupalLogout(); + + // Try to post comment with contact info (required). + $this->drupalGet('comment/reply/user/' . $this->web_user->uid . '/comment'); + $this->assertTrue($this->commentContactInfoAvailable(), 'Contact information available.'); + + $anonymous_comment3 = $this->postComment($this->web_user, $this->randomName(), $this->randomName(), TRUE); + // Name should have 'Anonymous' for value by default. + $this->assertText(t('E-mail field is required.'), 'E-mail required.'); + $this->assertFalse($this->commentExists($anonymous_comment3), 'Anonymous comment with contact info (required) not found.'); + + // Post comment with contact info (required). + $author_name = $this->randomName(); + $author_mail = $this->randomName() . '@example.com'; + $anonymous_comment3 = $this->postComment($this->web_user, $this->randomName(), $this->randomName(), array('name' => $author_name, 'mail' => $author_mail)); + $this->assertTrue($this->commentExists($anonymous_comment3), 'Anonymous comment with contact info (required) found.'); + + // Make sure the user data appears correctly when editing the comment. + $this->drupalLogin($this->admin_user); + $this->drupalGet('comment/' . $anonymous_comment3->id . '/edit'); + $this->assertRaw($author_name, "The anonymous user's name is correct when editing the comment."); + $this->assertRaw($author_mail, "The anonymous user's e-mail address is correct when editing the comment."); + + // Unpublish comment. + $this->performCommentOperation($anonymous_comment3, 'unpublish'); + + $this->drupalGet('admin/content/comment/approval'); + $this->assertRaw('comments[' . $anonymous_comment3->id . ']', 'Comment was unpublished.'); + + // Publish comment. + $this->performCommentOperation($anonymous_comment3, 'publish', TRUE); + + $this->drupalGet('admin/content/comment'); + $this->assertRaw('comments[' . $anonymous_comment3->id . ']', 'Comment was published.'); + + // Delete comment. + $this->performCommentOperation($anonymous_comment3, 'delete'); + + $this->drupalGet('admin/content/comment'); + $this->assertNoRaw('comments[' . $anonymous_comment3->id . ']', 'Comment was deleted.'); + $this->drupalLogout(); + + // Reset. + user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array( + 'access comments' => FALSE, + 'post comments' => FALSE, + 'skip comment approval' => FALSE, + )); + + // Attempt to view comments while disallowed. + // NOTE: if authenticated user has permission to post comments, then a + // "Login or register to post comments" type link may be shown. + $this->drupalGet('user/' . $this->web_user->uid); + $this->assertNoPattern('@]*>Comments@', 'Comments were not displayed.'); + $this->assertNoLink('Add new comment', 'Link to add comment was found.'); + + // Attempt to view node-comment form while disallowed. + $this->drupalGet('comment/reply/user/' . $this->web_user->uid . '/comment'); + $this->assertText('You are not authorized to post comments', 'Error attempting to post comment.'); + $this->assertNoFieldByName('subject', '', 'Subject field not found.'); + $this->assertNoFieldByName("comment_body[$langcode][0][value]", '', 'Comment field not found.'); + + user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array( + 'access comments' => TRUE, + 'post comments' => FALSE, + 'skip comment approval' => FALSE, + )); + $this->drupalGet('user/' . $this->web_uer->uid); + $this->assertPattern('@]*>Comments@', 'Comments were displayed.'); + $this->assertLink('Log in', 1, 'Link to log in was found.'); + $this->assertLink('register', 1, 'Link to register was found.'); + + user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array( + 'access comments' => FALSE, + 'post comments' => TRUE, + 'skip comment approval' => TRUE, + )); + $this->drupalGet('user/' . $this->web_user->uid); + $this->assertNoPattern('@]*>Comments@', 'Comments were not displayed.'); + $this->assertFieldByName('subject', '', 'Subject field found.'); + $this->assertFieldByName("comment_body[$langcode][0][value]", '', 'Comment field found.'); + + $this->drupalGet('comment/reply/user/' . $this->web_user->uid . '/comment/' . $anonymous_comment3->id); + $this->assertText('You are not authorized to view comments', 'Error attempting to post reply.'); + $this->assertNoText($author_name, 'Comment not displayed.'); + } + +} commit d4bc47a6e2d23b64c527ab9d704b3250cb16bd78 Author: Lee Rowlands Date: Fri Oct 26 08:12:16 2012 +1000 Fixes some test failures, removes joins against {node} unless wrapped in module_exists, adds CommentUserTest diff --git a/core/modules/comment/comment.admin.inc b/core/modules/comment/comment.admin.inc index c99a239..cb39e39 100644 --- a/core/modules/comment/comment.admin.inc +++ b/core/modules/comment/comment.admin.inc @@ -127,8 +127,6 @@ function comment_admin_overview($form, &$form_state, $arg) { $query = db_select('comment', 'c') ->extend('Drupal\Core\Database\Query\PagerSelectExtender') ->extend('Drupal\Core\Database\Query\TableSortExtender'); - $query->leftJoin('node', 'n', "n.nid = c.entity_id AND c.entity_type = 'node'"); - $query->addTag('node_access'); $query->addTag('entity_access'); $result = $query ->fields('c', array('cid', 'subject', 'name', 'changed', 'entity_id', 'entity_type', 'field_name')) diff --git a/core/modules/comment/comment.field.inc b/core/modules/comment/comment.field.inc index efcbc63..fe3b83f 100644 --- a/core/modules/comment/comment.field.inc +++ b/core/modules/comment/comment.field.inc @@ -201,32 +201,6 @@ function comment_field_widget_form(&$form, &$form_state, $field, $instance, $lan } /** - * Implements hook_field_formatter_settings_form(). - */ -function comment_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { - $display = $instance['display'][$view_mode]; - $settings = $display['settings']; - - // This is where we put the settings for 'display below' etc. - // @todo. - return $element; -} - -/** - * Implements hook_field_formatter_settings_summary(). - */ -function comment_field_formatter_settings_summary($field, $instance, $view_mode) { - $display = $instance['display'][$view_mode]; - $settings = $display['settings']; - - $summary = array(); - // @todo. - $summary[] = 'Settings here'; - return implode('
', $summary); -} - - -/** * Implements hook_field_formatter_view(). */ function comment_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 8a99ab4..ecf2513 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -10,9 +10,8 @@ * book page, user etc. */ -use Drupal\node\Node; use Drupal\file\File; -use Drupal\Core\Entity\EntityInterfaceInterface; +use Drupal\Core\Entity\EntityInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -201,8 +200,8 @@ function comment_entity_view($entity, $view_mode, $langcode) { // But we don't want this link if we're building the entity for search // indexing or constructing a search result excerpt. $values = field_get_items('node', $entity, $field_name); - $value = reset($values); - if (!empty($value['comment']) && $value['comment'] == COMMENT_ENTITY_OPEN) { + if (is_array($values) && ($value = reset($values)) && + !empty($value['comment']) && $value['comment'] == COMMENT_ENTITY_OPEN) { $comment_form_location = $instance['settings']['comment']['comment_form_location']; if (user_access('post comments')) { // Show the "post comment" link if the form is on another page, or @@ -470,11 +469,16 @@ function comment_entity_reply_load($entity_id, $args) { */ function comment_entity_reply_access(Drupal\Core\Entity\EntityInterface $entity) { $function = $entity->entityType() . '_access'; - // @todo replace this with entity access controls once generic access controller lands, + // @todo replace this with entity access controls once generic access + // controller lands. // @see http://drupal.org/node/1696660 - if (function_exists($function)) { + if (function_exists($function) && $function != 'user_access') { return $function('view', $entity); } + elseif ($function == 'user_access') { + // User access is a special case. + return user_view_access($entity); + } // We can't know how to control access to this entity, invoke // hook_comment_entity_access and if no other modules object, grant access. $access = module_invoke_all('comment_entity_access', $entity); @@ -656,18 +660,20 @@ function comment_permalink($cid) { */ function comment_get_recent($number = 10) { $query = db_select('comment', 'c'); - $query->leftJoin('node', 'n', "n.nid = c.entity_id AND c.entity_type = 'node'"); - $query->addTag('node_access'); $query->addTag('comment_entity_access'); $query->addMetaData('base_table', 'comment'); - $comments = $query - ->fields('c') - ->condition('c.status', COMMENT_PUBLISHED) - ->condition(db_or() + $query->fields('c') + ->condition('c.status', COMMENT_PUBLISHED); + if (module_exists('node')) { + // Special case to filter by published content. + $query->leftJoin('node', 'n', "n.nid = c.entity_id AND c.entity_type = 'node'"); + $query->addTag('node_access'); + $query->condition(db_or() ->condition('n.status', NODE_PUBLISHED) ->condition('n.status', NULL, 'IS NULL') - ) - ->orderBy('c.created', 'DESC') + ); + } + $comments = $query->orderBy('c.created', 'DESC') // Additionally order by cid to ensure that comments with the same timestamp // are returned in the exact order posted. ->orderBy('c.cid', 'DESC') diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/filter/NodeComment.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/filter/NodeComment.php index 1eae8c9..dd6bd8e 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/filter/NodeComment.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/filter/NodeComment.php @@ -24,9 +24,9 @@ class NodeComment extends InOperator { function get_value_options() { $this->value_options = array( - COMMENT_NODE_HIDDEN => t('Hidden'), - COMMENT_NODE_CLOSED => t('Closed'), - COMMENT_NODE_OPEN => t('Open'), + COMMENT_ENTITY_HIDDEN => t('Hidden'), + COMMENT_ENTITY_CLOSED => t('Closed'), + COMMENT_ENTITY_OPEN => t('Open'), ); } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentUserTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentUserTest.php index b18f752..d5c2678 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentUserTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentUserTest.php @@ -13,7 +13,7 @@ /** * Tests basic comment functionality against a user entity. */ -abstract class CommentUserTest extends WebTestBase { +class CommentUserTest extends WebTestBase { /** * Modules to enable. @@ -36,37 +36,51 @@ */ protected $web_user; + /** + * Provides test information. + */ + public static function getInfo() { + return array( + 'name' => 'Comment user tests', + 'description' => 'Test commenting on users.', + 'group' => 'Comment', + ); + } + function setUp() { parent::setUp(); // Create two test users. $this->admin_user = $this->drupalCreateUser(array( - 'administer content types', 'administer comments', 'skip comment approval', 'post comments', 'access comments', 'access content', - 'administer users' + 'administer users', + 'access user profiles', )); $this->web_user = $this->drupalCreateUser(array( 'access comments', 'post comments', - 'create article content', 'edit own comments', 'post comments', 'skip comment approval', 'access content', + 'access user profiles', )); // Create comment field on user bundle. comment_add_default_comment_field('user', 'user', 'comment', COMMENT_ENTITY_OPEN); + + $this->web_user->comment = array(LANGUAGE_NOT_SPECIFIED => array(array('comment' => COMMENT_ENTITY_OPEN))); + $this->web_user->save(); } /** * Posts a comment. * - * @param Drupal\node\User|null $account + * @param Drupal\user\User|null $account * User to post comment on or NULL to post to the previusly loaded page. * @param $comment * Comment body. @@ -86,8 +100,8 @@ function postComment($account, $comment, $subject = '', $contact = NULL) { $subject_mode = $instance['settings']['comment']['comment_subject_field']; // Must get the page before we test for fields. - if ($node !== NULL) { - $this->drupalGet('comment/reply/user/' . $user->uid . '/comment'); + if ($account !== NULL) { + $this->drupalGet('comment/reply/user/' . $account->uid . '/comment'); } if ($subject_mode == TRUE) { @@ -175,91 +189,6 @@ function deleteComment(Comment $comment) { } /** - * Sets the value governing whether the subject field should be enabled. - * - * @param boolean $enabled - * Boolean specifying whether the subject field should be enabled. - */ - function setCommentSubject($enabled) { - $this->setCommentSettings('comment_subject_field', ($enabled ? '1' : '0'), 'Comment subject ' . ($enabled ? 'enabled' : 'disabled') . '.'); - } - - /** - * Sets the value governing the previewing mode for the comment form. - * - * @param int $mode - * The preview mode: DRUPAL_DISABLED, DRUPAL_OPTIONAL or DRUPAL_REQUIRED. - */ - function setCommentPreview($mode) { - switch ($mode) { - case DRUPAL_DISABLED: - $mode_text = 'disabled'; - break; - - case DRUPAL_OPTIONAL: - $mode_text = 'optional'; - break; - - case DRUPAL_REQUIRED: - $mode_text = 'required'; - break; - } - $this->setCommentSettings('comment_preview', $mode, format_string('Comment preview @mode_text.', array('@mode_text' => $mode_text))); - } - - /** - * Sets the value governing whether the comment form is on its own page. - * - * @param boolean $enabled - * TRUE if the comment form should be displayed on the same page as the - * comments; FALSE if it should be displayed on its own page. - */ - function setCommentForm($enabled) { - $this->setCommentSettings('comment_form_location', ($enabled ? COMMENT_FORM_BELOW : COMMENT_FORM_SEPARATE_PAGE), 'Comment controls ' . ($enabled ? 'enabled' : 'disabled') . '.'); - } - - /** - * Sets the value governing restrictions on anonymous comments. - * - * @param integer $level - * The level of the contact information allowed for anonymous comments: - * - 0: No contact information allowed. - * - 1: Contact information allowed but not required. - * - 2: Contact information required. - */ - function setCommentAnonymous($level) { - $this->setCommentSettings('comment_anonymous', $level, format_string('Anonymous commenting set to level @level.', array('@level' => $level))); - } - - /** - * Sets the value specifying the default number of comments per page. - * - * @param integer $comments - * Comments per page value. - */ - function setCommentsPerPage($number) { - $this->setCommentSettings('comment_default_per_page', $number, format_string('Number of comments per page set to @number.', array('@number' => $number))); - } - - /** - * Sets a comment settings variable for the article content type. - * - * @param string $name - * Name of variable. - * @param string $value - * Value of variable. - * @param string $message - * Status message to display. - */ - function setCommentSettings($name, $value, $message) { - $instance = field_info_instance('node', 'comment', 'article'); - $instance['settings']['comment'][$name] = $value; - field_update_instance($instance); - // Display status message. - $this->pass($message); - } - - /** * Checks whether the commenter's contact information is displayed. * * @return boolean @@ -315,84 +244,33 @@ function getUnapprovedComment($subject) { */ function testCommentUser() { $this->drupalLogin($this->admin_user); - $this->setCommentAnonymous('0'); // Ensure that doesn't require contact info. - $this->drupalLogout(); - - // Post anonymous comment without contact info. - $anonymous_comment1 = $this->postComment($this->web_user, $this->randomName(), $this->randomName()); - $this->assertTrue($this->commentExists($anonymous_comment1), 'Anonymous comment without contact info found.'); - - // Allow contact info. - $this->drupalLogin($this->admin_user); - $this->setCommentAnonymous('1'); - - // Attempt to edit anonymous comment. - $this->drupalGet('comment/' . $anonymous_comment1->id . '/edit'); - $edited_comment = $this->postComment(NULL, $this->randomName(), $this->randomName()); - $this->assertTrue($this->commentExists($edited_comment, FALSE), 'Modified reply found.'); - $this->drupalLogout(); - - // Post anonymous comment with contact info (optional). - $this->drupalGet('comment/reply/user/' . $this->web_user->uid . '/comment'); - $this->assertTrue($this->commentContactInfoAvailable(), 'Contact information available.'); - - $anonymous_comment2 = $this->postComment($this->web_user, $this->randomName(), $this->randomName()); - $this->assertTrue($this->commentExists($anonymous_comment2), 'Anonymous comment with contact info (optional) found.'); - - // Ensure anonymous users cannot post in the name of registered users. - $langcode = LANGUAGE_NOT_SPECIFIED; - $edit = array( - 'name' => $this->admin_user->name, - 'mail' => $this->randomName() . '@example.com', - 'subject' => $this->randomName(), - "comment_body[$langcode][0][value]" => $this->randomName(), - ); - $this->drupalPost('comment/reply/user/' . $this->web_user->uid . '/comment', $edit, t('Save')); - $this->assertText(t('The name you used belongs to a registered user.')); - - // Require contact info. - $this->drupalLogin($this->admin_user); - $this->setCommentAnonymous('2'); - $this->drupalLogout(); - // Try to post comment with contact info (required). - $this->drupalGet('comment/reply/user/' . $this->web_user->uid . '/comment'); - $this->assertTrue($this->commentContactInfoAvailable(), 'Contact information available.'); - - $anonymous_comment3 = $this->postComment($this->web_user, $this->randomName(), $this->randomName(), TRUE); - // Name should have 'Anonymous' for value by default. - $this->assertText(t('E-mail field is required.'), 'E-mail required.'); - $this->assertFalse($this->commentExists($anonymous_comment3), 'Anonymous comment with contact info (required) not found.'); - - // Post comment with contact info (required). - $author_name = $this->randomName(); - $author_mail = $this->randomName() . '@example.com'; - $anonymous_comment3 = $this->postComment($this->web_user, $this->randomName(), $this->randomName(), array('name' => $author_name, 'mail' => $author_mail)); - $this->assertTrue($this->commentExists($anonymous_comment3), 'Anonymous comment with contact info (required) found.'); - - // Make sure the user data appears correctly when editing the comment. - $this->drupalLogin($this->admin_user); - $this->drupalGet('comment/' . $anonymous_comment3->id . '/edit'); - $this->assertRaw($author_name, "The anonymous user's name is correct when editing the comment."); - $this->assertRaw($author_mail, "The anonymous user's e-mail address is correct when editing the comment."); + // Post a comment. + $comment1 = $this->postComment($this->web_user, $this->randomName(), $this->randomName()); + $this->assertTrue($this->commentExists($comment1), 'Comment on web user exists.'); // Unpublish comment. - $this->performCommentOperation($anonymous_comment3, 'unpublish'); + $this->performCommentOperation($comment1, 'unpublish'); $this->drupalGet('admin/content/comment/approval'); - $this->assertRaw('comments[' . $anonymous_comment3->id . ']', 'Comment was unpublished.'); + $this->assertRaw('comments[' . $comment1->id . ']', 'Comment was unpublished.'); // Publish comment. - $this->performCommentOperation($anonymous_comment3, 'publish', TRUE); + $this->performCommentOperation($comment1, 'publish', TRUE); $this->drupalGet('admin/content/comment'); - $this->assertRaw('comments[' . $anonymous_comment3->id . ']', 'Comment was published.'); + $this->assertRaw('comments[' . $comment1->id . ']', 'Comment was published.'); // Delete comment. - $this->performCommentOperation($anonymous_comment3, 'delete'); + $this->performCommentOperation($comment1, 'delete'); $this->drupalGet('admin/content/comment'); - $this->assertNoRaw('comments[' . $anonymous_comment3->id . ']', 'Comment was deleted.'); + $this->assertNoRaw('comments[' . $comment1->id . ']', 'Comment was deleted.'); + + // Post another comment. + $comment1 = $this->postComment($this->web_user, $this->randomName(), $this->randomName()); + $this->assertTrue($this->commentExists($comment1), 'Comment on web user exists.'); + $this->drupalLogout(); // Reset. @@ -400,6 +278,7 @@ function testCommentUser() { 'access comments' => FALSE, 'post comments' => FALSE, 'skip comment approval' => FALSE, + 'access user profiles' => TRUE, )); // Attempt to view comments while disallowed. @@ -409,18 +288,20 @@ function testCommentUser() { $this->assertNoPattern('@]*>Comments@', 'Comments were not displayed.'); $this->assertNoLink('Add new comment', 'Link to add comment was found.'); - // Attempt to view node-comment form while disallowed. + // Attempt to view user-comment form while disallowed. $this->drupalGet('comment/reply/user/' . $this->web_user->uid . '/comment'); $this->assertText('You are not authorized to post comments', 'Error attempting to post comment.'); $this->assertNoFieldByName('subject', '', 'Subject field not found.'); + $langcode = LANGUAGE_NOT_SPECIFIED; $this->assertNoFieldByName("comment_body[$langcode][0][value]", '', 'Comment field not found.'); user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array( 'access comments' => TRUE, 'post comments' => FALSE, + 'access user profiles' => TRUE, 'skip comment approval' => FALSE, )); - $this->drupalGet('user/' . $this->web_uer->uid); + $this->drupalGet('user/' . $this->web_user->uid); $this->assertPattern('@]*>Comments@', 'Comments were displayed.'); $this->assertLink('Log in', 1, 'Link to log in was found.'); $this->assertLink('register', 1, 'Link to register was found.'); @@ -429,15 +310,16 @@ function testCommentUser() { 'access comments' => FALSE, 'post comments' => TRUE, 'skip comment approval' => TRUE, + 'access user profiles' => TRUE, )); $this->drupalGet('user/' . $this->web_user->uid); $this->assertNoPattern('@]*>Comments@', 'Comments were not displayed.'); $this->assertFieldByName('subject', '', 'Subject field found.'); $this->assertFieldByName("comment_body[$langcode][0][value]", '', 'Comment field found.'); - $this->drupalGet('comment/reply/user/' . $this->web_user->uid . '/comment/' . $anonymous_comment3->id); + $this->drupalGet('comment/reply/user/' . $this->web_user->uid . '/comment/' . $comment1->id); $this->assertText('You are not authorized to view comments', 'Error attempting to post reply.'); - $this->assertNoText($author_name, 'Comment not displayed.'); + $this->assertNoText($comment1->subject, 'Comment not displayed.'); } } diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php index 0bb8866..d3040b6 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php @@ -258,7 +258,8 @@ function testPrivateFileComment() { 'fields[_add_new_field][type]' => 'file', 'fields[_add_new_field][widget_type]' => 'file_generic', ); - $this->drupalPost('admin/structure/types/manage/article/comment/fields', $edit, t('Save')); + comment_add_default_comment_field('node', 'article', 'comment', COMMENT_ENTITY_OPEN); + $this->drupalPost('admin/structure/comments/comment/fields', $edit, t('Save')); $edit = array('field[settings][uri_scheme]' => 'private'); $this->drupalPost(NULL, $edit, t('Save field settings')); $this->drupalPost(NULL, array(), t('Save settings')); diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php index a7e38ac..0595d7d 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php @@ -67,7 +67,7 @@ function setUp() { // Setup a node to comment and test on. $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); - $this->node = $this->drupalCreateNode(); + $this->node = $this->drupalCreateNode(array('comment_page' => array(LANGUAGE_NOT_SPECIFIED => array(array('comment' => COMMENT_ENTITY_OPEN))))); } /** diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php index bf8f845..95eb046 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php @@ -33,6 +33,7 @@ public function setUp() { parent::setUp(); node_access_rebuild(); + comment_add_default_comment_field('node', 'page', 'comment', COMMENT_ENTITY_OPEN); $this->web_user = $this->drupalCreateUser(array('access content', 'access comments', 'node test view')); } @@ -46,7 +47,9 @@ public function testCommentPager() { // Create 60 comments. for ($i = 0; $i < 60; $i++) { $comment = entity_create('comment', array( - 'nid' => $node->nid, + 'entity_id' => $node->nid, + 'entity_type' => 'node', + 'field_name' => 'comment', 'subject' => $this->randomName(), 'comment_body' => array( LANGUAGE_NOT_SPECIFIED => array( diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTitleTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTitleTest.php index 1880d4f..542b3e7 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTitleTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTitleTest.php @@ -34,6 +34,7 @@ function setUp() { $this->admin_user = $this->drupalCreateUser(array('administer nodes', 'create article content', 'create page content', 'post comments')); $this->drupalLogin($this->admin_user); + comment_add_default_comment_field('node', 'page', 'comment', COMMENT_ENTITY_OPEN); } /** @@ -54,7 +55,7 @@ function testNodeTitle() { $this->assertEqual(current($this->xpath($xpath)), $node->label() .' | Drupal', 'Page title is equal to node title.', 'Node'); // Test breadcrumb in comment preview. - $this->drupalGet("comment/reply/$node->nid"); + $this->drupalGet("comment/reply/node/$node->nid/comment"); $xpath = '//nav[@class="breadcrumb"]/ol/li[last()]/a'; $this->assertEqual(current($this->xpath($xpath)), $node->label(), 'Node breadcrumb is equal to node title.', 'Node'); diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/CommentAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/CommentAttributesTest.php index fc883cb..222acf2 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/CommentAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/CommentAttributesTest.php @@ -57,6 +57,11 @@ public function setUp() { $this->setCommentSubject(TRUE); $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, 'Comment paging changed.'); + // Make sure the comment field defaults to open. + $instance = field_info_instance('node', 'article', 'comment'); + $instance['default_value'] = array(array('comment' => COMMENT_ENTITY_OPEN)); + field_update_instance($instance); + // Creates the nodes on which the test comments will be posted. $this->drupalLogin($this->web_user); $this->node1 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1)); diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/TrackerAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/TrackerAttributesTest.php index 2a8fba3..c27a80c 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/TrackerAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/TrackerAttributesTest.php @@ -42,6 +42,10 @@ function setUp() { 'post comments' => TRUE, 'skip comment approval' => TRUE, )); + // Make sure the comment field defaults to open. + $instance = field_info_instance('node', 'article', 'comment_article'); + $instance['default_value'] = array(array('comment' => COMMENT_ENTITY_OPEN)); + field_update_instance($instance); } /** @@ -119,7 +123,7 @@ function _testBasicTrackerRdfaMarkup(Node $node) { 'subject' => $this->randomName(), 'comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]' => $this->randomName(), ); - $this->drupalPost('comment/reply/' . $node->nid, $comment, t('Save')); + $this->drupalPost('comment/reply/node/' . $node->nid .'/comment_article', $comment, t('Save')); $this->drupalGet('tracker'); // Tests whether the property has been set for number of comments. diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module index d22d111..0cb38e9 100644 --- a/core/modules/rdf/rdf.module +++ b/core/modules/rdf/rdf.module @@ -429,9 +429,9 @@ function rdf_comment_load($comments) { // isn't needed until rdf_preprocess_comment() is called, but set it here // to optimize performance for websites that implement an entity cache. $comment->rdf_data['date'] = rdf_rdfa_attributes($comment->rdf_mapping['created'], $comment->created); - if ($comment->entity_type == 'node') { - $comment->rdf_data['nid_uri'] = url('node/' . $comment->entity_id); - } + $entity = entity_load($comment->entity_type, $comment->entity_id); + $uri = $entity->uri(); + $comment->rdf_data['entity_uri'] = $uri['path']; if ($comment->pid) { $comment->rdf_data['pid_uri'] = url('comment/' . $comment->pid, array('fragment' => 'comment-' . $comment->pid)); } @@ -556,11 +556,15 @@ function rdf_preprocess_node(&$variables) { } // Adds RDFa markup annotating the number of comments a node has. - if (isset($variables['node']->comment_count) && !empty($variables['node']->rdf_mapping['comment_count']['predicates'])) { + if (isset($variables['node']->comment_statistics) && !empty($variables['node']->rdf_mapping['comment_count']['predicates'])) { + $count = 0; + foreach ($variables['node']->comment_statistics as $field_name => $statistics) { + $count += $statistics->comment_count; + } // Annotates the 'x comments' link in teaser view. if (isset($variables['content']['links']['comment']['#links']['comment-comments'])) { $comment_count_attributes['property'] = $variables['node']->rdf_mapping['comment_count']['predicates']; - $comment_count_attributes['content'] = $variables['node']->comment_count; + $comment_count_attributes['content'] = $count; $comment_count_attributes['datatype'] = $variables['node']->rdf_mapping['comment_count']['datatype']; // According to RDFa parsing rule number 4, a new subject URI is created // from the href attribute if no rel/rev attribute is present. To get the @@ -579,7 +583,7 @@ function rdf_preprocess_node(&$variables) { '#attributes' => array( 'about' => $variables['node_url'], 'property' => $variables['node']->rdf_mapping['comment_count']['predicates'], - 'content' => $variables['node']->comment_count, + 'content' => $count, 'datatype' => $variables['node']->rdf_mapping['comment_count']['datatype'], ), ); @@ -752,7 +756,7 @@ function rdf_preprocess_comment(&$variables) { $parent_node_attributes['rel'] = $comment->rdf_mapping['pid']['predicates']; // The parent node URI is precomputed as part of the rdf_data so that it can // be cached as part of the entity. - $parent_node_attributes['resource'] = $comment->rdf_data['nid_uri']; + $parent_node_attributes['resource'] = $comment->rdf_data['entity_uri']; $variables['rdf_metadata_attributes'][] = $parent_node_attributes; // Adds the relation to parent comment, if it exists. diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchCommentCountToggleTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchCommentCountToggleTest.php index 338174d..602b36e 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchCommentCountToggleTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchCommentCountToggleTest.php @@ -47,7 +47,11 @@ function setUp() { $this->searching_user = $this->drupalCreateUser(array('search content', 'access content', 'access comments', 'skip comment approval')); // Create initial nodes. - $node_params = array('type' => 'article', 'body' => array(LANGUAGE_NOT_SPECIFIED => array(array('value' => 'SearchCommentToggleTestCase')))); + $node_params = array( + 'type' => 'article', + 'body' => array(LANGUAGE_NOT_SPECIFIED => array(array('value' => 'SearchCommentToggleTestCase'))), + 'comment_article' => array(LANGUAGE_NOT_SPECIFIED => array(array('comment' => COMMENT_ENTITY_OPEN))) + ); $this->searchable_nodes['1 comment'] = $this->drupalCreateNode($node_params); $this->searchable_nodes['0 comments'] = $this->drupalCreateNode($node_params); @@ -63,7 +67,7 @@ function setUp() { $edit_comment['comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][format]'] = $filtered_html_format_id; // Post comment to the test node with comment - $this->drupalPost('comment/reply/' . $this->searchable_nodes['1 comment']->nid, $edit_comment, t('Save')); + $this->drupalPost('comment/reply/node/' . $this->searchable_nodes['1 comment']->nid . '/comment_article', $edit_comment, t('Save')); // First update the index. This does the initial processing. node_update_index(); @@ -89,9 +93,13 @@ function testSearchCommentCountToggle() { $this->assertText(t('1 comment'), 'Non-empty comment count displays for nodes with comment status set to Open'); // Test comment count display for nodes with comment status set to Closed - $this->searchable_nodes['0 comments']->comment = COMMENT_NODE_CLOSED; + $this->searchable_nodes['0 comments']->comment_article = array( + LANGUAGE_NOT_SPECIFIED => array(array('comment' => COMMENT_ENTITY_CLOSED)) + ); node_save($this->searchable_nodes['0 comments']); - $this->searchable_nodes['1 comment']->comment = COMMENT_NODE_CLOSED; + $this->searchable_nodes['1 comment']->comment_article = array( + LANGUAGE_NOT_SPECIFIED => array(array('comment' => COMMENT_ENTITY_CLOSED)) + ); node_save($this->searchable_nodes['1 comment']); $this->drupalPost('', $edit, t('Search')); @@ -99,9 +107,13 @@ function testSearchCommentCountToggle() { $this->assertText(t('1 comment'), 'Non-empty comment count displays for nodes with comment status set to Closed'); // Test comment count display for nodes with comment status set to Hidden - $this->searchable_nodes['0 comments']->comment = COMMENT_NODE_HIDDEN; + $this->searchable_nodes['0 comments']->comment_article = array( + LANGUAGE_NOT_SPECIFIED => array(array('comment' => COMMENT_ENTITY_HIDDEN)) + );; node_save($this->searchable_nodes['0 comments']); - $this->searchable_nodes['1 comment']->comment = COMMENT_NODE_HIDDEN; + $this->searchable_nodes['1 comment']->comment_article = array( + LANGUAGE_NOT_SPECIFIED => array(array('comment' => COMMENT_ENTITY_HIDDEN)) + );; node_save($this->searchable_nodes['1 comment']); $this->drupalPost('', $edit, t('Search')); diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php index d6c25b1..f623b79 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php @@ -71,14 +71,21 @@ function testSearchResultsComment() { $this->drupalPost('admin/people/permissions', $edit, t('Save permissions')); // Create a node. - $node = $this->drupalCreateNode(array('type' => 'article')); + $node = $this->drupalCreateNode(array( + 'type' => 'article', + 'comment_article' => array( + LANGUAGE_NOT_SPECIFIED => array( + array('comment' => COMMENT_ENTITY_CLOSED) + ) + ) + )); // Post a comment using 'Full HTML' text format. $edit_comment = array(); $edit_comment['subject'] = 'Test comment subject'; $edit_comment['comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]'] = '

' . $comment_body . '

'; $full_html_format_id = 'full_html'; $edit_comment['comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][format]'] = $full_html_format_id; - $this->drupalPost('comment/reply/' . $node->nid, $edit_comment, t('Save')); + $this->drupalPost('comment/reply/node/' . $node->nid .'/comment_article', $edit_comment, t('Save')); // Invoke search index update. $this->drupalLogout(); @@ -130,14 +137,24 @@ function testSearchResultsCommentAccess() { $this->admin_role = key($this->admin_role); // Create a node. - variable_set('comment_preview_article', DRUPAL_OPTIONAL); - $this->node = $this->drupalCreateNode(array('type' => 'article')); + // Make preview optional. + $instance = field_info_instance('node', 'article', 'comment_article'); + $instance['settings']['comment']['comment_preview'] = DRUPAL_OPTIONAL; + field_update_instance($instance); + $this->node = $this->drupalCreateNode(array( + 'type' => 'article', + 'comment_article' => array( + LANGUAGE_NOT_SPECIFIED => array( + array('comment' => COMMENT_ENTITY_CLOSED) + ) + ) + )); // Post a comment using 'Full HTML' text format. $edit_comment = array(); $edit_comment['subject'] = $this->comment_subject; $edit_comment['comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]'] = '

' . $comment_body . '

'; - $this->drupalPost('comment/reply/' . $this->node->nid, $edit_comment, t('Save')); + $this->drupalPost('comment/reply/node/' . $this->node->nid . '/comment_article', $edit_comment, t('Save')); $this->drupalLogout(); $this->setRolePermissions(DRUPAL_ANONYMOUS_RID); @@ -222,6 +239,11 @@ function testAddNewComment() { 'type' => 'article', 'title' => 'short title', 'body' => array(LANGUAGE_NOT_SPECIFIED => array(array('value' => 'short body text'))), + 'comment_article' => array( + LANGUAGE_NOT_SPECIFIED => array( + array('comment' => COMMENT_ENTITY_CLOSED) + ) + ) ); $user = $this->drupalCreateUser(array('search content', 'create article content', 'access content')); diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index ecf2861..b1e6520 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -205,7 +205,7 @@ function drupalGetNodeByTitle($title, $reset = FALSE) { * ); * @endcode * - title: Random string. - * - comment: COMMENT_NODE_OPEN. + * - comment: COMMENT_ENTITY_OPEN. * - changed: REQUEST_TIME. * - promote: NODE_NOT_PROMOTED. * - log: Empty string. @@ -228,7 +228,7 @@ protected function drupalCreateNode(array $settings = array()) { $settings += array( 'body' => array(LANGUAGE_NOT_SPECIFIED => array(array())), 'title' => $this->randomName(8), - 'comment' => COMMENT_NODE_OPEN, + 'comment' => COMMENT_ENTITY_OPEN, 'changed' => REQUEST_TIME, 'promote' => NODE_NOT_PROMOTED, 'revision' => 1, diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php index 4afb574..c3eb83e 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php @@ -69,12 +69,19 @@ protected function assertHookMessageOrder($messages) { * Tests hook invocations for CRUD operations on comments. */ public function testCommentHooks() { + comment_add_default_comment_field('node', 'article', 'comment', COMMENT_ENTITY_OPEN); $node = entity_create('node', array( 'uid' => 1, 'type' => 'article', 'title' => 'Test node', 'status' => 1, - 'comment' => 2, + 'comment' => array( + LANGUAGE_NOT_SPECIFIED => array( + array( + 'comment' => COMMENT_ENTITY_OPEN + ) + ) + ), 'promote' => 0, 'sticky' => 0, 'langcode' => LANGUAGE_NOT_SPECIFIED, @@ -87,7 +94,9 @@ public function testCommentHooks() { $comment = entity_create('comment', array( 'cid' => NULL, 'pid' => 0, - 'nid' => $nid, + 'entity_id' => $nid, + 'entity_type' => 'node', + 'field_name' => 'comment', 'uid' => 1, 'subject' => 'Test comment', 'created' => REQUEST_TIME, diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php index 5c0ab5f..2a7edcc 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php @@ -134,8 +134,6 @@ function testBreadCrumbs() { "admin/structure/types/manage/$type/display" => t('Manage display'), ); $this->assertBreadcrumb("admin/structure/types/manage/$type/display/teaser", $trail_teaser); - $this->assertBreadcrumb("admin/structure/types/manage/$type/comment/fields", $trail); - $this->assertBreadcrumb("admin/structure/types/manage/$type/comment/display", $trail); $this->assertBreadcrumb("admin/structure/types/manage/$type/delete", $trail); $trail += array( "admin/structure/types/manage/$type/fields" => t('Manage fields'), diff --git a/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php b/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php index 8b51fe0..8bdb0ed 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php @@ -44,7 +44,14 @@ function testUserCancelWithoutPermission() { $account = user_load($account->uid, TRUE); // Create a node. - $node = $this->drupalCreateNode(array('uid' => $account->uid)); + $node = $this->drupalCreateNode(array( + 'uid' => $account->uid, + 'comment_page' => array( + LANGUAGE_NOT_SPECIFIED => array( + array('comment' => COMMENT_ENTITY_CLOSED) + ) + ) + )); // Attempt to cancel account. $this->drupalGet('user/' . $account->uid . '/edit'); @@ -286,7 +293,14 @@ function testUserDelete() { $account = user_load($account->uid, TRUE); // Create a simple node. - $node = $this->drupalCreateNode(array('uid' => $account->uid)); + $node = $this->drupalCreateNode(array( + 'uid' => $account->uid, + 'comment_page' => array( + LANGUAGE_NOT_SPECIFIED => array( + array('comment' => COMMENT_ENTITY_CLOSED) + ) + ) + )); // Create comment. $langcode = LANGUAGE_NOT_SPECIFIED; @@ -294,7 +308,7 @@ function testUserDelete() { $edit['subject'] = $this->randomName(8); $edit['comment_body[' . $langcode . '][0][value]'] = $this->randomName(16); - $this->drupalPost('comment/reply/' . $node->nid, $edit, t('Preview')); + $this->drupalPost('comment/reply/node/' . $node->nid . '/comment_page', $edit, t('Preview')); $this->drupalPost(NULL, array(), t('Save')); $this->assertText(t('Your comment has been posted.')); $comments = entity_load_multiple_by_properties('comment', array('subject' => $edit['subject'])); diff --git a/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php b/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php index 9ed88ca..70ca896 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php @@ -37,6 +37,8 @@ function setUp() { // Create Basic page node type. $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); + // Add a comment field. + comment_add_default_comment_field('node', 'page', 'comment', COMMENT_ENTITY_OPEN); // Prefetch and create text formats. $this->plain_text_format = filter_format_load('plain_text'); @@ -75,8 +77,8 @@ function setUp() { * upon display. */ function testUserSignature() { - // Create a new node with comments on. - $node = $this->drupalCreateNode(array('comment' => COMMENT_NODE_OPEN)); + // Create a new node with comments on (default). + $node = $this->drupalCreateNode(); // Verify that user signature field is not displayed on registration form. $this->drupalGet('user/register'); @@ -100,7 +102,7 @@ function testUserSignature() { $edit = array(); $edit['subject'] = $this->randomName(8); $edit['comment_body[' . $langcode . '][0][value]'] = $this->randomName(16); - $this->drupalPost('comment/reply/' . $node->nid, $edit, t('Preview')); + $this->drupalPost('comment/reply/node/' . $node->nid .'/comment', $edit, t('Preview')); $this->drupalPost(NULL, array(), t('Save')); // Get the comment ID. (This technique is the same one used in the Comment diff --git a/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerTest.php b/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerTest.php index 00d6b3e..4d93194 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerTest.php @@ -267,7 +267,7 @@ public function testSetRelationship() { // Setup a broken relationship. $view->addItem('default', 'relationship', $this->randomName(), $this->randomName(), array(), 'broken_relationship'); // Setup a valid relationship. - $view->addItem('default', 'relationship', 'comment', 'nid', array('relationship' => 'cid'), 'valid_relationship'); + $view->addItem('default', 'relationship', 'comment', 'entity_id', array('relationship' => 'cid'), 'valid_relationship'); $view->initHandlers(); $field = $view->field['title'];