class ContextMapperTest in Page Manager 8
Same name and namespace in other branches
- 8.4 tests/src/Unit/ContextMapperTest.php \Drupal\Tests\page_manager\Unit\ContextMapperTest
@coversDefaultClass \Drupal\page_manager\ContextMapper
@group PageManager
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\page_manager\Unit\ContextMapperTest
Expanded class hierarchy of ContextMapperTest
File
- tests/
src/ Unit/ ContextMapperTest.php, line 26 - Contains \Drupal\Tests\page_manager\Unit\ContextMapperTest.
Namespace
Drupal\Tests\page_manager\UnitView source
class ContextMapperTest extends UnitTestCase {
/**
* The typed data manager.
*
* @var \Drupal\Core\TypedData\TypedDataManager|\Prophecy\Prophecy\ProphecyInterface
*/
protected $typedDataManager;
/**
* @var \Drupal\Core\Entity\EntityRepositoryInterface|\Prophecy\Prophecy\ProphecyInterface
*/
protected $entityRepository;
/**
* @var \Drupal\page_manager\ContextMapper
*/
protected $staticContext;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->typedDataManager = $this
->prophesize(TypedDataManager::class);
$this->entityRepository = $this
->prophesize(EntityRepositoryInterface::class);
$this->staticContext = new ContextMapper($this->entityRepository
->reveal());
$container = new ContainerBuilder();
$container
->set('typed_data_manager', $this->typedDataManager
->reveal());
\Drupal::setContainer($container);
}
/**
* @covers ::getContextValues
*/
public function testGetContextValues() {
$input = [];
$actual = $this->staticContext
->getContextValues($input);
$this
->assertEquals([], $actual);
}
/**
* @covers ::getContextValues
*/
public function testGetContextValuesContext() {
$data_definition = DataDefinition::createFromDataType('integer');
$typed_data = IntegerData::createInstance($data_definition);
$this->typedDataManager
->createDataDefinition('integer')
->willReturn($data_definition);
$this->typedDataManager
->getDefaultConstraints($data_definition)
->willReturn([]);
$this->typedDataManager
->create($data_definition, 5)
->willReturn($typed_data);
$input = [
'foo' => [
'label' => 'Foo',
'type' => 'integer',
'value' => 5,
],
];
$expected = new Context(new ContextDefinition('integer', 'Foo'), 5);
$actual = $this->staticContext
->getContextValues($input)['foo'];
$this
->assertEquals($expected, $actual);
}
/**
* @covers ::getContextValues
*/
public function testGetContextValuesEntityContext() {
$input = [
'foo' => [
'label' => 'Foo',
'type' => 'entity:node',
'value' => 'the_node_uuid',
],
];
$expected = new EntityLazyLoadContext(new ContextDefinition('entity:node', 'Foo'), $this->entityRepository
->reveal(), 'the_node_uuid');
$actual = $this->staticContext
->getContextValues($input)['foo'];
$this
->assertEquals($expected, $actual);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContextMapperTest:: |
protected | property | ||
ContextMapperTest:: |
protected | property | ||
ContextMapperTest:: |
protected | property | The typed data manager. | |
ContextMapperTest:: |
protected | function |
Overrides UnitTestCase:: |
|
ContextMapperTest:: |
public | function | @covers ::getContextValues | |
ContextMapperTest:: |
public | function | @covers ::getContextValues | |
ContextMapperTest:: |
public | function | @covers ::getContextValues | |
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. |