|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LAG\AdminBundle\Tests\AdminBundle\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
|
6
|
|
|
use LAG\AdminBundle\Admin\AdminInterface; |
|
7
|
|
|
use LAG\AdminBundle\Admin\Configuration\AdminConfiguration; |
|
8
|
|
|
use LAG\AdminBundle\Tests\Base; |
|
9
|
|
|
|
|
10
|
|
|
class AdminTest extends Base |
|
11
|
|
|
{ |
|
12
|
|
|
public function testAdmin() |
|
13
|
|
|
{ |
|
14
|
|
|
$configurations = $this->getFakeAdminsConfiguration(); |
|
15
|
|
|
|
|
16
|
|
|
foreach ($configurations as $adminName => $configuration) { |
|
17
|
|
|
$adminConfiguration = new AdminConfiguration($configuration); |
|
18
|
|
|
$admin = $this->mockAdmin($adminName, $adminConfiguration); |
|
19
|
|
|
$this->doTestAdmin($admin, $configuration, $adminName); |
|
20
|
|
|
} |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
protected function doTestAdmin(AdminInterface $admin, array $configuration, $adminName) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->assertEquals($admin->getName(), $adminName); |
|
26
|
|
|
$this->assertEquals($admin->getConfiguration()->getFormType(), $configuration['form']); |
|
27
|
|
|
$this->assertEquals($admin->getConfiguration()->getEntityName(), $configuration['entity']); |
|
28
|
|
|
|
|
29
|
|
|
if (array_key_exists('controller', $configuration)) { |
|
30
|
|
|
$this->assertEquals($admin->getConfiguration()->getControllerName(), $configuration['controller']); |
|
31
|
|
|
} |
|
32
|
|
View Code Duplication |
if (array_key_exists('max_per_page', $configuration)) { |
|
33
|
|
|
$this->assertEquals($admin->getConfiguration()->getMaxPerPage(), $configuration['max_per_page']); |
|
34
|
|
|
} else { |
|
35
|
|
|
$this->assertEquals($admin->getConfiguration()->getMaxPerPage(), 25); |
|
36
|
|
|
} |
|
37
|
|
|
if (!array_key_exists('actions', $configuration)) { |
|
38
|
|
|
$configuration['actions'] = [ |
|
39
|
|
|
'create' => [], |
|
40
|
|
|
'edit' => [], |
|
41
|
|
|
'delete' => [], |
|
42
|
|
|
'list' => [] |
|
43
|
|
|
]; |
|
44
|
|
|
} |
|
45
|
|
|
foreach ($configuration['actions'] as $actionName => $actionConfiguration) { |
|
46
|
|
|
$action = $this->mockAction($actionName); |
|
47
|
|
|
$admin->addAction($action); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
$expectedActionNames = array_keys($configuration['actions']); |
|
50
|
|
|
$this->assertEquals($expectedActionNames, array_keys($admin->getActions())); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
protected function getFakeAdminsConfiguration() |
|
54
|
|
|
{ |
|
55
|
|
|
return [ |
|
56
|
|
|
'full_entity' => [ |
|
57
|
|
|
'entity' => 'Test\TestBundle\Entity\TestEntity', |
|
58
|
|
|
'form' => 'test', |
|
59
|
|
|
'controller' => 'TestTestBundle:Test', |
|
60
|
|
|
'max_per_page' => 50, |
|
61
|
|
|
'actions' => [ |
|
62
|
|
|
'custom_list' => [], |
|
63
|
|
|
'custom_edit' => [], |
|
64
|
|
|
], |
|
65
|
|
|
'manager' => 'Test\TestBundle\Manager\TestManager', |
|
66
|
|
|
'routing_url_pattern' => 'lag.admin.{admin}', |
|
67
|
|
|
'routing_name_pattern' => 'lag.{admin}.{action}', |
|
68
|
|
|
'data_provider' => null, |
|
69
|
|
|
'metadata' => new ClassMetadata('LAG\AdminBundle\Tests\Entity\EntityTest'), |
|
70
|
|
|
] |
|
71
|
|
|
]; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.