comparison core/modules/search/src/Tests/SearchQueryAlterTest.php @ 0:4c8ae668cc8c

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