浏览代码

fix tests

euromark 11 年之前
父节点
当前提交
8c94ce5eb7
共有 2 个文件被更改,包括 19 次插入10 次删除
  1. 11 2
      Test/Fixture/SluggedArticleFixture.php
  2. 8 8
      Test/TestCase/Model/Behavior/SluggedBehaviorTest.php

+ 11 - 2
Test/Fixture/SluggedArticleFixture.php

@@ -18,7 +18,10 @@ class SluggedArticleFixture extends TestFixture {
 	public $fields = array(
 		'id' => ['type' => 'integer'],
 		'title' => ['type' => 'string', 'length' => 255, 'null' => false],
-		'slug' => ['type' => 'string', 'length' => 255, 'null' => false],
+		'slug' => ['type' => 'string', 'length' => 245, 'null' => false],
+		'long_title' => array('type' => 'string', 'null' => false),
+		'long_slug' => array('type' => 'string', 'null' => false),
+		'section' => ['type' => 'integer', 'null' => true],
 		'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]
 	);
 
@@ -28,7 +31,13 @@ class SluggedArticleFixture extends TestFixture {
  * @var array
  */
 	public $records = array(
-		array('title' => 'Foo', 'slug' => 'foo'),
+		array(
+			'title' => 'Foo',
+			'slug' => 'foo',
+			'long_title' => 'Foo Bar',
+			'long_slug' => 'foo-bar',
+			'section' => null,
+		),
 	);
 
 }

+ 8 - 8
Test/TestCase/Model/Behavior/SluggedBehaviorTest.php

@@ -32,7 +32,7 @@ class SluggedBehaviorTest extends TestCase {
  */
 	public function setUp() {
 		parent::setUp();
-		$this->connection = ConnectionManager::get('test');
+		//$this->connection = ConnectionManager::get('test');
 
 		$options = ['alias' => 'Articles'];
 		$this->articles = TableRegistry::get('SluggedArticles', $options);
@@ -118,7 +118,7 @@ class SluggedBehaviorTest extends TestCase {
 		$entity = $this->_getEntity(str_repeat('foo bar ', 100));
 
 		$result = $this->articles->save($entity);
-		$this->assertEquals(255, strlen($result->get('slug')));
+		$this->assertEquals(245, strlen($result->get('slug')));
 	}
 
 /**
@@ -127,11 +127,11 @@ class SluggedBehaviorTest extends TestCase {
  * @return void
  */
 	public function testLengthRestrictionNoLimit() {
-		$this->articles->addBehavior('Tools.Slugged', ['length' => 0]);
-		$entity = $this->_getEntity(str_repeat('foo bar ', 100));
-		debug(strlen($entity->get('slug')));
+		$this->articles->addBehavior('Tools.Slugged', ['length' => 0, 'label' => 'long_title', 'field' => 'long_slug']);
+		$entity = $this->_getEntity(str_repeat('foo bar ', 100), 'long_title');
+		debug(strlen($entity->get('long_slug')));
 		$result = $this->articles->save($entity);
-		$this->assertEquals(799, strlen($result->get('slug')));
+		$this->assertEquals(799, strlen($result->get('long_slug')));
 	}
 
 /**
@@ -139,9 +139,9 @@ class SluggedBehaviorTest extends TestCase {
  *
  * @return Entity
  */
-	protected function _getEntity($title = 'test 123') {
+	protected function _getEntity($title = 'test 123', $field = 'title') {
 		return new Entity([
-			'title' => $title
+			$field => $title
 		]);
 	}