
| Current Path : /var/www/html/pallets_old/web/core/modules/search/tests/src/Functional/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/pallets_old/web/core/modules/search/tests/src/Functional/SearchQueryAlterTest.php |
<?php
namespace Drupal\Tests\search\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests that the node search query can be altered via the query alter hook.
*
* @group search
*/
class SearchQueryAlterTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['node', 'search', 'search_query_alter'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests that the query alter works.
*/
public function testQueryAlter() {
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
// Log in with sufficient privileges.
$this->drupalLogin($this->drupalCreateUser([
'create page content',
'search content',
]));
// Create a node and an article with the same keyword. The query alter
// test module will alter the query so only articles should be returned.
$data = [
'type' => 'page',
'title' => 'test page',
'body' => [['value' => 'pizza']],
];
$this->drupalCreateNode($data);
$data['type'] = 'article';
$data['title'] = 'test article';
$this->drupalCreateNode($data);
// Update the search index.
$this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
// Search for the body keyword 'pizza'.
$this->drupalGet('search/node');
$this->submitForm(['keys' => 'pizza'], 'Search');
// The article should be there but not the page.
$this->assertSession()->pageTextContains('article');
$this->assertSession()->pageTextNotContains('page');
}
}