You are here

public function EntityContextDefinitionDeprecationTest::testGetConstraints in Drupal 8

Test that getConstraints() proxies to the compatibility layer.

@covers ::getConstraints @expectedDeprecation Constructing a ContextDefinition object for an entity type is deprecated in Drupal 8.6.0. Use Drupal\Core\Plugin\Context\EntityContextDefinition instead. See https://www.drupal.org/node/2976400 for more information.

File

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

Class

EntityContextDefinitionDeprecationTest
Test deprecated use of ContextDefinition as an EntityContextDefinition.

Namespace

Drupal\Tests\Core\Plugin\Context

Code

public function testGetConstraints() {
  $bc_mock = $this
    ->getMockBuilder(EntityContextDefinition::class)
    ->setMethods([
    'getConstraints',
  ])
    ->getMock();
  $constraints = [
    'test_constraint',
  ];
  $bc_mock
    ->expects($this
    ->once())
    ->method('getConstraints')
    ->willReturn($constraints);
  $this->compatibilityLayer
    ->setValue($this->definition, $bc_mock);
  $this
    ->assertSame($constraints, $this->definition
    ->getConstraints());
}