ActiveFiltersTest.php in Facets Pretty Paths 8
File
tests/src/Kernel/ActiveFiltersTest.php
View source
<?php
namespace Drupal\Tests\facets_pretty_paths\Kernel;
use Drupal\facets\Entity\Facet;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\facets_pretty_paths\Traits\FacetsRequestTrait;
class ActiveFiltersTest extends KernelTestBase {
use FacetsRequestTrait;
protected static $modules = [
'system',
'facets',
'facets_pretty_paths',
'facets_pretty_paths_test',
];
protected function setUp() {
parent::setUp();
$this
->installConfig([
'system',
'facets_pretty_paths_test',
]);
}
public function testDefaultActiveFilters() {
$facet = $this->container
->get('entity_type.manager')
->getStorage('facets_facet')
->load('content_type');
$this
->assertInstanceOf(Facet::class, $facet);
$source_id = 'search_api:views_page__search__page_1';
$stack = $this->container
->get('request_stack');
$this
->pushRequest($stack, 'My search page', 'content_type/article/content_type/page/content_type/dummy');
$active_filters_service = $this->container
->get('facets_pretty_paths.active_filters');
$active_filters = $active_filters_service
->getActiveFilters($source_id);
$this
->assertEquals([
'content_type' => [
'article',
'page',
'dummy',
],
], $active_filters);
}
public function testEncodedActiveFilters() {
$facet = $this->container
->get('entity_type.manager')
->getStorage('facets_facet')
->load('content_type');
$this
->assertInstanceOf(Facet::class, $facet);
$facet
->setThirdPartySetting('facets_pretty_paths', 'coder', 'dummy_coder');
$facet
->save();
$source_id = 'search_api:views_page__search__page_1';
$stack = $this->container
->get('request_stack');
$this
->pushRequest($stack, 'My search page', 'content_type/dummy-article/content_type/dummy-page/content_type/dummy-dummy');
$active_filters_service = $this->container
->get('facets_pretty_paths.active_filters');
$active_filters = $active_filters_service
->getActiveFilters($source_id);
$this
->assertEquals([
'content_type' => [
'article',
'page',
'dummy',
],
], $active_filters);
}
}