diff --git a/.gitignore b/.gitignore index 26ad278..31f9b0b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -Tests/Resources/app/cache -Tests/Resources/app/logs +tests/Resources/app/cache +tests/Resources/app/logs composer.lock vendor diff --git a/composer.json b/composer.json index 394d6f0..5a4e764 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "require": { "php": "^5.6|^7.0", "symfony/framework-bundle": "^2.8|^3.0", - "symfony-cmf/routing-auto": "^2.0", + "symfony-cmf/routing-auto": "^2.0.0-RC2", "symfony-cmf/routing-bundle": "^1.2.0|^2.0", "aferrandini/urlizer": "1.0.*" }, @@ -24,8 +24,6 @@ "matthiasnoback/symfony-config-test": "^1.3.1", "doctrine/phpcr-odm": "^1.3" }, - "minimum-stability": "RC", - "prefer-stable": true, "suggest": { "doctrine/phpcr-odm": "To enable support for the PHPCR ODM documents", "doctrine/phpcr-bundle": "To enable support for the PHPCR ODM documents", @@ -45,5 +43,11 @@ "branch-alias": { "dev-master": "2.0-dev" } + }, + "scripts": { + "test": [ + "vendor/symfony-cmf/testing/bin/travis/phpcr_odm_doctrine_dbal.sh", + "SYMFONY_PHPUNIT_REMOVE=\"symfony/yaml\" vendor/bin/simple-phpunit" + ] } } diff --git a/src/Adapter/PhpcrOdmAdapter.php b/src/Adapter/PhpcrOdmAdapter.php index 7029462..5a6ff94 100644 --- a/src/Adapter/PhpcrOdmAdapter.php +++ b/src/Adapter/PhpcrOdmAdapter.php @@ -200,6 +200,20 @@ public function compareAutoRouteContent(AutoRouteInterface $autoRoute, $contentD return false; } + /** + * {@inheritdoc} + */ + public function compareAutoRouteLocale(AutoRouteInterface $autoRoute, $locale) + { + $autoRouteLocale = $autoRoute->getLocale(); + + if ($autoRouteLocale === self::TAG_NO_MULTILANG) { + $autoRouteLocale = null; + } + + return $autoRouteLocale === $locale; + } + /** * {@inheritdoc} */ diff --git a/tests/Functional/EventListener/AutoRouteListenerTest.php b/tests/Functional/EventListener/AutoRouteListenerTest.php index 6c904e1..150854e 100644 --- a/tests/Functional/EventListener/AutoRouteListenerTest.php +++ b/tests/Functional/EventListener/AutoRouteListenerTest.php @@ -17,6 +17,7 @@ use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Article; use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Blog; use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\ConcreteContent; +use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\ConflictProneArticle; use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Page; use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Post; use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\SeoArticle; @@ -359,6 +360,26 @@ public function testUpdateMultilangArticle($data, $expectedPaths) } } + public function testResolveConflictOnSingleMultilangArticle() + { + $article = new ConflictProneArticle(); + $article->path = '/test/article'; + $article->title = 'Weekend'; + $this->getDm()->persist($article); + $this->getDm()->bindTranslation($article, 'fr'); + + $article->title = 'Weekend'; + $this->getDm()->bindTranslation($article, 'en'); + + $this->getDm()->flush(); + + $route = $this->getDm()->find(AutoRoute::class, 'test/auto-route/conflict-prone-articles/weekend'); + $this->assertNotNull($route); + + $route = $this->getDm()->find(AutoRoute::class, 'test/auto-route/conflict-prone-articles/weekend-1'); + $this->assertNotNull($route); + } + public function provideLeaveRedirect() { return [ diff --git a/tests/Resources/Document/ConflictProneArticle.php b/tests/Resources/Document/ConflictProneArticle.php new file mode 100644 index 0000000..ebb238e --- /dev/null +++ b/tests/Resources/Document/ConflictProneArticle.php @@ -0,0 +1,21 @@ +adapter->compareAutoRouteContent($this->route->reveal(), $this->contentDocument); } + public function provideCompareAutoRouteLocale() + { + return [ + 'a not localized route and a null locale' => [ + PhpcrOdmAdapter::TAG_NO_MULTILANG, + null, + true, + ], + 'a not localized route and a locale' => [ + PhpcrOdmAdapter::TAG_NO_MULTILANG, + 'en', + false, + ], + 'a localized route and the matching locale' => [ + 'en', + 'en', + true, + ], + 'a localized route and a not matching locale' => [ + 'en', + 'fr', + false, + ], + ]; + } + + /** + * @dataProvider provideCompareAutoRouteLocale + */ + public function testCompareAutoRouteLocale($autoRouteLocale, $locale, $shouldMatch) + { + $this->route->getLocale()->willReturn($autoRouteLocale); + + $areMatching = $this->adapter->compareAutoRouteLocale($this->route->reveal(), $locale); + + $this->assertSame($shouldMatch, $areMatching); + } + public function testGetReferringRoutes() { $this->dm->getReferrers($this->contentDocument, null, null, null, 'Symfony\Cmf\Component\RoutingAuto\Model\AutoRouteInterface')