Add tests to ensure defaultLocale is properly passed to the URL generator
This commit is contained in:
parent
16c9bafee4
commit
9aa66e2f59
@ -22,10 +22,26 @@ class RouterTest extends TestCase
|
||||
|
||||
private $loader = null;
|
||||
|
||||
private $cacheDir;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
|
||||
$this->router = new Router($this->loader, 'routing.yml');
|
||||
|
||||
$this->cacheDir = sys_get_temp_dir().\DIRECTORY_SEPARATOR.uniqid('router_', true);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
if (is_dir($this->cacheDir)) {
|
||||
array_map('unlink', glob($this->cacheDir.\DIRECTORY_SEPARATOR.'*'));
|
||||
rmdir($this->cacheDir);
|
||||
}
|
||||
|
||||
$this->loader = null;
|
||||
$this->router = null;
|
||||
$this->cacheDir = null;
|
||||
}
|
||||
|
||||
public function testSetOptionsWithSupportedOptions()
|
||||
@ -132,4 +148,68 @@ class RouterTest extends TestCase
|
||||
|
||||
$this->router->matchRequest(Request::create('/'));
|
||||
}
|
||||
|
||||
public function testDefaultLocaleIsPassedToGeneratorClass()
|
||||
{
|
||||
$this->loader->expects($this->once())
|
||||
->method('load')->with('routing.yml', null)
|
||||
->willReturn(new RouteCollection());
|
||||
|
||||
$router = new Router($this->loader, 'routing.yml', [
|
||||
'cache_dir' => null,
|
||||
], null, null, 'hr');
|
||||
|
||||
$generator = $router->getGenerator();
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Routing\Generator\UrlGeneratorInterface', $generator);
|
||||
|
||||
$p = new \ReflectionProperty($generator, 'defaultLocale');
|
||||
$p->setAccessible(true);
|
||||
|
||||
$this->assertSame('hr', $p->getValue($generator));
|
||||
}
|
||||
|
||||
public function testDefaultLocaleIsPassedToCompiledGeneratorCacheClass()
|
||||
{
|
||||
$this->loader->expects($this->once())
|
||||
->method('load')->with('routing.yml', null)
|
||||
->willReturn(new RouteCollection());
|
||||
|
||||
$router = new Router($this->loader, 'routing.yml', [
|
||||
'cache_dir' => $this->cacheDir,
|
||||
], null, null, 'hr');
|
||||
|
||||
$generator = $router->getGenerator();
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Routing\Generator\UrlGeneratorInterface', $generator);
|
||||
|
||||
$p = new \ReflectionProperty($generator, 'defaultLocale');
|
||||
$p->setAccessible(true);
|
||||
|
||||
$this->assertSame('hr', $p->getValue($generator));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testDefaultLocaleIsPassedToNotCompiledGeneratorCacheClass()
|
||||
{
|
||||
$this->loader->expects($this->once())
|
||||
->method('load')->with('routing.yml', null)
|
||||
->willReturn(new RouteCollection());
|
||||
|
||||
$router = new Router($this->loader, 'routing.yml', [
|
||||
'cache_dir' => $this->cacheDir,
|
||||
'generator_class' => 'Symfony\Component\Routing\Generator\UrlGenerator',
|
||||
], null, null, 'hr');
|
||||
|
||||
$generator = $router->getGenerator();
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Routing\Generator\UrlGeneratorInterface', $generator);
|
||||
|
||||
$p = new \ReflectionProperty($generator, 'defaultLocale');
|
||||
$p->setAccessible(true);
|
||||
|
||||
$this->assertSame('hr', $p->getValue($generator));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user