Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/search/tests/src/Functional/SearchCommentCountToggleTest.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children | a9cd425dd02b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\search\Functional; | |
4 | |
5 use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; | |
6 use Drupal\comment\Tests\CommentTestTrait; | |
7 | |
8 /** | |
9 * Tests that comment count display toggles properly on comment status of node. | |
10 * | |
11 * Issue 537278 | |
12 * | |
13 * - Nodes with comment status set to Open should always how comment counts | |
14 * - Nodes with comment status set to Closed should show comment counts | |
15 * only when there are comments | |
16 * - Nodes with comment status set to Hidden should never show comment counts | |
17 * | |
18 * @group search | |
19 */ | |
20 class SearchCommentCountToggleTest extends SearchTestBase { | |
21 | |
22 use CommentTestTrait; | |
23 | |
24 /** | |
25 * Modules to enable. | |
26 * | |
27 * @var array | |
28 */ | |
29 public static $modules = ['node', 'comment']; | |
30 | |
31 /** | |
32 * A user with permission to search and post comments. | |
33 * | |
34 * @var \Drupal\user\UserInterface | |
35 */ | |
36 protected $searchingUser; | |
37 | |
38 /** | |
39 * Array of nodes available to search. | |
40 * | |
41 * @var \Drupal\node\NodeInterface[] | |
42 */ | |
43 protected $searchableNodes; | |
44 | |
45 protected function setUp() { | |
46 parent::setUp(); | |
47 | |
48 // Create searching user. | |
49 $this->searchingUser = $this->drupalCreateUser(['search content', 'access content', 'access comments', 'post comments', 'skip comment approval']); | |
50 | |
51 // Log in with sufficient privileges. | |
52 $this->drupalLogin($this->searchingUser); | |
53 | |
54 // Add a comment field. | |
55 $this->addDefaultCommentField('node', 'article'); | |
56 // Create initial nodes. | |
57 $node_params = ['type' => 'article', 'body' => [['value' => 'SearchCommentToggleTestCase']]]; | |
58 | |
59 $this->searchableNodes['1 comment'] = $this->drupalCreateNode($node_params); | |
60 $this->searchableNodes['0 comments'] = $this->drupalCreateNode($node_params); | |
61 | |
62 // Create a comment array | |
63 $edit_comment = []; | |
64 $edit_comment['subject[0][value]'] = $this->randomMachineName(); | |
65 $edit_comment['comment_body[0][value]'] = $this->randomMachineName(); | |
66 | |
67 // Post comment to the test node with comment | |
68 $this->drupalPostForm('comment/reply/node/' . $this->searchableNodes['1 comment']->id() . '/comment', $edit_comment, t('Save')); | |
69 | |
70 // First update the index. This does the initial processing. | |
71 $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex(); | |
72 | |
73 // Then, run the shutdown function. Testing is a unique case where indexing | |
74 // and searching has to happen in the same request, so running the shutdown | |
75 // function manually is needed to finish the indexing process. | |
76 search_update_totals(); | |
77 } | |
78 | |
79 /** | |
80 * Verify that comment count display toggles properly on comment status of node | |
81 */ | |
82 public function testSearchCommentCountToggle() { | |
83 // Search for the nodes by string in the node body. | |
84 $edit = [ | |
85 'keys' => "'SearchCommentToggleTestCase'", | |
86 ]; | |
87 $this->drupalGet('search/node'); | |
88 | |
89 // Test comment count display for nodes with comment status set to Open | |
90 $this->drupalPostForm(NULL, $edit, t('Search')); | |
91 $this->assertText(t('0 comments'), 'Empty comment count displays for nodes with comment status set to Open'); | |
92 $this->assertText(t('1 comment'), 'Non-empty comment count displays for nodes with comment status set to Open'); | |
93 | |
94 // Test comment count display for nodes with comment status set to Closed | |
95 $this->searchableNodes['0 comments']->set('comment', CommentItemInterface::CLOSED); | |
96 $this->searchableNodes['0 comments']->save(); | |
97 $this->searchableNodes['1 comment']->set('comment', CommentItemInterface::CLOSED); | |
98 $this->searchableNodes['1 comment']->save(); | |
99 | |
100 $this->drupalPostForm(NULL, $edit, t('Search')); | |
101 $this->assertNoText(t('0 comments'), 'Empty comment count does not display for nodes with comment status set to Closed'); | |
102 $this->assertText(t('1 comment'), 'Non-empty comment count displays for nodes with comment status set to Closed'); | |
103 | |
104 // Test comment count display for nodes with comment status set to Hidden | |
105 $this->searchableNodes['0 comments']->set('comment', CommentItemInterface::HIDDEN); | |
106 $this->searchableNodes['0 comments']->save(); | |
107 $this->searchableNodes['1 comment']->set('comment', CommentItemInterface::HIDDEN); | |
108 $this->searchableNodes['1 comment']->save(); | |
109 | |
110 $this->drupalPostForm(NULL, $edit, t('Search')); | |
111 $this->assertNoText(t('0 comments'), 'Empty comment count does not display for nodes with comment status set to Hidden'); | |
112 $this->assertNoText(t('1 comment'), 'Non-empty comment count does not display for nodes with comment status set to Hidden'); | |
113 } | |
114 | |
115 } |