|
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\SeoBundle\Tests\DependencyInjection\Compiler; |
|
15
|
|
|
|
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
|
17
|
|
|
use Sonata\SeoBundle\DependencyInjection\Compiler\BreadcrumbBlockServicesCompilerPass; |
|
18
|
|
|
use Sonata\SeoBundle\DependencyInjection\Compiler\ServiceCompilerPass; |
|
19
|
|
|
use Sonata\SeoBundle\DependencyInjection\SonataSeoExtension; |
|
20
|
|
|
use Sonata\SeoBundle\Seo\SeoPageInterface; |
|
21
|
|
|
use Sonata\SeoBundle\Tests\Stubs\SeoPageStub; |
|
22
|
|
|
use Sonata\SeoBundle\Tests\Stubs\SeoPageWithoutTitleInterfaceStub; |
|
23
|
|
|
use Symfony\Component\DependencyInjection\Compiler\PassConfig; |
|
24
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
25
|
|
|
|
|
26
|
|
|
class ServiceCompilerPassTest extends TestCase |
|
27
|
|
|
{ |
|
28
|
|
|
public function testServicesExistsAndCanBeOverridden() |
|
29
|
|
|
{ |
|
30
|
|
|
$container = new ContainerBuilder(); |
|
31
|
|
|
$container->register('sonata.seo.custom.page', SeoPageStub::class); |
|
32
|
|
|
$config = [ |
|
33
|
|
|
'page' => [ |
|
34
|
|
|
'default' => 'sonata.seo.custom.page', |
|
35
|
|
|
], |
|
36
|
|
|
]; |
|
37
|
|
|
|
|
38
|
|
|
$container->addCompilerPass( |
|
39
|
|
|
new AlterAliasPublicationPass(SeoPageInterface::class), |
|
40
|
|
|
PassConfig::TYPE_BEFORE_REMOVING |
|
41
|
|
|
); |
|
42
|
|
|
|
|
43
|
|
|
$this->processConfiguration($config, $container); |
|
44
|
|
|
|
|
45
|
|
|
$this->assertTrue($service = $container->has('sonata.seo.page')); |
|
46
|
|
|
$this->assertTrue($alias = $container->has(SeoPageInterface::class)); |
|
47
|
|
|
$this->assertSame($service, $alias); |
|
48
|
|
|
|
|
49
|
|
|
$this->assertInstanceOf(SeoPageStub::class, $container->get(SeoPageInterface::class)); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testServiceWithoutTitleInterfaceApplied() |
|
53
|
|
|
{ |
|
54
|
|
|
$container = new ContainerBuilder(); |
|
55
|
|
|
$container->register('sonata.seo.custom.page', SeoPageWithoutTitleInterfaceStub::class); |
|
56
|
|
|
$config = [ |
|
57
|
|
|
'page' => [ |
|
58
|
|
|
'default' => 'sonata.seo.custom.page', |
|
59
|
|
|
], |
|
60
|
|
|
]; |
|
61
|
|
|
|
|
62
|
|
|
$this->processConfiguration($config, $container); |
|
63
|
|
|
|
|
64
|
|
|
$container->get('sonata.seo.page'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function testSimpleTitleConfiguration() |
|
68
|
|
|
{ |
|
69
|
|
|
$container = new ContainerBuilder(); |
|
70
|
|
|
$config = [ |
|
71
|
|
|
'page' => [ |
|
72
|
|
|
'title' => 'My Title', |
|
73
|
|
|
], |
|
74
|
|
|
]; |
|
75
|
|
|
$this->processConfiguration($config, $container); |
|
76
|
|
|
|
|
77
|
|
|
$page = $container->get('sonata.seo.page'); |
|
78
|
|
|
$this->assertEquals('My Title', $page->getTitle()); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function testAdvancedTitleConfiguration() |
|
82
|
|
|
{ |
|
83
|
|
|
$container = new ContainerBuilder(); |
|
84
|
|
|
|
|
85
|
|
|
$config = [ |
|
86
|
|
|
'page' => [ |
|
87
|
|
|
'title' => [ |
|
88
|
|
|
'prefix' => 'Prefix', |
|
89
|
|
|
'suffix' => 'My Title', |
|
90
|
|
|
], |
|
91
|
|
|
], |
|
92
|
|
|
]; |
|
93
|
|
|
$this->processConfiguration($config, $container); |
|
94
|
|
|
|
|
95
|
|
|
$page = $container->get('sonata.seo.page'); |
|
96
|
|
|
$this->assertEquals('Prefix - My Title', $page->getTitle()); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
private function processConfiguration(array $config, ContainerBuilder $container) |
|
100
|
|
|
{ |
|
101
|
|
|
$container->setParameter('kernel.bundles', []); |
|
102
|
|
|
|
|
103
|
|
|
$container->registerExtension($extension = new SonataSeoExtension()); |
|
104
|
|
|
|
|
105
|
|
|
$container->loadFromExtension($extension->getAlias(), $config); |
|
106
|
|
|
|
|
107
|
|
|
$container |
|
108
|
|
|
->addCompilerPass(new ServiceCompilerPass()) |
|
109
|
|
|
->addCompilerPass(new BreadcrumbBlockServicesCompilerPass()); |
|
110
|
|
|
|
|
111
|
|
|
$container->compile(); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|