1 | <?php |
||
22 | class PoolTest extends TestCase |
||
23 | { |
||
24 | /** |
||
25 | * @var Pool |
||
26 | */ |
||
27 | private $pool = null; |
||
28 | |||
29 | public function setUp(): void |
||
30 | { |
||
31 | $this->pool = new Pool($this->getContainer(), 'Sonata Admin', '/path/to/pic.png', ['foo' => 'bar']); |
||
32 | } |
||
33 | |||
34 | public function testGetGroups(): void |
||
35 | { |
||
36 | $this->pool->setAdminServiceIds(['sonata.user.admin.group1']); |
||
37 | |||
38 | $this->pool->setAdminGroups([ |
||
39 | 'adminGroup1' => ['sonata.user.admin.group1' => []], |
||
40 | ]); |
||
41 | |||
42 | $expectedOutput = [ |
||
43 | 'adminGroup1' => [ |
||
44 | 'sonata.user.admin.group1' => 'sonata_user_admin_group1_AdminClass', |
||
45 | ], |
||
46 | ]; |
||
47 | |||
48 | $this->assertSame($expectedOutput, $this->pool->getGroups()); |
||
49 | } |
||
50 | |||
51 | public function testHasGroup(): void |
||
52 | { |
||
53 | $this->pool->setAdminGroups([ |
||
54 | 'adminGroup1' => [], |
||
55 | ]); |
||
56 | |||
57 | $this->assertTrue($this->pool->hasGroup('adminGroup1')); |
||
58 | $this->assertFalse($this->pool->hasGroup('adminGroup2')); |
||
59 | } |
||
60 | |||
61 | public function testGetDashboardGroups(): void |
||
62 | { |
||
63 | $admin_group1 = $this->createMock(AdminInterface::class); |
||
64 | $admin_group1->expects($this->once())->method('showIn')->will($this->returnValue(true)); |
||
65 | |||
66 | $admin_group2 = $this->createMock(AdminInterface::class); |
||
67 | $admin_group2->expects($this->once())->method('showIn')->will($this->returnValue(false)); |
||
68 | |||
69 | $admin_group3 = $this->createMock(AdminInterface::class); |
||
70 | $admin_group3->expects($this->once())->method('showIn')->will($this->returnValue(false)); |
||
71 | |||
72 | $container = $this->createMock(ContainerInterface::class); |
||
73 | |||
74 | $container->expects($this->any())->method('get')->will($this->onConsecutiveCalls( |
||
75 | $admin_group1, $admin_group2, $admin_group3 |
||
76 | )); |
||
77 | |||
78 | $pool = new Pool($container, 'Sonata Admin', '/path/to/pic.png'); |
||
79 | $pool->setAdminServiceIds(['sonata.user.admin.group1', 'sonata.user.admin.group2', 'sonata.user.admin.group3']); |
||
80 | |||
81 | $pool->setAdminGroups([ |
||
82 | 'adminGroup1' => [ |
||
83 | 'items' => ['itemKey' => $this->getItemArray('sonata.user.admin.group1')], |
||
84 | ], |
||
85 | 'adminGroup2' => [ |
||
86 | 'items' => ['itemKey' => $this->getItemArray('sonata.user.admin.group2')], |
||
87 | ], |
||
88 | 'adminGroup3' => [ |
||
89 | 'items' => ['itemKey' => $this->getItemArray('sonata.user.admin.group3')], |
||
90 | ], |
||
91 | ]); |
||
92 | |||
93 | $groups = $pool->getDashboardGroups(); |
||
94 | |||
95 | $this->assertCount(1, $groups); |
||
96 | $this->assertSame($admin_group1, $groups['adminGroup1']['items']['itemKey']); |
||
97 | } |
||
98 | |||
99 | public function testGetAdminsByGroupWhenGroupNotSet(): void |
||
100 | { |
||
101 | $this->expectException(\InvalidArgumentException::class); |
||
102 | |||
103 | $this->pool->setAdminGroups([ |
||
104 | 'adminGroup1' => [], |
||
105 | ]); |
||
106 | |||
107 | $this->pool->getAdminsByGroup('adminGroup2'); |
||
108 | } |
||
109 | |||
110 | public function testGetAdminsByGroupWhenGroupIsEmpty(): void |
||
111 | { |
||
112 | $this->pool->setAdminGroups([ |
||
113 | 'adminGroup1' => [], |
||
114 | ]); |
||
115 | |||
116 | $this->assertSame([], $this->pool->getAdminsByGroup('adminGroup1')); |
||
117 | } |
||
118 | |||
119 | public function testGetAdminsByGroup(): void |
||
120 | { |
||
121 | $this->pool->setAdminServiceIds(['sonata.admin1', 'sonata.admin2', 'sonata.admin3']); |
||
122 | $this->pool->setAdminGroups([ |
||
123 | 'adminGroup1' => [ |
||
124 | 'items' => [ |
||
125 | $this->getItemArray('sonata.admin1'), |
||
126 | $this->getItemArray('sonata.admin2'), |
||
127 | ], |
||
128 | ], |
||
129 | 'adminGroup2' => [ |
||
130 | 'items' => [$this->getItemArray('sonata.admin3')], |
||
131 | ], |
||
132 | ]); |
||
133 | |||
134 | $this->assertEquals([ |
||
135 | 'sonata_admin1_AdminClass', |
||
136 | 'sonata_admin2_AdminClass', |
||
137 | ], $this->pool->getAdminsByGroup('adminGroup1')); |
||
138 | $this->assertEquals(['sonata_admin3_AdminClass'], $this->pool->getAdminsByGroup('adminGroup2')); |
||
139 | } |
||
140 | |||
141 | public function testGetAdminForClassWhenAdminClassIsNotSet(): void |
||
142 | { |
||
143 | $this->pool->setAdminClasses(['someclass' => 'sonata.user.admin.group1']); |
||
144 | $this->assertFalse($this->pool->hasAdminByClass('notexists')); |
||
145 | $this->assertNull($this->pool->getAdminByClass('notexists')); |
||
146 | } |
||
147 | |||
148 | public function testGetAdminForClassWithInvalidFormat(): void |
||
149 | { |
||
150 | $this->expectException(\RuntimeException::class); |
||
151 | |||
152 | $this->pool->setAdminClasses(['someclass' => 'sonata.user.admin.group1']); |
||
153 | $this->assertTrue($this->pool->hasAdminByClass('someclass')); |
||
154 | |||
155 | $this->pool->getAdminByClass('someclass'); |
||
156 | } |
||
157 | |||
158 | public function testGetAdminForClassWithTooManyRegisteredAdmin(): void |
||
159 | { |
||
160 | $this->expectException(\RuntimeException::class); |
||
161 | |||
162 | $this->pool->setAdminClasses([ |
||
163 | 'someclass' => ['sonata.user.admin.group1', 'sonata.user.admin.group2'], |
||
164 | ]); |
||
165 | |||
166 | $this->assertTrue($this->pool->hasAdminByClass('someclass')); |
||
167 | $this->pool->getAdminByClass('someclass'); |
||
168 | } |
||
169 | |||
170 | public function testGetAdminForClassWhenAdminClassIsSet(): void |
||
180 | |||
181 | public function testGetInstanceWithUndefinedServiceId(): void |
||
182 | { |
||
183 | $this->expectException(\InvalidArgumentException::class); |
||
184 | $this->expectExceptionMessage('Admin service "sonata.news.admin.post" not found in admin pool.'); |
||
185 | |||
186 | $this->pool->getInstance('sonata.news.admin.post'); |
||
187 | } |
||
188 | |||
189 | public function testGetAdminByAdminCode(): void |
||
190 | { |
||
191 | $this->pool->setAdminServiceIds(['sonata.news.admin.post']); |
||
195 | |||
196 | public function testGetAdminByAdminCodeForChildClass(): void |
||
219 | |||
220 | public function testGetAdminByAdminCodeForChildInvalidClass(): void |
||
239 | |||
240 | public function testGetAdminClasses(): void |
||
245 | |||
246 | public function testGetAdminGroups(): void |
||
251 | |||
252 | public function testGetAdminServiceIds(): void |
||
257 | |||
258 | public function testGetContainer(): void |
||
262 | |||
263 | /** |
||
264 | * @group legacy |
||
265 | */ |
||
266 | public function testTemplate(): void |
||
277 | |||
278 | /** |
||
279 | * @group legacy |
||
280 | */ |
||
281 | public function testSetGetTemplates(): void |
||
301 | |||
302 | public function testGetTitleLogo(): void |
||
306 | |||
307 | public function testGetTitle(): void |
||
311 | |||
312 | public function testGetOption(): void |
||
318 | |||
319 | public function testOptionDefault(): void |
||
323 | |||
324 | /** |
||
325 | * @return Symfony\Component\DependencyInjection\ContainerInterface - the mock of container interface |
||
326 | */ |
||
327 | private function getContainer() |
||
338 | |||
339 | private function getItemArray($serviceId) |
||
348 | } |
||
349 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.