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