You are here

public function SearchTest::testAnonymousSearch in Lightning Core 8.5

Same name and namespace in other branches
  1. 8.4 modules/lightning_search/tests/src/Functional/SearchTest.php \Drupal\Tests\lightning_search\Functional\SearchTest::testAnonymousSearch()

Tests that search appears where we expect and respects access restrictions.

File

modules/lightning_search/tests/src/Functional/SearchTest.php, line 54

Class

SearchTest
Tests Lightning's out of the box search functionality.

Namespace

Drupal\Tests\lightning_search\Functional

Code

public function testAnonymousSearch() {
  $node_type = $this
    ->drupalCreateContentType()
    ->id();

  /** @var \Drupal\node\NodeInterface $node */
  $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');
}