function TypedDataDefinitionTest::testLists
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/TypedData/TypedDataDefinitionTest.php \Drupal\KernelTests\Core\TypedData\TypedDataDefinitionTest::testLists()
- 8.9.x core/tests/Drupal/KernelTests/Core/TypedData/TypedDataDefinitionTest.php \Drupal\KernelTests\Core\TypedData\TypedDataDefinitionTest::testLists()
- 10 core/tests/Drupal/KernelTests/Core/TypedData/TypedDataDefinitionTest.php \Drupal\KernelTests\Core\TypedData\TypedDataDefinitionTest::testLists()
Tests deriving metadata about list items.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ TypedData/ TypedDataDefinitionTest.php, line 43
Class
- TypedDataDefinitionTest
- Tests deriving metadata of core data types.
Namespace
Drupal\KernelTests\Core\TypedDataCode
public function testLists() : void {
$list_definition = ListDataDefinition::create('string');
$this->assertInstanceOf(ListDataDefinitionInterface::class, $list_definition);
$item_definition = $list_definition->getItemDefinition();
$this->assertInstanceOf(DataDefinitionInterface::class, $item_definition);
$this->assertEquals('string', $item_definition->getDataType());
// Test using the definition factory.
$list_definition2 = $this->typedDataManager
->createListDataDefinition('string');
$this->assertInstanceOf(ListDataDefinitionInterface::class, $list_definition2);
$this->assertEquals($list_definition, $list_definition2);
// Test creating the definition of data with type 'list', which is the same
// as creating a definition of a list of items of type 'any'.
$list_definition = $this->typedDataManager
->createDataDefinition('list');
$this->assertInstanceOf(ListDataDefinitionInterface::class, $list_definition);
$this->assertEquals('list', $list_definition->getDataType());
$this->assertEquals('any', $list_definition->getItemDefinition()
->getDataType());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.