SearchQueryAlterTest.php in Drupal 10
File
core/modules/search/tests/src/Functional/SearchQueryAlterTest.php
View source
<?php
namespace Drupal\Tests\search\Functional;
use Drupal\Tests\BrowserTestBase;
class SearchQueryAlterTest extends BrowserTestBase {
protected static $modules = [
'node',
'search',
'search_query_alter',
];
protected $defaultTheme = 'stark';
public function testQueryAlter() {
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page',
]);
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$this
->drupalLogin($this
->drupalCreateUser([
'create page content',
'search content',
]));
$data = [
'type' => 'page',
'title' => 'test page',
'body' => [
[
'value' => 'pizza',
],
],
];
$this
->drupalCreateNode($data);
$data['type'] = 'article';
$data['title'] = 'test article';
$this
->drupalCreateNode($data);
$this->container
->get('plugin.manager.search')
->createInstance('node_search')
->updateIndex();
$this
->drupalGet('search/node');
$this
->submitForm([
'keys' => 'pizza',
], 'Search');
$this
->assertSession()
->pageTextContains('article');
$this
->assertSession()
->pageTextNotContains('page');
}
}