diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php
index 3ac6f41..358b4d4 100644
--- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php
+++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php
@@ -2,24 +2,25 @@
/**
* @file
- * Contains Drupal\comment\Tests\CommentUserTest.
+ * Contains Drupal\comment\Tests\CommentTestBase.
*/
namespace Drupal\comment\Tests;
+
use Drupal\comment\Plugin\Core\Entity\Comment;
use Drupal\simpletest\WebTestBase;
/**
- * Tests basic comment functionality against a user entity.
+ * Provides setup and helper methods for comment tests.
*/
-class CommentUserTest extends WebTestBase {
+abstract class CommentTestBase extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
- public static $modules = array('comment', 'user');
+ public static $modules = array('comment', 'node', 'history');
/**
* An administrative user with permission to configure comment settings.
@@ -325,93 +326,4 @@ function getUnapprovedComment($subject) {
return $match[2];
}
- /**
- * Tests anonymous comment functionality.
- */
- function testCommentUser() {
- $this->drupalLogin($this->admin_user);
-
- // 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($comment1, 'unpublish');
-
- $this->drupalGet('admin/content/comment/approval');
- $this->assertRaw('comments[' . $comment1->id . ']', 'Comment was unpublished.');
-
- // Publish comment.
- $this->performCommentOperation($comment1, 'publish', TRUE);
-
- $this->drupalGet('admin/content/comment');
- $this->assertRaw('comments[' . $comment1->id . ']', 'Comment was published.');
-
- // Delete comment.
- $this->performCommentOperation($comment1, 'delete');
-
- $this->drupalGet('admin/content/comment');
- $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.');
-
- // Check comment was found.
- $this->drupalGet('admin/content/comment');
- $this->assertRaw('comments[' . $comment1->id . ']', 'Comment was published.');
-
- $this->drupalLogout();
-
- // Reset.
- user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
- 'access comments' => FALSE,
- 'post comments' => FALSE,
- 'skip comment approval' => FALSE,
- 'access user profiles' => TRUE,
- ));
-
- // 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 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,
- ));
- // Ensure the page cache is flushed.
- drupal_flush_all_caches();
- $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.');
-
- user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
- '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/' . $comment1->id);
- $this->assertText('You are not authorized to view comments', 'Error attempting to post reply.');
- $this->assertNoText($comment1->subject, 'Comment not displayed.');
- }
-
}
diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentUserTest.php
similarity index 71%
copy from core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php
copy to core/modules/comment/lib/Drupal/comment/Tests/CommentUserTest.php
index 3ac6f41..6a8a584 100644
--- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php
+++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentUserTest.php
@@ -36,53 +36,63 @@ class CommentUserTest extends WebTestBase {
protected $web_user;
/**
- * A test node to which comments will be posted.
- *
- * @var Drupal\node\Node
+ * Provides test information.
*/
- protected $node;
+ public static function getInfo() {
+ return array(
+ 'name' => 'Comment user tests',
+ 'description' => 'Test commenting on users.',
+ 'group' => 'Comment',
+ );
+ }
function setUp() {
parent::setUp();
- // Create an article content type only if it does not yet exist, so that
- // child classes may specify the standard profile.
- $types = node_type_get_types();
- if (empty($types['article'])) {
- $this->drupalCreateContentType(array('type' => 'article', 'name' => t('Article')));
- }
+ // Create comment field on user bundle.
+ comment_add_default_comment_field('user', 'user');
// 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',
+ '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 article.
- comment_add_default_comment_field('node', 'article');
+ // Enable anonymous and authenticated user comments.
+ user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array(
+ 'access comments',
+ 'post comments',
+ 'skip comment approval',
+ ));
+ user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array(
+ 'access comments',
+ 'post comments',
+ 'skip comment approval',
+ ));
- // Create a test node authored by the web user.
- $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->web_user->uid, 'comment' => array(LANGUAGE_NOT_SPECIFIED => array(array('comment' => COMMENT_OPEN)))));
+ $this->web_user->comment = array(LANGUAGE_NOT_SPECIFIED => array(array('comment' => COMMENT_OPEN)));
+ $this->web_user->save();
}
/**
* Posts a comment.
*
- * @param Drupal\node\Node|null $node
- * Node to post comment on or NULL to post to the previusly loaded page.
+ * @param Drupal\user\User|null $account
+ * User to post comment on or NULL to post to the previusly loaded page.
* @param $comment
* Comment body.
* @param $subject
@@ -91,18 +101,18 @@ function setUp() {
* Set to NULL for no contact info, TRUE to ignore success checking, and
* array of values to set contact info.
*/
- function postComment($node, $comment, $subject = '', $contact = NULL) {
+ function postComment($account, $comment, $subject = '', $contact = NULL) {
$langcode = LANGUAGE_NOT_SPECIFIED;
$edit = array();
$edit['comment_body[' . $langcode . '][0][value]'] = $comment;
- $instance = field_info_instance('node', 'comment', 'article');
+ $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/node/' . $node->nid . '/comment');
+ if ($account !== NULL) {
+ $this->drupalGet('comment/reply/user/' . $account->uid . '/comment');
}
if ($subject_mode == TRUE) {
@@ -190,91 +200,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