1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Lug package. |
5
|
|
|
* |
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Lug\Bundle\UiBundle\Tests\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Knp\Menu\FactoryInterface; |
15
|
|
|
use Lug\Bundle\UiBundle\DependencyInjection\LugUiExtension; |
16
|
|
|
use Lug\Bundle\UiBundle\Form\Extension\IconButtonExtension; |
17
|
|
|
use Lug\Bundle\UiBundle\Form\Extension\IconFormExtension; |
18
|
|
|
use Lug\Bundle\UiBundle\Menu\MenuBuilderInterface; |
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
20
|
|
|
use Symfony\Component\DependencyInjection\DefinitionDecorator; |
21
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
22
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ButtonType; |
23
|
|
|
use Symfony\Component\Form\Extension\Core\Type\FormType; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @author GeLo <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
abstract class AbstractLugUiExtensionTest extends \PHPUnit_Framework_TestCase |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var LugUiExtension |
32
|
|
|
*/ |
33
|
|
|
private $extension; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var ContainerBuilder |
37
|
|
|
*/ |
38
|
|
|
private $container; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var FactoryInterface |
42
|
|
|
*/ |
43
|
|
|
private $menuFactory; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var EventDispatcherInterface |
47
|
|
|
*/ |
48
|
|
|
private $eventDispatcher; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
|
|
protected function setUp() |
54
|
|
|
{ |
55
|
|
|
$this->menuFactory = $this->createMenuFactoryMock(); |
56
|
|
|
$this->eventDispatcher = $this->createEventDispatcherMock(); |
57
|
|
|
$this->extension = new LugUiExtension(); |
58
|
|
|
|
59
|
|
|
$this->container = new ContainerBuilder(); |
60
|
|
|
$this->container->set('knp_menu.factory', $this->menuFactory); |
61
|
|
|
$this->container->set('event_dispatcher', $this->eventDispatcher); |
62
|
|
|
$this->container->registerExtension($this->extension); |
63
|
|
|
$this->container->loadFromExtension($this->extension->getAlias()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testForms() |
67
|
|
|
{ |
68
|
|
|
$this->compileContainer(); |
69
|
|
|
|
70
|
|
|
$this->assertTrue($this->container->hasDefinition($iconFormName = 'lug.ui.form.extension.icon.form')); |
71
|
|
|
$this->assertTrue($this->container->hasDefinition($iconButtonName = 'lug.ui.form.extension.icon.button')); |
72
|
|
|
|
73
|
|
|
$iconFormDefinition = $this->container->getDefinition($iconFormName); |
74
|
|
|
$iconButtonDefinition = $this->container->getDefinition($iconButtonName); |
75
|
|
|
|
76
|
|
|
$this->assertTrue($iconFormDefinition->hasTag($formTypeExtensionTag = 'form.type_extension')); |
77
|
|
|
$this->assertSame([[ |
78
|
|
|
'extended_type' => FormType::class, |
79
|
|
|
'extended-type' => FormType::class, |
80
|
|
|
]], $iconFormDefinition->getTag($formTypeExtensionTag)); |
81
|
|
|
|
82
|
|
|
$this->assertTrue($iconButtonDefinition->hasTag($formTypeExtensionTag)); |
83
|
|
|
$this->assertSame([[ |
84
|
|
|
'extended_type' => ButtonType::class, |
85
|
|
|
'extended-type' => ButtonType::class, |
86
|
|
|
]], $iconButtonDefinition->getTag($formTypeExtensionTag)); |
87
|
|
|
|
88
|
|
|
$this->assertInstanceOf(IconFormExtension::class, $this->container->get($iconFormName)); |
89
|
|
|
$this->assertInstanceOf(IconButtonExtension::class, $this->container->get($iconButtonName)); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testMenu() |
93
|
|
|
{ |
94
|
|
|
$definition = new DefinitionDecorator('lug.ui.menu.builder'); |
95
|
|
|
$definition->setClass($class = $this->createMenuBuilderClassMock()); |
96
|
|
|
$this->container->setDefinition($menuName = 'lug.ui.menu.test', $definition); |
97
|
|
|
|
98
|
|
|
$this->compileContainer(); |
99
|
|
|
|
100
|
|
|
$this->assertInstanceOf($class, $this->container->get($menuName)); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param ContainerBuilder $container |
105
|
|
|
* @param string $configuration |
106
|
|
|
*/ |
107
|
|
|
abstract protected function loadConfiguration(ContainerBuilder $container, $configuration); |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param string|null $configuration |
111
|
|
|
*/ |
112
|
|
|
private function compileContainer($configuration = null) |
113
|
|
|
{ |
114
|
|
|
if ($configuration !== null) { |
115
|
|
|
$this->loadConfiguration($this->container, $configuration); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
$this->container->compile(); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|FactoryInterface |
123
|
|
|
*/ |
124
|
|
|
private function createMenuFactoryMock() |
125
|
|
|
{ |
126
|
|
|
return $this->getMock(FactoryInterface::class); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|EventDispatcherInterface |
131
|
|
|
*/ |
132
|
|
|
private function createEventDispatcherMock() |
133
|
|
|
{ |
134
|
|
|
return $this->getMock(EventDispatcherInterface::class); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return string |
139
|
|
|
*/ |
140
|
|
|
private function createMenuBuilderClassMock() |
141
|
|
|
{ |
142
|
|
|
return $this->getMockClass(MenuBuilderInterface::class); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|