comparison core/modules/rdf/tests/src/Unit/RdfMappingConfigEntityUnitTest.php @ 0:4c8ae668cc8c

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