protected function SearchCommentCountToggleTest::setUp in Drupal 8
Same name and namespace in other branches
- 9 core/modules/search/tests/src/Functional/SearchCommentCountToggleTest.php \Drupal\Tests\search\Functional\SearchCommentCountToggleTest::setUp()
Overrides BrowserTestBase::setUp
File
- core/modules/ search/ tests/ src/ Functional/ SearchCommentCountToggleTest.php, line 49 
Class
- SearchCommentCountToggleTest
- Tests that comment count display toggles properly on comment status of node.
Namespace
Drupal\Tests\search\FunctionalCode
protected function setUp() {
  parent::setUp();
  $this
    ->drupalCreateContentType([
    'type' => 'article',
    'name' => 'Article',
  ]);
  // Create searching user.
  $this->searchingUser = $this
    ->drupalCreateUser([
    'search content',
    'access content',
    'access comments',
    'post comments',
    'skip comment approval',
  ]);
  // Log in with sufficient privileges.
  $this
    ->drupalLogin($this->searchingUser);
  // Add a comment field.
  $this
    ->addDefaultCommentField('node', 'article');
  // Create initial nodes.
  $node_params = [
    'type' => 'article',
    'body' => [
      [
        'value' => 'SearchCommentToggleTestCase',
      ],
    ],
  ];
  $this->searchableNodes['1 comment'] = $this
    ->drupalCreateNode($node_params);
  $this->searchableNodes['0 comments'] = $this
    ->drupalCreateNode($node_params);
  // Create a comment array
  $edit_comment = [];
  $edit_comment['subject[0][value]'] = $this
    ->randomMachineName();
  $edit_comment['comment_body[0][value]'] = $this
    ->randomMachineName();
  // Post comment to the test node with comment
  $this
    ->drupalPostForm('comment/reply/node/' . $this->searchableNodes['1 comment']
    ->id() . '/comment', $edit_comment, t('Save'));
  // First update the index. This does the initial processing.
  $this->container
    ->get('plugin.manager.search')
    ->createInstance('node_search')
    ->updateIndex();
}