浏览代码

Add test for virtual field slugs

Jad Bitar 10 年之前
父节点
当前提交
8822a08e0a
共有 2 个文件被更改,包括 37 次插入0 次删除
  1. 13 0
      tests/TestApp/Model/Entity/SluggedArticle.php
  2. 24 0
      tests/TestCase/Model/Behavior/SluggedBehaviorTest.php

+ 13 - 0
tests/TestApp/Model/Entity/SluggedArticle.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace TestApp\Model\Entity;
+
+use Cake\ORM\Entity;
+
+class SluggedArticle extends Entity
+{
+	protected function _getSpecial()
+	{
+		return 'dereuromark';
+	}
+}

+ 24 - 0
tests/TestCase/Model/Behavior/SluggedBehaviorTest.php

@@ -584,6 +584,30 @@ class SluggedBehaviorTest extends TestCase {
 		$this->assertEquals('Some-Article-12345', $result['slug']);
 	}
 
+	/**
+	 * Test slug generation works with virtual fields.
+	 *
+	 * @return void
+	 */
+	public function testSlugGenerationWithVirualField()
+	{
+		$this->articles->removeBehavior('Slugged');
+		$this->articles->entityClass('\TestApp\Model\Entity\SluggedArticle');
+		$this->articles->addBehavior('Tools.Slugged', [
+			'label' => [
+				'title',
+				'special'
+			],
+		]);
+
+		$data = ['title' => 'Some Article 12345', 'section' => 0];
+
+		$article = $this->articles->newEntity($data);
+		$result = $this->articles->save($article);
+		$this->assertTrue((bool)$result);
+		$this->assertEquals('Some-Article-12345-dereuromark', $result['slug']);
+	}
+
 /**
  * Get a new Entity
  *