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

Commit c30ce68

Browse files
authored
Merge pull request #202 from damienflament/conflict-resolving
Implement the changes made in symfony-cmf/routing-auto#91
2 parents 47d467c + f85c39d commit c30ce68

File tree

7 files changed

+114
-8
lines changed

7 files changed

+114
-8
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Tests/Resources/app/cache
2-
Tests/Resources/app/logs
1+
tests/Resources/app/cache
2+
tests/Resources/app/logs
33
composer.lock
44
vendor

composer.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"require": {
1313
"php": "^5.6|^7.0",
1414
"symfony/framework-bundle": "^2.8|^3.0",
15-
"symfony-cmf/routing-auto": "^2.0",
15+
"symfony-cmf/routing-auto": "^2.0.0-RC2",
1616
"symfony-cmf/routing-bundle": "^1.2.0|^2.0",
1717
"aferrandini/urlizer": "1.0.*"
1818
},
@@ -24,8 +24,6 @@
2424
"matthiasnoback/symfony-config-test": "^1.3.1",
2525
"doctrine/phpcr-odm": "^1.3"
2626
},
27-
"minimum-stability": "RC",
28-
"prefer-stable": true,
2927
"suggest": {
3028
"doctrine/phpcr-odm": "To enable support for the PHPCR ODM documents",
3129
"doctrine/phpcr-bundle": "To enable support for the PHPCR ODM documents",
@@ -45,5 +43,11 @@
4543
"branch-alias": {
4644
"dev-master": "2.0-dev"
4745
}
46+
},
47+
"scripts": {
48+
"test": [
49+
"vendor/symfony-cmf/testing/bin/travis/phpcr_odm_doctrine_dbal.sh",
50+
"SYMFONY_PHPUNIT_REMOVE=\"symfony/yaml\" vendor/bin/simple-phpunit"
51+
]
4852
}
4953
}

src/Adapter/PhpcrOdmAdapter.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,20 @@ public function compareAutoRouteContent(AutoRouteInterface $autoRoute, $contentD
200200
return false;
201201
}
202202

203+
/**
204+
* {@inheritdoc}
205+
*/
206+
public function compareAutoRouteLocale(AutoRouteInterface $autoRoute, $locale)
207+
{
208+
$autoRouteLocale = $autoRoute->getLocale();
209+
210+
if ($autoRouteLocale === self::TAG_NO_MULTILANG) {
211+
$autoRouteLocale = null;
212+
}
213+
214+
return $autoRouteLocale === $locale;
215+
}
216+
203217
/**
204218
* {@inheritdoc}
205219
*/

tests/Functional/EventListener/AutoRouteListenerTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Article;
1818
use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Blog;
1919
use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\ConcreteContent;
20+
use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\ConflictProneArticle;
2021
use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Page;
2122
use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Post;
2223
use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\SeoArticle;
@@ -359,6 +360,26 @@ public function testUpdateMultilangArticle($data, $expectedPaths)
359360
}
360361
}
361362

363+
public function testResolveConflictOnSingleMultilangArticle()
364+
{
365+
$article = new ConflictProneArticle();
366+
$article->path = '/test/article';
367+
$article->title = 'Weekend';
368+
$this->getDm()->persist($article);
369+
$this->getDm()->bindTranslation($article, 'fr');
370+
371+
$article->title = 'Weekend';
372+
$this->getDm()->bindTranslation($article, 'en');
373+
374+
$this->getDm()->flush();
375+
376+
$route = $this->getDm()->find(AutoRoute::class, 'test/auto-route/conflict-prone-articles/weekend');
377+
$this->assertNotNull($route);
378+
379+
$route = $this->getDm()->find(AutoRoute::class, 'test/auto-route/conflict-prone-articles/weekend-1');
380+
$this->assertNotNull($route);
381+
}
382+
362383
public function provideLeaveRedirect()
363384
{
364385
return [
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony CMF package.
5+
*
6+
* (c) 2011-2017 Symfony CMF
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document;
13+
14+
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR;
15+
16+
/**
17+
* @PHPCR\Document(translator="child", referenceable=true)
18+
*/
19+
class ConflictProneArticle extends Article
20+
{
21+
}

tests/Resources/app/config/routing_auto.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Blog:
88
blog_title: [content_method, { method: getTitle } ]
99

1010
Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Post:
11-
definitions:
12-
view:
11+
definitions:
12+
view:
1313
uri_schema: /blog/{blog_title}/{post_date}/{post_title}
1414
token_providers:
1515
blog_title: [content_method, { method: getBlogTitle } ]
@@ -18,7 +18,7 @@ Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Post:
1818
conflict_resolver: [auto_increment, { }]
1919

2020
Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Article:
21-
definitions:
21+
definitions:
2222
view:
2323
uri_schema: /articles/{article_locale}/{article_title}
2424
defaults:
@@ -35,6 +35,14 @@ Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Article:
3535
article_title: [content_method, { method: getTitle } ]
3636
article_locale: [content_locale, {} ]
3737

38+
Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\ConflictProneArticle:
39+
definitions:
40+
view:
41+
uri_schema: /conflict-prone-articles/{article_title}
42+
token_providers:
43+
article_title: [content_method, { method: getTitle } ]
44+
conflict_resolver: [auto_increment]
45+
3846
Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\SeoArticle:
3947
definitions:
4048
view:

tests/Unit/Adapter/PhpcrOdmAdapterTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,44 @@ public function testCompareRouteContent($isMatch)
224224
$this->adapter->compareAutoRouteContent($this->route->reveal(), $this->contentDocument);
225225
}
226226

227+
public function provideCompareAutoRouteLocale()
228+
{
229+
return [
230+
'a not localized route and a null locale' => [
231+
PhpcrOdmAdapter::TAG_NO_MULTILANG,
232+
null,
233+
true,
234+
],
235+
'a not localized route and a locale' => [
236+
PhpcrOdmAdapter::TAG_NO_MULTILANG,
237+
'en',
238+
false,
239+
],
240+
'a localized route and the matching locale' => [
241+
'en',
242+
'en',
243+
true,
244+
],
245+
'a localized route and a not matching locale' => [
246+
'en',
247+
'fr',
248+
false,
249+
],
250+
];
251+
}
252+
253+
/**
254+
* @dataProvider provideCompareAutoRouteLocale
255+
*/
256+
public function testCompareAutoRouteLocale($autoRouteLocale, $locale, $shouldMatch)
257+
{
258+
$this->route->getLocale()->willReturn($autoRouteLocale);
259+
260+
$areMatching = $this->adapter->compareAutoRouteLocale($this->route->reveal(), $locale);
261+
262+
$this->assertSame($shouldMatch, $areMatching);
263+
}
264+
227265
public function testGetReferringRoutes()
228266
{
229267
$this->dm->getReferrers($this->contentDocument, null, null, null, 'Symfony\Cmf\Component\RoutingAuto\Model\AutoRouteInterface')

0 commit comments

Comments
 (0)