From 02a2349ca9fdbdc42644f497930ca6fb5e2c1955 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Thu, 9 Feb 2017 12:37:34 +0100 Subject: [PATCH] Added child restriction to Route & RedirectRoute documents --- composer.json | 2 +- .../doctrine-phpcr/RedirectRoute.phpcr.xml | 2 +- .../config/doctrine-phpcr/Route.phpcr.xml | 1 + .../Doctrine/Phpcr/RedirectRouteTest.php | 24 ++++++++++++++++++- .../Doctrine/Phpcr/RouteProviderTest.php | 2 +- tests/Functional/Doctrine/Phpcr/RouteTest.php | 19 ++++++++++++++- 6 files changed, 45 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 096a440c..7dc4c88b 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/Resources/config/doctrine-phpcr/RedirectRoute.phpcr.xml b/src/Resources/config/doctrine-phpcr/RedirectRoute.phpcr.xml index 07f12b07..820571b5 100644 --- a/src/Resources/config/doctrine-phpcr/RedirectRoute.phpcr.xml +++ b/src/Resources/config/doctrine-phpcr/RedirectRoute.phpcr.xml @@ -5,7 +5,7 @@ https://github.com/doctrine/phpcr-odm/raw/master/doctrine-phpcr-odm-mapping.xsd" > - + diff --git a/src/Resources/config/doctrine-phpcr/Route.phpcr.xml b/src/Resources/config/doctrine-phpcr/Route.phpcr.xml index c0f8f000..7c92eb5c 100644 --- a/src/Resources/config/doctrine-phpcr/Route.phpcr.xml +++ b/src/Resources/config/doctrine-phpcr/Route.phpcr.xml @@ -13,6 +13,7 @@ + diff --git a/tests/Functional/Doctrine/Phpcr/RedirectRouteTest.php b/tests/Functional/Doctrine/Phpcr/RedirectRouteTest.php index 3785a0fb..588f7827 100644 --- a/tests/Functional/Doctrine/Phpcr/RedirectRouteTest.php +++ b/tests/Functional/Doctrine/Phpcr/RedirectRouteTest.php @@ -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; @@ -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(); @@ -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 */ diff --git a/tests/Functional/Doctrine/Phpcr/RouteProviderTest.php b/tests/Functional/Doctrine/Phpcr/RouteProviderTest.php index 63e1fa2f..246bd08f 100644 --- a/tests/Functional/Doctrine/Phpcr/RouteProviderTest.php +++ b/tests/Functional/Doctrine/Phpcr/RouteProviderTest.php @@ -26,7 +26,7 @@ class RouteProviderTest extends BaseTestCase /** @var RouteProvider */ private $repository; - public function setUp() + protected function setUp() { parent::setUp(); $this->db('PHPCR')->createTestNode(); diff --git a/tests/Functional/Doctrine/Phpcr/RouteTest.php b/tests/Functional/Doctrine/Phpcr/RouteTest.php index c275f007..e9934d6e 100644 --- a/tests/Functional/Doctrine/Phpcr/RouteTest.php +++ b/tests/Functional/Doctrine/Phpcr/RouteTest.php @@ -11,6 +11,8 @@ 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; @@ -18,7 +20,7 @@ class RouteTest extends BaseTestCase { const ROUTE_ROOT = '/test/routing'; - public function setUp() + protected function setUp() { parent::setUp(); $this->db('PHPCR')->createTestNode(); @@ -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();