You are here

public function UrlIntegrationTest::testUrlIntegration in Facets 8

Tests various url integration things.

File

tests/src/Functional/UrlIntegrationTest.php, line 48

Class

UrlIntegrationTest
Tests the overall functionality of the Facets admin UI.

Namespace

Drupal\Tests\facets\Functional

Code

public function testUrlIntegration() {
  $id = 'facet';
  $name = '&^Facet@#1';
  $this
    ->createFacet($name, $id);
  $url = Url::fromUserInput('/search-api-test-fulltext', [
    'query' => [
      'f[0]' => 'facet:item',
    ],
  ]);
  $this
    ->checkClickedFacetUrl($url);

  /** @var \Drupal\facets\FacetInterface $facet */
  $facet = Facet::load($id);
  $this
    ->assertInstanceOf(FacetInterface::class, $facet);
  $config = $facet
    ->getFacetSourceConfig();
  $this
    ->assertInstanceOf(FacetSourceInterface::class, $config);
  $this
    ->assertEquals('f', $config
    ->getFilterKey());
  $facet = NULL;
  $config = NULL;

  // Go to the only enabled facet source's config and change the filter key.
  $this
    ->drupalGet('admin/config/search/facets');
  $this
    ->clickLink('Configure', 1);
  $edit = [
    'filter_key' => 'y',
    'url_processor' => 'query_string',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save');

  /** @var \Drupal\facets\FacetInterface $facet */
  $facet = Facet::load($id);
  $config = $facet
    ->getFacetSourceConfig();
  $this
    ->assertInstanceOf(FacetSourceInterface::class, $config);
  $this
    ->assertEquals('y', $config
    ->getFilterKey());
  $facet = NULL;
  $config = NULL;
  $url_2 = Url::fromUserInput('/search-api-test-fulltext', [
    'query' => [
      'y[0]' => 'facet:item',
    ],
  ]);
  $this
    ->checkClickedFacetUrl($url_2);

  // Go to the only enabled facet source's config and change the url
  // processor.
  $this
    ->drupalGet('admin/config/search/facets');
  $this
    ->clickLink('Configure', 1);
  $edit = [
    'filter_key' => 'y',
    'url_processor' => 'dummy_query',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save');

  /** @var \Drupal\facets\FacetInterface $facet */
  $facet = Facet::load($id);
  $config = $facet
    ->getFacetSourceConfig();
  $this
    ->assertInstanceOf(FacetSourceInterface::class, $config);
  $this
    ->assertEquals('y', $config
    ->getFilterKey());
  $facet = NULL;
  $config = NULL;
  $url_3 = Url::fromUserInput('/search-api-test-fulltext', [
    'query' => [
      'y[0]' => 'facet||item',
    ],
  ]);
  $this
    ->checkClickedFacetUrl($url_3);
}