Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #202 from damienflament/conflict-resolving
Browse files Browse the repository at this point in the history
Implement the changes made in symfony-cmf/routing-auto#91
  • Loading branch information
dantleech authored Jun 19, 2017
2 parents 47d467c + f85c39d commit c30ce68
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Tests/Resources/app/cache
Tests/Resources/app/logs
tests/Resources/app/cache
tests/Resources/app/logs
composer.lock
vendor
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.*"
},
Expand All @@ -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",
Expand All @@ -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"
]
}
}
14 changes: 14 additions & 0 deletions src/Adapter/PhpcrOdmAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
21 changes: 21 additions & 0 deletions tests/Functional/EventListener/AutoRouteListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 [
Expand Down
21 changes: 21 additions & 0 deletions tests/Resources/Document/ConflictProneArticle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2017 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document;

use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR;

/**
* @PHPCR\Document(translator="child", referenceable=true)
*/
class ConflictProneArticle extends Article
{
}
14 changes: 11 additions & 3 deletions tests/Resources/app/config/routing_auto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Blog:
blog_title: [content_method, { method: getTitle } ]

Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Post:
definitions:
view:
definitions:
view:
uri_schema: /blog/{blog_title}/{post_date}/{post_title}
token_providers:
blog_title: [content_method, { method: getBlogTitle } ]
Expand All @@ -18,7 +18,7 @@ Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Post:
conflict_resolver: [auto_increment, { }]

Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Article:
definitions:
definitions:
view:
uri_schema: /articles/{article_locale}/{article_title}
defaults:
Expand All @@ -35,6 +35,14 @@ Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Article:
article_title: [content_method, { method: getTitle } ]
article_locale: [content_locale, {} ]

Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\ConflictProneArticle:
definitions:
view:
uri_schema: /conflict-prone-articles/{article_title}
token_providers:
article_title: [content_method, { method: getTitle } ]
conflict_resolver: [auto_increment]

Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\SeoArticle:
definitions:
view:
Expand Down
38 changes: 38 additions & 0 deletions tests/Unit/Adapter/PhpcrOdmAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,44 @@ public function testCompareRouteContent($isMatch)
$this->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')
Expand Down

0 comments on commit c30ce68

Please sign in to comment.