annotate core/modules/comment/src/Tests/Views/CommentTestBase.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 1fec387a4317
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\comment\Tests\Views;
Chris@0 4
Chris@0 5 @trigger_error(__NAMESPACE__ . '\CommentTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Use \Drupal\Tests\comment\Functional\Views\CommentTestBase instead. See http://www.drupal.org/node/2908490', E_USER_DEPRECATED);
Chris@0 6
Chris@0 7 use Drupal\comment\Tests\CommentTestTrait;
Chris@0 8 use Drupal\views\Tests\ViewTestBase;
Chris@0 9 use Drupal\views\Tests\ViewTestData;
Chris@0 10 use Drupal\comment\Entity\Comment;
Chris@0 11
Chris@0 12 /**
Chris@0 13 * Provides setup and helper methods for comment views tests.
Chris@0 14 *
Chris@0 15 * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0.
Chris@0 16 * Use \Drupal\Tests\comment\Functional\Views\CommentTestBase instead.
Chris@0 17 *
Chris@0 18 * @see https://www.drupal.org/node/2908490
Chris@0 19 */
Chris@0 20 abstract class CommentTestBase extends ViewTestBase {
Chris@0 21
Chris@0 22 use CommentTestTrait;
Chris@0 23
Chris@0 24 /**
Chris@0 25 * Modules to install.
Chris@0 26 *
Chris@0 27 * @var array
Chris@0 28 */
Chris@0 29 public static $modules = ['node', 'comment', 'comment_test_views'];
Chris@0 30
Chris@0 31 /**
Chris@0 32 * A normal user with permission to post comments (without approval).
Chris@0 33 *
Chris@0 34 * @var \Drupal\user\UserInterface
Chris@0 35 */
Chris@0 36 protected $account;
Chris@0 37
Chris@0 38 /**
Chris@0 39 * A second normal user that will author a node for $account to comment on.
Chris@0 40 *
Chris@0 41 * @var \Drupal\user\UserInterface
Chris@0 42 */
Chris@0 43 protected $account2;
Chris@0 44
Chris@0 45 /**
Chris@0 46 * Stores a node posted by the user created as $account.
Chris@0 47 *
Chris@0 48 * @var \Drupal\node\NodeInterface
Chris@0 49 */
Chris@0 50 protected $nodeUserPosted;
Chris@0 51
Chris@0 52 /**
Chris@0 53 * Stores a node posted by the user created as $account2.
Chris@0 54 *
Chris@0 55 * @var \Drupal\node\NodeInterface
Chris@0 56 */
Chris@0 57 protected $nodeUserCommented;
Chris@0 58
Chris@0 59 /**
Chris@0 60 * Stores a comment used by the tests.
Chris@0 61 *
Chris@0 62 * @var \Drupal\comment\Entity\Comment
Chris@0 63 */
Chris@0 64 protected $comment;
Chris@0 65
Chris@14 66 protected function setUp($import_test_views = TRUE) {
Chris@14 67 parent::setUp($import_test_views);
Chris@0 68
Chris@0 69 ViewTestData::createTestViews(get_class($this), ['comment_test_views']);
Chris@0 70
Chris@0 71 // Add two users, create a node with the user1 as author and another node
Chris@0 72 // with user2 as author. For the second node add a comment from user1.
Chris@0 73 $this->account = $this->drupalCreateUser(['skip comment approval']);
Chris@0 74 $this->account2 = $this->drupalCreateUser();
Chris@0 75 $this->drupalLogin($this->account);
Chris@0 76
Chris@0 77 $this->drupalCreateContentType(['type' => 'page', 'name' => t('Basic page')]);
Chris@0 78 $this->addDefaultCommentField('node', 'page');
Chris@0 79
Chris@0 80 $this->nodeUserPosted = $this->drupalCreateNode();
Chris@0 81 $this->nodeUserCommented = $this->drupalCreateNode(['uid' => $this->account2->id()]);
Chris@0 82
Chris@0 83 $comment = [
Chris@0 84 'uid' => $this->loggedInUser->id(),
Chris@0 85 'entity_id' => $this->nodeUserCommented->id(),
Chris@0 86 'entity_type' => 'node',
Chris@0 87 'field_name' => 'comment',
Chris@0 88 'subject' => 'How much wood would a woodchuck chuck',
Chris@0 89 'cid' => '',
Chris@0 90 'pid' => '',
Chris@0 91 'mail' => 'someone@example.com',
Chris@0 92 ];
Chris@0 93 $this->comment = Comment::create($comment);
Chris@0 94 $this->comment->save();
Chris@0 95 }
Chris@0 96
Chris@0 97 }