comparison core/modules/search/tests/src/Functional/SearchQueryAlterTest.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents
children
comparison
equal deleted inserted replaced
3:307d7a7fd348 4:a9cd425dd02b
1 <?php
2
3 namespace Drupal\Tests\search\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8 * Tests that the node search query can be altered via the query alter hook.
9 *
10 * @group search
11 */
12 class SearchQueryAlterTest extends BrowserTestBase {
13
14 /**
15 * {@inheritdoc}
16 */
17 protected static $modules = ['node', 'search', 'search_query_alter'];
18
19 /**
20 * Tests that the query alter works.
21 */
22 public function testQueryAlter() {
23 $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
24 $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
25
26 // Log in with sufficient privileges.
27 $this->drupalLogin($this->drupalCreateUser(['create page content', 'search content']));
28
29 // Create a node and an article with the same keyword. The query alter
30 // test module will alter the query so only articles should be returned.
31 $data = [
32 'type' => 'page',
33 'title' => 'test page',
34 'body' => [['value' => 'pizza']],
35 ];
36 $this->drupalCreateNode($data);
37
38 $data['type'] = 'article';
39 $data['title'] = 'test article';
40 $this->drupalCreateNode($data);
41
42 // Update the search index.
43 $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
44 search_update_totals();
45
46 // Search for the body keyword 'pizza'.
47 $this->drupalPostForm('search/node', ['keys' => 'pizza'], t('Search'));
48 // The article should be there but not the page.
49 $this->assertText('article', 'Article is in search results');
50 $this->assertNoText('page', 'Page is not in search results');
51 }
52
53 }