Chris@0: drupalCreateContentType(['type' => 'article', 'name' => 'Article']); Chris@17: Chris@0: // Create searching user. Chris@0: $this->searchingUser = $this->drupalCreateUser(['search content', 'access content', 'access comments', 'post comments', 'skip comment approval']); Chris@0: Chris@0: // Log in with sufficient privileges. Chris@0: $this->drupalLogin($this->searchingUser); Chris@0: Chris@0: // Add a comment field. Chris@0: $this->addDefaultCommentField('node', 'article'); Chris@0: // Create initial nodes. Chris@0: $node_params = ['type' => 'article', 'body' => [['value' => 'SearchCommentToggleTestCase']]]; Chris@0: Chris@0: $this->searchableNodes['1 comment'] = $this->drupalCreateNode($node_params); Chris@0: $this->searchableNodes['0 comments'] = $this->drupalCreateNode($node_params); Chris@0: Chris@0: // Create a comment array Chris@0: $edit_comment = []; Chris@0: $edit_comment['subject[0][value]'] = $this->randomMachineName(); Chris@0: $edit_comment['comment_body[0][value]'] = $this->randomMachineName(); Chris@0: Chris@0: // Post comment to the test node with comment Chris@0: $this->drupalPostForm('comment/reply/node/' . $this->searchableNodes['1 comment']->id() . '/comment', $edit_comment, t('Save')); Chris@0: Chris@0: // First update the index. This does the initial processing. Chris@0: $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex(); Chris@0: Chris@0: // Then, run the shutdown function. Testing is a unique case where indexing Chris@0: // and searching has to happen in the same request, so running the shutdown Chris@0: // function manually is needed to finish the indexing process. Chris@0: search_update_totals(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Verify that comment count display toggles properly on comment status of node Chris@0: */ Chris@0: public function testSearchCommentCountToggle() { Chris@0: // Search for the nodes by string in the node body. Chris@0: $edit = [ Chris@0: 'keys' => "'SearchCommentToggleTestCase'", Chris@0: ]; Chris@0: $this->drupalGet('search/node'); Chris@0: Chris@0: // Test comment count display for nodes with comment status set to Open Chris@0: $this->drupalPostForm(NULL, $edit, t('Search')); Chris@0: $this->assertText(t('0 comments'), 'Empty comment count displays for nodes with comment status set to Open'); Chris@0: $this->assertText(t('1 comment'), 'Non-empty comment count displays for nodes with comment status set to Open'); Chris@0: Chris@0: // Test comment count display for nodes with comment status set to Closed Chris@0: $this->searchableNodes['0 comments']->set('comment', CommentItemInterface::CLOSED); Chris@0: $this->searchableNodes['0 comments']->save(); Chris@0: $this->searchableNodes['1 comment']->set('comment', CommentItemInterface::CLOSED); Chris@0: $this->searchableNodes['1 comment']->save(); Chris@0: Chris@0: $this->drupalPostForm(NULL, $edit, t('Search')); Chris@0: $this->assertNoText(t('0 comments'), 'Empty comment count does not display for nodes with comment status set to Closed'); Chris@0: $this->assertText(t('1 comment'), 'Non-empty comment count displays for nodes with comment status set to Closed'); Chris@0: Chris@0: // Test comment count display for nodes with comment status set to Hidden Chris@0: $this->searchableNodes['0 comments']->set('comment', CommentItemInterface::HIDDEN); Chris@0: $this->searchableNodes['0 comments']->save(); Chris@0: $this->searchableNodes['1 comment']->set('comment', CommentItemInterface::HIDDEN); Chris@0: $this->searchableNodes['1 comment']->save(); Chris@0: Chris@0: $this->drupalPostForm(NULL, $edit, t('Search')); Chris@0: $this->assertNoText(t('0 comments'), 'Empty comment count does not display for nodes with comment status set to Hidden'); Chris@0: $this->assertNoText(t('1 comment'), 'Non-empty comment count does not display for nodes with comment status set to Hidden'); Chris@0: } Chris@0: Chris@0: }