Skip to content

Commit

Permalink
Completing migration of ModelIntegration test case to phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jun 24, 2010
1 parent 1ce18ee commit 72c7c3f
Showing 1 changed file with 38 additions and 50 deletions.
88 changes: 38 additions & 50 deletions cake/tests/cases/libs/model/model_integration.test.php
Expand Up @@ -58,7 +58,7 @@ class ModelIntegrationTest extends BaseModelTest {
*/
function testPkInHabtmLinkModelArticleB() {
$this->loadFixtures('Article', 'Tag', 'ArticlesTag');
$TestModel2 =& new ArticleB();
$TestModel2 = new ArticleB();
$this->assertEqual($TestModel2->ArticlesTag->primaryKey, 'article_id');
}

Expand Down Expand Up @@ -92,21 +92,21 @@ function testCacheSourcesDisabling() {
function testPkInHabtmLinkModel() {
//Test Nonconformant Models
$this->loadFixtures('Content', 'ContentAccount', 'Account', 'JoinC', 'JoinAC');
$TestModel =& new Content();
$TestModel = new Content();
$this->assertEqual($TestModel->ContentAccount->primaryKey, 'iContentAccountsId');

//test conformant models with no PK in the join table
$this->loadFixtures('Article', 'Tag', 'User', 'Comment', 'Attachment', 'Syfile', 'Image', 'Item', 'Portfolio', 'ItemsPortfolio');
$TestModel2 =& new Article();
$TestModel2 = new Article();
$this->assertEqual($TestModel2->ArticlesTag->primaryKey, 'article_id');

//test conformant models with PK in join table
$TestModel3 =& new Portfolio();
$TestModel3 = new Portfolio();
$this->assertEqual($TestModel3->ItemsPortfolio->primaryKey, 'id');

//test conformant models with PK in join table - join table contains extra field
$this->loadFixtures('JoinA', 'JoinB', 'JoinAB');
$TestModel4 =& new JoinA();
$TestModel4 = new JoinA();
$this->assertEqual($TestModel4->JoinAsJoinB->primaryKey, 'id');

}
Expand All @@ -119,7 +119,7 @@ function testPkInHabtmLinkModel() {
*/
function testDynamicBehaviorAttachment() {
$this->loadFixtures('Apple', 'Sample', 'Author');
$TestModel =& new Apple();
$TestModel = new Apple();
$this->assertEqual($TestModel->Behaviors->attached(), array());

$TestModel->Behaviors->attach('Tree', array('left' => 'left_field', 'right' => 'right_field'));
Expand Down Expand Up @@ -168,7 +168,7 @@ function testCrossDatabaseJoins() {
}

$this->loadFixtures('Article', 'Tag', 'ArticlesTag', 'User', 'Comment');
$TestModel =& new Article();
$TestModel = new Article();

$expected = array(
array(
Expand Down Expand Up @@ -309,16 +309,8 @@ function testCrossDatabaseJoins() {
));
$this->assertEqual($TestModel->find('all'), $expected);

$db2 =& ConnectionManager::getDataSource('test2');

foreach (array('User', 'Comment') as $class) {
$this->_fixtures[$this->_fixtureClassMap[$class]]->create($db2);
$this->_fixtures[$this->_fixtureClassMap[$class]]->insert($db2);
$this->db->truncate(Inflector::pluralize(Inflector::underscore($class)));
}

$this->assertEqual($TestModel->User->find('all'), array());
$this->assertEqual($TestModel->Comment->find('all'), array());
$db2 = ConnectionManager::getDataSource('test2');
$this->loadFixtures('User', 'Comment');
$this->assertEqual($TestModel->find('count'), 3);

$TestModel->User->setDataSource('test2');
Expand Down Expand Up @@ -505,10 +497,6 @@ function testCrossDatabaseJoins() {
'updated' => '2007-03-18 10:43:31'
)));
$this->assertEqual($TestModel->Comment->find('all'), $expected);

foreach (array('User', 'Comment') as $class) {
$this->_fixtures[$this->_fixtureClassMap[$class]]->drop($db2);
}
}

/**
Expand Down Expand Up @@ -558,7 +546,7 @@ function testSchema() {
*/
function testDeconstructFieldsTime() {
$this->loadFixtures('Apple');
$TestModel =& new Apple();
$TestModel = new Apple();

$data = array();
$data['Apple']['mytime']['hour'] = '';
Expand Down Expand Up @@ -645,7 +633,7 @@ function testDeconstructFieldsTime() {
*/
function testDeconstructFieldsDateTime() {
$this->loadFixtures('Apple');
$TestModel =& new Apple();
$TestModel = new Apple();

//test null/empty values first
$data['Apple']['created']['year'] = '';
Expand Down Expand Up @@ -875,7 +863,7 @@ function testTablePrefixSwitching() {
* @return void
*/
function testInvalidAssociation() {
$TestModel =& new ValidationTest1();
$TestModel = new ValidationTest1();
$this->assertNull($TestModel->getAssociated('Foo'));
}

Expand Down Expand Up @@ -904,7 +892,7 @@ function testLoadModelSecondIteration() {
*/
function testResetOfExistsOnCreate() {
$this->loadFixtures('Article');
$Article =& new Article();
$Article = new Article();
$Article->id = 1;
$Article->saveField('title', 'Reset me');
$Article->delete();
Expand All @@ -926,7 +914,7 @@ function testResetOfExistsOnCreate() {
*/
function testUseTableFalseExistsCheck() {
$this->loadFixtures('Article');
$Article =& new Article();
$Article = new Article();
$Article->id = 1337;
$result = $Article->exists();
$this->assertFalse($result);
Expand All @@ -951,7 +939,7 @@ function testUseTableFalseExistsCheck() {
*/
function testPluginAssociations() {
$this->loadFixtures('TestPluginArticle', 'User', 'TestPluginComment');
$TestModel =& new TestPluginArticle();
$TestModel = new TestPluginArticle();

$result = $TestModel->find('all');
$expected = array(
Expand Down Expand Up @@ -1120,7 +1108,7 @@ function testGetAssociated() {
*/
function testAutoConstructAssociations() {
$this->loadFixtures('User', 'ArticleFeatured', 'Featured', 'ArticleFeaturedsTags');
$TestModel =& new AssociationTest1();
$TestModel = new AssociationTest1();

$result = $TestModel->hasAndBelongsToMany;
$expected = array('AssociationTest2' => array(
Expand All @@ -1136,8 +1124,8 @@ function testAutoConstructAssociations() {
$this->assertEqual($result, $expected);

// Tests related to ticket https://trac.cakephp.org/ticket/5594
$TestModel =& new ArticleFeatured();
$TestFakeModel =& new ArticleFeatured(array('table' => false));
$TestModel = new ArticleFeatured();
$TestFakeModel = new ArticleFeatured(array('table' => false));

$expected = array(
'User' => array(
Expand Down Expand Up @@ -1229,12 +1217,12 @@ function testAutoConstructAssociations() {
function testConstruct() {
$this->loadFixtures('Post', 'Comment');

$TestModel =& ClassRegistry::init('MergeVarPluginPost');
$TestModel = ClassRegistry::init('MergeVarPluginPost');
$this->assertEqual($TestModel->actsAs, array('Containable', 'Tree'));
$this->assertTrue(isset($TestModel->Behaviors->Containable));
$this->assertTrue(isset($TestModel->Behaviors->Tree));

$TestModel =& ClassRegistry::init('MergeVarPluginComment');
$TestModel = ClassRegistry::init('MergeVarPluginComment');
$expected = array('Containable', 'Containable' => array('some_settings'));
$this->assertEqual($TestModel->actsAs, $expected);
$this->assertTrue(isset($TestModel->Behaviors->Containable));
Expand All @@ -1248,13 +1236,13 @@ function testConstruct() {
* @return void
*/
function testConstructWithAlternateDataSource() {
$TestModel =& ClassRegistry::init(array(
$TestModel = ClassRegistry::init(array(
'class' => 'DoesntMatter', 'ds' => 'test_suite', 'table' => false
));
$this->assertEqual('test_suite', $TestModel->useDbConfig);

//deprecated but test it anyway
$NewVoid =& new TheVoid(null, false, 'other');
$NewVoid = new TheVoid(null, false, 'other');
$this->assertEqual('other', $NewVoid->useDbConfig);
}

Expand All @@ -1265,13 +1253,13 @@ function testConstructWithAlternateDataSource() {
* @return void
*/
function testColumnTypeFetching() {
$model =& new Test();
$model = new Test();
$this->assertEqual($model->getColumnType('id'), 'integer');
$this->assertEqual($model->getColumnType('notes'), 'text');
$this->assertEqual($model->getColumnType('updated'), 'datetime');
$this->assertEqual($model->getColumnType('unknown'), null);

$model =& new Article();
$model = new Article();
$this->assertEqual($model->getColumnType('User.created'), 'datetime');
$this->assertEqual($model->getColumnType('Tag.id'), 'integer');
$this->assertEqual($model->getColumnType('Article.id'), 'integer');
Expand All @@ -1284,7 +1272,7 @@ function testColumnTypeFetching() {
* @return void
*/
function testHabtmUniqueKey() {
$model =& new Item();
$model = new Item();
$this->assertFalse($model->hasAndBelongsToMany['Portfolio']['unique']);
}

Expand All @@ -1295,17 +1283,17 @@ function testHabtmUniqueKey() {
* @return void
*/
function testIdentity() {
$TestModel =& new Test();
$TestModel = new Test();
$result = $TestModel->alias;
$expected = 'Test';
$this->assertEqual($result, $expected);

$TestModel =& new TestAlias();
$TestModel = new TestAlias();
$result = $TestModel->alias;
$expected = 'TestAlias';
$this->assertEqual($result, $expected);

$TestModel =& new Test(array('alias' => 'AnotherTest'));
$TestModel = new Test(array('alias' => 'AnotherTest'));
$result = $TestModel->alias;
$expected = 'AnotherTest';
$this->assertEqual($result, $expected);
Expand All @@ -1319,7 +1307,7 @@ function testIdentity() {
*/
function testWithAssociation() {
$this->loadFixtures('Something', 'SomethingElse', 'JoinThing');
$TestModel =& new Something();
$TestModel = new Something();
$result = $TestModel->SomethingElse->find('all');

$expected = array(
Expand Down Expand Up @@ -1572,7 +1560,7 @@ function testWithAssociation() {
function testFindSelfAssociations() {
$this->loadFixtures('Person');

$TestModel =& new Person();
$TestModel = new Person();
$TestModel->recursive = 2;
$result = $TestModel->read(null, 1);
$expected = array(
Expand Down Expand Up @@ -1681,7 +1669,7 @@ function testFindSelfAssociations() {
*/
function testDynamicAssociations() {
$this->loadFixtures('Article', 'Comment');
$TestModel =& new Article();
$TestModel = new Article();

$TestModel->belongsTo = $TestModel->hasAndBelongsToMany = $TestModel->hasOne = array();
$TestModel->hasMany['Comment'] = array_merge($TestModel->hasMany['Comment'], array(
Expand Down Expand Up @@ -1789,11 +1777,11 @@ function testDynamicAssociations() {
*/
function testCreation() {
$this->loadFixtures('Article', 'ArticleFeaturedsTags');
$TestModel =& new Test();
$TestModel = new Test();
$result = $TestModel->create();
$expected = array('Test' => array('notes' => 'write some notes here'));
$this->assertEqual($result, $expected);
$TestModel =& new User();
$TestModel = new User();
$result = $TestModel->schema();

if (isset($this->db->columns['primary_key']['length'])) {
Expand Down Expand Up @@ -1843,12 +1831,12 @@ function testCreation() {

$this->assertEqual($result, $expected);

$TestModel =& new Article();
$TestModel = new Article();
$result = $TestModel->create();
$expected = array('Article' => array('published' => 'N'));
$this->assertEqual($result, $expected);

$FeaturedModel =& new Featured();
$FeaturedModel = new Featured();
$data = array(
'article_featured_id' => 1,
'category_id' => 1,
Expand Down Expand Up @@ -1907,8 +1895,8 @@ function testCreation() {
* @return void
*/
function testEscapeField() {
$TestModel =& new Test();
$db =& $TestModel->getDataSource();
$TestModel = new Test();
$db = $TestModel->getDataSource();

$result = $TestModel->escapeField('test_field');
$expected = $db->name('Test.test_field');
Expand All @@ -1924,7 +1912,7 @@ function testEscapeField() {

ConnectionManager::create('mock', array('driver' => 'mock'));
$TestModel->setDataSource('mock');
$db =& $TestModel->getDataSource();
$db = $TestModel->getDataSource();

$result = $TestModel->escapeField('DomainHandle', 'Domain');
$expected = $db->name('Domain.DomainHandle');
Expand Down

0 comments on commit 72c7c3f

Please sign in to comment.