|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LAG\AdminBundle\Tests\AdminBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Bundle\DoctrineBundle\Registry; |
|
6
|
|
|
use Knp\Bundle\MenuBundle\DependencyInjection\KnpMenuExtension; |
|
7
|
|
|
use Knp\Menu\Provider\MenuProviderInterface; |
|
8
|
|
|
use LAG\AdminBundle\Action\Factory\ActionFactory; |
|
9
|
|
|
use LAG\AdminBundle\DataProvider\Factory\DataProviderFactory; |
|
10
|
|
|
use LAG\AdminBundle\DependencyInjection\LAGAdminExtension; |
|
11
|
|
|
use LAG\AdminBundle\Field\Factory\FieldFactory; |
|
12
|
|
|
use LAG\AdminBundle\Menu\Factory\MenuFactory; |
|
13
|
|
|
use LAG\AdminBundle\Tests\AdminTestBase; |
|
14
|
|
|
use LAG\AdminBundle\Tests\Fake\Twig_Environment; |
|
15
|
|
|
use LAG\AdminBundle\Tests\Utils\FakeEntityManager; |
|
16
|
|
|
use Monolog\Logger; |
|
17
|
|
|
use stdClass; |
|
18
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension; |
|
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
20
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
21
|
|
|
use Symfony\Component\Form\FormFactoryInterface; |
|
22
|
|
|
use Symfony\Component\HttpFoundation\Session\Session; |
|
23
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
24
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; |
|
25
|
|
|
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker; |
|
26
|
|
|
use Symfony\Component\Translation\IdentityTranslator; |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
class LAGAdminExtensionTest extends AdminTestBase |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* The load should allow the container to compile without errors. |
|
33
|
|
|
*/ |
|
34
|
|
|
public function testLoad() |
|
35
|
|
|
{ |
|
36
|
|
|
$container = $this->getWorkingContainer(); |
|
37
|
|
|
$extension = new LAGAdminExtension(); |
|
38
|
|
|
$extension->load([ |
|
39
|
|
|
'lag_admin' => [ |
|
40
|
|
|
'application' => [], |
|
41
|
|
|
] |
|
42
|
|
|
], $container); |
|
43
|
|
|
|
|
44
|
|
|
$eventDispatcherExtension = new FrameworkExtension(); |
|
45
|
|
|
$eventDispatcherExtension->load([], $container); |
|
46
|
|
|
|
|
47
|
|
|
$knpMenuExtension = new KnpMenuExtension(); |
|
48
|
|
|
$knpMenuExtension->load([], $container); |
|
49
|
|
|
|
|
50
|
|
|
// the container should compile without errors |
|
51
|
|
|
$container->compile(); |
|
52
|
|
|
$this->assertTrue(true); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertServices($container); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Load method should not throw an exception if no application section was found. |
|
59
|
|
|
*/ |
|
60
|
|
|
public function testLoadWithoutApplication() |
|
61
|
|
|
{ |
|
62
|
|
|
$container = new ContainerBuilder(); |
|
63
|
|
|
$extension = new LAGAdminExtension(); |
|
64
|
|
|
|
|
65
|
|
|
$extension->load([], $container); |
|
66
|
|
|
// no exception raised |
|
67
|
|
|
$this->assertTrue(true); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* GetAlias method should return "lag_admin". |
|
72
|
|
|
*/ |
|
73
|
|
|
public function testGetAlias() |
|
74
|
|
|
{ |
|
75
|
|
|
$container = new ContainerBuilder(); |
|
76
|
|
|
$extension = new LAGAdminExtension(); |
|
77
|
|
|
$extension->load([ |
|
78
|
|
|
'lag_admin' => [ |
|
79
|
|
|
'application' => [] |
|
80
|
|
|
] |
|
81
|
|
|
], $container); |
|
82
|
|
|
|
|
83
|
|
|
$this->assertEquals('lag_admin', $extension->getAlias()); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
protected function assertServices(ContainerBuilder $container) |
|
87
|
|
|
{ |
|
88
|
|
|
// assert factories are rightly instanciate |
|
89
|
|
|
$this->assertInstanceOf(ActionFactory::class, $container->get('lag.admin.action_factory')); |
|
90
|
|
|
$this->assertInstanceOf(FieldFactory::class, $container->get('lag.admin.field_factory')); |
|
91
|
|
|
$this->assertInstanceOf(MenuFactory::class, $container->get('lag.admin.menu_factory')); |
|
92
|
|
|
$this->assertInstanceOf(DataProviderFactory::class, $container->get('lag.admin.data_providers_factory')); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Return a working container builder to compile. |
|
97
|
|
|
* |
|
98
|
|
|
* @return ContainerBuilder |
|
99
|
|
|
*/ |
|
100
|
|
|
protected function getWorkingContainer() |
|
101
|
|
|
{ |
|
102
|
|
|
$generic = new Definition(stdClass::class); |
|
103
|
|
|
|
|
104
|
|
|
$logger = new Definition(Logger::class, [ |
|
105
|
|
|
'default' |
|
106
|
|
|
]); |
|
107
|
|
|
$session= new Definition(Session::class); |
|
108
|
|
|
|
|
109
|
|
|
$entityManager = new Definition(); |
|
110
|
|
|
$entityManager->setClass(FakeEntityManager::class); |
|
111
|
|
|
|
|
112
|
|
|
$authorizationChecker = new Definition(); |
|
113
|
|
|
$authorizationChecker->setClass(AuthorizationChecker::class); |
|
114
|
|
|
|
|
115
|
|
|
$tokenStorage = new Definition(); |
|
116
|
|
|
$tokenStorage->setClass(TokenStorage::class); |
|
117
|
|
|
|
|
118
|
|
|
$formFactory = new Definition(FormFactoryInterface::class); |
|
119
|
|
|
|
|
120
|
|
|
$translator = new Definition(IdentityTranslator::class); |
|
121
|
|
|
|
|
122
|
|
|
$router = new Definition(RouterInterface::class); |
|
123
|
|
|
|
|
124
|
|
|
$workflowTwigExtension = new Definition(stdClass::class); |
|
125
|
|
|
$workflowTwigExtension->setAutowired(true); |
|
126
|
|
|
|
|
127
|
|
|
$registry = new Definition(Registry::class); |
|
128
|
|
|
$twig = new Definition(Twig_Environment::class); |
|
129
|
|
|
$menuProvider = new Definition(MenuProviderInterface::class); |
|
130
|
|
|
|
|
131
|
|
|
$container = new ContainerBuilder(); |
|
132
|
|
|
$container->setParameter('kernel.debug', false); |
|
133
|
|
|
$container->setParameter('kernel.cache_dir', sys_get_temp_dir().'/AdminBundleTests/cache'); |
|
134
|
|
|
$container->setParameter('kernel.root_dir', realpath(__DIR__.'/../../AdminBundle')); |
|
135
|
|
|
$container->setParameter('kernel.charset', 'utf8'); |
|
136
|
|
|
$container->setParameter('kernel.secret', 'MyLittleSecret'); |
|
137
|
|
|
$container->setParameter('kernel.bundles', []); |
|
138
|
|
|
$container->setParameter('kernel.bundles_metadata', []); |
|
139
|
|
|
$container->setParameter('kernel.environment', 'prod'); |
|
140
|
|
|
$container->setParameter('kernel.project_dir', __DIR__); |
|
141
|
|
|
|
|
142
|
|
|
$container->setDefinitions([ |
|
143
|
|
|
'doctrine.orm.entity_manager' => $entityManager, |
|
144
|
|
|
'doctrine' => $generic, |
|
145
|
|
|
'router' => $router, |
|
146
|
|
|
'logger' => $logger, |
|
147
|
|
|
'session' => $session, |
|
148
|
|
|
'form.factory' => $formFactory, |
|
149
|
|
|
'security.authorization_checker' => $authorizationChecker, |
|
150
|
|
|
'security.token_storage' => $tokenStorage, |
|
151
|
|
|
'translator' => $translator, |
|
152
|
|
|
'twig' => $twig, |
|
153
|
|
|
'registry' => $registry, |
|
154
|
|
|
'knp_menu.menu_provider' => $menuProvider, |
|
155
|
|
|
'service_container' => $generic, |
|
156
|
|
|
]); |
|
157
|
|
|
|
|
158
|
|
|
return $container; |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
|