SearchTest.php in Lightning Core 8.5
File
modules/lightning_search/tests/src/Functional/SearchTest.php
View source
<?php
namespace Drupal\Tests\lightning_search\Functional;
use Drupal\node\Entity\Node;
use Drupal\Tests\BrowserTestBase;
use Drupal\views\Entity\View;
class SearchTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'block',
'lightning_search',
];
protected function setUp() {
parent::setUp();
$view = View::load('search');
$display =& $view
->getDisplay('default');
$display['display_options']['cache'] = [
'type' => 'none',
'options' => [],
];
$view
->save();
$this
->drupalPlaceBlock('views_exposed_filter_block:search-page', [
'visibility' => [
'request_path' => [
'pages' => '/search',
],
],
]);
}
public function testAnonymousSearch() {
$node_type = $this
->drupalCreateContentType()
->id();
$node = Node::create([
'type' => $node_type,
'title' => 'Zombie 1',
'body' => 'Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro.',
]);
$node
->setUnpublished()
->save();
$node = Node::create([
'type' => $node_type,
'title' => 'Zombie 2',
'body' => 'De carne lumbering animata corpora quaeritis.',
]);
$node
->setUnpublished()
->save();
$node = Node::create([
'type' => $node_type,
'title' => 'Zombie 3',
'body' => 'Summus brains sit, morbo vel maleficia?',
]);
$node
->setPublished()
->save();
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalGet('/search');
$assert_session
->statusCodeEquals(200);
$page
->fillField('Keywords', 'zombie');
$page
->pressButton('Search');
$assert_session
->statusCodeEquals(200);
$assert_session
->linkNotExists('Zombie 1');
$assert_session
->linkNotExists('Zombie 2');
$assert_session
->linkExists('Zombie 3');
}
}
Classes
Name |
Description |
SearchTest |
Tests Lightning's out of the box search functionality. |