View source
<?php
namespace Drupal\Tests\search\Functional;
use Drupal\Tests\BrowserTestBase;
class SearchAdvancedSearchFormTest extends BrowserTestBase {
protected static $modules = [
'node',
'search',
'dblog',
];
protected $defaultTheme = 'stark';
protected $node;
protected function setUp() : void {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page',
]);
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$test_user = $this
->drupalCreateUser([
'access content',
'search content',
'use advanced search',
'administer nodes',
]);
$this
->drupalLogin($test_user);
$this->node = $this
->drupalCreateNode();
$this->container
->get('plugin.manager.search')
->createInstance('node_search')
->updateIndex();
}
public function testNodeType() {
$this
->assertSame('page', $this->node
->getType(), 'Node type is Basic page.');
$dummy_title = 'Lorem ipsum';
$this
->assertNotEquals($dummy_title, $this->node
->label(), "Dummy title doesn't equal node title.");
$this
->drupalGet('search/node', [
'query' => [
'keys' => $dummy_title,
],
]);
$this
->assertSession()
->pageTextNotContains($this->node
->label());
$this
->drupalGet('search/node', [
'query' => [
'keys' => $this->node
->label(),
],
]);
$this
->assertSession()
->pageTextContains($this->node
->label());
$edit = [
'or' => $this->node
->label(),
];
$this
->drupalGet('search/node');
$this
->submitForm($edit, 'edit-submit--2');
$this
->assertSession()
->pageTextContains($this->node
->label());
$this
->drupalGet('search/node');
$this
->submitForm(array_merge($edit, [
'type[page]' => 'page',
]), 'edit-submit--2');
$this
->assertSession()
->pageTextContains($this->node
->label());
$this
->drupalGet('search/node');
$this
->submitForm(array_merge($edit, [
'type[article]' => 'article',
]), 'edit-submit--2');
$this
->assertSession()
->pageTextContains('search yielded no results');
}
public function testFormRefill() {
$edit = [
'keys' => 'cat',
'or' => 'dog gerbil',
'phrase' => 'pets are nice',
'negative' => 'fish snake',
'type[page]' => 'page',
];
$this
->drupalGet('search/node');
$this
->submitForm($edit, 'edit-submit--2');
$this
->assertSession()
->pageTextContains('Search for cat dog OR gerbil -fish -snake');
foreach ($edit as $key => $value) {
if ($key != 'type[page]') {
$this
->assertSession()
->fieldValueEquals($key, $value);
}
else {
$this
->assertSession()
->checkboxChecked($key);
}
}
$edit2 = [
'keys' => 'cat dog OR gerbil -fish -snake',
];
$this
->drupalGet('search/node');
$this
->submitForm($edit2, 'edit-submit--2');
$this
->assertSession()
->pageTextContains('Search for cat dog OR gerbil -fish -snake');
foreach ($edit as $key => $value) {
if ($key != 'type[page]') {
$this
->assertSession()
->fieldValueNotEquals($key, $value);
}
}
}
}