annotate core/modules/search/tests/src/Functional/SearchQueryAlterTest.php @ 19:fa3358dc1485 tip

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