public function PageTest::testFilterParameters in Page Manager 8
Same name and namespace in other branches
- 8.4 tests/src/Unit/PageTest.php \Drupal\Tests\page_manager\Unit\PageTest::testFilterParameters()
@covers ::filterParameters
File
- tests/
src/ Unit/ PageTest.php, line 206 - Contains \Drupal\Tests\page_manager\Unit\PageTest.
Class
- PageTest
- Tests the Page entity.
Namespace
Drupal\Tests\page_manager\UnitCode
public function testFilterParameters() {
// Changing filters clears cached contexts on variants so we have to setup
// some variants for our page.
$variant1 = $this
->prophesize(PageVariantInterface::class);
$variant1
->id()
->willReturn('variant1');
$variant1
->getWeight()
->willReturn(0);
$variant1
->resetCollectedContexts()
->willReturn($variant1
->reveal());
$variant2 = $this
->prophesize(PageVariantInterface::class);
$variant2
->id()
->willReturn('variant2');
$variant2
->getWeight()
->willReturn(-10);
$variant2
->resetCollectedContexts()
->willReturn($variant2
->reveal());
$entity_storage = $this
->prophesize(EntityStorageInterface::class);
$entity_storage
->loadByProperties([
'page' => 'the_page',
])
->willReturn([
'variant1' => $variant1
->reveal(),
'variant2' => $variant2
->reveal(),
])
->shouldBeCalledTimes(1);
$entity_type_manager = $this
->prophesize(EntityTypeManagerInterface::class);
$entity_type_manager
->getStorage('page_variant')
->willReturn($entity_storage);
$container = new ContainerBuilder();
$container
->set('entity_type.manager', $entity_type_manager
->reveal());
\Drupal::setContainer($container);
$parameters = [
'foo' => [
'machine_name' => 'foo',
'type' => 'integer',
'label' => 'Foo',
],
'bar' => [
'machine_name' => 'bar',
'type' => '',
'label' => '',
],
'baz' => [
'machine_name' => 'baz',
'type' => 'integer',
'label' => 'Baz',
],
];
$page = new Page([
'id' => 'the_page',
'parameters' => $parameters,
'path' => 'test/{foo}/{bar}',
], 'page');
$expected = $parameters;
unset($expected['baz']);
$this
->assertEquals($expected, $page
->getParameters());
$method = new \ReflectionMethod($page, 'filterParameters');
$method
->setAccessible(TRUE);
$method
->invoke($page);
$expected = [
'foo' => [
'machine_name' => 'foo',
'type' => 'integer',
'label' => 'Foo',
],
];
$this
->assertEquals($expected, $page
->get('parameters'));
}