mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-06 03:22:39 +00:00
Remove added fixtures and use existing. Updated one old test to add data from afterFind callback
This commit is contained in:
parent
bb7ff48b01
commit
d7dab3282f
7 changed files with 299 additions and 385 deletions
|
@ -1708,7 +1708,8 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'body' => 'First Post Body',
|
||||
'published' => 'Y',
|
||||
'created' => '2007-03-18 10:39:23',
|
||||
'updated' => '2007-03-18 10:41:31'
|
||||
'updated' => '2007-03-18 10:41:31',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
),
|
||||
'Something' => array(
|
||||
array(
|
||||
|
@ -1724,7 +1725,8 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'something_else_id' => '1',
|
||||
'doomed' => true,
|
||||
'created' => '2007-03-18 10:43:23',
|
||||
'updated' => '2007-03-18 10:45:31'
|
||||
'updated' => '2007-03-18 10:45:31',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
)))),
|
||||
array(
|
||||
'SomethingElse' => array(
|
||||
|
@ -1733,7 +1735,8 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'body' => 'Second Post Body',
|
||||
'published' => 'Y',
|
||||
'created' => '2007-03-18 10:41:23',
|
||||
'updated' => '2007-03-18 10:43:31'
|
||||
'updated' => '2007-03-18 10:43:31',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
),
|
||||
'Something' => array(
|
||||
array(
|
||||
|
@ -1749,7 +1752,8 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'something_else_id' => '2',
|
||||
'doomed' => true,
|
||||
'created' => '2007-03-18 10:39:23',
|
||||
'updated' => '2007-03-18 10:41:31'
|
||||
'updated' => '2007-03-18 10:41:31',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
)))),
|
||||
array(
|
||||
'SomethingElse' => array(
|
||||
|
@ -1758,7 +1762,8 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'body' => 'Third Post Body',
|
||||
'published' => 'Y',
|
||||
'created' => '2007-03-18 10:43:23',
|
||||
'updated' => '2007-03-18 10:45:31'
|
||||
'updated' => '2007-03-18 10:45:31',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
),
|
||||
'Something' => array(
|
||||
array(
|
||||
|
@ -1774,7 +1779,8 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'something_else_id' => '3',
|
||||
'doomed' => false,
|
||||
'created' => '2007-03-18 10:41:23',
|
||||
'updated' => '2007-03-18 10:43:31'
|
||||
'updated' => '2007-03-18 10:43:31',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
)))));
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
|
@ -1800,8 +1806,11 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'JoinThing' => array(
|
||||
'doomed' => true,
|
||||
'something_id' => '1',
|
||||
'something_else_id' => '2'
|
||||
)))),
|
||||
'something_else_id' => '2',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
),
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
))),
|
||||
array(
|
||||
'Something' => array(
|
||||
'id' => '2',
|
||||
|
@ -1822,8 +1831,11 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'JoinThing' => array(
|
||||
'doomed' => false,
|
||||
'something_id' => '2',
|
||||
'something_else_id' => '3'
|
||||
)))),
|
||||
'something_else_id' => '3',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
),
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
))),
|
||||
array(
|
||||
'Something' => array(
|
||||
'id' => '3',
|
||||
|
@ -1844,8 +1856,11 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'JoinThing' => array(
|
||||
'doomed' => true,
|
||||
'something_id' => '3',
|
||||
'something_else_id' => '1'
|
||||
)))));
|
||||
'something_else_id' => '1',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
),
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
))));
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$result = $TestModel->findById(1);
|
||||
|
@ -1869,8 +1884,11 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'JoinThing' => array(
|
||||
'doomed' => true,
|
||||
'something_id' => '1',
|
||||
'something_else_id' => '2'
|
||||
))));
|
||||
'something_else_id' => '2',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
),
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
)));
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$expected = $TestModel->findById(1);
|
||||
|
@ -1910,8 +1928,10 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'JoinThing' => array(
|
||||
'doomed' => true,
|
||||
'something_id' => '1',
|
||||
'something_else_id' => '1'
|
||||
)
|
||||
'something_else_id' => '1',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
),
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
),
|
||||
array(
|
||||
'id' => '2',
|
||||
|
@ -1923,8 +1943,10 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'JoinThing' => array(
|
||||
'doomed' => true,
|
||||
'something_id' => '1',
|
||||
'something_else_id' => '2'
|
||||
)
|
||||
'something_else_id' => '2',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
),
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
),
|
||||
array(
|
||||
'id' => '3',
|
||||
|
@ -1936,10 +1958,12 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'JoinThing' => array(
|
||||
'doomed' => false,
|
||||
'something_id' => '1',
|
||||
'something_else_id' => '3')
|
||||
)
|
||||
'something_else_id' => '3',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
),
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
)
|
||||
);
|
||||
));
|
||||
$this->assertEquals(self::date(), $result['Something']['updated']);
|
||||
unset($result['Something']['updated']);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
|
|
@ -7974,201 +7974,243 @@ class ModelReadTest extends BaseModelTest {
|
|||
* @return void
|
||||
*/
|
||||
public function testRelatedAfterFindCallback() {
|
||||
$this->loadFixtures('ModelWithRelations', 'ModelRelated', 'ModelHabtmRelation');
|
||||
$ModelWithRelations = new ModelWithRelations();
|
||||
|
||||
$ModelWithRelations->bindModel(array(
|
||||
'belongsTo' => array(
|
||||
'BelongsTo' => array(
|
||||
'className' => 'ModelRelated',
|
||||
'foreignKey' => 'related_id',
|
||||
$this->loadFixtures('Something', 'SomethingElse', 'JoinThing');
|
||||
$Something = new Something();
|
||||
|
||||
$Something->bindModel(array(
|
||||
'hasMany' => array(
|
||||
'HasMany' => array(
|
||||
'className' => 'JoinThing',
|
||||
'foreignKey' => 'something_id'
|
||||
)
|
||||
),
|
||||
'hasOne'=>array(
|
||||
'HasOne'=>array(
|
||||
'className' => 'JoinThing',
|
||||
'foreignKey' => 'something_id'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$results = $ModelWithRelations->find('all');
|
||||
)
|
||||
);
|
||||
|
||||
$results = $Something->find('all');
|
||||
|
||||
$expected = array(
|
||||
array(
|
||||
'ModelWithRelations' => array(
|
||||
'Something' => array(
|
||||
'id' => '1',
|
||||
'name' => 'First record',
|
||||
'related_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'
|
||||
),
|
||||
'BelongsTo' => array(
|
||||
'HasOne' => array(
|
||||
'id' => '1',
|
||||
'name' => 'Successfuly changed in AfterFind',
|
||||
'primary_id' => '1'
|
||||
'something_id' => '1',
|
||||
'something_else_id' => '2',
|
||||
'doomed' => true,
|
||||
'created' => '2007-03-18 10:39:23',
|
||||
'updated' => '2007-03-18 10:41:31',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
),
|
||||
'HasMany' => array(
|
||||
array(
|
||||
'id' => '1',
|
||||
'something_id' => '1',
|
||||
'something_else_id' => '2',
|
||||
'doomed' => true,
|
||||
'created' => '2007-03-18 10:39:23',
|
||||
'updated' => '2007-03-18 10:41:31',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
)
|
||||
),
|
||||
'SomethingElse' => array(
|
||||
array(
|
||||
'id' => '2',
|
||||
'title' => 'Second Post',
|
||||
'body' => 'Second Post Body',
|
||||
'published' => 'Y',
|
||||
'created' => '2007-03-18 10:41:23',
|
||||
'updated' => '2007-03-18 10:43:31',
|
||||
'afterFind' => 'Successfuly added by AfterFind',
|
||||
'JoinThing' => array(
|
||||
'doomed' => true,
|
||||
'something_id' => '1',
|
||||
'something_else_id' => '2',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'ModelWithRelations' => array(
|
||||
'Something' => array(
|
||||
'id' => '2',
|
||||
'name' => 'Second record',
|
||||
'related_id' => '2'
|
||||
'title' => 'Second Post',
|
||||
'body' => 'Second Post Body',
|
||||
'published' => 'Y',
|
||||
'created' => '2007-03-18 10:41:23',
|
||||
'updated' => '2007-03-18 10:43:31'
|
||||
),
|
||||
'BelongsTo' => array(
|
||||
'HasOne' => array(
|
||||
'id' => '2',
|
||||
'name' => 'Successfuly changed in AfterFind',
|
||||
'primary_id' => '2'
|
||||
'something_id' => '2',
|
||||
'something_else_id' => '3',
|
||||
'doomed' => false,
|
||||
'created' => '2007-03-18 10:41:23',
|
||||
'updated' => '2007-03-18 10:43:31',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
),
|
||||
'HasMany' => array(
|
||||
array(
|
||||
'id' => '2',
|
||||
'something_id' => '2',
|
||||
'something_else_id' => '3',
|
||||
'doomed' => false,
|
||||
'created' => '2007-03-18 10:41:23',
|
||||
'updated' => '2007-03-18 10:43:31',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
)
|
||||
),
|
||||
'SomethingElse' => array(
|
||||
array(
|
||||
'id' => '3',
|
||||
'title' => 'Third Post',
|
||||
'body' => 'Third Post Body',
|
||||
'published' => 'Y',
|
||||
'created' => '2007-03-18 10:43:23',
|
||||
'updated' => '2007-03-18 10:45:31',
|
||||
'afterFind' => 'Successfuly added by AfterFind',
|
||||
'JoinThing' => array(
|
||||
'doomed' => false,
|
||||
'something_id' => '2',
|
||||
'something_else_id' => '3',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'Something' => array(
|
||||
'id' => '3',
|
||||
'title' => 'Third Post',
|
||||
'body' => 'Third Post Body',
|
||||
'published' => 'Y',
|
||||
'created' => '2007-03-18 10:43:23',
|
||||
'updated' => '2007-03-18 10:45:31'
|
||||
),
|
||||
'HasOne' => array(
|
||||
'id' => '3',
|
||||
'something_id' => '3',
|
||||
'something_else_id' => '1',
|
||||
'doomed' => true,
|
||||
'created' => '2007-03-18 10:43:23',
|
||||
'updated' => '2007-03-18 10:45:31',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
),
|
||||
'HasMany' => array(
|
||||
array(
|
||||
'id' => '3',
|
||||
'something_id' => '3',
|
||||
'something_else_id' => '1',
|
||||
'doomed' => true,
|
||||
'created' => '2007-03-18 10:43:23',
|
||||
'updated' => '2007-03-18 10:45:31',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
)
|
||||
),
|
||||
'SomethingElse' => array(
|
||||
array(
|
||||
'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',
|
||||
'afterFind' => 'Successfuly added by AfterFind',
|
||||
'JoinThing' => array(
|
||||
'doomed' => true,
|
||||
'something_id' => '3',
|
||||
'something_else_id' => '1',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, $results, 'Model related with has* afterFind callback fail');
|
||||
|
||||
$JoinThing = new JoinThing();
|
||||
$JoinThing->unbindModel(array(
|
||||
'belongsTo'=>array(
|
||||
'Something'
|
||||
)
|
||||
)
|
||||
);
|
||||
$results = $JoinThing->find('all');
|
||||
|
||||
$expected = array(
|
||||
array(
|
||||
'JoinThing' => array(
|
||||
'id' => '1',
|
||||
'something_id' => '1',
|
||||
'something_else_id' => '2',
|
||||
'doomed' => true,
|
||||
'created' => '2007-03-18 10:39:23',
|
||||
'updated' => '2007-03-18 10:41:31',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
),
|
||||
'SomethingElse' => array(
|
||||
'id' => '2',
|
||||
'title' => 'Second Post',
|
||||
'body' => 'Second Post Body',
|
||||
'published' => 'Y',
|
||||
'created' => '2007-03-18 10:41:23',
|
||||
'updated' => '2007-03-18 10:43:31',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'JoinThing' => array(
|
||||
'id' => '2',
|
||||
'something_id' => '2',
|
||||
'something_else_id' => '3',
|
||||
'doomed' => false,
|
||||
'created' => '2007-03-18 10:41:23',
|
||||
'updated' => '2007-03-18 10:43:31',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
),
|
||||
'SomethingElse' => array(
|
||||
'id' => '3',
|
||||
'title' => 'Third Post',
|
||||
'body' => 'Third Post Body',
|
||||
'published' => 'Y',
|
||||
'created' => '2007-03-18 10:43:23',
|
||||
'updated' => '2007-03-18 10:45:31',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'JoinThing' => array(
|
||||
'id' => '3',
|
||||
'something_id' => '3',
|
||||
'something_else_id' => '1',
|
||||
'doomed' => true,
|
||||
'created' => '2007-03-18 10:43:23',
|
||||
'updated' => '2007-03-18 10:45:31',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
),
|
||||
'SomethingElse' => array(
|
||||
'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',
|
||||
'afterFind' => 'Successfuly added by AfterFind'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, $results, 'Model related with belongsTo afterFind callback fail');
|
||||
|
||||
$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');
|
||||
|
||||
$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(
|
||||
array(
|
||||
'id' => '1',
|
||||
'name' => 'Successfuly changed in AfterFind',
|
||||
'primary_id' => '1'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'ModelWithRelations' => array(
|
||||
'id' => '2',
|
||||
'name' => 'Second record',
|
||||
'related_id' => '2'
|
||||
),
|
||||
'HasMany' => array(
|
||||
array(
|
||||
'id' => '2',
|
||||
'name' => 'Successfuly changed in AfterFind',
|
||||
'primary_id' => '2'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, $results, 'Model related with hasMany afterFind callback fail');
|
||||
|
||||
$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(
|
||||
array(
|
||||
'id' => '1',
|
||||
'name' => 'Successfuly changed in AfterFind',
|
||||
'primary_id' => '1',
|
||||
'ModelHabtmRelation' => array(
|
||||
'id' => '1',
|
||||
'primary_id' => '1',
|
||||
'related_id' => '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(
|
||||
array(
|
||||
'id' => '1',
|
||||
'name' => 'Successfuly changed in AfterFind',
|
||||
'primary_id' => '1',
|
||||
'ModelHabtmRelation' => array(
|
||||
'id' => '3',
|
||||
'primary_id' => '2',
|
||||
'related_id' => '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');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,6 @@ 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',
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
|
@ -1501,6 +1501,22 @@ class SomethingElse extends CakeTestModel {
|
|||
* @var array
|
||||
*/
|
||||
public $hasAndBelongsToMany = array('Something' => array('with' => 'JoinThing'));
|
||||
|
||||
/**
|
||||
* afterFind callBack
|
||||
*
|
||||
* @param array $results
|
||||
* @param bool $primary
|
||||
* @return array
|
||||
*/
|
||||
public function afterFind($results, $primary = false) {
|
||||
foreach ($results as $key => $result) {
|
||||
if(!empty($result[$this->alias]) && is_array($result[$this->alias])){
|
||||
$results[$key][$this->alias]['afterFind'] = 'Successfuly added by AfterFind';
|
||||
}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1523,6 +1539,22 @@ class JoinThing extends CakeTestModel {
|
|||
* @var array
|
||||
*/
|
||||
public $belongsTo = array('Something', 'SomethingElse');
|
||||
|
||||
/**
|
||||
* afterFind callBack
|
||||
*
|
||||
* @param array $results
|
||||
* @param bool $primary
|
||||
* @return array
|
||||
*/
|
||||
public function afterFind($results, $primary = false) {
|
||||
foreach ($results as $key => $result) {
|
||||
if(!empty($result[$this->alias]) && is_array($result[$this->alias])){
|
||||
$results[$key][$this->alias]['afterFind'] = 'Successfuly added by AfterFind';
|
||||
}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4992,35 +5024,4 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
<?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),
|
||||
);
|
||||
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
<?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)
|
||||
);
|
||||
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
<?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)
|
||||
);
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue