function EntityContextDefinitionDeprecationTest::setUp

Overrides UnitTestCase::setUp

File

core/tests/Drupal/Tests/Core/Plugin/Context/EntityContextDefinitionDeprecationTest.php, line 44

Class

EntityContextDefinitionDeprecationTest
Test deprecated use of ContextDefinition as an EntityContextDefinition.

Namespace

Drupal\Tests\Core\Plugin\Context

Code

protected function setUp() {
    parent::setUp();
    // Mock container services needed for constraint validation.
    $constraint_manager = $this->prophesize(ConstraintManager::class);
    $constraint_manager->create(Argument::type('string'), Argument::any())
        ->willReturn(TRUE);
    $typed_data_manager = $this->prophesize(TypedDataManagerInterface::class);
    $typed_data_manager->getValidationConstraintManager()
        ->willReturn($constraint_manager->reveal());
    $validator = $this->prophesize(ValidatorInterface::class)
        ->reveal();
    $typed_data_manager->getValidator()
        ->willReturn($validator);
    $container = new ContainerBuilder();
    $container->set('typed_data_manager', $typed_data_manager->reveal());
    \Drupal::setContainer($container);
    // Create a deprecated entity context definition and prepare the
    // compatibility layer to be overridden.
    $this->definition = new ContextDefinition('entity:node');
    // The code paths we're testing are private and protected, so use reflection
    // to manipulate protected properties.
    $reflector = new \ReflectionObject($this->definition);
    // Ensure that the BC object was created correctly.
    $this->assertTrue($reflector->hasProperty('entityContextDefinition'));
    $this->compatibilityLayer = $reflector->getProperty('entityContextDefinition');
    $this->compatibilityLayer
        ->setAccessible(TRUE);
    $this->assertInstanceOf(EntityContextDefinition::class, $this->compatibilityLayer
        ->getValue($this->definition));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.