From a0d34bc4ad4885477b9e01cd49cc929590450ea3 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 --- CHANGELOG.md | 2 ++ UPGRADE-2.0.md | 10 ++++++++ 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 ++++++++++++++- 8 files changed, 57 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c13e994..28393779 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ Changelog ========= + * **2017-02-09**: [BC BREAK] Added child restrictions to the `Route` and `RedirectRoute` documents. + See the UPGRADE guide for detailed information. * **2017-02-03**: [BC BREAK] Removed unused `cmf_routing.dynamic.persistence.phpcr.content_basepath` 2.0.0-RC1 diff --git a/UPGRADE-2.0.md b/UPGRADE-2.0.md index 54e2a075..88ef0ef7 100644 --- a/UPGRADE-2.0.md +++ b/UPGRADE-2.0.md @@ -155,6 +155,16 @@ $route->setParentDocument($routeRoot); ``` +## Doctrine PHPCR ODM + + * It is no longer possible to add a child to the `RedirectRoute` document. + This behaviour can be changed by overriding the `child-class` setting of the + PHPCR ODM mapping. + + * Only instances of `RouteObjectInterface` are allowed as children of the + `Route` document. This behaviour can be changed by overriding the + `child-class` setting of the PHPCR ODM mapping. + ## Configuration * Removed the `route_basepath` setting, use `route_basepaths` instead. diff --git a/composer.json b/composer.json index 096a440c..3c4a2d01 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.2", "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();