public function ArrayPluginDefinitionDecoratorTest::testGetContextDefinitions in Plugin 8.2
@covers ::setContextDefinitions @covers ::getContextDefinitions @covers ::offsetExists @covers ::offsetSet @covers ::offsetGet @covers ::offsetUnset
File
- tests/
src/ Unit/ PluginDefinition/ ArrayPluginDefinitionDecoratorTest.php, line 259
Class
- ArrayPluginDefinitionDecoratorTest
- @coversDefaultClass \Drupal\plugin\PluginDefinition\ArrayPluginDefinitionDecorator
Namespace
Drupal\Tests\plugin\Unit\PluginDefinitionCode
public function testGetContextDefinitions() {
// Test the injected value.
$this
->assertSame($this->arrayDefinition['context'], $this->sut
->getContextDefinitions());
$this
->assertSame($this->arrayDefinition['context'], $this->sut
->getArrayDefinition()['context']);
$this
->assertSame($this->arrayDefinition['context'], $this->sut['context']);
// Test changing the value through the setter.
$context_definition_name_a = $this
->randomMachineName();
$context_definition_a = $this
->createMock(ContextDefinitionInterface::class);
$context_definition_name_b = $this
->randomMachineName();
$context_definition_b = $this
->createMock(ContextDefinitionInterface::class);
$value = [
$context_definition_name_a => $context_definition_a,
$context_definition_name_b => $context_definition_b,
];
$this
->assertSame($this->sut, $this->sut
->setContextDefinitions($value));
$this
->assertSame($value, $this->sut
->getContextDefinitions());
$this
->assertSame($value, $this->sut
->getArrayDefinition()['context']);
$this
->assertSame($value, $this->sut['context']);
// Test changing the value through array access.
$context_definition_name_a = $this
->randomMachineName();
$context_definition_a = $this
->createMock(ContextDefinitionInterface::class);
$context_definition_name_b = $this
->randomMachineName();
$context_definition_b = $this
->createMock(ContextDefinitionInterface::class);
$value = [
$context_definition_name_a => $context_definition_a,
$context_definition_name_b => $context_definition_b,
];
$this->sut['context'] = $value;
$this
->assertSame($value, $this->sut
->getContextDefinitions());
$this
->assertSame($value, $this->sut
->getArrayDefinition()['context']);
$this
->assertSame($value, $this->sut['context']);
// Test unsetting the value.
unset($this->sut['context']);
$this
->assertFalse(isset($this->sut['context']));
$this
->assertSame([], $this->sut
->getContextDefinitions());
$this
->assertFalse(isset($this->sut
->getArrayDefinition()['context']));
}