|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sonata Project package. |
|
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\MediaBundle\Tests\DependencyInjection; |
|
13
|
|
|
|
|
14
|
|
|
use Sonata\MediaBundle\DependencyInjection\SonataMediaExtension; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
17
|
|
|
|
|
18
|
|
|
class SonataMediaExtensionTest extends \PHPUnit_Framework_TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
public function testLoadWithDefaultAndCustomCategoryManager() |
|
21
|
|
|
{ |
|
22
|
|
|
$container = $this->getContainer( |
|
23
|
|
|
array(array( |
|
24
|
|
|
'class' => array('category' => '\stdClass'), |
|
25
|
|
|
'category_manager' => 'dummy.service.name', |
|
26
|
|
|
))); |
|
27
|
|
|
|
|
28
|
|
|
$this->assertTrue($container->hasAlias('sonata.media.manager.category')); |
|
29
|
|
|
$this->assertSame($container->getAlias('sonata.media.manager.category')->__toString(), 'dummy.service.name'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testLoadWithForceDisableTrueAndWithCategoryManager() |
|
33
|
|
|
{ |
|
34
|
|
|
$container = $this->getContainer( |
|
35
|
|
|
array(array( |
|
36
|
|
|
'class' => array('category' => '\stdClass'), |
|
37
|
|
|
'category_manager' => 'dummy.service.name', |
|
38
|
|
|
'force_disable_category' => true, |
|
39
|
|
|
))); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertFalse($container->hasDefinition('sonata.media.manager.category')); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testLoadWithDefaultAndClassificationBundleEnable() |
|
45
|
|
|
{ |
|
46
|
|
|
$container = $this->getContainer(); |
|
47
|
|
|
$this->assertTrue($container->hasAlias('sonata.media.manager.category')); |
|
48
|
|
|
$this->assertSame($container->getDefinition('sonata.media.manager.category.default')->getClass(), 'Sonata\MediaBundle\Model\CategoryManager'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testLoadWithDefaultAndClassificationBundleEnableAndForceDisableCategory() |
|
52
|
|
|
{ |
|
53
|
|
|
$container = $this->getContainer(array(array('force_disable_category' => true))); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertFalse($container->hasDefinition('sonata.media.manager.category')); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function testLoadWithDefaultAndClassificationBundleEnableAndCustomCategoryManager() |
|
59
|
|
|
{ |
|
60
|
|
|
$container = $this->getContainer( |
|
61
|
|
|
array(array( |
|
62
|
|
|
'class' => array('category' => '\stdClass'), |
|
63
|
|
|
'category_manager' => 'dummy.service.name', |
|
64
|
|
|
))); |
|
65
|
|
|
|
|
66
|
|
|
$this->assertTrue($container->hasAlias('sonata.media.manager.category')); |
|
67
|
|
|
$this->assertSame($container->getAlias('sonata.media.manager.category')->__toString(), 'dummy.service.name'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
private function getContainer(array $config = array()) |
|
71
|
|
|
{ |
|
72
|
|
|
$defaults = array(array( |
|
73
|
|
|
'default_context' => 'default', |
|
74
|
|
|
'db_driver' => 'doctrine_orm', |
|
75
|
|
|
'contexts' => array('default' => array('formats' => array('small' => array('width' => 100, 'quality' => 50)))), |
|
76
|
|
|
'filesystem' => array('local' => array('directory' => '/tmp/')), |
|
77
|
|
|
)); |
|
78
|
|
|
|
|
79
|
|
|
$container = new ContainerBuilder(); |
|
80
|
|
|
$container->setParameter('kernel.bundles', array('SonataAdminBundle' => true)); |
|
81
|
|
|
$container->setDefinition('translator', new Definition('\stdClass')); |
|
82
|
|
|
$container->setDefinition('security.context', new Definition('\stdClass')); |
|
83
|
|
|
$container->setDefinition('doctrine', new Definition('\stdClass')); |
|
84
|
|
|
$container->setDefinition('session', new Definition('\stdClass')); |
|
85
|
|
|
|
|
86
|
|
|
if (isset($config[0]['category_manager'])) { |
|
87
|
|
|
$container->setDefinition($config[0]['category_manager'], new Definition('\stdClass')); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
$container->setDefinition('sonata.classification.manager.category', new Definition('Sonata\ClassificationBundle\Model\CategoryManager')); |
|
91
|
|
|
|
|
92
|
|
|
$loader = new SonataMediaExtension(); |
|
93
|
|
|
$loader->load(array_merge($defaults, $config), $container); |
|
94
|
|
|
$container->compile(); |
|
95
|
|
|
|
|
96
|
|
|
return $container; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|