Skip to content

Commit

Permalink
Added child restriction to Route & RedirectRoute documents
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Feb 9, 2017
1 parent 926de06 commit 02a2349
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"require-dev": {
"symfony-cmf/testing": "^2.0",
"doctrine/phpcr-odm": "^1.4|^2.0",
"doctrine/phpcr-odm": "^1.4",
"symfony/phpunit-bridge": "^3.2",
"matthiasnoback/symfony-dependency-injection-test": "~0.6",
"matthiasnoback/symfony-config-test": "^1.3.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
https://github.com/doctrine/phpcr-odm/raw/master/doctrine-phpcr-odm-mapping.xsd"
>

<document name="Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\RedirectRoute">
<document name="Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\RedirectRoute" is-leaf="true">
<id name="id">
<generator strategy="PARENT"/>
</id>
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/doctrine-phpcr/Route.phpcr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<nodename name="name"/>
<parent-document name="parent"/>
<children name="children"/>
<child-class name="Symfony\Cmf\Component\Routing\RouteObjectInterface"/>
</document>

</doctrine-mapping>
24 changes: 23 additions & 1 deletion tests/Functional/Doctrine/Phpcr/RedirectRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\Functional\Doctrine\Phpcr;

use Doctrine\ODM\PHPCR\Document\Generic;
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\RedirectRoute;
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route;
use Symfony\Cmf\Bundle\RoutingBundle\Tests\Functional\BaseTestCase;
Expand All @@ -21,7 +22,7 @@ class RedirectRouteTest extends BaseTestCase
{
const ROUTE_ROOT = '/test/redirectroute';

public function setUp()
protected function setUp()
{
parent::setUp();
$this->db('PHPCR')->createTestNode();
Expand Down Expand Up @@ -59,6 +60,27 @@ public function testRedirectDoctrine()
$this->assertEquals(['test' => 'toast'], $defaults);
}

/**
* @expectedException \Doctrine\ODM\PHPCR\Exception\OutOfBoundsException
* @expectedExceptionMessage It cannot have children
*/
public function testPersistChild()
{
$root = $this->getDm()->find(null, self::ROUTE_ROOT);

$redirect = new RedirectRoute();
$redirect->setPosition($root, 'redirect');
$redirect->setDefault('test', 'toast');
$this->getDm()->persist($redirect);

$child = new Generic();
$child->setParentDocument($redirect);
$child->setNodename('foo');
$this->getDm()->persist($child);

$this->getDm()->flush();
}

/**
* @expectedException \LogicException
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Doctrine/Phpcr/RouteProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RouteProviderTest extends BaseTestCase
/** @var RouteProvider */
private $repository;

public function setUp()
protected function setUp()
{
parent::setUp();
$this->db('PHPCR')->createTestNode();
Expand Down
19 changes: 18 additions & 1 deletion tests/Functional/Doctrine/Phpcr/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@

namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\Functional\Doctrine\Phpcr;

use Doctrine\ODM\PHPCR\Document\Generic;
use Doctrine\ODM\PHPCR\Exception\OutOfBoundsException;
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route;
use Symfony\Cmf\Bundle\RoutingBundle\Tests\Functional\BaseTestCase;

class RouteTest extends BaseTestCase
{
const ROUTE_ROOT = '/test/routing';

public function setUp()
protected function setUp()
{
parent::setUp();
$this->db('PHPCR')->createTestNode();
Expand Down Expand Up @@ -89,6 +91,21 @@ public function testPersistEmptyOptions()
return $route;
}

/**
* @expectedException \Doctrine\ODM\PHPCR\Exception\OutOfBoundsException
*/
public function testPersistInvalidChild()
{
$root = $this->getDm()->find(null, self::ROUTE_ROOT);

$document = new Generic();
$document->setParentDocument($root);
$document->setNodeName('foo');

$this->getDm()->persist($document);
$this->getDm()->flush();
}

public function testConditionOption()
{
$route = new Route();
Expand Down

0 comments on commit 02a2349

Please sign in to comment.