Added some tests for related models afterFind callback

This commit is contained in:
k-halaburda 2013-08-13 09:29:14 +02:00
parent 3855c0690e
commit 8e40a3a3d3
7 changed files with 14407 additions and 14009 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,5 @@
<?php
/**
* ModelReadTest file
*
@ -17,7 +18,6 @@
* @since CakePHP(tm) v 1.2.0.4206
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
require_once dirname(__FILE__) . DS . 'ModelTestBase.php';
/**
@ -27,7 +27,7 @@ require_once dirname(__FILE__) . DS . 'ModelTestBase.php';
*/
class ModelReadTest extends BaseModelTest {
/**
/**
* testExists function
* @return void
*/
@ -46,7 +46,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertFalse($TestModel->exists(2));
}
/**
/**
* testFetchingNonUniqueFKJoinTableRecords()
*
* Tests if the results are properly returned in the case there are non-unique FK's
@ -88,7 +88,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertTrue(in_array(false, $doomed));
}
/**
/**
* testGroupBy method
*
* These tests will never pass with Postgres or Oracle as all fields in a select must be
@ -248,7 +248,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testOldQuery method
*
* @return void
@ -284,7 +284,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertTrue(is_array($results));
}
/**
/**
* testPreparedQuery method
*
* @return void
@ -351,7 +351,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertFalse($result === false);
}
/**
/**
* testParameterMismatch method
*
* @expectedException PDOException
@ -370,7 +370,7 @@ class ModelReadTest extends BaseModelTest {
$Article->query($query, $params);
}
/**
/**
* testVeryStrangeUseCase method
*
* @expectedException PDOException
@ -390,7 +390,7 @@ class ModelReadTest extends BaseModelTest {
$Article->query($query, $param);
}
/**
/**
* testRecursiveUnbind method
*
* @return void
@ -2986,7 +2986,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testSelfAssociationAfterFind method
*
* @return void
@ -3008,7 +3008,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($afterFindData, $noAfterFindData);
}
/**
/**
* Test that afterFind can completely unset data.
*
* @return void
@ -3027,12 +3027,11 @@ class ModelReadTest extends BaseModelTest {
$model->ModifiedComment->remove = true;
$result = $model->find('all');
$this->assertTrue(
empty($result[0]['ModifiedComment']),
'Zeroith row should be removed by afterFind'
empty($result[0]['ModifiedComment']), 'Zeroith row should be removed by afterFind'
);
}
/**
/**
* testFindThreadedNoParent method
*
* @return void
@ -3046,7 +3045,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testFindThreaded method
*
* @return void
@ -3132,7 +3131,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testFindAllThreaded method
*
* @return void
@ -3608,7 +3607,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* test find('neighbors')
*
* @return void
@ -3762,7 +3761,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* Test find(neighbors) with missing fields so no neighbors are found.
*
* @return void
@ -3787,7 +3786,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testFindCombinedRelations method
*
* @return void
@ -4065,7 +4064,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testSaveEmpty method
*
* @return void
@ -4078,7 +4077,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertFalse($expected);
}
/**
/**
* testFindAllWithConditionInChildQuery
*
* @return void
@ -4121,7 +4120,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testFindAllWithConditionsHavingMixedDataTypes method
*
* @return void
@ -4202,22 +4201,14 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testBindUnbind method
*
* @return void
*/
public function testBindUnbind() {
$this->loadFixtures(
'User',
'Comment',
'FeatureSet',
'DeviceType',
'DeviceTypeCategory',
'ExteriorTypeCategory',
'Device',
'Document',
'DocumentDirectory'
'User', 'Comment', 'FeatureSet', 'DeviceType', 'DeviceTypeCategory', 'ExteriorTypeCategory', 'Device', 'Document', 'DocumentDirectory'
);
$TestModel = new User();
@ -4695,7 +4686,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertTrue(is_object($TestModel2->NewFeatureSet));
}
/**
/**
* testBindMultipleTimes method
*
* @return void
@ -4867,7 +4858,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* test that multiple reset = true calls to bindModel() result in the original associations.
*
* @return void
@ -4883,7 +4874,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertFalse(isset($TestModel->hasMany['Comment']), 'Association left behind');
}
/**
/**
* testBindMultipleTimes method with different reset settings
*
* @return void
@ -4901,8 +4892,7 @@ class ModelReadTest extends BaseModelTest {
));
$this->assertTrue($result);
$result = $TestModel->bindModel(
array('hasMany' => array('Article')),
false
array('hasMany' => array('Article')), false
);
$this->assertTrue($result);
@ -4917,7 +4907,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* test that bindModel behaves with Custom primary Key associations
*
* @return void
@ -4936,7 +4926,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertFalse(empty($result));
}
/**
/**
* test that calling unbindModel() with reset == true multiple times
* leaves associations in the correct state.
*
@ -4953,7 +4943,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertTrue(isset($TestModel->hasMany['Comment']), 'Association permanently removed');
}
/**
/**
* testBindMultipleTimes method with different reset settings
*
* @return void
@ -4971,8 +4961,7 @@ class ModelReadTest extends BaseModelTest {
));
$this->assertTrue($result);
$result = $TestModel->unbindModel(
array('belongsTo' => array('Article')),
false
array('belongsTo' => array('Article')), false
);
$this->assertTrue($result);
@ -4987,7 +4976,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testAssociationAfterFind method
*
* @return void
@ -5082,7 +5071,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result[0]['Post'][0]['Comment'][0]);
}
/**
/**
* testDeeperAssociationAfterFind method
*
* @return void
@ -5115,7 +5104,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals('Fired', $result['Comment'][0]['Attachment']['callback']);
}
/**
/**
* Tests that callbacks can be properly disabled
*
* @return void
@ -5141,7 +5130,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testAssociationAfterFindCallbacksDisabled method
*
* @return void
@ -5234,7 +5223,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result[0]['Post'][0]['Comment'][0]);
}
/**
/**
* Tests that the database configuration assigned to the model can be changed using
* (before|after)Find callbacks
*
@ -5246,7 +5235,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals(3, count($TestModel->find('all')));
}
/**
/**
* testCallbackSourceChangeUnknownDatasource method
*
* @expectedException MissingDatasourceConfigException
@ -5258,20 +5247,14 @@ class ModelReadTest extends BaseModelTest {
$this->assertFalse($TestModel->find('all', array('connection' => 'foo')));
}
/**
/**
* testMultipleBelongsToWithSameClass method
*
* @return void
*/
public function testMultipleBelongsToWithSameClass() {
$this->loadFixtures(
'DeviceType',
'DeviceTypeCategory',
'FeatureSet',
'ExteriorTypeCategory',
'Document',
'Device',
'DocumentDirectory'
'DeviceType', 'DeviceTypeCategory', 'FeatureSet', 'ExteriorTypeCategory', 'Document', 'Device', 'DocumentDirectory'
);
$DeviceType = new DeviceType();
@ -5356,7 +5339,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testHabtmRecursiveBelongsTo method
*
* @return void
@ -5414,7 +5397,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testNonNumericHabtmJoinKey method
*
* @return void
@ -5516,7 +5499,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testHabtmFinderQuery method
*
* @return void
@ -5545,8 +5528,7 @@ class ModelReadTest extends BaseModelTest {
)),
'conditions' => array(),
'order' => null
),
$Article
), $Article
);
$Article->hasAndBelongsToMany['Tag']['finderQuery'] = $sql;
@ -5564,7 +5546,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result['Tag']);
}
/**
/**
* testHabtmLimitOptimization method
*
* @return void
@ -5634,7 +5616,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testHasManyLimitOptimization method
*
* @return void
@ -5750,7 +5732,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testFindAllRecursiveSelfJoin method
*
* @return void
@ -5858,18 +5840,14 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testFindAllRecursiveWithHabtm method
*
* @return void
*/
public function testFindAllRecursiveWithHabtm() {
$this->loadFixtures(
'MyCategoriesMyUsers',
'MyCategoriesMyProducts',
'MyCategory',
'MyUser',
'MyProduct'
'MyCategoriesMyUsers', 'MyCategoriesMyProducts', 'MyCategory', 'MyUser', 'MyProduct'
);
$MyUser = new MyUser();
@ -5928,7 +5906,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testReadFakeThread method
*
* @return void
@ -5992,7 +5970,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testFindFakeThread method
*
* @return void
@ -6056,7 +6034,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testFindAllFakeThread method
*
* @return void
@ -6276,7 +6254,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testConditionalNumerics method
*
* @return void
@ -6293,7 +6271,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertTrue(empty($result));
}
/**
/**
* test buildQuery()
*
* @return void
@ -6324,7 +6302,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* test find('all') method
*
* @return void
@ -6553,7 +6531,7 @@ class ModelReadTest extends BaseModelTest {
}
}
/**
/**
* test find('list') method
*
* @return void
@ -6592,8 +6570,7 @@ class ModelReadTest extends BaseModelTest {
$TestModel->find('all', array(
'order' => 'Article.title ASC',
'fields' => array('id', 'title')
)),
'{n}.Article.id', '{n}.Article.title'
)), '{n}.Article.id', '{n}.Article.title'
);
$expected = array(
1 => 'First Article',
@ -6605,8 +6582,7 @@ class ModelReadTest extends BaseModelTest {
$result = Hash::combine(
$TestModel->find('all', array(
'order' => 'Article.title ASC'
)),
'{n}.Article.id', '{n}.Article'
)), '{n}.Article.id', '{n}.Article'
);
$expected = array(
1 => array(
@ -6642,8 +6618,7 @@ class ModelReadTest extends BaseModelTest {
$result = Hash::combine(
$TestModel->find('all', array(
'order' => 'Article.title ASC'
)),
'{n}.Article.id', '{n}.Article', '{n}.Article.user_id'
)), '{n}.Article.id', '{n}.Article', '{n}.Article.user_id'
);
$expected = array(
1 => array(
@ -6682,8 +6657,7 @@ class ModelReadTest extends BaseModelTest {
$TestModel->find('all', array(
'order' => 'Article.title ASC',
'fields' => array('id', 'title', 'user_id')
)),
'{n}.Article.id', '{n}.Article.title', '{n}.Article.user_id'
)), '{n}.Article.id', '{n}.Article.title', '{n}.Article.user_id'
);
$expected = array(
@ -6828,7 +6802,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testFindField method
*
* @return void
@ -6859,7 +6833,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals(4, $result);
}
/**
/**
* testFindUnique method
*
* @return void
@ -6881,7 +6855,7 @@ class ModelReadTest extends BaseModelTest {
)));
}
/**
/**
* test find('count') method
*
* @return void
@ -6929,7 +6903,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* Test that find('first') does not use the id set to the object.
*
* @return void
@ -6944,7 +6918,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals('Project 1', $result['Project']['name'], 'Wrong record retrieved');
}
/**
/**
* test find with COUNT(DISTINCT field)
*
* @return void
@ -6963,7 +6937,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals(4, $result);
}
/**
/**
* Test find(count) with Db::expression
*
* @return void
@ -6986,7 +6960,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals(1, $result);
}
/**
/**
* testFindMagic method
*
* @return void
@ -7017,7 +6991,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testRead method
*
* @return void
@ -7097,20 +7071,14 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testRecursiveRead method
*
* @return void
*/
public function testRecursiveRead() {
$this->loadFixtures(
'User',
'Article',
'Comment',
'Tag',
'ArticlesTag',
'Featured',
'ArticleFeatured'
'User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Featured', 'ArticleFeatured'
);
$TestModel = new User();
@ -7212,16 +7180,7 @@ class ModelReadTest extends BaseModelTest {
public function testRecursiveFindAll() {
$this->loadFixtures(
'User',
'Article',
'Comment',
'Tag',
'ArticlesTag',
'Attachment',
'ArticleFeatured',
'ArticleFeaturedsTags',
'Featured',
'Category'
'User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Attachment', 'ArticleFeatured', 'ArticleFeaturedsTags', 'Featured', 'Category'
);
$TestModel = new Article();
@ -7522,7 +7481,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testRecursiveFindAllWithLimit method
*
* @return void
@ -7688,7 +7647,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* Testing availability of $this->findQueryType in Model callbacks
*
* @return void
@ -7702,7 +7661,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals('first', $comments['Comment']['querytype']);
}
/**
/**
* testVirtualFields()
*
* Test correct fetching of virtual fields
@ -7722,7 +7681,7 @@ class ModelReadTest extends BaseModelTest {
$Post->Author->virtualFields = array('false' => '1 = 2');
$result = $Post->find('first');
$this->assertEquals(2, $result['Post']['two']);
$this->assertFalse((bool)$result['Author']['false']);
$this->assertFalse((bool) $result['Author']['false']);
}
$result = $Post->find('first', array('fields' => array('author_id')));
@ -7786,7 +7745,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals(4, $result);
}
/**
/**
* testVirtualFieldsOrder()
*
* Test correct order on virtual fields
@ -7832,7 +7791,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
/**
* testVirtualFieldsMysql()
*
* Test correct fetching of virtual fields
@ -7885,7 +7844,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertTrue(isset($result['Author']['full_name']));
}
/**
/**
* test that virtual fields work when they don't contain functions.
*
* @return void
@ -7900,7 +7859,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertTrue(isset($result['Post']['writer']), 'virtual field not fetched %s');
}
/**
/**
* test that isVirtualField will accept both aliased and non aliased fieldnames
*
* @return void
@ -7918,7 +7877,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertFalse($Post->isVirtualField(array()));
}
/**
/**
* test that getting virtual fields works with and without model alias attached
*
* @return void
@ -7932,7 +7891,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($Post->getVirtualField('Post.other_field'), $Post->virtualFields['other_field']);
}
/**
/**
* test that checks for error when NOT condition passed in key and a 1 element array value
*
* @return void
@ -7943,8 +7902,7 @@ class ModelReadTest extends BaseModelTest {
$Article->recursive = -1;
$result = $Article->find(
'all',
array(
'all', array(
'conditions' => array(
'Article.id NOT' => array(1)
)
@ -7953,7 +7911,7 @@ class ModelReadTest extends BaseModelTest {
$this->assertTrue(is_array($result) && !empty($result));
}
/**
/**
* test custom find method
*
* @return void
@ -7973,4 +7931,212 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals(1, count($result));
}
/**
* test after find callback on related model
*
* @return void
*/
public function testRelatedAfterFindCallback() {
$this->loadFixtures('ModelWithRelations', 'ModelRelated', 'ModelHabtmRelation');
$ModelWithRelations = new ModelWithRelations();
// belongsTo Test
$ModelWithRelations->bindModel(array(
'belongsTo' => array(
'BelongsTo' => array(
'className' => 'ModelRelated',
'foreignKey' => 'related_id',
)
)
)
);
$results = $ModelWithRelations->find('all');
$expected = array(
array(
'ModelWithRelations' => array(
'id' => '1',
'name' => 'First record',
'related_id' => '1'
),
'BelongsTo' => array(
'id' => '1',
'name' => 'Successfuly changed in AfterFind',
'primary_id' => '1'
)
),
array(
'ModelWithRelations' => array(
'id' => '2',
'name' => 'Second record',
'related_id' => '2'
),
'BelongsTo' => array(
'id' => '2',
'name' => 'Successfuly changed in AfterFind',
'primary_id' => '2'
)
)
);
$this->assertEquals($expected, $results, 'Model related with belongsTo afterFind callback fail');
// hasOne test
$ModelWithRelations->bindModel(array(
'hasOne' => array(
'HasOne' => array(
'className' => 'ModelRelated',
'foreignKey' => 'primary_id',
)
)
)
);
$results = $ModelWithRelations->find('all');
$expected = array(
array(
'ModelWithRelations' => array(
'id' => '1',
'name' => 'First record',
'related_id' => '1'
),
'HasOne' => array(
'id' => '1',
'name' => 'Successfuly changed in AfterFind',
'primary_id' => '1'
)
),
array(
'ModelWithRelations' => array(
'id' => '2',
'name' => 'Second record',
'related_id' => '2'
),
'HasOne' => array(
'id' => '2',
'name' => 'Successfuly changed in AfterFind',
'primary_id' => '2'
)
)
);
$this->assertEquals($expected, $results, 'Model related with hasOne afterFind callback fail');
// hasMany test
$ModelWithRelations->bindModel(array(
'hasMany' => array(
'HasMany' => array(
'className' => 'ModelRelated',
'foreignKey' => 'primary_id',
)
)
)
);
$results = $ModelWithRelations->find('all');
$expected = array(
array(
'ModelWithRelations' => array(
'id' => '1',
'name' => 'First record',
'related_id' => '1'
),
'HasMany' => array(
(int) 0 => array(
'id' => '1',
'name' => 'Successfuly changed in AfterFind',
'primary_id' => '1'
)
)
),
array(
'ModelWithRelations' => array(
'id' => '2',
'name' => 'Second record',
'related_id' => '2'
),
'HasMany' => array(
(int) 0 => array(
'id' => '2',
'name' => 'Successfuly changed in AfterFind',
'primary_id' => '2'
)
)
)
);
$this->assertEquals($expected, $results, 'Model related with hasMany afterFind callback fail');
// hasAndBelongsToMany test
$ModelWithRelations->bindModel(array(
'hasAndBelongsToMany' => array(
'HasAndBelongsToMany' => array(
'className' => 'ModelRelated',
'with' => 'ModelHabtmRelation',
'foreignKey' => 'primary_id',
'associationForeignKey' => 'related_id',
)
)
)
);
$results = $ModelWithRelations->find('all');
$expected = array(
array(
'ModelWithRelations' => array(
'id' => '1',
'name' => 'First record',
'related_id' => '1'
),
'HasAndBelongsToMany' => array(
(int) 0 => array(
'id' => '1',
'name' => 'Successfuly changed in AfterFind',
'primary_id' => '1',
'ModelHabtmRelation' => array(
'id' => '1',
'primary_id' => '1',
'related_id' => '1'
)
),
(int) 1 => array(
'id' => '2',
'name' => 'Successfuly changed in AfterFind',
'primary_id' => '2',
'ModelHabtmRelation' => array(
'id' => '2',
'primary_id' => '1',
'related_id' => '2'
)
)
)
),
array(
'ModelWithRelations' => array(
'id' => '2',
'name' => 'Second record',
'related_id' => '2'
),
'HasAndBelongsToMany' => array(
(int) 0 => array(
'id' => '1',
'name' => 'Successfuly changed in AfterFind',
'primary_id' => '1',
'ModelHabtmRelation' => array(
'id' => '3',
'primary_id' => '2',
'related_id' => '1'
)
),
(int) 1 => array(
'id' => '2',
'name' => 'Successfuly changed in AfterFind',
'primary_id' => '2',
'ModelHabtmRelation' => array(
'id' => '4',
'primary_id' => '2',
'related_id' => '2'
)
)
)
)
);
$this->assertEquals($expected, $results, 'Model related with hasAndBelongsToMany afterFind callback fail');
}
}

View file

@ -1,4 +1,5 @@
<?php
/**
* ModelTest file
*
@ -17,7 +18,6 @@
* @since CakePHP(tm) v 1.2.0.4206
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Model', 'Model');
App::uses('AppModel', 'Model');
require_once dirname(__FILE__) . DS . 'models.php';
@ -29,21 +29,21 @@ require_once dirname(__FILE__) . DS . 'models.php';
*/
abstract class BaseModelTest extends CakeTestCase {
/**
/**
* autoFixtures property
*
* @var bool false
*/
public $autoFixtures = false;
/**
/**
* Whether backup global state for each test method or not
*
* @var bool false
*/
public $backupGlobals = false;
/**
/**
* fixtures property
*
* @var array
@ -72,9 +72,10 @@ abstract class BaseModelTest extends CakeTestCase {
'core.fruits_uuid_tag', 'core.uuid_tag', 'core.product_update_all', 'core.group_update_all',
'core.player', 'core.guild', 'core.guilds_player', 'core.armor', 'core.armors_player',
'core.bidding', 'core.bidding_message', 'core.site', 'core.domain', 'core.domains_site',
'core.model_with_relations','core.model_related','core.model_habtm_relation',
);
/**
/**
* setUp method
*
* @return void
@ -84,7 +85,7 @@ abstract class BaseModelTest extends CakeTestCase {
$this->debug = Configure::read('debug');
}
/**
/**
* tearDown method
*
* @return void
@ -94,4 +95,5 @@ abstract class BaseModelTest extends CakeTestCase {
Configure::write('debug', $this->debug);
ClassRegistry::flush();
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,52 @@
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
* Class PrimaryRelatedFixture
*
* @package Cake.Test.Fixture
*/
class ModelHabtmRelationFixture extends CakeTestFixture {
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'primary_id' => array('type' => 'integer'),
'related_id' => array('type' => 'integer'),
);
/**
* records property
*
* @var array
*/
public $records = array(
array('id' => 1, 'primary_id' => 1, 'related_id' => 1),
array('id' => 2, 'primary_id' => 1, 'related_id' => 2),
array('id' => 3, 'primary_id' => 2, 'related_id' => 1),
array('id' => 4, 'primary_id' => 2, 'related_id' => 2),
);
}

View file

@ -0,0 +1,50 @@
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
* Class RelatedFixture
*
* @package Cake.Test.Fixture
*/
class ModelRelatedFixture extends CakeTestFixture {
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'name' => array('type' => 'string'),
'primary_id' => array('type' => 'integer'),
);
/**
* records property
*
* @var array
*/
public $records = array(
array('id' => 1, 'name' => 'This should change on afterFind', 'primary_id' => 1),
array('id' => 2, 'name' => 'This also should change on afterFind', 'primary_id' => 2)
);
}

View file

@ -0,0 +1,50 @@
<?php
/**
* Short description for file.
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
* Class PrimaryFixture
*
* @package Cake.Test.Fixture
*/
class ModelWithRelationsFixture extends CakeTestFixture {
/**
* fields property
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'name' => array('type' => 'string'),
'related_id' => array('type' => 'integer'),
);
/**
* records property
*
* @var array
*/
public $records = array(
array('id' => 1, 'name' => 'First record', 'related_id' => 1),
array('id' => 2, 'name' => 'Second record', 'related_id' => 2)
);
}