| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace Tools\Test\TestCase\Model\Behavior;
- use Cake\Database\Query;
- use Cake\Datasource\ConnectionManager;
- use Cake\Event\Event;
- use Cake\ORM\Entity;
- use Cake\ORM\Table;
- use Cake\ORM\TableRegistry;
- use Cake\TestSuite\TestCase;
- use Cake\Core\Configure;
- /**
- * SluggedBehaviorTest
- */
- class SluggedBehaviorTest extends TestCase {
- /**
- * Fixture
- *
- * @var array
- */
- public $fixtures = [
- 'plugin.tools.slugged_article',
- ];
- /**
- * setup
- *
- * @return void
- */
- public function setUp() {
- parent::setUp();
- $this->connection = ConnectionManager::get('test');
- $options = ['alias' => 'Articles'];
- $this->articles = TableRegistry::get('SluggedArticles', $options);
- Configure::delete('Slugged');
- }
- /**
- * teardown
- *
- * @return void
- */
- public function tearDown() {
- unset($this->articles);
- TableRegistry::clear();
- parent::tearDown();
- }
- /**
- * Testing simple slugging when adding a record
- *
- * @return void
- */
- public function testAdd() {
- $this->articles->addBehavior('Tools.Slugged');
- $entity = $this->_getEntity();
- $result = $this->articles->save($entity);
- $this->assertEquals('test-123', $result->get('slug'));
- }
- /**
- * Testing simple slugging when adding a record
- *
- * @return void
- */
- public function testAddUnique() {
- $this->articles->addBehavior('Tools.Slugged', ['unique' => true]);
- $entity = $this->_getEntity();
- $result = $this->articles->save($entity);
- $this->assertEquals('test-123', $result->get('slug'));
- //$entity = $this->_getEntity();
- //$result = $this->articles->save($entity);
- //$this->assertEquals('test-123', $result->get('slug'));
- //debug($result);
- }
- /**
- * SluggedBehaviorTest::testCustomFinder()
- *
- * @return void
- */
- public function testCustomFinder() {
- $this->articles->addBehavior('Tools.Slugged');
- $article = $this->articles->find()->find('slugged', ['slug' => 'foo'])->first();
- $this->assertEquals('Foo', $article->get('title'));
- }
- /**
- * Get a new Entity
- *
- * @return Entity
- */
- protected function _getEntity() {
- return new Entity([
- 'title' => 'test 123'
- ]);
- }
- }
|