Adding tests to show HABTM saving with custom model keys, disproves and closes #4791

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7082 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mariano.iglesias 2008-06-01 21:04:30 +00:00
parent 7101b8d4cd
commit 4b2b8fcc1c
4 changed files with 146 additions and 11 deletions

View file

@ -48,7 +48,8 @@ class ModelTest extends CakeTestCase {
'core.document', 'core.device', 'core.document_directory', 'core.primary_model', 'core.secondary_model', 'core.something', 'core.document', 'core.device', 'core.document_directory', 'core.primary_model', 'core.secondary_model', 'core.something',
'core.something_else', 'core.join_thing', 'core.join_a', 'core.join_b', 'core.join_c', 'core.join_a_b', 'core.join_a_c', 'core.something_else', 'core.join_thing', 'core.join_a', 'core.join_b', 'core.join_c', 'core.join_a_b', 'core.join_a_c',
'core.uuid', 'core.data_test', 'core.posts_tag', 'core.the_paper_monkies', 'core.person', 'core.underscore_field', 'core.uuid', 'core.data_test', 'core.posts_tag', 'core.the_paper_monkies', 'core.person', 'core.underscore_field',
'core.node', 'core.dependency' 'core.node', 'core.dependency',
'core.story', 'core.stories_tag'
); );
function start() { function start() {
@ -1880,8 +1881,6 @@ class ModelTest extends CakeTestCase {
); );
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
// Save with parent model data
$data = array( $data = array(
'Article' => array('id' => '2', 'title' => 'New Second Article'), 'Article' => array('id' => '2', 'title' => 'New Second Article'),
'Tag' => array('Tag' => array(1, 2)) 'Tag' => array('Tag' => array(1, 2))
@ -1983,8 +1982,6 @@ class ModelTest extends CakeTestCase {
); );
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
// Parent data after HABTM data
$data = array('Tag' => array('Tag' => array(1, 2)), 'Article' => array('id' => '2', 'title' => 'New Second Article')); $data = array('Tag' => array('Tag' => array(1, 2)), 'Article' => array('id' => '2', 'title' => 'New Second Article'));
$this->assertTrue($TestModel->set($data)); $this->assertTrue($TestModel->set($data));
$this->assertTrue($TestModel->save()); $this->assertTrue($TestModel->save());
@ -2095,6 +2092,34 @@ class ModelTest extends CakeTestCase {
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
} }
function testSaveHabtmCustomKeys() {
$this->loadFixtures('Story', 'StoriesTag', 'Tag');
$Story =& new Story();
$data = array('Story' => array('story' => '1'), 'Tag' => array('Tag' => array(2, 3)));
$result = $Story->set($data);
$this->assertTrue($result);
$result = $Story->save();
$this->assertTrue($result);
$result = $Story->find('all');
$expected = array(
array(
'Story' => array('story' => 1, 'title' => 'First Story'),
'Tag' => array(
array('id' => 2, 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'),
array('id' => 3, 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31')
)
),
array(
'Story' => array('story' => 2, 'title' => 'Second Story'),
'Tag' => array()
)
);
$this->assertEqual($result, $expected);
}
/** /**
* @todo This is technically incorrect (ThePaperMonkies.apple_id should be ThePaperMonkies.the_paper_id), * @todo This is technically incorrect (ThePaperMonkies.apple_id should be ThePaperMonkies.the_paper_id),
* the foreign key name should come from the association name, not the table name... but that's the existing * the foreign key name should come from the association name, not the table name... but that's the existing
@ -3685,10 +3710,6 @@ class ModelTest extends CakeTestCase {
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
} }
function testAfterFindAssociation() {
}
function testDeconstructFields() { function testDeconstructFields() {
$this->loadFixtures('Apple'); $this->loadFixtures('Apple');
$TestModel =& new Apple(); $TestModel =& new Apple();

View file

@ -662,12 +662,34 @@ class Person extends CakeTestModel {
'className' => 'Person', 'className' => 'Person',
'foreignKey' => 'father_id')); 'foreignKey' => 'father_id'));
} }
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.model
*/
class UnderscoreField extends CakeTestModel { class UnderscoreField extends CakeTestModel {
var $name = 'UnderscoreField'; var $name = 'UnderscoreField';
} }
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.model
*/
class Product extends CakeTestModel { class Product extends CakeTestModel {
var $name = 'Product'; var $name = 'Product';
} }
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.model
*/
class Story extends CakeTestModel {
var $name = 'Story';
var $primaryKey = 'story';
var $hasAndBelongsToMany = array('Tag' => array('foreignKey' => 'story'));
var $validate = array('title' => VALID_NOT_EMPTY);
}
?> ?>

View file

@ -0,0 +1,46 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright 2005-2008, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake.tests
* @subpackage cake.tests.fixtures
* @since CakePHP(tm) v 1.2.0.4667
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.fixtures
*/
class StoriesTagFixture extends CakeTestFixture {
var $name = 'StoriesTag';
var $fields = array(
'story' => array('type' => 'integer', 'null' => false),
'tag_id' => array('type' => 'integer', 'null' => false),
'indexes' => array('UNIQUE_TAG' => array('column'=> array('story', 'tag_id'), 'unique'=>1))
);
var $records = array(
array('story' => 1, 'tag_id' => 1)
);
}
?>

46
cake/tests/fixtures/story_fixture.php vendored Normal file
View file

@ -0,0 +1,46 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright 2005-2008, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake.tests
* @subpackage cake.tests.fixtures
* @since CakePHP(tm) v 1.2.0.4667
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.fixtures
*/
class StoryFixture extends CakeTestFixture {
var $name = 'Story';
var $fields = array(
'story' => array('type' => 'integer', 'key' => 'primary'),
'title' => array('type' => 'string', 'null' => false)
);
var $records = array(
array('title' => 'First Story'),
array('title' => 'Second Story')
);
}
?>