-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathPostfixInflectorTest.php
More file actions
69 lines (57 loc) · 3.15 KB
/
PostfixInflectorTest.php
File metadata and controls
69 lines (57 loc) · 3.15 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
<?php
namespace BeSimple\I18nRoutingBundle\Tests\Routing\RouteGenerator\NameInflector;
use BeSimple\I18nRoutingBundle\Routing\RouteGenerator\NameInflector\PostfixInflector;
class PostfixInflectorTest extends \PHPUnit_Framework_TestCase
{
public function testInflect()
{
$inflector = new PostfixInflector();
$this->assertSame(
'route.name.be-simple-i18n.en',
$inflector->inflect('route.name', 'en')
);
$this->assertSame(
'route.name.be-simple-i18n.nl',
$inflector->inflect('route.name', 'nl')
);
}
public function testUnInflect()
{
$inflector = new PostfixInflector();
$this->assertSame('test', $inflector->unInflect('test' . $inflector::INFIX . 'nl', $locale = 'nl'));
}
public function testisInflected()
{
$inflector = new PostfixInflector();
$this->assertFalse($inflector->isInflected('test', 'nl'), "'test' is not at BeSimple route");
$this->assertTrue($inflector->isInflected('test' . PostfixInflector::INFIX . 'nl', 'nl'), 'Should have been a BeSimple route.');
}
public function testIsValidMatch()
{
$inflector = new PostfixInflector();
$this->assertTrue($inflector->isValidMatch('test' . PostfixInflector::INFIX . 'nl', 'nl'));
$this->assertFalse($inflector->isValidMatch('test' . PostfixInflector::INFIX . 'nl', 'en'));
// see if it works with more than one locale in a collection, all with the same path spec
$routeMock = $this->getMockBuilder('Symfony\Component\Routing\Route')
->disableOriginalConstructor()->getMock();
$routeMock->expects($this->any())->method('getPath')->willReturn('/{_locale}/sites');
$routes = [
$inflector->inflect('sites', 'nl') => $routeMock,
$inflector->inflect('sites', 'de') => $routeMock,
$inflector->inflect('sites', 'se') => $routeMock,
$inflector->inflect('sites', 'fr') => $routeMock,
$inflector->inflect('sites', 'es') => $routeMock,
];
$routeCollection = $this->getMock('Symfony\Component\Routing\RouteCollection');
$routeCollection->expects($this->any())->method('getIterator')->willReturn(new \ArrayIterator($routes));
$this->assertTrue($inflector->isValidMatch('sites' . PostfixInflector::INFIX . 'nl', 'nl'));
$this->assertTrue($inflector->isValidMatch('sites' . PostfixInflector::INFIX . 'de', 'de'));
$this->assertTrue($inflector->isValidMatch('sites' . PostfixInflector::INFIX . 'se', 'se'));
$this->assertTrue($inflector->isValidMatch('sites' . PostfixInflector::INFIX . 'fr', 'fr'));
$this->assertTrue($inflector->isValidMatch('sites' . PostfixInflector::INFIX . 'es', 'es'));
$this->assertFalse($inflector->isValidMatch('sites' . PostfixInflector::INFIX . 'es', 'nl'));
$this->assertFalse($inflector->isValidMatch('sites' . PostfixInflector::INFIX . 'de', 'nl'));
$this->assertFalse($inflector->isValidMatch('sites' . PostfixInflector::INFIX . 'fr', 'nl'));
$this->assertFalse($inflector->isValidMatch('sites' . PostfixInflector::INFIX . 'se', 'nl'));
}
}