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

Commit 11dc7bf

Browse files
committed
Merge pull request #127 from symfony-cmf/fix_handling_of_root_parents
Fix the case when the uri is in fact the root
2 parents c41cae7 + 056025a commit 11dc7bf

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

Adapter/PhpcrOdmAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function removeAutoRoute(AutoRouteInterface $autoRoute)
117117
public function createAutoRoute($uri, $contentDocument, $autoRouteTag)
118118
{
119119
$path = $this->baseRoutePath;
120-
$parentDocument = $this->dm->find(null, $path);
120+
$document = $parentDocument = $this->dm->find(null, $path);
121121
$segments = preg_split('#/#', $uri, null, PREG_SPLIT_NO_EMPTY);
122122
$headName = array_pop($segments);
123123
foreach ($segments as $segment) {

Tests/Functional/EventListener/AutoRouteListenerTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\SeoArticleMultilang;
2323
use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\SeoArticle;
2424
use Symfony\Cmf\Component\RoutingAuto\Model\AutoRouteInterface;
25+
use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Page;
2526

2627
class AutoRouteListenerTest extends BaseTestCase
2728
{
@@ -467,6 +468,20 @@ public function testConflictResolverAutoIncrement()
467468
}
468469
}
469470

471+
public function testCreationOfChildOnRoot()
472+
{
473+
$page = new Page;
474+
$page->title = 'Home';
475+
$page->path = '/test/home';
476+
$this->getDm()->persist($page);
477+
$this->getDm()->flush();
478+
479+
$expectedRoute = '/test/auto-route/home';
480+
$route = $this->getDm()->find('Symfony\Cmf\Bundle\RoutingAutoBundle\Model\AutoRoute', $expectedRoute);
481+
482+
$this->assertNotNull($route);
483+
}
484+
470485
/**
471486
* @expectedException Symfony\Cmf\Component\RoutingAuto\ConflictResolver\Exception\ExistingUriException
472487
*/

Tests/Resources/Document/Page.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony CMF package.
5+
*
6+
* (c) 2011-2014 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+
13+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document;
14+
15+
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR;
16+
17+
/**
18+
* Document mapped to /{title} schema
19+
*
20+
* @PHPCR\Document(referenceable=true)
21+
*/
22+
class Page extends SeoArticle
23+
{
24+
}
25+

Tests/Resources/app/config/routing_auto.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@ Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\AbstractContent:
3535
uri_schema: /articles/{article_title}
3636
token_providers:
3737
article_title: [content_method, { method: getTitle } ]
38+
39+
Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Page:
40+
uri_schema: /{title}
41+
token_providers:
42+
title: [content_method, { method: getTitle } ]

0 commit comments

Comments
 (0)