class PageVariantTest in Page Manager 8
Same name and namespace in other branches
- 8.4 tests/src/Unit/PageVariantTest.php \Drupal\Tests\page_manager\Unit\PageVariantTest
@coversDefaultClass \Drupal\page_manager\Entity\PageVariant
@group PageManager
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\page_manager\Unit\PageVariantTest
Expanded class hierarchy of PageVariantTest
File
- tests/
src/ Unit/ PageVariantTest.php, line 23 - Contains \Drupal\Tests\page_manager\Unit\PageVariantTest.
Namespace
Drupal\Tests\page_manager\UnitView source
class PageVariantTest extends UnitTestCase {
/**
* @var \Drupal\page_manager\Entity\PageVariant
*/
protected $pageVariant;
/**
* @var \Drupal\page_manager\PageInterface|\Prophecy\Prophecy\ProphecyInterface
*/
protected $page;
/**
* @var \Drupal\page_manager\ContextMapperInterface|\Prophecy\Prophecy\ProphecyInterface
*/
protected $contextMapper;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->pageVariant = new PageVariant([
'id' => 'the_page_variant',
'page' => 'the_page',
], 'page_variant');
$this->page = $this
->prophesize(PageInterface::class);
$entity_storage = $this
->prophesize(EntityStorageInterface::class);
$entity_storage
->load('the_page')
->willReturn($this->page
->reveal());
$entity_type_manager = $this
->prophesize(EntityTypeManagerInterface::class);
$entity_type_manager
->getStorage('page')
->willReturn($entity_storage);
$this->contextMapper = $this
->prophesize(ContextMapperInterface::class);
$container = new ContainerBuilder();
$container
->set('entity_type.manager', $entity_type_manager
->reveal());
$container
->set('page_manager.context_mapper', $this->contextMapper
->reveal());
\Drupal::setContainer($container);
}
/**
* @covers ::getContexts
* @dataProvider providerTestGetContexts
*/
public function testGetContexts($static_contexts, $page_contexts, $expected) {
$this->contextMapper
->getContextValues([])
->willReturn($static_contexts)
->shouldBeCalledTimes(1);
$this->page
->getContexts()
->willReturn($page_contexts)
->shouldBeCalledTimes(1);
$contexts = $this->pageVariant
->getContexts();
$this
->assertSame($expected, $contexts);
$contexts = $this->pageVariant
->getContexts();
$this
->assertSame($expected, $contexts);
}
public function providerTestGetContexts() {
$data = [];
$data['empty'] = [
[],
[],
[],
];
$data['additive'] = [
[
'static' => 'static',
],
[
'page' => 'page',
],
[
'page' => 'page',
'static' => 'static',
],
];
$data['conflicting'] = [
[
'foo' => 'static',
],
[
'foo' => 'page',
],
[
'foo' => 'page',
],
];
return $data;
}
/**
* @covers ::getContexts
* @covers ::removeStaticContext
*/
public function testGetContextsAfterReset() {
$this->contextMapper
->getContextValues([])
->willReturn([])
->shouldBeCalledTimes(2);
$this->page
->getContexts()
->willReturn([])
->shouldBeCalledTimes(2);
$expected = [];
$contexts = $this->pageVariant
->getContexts();
$this
->assertSame($expected, $contexts);
$this->pageVariant
->removeStaticContext('anything');
$contexts = $this->pageVariant
->getContexts();
$this
->assertSame($expected, $contexts);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PageVariantTest:: |
protected | property | ||
PageVariantTest:: |
protected | property | ||
PageVariantTest:: |
protected | property | ||
PageVariantTest:: |
public | function | ||
PageVariantTest:: |
protected | function |
Overrides UnitTestCase:: |
|
PageVariantTest:: |
public | function | @covers ::getContexts @dataProvider providerTestGetContexts | |
PageVariantTest:: |
public | function | @covers ::getContexts @covers ::removeStaticContext | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |