You are here

public function SearchResultsTest::testPagerHeaderAndSorting in Google Search Appliance 8

Tests pager, header and sorting.

File

tests/src/Functional/SearchResultsTest.php, line 61

Class

SearchResultsTest
Tests search results are output.

Namespace

Drupal\Tests\google_appliance\Functional

Code

public function testPagerHeaderAndSorting() {

  // Submit the search specified in $file_spec via URL (form submission already tested)
  $this
    ->drupalGet('gsearch/ponies');
  $assert = $this
    ->assertSession();

  // Make sure we get a response, and that it is not an error message.
  $assert
    ->statusCodeEquals(200);
  $assert
    ->pageTextNotContains('No Results');

  // Verify that we have search stats report correctly.
  $expectation = 'Showing results 1 - 20 for <em class="placeholder">ponies</em>';
  $assert
    ->responseContains($expectation);

  // Verify that sort headers display correctly
  // default state is "Relevance" not linked and "Date" linked.
  $assert
    ->pageTextContains('Relevance');
  $assert
    ->linkNotExists('Relevance');
  $assert
    ->linkExists('Date');

  // Verify that we have the pager, and that page 1 is marked current.
  $page = $this
    ->getSession()
    ->getPage();
  $pager = $page
    ->find('css', 'ul.pager__items');
  $this
    ->assertNotEmpty($pager);
  $active = $page
    ->find('css', 'li.pager__item.is-active:contains("1")');
  $this
    ->assertNotEmpty($active);

  // Verify paging function.
  $pageTwoLink = $page
    ->find('css', 'li.pager__item a:contains("2")');
  $pageTwoLink
    ->click();

  // Make sure resulting page doesn't have error message.
  $assert
    ->pageTextNotContains('No Results');

  // Verify that we have the pager, and that page 2 is marked current.
  $pager = $page
    ->find('css', 'ul.pager__items');
  $this
    ->assertNotEmpty($pager);
  $active = $page
    ->find('css', 'li.pager__item.is-active:contains("2")');
  $this
    ->assertNotEmpty($active);

  // Verify sorting function.
  $this
    ->clickLink('Date');
  $assert
    ->pageTextNotContains('No Results');
  $this
    ->assertEquals(Url::fromRoute(SearchViewRoute::ROUTE_NAME, [
    'search_query' => 'ponies',
    'result_sort' => 'date',
  ])
    ->setAbsolute()
    ->setOption('query', [
    'page' => 1,
  ])
    ->toString(), $this
    ->getSession()
    ->getCurrentUrl());
  $assert
    ->linkNotExists('Date');

  // Bottom bar (second) link.
  $this
    ->clickLink('Relevance', 1);
  $assert
    ->pageTextNotContains('No Results');
  $assert
    ->linkNotExists('Relevance');
  $this
    ->assertEquals(Url::fromRoute(SearchViewRoute::ROUTE_NAME, [
    'search_query' => 'ponies',
    'result_sort' => 'rel',
  ])
    ->setAbsolute()
    ->setOption('query', [
    'page' => 1,
  ])
    ->toString(), $this
    ->getSession()
    ->getCurrentUrl());
}