|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Ivory CKEditor 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 FOS\CKEditorBundle\Tests\DependencyInjection\Compiler; |
|
13
|
|
|
|
|
14
|
|
|
use FOS\CKEditorBundle\DependencyInjection\Compiler\ResourceCompilerPass; |
|
15
|
|
|
use FOS\CKEditorBundle\Tests\AbstractTestCase; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @author GeLo <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class ResourceCompilerPassTest extends AbstractTestCase |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var ResourceCompilerPass |
|
25
|
|
|
*/ |
|
26
|
|
|
private $compilerPass; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritdoc} |
|
30
|
|
|
*/ |
|
31
|
|
|
protected function setUp() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->compilerPass = new ResourceCompilerPass(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
View Code Duplication |
public function testTwigResource() |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
|
|
$containerBuilder = $this->createContainerBuilderMock(); |
|
39
|
|
|
$containerBuilder |
|
|
|
|
|
|
40
|
|
|
->expects($this->exactly(2)) |
|
41
|
|
|
->method('hasParameter') |
|
42
|
|
|
->will($this->returnValueMap([ |
|
43
|
|
|
['templating.helper.form.resources', false], |
|
44
|
|
|
[$parameter = 'twig.form.resources', true], |
|
45
|
|
|
])); |
|
46
|
|
|
|
|
47
|
|
|
$containerBuilder |
|
48
|
|
|
->expects($this->once()) |
|
49
|
|
|
->method('getParameter') |
|
50
|
|
|
->with($this->identicalTo($parameter)) |
|
51
|
|
|
->will($this->returnValue([$template = 'layout.html.twig'])); |
|
52
|
|
|
|
|
53
|
|
|
$containerBuilder |
|
54
|
|
|
->expects($this->once()) |
|
55
|
|
|
->method('setParameter') |
|
56
|
|
|
->with( |
|
57
|
|
|
$this->identicalTo($parameter), |
|
58
|
|
|
$this->identicalTo([ |
|
59
|
|
|
'@FOSCKEditor/Form/ckeditor_widget.html.twig', |
|
60
|
|
|
$template, |
|
61
|
|
|
]) |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
$this->compilerPass->process($containerBuilder); |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
View Code Duplication |
public function testPhpResource() |
|
|
|
|
|
|
68
|
|
|
{ |
|
69
|
|
|
$containerBuilder = $this->createContainerBuilderMock(); |
|
70
|
|
|
$containerBuilder |
|
|
|
|
|
|
71
|
|
|
->expects($this->exactly(2)) |
|
72
|
|
|
->method('hasParameter') |
|
73
|
|
|
->will($this->returnValueMap([ |
|
74
|
|
|
[$parameter = 'templating.helper.form.resources', true], |
|
75
|
|
|
['twig.form.resources', false], |
|
76
|
|
|
])); |
|
77
|
|
|
|
|
78
|
|
|
$containerBuilder |
|
79
|
|
|
->expects($this->once()) |
|
80
|
|
|
->method('getParameter') |
|
81
|
|
|
->with($this->identicalTo($parameter)) |
|
82
|
|
|
->will($this->returnValue([$template = 'layout.html.php'])); |
|
83
|
|
|
|
|
84
|
|
|
$containerBuilder |
|
85
|
|
|
->expects($this->once()) |
|
86
|
|
|
->method('setParameter') |
|
87
|
|
|
->with( |
|
88
|
|
|
$this->identicalTo($parameter), |
|
89
|
|
|
$this->identicalTo(['FOSCKEditorBundle:Form', $template]) |
|
90
|
|
|
); |
|
91
|
|
|
|
|
92
|
|
|
$this->compilerPass->process($containerBuilder); |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @return ContainerBuilder|\PHPUnit_Framework_MockObject_MockObject |
|
97
|
|
|
*/ |
|
98
|
|
|
private function createContainerBuilderMock() |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->getMockBuilder(ContainerBuilder::class) |
|
101
|
|
|
->disableOriginalConstructor() |
|
102
|
|
|
->setMethods(['hasParameter', 'getParameter', 'setParameter']) |
|
103
|
|
|
->getMock(); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.