[Routing] Fix some wrong localized routes tests
This commit is contained in:
parent
2bd76fa32c
commit
99ae55ff1a
@ -87,8 +87,8 @@ class CompiledUrlGeneratorDumperTest extends TestCase
|
|||||||
public function testDumpWithSimpleLocalizedRoutes()
|
public function testDumpWithSimpleLocalizedRoutes()
|
||||||
{
|
{
|
||||||
$this->routeCollection->add('test', (new Route('/foo')));
|
$this->routeCollection->add('test', (new Route('/foo')));
|
||||||
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'test'));
|
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'test')->setRequirement('_locale', 'en'));
|
||||||
$this->routeCollection->add('test.nl', (new Route('/testen/is/leuk'))->setDefault('_locale', 'nl')->setDefault('_canonical_route', 'test'));
|
$this->routeCollection->add('test.nl', (new Route('/testen/is/leuk'))->setDefault('_locale', 'nl')->setDefault('_canonical_route', 'test')->setRequirement('_locale', 'nl'));
|
||||||
|
|
||||||
$code = $this->generatorDumper->dump();
|
$code = $this->generatorDumper->dump();
|
||||||
file_put_contents($this->testTmpFilepath, $code);
|
file_put_contents($this->testTmpFilepath, $code);
|
||||||
@ -120,7 +120,7 @@ class CompiledUrlGeneratorDumperTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');
|
$this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');
|
||||||
$this->expectExceptionMessage('Unable to generate a URL for the named route "test" as such route does not exist.');
|
$this->expectExceptionMessage('Unable to generate a URL for the named route "test" as such route does not exist.');
|
||||||
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'test'));
|
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'test')->setRequirement('_locale', 'en'));
|
||||||
|
|
||||||
$code = $this->generatorDumper->dump();
|
$code = $this->generatorDumper->dump();
|
||||||
file_put_contents($this->testTmpFilepath, $code);
|
file_put_contents($this->testTmpFilepath, $code);
|
||||||
@ -131,9 +131,9 @@ class CompiledUrlGeneratorDumperTest extends TestCase
|
|||||||
|
|
||||||
public function testDumpWithFallbackLocaleLocalizedRoutes()
|
public function testDumpWithFallbackLocaleLocalizedRoutes()
|
||||||
{
|
{
|
||||||
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'test'));
|
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'test')->setRequirement('_locale', 'en'));
|
||||||
$this->routeCollection->add('test.nl', (new Route('/testen/is/leuk'))->setDefault('_locale', 'nl')->setDefault('_canonical_route', 'test'));
|
$this->routeCollection->add('test.nl', (new Route('/testen/is/leuk'))->setDefault('_locale', 'nl')->setDefault('_canonical_route', 'test')->setRequirement('_locale', 'nl'));
|
||||||
$this->routeCollection->add('test.fr', (new Route('/tester/est/amusant'))->setDefault('_locale', 'fr')->setDefault('_canonical_route', 'test'));
|
$this->routeCollection->add('test.fr', (new Route('/tester/est/amusant'))->setDefault('_locale', 'fr')->setDefault('_canonical_route', 'test')->setRequirement('_locale', 'fr'));
|
||||||
|
|
||||||
$code = $this->generatorDumper->dump();
|
$code = $this->generatorDumper->dump();
|
||||||
file_put_contents($this->testTmpFilepath, $code);
|
file_put_contents($this->testTmpFilepath, $code);
|
||||||
@ -234,10 +234,10 @@ class CompiledUrlGeneratorDumperTest extends TestCase
|
|||||||
|
|
||||||
public function testDumpWithLocalizedRoutesPreserveTheGoodLocaleInTheUrl()
|
public function testDumpWithLocalizedRoutesPreserveTheGoodLocaleInTheUrl()
|
||||||
{
|
{
|
||||||
$this->routeCollection->add('foo.en', (new Route('/{_locale}/foo'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'foo'));
|
$this->routeCollection->add('foo.en', (new Route('/{_locale}/fork'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'foo')->setRequirement('_locale', 'en'));
|
||||||
$this->routeCollection->add('foo.fr', (new Route('/{_locale}/foo'))->setDefault('_locale', 'fr')->setDefault('_canonical_route', 'foo'));
|
$this->routeCollection->add('foo.fr', (new Route('/{_locale}/fourchette'))->setDefault('_locale', 'fr')->setDefault('_canonical_route', 'foo')->setRequirement('_locale', 'fr'));
|
||||||
$this->routeCollection->add('fun.en', (new Route('/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'fun'));
|
$this->routeCollection->add('fun.en', (new Route('/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'fun')->setRequirement('_locale', 'en'));
|
||||||
$this->routeCollection->add('fun.fr', (new Route('/amusant'))->setDefault('_locale', 'fr')->setDefault('_canonical_route', 'fun'));
|
$this->routeCollection->add('fun.fr', (new Route('/amusant'))->setDefault('_locale', 'fr')->setDefault('_canonical_route', 'fun')->setRequirement('_locale', 'fr'));
|
||||||
|
|
||||||
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump());
|
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump());
|
||||||
|
|
||||||
@ -246,10 +246,10 @@ class CompiledUrlGeneratorDumperTest extends TestCase
|
|||||||
|
|
||||||
$compiledUrlGenerator = new CompiledUrlGenerator(require $this->testTmpFilepath, $requestContext, null, null);
|
$compiledUrlGenerator = new CompiledUrlGenerator(require $this->testTmpFilepath, $requestContext, null, null);
|
||||||
|
|
||||||
$this->assertSame('/fr/foo', $compiledUrlGenerator->generate('foo'));
|
$this->assertSame('/fr/fourchette', $compiledUrlGenerator->generate('foo'));
|
||||||
$this->assertSame('/en/foo', $compiledUrlGenerator->generate('foo.en'));
|
$this->assertSame('/en/fork', $compiledUrlGenerator->generate('foo.en'));
|
||||||
$this->assertSame('/en/foo', $compiledUrlGenerator->generate('foo', ['_locale' => 'en']));
|
$this->assertSame('/en/fork', $compiledUrlGenerator->generate('foo', ['_locale' => 'en']));
|
||||||
$this->assertSame('/en/foo', $compiledUrlGenerator->generate('foo.fr', ['_locale' => 'en']));
|
$this->assertSame('/fr/fourchette', $compiledUrlGenerator->generate('foo.fr', ['_locale' => 'en']));
|
||||||
|
|
||||||
$this->assertSame('/amusant', $compiledUrlGenerator->generate('fun'));
|
$this->assertSame('/amusant', $compiledUrlGenerator->generate('fun'));
|
||||||
$this->assertSame('/fun', $compiledUrlGenerator->generate('fun.en'));
|
$this->assertSame('/fun', $compiledUrlGenerator->generate('fun.en'));
|
||||||
|
@ -90,8 +90,8 @@ class PhpGeneratorDumperTest extends TestCase
|
|||||||
public function testDumpWithSimpleLocalizedRoutes()
|
public function testDumpWithSimpleLocalizedRoutes()
|
||||||
{
|
{
|
||||||
$this->routeCollection->add('test', (new Route('/foo')));
|
$this->routeCollection->add('test', (new Route('/foo')));
|
||||||
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'test'));
|
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'test')->setRequirement('_locale', 'en'));
|
||||||
$this->routeCollection->add('test.nl', (new Route('/testen/is/leuk'))->setDefault('_locale', 'nl')->setDefault('_canonical_route', 'test'));
|
$this->routeCollection->add('test.nl', (new Route('/testen/is/leuk'))->setDefault('_locale', 'nl')->setDefault('_canonical_route', 'test')->setRequirement('_locale', 'nl'));
|
||||||
|
|
||||||
$code = $this->generatorDumper->dump([
|
$code = $this->generatorDumper->dump([
|
||||||
'class' => 'SimpleLocalizedProjectUrlGenerator',
|
'class' => 'SimpleLocalizedProjectUrlGenerator',
|
||||||
@ -126,7 +126,7 @@ class PhpGeneratorDumperTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');
|
$this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');
|
||||||
$this->expectExceptionMessage('Unable to generate a URL for the named route "test" as such route does not exist.');
|
$this->expectExceptionMessage('Unable to generate a URL for the named route "test" as such route does not exist.');
|
||||||
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'test'));
|
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'test')->setRequirement('_locale', 'en'));
|
||||||
|
|
||||||
$code = $this->generatorDumper->dump([
|
$code = $this->generatorDumper->dump([
|
||||||
'class' => 'RouteNotFoundLocalizedProjectUrlGenerator',
|
'class' => 'RouteNotFoundLocalizedProjectUrlGenerator',
|
||||||
@ -140,9 +140,9 @@ class PhpGeneratorDumperTest extends TestCase
|
|||||||
|
|
||||||
public function testDumpWithFallbackLocaleLocalizedRoutes()
|
public function testDumpWithFallbackLocaleLocalizedRoutes()
|
||||||
{
|
{
|
||||||
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'test'));
|
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'test')->setRequirement('_locale', 'en'));
|
||||||
$this->routeCollection->add('test.nl', (new Route('/testen/is/leuk'))->setDefault('_locale', 'nl')->setDefault('_canonical_route', 'test'));
|
$this->routeCollection->add('test.nl', (new Route('/testen/is/leuk'))->setDefault('_locale', 'nl')->setDefault('_canonical_route', 'test')->setRequirement('_locale', 'nl'));
|
||||||
$this->routeCollection->add('test.fr', (new Route('/tester/est/amusant'))->setDefault('_locale', 'fr')->setDefault('_canonical_route', 'test'));
|
$this->routeCollection->add('test.fr', (new Route('/tester/est/amusant'))->setDefault('_locale', 'fr')->setDefault('_canonical_route', 'test')->setRequirement('_locale', 'fr'));
|
||||||
|
|
||||||
$code = $this->generatorDumper->dump([
|
$code = $this->generatorDumper->dump([
|
||||||
'class' => 'FallbackLocaleLocalizedProjectUrlGenerator',
|
'class' => 'FallbackLocaleLocalizedProjectUrlGenerator',
|
||||||
@ -253,10 +253,10 @@ class PhpGeneratorDumperTest extends TestCase
|
|||||||
|
|
||||||
public function testDumpWithLocalizedRoutesPreserveTheGoodLocaleInTheUrl()
|
public function testDumpWithLocalizedRoutesPreserveTheGoodLocaleInTheUrl()
|
||||||
{
|
{
|
||||||
$this->routeCollection->add('foo.en', (new Route('/{_locale}/foo'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'foo'));
|
$this->routeCollection->add('foo.en', (new Route('/{_locale}/fork'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'foo')->setRequirement('_locale', 'en'));
|
||||||
$this->routeCollection->add('foo.fr', (new Route('/{_locale}/foo'))->setDefault('_locale', 'fr')->setDefault('_canonical_route', 'foo'));
|
$this->routeCollection->add('foo.fr', (new Route('/{_locale}/fourchette'))->setDefault('_locale', 'fr')->setDefault('_canonical_route', 'foo')->setRequirement('_locale', 'fr'));
|
||||||
$this->routeCollection->add('fun.en', (new Route('/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'fun'));
|
$this->routeCollection->add('fun.en', (new Route('/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'fun')->setRequirement('_locale', 'en'));
|
||||||
$this->routeCollection->add('fun.fr', (new Route('/amusant'))->setDefault('_locale', 'fr')->setDefault('_canonical_route', 'fun'));
|
$this->routeCollection->add('fun.fr', (new Route('/amusant'))->setDefault('_locale', 'fr')->setDefault('_canonical_route', 'fun')->setRequirement('_locale', 'fr'));
|
||||||
|
|
||||||
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump([
|
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump([
|
||||||
'class' => 'PreserveTheGoodLocaleInTheUrlGenerator',
|
'class' => 'PreserveTheGoodLocaleInTheUrlGenerator',
|
||||||
@ -268,10 +268,10 @@ class PhpGeneratorDumperTest extends TestCase
|
|||||||
|
|
||||||
$phpGenerator = new \PreserveTheGoodLocaleInTheUrlGenerator($requestContext);
|
$phpGenerator = new \PreserveTheGoodLocaleInTheUrlGenerator($requestContext);
|
||||||
|
|
||||||
$this->assertSame('/fr/foo', $phpGenerator->generate('foo'));
|
$this->assertSame('/fr/fourchette', $phpGenerator->generate('foo'));
|
||||||
$this->assertSame('/en/foo', $phpGenerator->generate('foo.en'));
|
$this->assertSame('/en/fork', $phpGenerator->generate('foo.en'));
|
||||||
$this->assertSame('/en/foo', $phpGenerator->generate('foo', ['_locale' => 'en']));
|
$this->assertSame('/en/fork', $phpGenerator->generate('foo', ['_locale' => 'en']));
|
||||||
$this->assertSame('/en/foo', $phpGenerator->generate('foo.fr', ['_locale' => 'en']));
|
$this->assertSame('/fr/fourchette', $phpGenerator->generate('foo.fr', ['_locale' => 'en']));
|
||||||
|
|
||||||
$this->assertSame('/amusant', $phpGenerator->generate('fun'));
|
$this->assertSame('/amusant', $phpGenerator->generate('fun'));
|
||||||
$this->assertSame('/fun', $phpGenerator->generate('fun.en'));
|
$this->assertSame('/fun', $phpGenerator->generate('fun.en'));
|
||||||
|
@ -171,6 +171,7 @@ class UrlGeneratorTest extends TestCase
|
|||||||
foreach (['hr' => '/foo', 'en' => '/bar'] as $locale => $path) {
|
foreach (['hr' => '/foo', 'en' => '/bar'] as $locale => $path) {
|
||||||
$localizedRoute = clone $route;
|
$localizedRoute = clone $route;
|
||||||
$localizedRoute->setDefault('_locale', $locale);
|
$localizedRoute->setDefault('_locale', $locale);
|
||||||
|
$localizedRoute->setRequirement('_locale', $locale);
|
||||||
$localizedRoute->setDefault('_canonical_route', $name);
|
$localizedRoute->setDefault('_canonical_route', $name);
|
||||||
$localizedRoute->setPath($path);
|
$localizedRoute->setPath($path);
|
||||||
$routes->add($name.'.'.$locale, $localizedRoute);
|
$routes->add($name.'.'.$locale, $localizedRoute);
|
||||||
@ -195,6 +196,7 @@ class UrlGeneratorTest extends TestCase
|
|||||||
foreach (['hr' => '/foo', 'en' => '/bar'] as $locale => $path) {
|
foreach (['hr' => '/foo', 'en' => '/bar'] as $locale => $path) {
|
||||||
$localizedRoute = clone $route;
|
$localizedRoute = clone $route;
|
||||||
$localizedRoute->setDefault('_locale', $locale);
|
$localizedRoute->setDefault('_locale', $locale);
|
||||||
|
$localizedRoute->setRequirement('_locale', $locale);
|
||||||
$localizedRoute->setDefault('_canonical_route', $name);
|
$localizedRoute->setDefault('_canonical_route', $name);
|
||||||
$localizedRoute->setPath($path);
|
$localizedRoute->setPath($path);
|
||||||
$routes->add($name.'.'.$locale, $localizedRoute);
|
$routes->add($name.'.'.$locale, $localizedRoute);
|
||||||
@ -219,6 +221,7 @@ class UrlGeneratorTest extends TestCase
|
|||||||
foreach (['hr' => '/foo', 'en' => '/bar'] as $locale => $path) {
|
foreach (['hr' => '/foo', 'en' => '/bar'] as $locale => $path) {
|
||||||
$localizedRoute = clone $route;
|
$localizedRoute = clone $route;
|
||||||
$localizedRoute->setDefault('_locale', $locale);
|
$localizedRoute->setDefault('_locale', $locale);
|
||||||
|
$localizedRoute->setRequirement('_locale', $locale);
|
||||||
$localizedRoute->setDefault('_canonical_route', $name);
|
$localizedRoute->setDefault('_canonical_route', $name);
|
||||||
$localizedRoute->setPath($path);
|
$localizedRoute->setPath($path);
|
||||||
$routes->add($name.'.'.$locale, $localizedRoute);
|
$routes->add($name.'.'.$locale, $localizedRoute);
|
||||||
@ -240,18 +243,18 @@ class UrlGeneratorTest extends TestCase
|
|||||||
{
|
{
|
||||||
$routeCollection = new RouteCollection();
|
$routeCollection = new RouteCollection();
|
||||||
|
|
||||||
$routeCollection->add('foo.en', (new Route('/{_locale}/foo'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'foo'));
|
$routeCollection->add('foo.en', (new Route('/{_locale}/fork'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'foo')->setRequirement('_locale', 'en'));
|
||||||
$routeCollection->add('foo.fr', (new Route('/{_locale}/foo'))->setDefault('_locale', 'fr')->setDefault('_canonical_route', 'foo'));
|
$routeCollection->add('foo.fr', (new Route('/{_locale}/fourchette'))->setDefault('_locale', 'fr')->setDefault('_canonical_route', 'foo')->setRequirement('_locale', 'fr'));
|
||||||
$routeCollection->add('fun.en', (new Route('/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'fun'));
|
$routeCollection->add('fun.en', (new Route('/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'fun')->setRequirement('_locale', 'en'));
|
||||||
$routeCollection->add('fun.fr', (new Route('/amusant'))->setDefault('_locale', 'fr')->setDefault('_canonical_route', 'fun'));
|
$routeCollection->add('fun.fr', (new Route('/amusant'))->setDefault('_locale', 'fr')->setDefault('_canonical_route', 'fun')->setRequirement('_locale', 'fr'));
|
||||||
|
|
||||||
$urlGenerator = $this->getGenerator($routeCollection);
|
$urlGenerator = $this->getGenerator($routeCollection);
|
||||||
$urlGenerator->getContext()->setParameter('_locale', 'fr');
|
$urlGenerator->getContext()->setParameter('_locale', 'fr');
|
||||||
|
|
||||||
$this->assertSame('/app.php/fr/foo', $urlGenerator->generate('foo'));
|
$this->assertSame('/app.php/fr/fourchette', $urlGenerator->generate('foo'));
|
||||||
$this->assertSame('/app.php/en/foo', $urlGenerator->generate('foo.en'));
|
$this->assertSame('/app.php/en/fork', $urlGenerator->generate('foo.en'));
|
||||||
$this->assertSame('/app.php/en/foo', $urlGenerator->generate('foo', ['_locale' => 'en']));
|
$this->assertSame('/app.php/en/fork', $urlGenerator->generate('foo', ['_locale' => 'en']));
|
||||||
$this->assertSame('/app.php/en/foo', $urlGenerator->generate('foo.fr', ['_locale' => 'en']));
|
$this->assertSame('/app.php/fr/fourchette', $urlGenerator->generate('foo.fr', ['_locale' => 'en']));
|
||||||
|
|
||||||
$this->assertSame('/app.php/amusant', $urlGenerator->generate('fun'));
|
$this->assertSame('/app.php/amusant', $urlGenerator->generate('fun'));
|
||||||
$this->assertSame('/app.php/fun', $urlGenerator->generate('fun.en'));
|
$this->assertSame('/app.php/fun', $urlGenerator->generate('fun.en'));
|
||||||
@ -278,6 +281,7 @@ class UrlGeneratorTest extends TestCase
|
|||||||
foreach (['hr' => '/foo', 'en' => '/bar'] as $locale => $path) {
|
foreach (['hr' => '/foo', 'en' => '/bar'] as $locale => $path) {
|
||||||
$localizedRoute = clone $route;
|
$localizedRoute = clone $route;
|
||||||
$localizedRoute->setDefault('_locale', $locale);
|
$localizedRoute->setDefault('_locale', $locale);
|
||||||
|
$localizedRoute->setRequirement('_locale', $locale);
|
||||||
$localizedRoute->setDefault('_canonical_route', $name);
|
$localizedRoute->setDefault('_canonical_route', $name);
|
||||||
$localizedRoute->setPath($path);
|
$localizedRoute->setPath($path);
|
||||||
$routes->add($name.'.'.$locale, $localizedRoute);
|
$routes->add($name.'.'.$locale, $localizedRoute);
|
||||||
|
Reference in New Issue
Block a user