class ContextAwarePluginBaseTest
Same name and namespace in other branches
- 8.9.x core/tests/Drupal/KernelTests/Core/Plugin/Context/ContextAwarePluginBaseTest.php \Drupal\KernelTests\Core\Plugin\Context\ContextAwarePluginBaseTest
@coversDefaultClass \Drupal\Core\Plugin\ContextAwarePluginBase
@group Plugin @group legacy
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Core\Plugin\Context\ContextAwarePluginBaseTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of ContextAwarePluginBaseTest
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Plugin/ Context/ ContextAwarePluginBaseTest.php, line 23
Namespace
Drupal\KernelTests\Core\Plugin\ContextView source
class ContextAwarePluginBaseTest extends KernelTestBase {
/**
* The plugin instance under test.
*
* @var \Drupal\Core\Plugin\ContextAwarePluginBase
*/
private $plugin;
/**
* {@inheritdoc}
*/
public function setUp() : void {
parent::setUp();
$configuration = [
'context' => [
'nato_letter' => 'Alpha',
],
];
$plugin_definition = new TestPluginDefinition();
$plugin_definition->addContextDefinition('nato_letter', ContextDefinition::create('string'));
$this->plugin = $this->getMockBuilder(ContextAwarePluginBase::class)
->setConstructorArgs([
$configuration,
'the_sisko',
$plugin_definition,
])
->onlyMethods([
'setContext',
])
->getMockForAbstractClass();
}
/**
* @covers ::getContextDefinitions
*/
public function testGetContextDefinitions() {
$this->assertIsArray($this->plugin
->getContextDefinitions());
}
/**
* @covers ::getContextDefinition
*/
public function testGetContextDefinition() {
// The context is not defined, so an exception will be thrown.
$this->expectException(ContextException::class);
$this->expectExceptionMessage('The person context is not a valid context.');
$this->plugin
->getContextDefinition('person');
}
/**
* @covers ::getContextValue
*/
public function testGetContextValue() {
// Assert that the context value passed in the plugin configuration is
// available.
$this->assertSame('Alpha', $this->plugin
->getContextValue('nato_letter'));
}
/**
* @covers ::setContextValue
*/
public function testSetContextValue() {
$typed_data_manager = $this->prophesize(TypedDataManagerInterface::class);
$container = new ContainerBuilder();
$container->set('typed_data_manager', $typed_data_manager->reveal());
\Drupal::setContainer($container);
$this->plugin
->getPluginDefinition()
->addContextDefinition('foo', new ContextDefinition('string'));
$this->plugin
->expects($this->exactly(1))
->method('setContext');
$this->plugin
->setContextValue('foo', new StringData(new DataDefinition(), 'bar'));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.