|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LAG\AdminBundle\Tests\AdminBundle\Event\Subscriber; |
|
4
|
|
|
|
|
5
|
|
|
use LAG\AdminBundle\Admin\Configuration\ApplicationConfiguration; |
|
6
|
|
|
use LAG\AdminBundle\Event\AdminEvent; |
|
7
|
|
|
use LAG\AdminBundle\Event\Subscriber\ExtraConfigurationSubscriber; |
|
8
|
|
|
use LAG\AdminBundle\Tests\Base; |
|
9
|
|
|
|
|
10
|
|
|
class ExtraConfigurationSubscriberTest extends Base |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* ExtraConfigurationSubscriber SHOULD subscribe to the Admin creation and the Action creation event |
|
14
|
|
|
*/ |
|
15
|
|
|
public function testGetSubscribedEvents() |
|
16
|
|
|
{ |
|
17
|
|
|
$subscribedEvents = ExtraConfigurationSubscriber::getSubscribedEvents(); |
|
18
|
|
|
|
|
19
|
|
|
$this->assertArrayHasKey(AdminEvent::ADMIN_CREATE, $subscribedEvents); |
|
20
|
|
|
$this->assertArrayHasKey(AdminEvent::ACTION_CREATE, $subscribedEvents); |
|
21
|
|
|
$this->assertContains('actionCreate', $subscribedEvents); |
|
22
|
|
|
$this->assertContains('adminCreate', $subscribedEvents); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* AdminCreate method SHOULD add the CRUD actions only if required |
|
27
|
|
|
*/ |
|
28
|
|
|
public function testAdminCreate() |
|
29
|
|
|
{ |
|
30
|
|
|
// with extra configuration disabled, adminCreate method SHOULD not modifiy the configuration |
|
31
|
|
|
$subscriber = new ExtraConfigurationSubscriber( |
|
32
|
|
|
false, |
|
33
|
|
|
$this->mockEntityManager(), |
|
34
|
|
|
new ApplicationConfiguration([], 'fr') |
|
35
|
|
|
); |
|
36
|
|
|
$event = new AdminEvent(); |
|
37
|
|
|
$event->setConfiguration([]); |
|
38
|
|
|
$subscriber->adminCreate($event); |
|
39
|
|
|
$this->assertEquals([], $event->getConfiguration()); |
|
40
|
|
|
|
|
41
|
|
|
// with extra configuration enabled, adminCreate method SHOULD fill action configuration if it is empty |
|
42
|
|
|
$subscriber = new ExtraConfigurationSubscriber( |
|
43
|
|
|
true, |
|
44
|
|
|
$this->mockEntityManager(), |
|
45
|
|
|
new ApplicationConfiguration([], 'fr') |
|
46
|
|
|
); |
|
47
|
|
|
$event = new AdminEvent(); |
|
48
|
|
|
$event->setConfiguration([]); |
|
49
|
|
|
$subscriber->adminCreate($event); |
|
50
|
|
|
$this->assertEquals([ |
|
51
|
|
|
'actions' => [ |
|
52
|
|
|
'create' => [], |
|
53
|
|
|
'list' => [], |
|
54
|
|
|
'edit' => [], |
|
55
|
|
|
'delete' => [], |
|
56
|
|
|
'batch' => [], |
|
57
|
|
|
] |
|
58
|
|
|
], $event->getConfiguration()); |
|
59
|
|
|
|
|
60
|
|
|
// adminCreate method SHOULD not modified actual configuration |
|
61
|
|
|
$event = new AdminEvent(); |
|
62
|
|
|
$event->setConfiguration([ |
|
63
|
|
|
'actions' => [ |
|
64
|
|
|
'myAction' => [] |
|
65
|
|
|
] |
|
66
|
|
|
]); |
|
67
|
|
|
$subscriber->adminCreate($event); |
|
68
|
|
|
$this->assertEquals([ |
|
69
|
|
|
'actions' => [ |
|
70
|
|
|
'myAction' => [] |
|
71
|
|
|
] |
|
72
|
|
|
], $event->getConfiguration()); |
|
73
|
|
|
|
|
74
|
|
|
// adminCreate method SHOULD add batch for list actions if not defined |
|
75
|
|
|
$event = new AdminEvent(); |
|
76
|
|
|
$event->setConfiguration([ |
|
77
|
|
|
'actions' => [ |
|
78
|
|
|
'list' => [] |
|
79
|
|
|
] |
|
80
|
|
|
]); |
|
81
|
|
|
$subscriber->adminCreate($event); |
|
82
|
|
|
$this->assertEquals([ |
|
83
|
|
|
'actions' => [ |
|
84
|
|
|
'list' => [], |
|
85
|
|
|
'batch' => [], |
|
86
|
|
|
] |
|
87
|
|
|
], $event->getConfiguration()); |
|
88
|
|
|
|
|
89
|
|
|
$event = new AdminEvent(); |
|
90
|
|
|
$event->setConfiguration([ |
|
91
|
|
|
'actions' => [ |
|
92
|
|
|
'list' => [ |
|
93
|
|
|
'batch' => false |
|
94
|
|
|
] |
|
95
|
|
|
] |
|
96
|
|
|
]); |
|
97
|
|
|
$subscriber->adminCreate($event); |
|
98
|
|
|
$this->assertEquals([ |
|
99
|
|
|
'actions' => [ |
|
100
|
|
|
'list' => [ |
|
101
|
|
|
'batch' => false |
|
102
|
|
|
] |
|
103
|
|
|
] |
|
104
|
|
|
], $event->getConfiguration()); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|