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