|
| 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\MenuBundle\Tests\Functional\Doctrine\Phpcr; |
| 13 | + |
| 14 | +use Doctrine\ODM\PHPCR\Document\Generic; |
| 15 | +use Doctrine\ODM\PHPCR\DocumentManager; |
| 16 | +use Symfony\Cmf\Bundle\MenuBundle\Doctrine\Phpcr\Menu; |
| 17 | +use Symfony\Cmf\Bundle\MenuBundle\Doctrine\Phpcr\MenuNode; |
| 18 | +use Symfony\Cmf\Component\Testing\Functional\BaseTestCase; |
| 19 | + |
| 20 | +class MenuTest extends BaseTestCase |
| 21 | +{ |
| 22 | + /** |
| 23 | + * @var DocumentManager |
| 24 | + */ |
| 25 | + private $dm; |
| 26 | + private $rootDocument; |
| 27 | + |
| 28 | + protected function setUp() |
| 29 | + { |
| 30 | + $this->db('PHPCR')->createTestNode(); |
| 31 | + |
| 32 | + $this->dm = $this->db('PHPCR')->getOm(); |
| 33 | + $this->rootDocument = $this->dm->find(null, '/test'); |
| 34 | + } |
| 35 | + |
| 36 | + public function testPersist() |
| 37 | + { |
| 38 | + $menu = new Menu(); |
| 39 | + $menu->setPosition($this->rootDocument, 'main'); |
| 40 | + $this->dm->persist($menu); |
| 41 | + |
| 42 | + $menuNode = new MenuNode(); |
| 43 | + $menuNode->setName('home'); |
| 44 | + $menu->addChild($menuNode); |
| 45 | + $this->dm->persist($menuNode); |
| 46 | + |
| 47 | + $this->dm->flush(); |
| 48 | + $this->dm->clear(); |
| 49 | + |
| 50 | + $menu = $this->dm->find(null, '/test/main'); |
| 51 | + |
| 52 | + $this->assertNotNull($menu); |
| 53 | + $this->assertEquals('main', $menu->getName()); |
| 54 | + |
| 55 | + $children = $menu->getChildren(); |
| 56 | + $this->assertCount(1, $children); |
| 57 | + $this->assertEquals('home', $children[0]->getName()); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * @dataProvider getInvalidChildren |
| 62 | + * @expectedException \Doctrine\ODM\PHPCR\Exception\OutOfBoundsException |
| 63 | + */ |
| 64 | + public function testPersistInvalidChild($invalidChild) |
| 65 | + { |
| 66 | + $menu = new Menu(); |
| 67 | + $menu->setPosition($this->rootDocument, 'main'); |
| 68 | + $this->dm->persist($menu); |
| 69 | + |
| 70 | + $invalidChild->setParentDocument($menu); |
| 71 | + $this->dm->persist($invalidChild); |
| 72 | + |
| 73 | + $this->dm->flush(); |
| 74 | + } |
| 75 | + |
| 76 | + public function getInvalidChildren() |
| 77 | + { |
| 78 | + return [ |
| 79 | + [(new Menu())->setName('invalid')], |
| 80 | + [(new Generic())->setNodename('invalid')], |
| 81 | + ]; |
| 82 | + } |
| 83 | +} |
0 commit comments