Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\rdf\Unit;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\DependencyInjection\ContainerBuilder;
|
Chris@14
|
6 use Drupal\Core\Entity\EntityManager;
|
Chris@14
|
7 use Drupal\Core\Entity\EntityTypeManagerInterface;
|
Chris@0
|
8 use Drupal\Tests\UnitTestCase;
|
Chris@0
|
9 use Drupal\rdf\Entity\RdfMapping;
|
Chris@0
|
10
|
Chris@0
|
11 /**
|
Chris@0
|
12 * @coversDefaultClass \Drupal\rdf\Entity\RdfMapping
|
Chris@0
|
13 * @group rdf
|
Chris@0
|
14 */
|
Chris@0
|
15 class RdfMappingConfigEntityUnitTest extends UnitTestCase {
|
Chris@0
|
16
|
Chris@0
|
17 /**
|
Chris@0
|
18 * The entity type used for testing.
|
Chris@0
|
19 *
|
Chris@0
|
20 * @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject
|
Chris@0
|
21 */
|
Chris@0
|
22 protected $entityType;
|
Chris@0
|
23
|
Chris@0
|
24 /**
|
Chris@0
|
25 * The entity manager used for testing.
|
Chris@0
|
26 *
|
Chris@0
|
27 * @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
Chris@0
|
28 */
|
Chris@0
|
29 protected $entityManager;
|
Chris@0
|
30
|
Chris@0
|
31 /**
|
Chris@14
|
32 * The entity type manager used for testing.
|
Chris@14
|
33 *
|
Chris@14
|
34 * @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
Chris@14
|
35 */
|
Chris@14
|
36 protected $entityTypeManager;
|
Chris@14
|
37
|
Chris@14
|
38 /**
|
Chris@0
|
39 * The ID of the type of the entity under test.
|
Chris@0
|
40 *
|
Chris@0
|
41 * @var string
|
Chris@0
|
42 */
|
Chris@0
|
43 protected $entityTypeId;
|
Chris@0
|
44
|
Chris@0
|
45 /**
|
Chris@0
|
46 * The UUID generator used for testing.
|
Chris@0
|
47 *
|
Chris@0
|
48 * @var \Drupal\Component\Uuid\UuidInterface|\PHPUnit_Framework_MockObject_MockObject
|
Chris@0
|
49 */
|
Chris@0
|
50 protected $uuid;
|
Chris@0
|
51
|
Chris@0
|
52 /**
|
Chris@0
|
53 * {@inheritdoc}
|
Chris@0
|
54 */
|
Chris@0
|
55 protected function setUp() {
|
Chris@0
|
56 $this->entityTypeId = $this->randomMachineName();
|
Chris@0
|
57
|
Chris@0
|
58 $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
|
Chris@0
|
59 $this->entityType->expects($this->any())
|
Chris@0
|
60 ->method('getProvider')
|
Chris@0
|
61 ->will($this->returnValue('entity'));
|
Chris@0
|
62
|
Chris@14
|
63 $this->entityManager = new EntityManager();
|
Chris@14
|
64 $this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
|
Chris@0
|
65
|
Chris@0
|
66 $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
|
Chris@0
|
67
|
Chris@0
|
68 $container = new ContainerBuilder();
|
Chris@0
|
69 $container->set('entity.manager', $this->entityManager);
|
Chris@14
|
70 $container->set('entity_type.manager', $this->entityTypeManager);
|
Chris@0
|
71 $container->set('uuid', $this->uuid);
|
Chris@14
|
72 $this->entityManager->setContainer($container);
|
Chris@0
|
73 \Drupal::setContainer($container);
|
Chris@0
|
74
|
Chris@0
|
75 }
|
Chris@0
|
76
|
Chris@0
|
77 /**
|
Chris@0
|
78 * @covers ::calculateDependencies
|
Chris@0
|
79 */
|
Chris@0
|
80 public function testCalculateDependencies() {
|
Chris@0
|
81 $target_entity_type_id = $this->randomMachineName(16);
|
Chris@0
|
82
|
Chris@0
|
83 $target_entity_type = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
|
Chris@0
|
84 $target_entity_type->expects($this->any())
|
Chris@0
|
85 ->method('getProvider')
|
Chris@0
|
86 ->will($this->returnValue('test_module'));
|
Chris@0
|
87 $values = ['targetEntityType' => $target_entity_type_id];
|
Chris@0
|
88 $target_entity_type->expects($this->any())
|
Chris@0
|
89 ->method('getBundleEntityType')
|
Chris@0
|
90 ->will($this->returnValue(NULL));
|
Chris@0
|
91
|
Chris@14
|
92 $this->entityTypeManager->expects($this->at(0))
|
Chris@0
|
93 ->method('getDefinition')
|
Chris@0
|
94 ->with($target_entity_type_id)
|
Chris@0
|
95 ->will($this->returnValue($target_entity_type));
|
Chris@14
|
96 $this->entityTypeManager->expects($this->at(1))
|
Chris@0
|
97 ->method('getDefinition')
|
Chris@0
|
98 ->with($this->entityTypeId)
|
Chris@0
|
99 ->will($this->returnValue($this->entityType));
|
Chris@0
|
100
|
Chris@0
|
101 $entity = new RdfMapping($values, $this->entityTypeId);
|
Chris@0
|
102 $dependencies = $entity->calculateDependencies()->getDependencies();
|
Chris@0
|
103 $this->assertArrayNotHasKey('config', $dependencies);
|
Chris@0
|
104 $this->assertContains('test_module', $dependencies['module']);
|
Chris@0
|
105 }
|
Chris@0
|
106
|
Chris@0
|
107 /**
|
Chris@0
|
108 * @covers ::calculateDependencies
|
Chris@0
|
109 */
|
Chris@0
|
110 public function testCalculateDependenciesWithEntityBundle() {
|
Chris@0
|
111 $target_entity_type_id = $this->randomMachineName(16);
|
Chris@0
|
112 $target_entity_type = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
|
Chris@0
|
113 $target_entity_type->expects($this->any())
|
Chris@0
|
114 ->method('getProvider')
|
Chris@0
|
115 ->will($this->returnValue('test_module'));
|
Chris@0
|
116 $bundle_id = $this->randomMachineName(10);
|
Chris@0
|
117 $values = ['targetEntityType' => $target_entity_type_id , 'bundle' => $bundle_id];
|
Chris@0
|
118
|
Chris@0
|
119 $target_entity_type->expects($this->any())
|
Chris@0
|
120 ->method('getBundleConfigDependency')
|
Chris@0
|
121 ->will($this->returnValue(['type' => 'config', 'name' => 'test_module.type.' . $bundle_id]));
|
Chris@0
|
122
|
Chris@14
|
123 $this->entityTypeManager->expects($this->at(0))
|
Chris@0
|
124 ->method('getDefinition')
|
Chris@0
|
125 ->with($target_entity_type_id)
|
Chris@0
|
126 ->will($this->returnValue($target_entity_type));
|
Chris@14
|
127 $this->entityTypeManager->expects($this->at(1))
|
Chris@0
|
128 ->method('getDefinition')
|
Chris@0
|
129 ->with($this->entityTypeId)
|
Chris@0
|
130 ->will($this->returnValue($this->entityType));
|
Chris@0
|
131
|
Chris@0
|
132 $entity = new RdfMapping($values, $this->entityTypeId);
|
Chris@0
|
133 $dependencies = $entity->calculateDependencies()->getDependencies();
|
Chris@0
|
134 $this->assertContains('test_module.type.' . $bundle_id, $dependencies['config']);
|
Chris@0
|
135 $this->assertContains('test_module', $dependencies['module']);
|
Chris@0
|
136 }
|
Chris@0
|
137
|
Chris@0
|
138 }
|