-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathYamlFileLoaderTest.php
More file actions
132 lines (108 loc) · 3.72 KB
/
YamlFileLoaderTest.php
File metadata and controls
132 lines (108 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
namespace BeSimple\I18nRoutingBundle\Tests\Routing\Loader;
use BeSimple\I18nRoutingBundle\Routing\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Routing\Route;
/**
* @author Francis Besset <francis.besset@gmail.com>
*/
class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
{
public function testSupports()
{
$loader = $this->getYamlFileLoader();
$this->assertTrue($loader->supports('foo.yml', 'be_simple_i18n'));
$this->assertTrue($loader->supports('foo.yaml', 'be_simple_i18n'));
$this->assertTrue($loader->supports('foo.bar.yml', 'be_simple_i18n'));
$this->assertFalse($loader->supports('foo.yml'));
$this->assertFalse($loader->supports('foo.yml', 'yaml'));
$this->assertFalse($loader->supports('foo.xml', 'be_simple_i18n'));
}
/**
* @expectedException \InvalidArgumentException
* @dataProvider getPathsToInvalidFiles()
*/
public function testLoadThrowsInvalidArgumentExceptionWithInvalidFile($filePath)
{
$this->load($filePath);
}
public function getPathsToInvalidFiles()
{
return array(
array('nonvalid_array.yml'),
array('nonvalid_extrakeys.yml'),
array('nonvalid_type_without_resource.yml'),
array('nonvalid_without_resource_and_locales.yml'),
);
}
/**
* @expectedException \Symfony\Component\Config\Exception\FileLoaderLoadException
* @dataProvider getPathsToInvalidImportFiles()
*/
public function testLoadThrowsFileLoaderLoadExceptionWithInvalidFile($filePath)
{
$this->load($filePath);
}
public function getPathsToInvalidImportFiles()
{
return array(array('nonvalid_resource_with_locales.yml'),);
}
public function testBasicI18nRoute()
{
$routes = $this->load('basic_i18n_route.yml')->all();
$this->assertEquals(3, count($routes));
$this->assertEquals(
array(
'homepage_locale.be-simple-i18n.en' => new Route('/en/', array(
'_locale' => 'en',
'_controller' => 'TestBundle:Frontend:homepageLocale'
)),
'homepage_locale.be-simple-i18n.de' => new Route('/de/', array(
'_locale' => 'de',
'_controller' => 'TestBundle:Frontend:homepageLocale'
)),
'homepage_locale.be-simple-i18n.fr' => new Route('/fr/', array(
'_locale' => 'fr',
'_controller' => 'TestBundle:Frontend:homepageLocale'
)),
),
$routes
);
}
public function testBasicRoutes()
{
$routes = $this->load('basic_routes.yml')->all();
$this->assertEquals(4, count($routes));
}
public function testFullLocale()
{
$routes = $this->load('full_locale.yml')->all();
$this->assertEquals(3, count($routes));
}
public function testImport()
{
$routes = $this->load('import.yml')->all();
$this->assertEquals(6, count($routes));
}
public function testImportPrefix()
{
$routes = $this->load('import_prefix.yml')->all();
$this->assertEquals(6, count($routes));
}
public function testImportPrefixLocalized()
{
$routes = $this->load('import_prefix_locale.yml')->all();
$this->assertEquals(6, count($routes));
}
private function load($file)
{
return $this
->getYamlFileLoader()
->load($file, 'be_simple_i18n')
;
}
private function getYamlFileLoader()
{
return new YamlFileLoader(new FileLocator(array(__DIR__.'/../../Fixtures')));
}
}