|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Gedmo\Sluggable; |
| 4 | + |
| 5 | +use Doctrine\Common\EventManager; |
| 6 | +use Gedmo\Tree\TreeListener; |
| 7 | +use Sluggable\Fixture\Handler\TreeSlug; |
| 8 | +use Tool\BaseTestCaseORM; |
| 9 | + |
| 10 | +class TreeSlugHandlerUniqueTest extends BaseTestCaseORM |
| 11 | +{ |
| 12 | + const TARGET = "Sluggable\\Fixture\\Handler\\TreeSlug"; |
| 13 | + |
| 14 | + protected function setUp() |
| 15 | + { |
| 16 | + parent::setUp(); |
| 17 | + |
| 18 | + $evm = new EventManager(); |
| 19 | + $evm->addEventSubscriber(new SluggableListener()); |
| 20 | + $evm->addEventSubscriber(new TreeListener()); |
| 21 | + |
| 22 | + $this->getMockSqliteEntityManager($evm); |
| 23 | + } |
| 24 | + |
| 25 | + public function testUniqueRoot() |
| 26 | + { |
| 27 | + $foo1 = new TreeSlug(); |
| 28 | + $foo1->setTitle('Foo'); |
| 29 | + |
| 30 | + $foo2 = new TreeSlug(); |
| 31 | + $foo2->setTitle('Foo'); |
| 32 | + |
| 33 | + $this->em->persist($foo1); |
| 34 | + $this->em->persist($foo2); |
| 35 | + |
| 36 | + $this->em->flush(); |
| 37 | + |
| 38 | + $this->assertEquals('foo', $foo1->getSlug()); |
| 39 | + $this->assertEquals('foo-1', $foo2->getSlug()); |
| 40 | + } |
| 41 | + |
| 42 | + public function testUniqueLeaf() |
| 43 | + { |
| 44 | + $root = new TreeSlug(); |
| 45 | + $root->setTitle('root'); |
| 46 | + |
| 47 | + $foo1 = new TreeSlug(); |
| 48 | + $foo1->setTitle('Foo'); |
| 49 | + $foo1->setParent($root); |
| 50 | + |
| 51 | + $foo2 = new TreeSlug(); |
| 52 | + $foo2->setTitle('Foo'); |
| 53 | + $foo2->setParent($root); |
| 54 | + |
| 55 | + $this->em->persist($root); |
| 56 | + $this->em->persist($foo1); |
| 57 | + $this->em->persist($foo2); |
| 58 | + |
| 59 | + $this->em->flush(); |
| 60 | + |
| 61 | + $this->assertEquals('root/foo', $foo1->getSlug()); |
| 62 | + $this->assertEquals('root/foo-1', $foo2->getSlug()); |
| 63 | + } |
| 64 | + |
| 65 | + protected function getUsedEntityFixtures() |
| 66 | + { |
| 67 | + return array( |
| 68 | + self::TARGET, |
| 69 | + ); |
| 70 | + } |
| 71 | +} |
0 commit comments