code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
function testUpdateExisting() { $this->loadFixtures('User', 'Article', 'Comment'); $TestModel =& new User(); $TestModel->create(); $TestModel->save(array( 'User' => array( 'user' => 'some user', 'password' => 'some password' ))); $this->assertTrue(is_int($TestModel->id) || (intval($TestModel->id) === 5)); $id = $TestModel->id; $TestModel->save(array( 'User' => array( 'user' => 'updated user' ))); $this->assertEqual($TestModel->id, $id); $result = $TestModel->findById($id); $this->assertEqual($result['User']['user'], 'updated user'); $this->assertEqual($result['User']['password'], 'some password'); $Article =& new Article(); $Comment =& new Comment(); $data = array( 'Comment' => array( 'id' => 1, 'comment' => 'First Comment for First Article' ), 'Article' => array( 'id' => 2, 'title' => 'Second Article' )); $result = $Article->save($data); $this->assertTrue($result); $result = $Comment->save($data); $this->assertTrue($result); }
testUpdateExisting method @access public @return void
testUpdateExisting
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testUpdateSavingBlankValues() { $this->loadFixtures('Article'); $Article =& new Article(); $Article->validate = array(); $Article->create(); $result = $Article->save(array( 'id' => 1, 'title' => '', 'body' => '' )); $this->assertTrue($result); $result = $Article->find('first', array('conditions' => array('Article.id' => 1))); $this->assertEqual('', $result['Article']['title'], 'Title is not blank'); $this->assertEqual('', $result['Article']['body'], 'Body is not blank'); }
test updating records and saving blank values. @return void
testUpdateSavingBlankValues
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testUpdateMultiple() { $this->loadFixtures('Comment', 'Article', 'User', 'CategoryThread'); $TestModel =& new Comment(); $result = Set::extract($TestModel->find('all'), '{n}.Comment.user_id'); $expected = array('2', '4', '1', '1', '1', '2'); $this->assertEqual($result, $expected); $TestModel->updateAll(array('Comment.user_id' => 5), array('Comment.user_id' => 2)); $result = Set::combine($TestModel->find('all'), '{n}.Comment.id', '{n}.Comment.user_id'); $expected = array(1 => 5, 2 => 4, 3 => 1, 4 => 1, 5 => 1, 6 => 5); $this->assertEqual($result, $expected); $result = $TestModel->updateAll( array('Comment.comment' => "'Updated today'"), array('Comment.user_id' => 5) ); $this->assertTrue($result); $result = Set::extract( $TestModel->find('all', array( 'conditions' => array( 'Comment.user_id' => 5 ))), '{n}.Comment.comment' ); $expected = array_fill(0, 2, 'Updated today'); $this->assertEqual($result, $expected); }
testUpdateMultiple method @access public @return void
testUpdateMultiple
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testHabtmUuidWithUuidId() { $this->loadFixtures('Uuidportfolio', 'Uuiditem', 'UuiditemsUuidportfolio'); $TestModel =& new Uuidportfolio(); $data = array('Uuidportfolio' => array('name' => 'Portfolio 3')); $data['Uuiditem']['Uuiditem'] = array('483798c8-c7cc-430e-8cf9-4fcc40cf8569'); $TestModel->create($data); $TestModel->save(); $id = $TestModel->id; $result = $TestModel->read(null, $id); $this->assertEqual(1, count($result['Uuiditem'])); $this->assertEqual(strlen($result['Uuiditem'][0]['UuiditemsUuidportfolio']['id']), 36); }
testHabtmUuidWithUuidId method @access public @return void
testHabtmUuidWithUuidId
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testHabtmSavingWithNoPrimaryKeyUuidJoinTable() { $this->loadFixtures('UuidTag', 'Fruit', 'FruitsUuidTag'); $Fruit =& new Fruit(); $data = array( 'Fruit' => array( 'color' => 'Red', 'shape' => 'Heart-shaped', 'taste' => 'sweet', 'name' => 'Strawberry', ), 'UuidTag' => array( 'UuidTag' => array( '481fc6d0-b920-43e0-e50f-6d1740cf8569' ) ) ); $this->assertTrue($Fruit->save($data)); }
test HABTM saving when join table has no primary key and only 2 columns. @return void
testHabtmSavingWithNoPrimaryKeyUuidJoinTable
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testHabtmSavingWithNoPrimaryKeyUuidJoinTableNoWith() { $this->loadFixtures('UuidTag', 'Fruit', 'FruitsUuidTag'); $Fruit =& new FruitNoWith(); $data = array( 'Fruit' => array( 'color' => 'Red', 'shape' => 'Heart-shaped', 'taste' => 'sweet', 'name' => 'Strawberry', ), 'UuidTag' => array( 'UuidTag' => array( '481fc6d0-b920-43e0-e50f-6d1740cf8569' ) ) ); $this->assertTrue($Fruit->save($data)); }
test HABTM saving when join table has no primary key and only 2 columns, no with model is used. @return void
testHabtmSavingWithNoPrimaryKeyUuidJoinTableNoWith
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testHabtmUuidWithNumericId() { $this->loadFixtures('Uuidportfolio', 'Uuiditem', 'UuiditemsUuidportfolioNumericid'); $TestModel =& new Uuiditem(); $data = array('Uuiditem' => array('name' => 'Item 7', 'published' => 0)); $data['Uuidportfolio']['Uuidportfolio'] = array('480af662-eb8c-47d3-886b-230540cf8569'); $TestModel->create($data); $TestModel->save(); $id = $TestModel->id; $result = $TestModel->read(null, $id); $this->assertEqual(1, count($result['Uuidportfolio'])); }
testHabtmUuidWithNumericId method @access public @return void
testHabtmUuidWithNumericId
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testSaveMultipleHabtm() { $this->loadFixtures('JoinA', 'JoinB', 'JoinC', 'JoinAB', 'JoinAC'); $TestModel = new JoinA(); $result = $TestModel->findById(1); $expected = array( 'JoinA' => array( 'id' => 1, 'name' => 'Join A 1', 'body' => 'Join A 1 Body', 'created' => '2008-01-03 10:54:23', 'updated' => '2008-01-03 10:54:23' ), 'JoinB' => array( 0 => array( 'id' => 2, 'name' => 'Join B 2', 'created' => '2008-01-03 10:55:02', 'updated' => '2008-01-03 10:55:02', 'JoinAsJoinB' => array( 'id' => 1, 'join_a_id' => 1, 'join_b_id' => 2, 'other' => 'Data for Join A 1 Join B 2', 'created' => '2008-01-03 10:56:33', 'updated' => '2008-01-03 10:56:33' ))), 'JoinC' => array( 0 => array( 'id' => 2, 'name' => 'Join C 2', 'created' => '2008-01-03 10:56:12', 'updated' => '2008-01-03 10:56:12', 'JoinAsJoinC' => array( 'id' => 1, 'join_a_id' => 1, 'join_c_id' => 2, 'other' => 'Data for Join A 1 Join C 2', 'created' => '2008-01-03 10:57:22', 'updated' => '2008-01-03 10:57:22' )))); $this->assertEqual($result, $expected); $ts = date('Y-m-d H:i:s'); $TestModel->id = 1; $data = array( 'JoinA' => array( 'id' => '1', 'name' => 'New name for Join A 1', 'updated' => $ts ), 'JoinB' => array( array( 'id' => 1, 'join_b_id' => 2, 'other' => 'New data for Join A 1 Join B 2', 'created' => $ts, 'updated' => $ts )), 'JoinC' => array( array( 'id' => 1, 'join_c_id' => 2, 'other' => 'New data for Join A 1 Join C 2', 'created' => $ts, 'updated' => $ts ))); $TestModel->set($data); $TestModel->save(); $result = $TestModel->findById(1); $expected = array( 'JoinA' => array( 'id' => 1, 'name' => 'New name for Join A 1', 'body' => 'Join A 1 Body', 'created' => '2008-01-03 10:54:23', 'updated' => $ts ), 'JoinB' => array( 0 => array( 'id' => 2, 'name' => 'Join B 2', 'created' => '2008-01-03 10:55:02', 'updated' => '2008-01-03 10:55:02', 'JoinAsJoinB' => array( 'id' => 1, 'join_a_id' => 1, 'join_b_id' => 2, 'other' => 'New data for Join A 1 Join B 2', 'created' => $ts, 'updated' => $ts ))), 'JoinC' => array( 0 => array( 'id' => 2, 'name' => 'Join C 2', 'created' => '2008-01-03 10:56:12', 'updated' => '2008-01-03 10:56:12', 'JoinAsJoinC' => array( 'id' => 1, 'join_a_id' => 1, 'join_c_id' => 2, 'other' => 'New data for Join A 1 Join C 2', 'created' => $ts, 'updated' => $ts )))); $this->assertEqual($result, $expected); }
testSaveMultipleHabtm method @access public @return void
testSaveMultipleHabtm
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testSaveAll() { $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment'); $TestModel =& new Post(); $result = $TestModel->find('all'); $this->assertEqual(count($result), 3); $this->assertFalse(isset($result[3])); $ts = date('Y-m-d H:i:s'); $TestModel->saveAll(array( 'Post' => array( 'title' => 'Post with Author', 'body' => 'This post will be saved with an author' ), 'Author' => array( 'user' => 'bob', 'password' => '5f4dcc3b5aa765d61d8327deb882cf90' ))); $result = $TestModel->find('all'); $expected = array( 'Post' => array( 'id' => '4', 'author_id' => '5', 'title' => 'Post with Author', 'body' => 'This post will be saved with an author', 'published' => 'N', 'created' => $ts, 'updated' => $ts ), 'Author' => array( 'id' => '5', 'user' => 'bob', 'password' => '5f4dcc3b5aa765d61d8327deb882cf90', 'created' => $ts, 'updated' => $ts, 'test' => 'working' )); $this->assertEqual($result[3], $expected); $this->assertEqual(count($result), 4); $TestModel->deleteAll(true); $this->assertEqual($TestModel->find('all'), array()); // SQLite seems to reset the PK counter when that happens, so we need this to make the tests pass $this->db->truncate($TestModel); $ts = date('Y-m-d H:i:s'); $TestModel->saveAll(array( array( 'title' => 'Multi-record post 1', 'body' => 'First multi-record post', 'author_id' => 2 ), array( 'title' => 'Multi-record post 2', 'body' => 'Second multi-record post', 'author_id' => 2 ))); $result = $TestModel->find('all', array( 'recursive' => -1, 'order' => 'Post.id ASC' )); $expected = array( array( 'Post' => array( 'id' => '1', 'author_id' => '2', 'title' => 'Multi-record post 1', 'body' => 'First multi-record post', 'published' => 'N', 'created' => $ts, 'updated' => $ts )), array( 'Post' => array( 'id' => '2', 'author_id' => '2', 'title' => 'Multi-record post 2', 'body' => 'Second multi-record post', 'published' => 'N', 'created' => $ts, 'updated' => $ts ))); $this->assertEqual($result, $expected); $TestModel =& new Comment(); $ts = date('Y-m-d H:i:s'); $result = $TestModel->saveAll(array( 'Comment' => array( 'article_id' => 2, 'user_id' => 2, 'comment' => 'New comment with attachment', 'published' => 'Y' ), 'Attachment' => array( 'attachment' => 'some_file.tgz' ))); $this->assertTrue($result); $result = $TestModel->find('all'); $expected = array( 'id' => '7', 'article_id' => '2', 'user_id' => '2', 'comment' => 'New comment with attachment', 'published' => 'Y', 'created' => $ts, 'updated' => $ts ); $this->assertEqual($result[6]['Comment'], $expected); $expected = array( 'id' => '7', 'article_id' => '2', 'user_id' => '2', 'comment' => 'New comment with attachment', 'published' => 'Y', 'created' => $ts, 'updated' => $ts ); $this->assertEqual($result[6]['Comment'], $expected); $expected = array( 'id' => '2', 'comment_id' => '7', 'attachment' => 'some_file.tgz', 'created' => $ts, 'updated' => $ts ); $this->assertEqual($result[6]['Attachment'], $expected); }
testSaveAll method @access public @return void
testSaveAll
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testSaveAllHabtm() { $this->loadFixtures('Article', 'Tag', 'Comment', 'User'); $data = array( 'Article' => array( 'user_id' => 1, 'title' => 'Article Has and belongs to Many Tags' ), 'Tag' => array( 'Tag' => array(1, 2) ), 'Comment' => array( array( 'comment' => 'Article comment', 'user_id' => 1 ))); $Article =& new Article(); $result = $Article->saveAll($data); $this->assertTrue($result); $result = $Article->read(); $this->assertEqual(count($result['Tag']), 2); $this->assertEqual($result['Tag'][0]['tag'], 'tag1'); $this->assertEqual(count($result['Comment']), 1); $this->assertEqual(count($result['Comment'][0]['comment']), 1); }
Test SaveAll with Habtm relations @access public @return void
testSaveAllHabtm
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testSaveAllHabtmWithExtraJoinTableFields() { $this->loadFixtures('Something', 'SomethingElse', 'JoinThing'); $data = array( 'Something' => array( 'id' => 4, 'title' => 'Extra Fields', 'body' => 'Extra Fields Body', 'published' => '1' ), 'SomethingElse' => array( array('something_else_id' => 1, 'doomed' => '1'), array('something_else_id' => 2, 'doomed' => '0'), array('something_else_id' => 3, 'doomed' => '1') ) ); $Something =& new Something(); $result = $Something->saveAll($data); $this->assertTrue($result); $result = $Something->read(); $this->assertEqual(count($result['SomethingElse']), 3); $this->assertTrue(Set::matches('/Something[id=4]', $result)); $this->assertTrue(Set::matches('/SomethingElse[id=1]', $result)); $this->assertTrue(Set::matches('/SomethingElse[id=1]/JoinThing[something_else_id=1]', $result)); $this->assertTrue(Set::matches('/SomethingElse[id=1]/JoinThing[doomed=1]', $result)); $this->assertTrue(Set::matches('/SomethingElse[id=2]', $result)); $this->assertTrue(Set::matches('/SomethingElse[id=2]/JoinThing[something_else_id=2]', $result)); $this->assertTrue(Set::matches('/SomethingElse[id=2]/JoinThing[doomed=0]', $result)); $this->assertTrue(Set::matches('/SomethingElse[id=3]', $result)); $this->assertTrue(Set::matches('/SomethingElse[id=3]/JoinThing[something_else_id=3]', $result)); $this->assertTrue(Set::matches('/SomethingElse[id=3]/JoinThing[doomed=1]', $result)); }
Test SaveAll with Habtm relations and extra join table fields @access public @return void
testSaveAllHabtmWithExtraJoinTableFields
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testSaveAllHasOne() { $model = new Comment(); $model->deleteAll(true); $this->assertEqual($model->find('all'), array()); $model->Attachment->deleteAll(true); $this->assertEqual($model->Attachment->find('all'), array()); $this->assertTrue($model->saveAll(array( 'Comment' => array( 'comment' => 'Comment with attachment', 'article_id' => 1, 'user_id' => 1 ), 'Attachment' => array( 'attachment' => 'some_file.zip' )))); $result = $model->find('all', array('fields' => array( 'Comment.id', 'Comment.comment', 'Attachment.id', 'Attachment.comment_id', 'Attachment.attachment' ))); $expected = array(array( 'Comment' => array( 'id' => '1', 'comment' => 'Comment with attachment' ), 'Attachment' => array( 'id' => '1', 'comment_id' => '1', 'attachment' => 'some_file.zip' ))); $this->assertEqual($result, $expected); $model->Attachment->bindModel(array('belongsTo' => array('Comment')), false); $data = array( 'Comment' => array( 'comment' => 'Comment with attachment', 'article_id' => 1, 'user_id' => 1 ), 'Attachment' => array( 'attachment' => 'some_file.zip' )); $this->assertTrue($model->saveAll($data, array('validate' => 'first'))); }
testSaveAllHasOne method @access public @return void
testSaveAllHasOne
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testSaveAllBelongsTo() { $model = new Comment(); $model->deleteAll(true); $this->assertEqual($model->find('all'), array()); $model->Article->deleteAll(true); $this->assertEqual($model->Article->find('all'), array()); $this->assertTrue($model->saveAll(array( 'Comment' => array( 'comment' => 'Article comment', 'article_id' => 1, 'user_id' => 1 ), 'Article' => array( 'title' => 'Model Associations 101', 'user_id' => 1 )))); $result = $model->find('all', array('fields' => array( 'Comment.id', 'Comment.comment', 'Comment.article_id', 'Article.id', 'Article.title' ))); $expected = array(array( 'Comment' => array( 'id' => '1', 'article_id' => '1', 'comment' => 'Article comment' ), 'Article' => array( 'id' => '1', 'title' => 'Model Associations 101' ))); $this->assertEqual($result, $expected); }
testSaveAllBelongsTo method @access public @return void
testSaveAllBelongsTo
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testSaveAllHasOneValidation() { $model = new Comment(); $model->deleteAll(true); $this->assertEqual($model->find('all'), array()); $model->Attachment->deleteAll(true); $this->assertEqual($model->Attachment->find('all'), array()); $model->validate = array('comment' => 'notEmpty'); $model->Attachment->validate = array('attachment' => 'notEmpty'); $model->Attachment->bindModel(array('belongsTo' => array('Comment'))); $this->assertFalse($model->saveAll( array( 'Comment' => array( 'comment' => '', 'article_id' => 1, 'user_id' => 1 ), 'Attachment' => array('attachment' => '') ), array('validate' => 'first') )); $expected = array( 'Comment' => array('comment' => 'This field cannot be left blank'), 'Attachment' => array('attachment' => 'This field cannot be left blank') ); $this->assertEqual($model->validationErrors, $expected['Comment']); $this->assertEqual($model->Attachment->validationErrors, $expected['Attachment']); $this->assertFalse($model->saveAll( array( 'Comment' => array('comment' => '', 'article_id' => 1, 'user_id' => 1), 'Attachment' => array('attachment' => '') ), array('validate' => 'only') )); $this->assertEqual($model->validationErrors, $expected['Comment']); $this->assertEqual($model->Attachment->validationErrors, $expected['Attachment']); }
testSaveAllHasOneValidation method @access public @return void
testSaveAllHasOneValidation
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testSaveAllAtomic() { $this->loadFixtures('Article', 'User'); $TestModel =& new Article(); $result = $TestModel->saveAll(array( 'Article' => array( 'title' => 'Post with Author', 'body' => 'This post will be saved with an author', 'user_id' => 2 ), 'Comment' => array( array('comment' => 'First new comment', 'user_id' => 2)) ), array('atomic' => false)); $this->assertIdentical($result, array('Article' => true, 'Comment' => array(true))); $result = $TestModel->saveAll(array( array( 'id' => '1', 'title' => 'Baleeted First Post', 'body' => 'Baleeted!', 'published' => 'N' ), array( 'id' => '2', 'title' => 'Just update the title' ), array( 'title' => 'Creating a fourth post', 'body' => 'Fourth post body', 'user_id' => 2 ) ), array('atomic' => false)); $this->assertIdentical($result, array(true, true, true)); $TestModel->validate = array('title' => 'notEmpty', 'author_id' => 'numeric'); $result = $TestModel->saveAll(array( array( 'id' => '1', 'title' => 'Un-Baleeted First Post', 'body' => 'Not Baleeted!', 'published' => 'Y' ), array( 'id' => '2', 'title' => '', 'body' => 'Trying to get away with an empty title' ) ), array('validate' => true, 'atomic' => false)); $this->assertIdentical($result, array(true, false)); $result = $TestModel->saveAll(array( 'Article' => array('id' => 2), 'Comment' => array( array( 'comment' => 'First new comment', 'published' => 'Y', 'user_id' => 1 ), array( 'comment' => 'Second new comment', 'published' => 'Y', 'user_id' => 2 )) ), array('validate' => true, 'atomic' => false)); $this->assertIdentical($result, array('Article' => true, 'Comment' => array(true, true))); }
testSaveAllAtomic method @access public @return void
testSaveAllAtomic
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testSaveAllHasMany() { $this->loadFixtures('Article', 'Comment'); $TestModel =& new Article(); $TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array(); $result = $TestModel->saveAll(array( 'Article' => array('id' => 2), 'Comment' => array( array('comment' => 'First new comment', 'published' => 'Y', 'user_id' => 1), array('comment' => 'Second new comment', 'published' => 'Y', 'user_id' => 2) ) )); $this->assertTrue($result); $result = $TestModel->findById(2); $expected = array( 'First Comment for Second Article', 'Second Comment for Second Article', 'First new comment', 'Second new comment' ); $this->assertEqual(Set::extract($result['Comment'], '{n}.comment'), $expected); $result = $TestModel->saveAll( array( 'Article' => array('id' => 2), 'Comment' => array( array( 'comment' => 'Third new comment', 'published' => 'Y', 'user_id' => 1 ))), array('atomic' => false) ); $this->assertTrue($result); $result = $TestModel->findById(2); $expected = array( 'First Comment for Second Article', 'Second Comment for Second Article', 'First new comment', 'Second new comment', 'Third new comment' ); $this->assertEqual(Set::extract($result['Comment'], '{n}.comment'), $expected); $TestModel->beforeSaveReturn = false; $result = $TestModel->saveAll( array( 'Article' => array('id' => 2), 'Comment' => array( array( 'comment' => 'Fourth new comment', 'published' => 'Y', 'user_id' => 1 ))), array('atomic' => false) ); $this->assertEqual($result, array('Article' => false)); $result = $TestModel->findById(2); $expected = array( 'First Comment for Second Article', 'Second Comment for Second Article', 'First new comment', 'Second new comment', 'Third new comment' ); $this->assertEqual(Set::extract($result['Comment'], '{n}.comment'), $expected); }
testSaveAllHasMany method @access public @return void
testSaveAllHasMany
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testSaveAllHasManyValidation() { $this->loadFixtures('Article', 'Comment'); $TestModel =& new Article(); $TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array(); $TestModel->Comment->validate = array('comment' => 'notEmpty'); $result = $TestModel->saveAll(array( 'Article' => array('id' => 2), 'Comment' => array( array('comment' => '', 'published' => 'Y', 'user_id' => 1), ) ), array('validate' => true)); $expected = array('Comment' => array(false)); $this->assertEqual($result, $expected); $expected = array('Comment' => array( array('comment' => 'This field cannot be left blank') )); $this->assertEqual($TestModel->validationErrors, $expected); $expected = array( array('comment' => 'This field cannot be left blank') ); $this->assertEqual($TestModel->Comment->validationErrors, $expected); $result = $TestModel->saveAll(array( 'Article' => array('id' => 2), 'Comment' => array( array( 'comment' => '', 'published' => 'Y', 'user_id' => 1 )) ), array('validate' => 'first')); $this->assertFalse($result); }
testSaveAllHasManyValidation method @access public @return void
testSaveAllHasManyValidation
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testSaveAllManyRowsTransactionNoRollback() { $this->loadFixtures('Post'); Mock::generate('DboSource', 'MockTransactionDboSource'); $db = ConnectionManager::create('mock_transaction', array( 'datasource' => 'MockTransactionDbo', )); $db->expectOnce('rollback'); $Post =& new Post(); $Post->useDbConfig = 'mock_transaction'; $Post->validate = array( 'title' => array('rule' => array('notEmpty')) ); $data = array( array('author_id' => 1, 'title' => 'New Fourth Post'), array('author_id' => 1, 'title' => '') ); $Post->saveAll($data, array('atomic' => true)); }
test saveAll with transactions and ensure there is no missing rollback. @return void
testSaveAllManyRowsTransactionNoRollback
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testSaveAllAssociatedTransactionNoRollback() { $testDb = ConnectionManager::getDataSource('test_suite'); Mock::generate('DboSource', 'MockTransactionAssociatedDboSource'); $db = ConnectionManager::create('mock_transaction_assoc', array( 'datasource' => 'MockTransactionAssociatedDbo', )); $db->columns = $testDb->columns; $db->expectOnce('rollback'); $Post =& new Post(); $Post->useDbConfig = 'mock_transaction_assoc'; $Post->Author->useDbConfig = 'mock_transaction_assoc'; $Post->Author->validate = array( 'user' => array('rule' => array('notEmpty')) ); $data = array( 'Post' => array( 'title' => 'New post', 'body' => 'Content', 'published' => 'Y' ), 'Author' => array( 'user' => '', 'password' => "sekret" ) ); $Post->saveAll($data); }
test saveAll with transactions and ensure there is no missing rollback. @return void
testSaveAllAssociatedTransactionNoRollback
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testSaveAllNestedSaveAll() { $this->loadFixtures('Sample'); $TransactionTestModel =& new TransactionTestModel(); $data = array( array('apple_id' => 1, 'name' => 'sample5'), ); $this->assertTrue($TransactionTestModel->saveAll($data, array('atomic' => true))); }
test saveAll with nested saveAll call. @return void
testSaveAllNestedSaveAll
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testSaveAllTransaction() { $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment'); $TestModel =& new Post(); $TestModel->validate = array('title' => 'notEmpty'); $data = array( array('author_id' => 1, 'title' => 'New Fourth Post'), array('author_id' => 1, 'title' => 'New Fifth Post'), array('author_id' => 1, 'title' => '') ); $ts = date('Y-m-d H:i:s'); $this->assertFalse($TestModel->saveAll($data)); $result = $TestModel->find('all', array('recursive' => -1)); $expected = array( array('Post' => array( 'id' => '1', 'author_id' => 1, 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' )), array('Post' => array( 'id' => '2', 'author_id' => 3, 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' )), array('Post' => array( 'id' => '3', 'author_id' => 1, 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ))); if (count($result) != 3) { // Database doesn't support transactions $expected[] = array( 'Post' => array( 'id' => '4', 'author_id' => 1, 'title' => 'New Fourth Post', 'body' => null, 'published' => 'N', 'created' => $ts, 'updated' => $ts )); $expected[] = array( 'Post' => array( 'id' => '5', 'author_id' => 1, 'title' => 'New Fifth Post', 'body' => null, 'published' => 'N', 'created' => $ts, 'updated' => $ts )); $this->assertEqual($result, $expected); // Skip the rest of the transactional tests return; } $this->assertEqual($result, $expected); $data = array( array('author_id' => 1, 'title' => 'New Fourth Post'), array('author_id' => 1, 'title' => ''), array('author_id' => 1, 'title' => 'New Sixth Post') ); $ts = date('Y-m-d H:i:s'); $this->assertFalse($TestModel->saveAll($data)); $result = $TestModel->find('all', array('recursive' => -1)); $expected = array( array('Post' => array( 'id' => '1', 'author_id' => 1, 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' )), array('Post' => array( 'id' => '2', 'author_id' => 3, 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' )), array('Post' => array( 'id' => '3', 'author_id' => 1, 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ))); if (count($result) != 3) { // Database doesn't support transactions $expected[] = array( 'Post' => array( 'id' => '4', 'author_id' => 1, 'title' => 'New Fourth Post', 'body' => 'Third Post Body', 'published' => 'N', 'created' => $ts, 'updated' => $ts )); $expected[] = array( 'Post' => array( 'id' => '5', 'author_id' => 1, 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'N', 'created' => $ts, 'updated' => $ts )); } $this->assertEqual($result, $expected); $TestModel->validate = array('title' => 'notEmpty'); $data = array( array('author_id' => 1, 'title' => 'New Fourth Post'), array('author_id' => 1, 'title' => 'New Fifth Post'), array('author_id' => 1, 'title' => 'New Sixth Post') ); $this->assertTrue($TestModel->saveAll($data)); $result = $TestModel->find('all', array( 'recursive' => -1, 'fields' => array('author_id', 'title','body','published') )); $expected = array( array('Post' => array( 'author_id' => 1, 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y' )), array('Post' => array( 'author_id' => 3, 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y' )), array('Post' => array( 'author_id' => 1, 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y' )), array('Post' => array( 'author_id' => 1, 'title' => 'New Fourth Post', 'body' => '', 'published' => 'N' )), array('Post' => array( 'author_id' => 1, 'title' => 'New Fifth Post', 'body' => '', 'published' => 'N' )), array('Post' => array( 'author_id' => 1, 'title' => 'New Sixth Post', 'body' => '', 'published' => 'N' ))); $this->assertEqual($result, $expected); }
testSaveAllTransaction method @access public @return void
testSaveAllTransaction
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testSaveAllValidation() { $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment'); $TestModel =& new Post(); $data = array( array( 'id' => '1', 'title' => 'Baleeted First Post', 'body' => 'Baleeted!', 'published' => 'N' ), array( 'id' => '2', 'title' => 'Just update the title' ), array( 'title' => 'Creating a fourth post', 'body' => 'Fourth post body', 'author_id' => 2 )); $this->assertTrue($TestModel->saveAll($data)); $result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); $ts = date('Y-m-d H:i:s'); $expected = array( array( 'Post' => array( 'id' => '1', 'author_id' => '1', 'title' => 'Baleeted First Post', 'body' => 'Baleeted!', 'published' => 'N', 'created' => '2007-03-18 10:39:23', 'updated' => $ts )), array( 'Post' => array( 'id' => '2', 'author_id' => '3', 'title' => 'Just update the title', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => $ts )), array( 'Post' => array( 'id' => '3', 'author_id' => '1', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' )), array( 'Post' => array( 'id' => '4', 'author_id' => '2', 'title' => 'Creating a fourth post', 'body' => 'Fourth post body', 'published' => 'N', 'created' => $ts, 'updated' => $ts ))); $this->assertEqual($result, $expected); $TestModel->validate = array('title' => 'notEmpty', 'author_id' => 'numeric'); $data = array( array( 'id' => '1', 'title' => 'Un-Baleeted First Post', 'body' => 'Not Baleeted!', 'published' => 'Y' ), array( 'id' => '2', 'title' => '', 'body' => 'Trying to get away with an empty title' )); $result = $TestModel->saveAll($data); $this->assertEqual($result, false); $result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); $errors = array(1 => array('title' => 'This field cannot be left blank')); $transactionWorked = Set::matches('/Post[1][title=Baleeted First Post]', $result); if (!$transactionWorked) { $this->assertTrue(Set::matches('/Post[1][title=Un-Baleeted First Post]', $result)); $this->assertTrue(Set::matches('/Post[2][title=Just update the title]', $result)); } $this->assertEqual($TestModel->validationErrors, $errors); $TestModel->validate = array('title' => 'notEmpty', 'author_id' => 'numeric'); $data = array( array( 'id' => '1', 'title' => 'Un-Baleeted First Post', 'body' => 'Not Baleeted!', 'published' => 'Y' ), array( 'id' => '2', 'title' => '', 'body' => 'Trying to get away with an empty title' )); $result = $TestModel->saveAll($data, array('validate' => true, 'atomic' => false)); $this->assertEqual($result, array(true, false)); $result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); $errors = array(1 => array('title' => 'This field cannot be left blank')); $newTs = date('Y-m-d H:i:s'); $expected = array( array( 'Post' => array( 'id' => '1', 'author_id' => '1', 'title' => 'Un-Baleeted First Post', 'body' => 'Not Baleeted!', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => $newTs )), array( 'Post' => array( 'id' => '2', 'author_id' => '3', 'title' => 'Just update the title', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => $ts )), array( 'Post' => array( 'id' => '3', 'author_id' => '1', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' )), array( 'Post' => array( 'id' => '4', 'author_id' => '2', 'title' => 'Creating a fourth post', 'body' => 'Fourth post body', 'published' => 'N', 'created' => $ts, 'updated' => $ts ))); $this->assertEqual($result, $expected); $this->assertEqual($TestModel->validationErrors, $errors); $data = array( array( 'id' => '1', 'title' => 'Re-Baleeted First Post', 'body' => 'Baleeted!', 'published' => 'N' ), array( 'id' => '2', 'title' => '', 'body' => 'Trying to get away with an empty title' )); $this->assertFalse($TestModel->saveAll($data, array('validate' => 'first'))); $result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); $this->assertEqual($result, $expected); $this->assertEqual($TestModel->validationErrors, $errors); $data = array( array( 'title' => 'First new post', 'body' => 'Woohoo!', 'published' => 'Y' ), array( 'title' => 'Empty body', 'body' => '' )); $TestModel->validate['body'] = 'notEmpty'; }
testSaveAllValidation method @access public @return void
testSaveAllValidation
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testSaveAllValidationOnly() { $TestModel =& new Comment(); $TestModel->Attachment->validate = array('attachment' => 'notEmpty'); $data = array( 'Comment' => array( 'comment' => 'This is the comment' ), 'Attachment' => array( 'attachment' => '' ) ); $result = $TestModel->saveAll($data, array('validate' => 'only')); $this->assertFalse($result); $TestModel =& new Article(); $TestModel->validate = array('title' => 'notEmpty'); $result = $TestModel->saveAll( array( 0 => array('title' => ''), 1 => array('title' => 'title 1'), 2 => array('title' => 'title 2'), ), array('validate'=>'only') ); $this->assertFalse($result); $expected = array( 0 => array('title' => 'This field cannot be left blank'), ); $this->assertEqual($TestModel->validationErrors, $expected); $result = $TestModel->saveAll( array( 0 => array('title' => 'title 0'), 1 => array('title' => ''), 2 => array('title' => 'title 2'), ), array('validate'=>'only') ); $this->assertFalse($result); $expected = array( 1 => array('title' => 'This field cannot be left blank'), ); $this->assertEqual($TestModel->validationErrors, $expected); }
testSaveAllValidationOnly method @access public @return void
testSaveAllValidationOnly
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testSaveAllValidateFirst() { $model =& new Article(); $model->deleteAll(true); $model->Comment->validate = array('comment' => 'notEmpty'); $result = $model->saveAll(array( 'Article' => array( 'title' => 'Post with Author', 'body' => 'This post will be saved author' ), 'Comment' => array( array('comment' => 'First new comment'), array('comment' => '') ) ), array('validate' => 'first')); $this->assertFalse($result); $result = $model->find('all'); $this->assertEqual($result, array()); $expected = array('Comment' => array( 1 => array('comment' => 'This field cannot be left blank') )); $this->assertEqual($model->Comment->validationErrors, $expected['Comment']); $this->assertIdentical($model->Comment->find('count'), 0); $result = $model->saveAll( array( 'Article' => array( 'title' => 'Post with Author', 'body' => 'This post will be saved with an author', 'user_id' => 2 ), 'Comment' => array( array( 'comment' => 'Only new comment', 'user_id' => 2 ))), array('validate' => 'first') ); $this->assertIdentical($result, true); $result = $model->Comment->find('all'); $this->assertIdentical(count($result), 1); $result = Set::extract('/Comment/article_id', $result); $this->assertTrue($result[0] === 1 || $result[0] === '1'); $model->deleteAll(true); $data = array( 'Article' => array( 'title' => 'Post with Author saveAlled from comment', 'body' => 'This post will be saved with an author', 'user_id' => 2 ), 'Comment' => array( 'comment' => 'Only new comment', 'user_id' => 2 )); $result = $model->Comment->saveAll($data, array('validate' => 'first')); $this->assertTrue($result); $result = $model->find('all'); $this->assertEqual( $result[0]['Article']['title'], 'Post with Author saveAlled from comment' ); $this->assertEqual($result[0]['Comment'][0]['comment'], 'Only new comment'); }
testSaveAllValidateFirst method @access public @return void
testSaveAllValidateFirst
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testSaveAllValidateFirstAtomicFalse() { $Something =& new Something(); $invalidData = array( array( 'title' => 'foo', 'body' => 'bar', 'published' => 'baz', ), array( 'body' => 3, 'published' =>'sd', ), ); $Something->create(); $Something->validate = array( 'title' => array( 'rule' => 'alphaNumeric', 'required' => true, ), 'body' => array( 'rule' => 'alphaNumeric', 'required' => true, 'allowEmpty' => true, ), ); $result = $Something->saveAll($invalidData, array( 'atomic' => false, 'validate' => 'first', )); $expected = array(true, false); $this->assertEqual($result, $expected); $Something =& new Something(); $validData = array( array( 'title' => 'title value', 'body' => 'body value', 'published' => 'baz', ), array( 'title' => 'valid', 'body' => 'this body', 'published' =>'sd', ), ); $Something->create(); $result = $Something->saveAll($validData, array( 'atomic' => false, 'validate' => 'first', )); $expected = array(true, true); $this->assertEqual($result, $expected); }
test saveAll()'s return is correct when using atomic = false and validate = first. @return void
testSaveAllValidateFirstAtomicFalse
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testUpdateWithCalculation() { $this->loadFixtures('DataTest'); $model =& new DataTest(); $model->deleteAll(true); $result = $model->saveAll(array( array('count' => 5, 'float' => 1.1), array('count' => 3, 'float' => 1.2), array('count' => 4, 'float' => 1.3), array('count' => 1, 'float' => 2.0), )); $this->assertTrue($result); $result = Set::extract('/DataTest/count', $model->find('all', array('fields' => 'count'))); $this->assertEqual($result, array(5, 3, 4, 1)); $this->assertTrue($model->updateAll(array('count' => 'count + 2'))); $result = Set::extract('/DataTest/count', $model->find('all', array('fields' => 'count'))); $this->assertEqual($result, array(7, 5, 6, 3)); $this->assertTrue($model->updateAll(array('DataTest.count' => 'DataTest.count - 1'))); $result = Set::extract('/DataTest/count', $model->find('all', array('fields' => 'count'))); $this->assertEqual($result, array(6, 4, 5, 2)); }
testUpdateWithCalculation method @access public @return void
testUpdateWithCalculation
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testSaveAllHasManyValidationOnly() { $this->loadFixtures('Article', 'Comment'); $TestModel =& new Article(); $TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array(); $TestModel->Comment->validate = array('comment' => 'notEmpty'); $result = $TestModel->saveAll( array( 'Article' => array('id' => 2), 'Comment' => array( array( 'id' => 1, 'comment' => '', 'published' => 'Y', 'user_id' => 1), array( 'id' => 2, 'comment' => 'comment', 'published' => 'Y', 'user_id' => 1 ))), array('validate' => 'only') ); $this->assertFalse($result); $result = $TestModel->saveAll( array( 'Article' => array('id' => 2), 'Comment' => array( array( 'id' => 1, 'comment' => '', 'published' => 'Y', 'user_id' => 1 ), array( 'id' => 2, 'comment' => 'comment', 'published' => 'Y', 'user_id' => 1 ), array( 'id' => 3, 'comment' => '', 'published' => 'Y', 'user_id' => 1 ))), array( 'validate' => 'only', 'atomic' => false )); $expected = array( 'Article' => true, 'Comment' => array(false, true, false) ); $this->assertIdentical($result, $expected); $expected = array('Comment' => array( 0 => array('comment' => 'This field cannot be left blank'), 2 => array('comment' => 'This field cannot be left blank') )); $this->assertEqual($TestModel->validationErrors, $expected); $expected = array( 0 => array('comment' => 'This field cannot be left blank'), 2 => array('comment' => 'This field cannot be left blank') ); $this->assertEqual($TestModel->Comment->validationErrors, $expected); }
testSaveAllHasManyValidationOnly method @access public @return void
testSaveAllHasManyValidationOnly
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testFindAllForeignKey() { $this->loadFixtures('ProductUpdateAll', 'GroupUpdateAll'); $ProductUpdateAll =& new ProductUpdateAll(); $conditions = array('Group.name' => 'group one'); $ProductUpdateAll->bindModel(array( 'belongsTo' => array( 'Group' => array('className' => 'GroupUpdateAll') ) )); $ProductUpdateAll->belongsTo = array( 'Group' => array('className' => 'GroupUpdateAll', 'foreignKey' => 'group_id') ); $results = $ProductUpdateAll->find('all', compact('conditions')); $this->assertTrue(!empty($results)); $ProductUpdateAll->bindModel(array('belongsTo'=>array('Group'))); $ProductUpdateAll->belongsTo = array( 'Group' => array( 'className' => 'GroupUpdateAll', 'foreignKey' => false, 'conditions' => 'ProductUpdateAll.groupcode = Group.code' )); $resultsFkFalse = $ProductUpdateAll->find('all', compact('conditions')); $this->assertTrue(!empty($resultsFkFalse)); $expected = array( '0' => array( 'ProductUpdateAll' => array( 'id' => 1, 'name' => 'product one', 'groupcode' => 120, 'group_id' => 1), 'Group' => array( 'id' => 1, 'name' => 'group one', 'code' => 120) ), '1' => array( 'ProductUpdateAll' => array( 'id' => 2, 'name' => 'product two', 'groupcode' => 120, 'group_id' => 1), 'Group' => array( 'id' => 1, 'name' => 'group one', 'code' => 120) ) ); $this->assertEqual($results, $expected); $this->assertEqual($resultsFkFalse, $expected); }
TestFindAllWithoutForeignKey @link http://code.cakephp.org/tickets/view/69 @access public @return void
testFindAllForeignKey
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testUpdateAllEmptyValues() { $this->loadFixtures('Author', 'Post'); $model = new Author(); $result = $model->updateAll(array('user' => '""')); $this->assertTrue($result); }
test updateAll with empty values. @return void
testUpdateAllEmptyValues
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testUpdateAllWithJoins() { $this->skipIf( $this->db->config['driver'] == 'postgres', '%s Currently, there is no way of doing joins in an update statement in postgresql' ); $this->loadFixtures('ProductUpdateAll', 'GroupUpdateAll'); $ProductUpdateAll =& new ProductUpdateAll(); $conditions = array('Group.name' => 'group one'); $ProductUpdateAll->bindModel(array('belongsTo' => array( 'Group' => array('className' => 'GroupUpdateAll'))) ); $ProductUpdateAll->updateAll(array('name' => "'new product'"), $conditions); $results = $ProductUpdateAll->find('all', array( 'conditions' => array('ProductUpdateAll.name' => 'new product') )); $expected = array( '0' => array( 'ProductUpdateAll' => array( 'id' => 1, 'name' => 'new product', 'groupcode' => 120, 'group_id' => 1), 'Group' => array( 'id' => 1, 'name' => 'group one', 'code' => 120) ), '1' => array( 'ProductUpdateAll' => array( 'id' => 2, 'name' => 'new product', 'groupcode' => 120, 'group_id' => 1), 'Group' => array( 'id' => 1, 'name' => 'group one', 'code' => 120))); $this->assertEqual($results, $expected); }
testUpdateAllWithJoins @link http://code.cakephp.org/tickets/view/69 @access public @return void
testUpdateAllWithJoins
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testUpdateAllWithoutForeignKey() { $this->skipIf( $this->db->config['driver'] == 'postgres', '%s Currently, there is no way of doing joins in an update statement in postgresql' ); $this->loadFixtures('ProductUpdateAll', 'GroupUpdateAll'); $ProductUpdateAll =& new ProductUpdateAll(); $conditions = array('Group.name' => 'group one'); $ProductUpdateAll->bindModel(array('belongsTo' => array( 'Group' => array('className' => 'GroupUpdateAll') ))); $ProductUpdateAll->belongsTo = array( 'Group' => array( 'className' => 'GroupUpdateAll', 'foreignKey' => false, 'conditions' => 'ProductUpdateAll.groupcode = Group.code' ) ); $ProductUpdateAll->updateAll(array('name' => "'new product'"), $conditions); $resultsFkFalse = $ProductUpdateAll->find('all', array('conditions' => array('ProductUpdateAll.name'=>'new product'))); $expected = array( '0' => array( 'ProductUpdateAll' => array( 'id' => 1, 'name' => 'new product', 'groupcode' => 120, 'group_id' => 1), 'Group' => array( 'id' => 1, 'name' => 'group one', 'code' => 120) ), '1' => array( 'ProductUpdateAll' => array( 'id' => 2, 'name' => 'new product', 'groupcode' => 120, 'group_id' => 1), 'Group' => array( 'id' => 1, 'name' => 'group one', 'code' => 120))); $this->assertEqual($resultsFkFalse, $expected); }
testUpdateAllWithoutForeignKey @link http://code.cakephp.org/tickets/view/69 @access public @return void
testUpdateAllWithoutForeignKey
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testSaveAllEmptyData() { $this->loadFixtures('Article', 'ProductUpdateAll'); $model =& new Article(); $result = $model->saveAll(array(), array('validate' => 'first')); $this->assertTrue($result); $model =& new ProductUpdateAll(); $result = $model->saveAll(array()); $this->assertFalse($result); }
test that saveAll behaves like plain save() when suplied empty data @link http://cakephp.lighthouseapp.com/projects/42648/tickets/277-test-saveall-with-validation-returns-incorrect-boolean-when-saving-empty-data @access public @return void
testSaveAllEmptyData
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function testWriteFloatAsGerman() { $restore = setlocale(LC_ALL, null); setlocale(LC_ALL, 'de_DE'); $model = new DataTest(); $result = $model->save(array( 'count' => 1, 'float' => 3.14593 )); $this->assertTrue($result); setlocale(LC_ALL, $restore); }
test writing floats in german locale. @return void
testWriteFloatAsGerman
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_write.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_write.test.php
MIT
function parentNode() { if (!$this->id && empty($this->data)) { return null; } if (isset($this->data['AclPerson']['mother_id'])) { $motherId = $this->data['AclPerson']['mother_id']; } else { $motherId = $this->field('mother_id'); } if (!$motherId) { return null; } else { return array('AclPerson' => array('id' => $motherId)); } }
parentNode method @return void @access public
parentNode
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/acl.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/acl.test.php
MIT
function startTest() { Configure::write('Acl.database', 'test_suite'); $this->Aco =& new Aco(); $this->Aro =& new Aro(); }
Set up the test @return void @access public
startTest
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/acl.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/acl.test.php
MIT
function tearDown() { ClassRegistry::flush(); unset($this->Aro, $this->Aco); }
tearDown method @return void @access public
tearDown
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/acl.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/acl.test.php
MIT
function testSetup() { $User =& new AclUser(); $this->assertTrue(isset($User->Behaviors->Acl->settings['User'])); $this->assertEqual($User->Behaviors->Acl->settings['User']['type'], 'requester'); $this->assertTrue(is_object($User->Aro)); $Post =& new AclPost(); $this->assertTrue(isset($Post->Behaviors->Acl->settings['Post'])); $this->assertEqual($Post->Behaviors->Acl->settings['Post']['type'], 'controlled'); $this->assertTrue(is_object($Post->Aco)); }
Test Setup of AclBehavior @return void @access public
testSetup
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/acl.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/acl.test.php
MIT
function testAfterSave() { $Post =& new AclPost(); $data = array( 'Post' => array( 'author_id' => 1, 'title' => 'Acl Post', 'body' => 'post body', 'published' => 1 ), ); $Post->save($data); $result = $this->Aco->find('first', array( 'conditions' => array('Aco.model' => 'Post', 'Aco.foreign_key' => $Post->id) )); $this->assertTrue(is_array($result)); $this->assertEqual($result['Aco']['model'], 'Post'); $this->assertEqual($result['Aco']['foreign_key'], $Post->id); $aroData = array( 'Aro' => array( 'model' => 'AclPerson', 'foreign_key' => 2, 'parent_id' => null ) ); $this->Aro->save($aroData); $Person =& new AclPerson(); $data = array( 'AclPerson' => array( 'name' => 'Trent', 'mother_id' => 2, 'father_id' => 3, ), ); $Person->save($data); $result = $this->Aro->find('first', array( 'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id) )); $this->assertTrue(is_array($result)); $this->assertEqual($result['Aro']['parent_id'], 5); $node = $Person->node(array('model' => 'AclPerson', 'foreign_key' => 8)); $this->assertEqual(count($node), 2); $this->assertEqual($node[0]['Aro']['parent_id'], 5); $this->assertEqual($node[1]['Aro']['parent_id'], null); $aroData = array( 'Aro' => array( 'model' => 'AclPerson', 'foreign_key' => 1, 'parent_id' => null ) ); $this->Aro->create(); $this->Aro->save($aroData); $Person->read(null, 8); $Person->set('mother_id', 1); $Person->save(); $result = $this->Aro->find('first', array( 'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id) )); $this->assertTrue(is_array($result)); $this->assertEqual($result['Aro']['parent_id'], 7); $node = $Person->node(array('model' => 'AclPerson', 'foreign_key' => 8)); $this->assertEqual(sizeof($node), 2); $this->assertEqual($node[0]['Aro']['parent_id'], 7); $this->assertEqual($node[1]['Aro']['parent_id'], null); }
test After Save @return void @access public
testAfterSave
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/acl.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/acl.test.php
MIT
function testAfterSaveUpdateParentIdNotNull() { $aroData = array( 'Aro' => array( 'model' => 'AclPerson', 'foreign_key' => 2, 'parent_id' => null ) ); $this->Aro->save($aroData); $Person =& new AclPerson(); $data = array( 'AclPerson' => array( 'name' => 'Trent', 'mother_id' => 2, 'father_id' => 3, ), ); $Person->save($data); $result = $this->Aro->find('first', array( 'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id) )); $this->assertTrue(is_array($result)); $this->assertEqual($result['Aro']['parent_id'], 5); $Person->save(array('id' => $Person->id, 'name' => 'Bruce')); $result = $this->Aro->find('first', array( 'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id) )); $this->assertEqual($result['Aro']['parent_id'], 5); }
test that an afterSave on an update does not cause parent_id to become null. @return void
testAfterSaveUpdateParentIdNotNull
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/acl.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/acl.test.php
MIT
function testAfterDelete() { $aroData = array( 'Aro' => array( 'model' => 'AclPerson', 'foreign_key' => 2, 'parent_id' => null ) ); $this->Aro->save($aroData); $Person =& new AclPerson(); $data = array( 'AclPerson' => array( 'name' => 'Trent', 'mother_id' => 2, 'father_id' => 3, ), ); $Person->save($data); $id = $Person->id; $node = $Person->node(); $this->assertEqual(count($node), 2); $this->assertEqual($node[0]['Aro']['parent_id'], 5); $this->assertEqual($node[1]['Aro']['parent_id'], null); $Person->delete($id); $result = $this->Aro->find('first', array( 'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $id) )); $this->assertTrue(empty($result)); $result = $this->Aro->find('first', array( 'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => 2) )); $this->assertFalse(empty($result)); $data = array( 'AclPerson' => array( 'name' => 'Trent', 'mother_id' => 2, 'father_id' => 3, ), ); $Person->save($data); $id = $Person->id; $Person->delete(2); $result = $this->Aro->find('first', array( 'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $id) )); $this->assertTrue(empty($result)); $result = $this->Aro->find('first', array( 'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => 2) )); $this->assertTrue(empty($result)); }
Test After Delete @return void @access public
testAfterDelete
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/acl.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/acl.test.php
MIT
function testNode() { $Person =& new AclPerson(); $aroData = array( 'Aro' => array( 'model' => 'AclPerson', 'foreign_key' => 2, 'parent_id' => null ) ); $this->Aro->save($aroData); $Person->id = 2; $result = $Person->node(); $this->assertTrue(is_array($result)); $this->assertEqual(count($result), 1); }
Test Node() @return void @access public
testNode
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/acl.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/acl.test.php
MIT
function startTest() { $this->User =& ClassRegistry::init('User'); $this->Article =& ClassRegistry::init('Article'); $this->Tag =& ClassRegistry::init('Tag'); $this->User->bindModel(array( 'hasMany' => array('Article', 'ArticleFeatured', 'Comment') ), false); $this->User->ArticleFeatured->unbindModel(array('belongsTo' => array('Category')), false); $this->User->ArticleFeatured->hasMany['Comment']['foreignKey'] = 'article_id'; $this->Tag->bindModel(array( 'hasAndBelongsToMany' => array('Article') ), false); $this->User->Behaviors->attach('Containable'); $this->Article->Behaviors->attach('Containable'); $this->Tag->Behaviors->attach('Containable'); }
Method executed before each test @access public
startTest
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function endTest() { unset($this->Article); unset($this->User); unset($this->Tag); ClassRegistry::flush(); }
Method executed after each test @access public
endTest
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testContainments() { $r = $this->__containments($this->Article, array('Comment' => array('conditions' => array('Comment.user_id' => 2)))); $this->assertTrue(Set::matches('/Article/keep/Comment/conditions[Comment.user_id=2]', $r)); $r = $this->__containments($this->User, array( 'ArticleFeatured' => array( 'Featured' => array( 'id', 'Category' => 'name' ) ))); $this->assertEqual(Set::extract('/ArticleFeatured/keep/Featured/fields', $r), array('id')); $r = $this->__containments($this->Article, array( 'Comment' => array( 'User', 'conditions' => array('Comment' => array('user_id' => 2)), ), )); $this->assertTrue(Set::matches('/User', $r)); $this->assertTrue(Set::matches('/Comment', $r)); $this->assertTrue(Set::matches('/Article/keep/Comment/conditions/Comment[user_id=2]', $r)); $r = $this->__containments($this->Article, array('Comment(comment, published)' => 'Attachment(attachment)', 'User(user)')); $this->assertTrue(Set::matches('/Comment', $r)); $this->assertTrue(Set::matches('/User', $r)); $this->assertTrue(Set::matches('/Article/keep/Comment', $r)); $this->assertTrue(Set::matches('/Article/keep/User', $r)); $this->assertEqual(Set::extract('/Article/keep/Comment/fields', $r), array('comment', 'published')); $this->assertEqual(Set::extract('/Article/keep/User/fields', $r), array('user')); $this->assertTrue(Set::matches('/Comment/keep/Attachment', $r)); $this->assertEqual(Set::extract('/Comment/keep/Attachment/fields', $r), array('attachment')); $r = $this->__containments($this->Article, array('Comment' => array('limit' => 1))); $this->assertEqual(array_keys($r), array('Comment', 'Article')); $this->assertEqual(array_shift(Set::extract('/Comment/keep', $r)), array('keep' => array())); $this->assertTrue(Set::matches('/Article/keep/Comment', $r)); $this->assertEqual(array_shift(Set::extract('/Article/keep/Comment/.', $r)), array('limit' => 1)); $r = $this->__containments($this->Article, array('Comment.User')); $this->assertEqual(array_keys($r), array('User', 'Comment', 'Article')); $this->assertEqual(array_shift(Set::extract('/User/keep', $r)), array('keep' => array())); $this->assertEqual(array_shift(Set::extract('/Comment/keep', $r)), array('keep' => array('User' => array()))); $this->assertEqual(array_shift(Set::extract('/Article/keep', $r)), array('keep' => array('Comment' => array()))); $r = $this->__containments($this->Tag, array('Article' => array('User' => array('Comment' => array( 'Attachment' => array('conditions' => array('Attachment.id >' => 1)) ))))); $this->assertTrue(Set::matches('/Attachment', $r)); $this->assertTrue(Set::matches('/Comment/keep/Attachment/conditions', $r)); $this->assertEqual($r['Comment']['keep']['Attachment']['conditions'], array('Attachment.id >' => 1)); $this->assertTrue(Set::matches('/User/keep/Comment', $r)); $this->assertTrue(Set::matches('/Article/keep/User', $r)); $this->assertTrue(Set::matches('/Tag/keep/Article', $r)); }
testContainments method @access public @return void
testContainments
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testInvalidContainments() { $this->expectError(); $r = $this->__containments($this->Article, array('Comment', 'InvalidBinding')); $this->Article->Behaviors->attach('Containable', array('notices' => false)); $r = $this->__containments($this->Article, array('Comment', 'InvalidBinding')); }
testInvalidContainments method @access public @return void
testInvalidContainments
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testBeforeFind() { $r = $this->Article->find('all', array('contain' => array('Comment'))); $this->assertFalse(Set::matches('/User', $r)); $this->assertTrue(Set::matches('/Comment', $r)); $this->assertFalse(Set::matches('/Comment/User', $r)); $r = $this->Article->find('all', array('contain' => 'Comment.User')); $this->assertTrue(Set::matches('/Comment/User', $r)); $this->assertFalse(Set::matches('/Comment/Article', $r)); $r = $this->Article->find('all', array('contain' => array('Comment' => array('User', 'Article')))); $this->assertTrue(Set::matches('/Comment/User', $r)); $this->assertTrue(Set::matches('/Comment/Article', $r)); $r = $this->Article->find('all', array('contain' => array('Comment' => array('conditions' => array('Comment.user_id' => 2))))); $this->assertFalse(Set::matches('/Comment[user_id!=2]', $r)); $this->assertTrue(Set::matches('/Comment[user_id=2]', $r)); $r = $this->Article->find('all', array('contain' => array('Comment.user_id = 2'))); $this->assertFalse(Set::matches('/Comment[user_id!=2]', $r)); $r = $this->Article->find('all', array('contain' => 'Comment.id DESC')); $ids = $descIds = Set::extract('/Comment[1]/id', $r); rsort($descIds); $this->assertEqual($ids, $descIds); $r = $this->Article->find('all', array('contain' => 'Comment')); $this->assertTrue(Set::matches('/Comment[user_id!=2]', $r)); $r = $this->Article->find('all', array('contain' => array('Comment' => array('fields' => 'comment')))); $this->assertFalse(Set::matches('/Comment/created', $r)); $this->assertTrue(Set::matches('/Comment/comment', $r)); $this->assertFalse(Set::matches('/Comment/updated', $r)); $r = $this->Article->find('all', array('contain' => array('Comment' => array('fields' => array('comment', 'updated'))))); $this->assertFalse(Set::matches('/Comment/created', $r)); $this->assertTrue(Set::matches('/Comment/comment', $r)); $this->assertTrue(Set::matches('/Comment/updated', $r)); $r = $this->Article->find('all', array('contain' => array('Comment' => array('comment', 'updated')))); $this->assertFalse(Set::matches('/Comment/created', $r)); $this->assertTrue(Set::matches('/Comment/comment', $r)); $this->assertTrue(Set::matches('/Comment/updated', $r)); $r = $this->Article->find('all', array('contain' => array('Comment(comment,updated)'))); $this->assertFalse(Set::matches('/Comment/created', $r)); $this->assertTrue(Set::matches('/Comment/comment', $r)); $this->assertTrue(Set::matches('/Comment/updated', $r)); $r = $this->Article->find('all', array('contain' => 'Comment.created')); $this->assertTrue(Set::matches('/Comment/created', $r)); $this->assertFalse(Set::matches('/Comment/comment', $r)); $r = $this->Article->find('all', array('contain' => array('User.Article(title)', 'Comment(comment)'))); $this->assertFalse(Set::matches('/Comment/Article', $r)); $this->assertFalse(Set::matches('/Comment/User', $r)); $this->assertTrue(Set::matches('/Comment/comment', $r)); $this->assertFalse(Set::matches('/Comment/created', $r)); $this->assertTrue(Set::matches('/User/Article/title', $r)); $this->assertFalse(Set::matches('/User/Article/created', $r)); $r = $this->Article->find('all', array('contain' => array())); $this->assertFalse(Set::matches('/User', $r)); $this->assertFalse(Set::matches('/Comment', $r)); $this->expectError(); $r = $this->Article->find('all', array('contain' => array('Comment' => 'NonExistingBinding'))); }
testBeforeFind method @access public @return void
testBeforeFind
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testContain() { $this->Article->contain('Comment.User'); $r = $this->Article->find('all'); $this->assertTrue(Set::matches('/Comment/User', $r)); $this->assertFalse(Set::matches('/Comment/Article', $r)); $r = $this->Article->find('all'); $this->assertFalse(Set::matches('/Comment/User', $r)); }
testContain method @access public @return void
testContain
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testContainAndContainOption() { $this->Article->contain(); $r = $this->Article->find('all', array( 'contain' => array('Comment') )); $this->assertTrue(isset($r[0]['Comment']), 'No comment returned'); }
Test that mixing contain() and the contain find option. @access public @return void
testContainAndContainOption
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testFindEmbeddedNoBindings() { $result = $this->Article->find('all', array('contain' => false)); $expected = array( array('Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' )), array('Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' )), array('Article' => array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' )) ); $this->assertEqual($result, $expected); }
testFindEmbeddedNoBindings method @access public @return void
testFindEmbeddedNoBindings
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testFindFirstLevel() { $this->Article->contain('User'); $result = $this->Article->find('all', array('recursive' => 1)); $expected = array( array( 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ) ), array( 'Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' ) ), array( 'Article' => array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ), 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ) ) ); $this->assertEqual($result, $expected); $this->Article->contain('User', 'Comment'); $result = $this->Article->find('all', array('recursive' => 1)); $expected = array( array( 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ), 'Comment' => array( array( 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31' ), array( 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31' ), array( 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31' ), array( 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31' ) ) ), array( 'Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' ), 'Comment' => array( array( 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31' ), array( 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31' ) ) ), array( 'Article' => array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ), 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ), 'Comment' => array() ) ); $this->assertEqual($result, $expected); }
testFindFirstLevel method @access public @return void
testFindFirstLevel
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testFindEmbeddedFirstLevel() { $result = $this->Article->find('all', array('contain' => array('User'))); $expected = array( array( 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ) ), array( 'Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' ) ), array( 'Article' => array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ), 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ) ) ); $this->assertEqual($result, $expected); $result = $this->Article->find('all', array('contain' => array('User', 'Comment'))); $expected = array( array( 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ), 'Comment' => array( array( 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31' ), array( 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31' ), array( 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31' ), array( 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31' ) ) ), array( 'Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' ), 'Comment' => array( array( 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31' ), array( 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31' ) ) ), array( 'Article' => array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ), 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ), 'Comment' => array() ) ); $this->assertEqual($result, $expected); }
testFindEmbeddedFirstLevel method @access public @return void
testFindEmbeddedFirstLevel
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testFindSecondLevel() { $this->Article->contain(array('Comment' => 'User')); $result = $this->Article->find('all', array('recursive' => 2)); $expected = array( array( 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Comment' => array( array( 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31', 'User' => array( 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' ) ), array( 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31', 'User' => array( 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ) ), array( 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31', 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ) ), array( 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31', 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ) ) ) ), array( 'Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'Comment' => array( array( 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31', 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ) ), array( 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31', 'User' => array( 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' ) ) ) ), array( 'Article' => array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ), 'Comment' => array() ) ); $this->assertEqual($result, $expected); $this->Article->contain(array('User' => 'ArticleFeatured')); $result = $this->Article->find('all', array('recursive' => 2)); $expected = array( array( 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ) ) ) ), array( 'Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31', 'ArticleFeatured' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ) ) ) ), array( 'Article' => array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ), 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ) ) ) ) ); $this->assertEqual($result, $expected); $this->Article->contain(array('User' => array('ArticleFeatured', 'Comment'))); $result = $this->Article->find('all', array('recursive' => 2)); $expected = array( array( 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ) ), 'Comment' => array( array( 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31' ), array( 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31' ), array( 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31' ) ) ) ), array( 'Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31', 'ArticleFeatured' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ) ), 'Comment' => array() ) ), array( 'Article' => array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ), 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ) ), 'Comment' => array( array( 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31' ), array( 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31' ), array( 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31' ) ) ) ) ); $this->assertEqual($result, $expected); $this->Article->contain(array('User' => array('ArticleFeatured')), 'Tag', array('Comment' => 'Attachment')); $result = $this->Article->find('all', array('recursive' => 2)); $expected = array( array( 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ) ) ), 'Comment' => array( array( 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31', 'Attachment' => array() ), array( 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31', 'Attachment' => array() ), array( 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31', 'Attachment' => array() ), array( 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31', 'Attachment' => array() ) ), 'Tag' => array( array('id' => 1, 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), array('id' => 2, 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31') ) ), array( 'Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31', 'ArticleFeatured' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ) ) ), 'Comment' => array( array( 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31', 'Attachment' => array( 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31' ) ), array( 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31', 'Attachment' => array() ) ), 'Tag' => array( array('id' => 1, 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), array('id' => 3, 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31') ) ), array( 'Article' => array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ), 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ) ) ), 'Comment' => array(), 'Tag' => array() ) ); $this->assertEqual($result, $expected); }
testFindSecondLevel method @access public @return void
testFindSecondLevel
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testFindEmbeddedSecondLevel() { $result = $this->Article->find('all', array('contain' => array('Comment' => 'User'))); $expected = array( array( 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Comment' => array( array( 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31', 'User' => array( 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' ) ), array( 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31', 'User' => array( 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ) ), array( 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31', 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ) ), array( 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31', 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ) ) ) ), array( 'Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'Comment' => array( array( 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31', 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ) ), array( 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31', 'User' => array( 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' ) ) ) ), array( 'Article' => array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ), 'Comment' => array() ) ); $this->assertEqual($result, $expected); $result = $this->Article->find('all', array('contain' => array('User' => 'ArticleFeatured'))); $expected = array( array( 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ) ) ) ), array( 'Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31', 'ArticleFeatured' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ) ) ) ), array( 'Article' => array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ), 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ) ) ) ) ); $this->assertEqual($result, $expected); $result = $this->Article->find('all', array('contain' => array('User' => array('ArticleFeatured', 'Comment')))); $expected = array( array( 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ) ), 'Comment' => array( array( 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31' ), array( 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31' ), array( 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31' ) ) ) ), array( 'Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31', 'ArticleFeatured' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ) ), 'Comment' => array() ) ), array( 'Article' => array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ), 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ) ), 'Comment' => array( array( 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31' ), array( 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31' ), array( 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31' ) ) ) ) ); $this->assertEqual($result, $expected); $result = $this->Article->find('all', array('contain' => array('User' => 'ArticleFeatured', 'Tag', 'Comment' => 'Attachment'))); $expected = array( array( 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ) ) ), 'Comment' => array( array( 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31', 'Attachment' => array() ), array( 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31', 'Attachment' => array() ), array( 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31', 'Attachment' => array() ), array( 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31', 'Attachment' => array() ) ), 'Tag' => array( array('id' => 1, 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), array('id' => 2, 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31') ) ), array( 'Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31', 'ArticleFeatured' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ) ) ), 'Comment' => array( array( 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31', 'Attachment' => array( 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31' ) ), array( 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31', 'Attachment' => array() ) ), 'Tag' => array( array('id' => 1, 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), array('id' => 3, 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31') ) ), array( 'Article' => array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ), 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ) ) ), 'Comment' => array(), 'Tag' => array() ) ); $this->assertEqual($result, $expected); }
testFindEmbeddedSecondLevel method @access public @return void
testFindEmbeddedSecondLevel
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testFindThirdLevel() { $this->User->contain(array('ArticleFeatured' => array('Featured' => 'Category'))); $result = $this->User->find('all', array('recursive' => 3)); $expected = array( array( 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ), 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Featured' => array( 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ) ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', 'Featured' => array() ) ) ), array( 'User' => array( 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' ), 'ArticleFeatured' => array() ), array( 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' ), 'ArticleFeatured' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', 'Featured' => array( 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ) ) ) ), array( 'User' => array( 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ), 'ArticleFeatured' => array() ) ); $this->assertEqual($result, $expected); $this->User->contain(array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment')))); $result = $this->User->find('all', array('recursive' => 3)); $expected = array( array( 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ), 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Featured' => array( 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ), 'Comment' => array( array( 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31', 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Attachment' => array() ), array( 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31', 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Attachment' => array() ), array( 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31', 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Attachment' => array() ), array( 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31', 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Attachment' => array() ) ) ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', 'Featured' => array(), 'Comment' => array() ) ) ), array( 'User' => array( 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' ), 'ArticleFeatured' => array() ), array( 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' ), 'ArticleFeatured' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', 'Featured' => array( 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ), 'Comment' => array( array( 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31', 'Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'Attachment' => array( 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31' ) ), array( 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31', 'Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'Attachment' => array() ) ) ) ) ), array( 'User' => array( 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ), 'ArticleFeatured' => array() ) ); $this->assertEqual($result, $expected); $this->User->contain(array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => 'Attachment'), 'Article')); $result = $this->User->find('all', array('recursive' => 3)); $expected = array( array( 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ), 'Article' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ) ), 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Featured' => array( 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ), 'Comment' => array( array( 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31', 'Attachment' => array() ), array( 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31', 'Attachment' => array() ), array( 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31', 'Attachment' => array() ), array( 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31', 'Attachment' => array() ) ) ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', 'Featured' => array(), 'Comment' => array() ) ) ), array( 'User' => array( 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' ), 'Article' => array(), 'ArticleFeatured' => array() ), array( 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' ), 'Article' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ) ), 'ArticleFeatured' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', 'Featured' => array( 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ), 'Comment' => array( array( 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31', 'Attachment' => array( 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31' ) ), array( 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31', 'Attachment' => array() ) ) ) ) ), array( 'User' => array( 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ), 'Article' => array(), 'ArticleFeatured' => array() ) ); $this->assertEqual($result, $expected); }
testFindThirdLevel method @access public @return void
testFindThirdLevel
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testFindEmbeddedThirdLevel() { $result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => 'Category')))); $expected = array( array( 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ), 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Featured' => array( 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ) ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', 'Featured' => array() ) ) ), array( 'User' => array( 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' ), 'ArticleFeatured' => array() ), array( 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' ), 'ArticleFeatured' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', 'Featured' => array( 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ) ) ) ), array( 'User' => array( 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ), 'ArticleFeatured' => array() ) ); $this->assertEqual($result, $expected); $result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment'))))); $expected = array( array( 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ), 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Featured' => array( 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ), 'Comment' => array( array( 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31', 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Attachment' => array() ), array( 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31', 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Attachment' => array() ), array( 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31', 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Attachment' => array() ), array( 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31', 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Attachment' => array() ) ) ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', 'Featured' => array(), 'Comment' => array() ) ) ), array( 'User' => array( 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' ), 'ArticleFeatured' => array() ), array( 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' ), 'ArticleFeatured' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', 'Featured' => array( 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ), 'Comment' => array( array( 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31', 'Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'Attachment' => array( 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31' ) ), array( 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31', 'Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'Attachment' => array() ) ) ) ) ), array( 'User' => array( 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ), 'ArticleFeatured' => array() ) ); $this->assertEqual($result, $expected); $result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => 'Attachment'), 'Article'))); $expected = array( array( 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ), 'Article' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ) ), 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Featured' => array( 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ), 'Comment' => array( array( 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31', 'Attachment' => array() ), array( 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31', 'Attachment' => array() ), array( 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31', 'Attachment' => array() ), array( 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31', 'Attachment' => array() ) ) ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', 'Featured' => array(), 'Comment' => array() ) ) ), array( 'User' => array( 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' ), 'Article' => array(), 'ArticleFeatured' => array() ), array( 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' ), 'Article' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ) ), 'ArticleFeatured' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', 'Featured' => array( 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ), 'Comment' => array( array( 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31', 'Attachment' => array( 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31' ) ), array( 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31', 'Attachment' => array() ) ) ) ) ), array( 'User' => array( 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ), 'Article' => array(), 'ArticleFeatured' => array() ) ); $this->assertEqual($result, $expected); }
testFindEmbeddedThirdLevel method @access public @return void
testFindEmbeddedThirdLevel
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testSettingsThirdLevel() { $result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => array('Category' => array('id', 'name')))))); $expected = array( array( 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ), 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Featured' => array( 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'name' => 'Category 1' ) ) ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', 'Featured' => array() ) ) ), array( 'User' => array( 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' ), 'ArticleFeatured' => array() ), array( 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' ), 'ArticleFeatured' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', 'Featured' => array( 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'name' => 'Category 1' ) ) ) ) ), array( 'User' => array( 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ), 'ArticleFeatured' => array() ) ); $this->assertEqual($result, $expected); $r = $this->User->find('all', array('contain' => array( 'ArticleFeatured' => array( 'id', 'title', 'Featured' => array( 'id', 'category_id', 'Category' => array('id', 'name') ) ) ))); $this->assertTrue(Set::matches('/User[id=1]', $r)); $this->assertFalse(Set::matches('/Article', $r) || Set::matches('/Comment', $r)); $this->assertTrue(Set::matches('/ArticleFeatured', $r)); $this->assertFalse(Set::matches('/ArticleFeatured/User', $r) || Set::matches('/ArticleFeatured/Comment', $r) || Set::matches('/ArticleFeatured/Tag', $r)); $this->assertTrue(Set::matches('/ArticleFeatured/Featured', $r)); $this->assertFalse(Set::matches('/ArticleFeatured/Featured/ArticleFeatured', $r)); $this->assertTrue(Set::matches('/ArticleFeatured/Featured/Category', $r)); $this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]', $r)); $this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]/Category[id=1]', $r)); $this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]/Category[name=Category 1]', $r)); $r = $this->User->find('all', array('contain' => array( 'ArticleFeatured' => array( 'title', 'Featured' => array( 'id', 'Category' => 'name' ) ) ))); $this->assertTrue(Set::matches('/User[id=1]', $r)); $this->assertFalse(Set::matches('/Article', $r) || Set::matches('/Comment', $r)); $this->assertTrue(Set::matches('/ArticleFeatured', $r)); $this->assertFalse(Set::matches('/ArticleFeatured/User', $r) || Set::matches('/ArticleFeatured/Comment', $r) || Set::matches('/ArticleFeatured/Tag', $r)); $this->assertTrue(Set::matches('/ArticleFeatured/Featured', $r)); $this->assertFalse(Set::matches('/ArticleFeatured/Featured/ArticleFeatured', $r)); $this->assertTrue(Set::matches('/ArticleFeatured/Featured/Category', $r)); $this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]', $r)); $this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]/Category[name=Category 1]', $r)); $result = $this->User->find('all', array('contain' => array( 'ArticleFeatured' => array( 'title', 'Featured' => array( 'category_id', 'Category' => 'name' ) ) ))); $expected = array( array( 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ), 'ArticleFeatured' => array( array( 'title' => 'First Article', 'id' => 1, 'user_id' => 1, 'Featured' => array( 'category_id' => 1, 'id' => 1, 'Category' => array( 'name' => 'Category 1' ) ) ), array( 'title' => 'Third Article', 'id' => 3, 'user_id' => 1, 'Featured' => array() ) ) ), array( 'User' => array( 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' ), 'ArticleFeatured' => array() ), array( 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' ), 'ArticleFeatured' => array( array( 'title' => 'Second Article', 'id' => 2, 'user_id' => 3, 'Featured' => array( 'category_id' => 1, 'id' => 2, 'Category' => array( 'name' => 'Category 1' ) ) ) ) ), array( 'User' => array( 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ), 'ArticleFeatured' => array() ) ); $this->assertEqual($result, $expected); $orders = array( 'title DESC', 'title DESC, published DESC', array('title' => 'DESC'), array('title' => 'DESC', 'published' => 'DESC'), ); foreach ($orders as $order) { $result = $this->User->find('all', array('contain' => array( 'ArticleFeatured' => array( 'title', 'order' => $order, 'Featured' => array( 'category_id', 'Category' => 'name' ) ) ))); $expected = array( array( 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ), 'ArticleFeatured' => array( array( 'title' => 'Third Article', 'id' => 3, 'user_id' => 1, 'Featured' => array() ), array( 'title' => 'First Article', 'id' => 1, 'user_id' => 1, 'Featured' => array( 'category_id' => 1, 'id' => 1, 'Category' => array( 'name' => 'Category 1' ) ) ) ) ), array( 'User' => array( 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' ), 'ArticleFeatured' => array() ), array( 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' ), 'ArticleFeatured' => array( array( 'title' => 'Second Article', 'id' => 2, 'user_id' => 3, 'Featured' => array( 'category_id' => 1, 'id' => 2, 'Category' => array( 'name' => 'Category 1' ) ) ) ) ), array( 'User' => array( 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ), 'ArticleFeatured' => array() ) ); $this->assertEqual($result, $expected); } }
testSettingsThirdLevel method @access public @return void
testSettingsThirdLevel
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testFindThirdLevelNonReset() { $this->User->contain(false, array('ArticleFeatured' => array('Featured' => 'Category'))); $result = $this->User->find('all', array('recursive' => 3)); $expected = array( array( 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ), 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Featured' => array( 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ) ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', 'Featured' => array() ) ) ), array( 'User' => array( 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' ), 'ArticleFeatured' => array() ), array( 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' ), 'ArticleFeatured' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', 'Featured' => array( 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ) ) ) ), array( 'User' => array( 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ), 'ArticleFeatured' => array() ) ); $this->assertEqual($result, $expected); $this->User->resetBindings(); $this->User->contain(false, array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment')))); $result = $this->User->find('all', array('recursive' => 3)); $expected = array( array( 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ), 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Featured' => array( 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ), 'Comment' => array( array( 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31', 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Attachment' => array() ), array( 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31', 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Attachment' => array() ), array( 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31', 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Attachment' => array() ), array( 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31', 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Attachment' => array() ) ) ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', 'Featured' => array(), 'Comment' => array() ) ) ), array( 'User' => array( 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' ), 'ArticleFeatured' => array() ), array( 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' ), 'ArticleFeatured' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', 'Featured' => array( 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ), 'Comment' => array( array( 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31', 'Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'Attachment' => array( 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31' ) ), array( 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31', 'Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'Attachment' => array() ) ) ) ) ), array( 'User' => array( 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ), 'ArticleFeatured' => array() ) ); $this->assertEqual($result, $expected); $this->User->resetBindings(); $this->User->contain(false, array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => 'Attachment'), 'Article')); $result = $this->User->find('all', array('recursive' => 3)); $expected = array( array( 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ), 'Article' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ) ), 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Featured' => array( 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ), 'Comment' => array( array( 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31', 'Attachment' => array() ), array( 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31', 'Attachment' => array() ), array( 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31', 'Attachment' => array() ), array( 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31', 'Attachment' => array() ) ) ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', 'Featured' => array(), 'Comment' => array() ) ) ), array( 'User' => array( 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' ), 'Article' => array(), 'ArticleFeatured' => array() ), array( 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' ), 'Article' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ) ), 'ArticleFeatured' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', 'Featured' => array( 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ), 'Comment' => array( array( 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31', 'Attachment' => array( 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31' ) ), array( 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31', 'Attachment' => array() ) ) ) ) ), array( 'User' => array( 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ), 'Article' => array(), 'ArticleFeatured' => array() ) ); $this->assertEqual($result, $expected); }
testFindThirdLevelNonReset method @access public @return void
testFindThirdLevelNonReset
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testFindEmbeddedThirdLevelNonReset() { $result = $this->User->find('all', array('reset' => false, 'contain' => array('ArticleFeatured' => array('Featured' => 'Category')))); $expected = array( array( 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ), 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Featured' => array( 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ) ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', 'Featured' => array() ) ) ), array( 'User' => array( 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' ), 'ArticleFeatured' => array() ), array( 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' ), 'ArticleFeatured' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', 'Featured' => array( 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ) ) ) ), array( 'User' => array( 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ), 'ArticleFeatured' => array() ) ); $this->assertEqual($result, $expected); $this->__assertBindings($this->User, array('hasMany' => array('ArticleFeatured'))); $this->__assertBindings($this->User->ArticleFeatured, array('hasOne' => array('Featured'))); $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('Category'))); $this->User->resetBindings(); $this->__assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured', 'Comment'))); $this->__assertBindings($this->User->ArticleFeatured, array('belongsTo' => array('User'), 'hasOne' => array('Featured'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag'))); $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('ArticleFeatured', 'Category'))); $this->__assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article', 'User'), 'hasOne' => array('Attachment'))); $result = $this->User->find('all', array('reset' => false, 'contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment'))))); $expected = array( array( 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ), 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Featured' => array( 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ), 'Comment' => array( array( 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31', 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Attachment' => array() ), array( 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31', 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Attachment' => array() ), array( 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31', 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Attachment' => array() ), array( 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31', 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Attachment' => array() ) ) ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', 'Featured' => array(), 'Comment' => array() ) ) ), array( 'User' => array( 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' ), 'ArticleFeatured' => array() ), array( 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' ), 'ArticleFeatured' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', 'Featured' => array( 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ), 'Comment' => array( array( 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31', 'Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'Attachment' => array( 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31' ) ), array( 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31', 'Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'Attachment' => array() ) ) ) ) ), array( 'User' => array( 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ), 'ArticleFeatured' => array() ) ); $this->assertEqual($result, $expected); $this->__assertBindings($this->User, array('hasMany' => array('ArticleFeatured'))); $this->__assertBindings($this->User->ArticleFeatured, array('hasOne' => array('Featured'), 'hasMany' => array('Comment'))); $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('Category'))); $this->__assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article'), 'hasOne' => array('Attachment'))); $this->User->resetBindings(); $this->__assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured', 'Comment'))); $this->__assertBindings($this->User->ArticleFeatured, array('belongsTo' => array('User'), 'hasOne' => array('Featured'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag'))); $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('ArticleFeatured', 'Category'))); $this->__assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article', 'User'), 'hasOne' => array('Attachment'))); $result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment')), false))); $expected = array( array( 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ), 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Featured' => array( 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ), 'Comment' => array( array( 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31', 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Attachment' => array() ), array( 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31', 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Attachment' => array() ), array( 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31', 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Attachment' => array() ), array( 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31', 'Article' => array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Attachment' => array() ) ) ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', 'Featured' => array(), 'Comment' => array() ) ) ), array( 'User' => array( 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' ), 'ArticleFeatured' => array() ), array( 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' ), 'ArticleFeatured' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', 'Featured' => array( 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ), 'Comment' => array( array( 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31', 'Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'Attachment' => array( 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31' ) ), array( 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31', 'Article' => array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'Attachment' => array() ) ) ) ) ), array( 'User' => array( 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ), 'ArticleFeatured' => array() ) ); $this->assertEqual($result, $expected); $this->__assertBindings($this->User, array('hasMany' => array('ArticleFeatured'))); $this->__assertBindings($this->User->ArticleFeatured, array('hasOne' => array('Featured'), 'hasMany' => array('Comment'))); $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('Category'))); $this->__assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article'), 'hasOne' => array('Attachment'))); $this->User->resetBindings(); $this->__assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured', 'Comment'))); $this->__assertBindings($this->User->ArticleFeatured, array('belongsTo' => array('User'), 'hasOne' => array('Featured'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag'))); $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('ArticleFeatured', 'Category'))); $this->__assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article', 'User'), 'hasOne' => array('Attachment'))); $result = $this->User->find('all', array('reset' => false, 'contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => 'Attachment'), 'Article'))); $expected = array( array( 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ), 'Article' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ) ), 'ArticleFeatured' => array( array( 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Featured' => array( 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ), 'Comment' => array( array( 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31', 'Attachment' => array() ), array( 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31', 'Attachment' => array() ), array( 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31', 'Attachment' => array() ), array( 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31', 'Attachment' => array() ) ) ), array( 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', 'Featured' => array(), 'Comment' => array() ) ) ), array( 'User' => array( 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' ), 'Article' => array(), 'ArticleFeatured' => array() ), array( 'User' => array( 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' ), 'Article' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ) ), 'ArticleFeatured' => array( array( 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', 'Featured' => array( 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ) ), 'Comment' => array( array( 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31', 'Attachment' => array( 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31' ) ), array( 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31', 'Attachment' => array() ) ) ) ) ), array( 'User' => array( 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ), 'Article' => array(), 'ArticleFeatured' => array() ) ); $this->assertEqual($result, $expected); $this->__assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured'))); $this->__assertBindings($this->User->Article); $this->__assertBindings($this->User->ArticleFeatured, array('hasOne' => array('Featured'), 'hasMany' => array('Comment'))); $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('Category'))); $this->__assertBindings($this->User->ArticleFeatured->Comment, array('hasOne' => array('Attachment'))); $this->User->resetBindings(); $this->__assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured', 'Comment'))); $this->__assertBindings($this->User->Article, array('belongsTo' => array('User'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag'))); $this->__assertBindings($this->User->ArticleFeatured, array('belongsTo' => array('User'), 'hasOne' => array('Featured'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag'))); $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('ArticleFeatured', 'Category'))); $this->__assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article', 'User'), 'hasOne' => array('Attachment'))); }
testFindEmbeddedThirdLevelNonReset method @access public @return void
testFindEmbeddedThirdLevelNonReset
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testEmbeddedFindFields() { $result = $this->Article->find('all', array( 'contain' => array('User(user)'), 'fields' => array('title') )); $expected = array( array('Article' => array('title' => 'First Article'), 'User' => array('user' => 'mariano', 'id' => 1)), array('Article' => array('title' => 'Second Article'), 'User' => array('user' => 'larry', 'id' => 3)), array('Article' => array('title' => 'Third Article'), 'User' => array('user' => 'mariano', 'id' => 1)), ); $this->assertEqual($result, $expected); $result = $this->Article->find('all', array( 'contain' => array('User(id, user)'), 'fields' => array('title') )); $expected = array( array('Article' => array('title' => 'First Article'), 'User' => array('user' => 'mariano', 'id' => 1)), array('Article' => array('title' => 'Second Article'), 'User' => array('user' => 'larry', 'id' => 3)), array('Article' => array('title' => 'Third Article'), 'User' => array('user' => 'mariano', 'id' => 1)), ); $this->assertEqual($result, $expected); $result = $this->Article->find('all', array( 'contain' => array( 'Comment(comment, published)' => 'Attachment(attachment)', 'User(user)' ), 'fields' => array('title') )); if (!empty($result)) { foreach($result as $i=>$article) { foreach($article['Comment'] as $j=>$comment) { $result[$i]['Comment'][$j] = array_diff_key($comment, array('id'=>true)); } } } $expected = array( array( 'Article' => array('title' => 'First Article', 'id' => 1), 'User' => array('user' => 'mariano', 'id' => 1), 'Comment' => array( array('comment' => 'First Comment for First Article', 'published' => 'Y', 'article_id' => 1, 'Attachment' => array()), array('comment' => 'Second Comment for First Article', 'published' => 'Y', 'article_id' => 1, 'Attachment' => array()), array('comment' => 'Third Comment for First Article', 'published' => 'Y', 'article_id' => 1, 'Attachment' => array()), array('comment' => 'Fourth Comment for First Article', 'published' => 'N', 'article_id' => 1, 'Attachment' => array()), ) ), array( 'Article' => array('title' => 'Second Article', 'id' => 2), 'User' => array('user' => 'larry', 'id' => 3), 'Comment' => array( array('comment' => 'First Comment for Second Article', 'published' => 'Y', 'article_id' => 2, 'Attachment' => array( 'attachment' => 'attachment.zip', 'id' => 1 )), array('comment' => 'Second Comment for Second Article', 'published' => 'Y', 'article_id' => 2, 'Attachment' => array()) ) ), array( 'Article' => array('title' => 'Third Article', 'id' => 3), 'User' => array('user' => 'mariano', 'id' => 1), 'Comment' => array() ), ); $this->assertEqual($result, $expected); }
testEmbeddedFindFields method @access public @return void
testEmbeddedFindFields
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testHasOneFieldsInContain() { $this->Article->unbindModel(array( 'hasMany' => array('Comment') ), true); unset($this->Article->Comment); $this->Article->bindModel(array( 'hasOne' => array('Comment') )); $result = $this->Article->find('all', array( 'fields' => array('title', 'body'), 'contain' => array( 'Comment' => array( 'fields' => array('comment') ), 'User' => array( 'fields' => array('user') ) ) )); $this->assertTrue(isset($result[0]['Article']['title']), 'title missing %s'); $this->assertTrue(isset($result[0]['Article']['body']), 'body missing %s'); $this->assertTrue(isset($result[0]['Comment']['comment']), 'comment missing %s'); $this->assertTrue(isset($result[0]['User']['user']), 'body missing %s'); $this->assertFalse(isset($result[0]['Comment']['published']), 'published found %s'); $this->assertFalse(isset($result[0]['User']['password']), 'password found %s'); }
test that hasOne and belongsTo fields act the same in a contain array. @return void
testHasOneFieldsInContain
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testFindConditionalBinding() { $this->Article->contain(array( 'User(user)', 'Tag' => array( 'fields' => array('tag', 'created'), 'conditions' => array('created >=' => '2007-03-18 12:24') ) )); $result = $this->Article->find('all', array('fields' => array('title'))); $expected = array( array( 'Article' => array('id' => 1, 'title' => 'First Article'), 'User' => array('id' => 1, 'user' => 'mariano'), 'Tag' => array(array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23')) ), array( 'Article' => array('id' => 2, 'title' => 'Second Article'), 'User' => array('id' => 3, 'user' => 'larry'), 'Tag' => array(array('tag' => 'tag3', 'created' => '2007-03-18 12:26:23')) ), array( 'Article' => array('id' => 3, 'title' => 'Third Article'), 'User' => array('id' => 1, 'user' => 'mariano'), 'Tag' => array() ) ); $this->assertEqual($result, $expected); $this->Article->contain(array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created')))); $result = $this->Article->find('all', array('fields' => array('title'))); $expected = array( array( 'Article' => array('id' => 1, 'title' => 'First Article'), 'User' => array('id' => 1, 'user' => 'mariano'), 'Tag' => array( array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'), array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23') ) ), array( 'Article' => array('id' => 2, 'title' => 'Second Article'), 'User' => array('id' => 3, 'user' => 'larry'), 'Tag' => array( array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'), array('tag' => 'tag3', 'created' => '2007-03-18 12:26:23') ) ), array( 'Article' => array('id' => 3, 'title' => 'Third Article'), 'User' => array('id' => 1, 'user' => 'mariano'), 'Tag' => array() ) ); $this->assertEqual($result, $expected); $result = $this->Article->find('all', array( 'fields' => array('title'), 'contain' => array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created'))) )); $expected = array( array( 'Article' => array('id' => 1, 'title' => 'First Article'), 'User' => array('id' => 1, 'user' => 'mariano'), 'Tag' => array( array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'), array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23') ) ), array( 'Article' => array('id' => 2, 'title' => 'Second Article'), 'User' => array('id' => 3, 'user' => 'larry'), 'Tag' => array( array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'), array('tag' => 'tag3', 'created' => '2007-03-18 12:26:23') ) ), array( 'Article' => array('id' => 3, 'title' => 'Third Article'), 'User' => array('id' => 1, 'user' => 'mariano'), 'Tag' => array() ) ); $this->assertEqual($result, $expected); $this->Article->contain(array( 'User(id,user)', 'Tag' => array( 'fields' => array('tag', 'created'), 'conditions' => array('created >=' => '2007-03-18 12:24') ) )); $result = $this->Article->find('all', array('fields' => array('title'))); $expected = array( array( 'Article' => array('id' => 1, 'title' => 'First Article'), 'User' => array('id' => 1, 'user' => 'mariano'), 'Tag' => array(array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23')) ), array( 'Article' => array('id' => 2, 'title' => 'Second Article'), 'User' => array('id' => 3, 'user' => 'larry'), 'Tag' => array(array('tag' => 'tag3', 'created' => '2007-03-18 12:26:23')) ), array( 'Article' => array('id' => 3, 'title' => 'Third Article'), 'User' => array('id' => 1, 'user' => 'mariano'), 'Tag' => array() ) ); $this->assertEqual($result, $expected); $this->assertTrue(empty($this->User->Article->hasAndBelongsToMany['Tag']['conditions'])); $result = $this->User->find('all', array('contain' => array( 'Article.Tag' => array('conditions' => array('created >=' => '2007-03-18 12:24')) ))); $this->assertTrue(Set::matches('/User[id=1]', $result)); $this->assertFalse(Set::matches('/Article[id=1]/Tag[id=1]', $result)); $this->assertTrue(Set::matches('/Article[id=1]/Tag[id=2]', $result)); $this->assertTrue(empty($this->User->Article->hasAndBelongsToMany['Tag']['conditions'])); $this->assertTrue(empty($this->User->Article->hasAndBelongsToMany['Tag']['order'])); $result = $this->User->find('all', array('contain' => array( 'Article.Tag' => array('order' => 'created DESC') ))); $this->assertTrue(Set::matches('/User[id=1]', $result)); $this->assertTrue(Set::matches('/Article[id=1]/Tag[id=1]', $result)); $this->assertTrue(Set::matches('/Article[id=1]/Tag[id=2]', $result)); $this->assertTrue(empty($this->User->Article->hasAndBelongsToMany['Tag']['order'])); }
testFindConditionalBinding method @access public @return void
testFindConditionalBinding
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testOtherFinds() { $result = $this->Article->find('count'); $expected = 3; $this->assertEqual($result, $expected); $result = $this->Article->find('count', array('conditions' => array('Article.id >' => '1'))); $expected = 2; $this->assertEqual($result, $expected); $result = $this->Article->find('count', array('contain' => array())); $expected = 3; $this->assertEqual($result, $expected); $this->Article->contain(array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created'), 'conditions' => array('created >=' => '2007-03-18 12:24')))); $result = $this->Article->find('first', array('fields' => array('title'))); $expected = array( 'Article' => array('id' => 1, 'title' => 'First Article'), 'User' => array('id' => 1, 'user' => 'mariano'), 'Tag' => array(array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23')) ); $this->assertEqual($result, $expected); $this->Article->contain(array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created')))); $result = $this->Article->find('first', array('fields' => array('title'))); $expected = array( 'Article' => array('id' => 1, 'title' => 'First Article'), 'User' => array('id' => 1, 'user' => 'mariano'), 'Tag' => array( array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'), array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23') ) ); $this->assertEqual($result, $expected); $result = $this->Article->find('first', array( 'fields' => array('title'), 'order' => 'Article.id DESC', 'contain' => array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created'))) )); $expected = array( 'Article' => array('id' => 3, 'title' => 'Third Article'), 'User' => array('id' => 1, 'user' => 'mariano'), 'Tag' => array() ); $this->assertEqual($result, $expected); $result = $this->Article->find('list', array( 'contain' => array('User(id,user)'), 'fields' => array('Article.id', 'Article.title') )); $expected = array( 1 => 'First Article', 2 => 'Second Article', 3 => 'Third Article' ); $this->assertEqual($result, $expected); }
testOtherFinds method @access public @return void
testOtherFinds
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testPaginate() { $Controller =& new Controller(); $Controller->uses = array('Article'); $Controller->passedArgs[] = '1'; $Controller->params['url'] = array(); $Controller->constructClasses(); $Controller->paginate = array('Article' => array('fields' => array('title'), 'contain' => array('User(user)'))); $result = $Controller->paginate('Article'); $expected = array( array('Article' => array('title' => 'First Article'), 'User' => array('user' => 'mariano', 'id' => 1)), array('Article' => array('title' => 'Second Article'), 'User' => array('user' => 'larry', 'id' => 3)), array('Article' => array('title' => 'Third Article'), 'User' => array('user' => 'mariano', 'id' => 1)), ); $this->assertEqual($result, $expected); $r = $Controller->Article->find('all'); $this->assertTrue(Set::matches('/Article[id=1]', $r)); $this->assertTrue(Set::matches('/User[id=1]', $r)); $this->assertTrue(Set::matches('/Tag[id=1]', $r)); $Controller->paginate = array('Article' => array('contain' => array('Comment(comment)' => 'User(user)'), 'fields' => array('title'))); $result = $Controller->paginate('Article'); $expected = array( array( 'Article' => array('title' => 'First Article', 'id' => 1), 'Comment' => array( array( 'comment' => 'First Comment for First Article', 'user_id' => 2, 'article_id' => 1, 'User' => array('user' => 'nate') ), array( 'comment' => 'Second Comment for First Article', 'user_id' => 4, 'article_id' => 1, 'User' => array('user' => 'garrett') ), array( 'comment' => 'Third Comment for First Article', 'user_id' => 1, 'article_id' => 1, 'User' => array('user' => 'mariano') ), array( 'comment' => 'Fourth Comment for First Article', 'user_id' => 1, 'article_id' => 1, 'User' => array('user' => 'mariano') ) ) ), array( 'Article' => array('title' => 'Second Article', 'id' => 2), 'Comment' => array( array( 'comment' => 'First Comment for Second Article', 'user_id' => 1, 'article_id' => 2, 'User' => array('user' => 'mariano') ), array( 'comment' => 'Second Comment for Second Article', 'user_id' => 2, 'article_id' => 2, 'User' => array('user' => 'nate') ) ) ), array( 'Article' => array('title' => 'Third Article', 'id' => 3), 'Comment' => array() ), ); $this->assertEqual($result, $expected); $r = $Controller->Article->find('all'); $this->assertTrue(Set::matches('/Article[id=1]', $r)); $this->assertTrue(Set::matches('/User[id=1]', $r)); $this->assertTrue(Set::matches('/Tag[id=1]', $r)); $Controller->Article->unbindModel(array('hasMany' => array('Comment'), 'belongsTo' => array('User'), 'hasAndBelongsToMany' => array('Tag')), false); $Controller->Article->bindModel(array('hasMany' => array('Comment'), 'belongsTo' => array('User')), false); $Controller->paginate = array('Article' => array('contain' => array('Comment(comment)', 'User(user)'), 'fields' => array('title'))); $r = $Controller->paginate('Article'); $this->assertTrue(Set::matches('/Article[id=1]', $r)); $this->assertTrue(Set::matches('/User[id=1]', $r)); $this->assertTrue(Set::matches('/Comment[article_id=1]', $r)); $this->assertFalse(Set::matches('/Comment[id=1]', $r)); $r = $this->Article->find('all'); $this->assertTrue(Set::matches('/Article[id=1]', $r)); $this->assertTrue(Set::matches('/User[id=1]', $r)); $this->assertTrue(Set::matches('/Comment[article_id=1]', $r)); $this->assertTrue(Set::matches('/Comment[id=1]', $r)); }
testPaginate method @access public @return void
testPaginate
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testOriginalAssociations() { $this->Article->Comment->Behaviors->attach('Containable'); $options = array( 'conditions' => array( 'Comment.published' => 'Y', ), 'contain' => 'User', 'recursive' => 1 ); $firstResult = $this->Article->Comment->find('all', $options); $dummyResult = $this->Article->Comment->find('all', array( 'conditions' => array( 'User.user' => 'mariano' ), 'fields' => array('User.password'), 'contain' => array('User.password'), )); $result = $this->Article->Comment->find('all', $options); $this->assertEqual($result, $firstResult); $this->Article->unbindModel(array('hasMany' => array('Comment'), 'belongsTo' => array('User'), 'hasAndBelongsToMany' => array('Tag')), false); $this->Article->bindModel(array('hasMany' => array('Comment'), 'belongsTo' => array('User')), false); $r = $this->Article->find('all', array('contain' => array('Comment(comment)', 'User(user)'), 'fields' => array('title'))); $this->assertTrue(Set::matches('/Article[id=1]', $r)); $this->assertTrue(Set::matches('/User[id=1]', $r)); $this->assertTrue(Set::matches('/Comment[article_id=1]', $r)); $this->assertFalse(Set::matches('/Comment[id=1]', $r)); $r = $this->Article->find('all'); $this->assertTrue(Set::matches('/Article[id=1]', $r)); $this->assertTrue(Set::matches('/User[id=1]', $r)); $this->assertTrue(Set::matches('/Comment[article_id=1]', $r)); $this->assertTrue(Set::matches('/Comment[id=1]', $r)); $this->Article->bindModel(array('hasAndBelongsToMany' => array('Tag')), false); $this->Article->contain(false, array('User(id,user)', 'Comment' => array('fields' => array('comment'), 'conditions' => array('created >=' => '2007-03-18 10:49')))); $result = $this->Article->find('all', array('fields' => array('title'), 'limit' => 1, 'page' => 1, 'order' => 'Article.id ASC')); $expected = array(array( 'Article' => array('id' => 1, 'title' => 'First Article'), 'User' => array('id' => 1, 'user' => 'mariano'), 'Comment' => array( array('comment' => 'Third Comment for First Article', 'article_id' => 1), array('comment' => 'Fourth Comment for First Article', 'article_id' => 1) ) )); $this->assertEqual($result, $expected); $result = $this->Article->find('all', array('fields' => array('title', 'User.id', 'User.user'), 'limit' => 1, 'page' => 2, 'order' => 'Article.id ASC')); $expected = array(array( 'Article' => array('id' => 2, 'title' => 'Second Article'), 'User' => array('id' => 3, 'user' => 'larry'), 'Comment' => array( array('comment' => 'First Comment for Second Article', 'article_id' => 2), array('comment' => 'Second Comment for Second Article', 'article_id' => 2) ) )); $this->assertEqual($result, $expected); $result = $this->Article->find('all', array('fields' => array('title', 'User.id', 'User.user'), 'limit' => 1, 'page' => 3, 'order' => 'Article.id ASC')); $expected = array(array( 'Article' => array('id' => 3, 'title' => 'Third Article'), 'User' => array('id' => 1, 'user' => 'mariano'), 'Comment' => array() )); $this->assertEqual($result, $expected); $this->Article->contain(false, array('User' => array('fields' => 'user'), 'Comment')); $result = $this->Article->find('all'); $this->assertTrue(Set::matches('/Article[id=1]', $result)); $this->assertTrue(Set::matches('/User[user=mariano]', $result)); $this->assertTrue(Set::matches('/Comment[article_id=1]', $result)); $this->Article->resetBindings(); $this->Article->contain(false, array('User' => array('fields' => array('user')), 'Comment')); $result = $this->Article->find('all'); $this->assertTrue(Set::matches('/Article[id=1]', $result)); $this->assertTrue(Set::matches('/User[user=mariano]', $result)); $this->assertTrue(Set::matches('/Comment[article_id=1]', $result)); $this->Article->resetBindings(); }
testOriginalAssociations method @access public @return void
testOriginalAssociations
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testBindMultipleTimesWithFind() { $binding = array( 'hasOne' => array( 'ArticlesTag' => array( 'foreignKey' => false, 'type' => 'INNER', 'conditions' => array( 'ArticlesTag.article_id = Article.id' ) ), 'Tag' => array( 'type' => 'INNER', 'foreignKey' => false, 'conditions' => array( 'ArticlesTag.tag_id = Tag.id' ) ) ) ); $this->Article->unbindModel(array('hasAndBelongsToMany' => array('Tag'))); $this->Article->bindModel($binding); $result = $this->Article->find('all', array('limit' => 1, 'contain' => array('ArticlesTag', 'Tag'))); $this->Article->unbindModel(array('hasAndBelongsToMany' => array('Tag'))); $this->Article->bindModel($binding); $result = $this->Article->find('all', array('limit' => 1, 'contain' => array('ArticlesTag', 'Tag'))); $associated = $this->Article->getAssociated(); $this->assertEqual('hasAndBelongsToMany', $associated['Tag']); $this->assertFalse(isset($associated['ArticleTag'])); }
test that bindModel and unbindModel work with find() calls in between.
testBindMultipleTimesWithFind
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testAutoFieldsWithMultipleDatabases() { $config = new DATABASE_CONFIG(); $skip = $this->skipIf( !isset($config->test) || !isset($config->test2), '%s Primary and secondary test databases not configured, skipping cross-database ' .'join tests.' .' To run these tests, you must define $test and $test2 in your database configuration.' ); if ($skip) { return; } $db =& ConnectionManager::getDataSource('test2'); $this->_fixtures[$this->_fixtureClassMap['User']]->create($db); $this->_fixtures[$this->_fixtureClassMap['User']]->insert($db); $this->Article->User->setDataSource('test2'); $result = $this->Article->find('all', array( 'fields' => array('Article.title'), 'contain' => array('User') )); $this->assertTrue(isset($result[0]['Article'])); $this->assertTrue(isset($result[0]['User'])); $this->_fixtures[$this->_fixtureClassMap['User']]->drop($db); }
test that autoFields doesn't splice in fields from other databases. @return void
testAutoFieldsWithMultipleDatabases
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testAutoFieldsWithRecursiveNegativeOne() { $this->Article->recursive = -1; $result = $this->Article->field('title', array('Article.title' => 'First Article')); $this->assertNoErrors(); $this->assertEqual($result, 'First Article', 'Field is wrong'); }
test that autoFields doesn't splice in columns that aren't part of the join. @return void
testAutoFieldsWithRecursiveNegativeOne
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testFindAllReturn() { $result = $this->Article->find('all', array( 'conditions' => array('Article.id' => 999999999) )); $this->assertEqual($result, array(), 'Should be empty.'); }
test that find(all) doesn't return incorrect values when mixed with containable. @return void
testFindAllReturn
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function __containments(&$Model, $contain = array()) { if (!is_array($Model)) { $result = $Model->containments($contain); return $this->__containments($result['models']); } else { $result = $Model; foreach($result as $i => $containment) { $result[$i] = array_diff_key($containment, array('instance' => true)); } } return $result; }
containments method @param mixed $Model @param array $contain @access private @return void
__containments
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function __assertBindings(&$Model, $expected = array()) { $expected = array_merge(array('belongsTo' => array(), 'hasOne' => array(), 'hasMany' => array(), 'hasAndBelongsToMany' => array()), $expected); foreach($expected as $binding => $expect) { $this->assertEqual(array_keys($Model->$binding), $expect); } }
assertBindings method @param mixed $Model @param array $expected @access private @return void
__assertBindings
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function __bindings(&$Model, $extra = array(), $output = true) { $relationTypes = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'); $debug = '['; $lines = array(); foreach($relationTypes as $binding) { if (!empty($Model->$binding)) { $models = array_keys($Model->$binding); foreach($models as $linkedModel) { $line = $linkedModel; if (!empty($extra) && !empty($Model->{$binding}[$linkedModel])) { $extraData = array(); foreach(array_intersect_key($Model->{$binding}[$linkedModel], array_flip($extra)) as $key => $value) { $extraData[] = $key . ': ' . (is_array($value) ? '(' . implode(', ', $value) . ')' : $value); } $line .= ' {' . implode(' - ', $extraData) . '}'; } $lines[] = $line; } } } $debug .= implode(' | ' , $lines); $debug .= ']'; $debug = '<strong>' . $Model->alias . '</strong>: ' . $debug . '<br />'; if ($output) { echo $debug; } return $debug; }
bindings method @param mixed $Model @param array $extra @param bool $output @access private @return void
__bindings
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/containable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/containable.test.php
MIT
function testCountWithConditions() { $this->loadFixtures('Translate', 'TranslatedItem'); $Model =& new TranslatedItem(); $Model->locale = 'eng'; $result = $Model->find('count', array( 'conditions' => array( 'I18n__content.locale' => 'eng' ) )); $this->assertEqual(3, $result); }
Test that count queries with conditions get the correct joins @return void
testCountWithConditions
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
function testTranslateModel() { $TestModel =& new Tag(); $TestModel->translateTable = 'another_i18n'; $TestModel->Behaviors->attach('Translate', array('title')); $translateModel =& $TestModel->Behaviors->Translate->translateModel($TestModel); $this->assertEqual($translateModel->name, 'I18nModel'); $this->assertEqual($translateModel->useTable, 'another_i18n'); $TestModel =& new User(); $TestModel->Behaviors->attach('Translate', array('title')); $translateModel =& $TestModel->Behaviors->Translate->translateModel($TestModel); $this->assertEqual($translateModel->name, 'I18nModel'); $this->assertEqual($translateModel->useTable, 'i18n'); $TestModel =& new TranslatedArticle(); $translateModel =& $TestModel->Behaviors->Translate->translateModel($TestModel); $this->assertEqual($translateModel->name, 'TranslateArticleModel'); $this->assertEqual($translateModel->useTable, 'article_i18n'); $TestModel =& new TranslatedItem(); $translateModel =& $TestModel->Behaviors->Translate->translateModel($TestModel); $this->assertEqual($translateModel->name, 'TranslateTestModel'); $this->assertEqual($translateModel->useTable, 'i18n'); }
testTranslateModel method @access public @return void
testTranslateModel
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
function testLocaleFalsePlain() { $this->loadFixtures('Translate', 'TranslatedItem'); $TestModel =& new TranslatedItem(); $TestModel->locale = false; $result = $TestModel->read(null, 1); $expected = array('TranslatedItem' => array( 'id' => 1, 'slug' => 'first_translated', 'translated_article_id' => 1, )); $this->assertEqual($expected, $result); $result = $TestModel->find('all', array('fields' => array('slug'))); $expected = array( array('TranslatedItem' => array('slug' => 'first_translated')), array('TranslatedItem' => array('slug' => 'second_translated')), array('TranslatedItem' => array('slug' => 'third_translated')) ); $this->assertEqual($result, $expected); }
testLocaleFalsePlain method @access public @return void
testLocaleFalsePlain
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
function testLocaleFalseAssociations() { $this->loadFixtures('Translate', 'TranslatedItem'); $TestModel =& new TranslatedItem(); $TestModel->locale = false; $TestModel->unbindTranslation(); $translations = array('title' => 'Title', 'content' => 'Content'); $TestModel->bindTranslation($translations, false); $result = $TestModel->read(null, 1); $expected = array( 'TranslatedItem' => array('id' => 1, 'slug' => 'first_translated', 'translated_article_id' => 1), 'Title' => array( array('id' => 1, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Title #1'), array('id' => 3, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titel #1'), array('id' => 5, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titulek #1') ), 'Content' => array( array('id' => 2, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Content #1'), array('id' => 4, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Inhalt #1'), array('id' => 6, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Obsah #1') ) ); $this->assertEqual($result, $expected); $TestModel->hasMany['Title']['fields'] = $TestModel->hasMany['Content']['fields'] = array('content'); $TestModel->hasMany['Title']['conditions']['locale'] = $TestModel->hasMany['Content']['conditions']['locale'] = 'eng'; $result = $TestModel->find('all', array('fields' => array('TranslatedItem.slug'))); $expected = array( array( 'TranslatedItem' => array('id' => 1, 'slug' => 'first_translated'), 'Title' => array(array('foreign_key' => 1, 'content' => 'Title #1')), 'Content' => array(array('foreign_key' => 1, 'content' => 'Content #1')) ), array( 'TranslatedItem' => array('id' => 2, 'slug' => 'second_translated'), 'Title' => array(array('foreign_key' => 2, 'content' => 'Title #2')), 'Content' => array(array('foreign_key' => 2, 'content' => 'Content #2')) ), array( 'TranslatedItem' => array('id' => 3, 'slug' => 'third_translated'), 'Title' => array(array('foreign_key' => 3, 'content' => 'Title #3')), 'Content' => array(array('foreign_key' => 3, 'content' => 'Content #3')) ) ); $this->assertEqual($result, $expected); }
testLocaleFalseAssociations method @access public @return void
testLocaleFalseAssociations
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
function testLocaleSingle() { $this->loadFixtures('Translate', 'TranslatedItem'); $TestModel =& new TranslatedItem(); $TestModel->locale = 'eng'; $result = $TestModel->read(null, 1); $expected = array( 'TranslatedItem' => array( 'id' => 1, 'slug' => 'first_translated', 'locale' => 'eng', 'title' => 'Title #1', 'content' => 'Content #1', 'translated_article_id' => 1, ) ); $this->assertEqual($result, $expected); $result = $TestModel->find('all'); $expected = array( array( 'TranslatedItem' => array( 'id' => 1, 'slug' => 'first_translated', 'locale' => 'eng', 'title' => 'Title #1', 'content' => 'Content #1', 'translated_article_id' => 1, ) ), array( 'TranslatedItem' => array( 'id' => 2, 'slug' => 'second_translated', 'locale' => 'eng', 'title' => 'Title #2', 'content' => 'Content #2', 'translated_article_id' => 1, ) ), array( 'TranslatedItem' => array( 'id' => 3, 'slug' => 'third_translated', 'locale' => 'eng', 'title' => 'Title #3', 'content' => 'Content #3', 'translated_article_id' => 1, ) ) ); $this->assertEqual($result, $expected); }
testLocaleSingle method @access public @return void
testLocaleSingle
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
function testLocaleSingleWithConditions() { $this->loadFixtures('Translate', 'TranslatedItem'); $TestModel =& new TranslatedItem(); $TestModel->locale = 'eng'; $result = $TestModel->find('all', array('conditions' => array('slug' => 'first_translated'))); $expected = array( array( 'TranslatedItem' => array( 'id' => 1, 'slug' => 'first_translated', 'locale' => 'eng', 'title' => 'Title #1', 'content' => 'Content #1', 'translated_article_id' => 1, ) ) ); $this->assertEqual($result, $expected); $result = $TestModel->find('all', array('conditions' => "TranslatedItem.slug = 'first_translated'")); $expected = array( array( 'TranslatedItem' => array( 'id' => 1, 'slug' => 'first_translated', 'locale' => 'eng', 'title' => 'Title #1', 'content' => 'Content #1', 'translated_article_id' => 1, ) ) ); $this->assertEqual($result, $expected); }
testLocaleSingleWithConditions method @access public @return void
testLocaleSingleWithConditions
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
function testLocaleSingleAssociations() { $this->loadFixtures('Translate', 'TranslatedItem'); $TestModel =& new TranslatedItem(); $TestModel->locale = 'eng'; $TestModel->unbindTranslation(); $translations = array('title' => 'Title', 'content' => 'Content'); $TestModel->bindTranslation($translations, false); $result = $TestModel->read(null, 1); $expected = array( 'TranslatedItem' => array( 'id' => 1, 'slug' => 'first_translated', 'locale' => 'eng', 'title' => 'Title #1', 'content' => 'Content #1', 'translated_article_id' => 1, ), 'Title' => array( array('id' => 1, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Title #1'), array('id' => 3, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titel #1'), array('id' => 5, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titulek #1') ), 'Content' => array( array('id' => 2, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Content #1'), array('id' => 4, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Inhalt #1'), array('id' => 6, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Obsah #1') ) ); $this->assertEqual($result, $expected); $TestModel->hasMany['Title']['fields'] = $TestModel->hasMany['Content']['fields'] = array('content'); $TestModel->hasMany['Title']['conditions']['locale'] = $TestModel->hasMany['Content']['conditions']['locale'] = 'eng'; $result = $TestModel->find('all', array('fields' => array('TranslatedItem.title'))); $expected = array( array( 'TranslatedItem' => array( 'id' => 1, 'locale' => 'eng', 'title' => 'Title #1', ), 'Title' => array(array('foreign_key' => 1, 'content' => 'Title #1')), 'Content' => array(array('foreign_key' => 1, 'content' => 'Content #1')) ), array( 'TranslatedItem' => array( 'id' => 2, 'locale' => 'eng', 'title' => 'Title #2', ), 'Title' => array(array('foreign_key' => 2, 'content' => 'Title #2')), 'Content' => array(array('foreign_key' => 2, 'content' => 'Content #2')) ), array( 'TranslatedItem' => array( 'id' => 3, 'locale' => 'eng', 'title' => 'Title #3', ), 'Title' => array(array('foreign_key' => 3, 'content' => 'Title #3')), 'Content' => array(array('foreign_key' => 3, 'content' => 'Content #3')) ) ); $this->assertEqual($result, $expected); }
testLocaleSingleAssociations method @access public @return void
testLocaleSingleAssociations
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
function testLocaleMultiple() { $this->loadFixtures('Translate', 'TranslatedItem'); $TestModel =& new TranslatedItem(); $TestModel->locale = array('deu', 'eng', 'cze'); $delete = array( array('locale' => 'deu'), array('foreign_key' => 1, 'field' => 'title', 'locale' => 'eng'), array('foreign_key' => 1, 'field' => 'content', 'locale' => 'cze'), array('foreign_key' => 2, 'field' => 'title', 'locale' => 'cze'), array('foreign_key' => 2, 'field' => 'content', 'locale' => 'eng'), array('foreign_key' => 3, 'field' => 'title') ); $I18nModel =& ClassRegistry::getObject('TranslateTestModel'); $I18nModel->deleteAll(array('or' => $delete)); $result = $TestModel->read(null, 1); $expected = array( 'TranslatedItem' => array( 'id' => 1, 'translated_article_id' => 1, 'slug' => 'first_translated', 'locale' => 'deu', 'title' => 'Titulek #1', 'content' => 'Content #1', ) ); $this->assertEqual($result, $expected); $result = $TestModel->find('all', array('fields' => array('slug', 'title', 'content'))); $expected = array( array( 'TranslatedItem' => array( 'slug' => 'first_translated', 'locale' => 'deu', 'content' => 'Content #1', 'title' => 'Titulek #1', ) ), array( 'TranslatedItem' => array( 'slug' => 'second_translated', 'locale' => 'deu', 'title' => 'Title #2', 'content' => 'Obsah #2', ) ), array( 'TranslatedItem' => array( 'slug' => 'third_translated', 'locale' => 'deu', 'title' => '', 'content' => 'Content #3', ) ) ); $this->assertEqual($result, $expected); }
testLocaleMultiple method @access public @return void
testLocaleMultiple
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
function testMissingTranslation() { $this->loadFixtures('Translate', 'TranslatedItem'); $TestModel =& new TranslatedItem(); $TestModel->locale = 'rus'; $result = $TestModel->read(null, 1); $this->assertFalse($result); $TestModel->locale = array('rus'); $result = $TestModel->read(null, 1); $expected = array( 'TranslatedItem' => array( 'id' => 1, 'slug' => 'first_translated', 'locale' => 'rus', 'title' => '', 'content' => '', 'translated_article_id' => 1, ) ); $this->assertEqual($result, $expected); }
testMissingTranslation method @access public @return void
testMissingTranslation
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
function testTranslatedFindList() { $this->loadFixtures('Translate', 'TranslatedItem'); $TestModel =& new TranslatedItem(); $TestModel->locale = 'deu'; $TestModel->displayField = 'title'; $result = $TestModel->find('list', array('recursive' => 1)); $expected = array(1 => 'Titel #1', 2 => 'Titel #2', 3 => 'Titel #3'); $this->assertEqual($result, $expected); // MSSQL trigger an error and stops the page even if the debug = 0 if ($this->db->config['driver'] != 'mssql') { $debug = Configure::read('debug'); Configure::write('debug', 0); $result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => false)); $this->assertEqual($result, array()); $result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => 'after')); $this->assertEqual($result, array()); Configure::write('debug', $debug); } $result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => 'before')); $expected = array(1 => null, 2 => null, 3 => null); $this->assertEqual($result, $expected); }
testTranslatedFindList method @access public @return void
testTranslatedFindList
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
function testReadSelectedFields() { $this->loadFixtures('Translate', 'TranslatedItem'); $TestModel =& new TranslatedItem(); $TestModel->locale = 'eng'; $result = $TestModel->find('all', array('fields' => array('slug', 'TranslatedItem.content'))); $expected = array( array('TranslatedItem' => array('slug' => 'first_translated', 'locale' => 'eng', 'content' => 'Content #1')), array('TranslatedItem' => array('slug' => 'second_translated', 'locale' => 'eng', 'content' => 'Content #2')), array('TranslatedItem' => array('slug' => 'third_translated', 'locale' => 'eng', 'content' => 'Content #3')) ); $this->assertEqual($result, $expected); $result = $TestModel->find('all', array('fields' => array('TranslatedItem.slug', 'content'))); $this->assertEqual($result, $expected); $TestModel->locale = array('eng', 'deu', 'cze'); $delete = array(array('locale' => 'deu'), array('field' => 'content', 'locale' => 'eng')); $I18nModel =& ClassRegistry::getObject('TranslateTestModel'); $I18nModel->deleteAll(array('or' => $delete)); $result = $TestModel->find('all', array('fields' => array('title', 'content'))); $expected = array( array('TranslatedItem' => array('locale' => 'eng', 'title' => 'Title #1', 'content' => 'Obsah #1')), array('TranslatedItem' => array('locale' => 'eng', 'title' => 'Title #2', 'content' => 'Obsah #2')), array('TranslatedItem' => array('locale' => 'eng', 'title' => 'Title #3', 'content' => 'Obsah #3')) ); $this->assertEqual($result, $expected); }
testReadSelectedFields method @access public @return void
testReadSelectedFields
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
function testSaveCreate() { $this->loadFixtures('Translate', 'TranslatedItem'); $TestModel =& new TranslatedItem(); $TestModel->locale = 'spa'; $data = array( 'slug' => 'fourth_translated', 'title' => 'Leyenda #4', 'content' => 'Contenido #4', 'translated_article_id' => null ); $TestModel->create($data); $TestModel->save(); $result = $TestModel->read(); $expected = array('TranslatedItem' => array_merge($data, array('id' => $TestModel->id, 'locale' => 'spa'))); $this->assertEqual($result, $expected); }
testSaveCreate method @access public @return void
testSaveCreate
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
function testSaveUpdate() { $this->loadFixtures('Translate', 'TranslatedItem'); $TestModel =& new TranslatedItem(); $TestModel->locale = 'spa'; $oldData = array('slug' => 'fourth_translated', 'title' => 'Leyenda #4', 'translated_article_id' => 1); $TestModel->create($oldData); $TestModel->save(); $id = $TestModel->id; $newData = array('id' => $id, 'content' => 'Contenido #4'); $TestModel->create($newData); $TestModel->save(); $result = $TestModel->read(null, $id); $expected = array('TranslatedItem' => array_merge($oldData, $newData, array('locale' => 'spa'))); $this->assertEqual($result, $expected); }
testSaveUpdate method @access public @return void
testSaveUpdate
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
function testMultipleCreate() { $this->loadFixtures('Translate', 'TranslatedItem'); $TestModel =& new TranslatedItem(); $TestModel->locale = 'deu'; $data = array( 'slug' => 'new_translated', 'title' => array('eng' => 'New title', 'spa' => 'Nuevo leyenda'), 'content' => array('eng' => 'New content', 'spa' => 'Nuevo contenido') ); $TestModel->create($data); $TestModel->save(); $TestModel->unbindTranslation(); $translations = array('title' => 'Title', 'content' => 'Content'); $TestModel->bindTranslation($translations, false); $TestModel->locale = array('eng', 'spa'); $result = $TestModel->read(); $expected = array( 'TranslatedItem' => array( 'id' => 4, 'slug' => 'new_translated', 'locale' => 'eng', 'title' => 'New title', 'content' => 'New content', 'translated_article_id' => null, ), 'Title' => array( array('id' => 21, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 4, 'field' => 'title', 'content' => 'New title'), array('id' => 22, 'locale' => 'spa', 'model' => 'TranslatedItem', 'foreign_key' => 4, 'field' => 'title', 'content' => 'Nuevo leyenda') ), 'Content' => array( array('id' => 19, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 4, 'field' => 'content', 'content' => 'New content'), array('id' => 20, 'locale' => 'spa', 'model' => 'TranslatedItem', 'foreign_key' => 4, 'field' => 'content', 'content' => 'Nuevo contenido') ) ); $this->assertEqual($result, $expected); }
testMultipleCreate method @access public @return void
testMultipleCreate
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
function testMultipleUpdate() { $this->loadFixtures('Translate', 'TranslatedItem'); $TestModel =& new TranslatedItem(); $TestModel->locale = 'eng'; $TestModel->validate['title'] = 'notEmpty'; $data = array('TranslatedItem' => array( 'id' => 1, 'title' => array('eng' => 'New Title #1', 'deu' => 'Neue Titel #1', 'cze' => 'Novy Titulek #1'), 'content' => array('eng' => 'New Content #1', 'deu' => 'Neue Inhalt #1', 'cze' => 'Novy Obsah #1') )); $TestModel->create(); $TestModel->save($data); $TestModel->unbindTranslation(); $translations = array('title' => 'Title', 'content' => 'Content'); $TestModel->bindTranslation($translations, false); $result = $TestModel->read(null, 1); $expected = array( 'TranslatedItem' => array( 'id' => '1', 'slug' => 'first_translated', 'locale' => 'eng', 'title' => 'New Title #1', 'content' => 'New Content #1', 'translated_article_id' => 1, ), 'Title' => array( array('id' => 1, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'New Title #1'), array('id' => 3, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Neue Titel #1'), array('id' => 5, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Novy Titulek #1') ), 'Content' => array( array('id' => 2, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'New Content #1'), array('id' => 4, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Neue Inhalt #1'), array('id' => 6, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Novy Obsah #1') ) ); $this->assertEqual($result, $expected); $TestModel->unbindTranslation($translations); $TestModel->bindTranslation(array('title', 'content'), false); }
testMultipleUpdate method @access public @return void
testMultipleUpdate
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
function testMixedCreateUpdateWithArrayLocale() { $this->loadFixtures('Translate', 'TranslatedItem'); $TestModel =& new TranslatedItem(); $TestModel->locale = array('cze', 'deu'); $data = array('TranslatedItem' => array( 'id' => 1, 'title' => array('eng' => 'Updated Title #1', 'spa' => 'Nuevo leyenda #1'), 'content' => 'Upraveny obsah #1' )); $TestModel->create(); $TestModel->save($data); $TestModel->unbindTranslation(); $translations = array('title' => 'Title', 'content' => 'Content'); $TestModel->bindTranslation($translations, false); $result = $TestModel->read(null, 1); $expected = array( 'TranslatedItem' => array( 'id' => 1, 'slug' => 'first_translated', 'locale' => 'cze', 'title' => 'Titulek #1', 'content' => 'Upraveny obsah #1', 'translated_article_id' => 1, ), 'Title' => array( array('id' => 1, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Updated Title #1'), array('id' => 3, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titel #1'), array('id' => 5, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titulek #1'), array('id' => 19, 'locale' => 'spa', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Nuevo leyenda #1') ), 'Content' => array( array('id' => 2, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Content #1'), array('id' => 4, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Inhalt #1'), array('id' => 6, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Upraveny obsah #1') ) ); $this->assertEqual($result, $expected); }
testMixedCreateUpdateWithArrayLocale method @access public @return void
testMixedCreateUpdateWithArrayLocale
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
public function testSaveAllTranslatedAssociations() { $this->loadFixtures('Translate', 'TranslateArticle', 'TranslatedItem', 'TranslatedArticle', 'User'); $Model = new TranslatedArticle(); $Model->locale = 'eng'; $data = array( 'TranslatedArticle' => array( 'user_id' => 1, 'published' => 'Y', 'title' => 'Title (eng) #1', 'body' => 'Body (eng) #1' ), 'TranslatedItem' => array( array( 'title' => 'Nuevo leyenda #1', 'content' => 'Upraveny obsah #1' ), array( 'title' => 'New Title #2', 'content' => 'New Content #2' ), ) ); $result = $Model->saveAll($data); $this->assertTrue($result); $result = $Model->TranslatedItem->find('all', array( 'conditions' => array('translated_article_id' => $Model->id) )); $this->assertEqual(2, count($result)); $this->assertEqual($data['TranslatedItem'][0]['title'], $result[0]['TranslatedItem']['title']); $this->assertEqual($data['TranslatedItem'][1]['title'], $result[1]['TranslatedItem']['title']); }
Test that saveAll() works with hasMany associations that contain translations. @return void
testSaveAllTranslatedAssociations
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
function testValidation() { $this->loadFixtures('Translate', 'TranslatedItem'); $TestModel =& new TranslatedItem(); $TestModel->locale = 'eng'; $TestModel->validate['title'] = '/Only this title/'; $data = array( 'TranslatedItem' => array( 'id' => 1, 'title' => array('eng' => 'New Title #1', 'deu' => 'Neue Titel #1', 'cze' => 'Novy Titulek #1'), 'content' => array('eng' => 'New Content #1', 'deu' => 'Neue Inhalt #1', 'cze' => 'Novy Obsah #1') ) ); $TestModel->create(); $this->assertFalse($TestModel->save($data)); $this->assertEqual($TestModel->validationErrors['title'], 'This field cannot be left blank'); $TestModel->locale = 'eng'; $TestModel->validate['title'] = '/Only this title/'; $data = array('TranslatedItem' => array( 'id' => 1, 'title' => array('eng' => 'Only this title', 'deu' => 'Neue Titel #1', 'cze' => 'Novy Titulek #1'), 'content' => array('eng' => 'New Content #1', 'deu' => 'Neue Inhalt #1', 'cze' => 'Novy Obsah #1') )); $TestModel->create(); $this->assertTrue($TestModel->save($data)); }
testValidation method @access public @return void
testValidation
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
function testAttachDetach() { $this->loadFixtures('Translate', 'TranslatedItem'); $TestModel =& new TranslatedItem(); $Behavior =& $this->Model->Behaviors->Translate; $TestModel->unbindTranslation(); $translations = array('title' => 'Title', 'content' => 'Content'); $TestModel->bindTranslation($translations, false); $result = array_keys($TestModel->hasMany); $expected = array('Title', 'Content'); $this->assertEqual($result, $expected); $TestModel->Behaviors->detach('Translate'); $result = array_keys($TestModel->hasMany); $expected = array(); $this->assertEqual($result, $expected); $result = isset($TestModel->Behaviors->Translate); $this->assertFalse($result); $result = isset($Behavior->settings[$TestModel->alias]); $this->assertFalse($result); $result = isset($Behavior->runtime[$TestModel->alias]); $this->assertFalse($result); $TestModel->Behaviors->attach('Translate', array('title' => 'Title', 'content' => 'Content')); $result = array_keys($TestModel->hasMany); $expected = array('Title', 'Content'); $this->assertEqual($result, $expected); $result = isset($TestModel->Behaviors->Translate); $this->assertTrue($result); $Behavior = $TestModel->Behaviors->Translate; $result = isset($Behavior->settings[$TestModel->alias]); $this->assertTrue($result); $result = isset($Behavior->runtime[$TestModel->alias]); $this->assertTrue($result); }
testAttachDetach method @access public @return void
testAttachDetach
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
function testAnotherTranslateTable() { $this->loadFixtures('Translate', 'TranslatedItem', 'TranslateTable'); $TestModel =& new TranslatedItemWithTable(); $TestModel->locale = 'eng'; $result = $TestModel->read(null, 1); $expected = array( 'TranslatedItemWithTable' => array( 'id' => 1, 'slug' => 'first_translated', 'locale' => 'eng', 'title' => 'Another Title #1', 'content' => 'Another Content #1', 'translated_article_id' => 1, ) ); $this->assertEqual($result, $expected); }
testAnotherTranslateTable method @access public @return void
testAnotherTranslateTable
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
function testTranslateWithAssociations() { $this->loadFixtures('TranslateArticle', 'TranslatedArticle', 'TranslatedItem', 'User', 'Comment', 'ArticlesTag', 'Tag'); $TestModel =& new TranslatedArticle(); $TestModel->locale = 'eng'; $recursive = $TestModel->recursive; $result = $TestModel->read(null, 1); $expected = array( 'TranslatedArticle' => array( 'id' => 1, 'user_id' => 1, 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'locale' => 'eng', 'title' => 'Title (eng) #1', 'body' => 'Body (eng) #1' ), 'User' => array( 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ), 'TranslatedItem' => array( array( 'id' => 1, 'translated_article_id' => 1, 'slug' => 'first_translated' ), array( 'id' => 2, 'translated_article_id' => 1, 'slug' => 'second_translated' ), array( 'id' => 3, 'translated_article_id' => 1, 'slug' => 'third_translated' ), ) ); $this->assertEqual($result, $expected); $result = $TestModel->find('all', array('recursive' => -1)); $expected = array( array( 'TranslatedArticle' => array( 'id' => 1, 'user_id' => 1, 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'locale' => 'eng', 'title' => 'Title (eng) #1', 'body' => 'Body (eng) #1' ) ), array( 'TranslatedArticle' => array( 'id' => 2, 'user_id' => 3, 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', 'locale' => 'eng', 'title' => 'Title (eng) #2', 'body' => 'Body (eng) #2' ) ), array( 'TranslatedArticle' => array( 'id' => 3, 'user_id' => 1, 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', 'locale' => 'eng', 'title' => 'Title (eng) #3', 'body' => 'Body (eng) #3' ) ) ); $this->assertEqual($result, $expected); $this->assertEqual($TestModel->recursive, $recursive); $TestModel->recursive = -1; $result = $TestModel->read(null, 1); $expected = array( 'TranslatedArticle' => array( 'id' => 1, 'user_id' => 1, 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'locale' => 'eng', 'title' => 'Title (eng) #1', 'body' => 'Body (eng) #1' ) ); $this->assertEqual($result, $expected); }
testTranslateWithAssociations method @access public @return void
testTranslateWithAssociations
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
function testTranslateTableWithPrefix() { $this->loadFixtures('TranslateWithPrefix', 'TranslatedItem'); $TestModel =& new TranslatedItem2; $TestModel->locale = 'eng'; $result = $TestModel->read(null, 1); $expected = array('TranslatedItem' => array( 'id' => 1, 'slug' => 'first_translated', 'locale' => 'eng', 'content' => 'Content #1', 'title' => 'Title #1', 'translated_article_id' => 1, )); $this->assertEqual($result, $expected); }
testTranslateTableWithPrefix method Tests that is possible to have a translation model with a custom tablePrefix @access public @return void
testTranslateTableWithPrefix
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
function testUnbindTranslationInfinteLoop() { $this->loadFixtures('Translate', 'TranslatedItem'); $TestModel =& new TranslatedItem(); $TestModel->Behaviors->detach('Translate'); $TestModel->actsAs = array(); $TestModel->Behaviors->attach('Translate'); $TestModel->bindTranslation(array('title', 'content'), true); $result = $TestModel->unbindTranslation(); $this->assertFalse($result); }
Test infinite loops not occuring with unbindTranslation() @return void
testUnbindTranslationInfinteLoop
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/translate.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/translate.test.php
MIT
function testInitialize() { extract($this->settings); $this->Tree =& new $modelClass(); $this->Tree->initialize(2, 2); $result = $this->Tree->find('count'); $this->assertEqual($result, 7); $validTree = $this->Tree->verify(); $this->assertIdentical($validTree, true); }
testInitialize method @access public @return void
testInitialize
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/tree.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/tree.test.php
MIT
function testDetectInvalidLeft() { extract($this->settings); $this->Tree =& new $modelClass(); $this->Tree->initialize(2, 2); $result = $this->Tree->findByName('1.1'); $save[$modelClass]['id'] = $result[$modelClass]['id']; $save[$modelClass][$leftField] = 0; $this->Tree->save($save); $result = $this->Tree->verify(); $this->assertNotIdentical($result, true); $result = $this->Tree->recover(); $this->assertIdentical($result, true); $result = $this->Tree->verify(); $this->assertIdentical($result, true); }
testDetectInvalidLeft method @access public @return void
testDetectInvalidLeft
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/tree.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/tree.test.php
MIT
function testDetectInvalidRight() { extract($this->settings); $this->Tree =& new $modelClass(); $this->Tree->initialize(2, 2); $result = $this->Tree->findByName('1.1'); $save[$modelClass]['id'] = $result[$modelClass]['id']; $save[$modelClass][$rightField] = 0; $this->Tree->save($save); $result = $this->Tree->verify(); $this->assertNotIdentical($result, true); $result = $this->Tree->recover(); $this->assertIdentical($result, true); $result = $this->Tree->verify(); $this->assertIdentical($result, true); }
testDetectInvalidRight method @access public @return void
testDetectInvalidRight
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/tree.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/tree.test.php
MIT
function testDetectInvalidParent() { extract($this->settings); $this->Tree =& new $modelClass(); $this->Tree->initialize(2, 2); $result = $this->Tree->findByName('1.1'); // Bypass behavior and any other logic $this->Tree->updateAll(array($parentField => null), array('id' => $result[$modelClass]['id'])); $result = $this->Tree->verify(); $this->assertNotIdentical($result, true); $result = $this->Tree->recover(); $this->assertIdentical($result, true); $result = $this->Tree->verify(); $this->assertIdentical($result, true); }
testDetectInvalidParent method @access public @return void
testDetectInvalidParent
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/tree.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/tree.test.php
MIT
function testDetectNoneExistantParent() { extract($this->settings); $this->Tree =& new $modelClass(); $this->Tree->initialize(2, 2); $result = $this->Tree->findByName('1.1'); $this->Tree->updateAll(array($parentField => 999999), array('id' => $result[$modelClass]['id'])); $result = $this->Tree->verify(); $this->assertNotIdentical($result, true); $result = $this->Tree->recover('MPTT'); $this->assertIdentical($result, true); $result = $this->Tree->verify(); $this->assertIdentical($result, true); }
testDetectNoneExistantParent method @access public @return void
testDetectNoneExistantParent
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/tree.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/tree.test.php
MIT
function testRecoverFromMissingParent() { extract($this->settings); $this->Tree =& new $modelClass(); $this->Tree->initialize(2, 2); $result = $this->Tree->findByName('1.1'); $this->Tree->updateAll(array($parentField => 999999), array('id' => $result[$modelClass]['id'])); $result = $this->Tree->verify(); $this->assertNotIdentical($result, true); $result = $this->Tree->recover(); $this->assertIdentical($result, true); $result = $this->Tree->verify(); $this->assertIdentical($result, true); }
testRecoverFromMissingParent method @access public @return void
testRecoverFromMissingParent
php
Datawalke/Coordino
cake/tests/cases/libs/model/behaviors/tree.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/behaviors/tree.test.php
MIT