X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Ftests%2FDrupal%2FKernelTests%2FCore%2FEntity%2FEntityTypedDataDefinitionTest.php;h=d0c01bccb5d8727121da0d42885539df5c443a3d;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=5e755d95842e30f04dbfb62b014fad7404d6d461;hpb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;p=yaffs-website diff --git a/web/core/tests/Drupal/KernelTests/Core/Entity/EntityTypedDataDefinitionTest.php b/web/core/tests/Drupal/KernelTests/Core/Entity/EntityTypedDataDefinitionTest.php index 5e755d958..d0c01bccb 100644 --- a/web/core/tests/Drupal/KernelTests/Core/Entity/EntityTypedDataDefinitionTest.php +++ b/web/core/tests/Drupal/KernelTests/Core/Entity/EntityTypedDataDefinitionTest.php @@ -2,6 +2,9 @@ namespace Drupal\KernelTests\Core\Entity; +use Drupal\Core\Config\Entity\ConfigEntityInterface; +use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\TypedData\EntityDataDefinition; use Drupal\Core\Entity\TypedData\EntityDataDefinitionInterface; use Drupal\Core\Field\BaseFieldDefinition; @@ -11,6 +14,7 @@ use Drupal\Core\TypedData\DataReferenceDefinition; use Drupal\Core\TypedData\DataReferenceDefinitionInterface; use Drupal\Core\TypedData\ListDataDefinitionInterface; use Drupal\KernelTests\KernelTestBase; +use Drupal\node\Entity\NodeType; /** * Tests deriving metadata of entity and field data types. @@ -31,10 +35,11 @@ class EntityTypedDataDefinitionTest extends KernelTestBase { * * @var array */ - public static $modules = ['filter', 'text', 'node', 'user']; + public static $modules = ['system', 'filter', 'text', 'node', 'user']; protected function setUp() { parent::setup(); + $this->typedDataManager = $this->container->get('typed_data_manager'); } @@ -81,11 +86,21 @@ class EntityTypedDataDefinitionTest extends KernelTestBase { * Tests deriving metadata about entities. */ public function testEntities() { + NodeType::create([ + 'type' => 'article', + 'name' => 'Article', + ])->save(); + $entity_definition = EntityDataDefinition::create('node'); + $bundle_definition = EntityDataDefinition::create('node', 'article'); // Entities are complex data. $this->assertFalse($entity_definition instanceof ListDataDefinitionInterface); $this->assertTrue($entity_definition instanceof ComplexDataDefinitionInterface); + // Entity definitions should inherit their labels from the entity type. + $this->assertEquals('Content', $entity_definition->getLabel()); + $this->assertEquals('Article', $bundle_definition->getLabel()); + $field_definitions = $entity_definition->getPropertyDefinitions(); // Comparison should ignore the internal static cache, so compare the // serialized objects instead. @@ -126,4 +141,37 @@ class EntityTypedDataDefinitionTest extends KernelTestBase { $this->assertEqual(serialize($reference_definition2), serialize($reference_definition)); } + /** + * Tests that an entity annotation can mark the data definition as internal. + * + * @dataProvider entityDefinitionIsInternalProvider + */ + public function testEntityDefinitionIsInternal($internal, $expected) { + $entity_type_id = $this->randomMachineName(); + + $entity_type = $this->prophesize(EntityTypeInterface::class); + $entity_type->entityClassImplements(ConfigEntityInterface::class)->willReturn(FALSE); + $entity_type->getLabel()->willReturn($this->randomString()); + $entity_type->getConstraints()->willReturn([]); + $entity_type->isInternal()->willReturn($internal); + + $entity_manager = $this->prophesize(EntityManagerInterface::class); + $entity_manager->getDefinitions()->willReturn([$entity_type_id => $entity_type->reveal()]); + $this->container->set('entity.manager', $entity_manager->reveal()); + + $entity_data_definition = EntityDataDefinition::create($entity_type_id); + $this->assertSame($expected, $entity_data_definition->isInternal()); + } + + /** + * Provides test cases for testEntityDefinitionIsInternal. + */ + public function entityDefinitionIsInternalProvider() { + return [ + 'internal' => [TRUE, TRUE], + 'external' => [FALSE, FALSE], + 'undefined' => [NULL, FALSE], + ]; + } + }