1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sonata project. |
5
|
|
|
* |
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sonata\DoctrineORMAdminBundle\Tests\DependencyInjection\Compiler; |
13
|
|
|
|
14
|
|
|
use Sonata\DoctrineORMAdminBundle\DependencyInjection\Compiler\AddTemplatesCompilerPass; |
15
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
16
|
|
|
|
17
|
|
|
class AddTemplatesCompilerPassTest extends \PHPUnit_Framework_TestCase |
18
|
|
|
{ |
19
|
|
|
public function testDefaultBehavior() |
20
|
|
|
{ |
21
|
|
|
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder'); |
22
|
|
|
|
23
|
|
|
$container |
24
|
|
|
->expects($this->any()) |
25
|
|
|
->method('getParameter') |
26
|
|
|
->will($this->returnCallback(function($value) { |
27
|
|
|
if ($value == 'sonata.admin.configuration.admin_services') { |
28
|
|
|
return array( |
29
|
|
|
'my.admin' => array( |
30
|
|
|
'templates' => array( |
31
|
|
|
'form' => array('myform.twig.html'), |
32
|
|
|
'filter' => array('myfilter.twig.html') |
33
|
|
|
) |
34
|
|
|
) |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
if ($value == 'sonata_doctrine_orm_admin.templates') { |
39
|
|
|
return array( |
40
|
|
|
'form' => array('default_form.twig.html'), |
41
|
|
|
'filter' => array('default_filter.twig.html'), |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
})) |
45
|
|
|
; |
46
|
|
|
|
47
|
|
|
$container |
48
|
|
|
->expects($this->any()) |
49
|
|
|
->method('findTaggedServiceIds') |
50
|
|
|
->will($this->returnValue(array('my.admin' => array(array('manager_type' => 'orm'))))) |
51
|
|
|
; |
52
|
|
|
|
53
|
|
|
$definition = new Definition(null); |
54
|
|
|
|
55
|
|
|
$container |
56
|
|
|
->expects($this->any()) |
57
|
|
|
->method('getDefinition') |
58
|
|
|
->will($this->returnValue($definition)) |
59
|
|
|
; |
60
|
|
|
|
61
|
|
|
$definition->addMethodCall('setFilterTheme', array(array('custom_call.twig.html'))); |
62
|
|
|
|
63
|
|
|
$compilerPass = new AddTemplatesCompilerPass(); |
64
|
|
|
$compilerPass->process($container); |
65
|
|
|
|
66
|
|
|
$expected = array( |
67
|
|
|
array('setFilterTheme', array(array('custom_call.twig.html', 'myfilter.twig.html',))), |
68
|
|
|
array('setFormTheme', array(array('default_form.twig.html', 'myform.twig.html',))), |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
$this->assertEquals($expected, $definition->getMethodCalls()); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|