From 82f4427b8b53a5ae7a78f5f70a3a683aa825e89a Mon Sep 17 00:00:00 2001 From: nate Date: Sat, 8 Mar 2008 17:27:32 +0000 Subject: [PATCH] Fixing '0' default values in fixture generation, fixes #4295 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6519 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/tests/cases/libs/model/behaviors/tree.test.php | 2 +- cake/tests/cases/libs/model/model.test.php | 11 ++++++++++- cake/tests/fixtures/uuid_fixture.php | 9 +++++---- cake/tests/lib/cake_test_fixture.php | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/cake/tests/cases/libs/model/behaviors/tree.test.php b/cake/tests/cases/libs/model/behaviors/tree.test.php index eb095e00d..91479899f 100644 --- a/cake/tests/cases/libs/model/behaviors/tree.test.php +++ b/cake/tests/cases/libs/model/behaviors/tree.test.php @@ -41,7 +41,7 @@ class NumberTree extends CakeTestModel { function __initialize($levelLimit = 3, $childLimit = 3, $currentLevel = null, $parent_id = null, $prefix = '1', $hierachial = true) { if (!$parent_id) { - $this->deleteAll('1 = 1'); + $this->deleteAll(true); $this->save(array($this->name => array('name' => '1. Root'))); $this->__initialize($levelLimit, $childLimit, 1, $this->id, '1', $hierachial); $this->create(array()); diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 48230dc82..a038354a4 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -2881,10 +2881,19 @@ class ModelTest extends CakeTestCase { $this->model->save(array('title' => 'Test record')); $result = $this->model->findByTitle('Test record'); - $this->assertEqual(array_keys($result['Uuid']), array('id', 'title', 'created', 'updated')); + $this->assertEqual(array_keys($result['Uuid']), array('id', 'title', 'count', 'created', 'updated')); $this->assertEqual(strlen($result['Uuid']['id']), 36); } + function testZeroDefaultFieldValue() { + $this->loadFixtures('Uuid'); + $this->model =& new Uuid(); + + $this->model->create() && $this->model->save(); + $result = $this->model->findById($this->model->id); + $this->assertIdentical($result['Uuid']['count'], '0'); + } + function testAfterFindAssociation() { } diff --git a/cake/tests/fixtures/uuid_fixture.php b/cake/tests/fixtures/uuid_fixture.php index 4cda5fd2a..02a776e73 100644 --- a/cake/tests/fixtures/uuid_fixture.php +++ b/cake/tests/fixtures/uuid_fixture.php @@ -37,14 +37,15 @@ class UuidFixture extends CakeTestFixture { var $fields = array( 'id' => array('type' => 'string', 'length' => 36, 'key' => 'primary'), 'title' => 'string', + 'count' => array('type' => 'integer', 'default' => 0), 'created' => 'datetime', 'updated' => 'datetime' ); var $records = array( - array('id' => '47c36f9c-bc00-4d17-9626-4e183ca6822b', 'title' => 'Unique record 1', 'created' => '2008-03-13 01:16:23', 'updated' => '2008-03-13 01:18:31'), - array('id' => '47c36f9c-f2b0-43f5-b3f7-4e183ca6822b', 'title' => 'Unique record 2', 'created' => '2008-03-13 01:18:24', 'updated' => '2008-03-13 01:20:32'), - array('id' => '47c36f9c-0ffc-4084-9b03-4e183ca6822b', 'title' => 'Unique record 3', 'created' => '2008-03-13 01:20:25', 'updated' => '2008-03-13 01:22:33'), - array('id' => '47c36f9c-2578-4c2e-aeab-4e183ca6822b', 'title' => 'Unique record 4', 'created' => '2008-03-13 01:22:26', 'updated' => '2008-03-13 01:24:34'), + array('id' => '47c36f9c-bc00-4d17-9626-4e183ca6822b', 'title' => 'Unique record 1', 'count' => 2, 'created' => '2008-03-13 01:16:23', 'updated' => '2008-03-13 01:18:31'), + array('id' => '47c36f9c-f2b0-43f5-b3f7-4e183ca6822b', 'title' => 'Unique record 2', 'count' => 4, 'created' => '2008-03-13 01:18:24', 'updated' => '2008-03-13 01:20:32'), + array('id' => '47c36f9c-0ffc-4084-9b03-4e183ca6822b', 'title' => 'Unique record 3', 'count' => 5, 'created' => '2008-03-13 01:20:25', 'updated' => '2008-03-13 01:22:33'), + array('id' => '47c36f9c-2578-4c2e-aeab-4e183ca6822b', 'title' => 'Unique record 4', 'count' => 3, 'created' => '2008-03-13 01:22:26', 'updated' => '2008-03-13 01:24:34'), ); } diff --git a/cake/tests/lib/cake_test_fixture.php b/cake/tests/lib/cake_test_fixture.php index f373f5806..c011cdc1b 100644 --- a/cake/tests/lib/cake_test_fixture.php +++ b/cake/tests/lib/cake_test_fixture.php @@ -110,7 +110,7 @@ class CakeTestFixture extends Object { } if (isset($this->fields)) { foreach ($this->fields as $index => $field) { - if (empty($field['default'])) { + if (isset($field['default']) && empty($field['default']) && $field['default'] !== 0) { unset($this->fields[$index]['default']); } }