function EntityContextDefinitionDeprecationTest::testSerialization

Test that the BC layer survives serialization and unserialization.

@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 81

Class

EntityContextDefinitionDeprecationTest
Test deprecated use of ContextDefinition as an EntityContextDefinition.

Namespace

Drupal\Tests\Core\Plugin\Context

Code

public function testSerialization() {
  $this->definition
    ->addConstraint('foo');
  $definition = unserialize(serialize($this->definition));
  $this->assertEquals([
    'foo' => NULL,
  ], $definition->getConstraints());
  $bc_layer = $this->compatibilityLayer
    ->getValue($definition);
  $this->assertInstanceOf(EntityContextDefinition::class, $bc_layer);
}

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