public function QueryStringTest::testBuildWithActiveItem in Facets 8
Tests with an active item already from url.
File
- tests/
src/ Unit/ Plugin/ url_processor/ QueryStringTest.php, line 205
Class
- QueryStringTest
- Unit test for processor.
Namespace
Drupal\Tests\facets\Unit\Plugin\url_processorCode
public function testBuildWithActiveItem() {
$facet = new Facet([], 'facets_facet');
$facet
->setFieldIdentifier('test');
$facet
->setUrlAlias('test');
$facet
->setFacetSourceId('facet_source__dummy');
$facet2 = new Facet([], 'facets_facet');
$facet2
->setFieldIdentifier('king');
$facet2
->setUrlAlias('king');
$facet2
->setFacetSourceId('facet_source__dummy');
$discovery_property = new \ReflectionProperty($facet, 'id');
$discovery_property
->setAccessible(TRUE);
$discovery_property
->setValue($facet, 'test');
$storage = $this
->createMock(EntityStorageInterface::class);
$storage
->expects($this
->atLeastOnce())
->method('loadByProperties')
->willReturnOnConsecutiveCalls([
$facet2,
], [
$facet2,
], [
$facet2,
], [
$facet2,
], [
$facet2,
], [
$facet2,
]);
$entityTypeManager = $this
->getMockBuilder(EntityTypeManagerInterface::class)
->disableOriginalConstructor()
->getMock();
$entityTypeManager
->expects($this
->any())
->method('getStorage')
->willReturn($storage);
$container = \Drupal::getContainer();
$container
->set('entity_type.manager', $entityTypeManager);
\Drupal::setContainer($container);
$original_results = $this->originalResults;
$original_results[2]
->setActiveState(TRUE);
$request = new Request();
$request->query
->set('f', [
'king:kong',
]);
$this->processor = new QueryString([
'facet' => $facet,
], 'query_string', [], $request, $entityTypeManager, $this->eventDispatcher);
$results = $this->processor
->buildUrls($facet, $original_results);
/** @var \Drupal\facets\Result\ResultInterface $r */
foreach ($results as $k => $r) {
$this
->assertInstanceOf(ResultInterface::class, $r);
if ($k === 2) {
$this
->assertEquals('route:test?f%5B0%5D=king%3Akong', $r
->getUrl()
->toUriString());
}
else {
$this
->assertEquals('route:test?f%5B0%5D=king%3Akong&f%5B1%5D=test%3A' . $r
->getRawValue(), $r
->getUrl()
->toUriString());
}
}
}