|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Sonata Project package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Sonata\MediaBundle\Tests\DependencyInjection\Compiler; |
|
15
|
|
|
|
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
|
17
|
|
|
use Sonata\MediaBundle\DependencyInjection\Compiler\AddProviderCompilerPass; |
|
18
|
|
|
use Sonata\MediaBundle\DependencyInjection\SonataMediaExtension; |
|
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
20
|
|
|
|
|
21
|
|
|
class AddProviderCompilerPassTest extends TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
public function testProcess(): void |
|
24
|
|
|
{ |
|
25
|
|
|
// Create ContainerBuilder and set up basic sonata_media config with formats |
|
26
|
|
|
$container = new ContainerBuilder(); |
|
27
|
|
|
$extension = new SonataMediaExtension(); |
|
28
|
|
|
$container->registerExtension($extension); |
|
29
|
|
|
$container->loadFromExtension( |
|
30
|
|
|
$extension->getAlias(), |
|
31
|
|
|
[ |
|
32
|
|
|
'db_driver' => 'doctrine_orm', |
|
33
|
|
|
'default_context' => 'default', |
|
34
|
|
|
'providers' => [ |
|
35
|
|
|
'image' => [ |
|
36
|
|
|
'filesystem' => 'foo_filesystem', |
|
37
|
|
|
], |
|
38
|
|
|
], |
|
39
|
|
|
'contexts' => [ |
|
40
|
|
|
'default' => [ |
|
41
|
|
|
'providers' => [ |
|
42
|
|
|
'foo_provider', |
|
43
|
|
|
], |
|
44
|
|
|
'formats' => '%foo_formats%', |
|
45
|
|
|
], |
|
46
|
|
|
], |
|
47
|
|
|
] |
|
48
|
|
|
); |
|
49
|
|
|
|
|
50
|
|
|
// Define 'foo_formats' parameter, parameter reference in 'sonata_media' config should resolve to this value. |
|
51
|
|
|
$container->setParameter('foo_formats', [ |
|
52
|
|
|
'foo_format' => [ |
|
53
|
|
|
'width' => 350, |
|
54
|
|
|
'height' => 200, |
|
55
|
|
|
'quality' => 70, |
|
56
|
|
|
], |
|
57
|
|
|
]); |
|
58
|
|
|
|
|
59
|
|
|
// Register parameters and services needed by compiler pass |
|
60
|
|
|
$container->setParameter('sonata.media.admin_format', [ |
|
61
|
|
|
'width' => 200, |
|
62
|
|
|
'height' => false, |
|
63
|
|
|
'quality' => 90, |
|
64
|
|
|
]); |
|
65
|
|
|
$container |
|
66
|
|
|
->register('foo_filesystem') |
|
67
|
|
|
->setPublic(false); |
|
68
|
|
|
$container |
|
69
|
|
|
->register('foo_provider') |
|
70
|
|
|
->setPublic(false); |
|
71
|
|
|
$container |
|
72
|
|
|
->register('sonata.media.pool') |
|
73
|
|
|
->setPublic(false); |
|
74
|
|
|
|
|
75
|
|
|
(new AddProviderCompilerPass())->process($container); |
|
76
|
|
|
|
|
77
|
|
|
// 'foo_provider' should have 1 'addFormat' method call with correctly resolved config values. |
|
78
|
|
|
$calls = $container->getDefinition('foo_provider')->getMethodCalls(); |
|
79
|
|
|
$callFound = false; |
|
80
|
|
|
$expectedCall = [ |
|
81
|
|
|
'default_foo_format', |
|
82
|
|
|
[ |
|
83
|
|
|
'width' => 350, |
|
84
|
|
|
'height' => 200, |
|
85
|
|
|
'quality' => 70, |
|
86
|
|
|
'format' => 'jpg', |
|
87
|
|
|
'constraint' => true, |
|
88
|
|
|
'resizer' => false, |
|
89
|
|
|
'resizer_options' => [], |
|
90
|
|
|
], |
|
91
|
|
|
]; |
|
92
|
|
|
foreach ($calls as $call) { |
|
93
|
|
|
if ('addFormat' === $call[0]) { |
|
94
|
|
|
$callFound = true; |
|
95
|
|
|
$this->assertSame( |
|
96
|
|
|
$expectedCall, |
|
97
|
|
|
$call[1], |
|
98
|
|
|
'Format config of "foo_provider" doesn\'t match the expected config.' |
|
99
|
|
|
); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
$this->assertTrue( |
|
103
|
|
|
$callFound, |
|
104
|
|
|
'Expected "addFormat" method call on "foo_provider" service was not registered.' |
|
105
|
|
|
); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|