class ContextMapperTest
Same name in other branches
- 4.0.x tests/src/Unit/ContextMapperTest.php \Drupal\Tests\ctools\Unit\ContextMapperTest
@coversDefaultClass \Drupal\ctools\ContextMapper
@group CTools
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait
- class \Drupal\Tests\ctools\Unit\ContextMapperTest extends \Drupal\Tests\UnitTestCase uses \Prophecy\PhpUnit\ProphecyTrait
Expanded class hierarchy of ContextMapperTest
File
-
tests/
src/ Unit/ ContextMapperTest.php, line 23
Namespace
Drupal\Tests\ctools\UnitView source
class ContextMapperTest extends UnitTestCase {
use ProphecyTrait;
/**
* 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() : void {
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',
'description' => NULL,
'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',
'description' => NULL,
'type' => 'entity:node',
'value' => 'the_node_uuid',
],
];
$expected = new EntityLazyLoadContext(new EntityContextDefinition('entity:node', 'Foo'), $this->entityRepository
->reveal(), 'the_node_uuid');
$actual = $this->staticContext
->getContextValues($input)['foo'];
$this->assertEquals($expected, $actual);
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|---|
ContextMapperTest::$entityRepository | protected | property | ||||
ContextMapperTest::$staticContext | protected | property | ||||
ContextMapperTest::$typedDataManager | protected | property | The typed data manager. | |||
ContextMapperTest::setUp | protected | function | Overrides UnitTestCase::setUp | |||
ContextMapperTest::testGetContextValues | public | function | @covers ::getContextValues | |||
ContextMapperTest::testGetContextValuesContext | public | function | @covers ::getContextValues | |||
ContextMapperTest::testGetContextValuesEntityContext | public | function | @covers ::getContextValues | |||
PhpUnitWarnings::$deprecationWarnings | private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |||
PhpUnitWarnings::addWarning | public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |||
UnitTestCase::$randomGenerator | protected | property | The random generator. | |||
UnitTestCase::$root | protected | property | The app root. | 1 | ||
UnitTestCase::assertArrayEquals | Deprecated | protected | function | Asserts if two arrays are equal by sorting them first. | ||
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |||
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |||
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |||
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |||
UnitTestCase::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |||
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |||
UnitTestCase::randomMachineName | public | function | Generates a unique random string containing letters and numbers. | |||
UnitTestCase::setUpBeforeClass | public static | function |