comparison core/modules/field/tests/src/Kernel/ConfigFieldDefinitionTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\Tests\field\Kernel;
4
5 use Drupal\Core\Field\FieldDefinitionInterface;
6 use Drupal\Core\Field\FieldStorageDefinitionInterface;
7
8 /**
9 * Tests exposing field definitions for configurable fields.
10 *
11 * @group field
12 */
13 class ConfigFieldDefinitionTest extends FieldKernelTestBase {
14
15 /**
16 * The entity manager service.
17 *
18 * @var \Drupal\Core\Entity\EntityManagerInterface;
19 */
20 protected $entityManager;
21
22 /**
23 * @var string
24 */
25 private $entityType;
26
27 /**
28 * @var string
29 */
30 private $bundle;
31
32 /**
33 * {@inheritdoc}
34 */
35 protected function setUp() {
36 parent::setUp();
37
38 // Create a field and a storage of type 'test_field', on the 'entity_test'
39 // entity type.
40 $this->entityType = 'entity_test';
41 $this->bundle = 'entity_test';
42 $this->createFieldWithStorage('', $this->entityType, $this->bundle);
43 $this->entityManager = $this->container->get('entity.manager');
44
45 // Create a second field on 'entity_test_rev'.
46 $this->createFieldWithStorage('_rev', 'entity_test_rev', 'entity_test_rev');
47 }
48
49 /**
50 * Makes sure a field definition is exposed for a configurable field.
51 */
52 public function testBundleFieldDefinition() {
53 $definitions = $this->entityManager->getFieldDefinitions($this->entityType, $this->bundle);
54 $this->assertTrue(isset($definitions[$this->fieldTestData->field->getName()]));
55 $this->assertTrue($definitions[$this->fieldTestData->field->getName()] instanceof FieldDefinitionInterface);
56 // Make sure fields on other entity types are not exposed.
57 $this->assertFalse(isset($definitions[$this->fieldTestData->field_rev->getName()]));
58 }
59
60 /**
61 * Makes sure a field storage definition is exposed for a configurable field.
62 */
63 public function testFieldStorageDefinition() {
64 $field_storage_definitions = $this->entityManager->getFieldStorageDefinitions($this->entityType);
65 $this->assertTrue(isset($field_storage_definitions[$this->fieldTestData->field->getName()]));
66 $this->assertTrue($field_storage_definitions[$this->fieldTestData->field->getName()] instanceof FieldStorageDefinitionInterface);
67 // Make sure storages on other entity types are not exposed.
68 $this->assertFalse(isset($field_storage_definitions[$this->fieldTestData->field_rev->getName()]));
69 }
70
71 }