function TypedDataDefinitionTest::testMaps

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/TypedData/TypedDataDefinitionTest.php \Drupal\KernelTests\Core\TypedData\TypedDataDefinitionTest::testMaps()
  2. 10 core/tests/Drupal/KernelTests/Core/TypedData/TypedDataDefinitionTest.php \Drupal\KernelTests\Core\TypedData\TypedDataDefinitionTest::testMaps()
  3. 11.x core/tests/Drupal/KernelTests/Core/TypedData/TypedDataDefinitionTest.php \Drupal\KernelTests\Core\TypedData\TypedDataDefinitionTest::testMaps()

Tests deriving metadata about maps.

File

core/tests/Drupal/KernelTests/Core/TypedData/TypedDataDefinitionTest.php, line 63

Class

TypedDataDefinitionTest
Tests deriving metadata of core data types.

Namespace

Drupal\KernelTests\Core\TypedData

Code

public function testMaps() {
    $map_definition = MapDataDefinition::create()->setPropertyDefinition('one', DataDefinition::create('string'))
        ->setPropertyDefinition('two', DataDefinition::create('string'))
        ->setPropertyDefinition('three', DataDefinition::create('string'));
    $this->assertInstanceOf(ComplexDataDefinitionInterface::class, $map_definition);
    // Test retrieving metadata about contained properties.
    $this->assertEquals([
        'one',
        'two',
        'three',
    ], array_keys($map_definition->getPropertyDefinitions()));
    $this->assertEquals('string', $map_definition->getPropertyDefinition('one')
        ->getDataType());
    $this->assertNull($map_definition->getMainPropertyName());
    $this->assertNull($map_definition->getPropertyDefinition('invalid'));
    // Test using the definition factory.
    $map_definition2 = $this->typedDataManager
        ->createDataDefinition('map');
    $this->assertInstanceOf(ComplexDataDefinitionInterface::class, $map_definition2);
    $map_definition2->setPropertyDefinition('one', DataDefinition::create('string'))
        ->setPropertyDefinition('two', DataDefinition::create('string'))
        ->setPropertyDefinition('three', DataDefinition::create('string'));
    $this->assertEquals(serialize($map_definition2), serialize($map_definition));
}

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