From 2e7d2d5587f7d3794aa533873777c575e0e6bb39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Wed, 2 Jun 2010 00:30:52 -0430 Subject: [PATCH] Migrating ModelWriteTest to phpunit --- cake/tests/cases/libs/model/model.test.php | 7 + .../cases/libs/model/model_write.test.php | 501 ++++++++---------- 2 files changed, 217 insertions(+), 291 deletions(-) diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index aa378a404..55805c9bf 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -38,6 +38,13 @@ abstract class BaseModelTest extends CakeTestCase { */ public $autoFixtures = false; +/** + * Whether backup global state for each test method or not + * + * @var bool false + * @access public + */ + public $backupGlobals = false; /** * fixtures property * diff --git a/cake/tests/cases/libs/model/model_write.test.php b/cake/tests/cases/libs/model/model_write.test.php index 3c45c395e..3187e9ce4 100644 --- a/cake/tests/cases/libs/model/model_write.test.php +++ b/cake/tests/cases/libs/model/model_write.test.php @@ -28,60 +28,61 @@ require_once dirname(__FILE__) . DS . 'model.test.php'; */ class ModelWriteTest extends BaseModelTest { -/** - * testInsertAnotherHabtmRecordWithSameForeignKey method - * - * @access public - * @return void - */ - function testInsertAnotherHabtmRecordWithSameForeignKey() { - $this->loadFixtures('JoinA', 'JoinB', 'JoinAB'); - $TestModel = new JoinA(); + /** + * testInsertAnotherHabtmRecordWithSameForeignKey method + * + * @access public + * @return void + */ + function testInsertAnotherHabtmRecordWithSameForeignKey() { + $this->loadFixtures('JoinA', 'JoinB', 'JoinAB', 'JoinC', 'JoinAC'); + $TestModel = new JoinA(); - $result = $TestModel->JoinAsJoinB->findById(1); - $expected = array( - 'JoinAsJoinB' => array( - 'id' => 1, + $result = $TestModel->JoinAsJoinB->findById(1); + $expected = array( + 'JoinAsJoinB' => array( + 'id' => 1, + 'join_a_id' => 1, + 'join_b_id' => 2, + 'other' => 'Data for Join A 1 Join B 2', + 'created' => '2008-01-03 10:56:33', + 'updated' => '2008-01-03 10:56:33' + )); + $this->assertEqual($result, $expected); + + $TestModel->JoinAsJoinB->create(); + $data = array( 'join_a_id' => 1, - 'join_b_id' => 2, - 'other' => 'Data for Join A 1 Join B 2', - 'created' => '2008-01-03 10:56:33', - 'updated' => '2008-01-03 10:56:33' - )); - $this->assertEqual($result, $expected); + 'join_b_id' => 1, + 'other' => 'Data for Join A 1 Join B 1', + 'created' => '2008-01-03 10:56:44', + 'updated' => '2008-01-03 10:56:44' + ); + $result = $TestModel->JoinAsJoinB->save($data); + $this->assertEquals($result, array('JoinAsJoinB' => $data)); + $lastInsertId = $TestModel->JoinAsJoinB->getLastInsertID(); + $this->assertTrue($lastInsertId != null); - $TestModel->JoinAsJoinB->create(); - $result = $TestModel->JoinAsJoinB->save(array( - 'join_a_id' => 1, - 'join_b_id' => 1, - 'other' => 'Data for Join A 1 Join B 1', - 'created' => '2008-01-03 10:56:44', - 'updated' => '2008-01-03 10:56:44' - )); - $this->assertTrue($result); - $lastInsertId = $TestModel->JoinAsJoinB->getLastInsertID(); - $this->assertTrue($lastInsertId != null); + $result = $TestModel->JoinAsJoinB->findById(1); + $expected = array( + 'JoinAsJoinB' => array( + 'id' => 1, + 'join_a_id' => 1, + 'join_b_id' => 2, + 'other' => 'Data for Join A 1 Join B 2', + 'created' => '2008-01-03 10:56:33', + 'updated' => '2008-01-03 10:56:33' + )); + $this->assertEqual($result, $expected); - $result = $TestModel->JoinAsJoinB->findById(1); - $expected = array( - 'JoinAsJoinB' => array( - 'id' => 1, - 'join_a_id' => 1, - 'join_b_id' => 2, - 'other' => 'Data for Join A 1 Join B 2', - 'created' => '2008-01-03 10:56:33', - 'updated' => '2008-01-03 10:56:33' - )); - $this->assertEqual($result, $expected); + $updatedValue = 'UPDATED Data for Join A 1 Join B 2'; + $TestModel->JoinAsJoinB->id = 1; + $result = $TestModel->JoinAsJoinB->saveField('other', $updatedValue, false); + $this->assertFalse(empty($result)); - $updatedValue = 'UPDATED Data for Join A 1 Join B 2'; - $TestModel->JoinAsJoinB->id = 1; - $result = $TestModel->JoinAsJoinB->saveField('other', $updatedValue, false); - $this->assertTrue($result); - - $result = $TestModel->JoinAsJoinB->findById(1); - $this->assertEqual($result['JoinAsJoinB']['other'], $updatedValue); - } + $result = $TestModel->JoinAsJoinB->findById(1); + $this->assertEqual($result['JoinAsJoinB']['other'], $updatedValue); + } /** * testSaveDateAsFirstEntry method @@ -90,9 +91,9 @@ class ModelWriteTest extends BaseModelTest { * @return void */ function testSaveDateAsFirstEntry() { - $this->loadFixtures('Article'); + $this->loadFixtures('Article', 'User', 'Comment', 'Attachment', 'Tag', 'ArticlesTag'); - $Article =& new Article(); + $Article = new Article(); $data = array( 'Article' => array( @@ -105,7 +106,8 @@ class ModelWriteTest extends BaseModelTest { 'user_id' => 1 )); $Article->create(); - $this->assertTrue($Article->save($data)); + $result = $Article->save($data); + $this->assertFalse(empty($result)); $testResult = $Article->find(array('Article.title' => 'Test Title')); @@ -122,7 +124,7 @@ class ModelWriteTest extends BaseModelTest { */ function testUnderscoreFieldSave() { $this->loadFixtures('UnderscoreField'); - $UnderscoreField =& new UnderscoreField(); + $UnderscoreField = new UnderscoreField(); $currentCount = $UnderscoreField->find('count'); $this->assertEqual($currentCount, 3); @@ -134,7 +136,7 @@ class ModelWriteTest extends BaseModelTest { 'another_field' => 4 )); $ret = $UnderscoreField->save($data); - $this->assertTrue($ret); + $this->assertFalse(empty($ret)); $currentCount = $UnderscoreField->find('count'); $this->assertEqual($currentCount, 4); @@ -151,7 +153,7 @@ class ModelWriteTest extends BaseModelTest { $this->skipIf($this->db->config['driver'] == 'sqlite'); $this->loadFixtures('Uuid'); - $TestModel =& new Uuid(); + $TestModel = new Uuid(); $TestModel->save(array('title' => 'Test record')); $result = $TestModel->findByTitle('Test record'); @@ -173,7 +175,7 @@ class ModelWriteTest extends BaseModelTest { $this->skipIf($this->db->config['driver'] == 'sqlite'); $this->loadFixtures('Uuid'); - $TestModel =& new Uuid(); + $TestModel = new Uuid(); $TestModel->save(array('title' => 'Test record', 'id' => null)); $result = $TestModel->findByTitle('Test record'); @@ -196,7 +198,7 @@ class ModelWriteTest extends BaseModelTest { '%s SQLite uses loose typing, this operation is unsupported' ); $this->loadFixtures('DataTest'); - $TestModel =& new DataTest(); + $TestModel = new DataTest(); $TestModel->create(array()); $TestModel->save(); @@ -205,107 +207,6 @@ class ModelWriteTest extends BaseModelTest { $this->assertIdentical($result['DataTest']['float'], '0'); } -/** - * testNonNumericHabtmJoinKey method - * - * @access public - * @return void - */ - function testNonNumericHabtmJoinKey() { - $this->loadFixtures('Post', 'Tag', 'PostsTag'); - $Post =& new Post(); - $Post->bindModel(array( - 'hasAndBelongsToMany' => array('Tag') - )); - $Post->Tag->primaryKey = 'tag'; - - $result = $Post->find('all'); - $expected = array( - array( - 'Post' => array( - 'id' => '1', - 'author_id' => '1', - 'title' => 'First Post', - 'body' => 'First Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'Author' => array( - 'id' => null, - 'user' => null, - 'password' => null, - 'created' => null, - 'updated' => null, - 'test' => 'working' - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '2', - 'tag' => 'tag2', - 'created' => '2007-03-18 12:24:23', - 'updated' => '2007-03-18 12:26:31' - ))), - array( - 'Post' => array( - 'id' => '2', - 'author_id' => '3', - 'title' => 'Second Post', - 'body' => 'Second Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'Author' => array( - 'id' => null, - 'user' => null, - 'password' => null, - 'created' => null, - 'updated' => null, - 'test' => 'working' - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - ))), - array( - 'Post' => array( - 'id' => '3', - 'author_id' => '1', - 'title' => 'Third Post', - 'body' => 'Third Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ), - 'Author' => array( - 'id' => null, - 'user' => null, - 'password' => null, - 'created' => null, - 'updated' => null, - 'test' => 'working' - ), - 'Tag' => array() - )); - $this->assertEqual($result, $expected); - } - /** * Tests validation parameter order in custom validation methods * @@ -313,7 +214,7 @@ class ModelWriteTest extends BaseModelTest { * @return void */ function testAllowSimulatedFields() { - $TestModel =& new ValidationTest1(); + $TestModel = new ValidationTest1(); $TestModel->create(array( 'title' => 'foo', @@ -343,7 +244,7 @@ class ModelWriteTest extends BaseModelTest { Configure::write('Cache.disable', false); $this->loadFixtures('OverallFavorite'); - $OverallFavorite =& new OverallFavorite(); + $OverallFavorite = new OverallFavorite(); touch(CACHE . 'views' . DS . 'some_dir_overallfavorites_index.php'); touch(CACHE . 'views' . DS . 'some_dir_overall_favorites_index.php'); @@ -373,9 +274,9 @@ class ModelWriteTest extends BaseModelTest { * @return void */ function testSaveWithCounterCache() { - $this->loadFixtures('Syfile', 'Item'); - $TestModel =& new Syfile(); - $TestModel2 =& new Item(); + $this->loadFixtures('Syfile', 'Item', 'Image', 'Portfolio', 'ItemsPortfolio'); + $TestModel = new Syfile(); + $TestModel2 = new Item(); $result = $TestModel->findById(1); $this->assertIdentical($result['Syfile']['item_count'], null); @@ -519,11 +420,11 @@ class ModelWriteTest extends BaseModelTest { $this->loadFixtures('CategoryThread'); $this->db->query('ALTER TABLE '. $this->db->fullTableName('category_threads') . " ADD COLUMN child_count INTEGER"); - $Category =& new CategoryThread(); + $Category = new CategoryThread(); $result = $Category->updateAll(array('CategoryThread.name' => "'updated'"), array('CategoryThread.parent_id' => 5)); - $this->assertTrue($result); + $this->assertFalse(empty($result)); - $Category =& new CategoryThread(); + $Category = new CategoryThread(); $Category->belongsTo['ParentCategory']['counterCache'] = 'child_count'; $Category->updateCounterCache(array('parent_id' => 5)); $result = Set::extract($Category->find('all', array('conditions' => array('CategoryThread.id' => 5))), '{n}.CategoryThread.child_count'); @@ -539,8 +440,8 @@ class ModelWriteTest extends BaseModelTest { */ function testSaveWithCounterCacheScope() { $this->loadFixtures('Syfile', 'Item'); - $TestModel =& new Syfile(); - $TestModel2 =& new Item(); + $TestModel = new Syfile(); + $TestModel2 = new Item(); $TestModel2->belongsTo['Syfile']['counterCache'] = true; $TestModel2->belongsTo['Syfile']['counterScope'] = array('published' => true); @@ -577,7 +478,8 @@ class ModelWriteTest extends BaseModelTest { * @return void */ function testBeforeValidateSaveAbortion() { - $Model =& new CallbackPostTestModel(); + $this->loadFixtures('Post'); + $Model = new CallbackPostTestModel(); $Model->beforeValidateReturn = false; $data = array( @@ -594,7 +496,8 @@ class ModelWriteTest extends BaseModelTest { * @return void */ function testBeforeSaveSaveAbortion() { - $Model =& new CallbackPostTestModel(); + $this->loadFixtures('Post'); + $Model = new CallbackPostTestModel(); $Model->beforeSaveReturn = false; $data = array( @@ -614,11 +517,11 @@ class ModelWriteTest extends BaseModelTest { */ function testSaveField() { $this->loadFixtures('Article'); - $TestModel =& new Article(); + $TestModel = new Article(); $TestModel->id = 1; $result = $TestModel->saveField('title', 'New First Article'); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body'), 1); @@ -632,7 +535,7 @@ class ModelWriteTest extends BaseModelTest { $TestModel->id = 1; $result = $TestModel->saveField('title', ''); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body'), 1); @@ -647,7 +550,8 @@ class ModelWriteTest extends BaseModelTest { $TestModel->id = 1; $TestModel->set('body', 'Messed up data'); - $this->assertTrue($TestModel->saveField('title', 'First Article')); + $result = $TestModel->saveField('title', 'First Article'); + $this->assertFalse(empty($result)); $result = $TestModel->read(array('id', 'user_id', 'title', 'body'), 1); $expected = array('Article' => array( 'id' => '1', @@ -665,7 +569,7 @@ class ModelWriteTest extends BaseModelTest { $this->assertFalse($result); $this->loadFixtures('Node', 'Dependency'); - $Node =& new Node(); + $Node = new Node(); $Node->set('id', 1); $result = $Node->read(); $this->assertEqual(Set::extract('/ParentNode/name', $result), array('Second')); @@ -691,7 +595,7 @@ class ModelWriteTest extends BaseModelTest { 'ArticlesTag', 'Attachment' ); - $TestModel =& new User(); + $TestModel = new User(); $data = array('User' => array( 'user' => 'user', @@ -701,7 +605,7 @@ class ModelWriteTest extends BaseModelTest { $this->assertFalse($result); $this->assertTrue(!empty($TestModel->validationErrors)); - $TestModel =& new Article(); + $TestModel = new Article(); $data = array('Article' => array( 'user_id' => '', @@ -726,7 +630,7 @@ class ModelWriteTest extends BaseModelTest { 'title' => 'New First Article' )); $result = $TestModel->create() && $TestModel->save($data, false); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 1); @@ -747,7 +651,7 @@ class ModelWriteTest extends BaseModelTest { 'published' => 'Y' )); $result = $TestModel->create() && $TestModel->save($data, true, array('id', 'title', 'published')); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 1); @@ -772,7 +676,7 @@ class ModelWriteTest extends BaseModelTest { ); $TestModel->create(); $result = $TestModel->create() && $TestModel->save($data); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $TestModel->recursive = 2; $result = $TestModel->read(null, 4); @@ -818,7 +722,7 @@ class ModelWriteTest extends BaseModelTest { 'updated' => '2007-03-18 14:59:31' )); $result = $TestModel->Comment->create() && $TestModel->Comment->save($data); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $data = array('Attachment' => array( 'comment_id' => '7', @@ -827,7 +731,7 @@ class ModelWriteTest extends BaseModelTest { 'updated' => '2007-03-18 15:04:31' )); $result = $TestModel->Comment->Attachment->save($data); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $TestModel->recursive = 2; $result = $TestModel->read(null, 4); @@ -904,19 +808,22 @@ class ModelWriteTest extends BaseModelTest { */ function testSaveWithNullId() { $this->loadFixtures('User'); - $User =& new User(); + $User = new User(); $User->read(null, 1); $User->data['User']['id'] = null; - $this->assertTrue($User->save(array('password' => 'test'))); + $result = $User->save(array('password' => 'test')); + $this->assertFalse(empty($result)); $this->assertTrue($User->id > 0); - $result = $User->read(null, 2); + $User->read(null, 2); $User->data['User']['id'] = null; - $this->assertTrue($User->save(array('password' => 'test'))); + $result = $User->save(array('password' => 'test')); + $this->assertFalse(empty($result)); $this->assertTrue($User->id > 0); $User->data['User'] = array('password' => 'something'); - $this->assertTrue($User->save()); + $result = $User->save(); + $this->assertFalse(empty($result)); $result = $User->read(); $this->assertEqual($User->data['User']['password'], 'something'); } @@ -929,7 +836,7 @@ class ModelWriteTest extends BaseModelTest { */ function testSaveWithSet() { $this->loadFixtures('Article'); - $TestModel =& new Article(); + $TestModel = new Article(); // Create record we will be updating later @@ -940,7 +847,7 @@ class ModelWriteTest extends BaseModelTest { 'published' => 'Y' )); $result = $TestModel->create() && $TestModel->save($data); - $this->assertTrue($result); + $this->assertFalse(empty($result)); // Check record we created @@ -964,7 +871,7 @@ class ModelWriteTest extends BaseModelTest { 'published' => 'Y' )); $result = $TestModel->create() && $TestModel->save($data); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 5); @@ -998,7 +905,7 @@ class ModelWriteTest extends BaseModelTest { 'published' => 'N' )); $result = $TestModel->set($data) && $TestModel->save(); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 4); @@ -1024,7 +931,7 @@ class ModelWriteTest extends BaseModelTest { $data = array('Article' => array('id' => '5', 'title' => 'Fifth Article - New Title 5')); $result = ($TestModel->set($data) && $TestModel->save()); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 5); @@ -1057,7 +964,7 @@ class ModelWriteTest extends BaseModelTest { */ function testSaveWithNonExistentFields() { $this->loadFixtures('Article'); - $TestModel =& new Article(); + $TestModel = new Article(); $TestModel->recursive = -1; $data = array( @@ -1068,7 +975,7 @@ class ModelWriteTest extends BaseModelTest { 'published' => 'N' ); $result = $TestModel->create() && $TestModel->save($data); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $expected = array('Article' => array( 'id' => '4', @@ -1088,7 +995,7 @@ class ModelWriteTest extends BaseModelTest { 'published' => 'N' ); $result = $TestModel->create() && $TestModel->save($data); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $expected = array('Article' => array( 'id' => '5', @@ -1113,10 +1020,11 @@ class ModelWriteTest extends BaseModelTest { $Article = new Article(); $Article->save(new Xml('
')); - $this->assertTrue($Article->save(new Xml('
'))); + $result = $Article->save(new Xml('
')); + $this->assertFalse(empty($result)); $results = $Article->find(array('Article.title' => 'test xml')); - $this->assertTrue($results); + $this->assertFalse(empty($results)); } /** @@ -1127,7 +1035,7 @@ class ModelWriteTest extends BaseModelTest { */ function testSaveHabtm() { $this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'ArticlesTag'); - $TestModel =& new Article(); + $TestModel = new Article(); $result = $TestModel->findById(2); $expected = array( @@ -1191,8 +1099,10 @@ class ModelWriteTest extends BaseModelTest { 'Tag' => array('Tag' => array(1, 2)) ); - $this->assertTrue($TestModel->set($data)); - $this->assertTrue($TestModel->save()); + $result = $TestModel->set($data); + $this->assertFalse(empty($result)); + $result = $TestModel->save(); + $this->assertFalse(empty($result)); $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); $result = $TestModel->find(array('Article.id' => 2), array('id', 'user_id', 'title', 'body')); @@ -1220,10 +1130,10 @@ class ModelWriteTest extends BaseModelTest { $data = array('Article' => array('id' => '2'), 'Tag' => array('Tag' => array(2, 3))); $result = $TestModel->set($data); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $result = $TestModel->save(); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $TestModel->unbindModel(array( 'belongsTo' => array('User'), @@ -1255,10 +1165,10 @@ class ModelWriteTest extends BaseModelTest { $data = array('Tag' => array('Tag' => array(1, 2, 3))); $result = $TestModel->set($data); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $result = $TestModel->save(); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $TestModel->unbindModel(array( 'belongsTo' => array('User'), @@ -1295,17 +1205,17 @@ class ModelWriteTest extends BaseModelTest { $data = array('Tag' => array('Tag' => array())); $result = $TestModel->set($data); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $result = $TestModel->save(); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $data = array('Tag' => array('Tag' => '')); $result = $TestModel->set($data); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $result = $TestModel->save(); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $TestModel->unbindModel(array( 'belongsTo' => array('User'), @@ -1325,10 +1235,10 @@ class ModelWriteTest extends BaseModelTest { $data = array('Tag' => array('Tag' => array(2, 3))); $result = $TestModel->set($data); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $result = $TestModel->save(); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $TestModel->unbindModel(array( 'belongsTo' => array('User'), @@ -1365,8 +1275,10 @@ class ModelWriteTest extends BaseModelTest { 'id' => '2', 'title' => 'New Second Article' )); - $this->assertTrue($TestModel->set($data)); - $this->assertTrue($TestModel->save()); + $result = $TestModel->set($data); + $this->assertFalse(empty($result)); + $result = $TestModel->save(); + $this->assertFalse(empty($result)); $TestModel->unbindModel(array( 'belongsTo' => array('User'), @@ -1404,8 +1316,9 @@ class ModelWriteTest extends BaseModelTest { 'title' => 'New Second Article Title' )); $result = $TestModel->set($data); - $this->assertTrue($result); - $this->assertTrue($TestModel->save()); + $this->assertFalse(empty($result)); + $result = $TestModel->save(); + $this->assertFalse(empty($result)); $TestModel->unbindModel(array( 'belongsTo' => array('User'), @@ -1444,8 +1357,10 @@ class ModelWriteTest extends BaseModelTest { 'id' => '2', 'title' => 'Changed Second Article' )); - $this->assertTrue($TestModel->set($data)); - $this->assertTrue($TestModel->save()); + $result = $TestModel->set($data); + $this->assertFalse(empty($result)); + $result = $TestModel->save(); + $this->assertFalse(empty($result)); $TestModel->unbindModel(array( 'belongsTo' => array('User'), @@ -1484,10 +1399,10 @@ class ModelWriteTest extends BaseModelTest { ); $result = $TestModel->set($data); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $result = $TestModel->save(); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $TestModel->unbindModel(array( 'belongsTo' => array('User'), @@ -1530,7 +1445,7 @@ class ModelWriteTest extends BaseModelTest { )); $result = $TestModel->create() && $TestModel->save($data, true, array('user_id', 'title', 'published')); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); $result = $TestModel->read(); @@ -1599,7 +1514,7 @@ class ModelWriteTest extends BaseModelTest { */ function testSaveHabtmCustomKeys() { $this->loadFixtures('Story', 'StoriesTag', 'Tag'); - $Story =& new Story(); + $Story = new Story(); $data = array( 'Story' => array('story' => '1'), @@ -1607,10 +1522,10 @@ class ModelWriteTest extends BaseModelTest { 'Tag' => array(2, 3) )); $result = $Story->set($data); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $result = $Story->save(); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $result = $Story->find('all', array('order' => array('Story.story'))); $expected = array( @@ -1650,7 +1565,7 @@ class ModelWriteTest extends BaseModelTest { */ function testHabtmSaveWithConditionsInAssociation() { $this->loadFixtures('JoinThing', 'Something', 'SomethingElse'); - $Something =& new Something(); + $Something = new Something(); $Something->unbindModel(array('hasAndBelongsToMany' => array('SomethingElse')), false); $Something->bindModel(array( @@ -1684,7 +1599,7 @@ class ModelWriteTest extends BaseModelTest { ); $Something->create($data); $result = $Something->save(); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $result = $Something->read(null, 1); $this->assertEqual(count($result['NotDoomedSomethingElse']), 2); @@ -1698,7 +1613,7 @@ class ModelWriteTest extends BaseModelTest { */ function testHabtmSaveKeyResolution() { $this->loadFixtures('Apple', 'Device', 'ThePaperMonkies'); - $ThePaper =& new ThePaper(); + $ThePaper = new ThePaper(); $ThePaper->id = 1; $ThePaper->save(array('Monkey' => array(2, 3))); @@ -1788,7 +1703,7 @@ class ModelWriteTest extends BaseModelTest { */ function testCreationOfEmptyRecord() { $this->loadFixtures('Author'); - $TestModel =& new Author(); + $TestModel = new Author(); $this->assertEqual($TestModel->find('count'), 4); $TestModel->deleteAll(true, false, false); @@ -1807,7 +1722,7 @@ class ModelWriteTest extends BaseModelTest { * @return void */ function testCreateWithPKFiltering() { - $TestModel =& new Article(); + $TestModel = new Article(); $data = array( 'id' => 5, 'user_id' => 2, @@ -1905,8 +1820,8 @@ class ModelWriteTest extends BaseModelTest { */ function testCreationWithMultipleData() { $this->loadFixtures('Article', 'Comment'); - $Article =& new Article(); - $Comment =& new Comment(); + $Article = new Article(); + $Comment = new Comment(); $articles = $Article->find('all', array( 'fields' => array('id','title'), @@ -1988,9 +1903,9 @@ class ModelWriteTest extends BaseModelTest { $result = $Comment->create($data); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $result = $Comment->save(); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $articles = $Article->find('all', array( 'fields' => array('id','title'), @@ -2077,8 +1992,8 @@ class ModelWriteTest extends BaseModelTest { */ function testCreationWithMultipleDataSameModel() { $this->loadFixtures('Article'); - $Article =& new Article(); - $SecondaryArticle =& new Article(); + $Article = new Article(); + $SecondaryArticle = new Article(); $result = $Article->field('title', array('id' => 1)); $this->assertEqual($result, 'First Article'); @@ -2096,7 +2011,7 @@ class ModelWriteTest extends BaseModelTest { $Article->create(); $result = $Article->save($data); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $result = $Article->getInsertID(); $this->assertTrue(!empty($result)); @@ -2136,8 +2051,8 @@ class ModelWriteTest extends BaseModelTest { */ function testCreationWithMultipleDataSameModelManualInstances() { $this->loadFixtures('PrimaryModel'); - $Primary =& new PrimaryModel(); - $Secondary =& new PrimaryModel(); + $Primary = new PrimaryModel(); + $Secondary = new PrimaryModel(); $result = $Primary->field('primary_name', array('id' => 1)); $this->assertEqual($result, 'Primary Name Existing'); @@ -2152,7 +2067,7 @@ class ModelWriteTest extends BaseModelTest { $Primary->create(); $result = $Primary->save($data); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $result = $Primary->field('primary_name', array('id' => 1)); $this->assertEqual($result, 'Primary Name Existing'); @@ -2175,7 +2090,7 @@ class ModelWriteTest extends BaseModelTest { */ function testRecordExists() { $this->loadFixtures('User'); - $TestModel =& new User(); + $TestModel = new User(); $this->assertFalse($TestModel->exists()); $TestModel->read(null, 1); @@ -2185,7 +2100,7 @@ class ModelWriteTest extends BaseModelTest { $TestModel->id = 4; $this->assertTrue($TestModel->exists()); - $TestModel =& new TheVoid(); + $TestModel = new TheVoid(); $this->assertFalse($TestModel->exists()); $TestModel->id = 5; @@ -2203,7 +2118,7 @@ class ModelWriteTest extends BaseModelTest { */ function testUpdateExisting() { $this->loadFixtures('User', 'Article', 'Comment'); - $TestModel =& new User(); + $TestModel = new User(); $TestModel->create(); $TestModel->save(array( @@ -2224,8 +2139,8 @@ class ModelWriteTest extends BaseModelTest { $this->assertEqual($result['User']['user'], 'updated user'); $this->assertEqual($result['User']['password'], 'some password'); - $Article =& new Article(); - $Comment =& new Comment(); + $Article = new Article(); + $Comment = new Comment(); $data = array( 'Comment' => array( 'id' => 1, @@ -2237,10 +2152,10 @@ class ModelWriteTest extends BaseModelTest { )); $result = $Article->save($data); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $result = $Comment->save($data); - $this->assertTrue($result); + $this->assertFalse(empty($result)); } /** @@ -2251,7 +2166,7 @@ class ModelWriteTest extends BaseModelTest { */ function testUpdateMultiple() { $this->loadFixtures('Comment', 'Article', 'User', 'CategoryThread'); - $TestModel =& new Comment(); + $TestModel = new Comment(); $result = Set::extract($TestModel->find('all'), '{n}.Comment.user_id'); $expected = array('2', '4', '1', '1', '1', '2'); $this->assertEqual($result, $expected); @@ -2265,7 +2180,7 @@ class ModelWriteTest extends BaseModelTest { array('Comment.comment' => "'Updated today'"), array('Comment.user_id' => 5) ); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $result = Set::extract( $TestModel->find('all', array( 'conditions' => array( @@ -2284,8 +2199,8 @@ class ModelWriteTest extends BaseModelTest { * @return void */ function testHabtmUuidWithUuidId() { - $this->loadFixtures('Uuidportfolio', 'Uuiditem', 'UuiditemsUuidportfolio'); - $TestModel =& new Uuidportfolio(); + $this->loadFixtures('Uuidportfolio', 'Uuiditem', 'UuiditemsUuidportfolio', 'UuiditemsUuidportfolioNumericid'); + $TestModel = new Uuidportfolio(); $data = array('Uuidportfolio' => array('name' => 'Portfolio 3')); $data['Uuiditem']['Uuiditem'] = array('483798c8-c7cc-430e-8cf9-4fcc40cf8569'); @@ -2304,7 +2219,7 @@ class ModelWriteTest extends BaseModelTest { */ function testHabtmSavingWithNoPrimaryKeyUuidJoinTable() { $this->loadFixtures('UuidTag', 'Fruit', 'FruitsUuidTag'); - $Fruit =& new Fruit(); + $Fruit = new Fruit(); $data = array( 'Fruit' => array( 'color' => 'Red', @@ -2318,7 +2233,8 @@ class ModelWriteTest extends BaseModelTest { ) ) ); - $this->assertTrue($Fruit->save($data)); + $result = $Fruit->save($data); + $this->assertFalse(empty($result)); } /** @@ -2328,7 +2244,7 @@ class ModelWriteTest extends BaseModelTest { */ function testHabtmSavingWithNoPrimaryKeyUuidJoinTableNoWith() { $this->loadFixtures('UuidTag', 'Fruit', 'FruitsUuidTag'); - $Fruit =& new FruitNoWith(); + $Fruit = new FruitNoWith(); $data = array( 'Fruit' => array( 'color' => 'Red', @@ -2342,7 +2258,8 @@ class ModelWriteTest extends BaseModelTest { ) ) ); - $this->assertTrue($Fruit->save($data)); + $result = $Fruit->save($data); + $this->assertFalse(empty($result)); } /** @@ -2353,7 +2270,7 @@ class ModelWriteTest extends BaseModelTest { */ function testHabtmUuidWithNumericId() { $this->loadFixtures('Uuidportfolio', 'Uuiditem', 'UuiditemsUuidportfolioNumericid'); - $TestModel =& new Uuiditem(); + $TestModel = new Uuiditem(); $data = array('Uuiditem' => array('name' => 'Item 7', 'published' => 0)); $data['Uuidportfolio']['Uuidportfolio'] = array('480af662-eb8c-47d3-886b-230540cf8569'); @@ -2491,7 +2408,7 @@ class ModelWriteTest extends BaseModelTest { */ function testSaveAll() { $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment'); - $TestModel =& new Post(); + $TestModel = new Post(); $result = $TestModel->find('all'); $this->assertEqual(count($result), 3); @@ -2576,7 +2493,7 @@ class ModelWriteTest extends BaseModelTest { ))); $this->assertEqual($result, $expected); - $TestModel =& new Comment(); + $TestModel = new Comment(); $ts = date('Y-m-d H:i:s'); $result = $TestModel->saveAll(array( 'Comment' => array( @@ -2588,7 +2505,7 @@ class ModelWriteTest extends BaseModelTest { 'Attachment' => array( 'attachment' => 'some_file.tgz' ))); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $result = $TestModel->find('all'); $expected = array( @@ -2644,9 +2561,9 @@ class ModelWriteTest extends BaseModelTest { 'comment' => 'Article comment', 'user_id' => 1 ))); - $Article =& new Article(); + $Article = new Article(); $result = $Article->saveAll($data); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $result = $Article->read(); $this->assertEqual(count($result['Tag']), 2); @@ -2678,9 +2595,9 @@ class ModelWriteTest extends BaseModelTest { ) ); - $Something =& new Something(); + $Something = new Something(); $result = $Something->saveAll($data); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $result = $Something->read(); $this->assertEqual(count($result['SomethingElse']), 3); @@ -2810,7 +2727,7 @@ class ModelWriteTest extends BaseModelTest { $model->Attachment->validate = array('attachment' => 'notEmpty'); $model->Attachment->bindModel(array('belongsTo' => array('Comment'))); - $this->assertFalse($model->saveAll( + $this->assertEquals($model->saveAll( array( 'Comment' => array( 'comment' => '', @@ -2820,7 +2737,7 @@ class ModelWriteTest extends BaseModelTest { 'Attachment' => array('attachment' => '') ), array('validate' => 'first') - )); + ), array()); $expected = array( 'Comment' => array('comment' => 'This field cannot be left blank'), 'Attachment' => array('attachment' => 'This field cannot be left blank') @@ -2847,7 +2764,7 @@ class ModelWriteTest extends BaseModelTest { */ function testSaveAllAtomic() { $this->loadFixtures('Article', 'User'); - $TestModel =& new Article(); + $TestModel = new Article(); $result = $TestModel->saveAll(array( 'Article' => array( @@ -2922,7 +2839,7 @@ class ModelWriteTest extends BaseModelTest { */ function testSaveAllHasMany() { $this->loadFixtures('Article', 'Comment'); - $TestModel =& new Article(); + $TestModel = new Article(); $TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array(); $result = $TestModel->saveAll(array( @@ -2932,7 +2849,7 @@ class ModelWriteTest extends BaseModelTest { array('comment' => 'Second new comment', 'published' => 'Y', 'user_id' => 2) ) )); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $result = $TestModel->findById(2); $expected = array( @@ -2954,7 +2871,7 @@ class ModelWriteTest extends BaseModelTest { ))), array('atomic' => false) ); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $result = $TestModel->findById(2); $expected = array( @@ -2999,7 +2916,7 @@ class ModelWriteTest extends BaseModelTest { */ function testSaveAllHasManyValidation() { $this->loadFixtures('Article', 'Comment'); - $TestModel =& new Article(); + $TestModel = new Article(); $TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array(); $TestModel->Comment->validate = array('comment' => 'notEmpty'); @@ -3040,7 +2957,7 @@ class ModelWriteTest extends BaseModelTest { */ function testSaveAllTransaction() { $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment'); - $TestModel =& new Post(); + $TestModel = new Post(); $TestModel->validate = array('title' => 'notEmpty'); $data = array( @@ -3049,7 +2966,7 @@ class ModelWriteTest extends BaseModelTest { array('author_id' => 1, 'title' => '') ); $ts = date('Y-m-d H:i:s'); - $this->assertFalse($TestModel->saveAll($data)); + $this->assertEquals($TestModel->saveAll($data), array()); $result = $TestModel->find('all', array('recursive' => -1)); $expected = array( @@ -3118,7 +3035,7 @@ class ModelWriteTest extends BaseModelTest { array('author_id' => 1, 'title' => 'New Sixth Post') ); $ts = date('Y-m-d H:i:s'); - $this->assertFalse($TestModel->saveAll($data)); + $this->assertEquals($TestModel->saveAll($data), array()); $result = $TestModel->find('all', array('recursive' => -1)); $expected = array( @@ -3237,7 +3154,7 @@ class ModelWriteTest extends BaseModelTest { */ function testSaveAllValidation() { $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment'); - $TestModel =& new Post(); + $TestModel = new Post(); $data = array( array( @@ -3316,7 +3233,7 @@ class ModelWriteTest extends BaseModelTest { 'body' => 'Trying to get away with an empty title' )); $result = $TestModel->saveAll($data); - $this->assertEqual($result, false); + $this->assertEqual($result, array()); $result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); $errors = array(1 => array('title' => 'This field cannot be left blank')); @@ -3402,7 +3319,7 @@ class ModelWriteTest extends BaseModelTest { 'title' => '', 'body' => 'Trying to get away with an empty title' )); - $this->assertFalse($TestModel->saveAll($data, array('validate' => 'first'))); + $this->assertEquals($TestModel->saveAll($data, array('validate' => 'first')), array()); $result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); $this->assertEqual($result, $expected); @@ -3429,7 +3346,8 @@ class ModelWriteTest extends BaseModelTest { * @return void */ function testSaveAllValidationOnly() { - $TestModel =& new Comment(); + $this->loadFixtures('Comment', 'Attachment'); + $TestModel = new Comment(); $TestModel->Attachment->validate = array('attachment' => 'notEmpty'); $data = array( @@ -3444,7 +3362,7 @@ class ModelWriteTest extends BaseModelTest { $result = $TestModel->saveAll($data, array('validate' => 'only')); $this->assertFalse($result); - $TestModel =& new Article(); + $TestModel = new Article(); $TestModel->validate = array('title' => 'notEmpty'); $result = $TestModel->saveAll( array( @@ -3482,7 +3400,8 @@ class ModelWriteTest extends BaseModelTest { * @return void */ function testSaveAllValidateFirst() { - $model =& new Article(); + $this->loadFixtures('Article', 'Comment', 'Attachment'); + $model = new Article(); $model->deleteAll(true); $model->Comment->validate = array('comment' => 'notEmpty'); @@ -3497,7 +3416,7 @@ class ModelWriteTest extends BaseModelTest { ) ), array('validate' => 'first')); - $this->assertFalse($result); + $this->assertEquals($result, array()); $result = $model->find('all'); $this->assertEqual($result, array()); @@ -3529,7 +3448,7 @@ class ModelWriteTest extends BaseModelTest { $result = $model->Comment->find('all'); $this->assertIdentical(count($result), 1); $result = Set::extract('/Comment/article_id', $result); - $this->assertTrue($result[0] === 1 || $result[0] === '1'); + $this->assertEquals($result[0], 4); $model->deleteAll(true); @@ -3544,7 +3463,7 @@ class ModelWriteTest extends BaseModelTest { )); $result = $model->Comment->saveAll($data, array('validate' => 'first')); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $result = $model->find('all'); $this->assertEqual( @@ -3562,14 +3481,14 @@ class ModelWriteTest extends BaseModelTest { */ function testUpdateWithCalculation() { $this->loadFixtures('DataTest'); - $model =& new DataTest(); + $model = new DataTest(); $result = $model->saveAll(array( array('count' => 5, 'float' => 1.1), array('count' => 3, 'float' => 1.2), array('count' => 4, 'float' => 1.3), array('count' => 1, 'float' => 2.0), )); - $this->assertTrue($result); + $this->assertFalse(empty($result)); $result = Set::extract('/DataTest/count', $model->find('all', array('fields' => 'count'))); $this->assertEqual($result, array(5, 3, 4, 1)); @@ -3590,8 +3509,8 @@ class ModelWriteTest extends BaseModelTest { * @return void */ function testSaveAllHasManyValidationOnly() { - $this->loadFixtures('Article', 'Comment'); - $TestModel =& new Article(); + $this->loadFixtures('Article', 'Comment', 'Attachment'); + $TestModel = new Article(); $TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array(); $TestModel->Comment->validate = array('comment' => 'notEmpty'); @@ -3668,7 +3587,7 @@ class ModelWriteTest extends BaseModelTest { */ function testFindAllForeignKey() { $this->loadFixtures('ProductUpdateAll', 'GroupUpdateAll'); - $ProductUpdateAll =& new ProductUpdateAll(); + $ProductUpdateAll = new ProductUpdateAll(); $conditions = array('Group.name' => 'group one'); @@ -3736,7 +3655,7 @@ class ModelWriteTest extends BaseModelTest { '%s Currently, there is no way of doing joins in an update statement in postgresql' ); $this->loadFixtures('ProductUpdateAll', 'GroupUpdateAll'); - $ProductUpdateAll =& new ProductUpdateAll(); + $ProductUpdateAll = new ProductUpdateAll(); $conditions = array('Group.name' => 'group one'); @@ -3787,7 +3706,7 @@ class ModelWriteTest extends BaseModelTest { '%s Currently, there is no way of doing joins in an update statement in postgresql' ); $this->loadFixtures('ProductUpdateAll', 'GroupUpdateAll'); - $ProductUpdateAll =& new ProductUpdateAll(); + $ProductUpdateAll = new ProductUpdateAll(); $conditions = array('Group.name' => 'group one'); @@ -3838,14 +3757,14 @@ class ModelWriteTest extends BaseModelTest { * @return void */ function testSaveAllEmptyData() { - $this->loadFixtures('Article', 'ProductUpdateAll'); - $model =& new Article(); + $this->loadFixtures('Article', 'ProductUpdateAll', 'Comment', 'Attachment'); + $model = new Article(); $result = $model->saveAll(array(), array('validate' => 'first')); - $this->assertTrue($result); + $this->assertFalse(empty($result)); - $model =& new ProductUpdateAll(); + $model = new ProductUpdateAll(); $result = $model->saveAll(array()); $this->assertFalse($result); } -} +} \ No newline at end of file