You are here

public function FacetsUrlGeneratorTest::testWithAlreadySetFacet in Facets 8

Create url with already set facet.

File

tests/src/Functional/FacetsUrlGeneratorTest.php, line 72

Class

FacetsUrlGeneratorTest
Class FacetsUrlGeneratorTest.

Namespace

Drupal\Tests\facets\Functional

Code

public function testWithAlreadySetFacet() {
  $this
    ->drupalPlaceBlock('display_generated_link');
  $this
    ->createFacet('Owl', 'owl');
  $this
    ->createFacet('Llama', 'llama', 'keywords');
  $facet = Facet::load('owl');
  $facet
    ->setUrlAlias('donkey');
  $facet
    ->save();
  $url = $this->urlGenerator
    ->getUrl([
    'owl' => [
      'foo',
    ],
  ]);
  $this
    ->assertEquals('route:view.search_api_test_view.page_1;arg_0&arg_1&arg_2?f%5B0%5D=donkey%3Afoo', $url
    ->toUriString());

  // This won't work without it being in the request, so we need to do this
  // from a block. We first click the link, check that the "orange" facet is
  // active as expected and that the output from the custom block is shown.
  // Then we click the item from the custom block and check that the orange is
  // no longer active, but item is.
  $this
    ->drupalGet('search-api-test-fulltext');
  $this
    ->clickLink('orange');
  $this
    ->checkFacetIsActive('orange');
  $this
    ->checkFacetIsNotActive('item');
  $this
    ->assertSession()
    ->pageTextContains('Link to owl item');
  $this
    ->clickLink('Link to owl item');
  $this
    ->checkFacetIsActive('item');
  $this
    ->checkFacetIsNotActive('orange');

  // This won't work without it being in the request, so we need to do this
  // from a block. We first click the link, check that the "orange" facet is
  // active as expected and that the output from the custom block is shown.
  // Then we click the item from the custom block and check that the orange is
  // still active, but item is.
  \Drupal::state()
    ->get('facets_url_generator_keep_active', TRUE);
  $this
    ->drupalGet('search-api-test-fulltext');
  $this
    ->clickLink('orange');
  $this
    ->checkFacetIsActive('orange');
  $this
    ->checkFacetIsNotActive('item');
  $this
    ->assertSession()
    ->pageTextContains('Link to owl item');
  $this
    ->clickLink('Link to owl item');
  $this
    ->checkFacetIsActive('item');
  $this
    ->checkFacetIsActive('orange');
}