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

View file

@ -1,4 +1,5 @@
<?php
/**
* Dbo Source
*
@ -17,7 +18,6 @@
* @since CakePHP(tm) v 0.10.0.1076
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('DataSource', 'Model/Datasource');
App::uses('String', 'Utility');
App::uses('View', 'View');
@ -319,8 +319,7 @@ class DboSource extends DataSource {
public function value($data, $column = null) {
if (is_array($data) && !empty($data)) {
return array_map(
array(&$this, 'value'),
$data, array_fill(0, count($data), $column)
array(&$this, 'value'), $data, array_fill(0, count($data), $column)
);
} elseif (is_object($data) && isset($data->type, $data->value)) {
if ($data->type === 'identifier') {
@ -816,26 +815,22 @@ class DboSource extends DataSource {
return $this->cacheMethod(__FUNCTION__, $cacheKey, $this->startQuote . $data . $this->endQuote);
}
$items = explode('.', $data);
return $this->cacheMethod(__FUNCTION__, $cacheKey,
$this->startQuote . implode($this->endQuote . '.' . $this->startQuote, $items) . $this->endQuote
return $this->cacheMethod(__FUNCTION__, $cacheKey, $this->startQuote . implode($this->endQuote . '.' . $this->startQuote, $items) . $this->endQuote
);
}
if (preg_match('/^[\w-]+\.\*$/', $data)) { // string.*
return $this->cacheMethod(__FUNCTION__, $cacheKey,
$this->startQuote . str_replace('.*', $this->endQuote . '.*', $data)
return $this->cacheMethod(__FUNCTION__, $cacheKey, $this->startQuote . str_replace('.*', $this->endQuote . '.*', $data)
);
}
if (preg_match('/^([\w-]+)\((.*)\)$/', $data, $matches)) { // Functions
return $this->cacheMethod(__FUNCTION__, $cacheKey,
$matches[1] . '(' . $this->name($matches[2]) . ')'
return $this->cacheMethod(__FUNCTION__, $cacheKey, $matches[1] . '(' . $this->name($matches[2]) . ')'
);
}
if (
preg_match('/^([\w-]+(\.[\w-]+|\(.*\))*)\s+' . preg_quote($this->alias) . '\s*([\w-]+)$/i', $data, $matches
)) {
return $this->cacheMethod(
__FUNCTION__, $cacheKey,
preg_replace(
__FUNCTION__, $cacheKey, preg_replace(
'/\s{2,}/', ' ', $this->name($matches[1]) . ' ' . $this->alias . ' ' . $this->name($matches[3])
)
);
@ -1513,8 +1508,7 @@ class DboSource extends DataSource {
'conditions' => $queryData['conditions'],
'order' => $queryData['order'],
'group' => $queryData['group']
),
$model
), $model
);
}
if ($external && !empty($assocData['finderQuery'])) {
@ -1535,8 +1529,7 @@ class DboSource extends DataSource {
case 'hasOne':
case 'belongsTo':
$conditions = $this->_mergeConditions(
$assocData['conditions'],
$this->getConstraint($type, $model, $linkModel, $association, array_merge($assocData, compact('external', 'self')))
$assocData['conditions'], $this->getConstraint($type, $model, $linkModel, $association, array_merge($assocData, compact('external', 'self')))
);
if (!$self && $external) {
@ -1984,8 +1977,7 @@ class DboSource extends DataSource {
'alias' => $assoc,
'type' => isset($assocData['type']) ? $assocData['type'] : 'LEFT',
'conditions' => trim($this->conditions(
$this->_mergeConditions($assocData['conditions'], $this->getConstraint($assocData['association'], $model, $model->{$assoc}, $assoc, $assocData)),
true, false, $model
$this->_mergeConditions($assocData['conditions'], $this->getConstraint($assocData['association'], $model, $model->{$assoc}, $assoc, $assocData)), true, false, $model
))
));
}
@ -2641,9 +2633,7 @@ class DboSource extends DataSource {
}
$conditions = str_replace(array($start, $end), '', $conditions);
$conditions = preg_replace_callback(
'/(?:[\'\"][^\'\"\\\]*(?:\\\.[^\'\"\\\]*)*[\'\"])|([a-z0-9_][a-z0-9\\-_]*\\.[a-z0-9_][a-z0-9_\\-]*)/i',
array(&$this, '_quoteMatchedField'),
$conditions
'/(?:[\'\"][^\'\"\\\]*(?:\\\.[^\'\"\\\]*)*[\'\"])|([a-z0-9_][a-z0-9\\-_]*\\.[a-z0-9_][a-z0-9_\\-]*)/i', array(&$this, '_quoteMatchedField'), $conditions
);
if ($conditions !== null) {
return $conditions;
@ -2944,6 +2934,7 @@ class DboSource extends DataSource {
* @return boolean|void success.
*/
public function resetSequence($table, $column) {
}
/**

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';
/**
@ -3027,8 +3027,7 @@ 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'
);
}
@ -4209,15 +4208,7 @@ class ModelReadTest extends BaseModelTest {
*/
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();
@ -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);
@ -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);
@ -5265,13 +5254,7 @@ class ModelReadTest extends BaseModelTest {
*/
public function testMultipleBelongsToWithSameClass() {
$this->loadFixtures(
'DeviceType',
'DeviceTypeCategory',
'FeatureSet',
'ExteriorTypeCategory',
'Document',
'Device',
'DocumentDirectory'
'DeviceType', 'DeviceTypeCategory', 'FeatureSet', 'ExteriorTypeCategory', 'Document', 'Device', 'DocumentDirectory'
);
$DeviceType = new DeviceType();
@ -5545,8 +5528,7 @@ class ModelReadTest extends BaseModelTest {
)),
'conditions' => array(),
'order' => null
),
$Article
), $Article
);
$Article->hasAndBelongsToMany['Tag']['finderQuery'] = $sql;
@ -5865,11 +5847,7 @@ class ModelReadTest extends BaseModelTest {
*/
public function testFindAllRecursiveWithHabtm() {
$this->loadFixtures(
'MyCategoriesMyUsers',
'MyCategoriesMyProducts',
'MyCategory',
'MyUser',
'MyProduct'
'MyCategoriesMyUsers', 'MyCategoriesMyProducts', 'MyCategory', 'MyUser', 'MyProduct'
);
$MyUser = new MyUser();
@ -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(
@ -7104,13 +7078,7 @@ class ModelReadTest extends BaseModelTest {
*/
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();
@ -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)
)
@ -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';
@ -72,6 +72,7 @@ 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',
);
/**
@ -94,4 +95,5 @@ abstract class BaseModelTest extends CakeTestCase {
Configure::write('debug', $this->debug);
ClassRegistry::flush();
}
}

View file

@ -1,4 +1,5 @@
<?php
/**
* Mock models file
*
@ -19,7 +20,6 @@
* @since CakePHP(tm) v 1.2.0.6464
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Model', 'Model');
/**
@ -129,6 +129,7 @@ class TestAlias extends CakeTestModel {
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
);
}
/**
@ -315,7 +316,6 @@ class Article extends CakeTestModel {
class BeforeDeleteComment extends CakeTestModel {
public $name = 'BeforeDeleteComment';
public $useTable = 'comments';
public function beforeDelete($cascade = true) {
@ -450,6 +450,7 @@ class Featured extends CakeTestModel {
* @var array
*/
public $belongsTo = array('ArticleFeatured', 'Category');
}
/**
@ -465,6 +466,7 @@ class Tag extends CakeTestModel {
* @var string
*/
public $name = 'Tag';
}
/**
@ -480,6 +482,7 @@ class ArticlesTag extends CakeTestModel {
* @var string
*/
public $name = 'ArticlesTag';
}
/**
@ -495,6 +498,7 @@ class ArticleFeaturedsTag extends CakeTestModel {
* @var string
*/
public $name = 'ArticleFeaturedsTag';
}
/**
@ -524,6 +528,7 @@ class Comment extends CakeTestModel {
* @var array
*/
public $hasOne = array('Attachment' => array('dependent' => true));
}
/**
@ -635,6 +640,7 @@ class MergeVarPluginAppModel extends AppModel {
public $actsAs = array(
'Containable'
);
}
/**
@ -659,6 +665,7 @@ class MergeVarPluginPost extends MergeVarPluginAppModel {
* @var string
*/
public $useTable = 'posts';
}
/**
@ -683,6 +690,7 @@ class MergeVarPluginComment extends MergeVarPluginAppModel {
* @var string
*/
public $useTable = 'comments';
}
/**
@ -705,6 +713,7 @@ class Attachment extends CakeTestModel {
* @var array
*/
public $belongsTo = array('Comment');
}
/**
@ -755,6 +764,7 @@ class Category extends CakeTestModel {
* @var string
*/
public $name = 'Category';
}
/**
@ -777,6 +787,7 @@ class CategoryThread extends CakeTestModel {
* @var array
*/
public $belongsTo = array('ParentCategory' => array('className' => 'CategoryThread', 'foreignKey' => 'parent_id'));
}
/**
@ -820,6 +831,7 @@ class Apple extends CakeTestModel {
* @var array
*/
public $belongsTo = array('Parent' => array('className' => 'Apple', 'foreignKey' => 'apple_id'));
}
/**
@ -842,6 +854,7 @@ class Sample extends CakeTestModel {
* @var string
*/
public $belongsTo = 'Apple';
}
/**
@ -864,6 +877,7 @@ class AnotherArticle extends CakeTestModel {
* @var string
*/
public $hasMany = 'Home';
}
/**
@ -886,6 +900,7 @@ class Advertisement extends CakeTestModel {
* @var string
*/
public $hasMany = 'Home';
}
/**
@ -908,6 +923,7 @@ class Home extends CakeTestModel {
* @var array
*/
public $belongsTo = array('AnotherArticle', 'Advertisement');
}
/**
@ -1028,6 +1044,7 @@ class Project extends CakeTestModel {
* @var array
*/
public $hasMany = array('Thread');
}
/**
@ -1057,6 +1074,7 @@ class Thread extends CakeTestModel {
* @var array
*/
public $hasMany = array('Message');
}
/**
@ -1079,6 +1097,7 @@ class Message extends CakeTestModel {
* @var array
*/
public $hasOne = array('Bid');
}
/**
@ -1101,6 +1120,7 @@ class Bid extends CakeTestModel {
* @var array
*/
public $belongsTo = array('Message');
}
/**
@ -1135,6 +1155,7 @@ class BiddingMessage extends CakeTestModel {
'conditions' => array('BiddingMessage.bidding = Bidding.bid')
)
);
}
/**
@ -1163,6 +1184,7 @@ class Bidding extends CakeTestModel {
'dependent' => true
)
);
}
/**
@ -1253,6 +1275,7 @@ class NodeAfterFindSample extends CakeTestModel {
* @var string
*/
public $belongsTo = 'NodeAfterFind';
}
/**
@ -1303,6 +1326,7 @@ class NodeNoAfterFind extends CakeTestModel {
* @var array
*/
public $belongsTo = array('Parent' => array('className' => 'NodeAfterFind', 'foreignKey' => 'apple_id'));
}
/**
@ -1333,6 +1357,7 @@ class Node extends CakeTestModel {
'associationForeignKey' => 'parent_id',
)
);
}
/**
@ -1348,6 +1373,7 @@ class Dependency extends CakeTestModel {
* @var string
*/
public $name = 'Dependency';
}
/**
@ -1377,6 +1403,7 @@ class ModelA extends CakeTestModel {
* @var array
*/
public $hasMany = array('ModelB', 'ModelC');
}
/**
@ -1406,6 +1433,7 @@ class ModelB extends CakeTestModel {
* @var array
*/
public $hasMany = array('ModelD');
}
/**
@ -1435,6 +1463,7 @@ class ModelC extends CakeTestModel {
* @var array
*/
public $hasMany = array('ModelD');
}
/**
@ -1457,6 +1486,7 @@ class ModelD extends CakeTestModel {
* @var string
*/
public $useTable = 'threads';
}
/**
@ -1479,6 +1509,7 @@ class Something extends CakeTestModel {
* @var array
*/
public $hasAndBelongsToMany = array('SomethingElse' => array('with' => array('JoinThing' => array('doomed'))));
}
/**
@ -1501,6 +1532,7 @@ class SomethingElse extends CakeTestModel {
* @var array
*/
public $hasAndBelongsToMany = array('Something' => array('with' => 'JoinThing'));
}
/**
@ -1523,6 +1555,7 @@ class JoinThing extends CakeTestModel {
* @var array
*/
public $belongsTo = array('Something', 'SomethingElse');
}
/**
@ -1545,6 +1578,7 @@ class Portfolio extends CakeTestModel {
* @var array
*/
public $hasAndBelongsToMany = array('Item');
}
/**
@ -1574,6 +1608,7 @@ class Item extends CakeTestModel {
* @var array
*/
public $hasAndBelongsToMany = array('Portfolio' => array('unique' => false));
}
/**
@ -1589,6 +1624,7 @@ class ItemsPortfolio extends CakeTestModel {
* @var string
*/
public $name = 'ItemsPortfolio';
}
/**
@ -1611,6 +1647,7 @@ class Syfile extends CakeTestModel {
* @var array
*/
public $belongsTo = array('Image');
}
/**
@ -1626,6 +1663,7 @@ class Image extends CakeTestModel {
* @var string
*/
public $name = 'Image';
}
/**
@ -1666,6 +1704,7 @@ class DeviceType extends CakeTestModel {
* @var array
*/
public $hasMany = array('Device' => array('order' => array('Device.id' => 'ASC')));
}
/**
@ -1681,6 +1720,7 @@ class DeviceTypeCategory extends CakeTestModel {
* @var string
*/
public $name = 'DeviceTypeCategory';
}
/**
@ -1696,6 +1736,7 @@ class FeatureSet extends CakeTestModel {
* @var string
*/
public $name = 'FeatureSet';
}
/**
@ -1718,6 +1759,7 @@ class ExteriorTypeCategory extends CakeTestModel {
* @var array
*/
public $belongsTo = array('Image' => array('className' => 'Device'));
}
/**
@ -1740,6 +1782,7 @@ class Document extends CakeTestModel {
* @var array
*/
public $belongsTo = array('DocumentDirectory');
}
/**
@ -1755,6 +1798,7 @@ class Device extends CakeTestModel {
* @var string
*/
public $name = 'Device';
}
/**
@ -1770,6 +1814,7 @@ class DocumentDirectory extends CakeTestModel {
* @var string
*/
public $name = 'DocumentDirectory';
}
/**
@ -1785,6 +1830,7 @@ class PrimaryModel extends CakeTestModel {
* @var string
*/
public $name = 'PrimaryModel';
}
/**
@ -1800,6 +1846,7 @@ class SecondaryModel extends CakeTestModel {
* @var string
*/
public $name = 'SecondaryModel';
}
/**
@ -1822,6 +1869,7 @@ class JoinA extends CakeTestModel {
* @var array
*/
public $hasAndBelongsToMany = array('JoinB', 'JoinC');
}
/**
@ -1844,6 +1892,7 @@ class JoinB extends CakeTestModel {
* @var array
*/
public $hasAndBelongsToMany = array('JoinA');
}
/**
@ -1866,6 +1915,7 @@ class JoinC extends CakeTestModel {
* @var array
*/
public $hasAndBelongsToMany = array('JoinA');
}
/**
@ -1902,6 +1952,7 @@ class ThePaper extends CakeTestModel {
* @var array
*/
public $hasAndBelongsToMany = array('Monkey' => array('joinTable' => 'the_paper_monkies', 'order' => 'id'));
}
/**
@ -1924,6 +1975,7 @@ class Monkey extends CakeTestModel {
* @var string
*/
public $useTable = 'devices';
}
/**
@ -1955,6 +2007,7 @@ class AssociationTest1 extends CakeTestModel {
public $hasAndBelongsToMany = array('AssociationTest2' => array(
'unique' => false, 'joinTable' => 'join_as_join_bs', 'foreignKey' => false
));
}
/**
@ -1986,6 +2039,7 @@ class AssociationTest2 extends CakeTestModel {
public $hasAndBelongsToMany = array('AssociationTest1' => array(
'unique' => false, 'joinTable' => 'join_as_join_bs'
));
}
/**
@ -2069,6 +2123,7 @@ class Uuid extends CakeTestModel {
* @var string
*/
public $name = 'Uuid';
}
/**
@ -2084,6 +2139,7 @@ class DataTest extends CakeTestModel {
* @var string
*/
public $name = 'DataTest';
}
/**
@ -2106,6 +2162,7 @@ class TheVoid extends CakeTestModel {
* @var bool false
*/
public $useTable = false;
}
/**
@ -2280,6 +2337,7 @@ class Person extends CakeTestModel {
'foreignKey' => 'father_id'
)
);
}
/**
@ -2295,6 +2353,7 @@ class UnderscoreField extends CakeTestModel {
* @var string
*/
public $name = 'UnderscoreField';
}
/**
@ -2310,6 +2369,7 @@ class Product extends CakeTestModel {
* @var string
*/
public $name = 'Product';
}
/**
@ -2346,6 +2406,7 @@ class Story extends CakeTestModel {
* @var array
*/
public $validate = array('title' => 'notEmpty');
}
/**
@ -2419,6 +2480,7 @@ class OverallFavorite extends CakeTestModel {
* @var string
*/
public $name = 'OverallFavorite';
}
/**
@ -2441,6 +2503,7 @@ class MyUser extends CakeTestModel {
* @var string
*/
public $hasAndBelongsToMany = array('MyCategory');
}
/**
@ -2463,6 +2526,7 @@ class MyCategory extends CakeTestModel {
* @var string
*/
public $hasAndBelongsToMany = array('MyProduct', 'MyUser');
}
/**
@ -2485,6 +2549,7 @@ class MyProduct extends CakeTestModel {
* @var string
*/
public $hasAndBelongsToMany = array('MyCategory');
}
/**
@ -2500,6 +2565,7 @@ class MyCategoriesMyUser extends CakeTestModel {
* @var string
*/
public $name = 'MyCategoriesMyUser';
}
/**
@ -2515,8 +2581,8 @@ class MyCategoriesMyProduct extends CakeTestModel {
* @var string
*/
public $name = 'MyCategoriesMyProduct';
}
}
/**
* NumberTree class
@ -2602,6 +2668,7 @@ class NumberTreeTwo extends NumberTree {
* @var array
*/
public $actsAs = array();
}
/**
@ -2617,6 +2684,7 @@ class FlagTree extends NumberTree {
* @var string
*/
public $name = 'FlagTree';
}
/**
@ -2632,7 +2700,6 @@ class UnconventionalTree extends NumberTree {
* @var string
*/
public $name = 'UnconventionalTree';
public $actsAs = array(
'Tree' => array(
'parent' => 'join',
@ -2656,6 +2723,7 @@ class UuidTree extends NumberTree {
* @var string
*/
public $name = 'UuidTree';
}
/**
@ -2678,6 +2746,7 @@ class Campaign extends CakeTestModel {
* @var array
*/
public $hasMany = array('Ad' => array('fields' => array('id', 'campaign_id', 'name')));
}
/**
@ -2707,6 +2776,7 @@ class Ad extends CakeTestModel {
* @var array
*/
public $belongsTo = array('Campaign');
}
/**
@ -2772,6 +2842,7 @@ class Content extends CakeTestModel {
* @var array
*/
public $hasAndBelongsToMany = array('Account' => array('className' => 'Account', 'with' => 'ContentAccount', 'joinTable' => 'ContentAccounts', 'foreignKey' => 'iContentId', 'associationForeignKey', 'iAccountId'));
}
/**
@ -2801,6 +2872,7 @@ class Account extends CakeTestModel {
* @var string
*/
public $primaryKey = 'iAccountId';
}
/**
@ -2830,6 +2902,7 @@ class ContentAccount extends CakeTestModel {
* @var string
*/
public $primaryKey = 'iContentAccountsId';
}
/**
@ -2851,7 +2924,6 @@ class FilmFile extends CakeTestModel {
class Basket extends CakeTestModel {
public $name = 'Basket';
public $belongsTo = array(
'FilmFile' => array(
'className' => 'FilmFile',
@ -2897,6 +2969,7 @@ class TestPluginArticle extends CakeTestModel {
'dependent' => true
)
);
}
/**
@ -2925,6 +2998,7 @@ class TestPluginComment extends CakeTestModel {
),
'TestPlugin.User'
);
}
/**
@ -2947,6 +3021,7 @@ class Uuidportfolio extends CakeTestModel {
* @var array
*/
public $hasAndBelongsToMany = array('Uuiditem');
}
/**
@ -2985,6 +3060,7 @@ class UuiditemsUuidportfolio extends CakeTestModel {
* @var string
*/
public $name = 'UuiditemsUuidportfolio';
}
/**
@ -3000,6 +3076,7 @@ class UuiditemsUuidportfolioNumericid extends CakeTestModel {
* @var string
*/
public $name = 'UuiditemsUuidportfolioNumericid';
}
/**
@ -3029,6 +3106,7 @@ class TranslateTestModel extends CakeTestModel {
* @var string
*/
public $displayField = 'field';
}
/**
@ -3270,23 +3348,20 @@ class TranslatedArticle extends CakeTestModel {
class CounterCacheUser extends CakeTestModel {
public $name = 'CounterCacheUser';
public $alias = 'User';
public $hasMany = array(
'Post' => array(
'className' => 'CounterCachePost',
'foreignKey' => 'user_id'
)
);
}
class CounterCachePost extends CakeTestModel {
public $name = 'CounterCachePost';
public $alias = 'Post';
public $belongsTo = array(
'User' => array(
'className' => 'CounterCacheUser',
@ -3294,16 +3369,14 @@ class CounterCachePost extends CakeTestModel {
'counterCache' => true
)
);
}
class CounterCacheUserNonstandardPrimaryKey extends CakeTestModel {
public $name = 'CounterCacheUserNonstandardPrimaryKey';
public $alias = 'User';
public $primaryKey = 'uid';
public $hasMany = array(
'Post' => array(
'className' => 'CounterCachePostNonstandardPrimaryKey',
@ -3316,11 +3389,8 @@ class CounterCacheUserNonstandardPrimaryKey extends CakeTestModel {
class CounterCachePostNonstandardPrimaryKey extends CakeTestModel {
public $name = 'CounterCachePostNonstandardPrimaryKey';
public $alias = 'Post';
public $primaryKey = 'pid';
public $belongsTo = array(
'User' => array(
'className' => 'CounterCacheUserNonstandardPrimaryKey',
@ -3334,9 +3404,7 @@ class CounterCachePostNonstandardPrimaryKey extends CakeTestModel {
class ArticleB extends CakeTestModel {
public $name = 'ArticleB';
public $useTable = 'articles';
public $hasAndBelongsToMany = array(
'TagB' => array(
'className' => 'TagB',
@ -3351,9 +3419,7 @@ class ArticleB extends CakeTestModel {
class TagB extends CakeTestModel {
public $name = 'TagB';
public $useTable = 'tags';
public $hasAndBelongsToMany = array(
'ArticleB' => array(
'className' => 'ArticleB',
@ -3368,7 +3434,6 @@ class TagB extends CakeTestModel {
class Fruit extends CakeTestModel {
public $name = 'Fruit';
public $hasAndBelongsToMany = array(
'UuidTag' => array(
'className' => 'UuidTag',
@ -3384,9 +3449,7 @@ class Fruit extends CakeTestModel {
class FruitsUuidTag extends CakeTestModel {
public $name = 'FruitsUuidTag';
public $primaryKey = false;
public $belongsTo = array(
'UuidTag' => array(
'className' => 'UuidTag',
@ -3403,7 +3466,6 @@ class FruitsUuidTag extends CakeTestModel {
class UuidTag extends CakeTestModel {
public $name = 'UuidTag';
public $hasAndBelongsToMany = array(
'Fruit' => array(
'className' => 'Fruit',
@ -3419,9 +3481,7 @@ class UuidTag extends CakeTestModel {
class FruitNoWith extends CakeTestModel {
public $name = 'Fruit';
public $useTable = 'fruits';
public $hasAndBelongsToMany = array(
'UuidTag' => array(
'className' => 'UuidTagNoWith',
@ -3436,9 +3496,7 @@ class FruitNoWith extends CakeTestModel {
class UuidTagNoWith extends CakeTestModel {
public $name = 'UuidTag';
public $useTable = 'uuid_tags';
public $hasAndBelongsToMany = array(
'Fruit' => array(
'className' => 'FruitNoWith',
@ -3453,7 +3511,6 @@ class UuidTagNoWith extends CakeTestModel {
class ProductUpdateAll extends CakeTestModel {
public $name = 'ProductUpdateAll';
public $useTable = 'product_update_all';
}
@ -3461,7 +3518,6 @@ class ProductUpdateAll extends CakeTestModel {
class GroupUpdateAll extends CakeTestModel {
public $name = 'GroupUpdateAll';
public $useTable = 'group_update_all';
}
@ -3469,7 +3525,6 @@ class GroupUpdateAll extends CakeTestModel {
class TransactionTestModel extends CakeTestModel {
public $name = 'TransactionTestModel';
public $useTable = 'samples';
public function afterSave($created) {
@ -3484,7 +3539,6 @@ class TransactionTestModel extends CakeTestModel {
class TransactionManyTestModel extends CakeTestModel {
public $name = 'TransactionManyTestModel';
public $useTable = 'samples';
public function afterSave($created) {
@ -3499,23 +3553,21 @@ class TransactionManyTestModel extends CakeTestModel {
class Site extends CakeTestModel {
public $name = 'Site';
public $useTable = 'sites';
public $hasAndBelongsToMany = array(
'Domain' => array('unique' => 'keepExisting'),
);
}
class Domain extends CakeTestModel {
public $name = 'Domain';
public $useTable = 'domains';
public $hasAndBelongsToMany = array(
'Site' => array('unique' => 'keepExisting'),
);
}
/**
@ -3613,6 +3665,7 @@ class TestModel2 extends CakeTestModel {
* @var bool false
*/
public $useTable = false;
}
/**
@ -3635,6 +3688,7 @@ class TestModel3 extends CakeTestModel {
* @var bool false
*/
public $useTable = false;
}
/**
@ -4329,7 +4383,6 @@ class Category2 extends CakeTestModel {
'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'),
'icon' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'),
'description' => array('type' => 'text', 'null' => false, 'default' => '', 'length' => null),
);
}
return $this->_schema;
@ -4731,12 +4784,12 @@ class MysqlTestModel extends Model {
*
*/
class PrefixTestModel extends CakeTestModel {
}
class PrefixTestUseTableModel extends CakeTestModel {
public $name = 'PrefixTest';
public $useTable = 'prefix_tests';
}
@ -4820,6 +4873,7 @@ class ScaffoldUser extends CakeTestModel {
'foreignKey' => 'article_id',
)
);
}
/**
@ -4847,6 +4901,7 @@ class ScaffoldComment extends CakeTestModel {
'foreignKey' => 'article_id',
)
);
}
/**
@ -4905,11 +4960,11 @@ class Guild extends CakeTestModel {
class GuildsPlayer extends CakeTestModel {
public $useDbConfig = 'test2';
public $belongsTo = array(
'Player',
'Guild',
);
}
/**
@ -4920,10 +4975,10 @@ class GuildsPlayer extends CakeTestModel {
class Armor extends CakeTestModel {
public $useDbConfig = 'test2';
public $hasAndBelongsToMany = array(
'Player' => array('with' => 'ArmorsPlayer'),
);
}
/**
@ -4993,3 +5048,35 @@ class CustomArticle extends AppModel {
}
}
/**
* ModelWithRelations class
*
* @package Cake.Test.Case.Model
*/
class ModelWithRelations extends CakeTestModel {
}
/**
* ModelRelated class
*
* @package Cake.Test.Case.Model
*/
class ModelRelated extends CakeTestModel {
/**
* afterFind callback method
*
* @param array $results
* @param boolean $primary
* @return array Modified $results
*/
public function afterFind($results, $primary = false) {
foreach ($results as $key => $result) {
$results[$key][$this->alias]['name'] = 'Successfuly changed in AfterFind';
}
return $results;
}
}

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)
);
}