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