UserRelativeSlugHandlerTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Gedmo\Sluggable;
  3. use Doctrine\Common\EventManager;
  4. use Tool\BaseTestCaseORM;
  5. use Sluggable\Fixture\Handler\User;
  6. use Sluggable\Fixture\Handler\Company;
  7. /**
  8. * These are tests for Sluggable behavior
  9. *
  10. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  11. * @link http://www.gediminasm.org
  12. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  13. */
  14. class UserRelativeSlugHandlerTest extends BaseTestCaseORM
  15. {
  16. const USER = "Sluggable\\Fixture\\Handler\\User";
  17. const COMPANY = "Sluggable\\Fixture\\Handler\\Company";
  18. protected function setUp()
  19. {
  20. parent::setUp();
  21. $evm = new EventManager;
  22. $evm->addEventSubscriber(new SluggableListener);
  23. $this->getMockSqliteEntityManager($evm);
  24. }
  25. public function testRelativeSlug()
  26. {
  27. $company = new Company;
  28. $company->setTitle('KnpLabs');
  29. $this->em->persist($company);
  30. $gedi = new User;
  31. $gedi->setUsername('Gedi');
  32. $gedi->setCompany($company);
  33. $this->em->persist($gedi);
  34. $this->em->flush();
  35. $this->assertEquals('knplabs/gedi', $gedi->getSlug(), 'relative slug is invalid');
  36. $company->setTitle('KnpLabs Nantes');
  37. $this->em->persist($company);
  38. $this->em->flush();
  39. $this->assertEquals('knplabs-nantes/gedi', $gedi->getSlug(), 'relative slug is invalid');
  40. }
  41. protected function getUsedEntityFixtures()
  42. {
  43. return array(
  44. self::USER,
  45. self::COMPANY
  46. );
  47. }
  48. }