Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\search\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 /**
|
Chris@0
|
6 * Tests that searching for a phrase gets the correct page count.
|
Chris@0
|
7 *
|
Chris@0
|
8 * @group search
|
Chris@0
|
9 */
|
Chris@0
|
10 class SearchExactTest extends SearchTestBase {
|
Chris@0
|
11 /**
|
Chris@0
|
12 * Tests that the correct number of pager links are found for both keywords and phrases.
|
Chris@0
|
13 */
|
Chris@0
|
14 public function testExactQuery() {
|
Chris@0
|
15 // Log in with sufficient privileges.
|
Chris@0
|
16 $user = $this->drupalCreateUser(['create page content', 'search content']);
|
Chris@0
|
17 $this->drupalLogin($user);
|
Chris@0
|
18
|
Chris@0
|
19 $settings = [
|
Chris@0
|
20 'type' => 'page',
|
Chris@0
|
21 'title' => 'Simple Node',
|
Chris@0
|
22 ];
|
Chris@0
|
23 // Create nodes with exact phrase.
|
Chris@0
|
24 for ($i = 0; $i <= 17; $i++) {
|
Chris@0
|
25 $settings['body'] = [['value' => 'love pizza']];
|
Chris@0
|
26 $this->drupalCreateNode($settings);
|
Chris@0
|
27 }
|
Chris@0
|
28 // Create nodes containing keywords.
|
Chris@0
|
29 for ($i = 0; $i <= 17; $i++) {
|
Chris@0
|
30 $settings['body'] = [['value' => 'love cheesy pizza']];
|
Chris@0
|
31 $this->drupalCreateNode($settings);
|
Chris@0
|
32 }
|
Chris@0
|
33 // Create another node and save it for later.
|
Chris@0
|
34 $settings['body'] = [['value' => 'Druplicon']];
|
Chris@0
|
35 $node = $this->drupalCreateNode($settings);
|
Chris@0
|
36
|
Chris@0
|
37 // Update the search index.
|
Chris@0
|
38 $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
|
Chris@0
|
39 search_update_totals();
|
Chris@0
|
40
|
Chris@0
|
41 // Refresh variables after the treatment.
|
Chris@0
|
42 $this->refreshVariables();
|
Chris@0
|
43
|
Chris@0
|
44 // Test that the correct number of pager links are found for keyword search.
|
Chris@0
|
45 $edit = ['keys' => 'love pizza'];
|
Chris@0
|
46 $this->drupalPostForm('search/node', $edit, t('Search'));
|
Chris@0
|
47 $this->assertLinkByHref('page=1', 0, '2nd page link is found for keyword search.');
|
Chris@0
|
48 $this->assertLinkByHref('page=2', 0, '3rd page link is found for keyword search.');
|
Chris@0
|
49 $this->assertLinkByHref('page=3', 0, '4th page link is found for keyword search.');
|
Chris@0
|
50 $this->assertNoLinkByHref('page=4', '5th page link is not found for keyword search.');
|
Chris@0
|
51
|
Chris@0
|
52 // Test that the correct number of pager links are found for exact phrase search.
|
Chris@0
|
53 $edit = ['keys' => '"love pizza"'];
|
Chris@0
|
54 $this->drupalPostForm('search/node', $edit, t('Search'));
|
Chris@0
|
55 $this->assertLinkByHref('page=1', 0, '2nd page link is found for exact phrase search.');
|
Chris@0
|
56 $this->assertNoLinkByHref('page=2', '3rd page link is not found for exact phrase search.');
|
Chris@0
|
57
|
Chris@0
|
58 // Check that with post settings turned on the post information is displayed.
|
Chris@0
|
59 $node_type_config = \Drupal::configFactory()->getEditable('node.type.page');
|
Chris@0
|
60 $node_type_config->set('display_submitted', TRUE);
|
Chris@0
|
61 $node_type_config->save();
|
Chris@0
|
62
|
Chris@0
|
63 $edit = ['keys' => 'Druplicon'];
|
Chris@0
|
64 $this->drupalPostForm('search/node', $edit, t('Search'));
|
Chris@0
|
65 $this->assertText($user->getUsername(), 'Basic page node displays author name when post settings are on.');
|
Chris@0
|
66 $this->assertText(format_date($node->getChangedTime(), 'short'), 'Basic page node displays post date when post settings are on.');
|
Chris@0
|
67
|
Chris@0
|
68 // Check that with post settings turned off the user and changed date
|
Chris@0
|
69 // information is not displayed.
|
Chris@0
|
70 $node_type_config->set('display_submitted', FALSE);
|
Chris@0
|
71 $node_type_config->save();
|
Chris@0
|
72 $edit = ['keys' => 'Druplicon'];
|
Chris@0
|
73 $this->drupalPostForm('search/node', $edit, t('Search'));
|
Chris@0
|
74 $this->assertNoText($user->getUsername(), 'Basic page node does not display author name when post settings are off.');
|
Chris@0
|
75 $this->assertNoText(format_date($node->getChangedTime(), 'short'), 'Basic page node does not display post date when post settings are off.');
|
Chris@0
|
76
|
Chris@0
|
77 }
|
Chris@0
|
78
|
Chris@0
|
79 }
|