function SearchCommentCountToggleTest::setUp

Same name and namespace in other branches
  1. 9 core/modules/search/tests/src/Functional/SearchCommentCountToggleTest.php \Drupal\Tests\search\Functional\SearchCommentCountToggleTest::setUp()
  2. 10 core/modules/search/tests/src/Functional/SearchCommentCountToggleTest.php \Drupal\Tests\search\Functional\SearchCommentCountToggleTest::setUp()
  3. 11.x 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\Functional

Code

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();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.