1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the OrbitaleCmsBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Alexandre Rock Ancelet <[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 Orbitale\Bundle\CmsBundle\Tests\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Orbitale\Bundle\CmsBundle\Tests\Fixtures\App\Stub\OrbitaleCmsExtensionStub; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
16
|
|
|
use Symfony\Component\Yaml\Yaml; |
17
|
|
|
|
18
|
|
|
class OrbitaleCmsExtensionTest extends \PHPUnit_Framework_TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
22
|
|
|
* @expectedExceptionMessage Page class must be a valid class extending Orbitale\Bundle\CmsBundle\Entity\Page. "inexistent_page_class" given. |
23
|
|
|
*/ |
24
|
|
View Code Duplication |
public function testInexistentPageClass() |
25
|
|
|
{ |
26
|
|
|
$builder = new ContainerBuilder(); |
27
|
|
|
|
28
|
|
|
$ext = new OrbitaleCmsExtensionStub(true); |
29
|
|
|
|
30
|
|
|
$ext->load([ |
31
|
|
|
'orbitale_cms' => [ |
32
|
|
|
'page_class' => 'inexistent_page_class', |
33
|
|
|
'category_class' => 'Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity\Category', |
34
|
|
|
], |
35
|
|
|
], $builder); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
40
|
|
|
* @expectedExceptionMessage Category class must be a valid class extending Orbitale\Bundle\CmsBundle\Entity\Category. "inexistent_category_class" given. |
41
|
|
|
*/ |
42
|
|
View Code Duplication |
public function testInexistentCategoryClass() |
43
|
|
|
{ |
44
|
|
|
$builder = new ContainerBuilder(); |
45
|
|
|
|
46
|
|
|
$ext = new OrbitaleCmsExtensionStub(true); |
47
|
|
|
|
48
|
|
|
$ext->load([ |
49
|
|
|
'orbitale_cms' => [ |
50
|
|
|
'page_class' => 'Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity\Page', |
51
|
|
|
'category_class' => 'inexistent_category_class', |
52
|
|
|
], |
53
|
|
|
], $builder); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @dataProvider provideYamlConfiguration |
58
|
|
|
* |
59
|
|
|
* @param $config |
60
|
|
|
* @param $expected |
61
|
|
|
*/ |
62
|
|
View Code Duplication |
public function testYamlConfiguration($config, $expected) |
63
|
|
|
{ |
64
|
|
|
$builder = new ContainerBuilder(); |
65
|
|
|
|
66
|
|
|
$ext = new OrbitaleCmsExtensionStub(true); |
67
|
|
|
|
68
|
|
|
$ext->load($config, $builder); |
69
|
|
|
|
70
|
|
|
foreach ($expected['orbitale_cms'] as $key => $expectedValue) { |
71
|
|
|
static::assertEquals($expectedValue, $builder->getParameter('orbitale_cms.' . $key)); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @dataProvider provideYamlConfiguration |
77
|
|
|
* |
78
|
|
|
* @param $config |
79
|
|
|
* @param $expected |
80
|
|
|
*/ |
81
|
|
View Code Duplication |
public function testYamlConfigurationSymfony2($config, $expected) |
82
|
|
|
{ |
83
|
|
|
$builder = new ContainerBuilder(); |
84
|
|
|
|
85
|
|
|
$ext = new OrbitaleCmsExtensionStub(false); |
86
|
|
|
|
87
|
|
|
$ext->load($config, $builder); |
88
|
|
|
|
89
|
|
|
foreach ($expected['orbitale_cms'] as $key => $expectedValue) { |
90
|
|
|
static::assertSame($expectedValue, $builder->getParameter('orbitale_cms.' . $key)); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function provideYamlConfiguration() |
95
|
|
|
{ |
96
|
|
|
$dir = __DIR__ . '/../Fixtures/App/extension_test/'; |
97
|
|
|
|
98
|
|
|
$configFiles = glob($dir . 'config_*.yml'); |
99
|
|
|
$resultFiles = glob($dir . 'result_*.yml'); |
100
|
|
|
|
101
|
|
|
sort($configFiles); |
102
|
|
|
sort($resultFiles); |
103
|
|
|
|
104
|
|
|
$tests = []; |
105
|
|
|
|
106
|
|
|
foreach ($configFiles as $k => $file) { |
107
|
|
|
$tests[] = [ |
108
|
|
|
Yaml::parse(file_get_contents($file)), |
109
|
|
|
Yaml::parse(file_get_contents($resultFiles[$k])), |
110
|
|
|
]; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
return $tests; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|