| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 | <?php
namespace Gedmo\Sluggable;
use Doctrine\Common\EventManager;
use Tool\BaseTestCaseORM;
use Doctrine\Common\Util\Debug,
    Sluggable\Fixture\ConfigurationArticle;
/**
 * These are tests for Sluggable behavior
 *
 * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
 * @package Gedmo.Sluggable
 * @link http://www.gediminasm.org
 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
class SluggableConfigurationTest extends BaseTestCaseORM
{
    const ARTICLE = 'Sluggable\\Fixture\\ConfigurationArticle';
    private $articleId;
    protected function setUp()
    {
        parent::setUp();
        $evm = new EventManager;
        $evm->addEventSubscriber(new SluggableListener);
        $this->getMockSqliteEntityManager($evm);
        $this->populate();
    }
    public function testInsertedNewSlug()
    {
        $article = $this->em->find(self::ARTICLE, $this->articleId);
        $this->assertTrue($article instanceof Sluggable);
        $this->assertEquals('the-title-my-code', $article->getSlug());
    }
    public function testNonUniqueSlugGeneration()
    {
        for ($i = 0; $i < 5; $i++) {
            $article = new ConfigurationArticle();
            $article->setTitle('the title');
            $article->setCode('my code');
            $this->em->persist($article);
            $this->em->flush();
            $this->em->clear();
            $this->assertEquals('the-title-my-code', $article->getSlug());
        }
    }
    public function testSlugLimit()
    {
        $long = 'the title the title the title the title the';
        $article = new ConfigurationArticle();
        $article->setTitle($long);
        $article->setCode('my code');
        $this->em->persist($article);
        $this->em->flush();
        $this->em->clear();
        $shorten = $article->getSlug();
        $this->assertEquals(32, strlen($shorten));
    }
    public function testNonUpdatableSlug()
    {
        $article = $this->em->find(self::ARTICLE, $this->articleId);
        $article->setTitle('the title updated');
        $this->em->persist($article);
        $this->em->flush();
        $this->em->clear();
        $this->assertEquals('the-title-my-code', $article->getSlug());
    }
    protected function getUsedEntityFixtures()
    {
        return array(
            self::ARTICLE,
        );
    }
    private function populate()
    {
        $article = new ConfigurationArticle();
        $article->setTitle('the title');
        $article->setCode('my code');
        $this->em->persist($article);
        $this->em->flush();
        $this->em->clear();
        $this->articleId = $article->getId();
    }
}
 |