class SearchKeywordsConditionsTest
Same name and namespace in other branches
- 11.x core/modules/search/tests/src/Functional/SearchKeywordsConditionsTest.php \Drupal\Tests\search\Functional\SearchKeywordsConditionsTest
- 10 core/modules/search/tests/src/Functional/SearchKeywordsConditionsTest.php \Drupal\Tests\search\Functional\SearchKeywordsConditionsTest
- 8.9.x core/modules/search/tests/src/Functional/SearchKeywordsConditionsTest.php \Drupal\Tests\search\Functional\SearchKeywordsConditionsTest
Verify the search without keywords set and extra conditions.
Verifies that a plugin can override the isSearchExecutable() method to allow searching without keywords set and that GET query parameters are made available to plugins during search execution.
@group search
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\search\Functional\SearchKeywordsConditionsTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of SearchKeywordsConditionsTest
File
-
core/
modules/ search/ tests/ src/ Functional/ SearchKeywordsConditionsTest.php, line 17
Namespace
Drupal\Tests\search\FunctionalView source
class SearchKeywordsConditionsTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'comment',
'search',
'search_extra_type',
'test_page_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* A user with permission to search and post comments.
*
* @var \Drupal\user\UserInterface
*/
protected $searchingUser;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Create searching user.
$this->searchingUser = $this->drupalCreateUser([
'search content',
'access content',
'access comments',
'skip comment approval',
]);
// Log in with sufficient privileges.
$this->drupalLogin($this->searchingUser);
}
/**
* Verify the keywords are captured and conditions respected.
*/
public function testSearchKeywordsConditions() {
// No keys, not conditions - no results.
$this->drupalGet('search/dummy_path');
$this->assertSession()
->pageTextNotContains('Dummy search snippet to display');
// With keys - get results.
$keys = 'bike shed ' . $this->randomMachineName();
$this->drupalGet("search/dummy_path", [
'query' => [
'keys' => $keys,
],
]);
$this->assertSession()
->pageTextContains("Dummy search snippet to display. Keywords: {$keys}");
$keys = 'blue drop ' . $this->randomMachineName();
$this->drupalGet("search/dummy_path", [
'query' => [
'keys' => $keys,
],
]);
$this->assertSession()
->pageTextContains("Dummy search snippet to display. Keywords: {$keys}");
// Add some conditions and keys.
$keys = 'moving drop ' . $this->randomMachineName();
$this->drupalGet("search/dummy_path", [
'query' => [
'keys' => 'bike',
'search_conditions' => $keys,
],
]);
$this->assertSession()
->pageTextContains("Dummy search snippet to display.");
$this->assertSession()
->responseContains(Html::escape(print_r([
'keys' => 'bike',
'search_conditions' => $keys,
], TRUE)));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.