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 testHabtmUniqueKey() { $model =& new Item(); $this->assertFalse($model->hasAndBelongsToMany['Portfolio']['unique']); }
testHabtmUniqueKey method @access public @return void
testHabtmUniqueKey
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_integration.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php
MIT
function testIdentity() { $TestModel =& new Test(); $result = $TestModel->alias; $expected = 'Test'; $this->assertEqual($result, $expected); $TestModel =& new TestAlias(); $result = $TestModel->alias; $expected = 'TestAlias'; $this->assertEqual($result, $expected); $TestModel =& new Test(array('alias' => 'AnotherTest')); $result = $TestModel->alias; $expected = 'AnotherTest'; $this->assertEqual($result, $expected); }
testIdentity method @access public @return void
testIdentity
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_integration.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php
MIT
function testWithAssociation() { $this->loadFixtures('Something', 'SomethingElse', 'JoinThing'); $TestModel =& new Something(); $result = $TestModel->SomethingElse->find('all'); $expected = array( array( 'SomethingElse' => array( 'id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'Something' => array( array( 'id' => '3', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', 'JoinThing' => array( 'id' => '3', 'something_id' => '3', 'something_else_id' => '1', 'doomed' => '1', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' )))), array( 'SomethingElse' => array( 'id' => '2', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'Something' => array( array( 'id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'JoinThing' => array( 'id' => '1', 'something_id' => '1', 'something_else_id' => '2', 'doomed' => '1', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' )))), array( 'SomethingElse' => array( 'id' => '3', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ), 'Something' => array( array( 'id' => '2', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', 'JoinThing' => array( 'id' => '2', 'something_id' => '2', 'something_else_id' => '3', 'doomed' => '0', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ))))); $this->assertEqual($result, $expected); $result = $TestModel->find('all'); $expected = array( array( 'Something' => array( 'id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'SomethingElse' => array( array( 'id' => '2', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', 'JoinThing' => array( 'doomed' => '1', 'something_id' => '1', 'something_else_id' => '2' )))), array( 'Something' => array( 'id' => '2', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'SomethingElse' => array( array( 'id' => '3', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', 'JoinThing' => array( 'doomed' => '0', 'something_id' => '2', 'something_else_id' => '3' )))), array( 'Something' => array( 'id' => '3', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ), 'SomethingElse' => array( array( 'id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'JoinThing' => array( 'doomed' => '1', 'something_id' => '3', 'something_else_id' => '1' ))))); $this->assertEqual($result, $expected); $result = $TestModel->findById(1); $expected = array( 'Something' => array( 'id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'SomethingElse' => array( array( 'id' => '2', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', 'JoinThing' => array( 'doomed' => '1', 'something_id' => '1', 'something_else_id' => '2' )))); $this->assertEqual($result, $expected); $expected = $TestModel->findById(1); $TestModel->set($expected); $TestModel->save(); $result = $TestModel->findById(1); $this->assertEqual($result, $expected); $TestModel->hasAndBelongsToMany['SomethingElse']['unique'] = false; $TestModel->create(array( 'Something' => array('id' => 1), 'SomethingElse' => array(3, array( 'something_else_id' => 1, 'doomed' => '1' )))); $ts = date('Y-m-d H:i:s'); $TestModel->save(); $TestModel->hasAndBelongsToMany['SomethingElse']['order'] = 'SomethingElse.id ASC'; $result = $TestModel->findById(1); $expected = array( 'Something' => array( 'id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => $ts), 'SomethingElse' => array( array( 'id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'JoinThing' => array( 'doomed' => '1', 'something_id' => '1', 'something_else_id' => '1' )), array( 'id' => '2', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', 'JoinThing' => array( 'doomed' => '1', 'something_id' => '1', 'something_else_id' => '2' )), array( 'id' => '3', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', 'JoinThing' => array( 'doomed' => '0', 'something_id' => '1', 'something_else_id' => '3' )))); $this->assertEqual($result, $expected); }
testWithAssociation method @access public @return void
testWithAssociation
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_integration.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php
MIT
function testFindSelfAssociations() { $this->loadFixtures('Person'); $TestModel =& new Person(); $TestModel->recursive = 2; $result = $TestModel->read(null, 1); $expected = array( 'Person' => array( 'id' => 1, 'name' => 'person', 'mother_id' => 2, 'father_id' => 3 ), 'Mother' => array( 'id' => 2, 'name' => 'mother', 'mother_id' => 4, 'father_id' => 5, 'Mother' => array( 'id' => 4, 'name' => 'mother - grand mother', 'mother_id' => 0, 'father_id' => 0 ), 'Father' => array( 'id' => 5, 'name' => 'mother - grand father', 'mother_id' => 0, 'father_id' => 0 )), 'Father' => array( 'id' => 3, 'name' => 'father', 'mother_id' => 6, 'father_id' => 7, 'Father' => array( 'id' => 7, 'name' => 'father - grand father', 'mother_id' => 0, 'father_id' => 0 ), 'Mother' => array( 'id' => 6, 'name' => 'father - grand mother', 'mother_id' => 0, 'father_id' => 0 ))); $this->assertEqual($result, $expected); $TestModel->recursive = 3; $result = $TestModel->read(null, 1); $expected = array( 'Person' => array( 'id' => 1, 'name' => 'person', 'mother_id' => 2, 'father_id' => 3 ), 'Mother' => array( 'id' => 2, 'name' => 'mother', 'mother_id' => 4, 'father_id' => 5, 'Mother' => array( 'id' => 4, 'name' => 'mother - grand mother', 'mother_id' => 0, 'father_id' => 0, 'Mother' => array(), 'Father' => array()), 'Father' => array( 'id' => 5, 'name' => 'mother - grand father', 'mother_id' => 0, 'father_id' => 0, 'Father' => array(), 'Mother' => array() )), 'Father' => array( 'id' => 3, 'name' => 'father', 'mother_id' => 6, 'father_id' => 7, 'Father' => array( 'id' => 7, 'name' => 'father - grand father', 'mother_id' => 0, 'father_id' => 0, 'Father' => array(), 'Mother' => array() ), 'Mother' => array( 'id' => 6, 'name' => 'father - grand mother', 'mother_id' => 0, 'father_id' => 0, 'Mother' => array(), 'Father' => array() ))); $this->assertEqual($result, $expected); }
testFindSelfAssociations method @access public @return void
testFindSelfAssociations
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_integration.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php
MIT
function testDynamicAssociations() { $this->loadFixtures('Article', 'Comment'); $TestModel =& new Article(); $TestModel->belongsTo = $TestModel->hasAndBelongsToMany = $TestModel->hasOne = array(); $TestModel->hasMany['Comment'] = array_merge($TestModel->hasMany['Comment'], array( 'foreignKey' => false, 'conditions' => array('Comment.user_id =' => '2') )); $result = $TestModel->find('all'); $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' ), 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' => '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' => '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' => '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' ), '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' => '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' )))); $this->assertEqual($result, $expected); }
testDynamicAssociations method @access public @return void
testDynamicAssociations
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_integration.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php
MIT
function testCreation() { $this->loadFixtures('Article'); $TestModel =& new Test(); $result = $TestModel->create(); $expected = array('Test' => array('notes' => 'write some notes here')); $this->assertEqual($result, $expected); $TestModel =& new User(); $result = $TestModel->schema(); if (isset($this->db->columns['primary_key']['length'])) { $intLength = $this->db->columns['primary_key']['length']; } elseif (isset($this->db->columns['integer']['length'])) { $intLength = $this->db->columns['integer']['length']; } else { $intLength = 11; } foreach (array('collate', 'charset') as $type) { unset($result['user'][$type]); unset($result['password'][$type]); } $expected = array( 'id' => array( 'type' => 'integer', 'null' => false, 'default' => null, 'length' => $intLength, 'key' => 'primary' ), 'user' => array( 'type' => 'string', 'null' => false, 'default' => '', 'length' => 255 ), 'password' => array( 'type' => 'string', 'null' => false, 'default' => '', 'length' => 255 ), 'created' => array( 'type' => 'datetime', 'null' => true, 'default' => null, 'length' => null ), 'updated'=> array( 'type' => 'datetime', 'null' => true, 'default' => null, 'length' => null )); $this->assertEqual($result, $expected); $TestModel =& new Article(); $result = $TestModel->create(); $expected = array('Article' => array('published' => 'N')); $this->assertEqual($result, $expected); $FeaturedModel =& new Featured(); $data = array( 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => array( 'year' => 2008, 'month' => 06, 'day' => 11 ), 'end_date' => array( 'year' => 2008, 'month' => 06, 'day' => 20 )); $expected = array( 'Featured' => array( 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2008-6-11 00:00:00', 'end_date' => '2008-6-20 00:00:00' )); $this->assertEqual($FeaturedModel->create($data), $expected); $data = array( 'published_date' => array( 'year' => 2008, 'month' => 06, 'day' => 11 ), 'end_date' => array( 'year' => 2008, 'month' => 06, 'day' => 20 ), 'article_featured_id' => 1, 'category_id' => 1 ); $expected = array( 'Featured' => array( 'published_date' => '2008-6-11 00:00:00', 'end_date' => '2008-6-20 00:00:00', 'article_featured_id' => 1, 'category_id' => 1 )); $this->assertEqual($FeaturedModel->create($data), $expected); }
testCreation method @access public @return void
testCreation
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_integration.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php
MIT
function testEscapeField() { $TestModel =& new Test(); $db =& $TestModel->getDataSource(); $result = $TestModel->escapeField('test_field'); $expected = $db->name('Test.test_field'); $this->assertEqual($result, $expected); $result = $TestModel->escapeField('TestField'); $expected = $db->name('Test.TestField'); $this->assertEqual($result, $expected); $result = $TestModel->escapeField('DomainHandle', 'Domain'); $expected = $db->name('Domain.DomainHandle'); $this->assertEqual($result, $expected); ConnectionManager::create('mock', array('driver' => 'mock')); $TestModel->setDataSource('mock'); $db =& $TestModel->getDataSource(); $result = $TestModel->escapeField('DomainHandle', 'Domain'); $expected = $db->name('Domain.DomainHandle'); $this->assertEqual($result, $expected); }
testEscapeField to prove it escapes the field well even when it has part of the alias on it @see ttp://cakephp.lighthouseapp.com/projects/42648-cakephp-1x/tickets/473-escapefield-doesnt-consistently-prepend-modelname @access public @return void
testEscapeField
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_integration.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_integration.test.php
MIT
function testFetchingNonUniqueFKJoinTableRecords() { $this->loadFixtures('Something', 'SomethingElse', 'JoinThing'); $Something = new Something(); $joinThingData = array( 'JoinThing' => array( 'something_id' => 1, 'something_else_id' => 2, 'doomed' => '0', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ) ); $Something->JoinThing->create($joinThingData); $Something->JoinThing->save(); $result = $Something->JoinThing->find('all', array('conditions' => array('something_else_id' => 2))); $this->assertEqual($result[0]['JoinThing']['doomed'], true); $this->assertEqual($result[1]['JoinThing']['doomed'], false); $result = $Something->find('first'); $this->assertEqual(count($result['SomethingElse']), 2); $doomed = Set::extract('/JoinThing/doomed', $result['SomethingElse']); $this->assertTrue(in_array(true, $doomed)); $this->assertTrue(in_array(false, $doomed)); }
testFetchingNonUniqueFKJoinTableRecords() Tests if the results are properly returned in the case there are non-unique FK's in the join table but another fields value is different. For example: something_id | something_else_id | doomed = 1 something_id | something_else_id | doomed = 0 Should return both records and not just one. @access public @return void
testFetchingNonUniqueFKJoinTableRecords
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testGroupBy() { $db = ConnectionManager::getDataSource('test_suite'); $isStrictGroupBy = in_array($db->config['driver'], array('postgres', 'oracle')); $message = '%s Postgres and Oracle have strict GROUP BY and are incompatible with this test.'; if ($this->skipIf($isStrictGroupBy, $message )) { return; } $this->loadFixtures('Project', 'Product', 'Thread', 'Message', 'Bid'); $Thread =& new Thread(); $Product =& new Product(); $result = $Thread->find('all', array( 'group' => 'Thread.project_id', 'order' => 'Thread.id ASC' )); $expected = array( array( 'Thread' => array( 'id' => 1, 'project_id' => 1, 'name' => 'Project 1, Thread 1' ), 'Project' => array( 'id' => 1, 'name' => 'Project 1' ), 'Message' => array( array( 'id' => 1, 'thread_id' => 1, 'name' => 'Thread 1, Message 1' ))), array( 'Thread' => array( 'id' => 3, 'project_id' => 2, 'name' => 'Project 2, Thread 1' ), 'Project' => array( 'id' => 2, 'name' => 'Project 2' ), 'Message' => array( array( 'id' => 3, 'thread_id' => 3, 'name' => 'Thread 3, Message 1' )))); $this->assertEqual($result, $expected); $rows = $Thread->find('all', array( 'group' => 'Thread.project_id', 'fields' => array('Thread.project_id', 'COUNT(*) AS total') )); $result = array(); foreach($rows as $row) { $result[$row['Thread']['project_id']] = $row[0]['total']; } $expected = array( 1 => 2, 2 => 1 ); $this->assertEqual($result, $expected); $rows = $Thread->find('all', array( 'group' => 'Thread.project_id', 'fields' => array('Thread.project_id', 'COUNT(*) AS total'), 'order'=> 'Thread.project_id' )); $result = array(); foreach($rows as $row) { $result[$row['Thread']['project_id']] = $row[0]['total']; } $expected = array( 1 => 2, 2 => 1 ); $this->assertEqual($result, $expected); $result = $Thread->find('all', array( 'conditions' => array('Thread.project_id' => 1), 'group' => 'Thread.project_id' )); $expected = array( array( 'Thread' => array( 'id' => 1, 'project_id' => 1, 'name' => 'Project 1, Thread 1' ), 'Project' => array( 'id' => 1, 'name' => 'Project 1' ), 'Message' => array( array( 'id' => 1, 'thread_id' => 1, 'name' => 'Thread 1, Message 1' )))); $this->assertEqual($result, $expected); $result = $Thread->find('all', array( 'conditions' => array('Thread.project_id' => 1), 'group' => 'Thread.project_id, Project.id' )); $this->assertEqual($result, $expected); $result = $Thread->find('all', array( 'conditions' => array('Thread.project_id' => 1), 'group' => 'project_id' )); $this->assertEqual($result, $expected); $result = $Thread->find('all', array( 'conditions' => array('Thread.project_id' => 1), 'group' => array('project_id') )); $this->assertEqual($result, $expected); $result = $Thread->find('all', array( 'conditions' => array('Thread.project_id' => 1), 'group' => array('project_id', 'Project.id') )); $this->assertEqual($result, $expected); $result = $Thread->find('all', array( 'conditions' => array('Thread.project_id' => 1), 'group' => array('Thread.project_id', 'Project.id') )); $this->assertEqual($result, $expected); $expected = array( array('Product' => array('type' => 'Clothing'), array('price' => 32)), array('Product' => array('type' => 'Food'), array('price' => 9)), array('Product' => array('type' => 'Music'), array( 'price' => 4)), array('Product' => array('type' => 'Toy'), array('price' => 3)) ); $result = $Product->find('all',array( 'fields'=>array('Product.type', 'MIN(Product.price) as price'), 'group'=> 'Product.type', 'order' => 'Product.type ASC' )); $this->assertEqual($result, $expected); $result = $Product->find('all', array( 'fields'=>array('Product.type', 'MIN(Product.price) as price'), 'group'=> array('Product.type'), 'order' => 'Product.type ASC')); $this->assertEqual($result, $expected); }
testGroupBy method These tests will never pass with Postgres or Oracle as all fields in a select must be part of an aggregate function or in the GROUP BY statement. @access public @return void
testGroupBy
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testOldQuery() { $this->loadFixtures('Article'); $Article =& new Article(); $query = 'SELECT title FROM '; $query .= $this->db->fullTableName('articles'); $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.id IN (1,2)'; $results = $Article->query($query); $this->assertTrue(is_array($results)); $this->assertEqual(count($results), 2); $query = 'SELECT title, body FROM '; $query .= $this->db->fullTableName('articles'); $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.id = 1'; $results = $Article->query($query, false); $this->assertTrue(!isset($this->db->_queryCache[$query])); $this->assertTrue(is_array($results)); $query = 'SELECT title, id FROM '; $query .= $this->db->fullTableName('articles'); $query .= ' WHERE ' . $this->db->fullTableName('articles'); $query .= '.published = ' . $this->db->value('Y'); $results = $Article->query($query, true); $this->assertTrue(isset($this->db->_queryCache[$query])); $this->assertTrue(is_array($results)); }
testOldQuery method @access public @return void
testOldQuery
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testPreparedQuery() { $this->loadFixtures('Article'); $Article =& new Article(); $this->db->_queryCache = array(); $finalQuery = 'SELECT title, published FROM '; $finalQuery .= $this->db->fullTableName('articles'); $finalQuery .= ' WHERE ' . $this->db->fullTableName('articles'); $finalQuery .= '.id = ' . $this->db->value(1); $finalQuery .= ' AND ' . $this->db->fullTableName('articles'); $finalQuery .= '.published = ' . $this->db->value('Y'); $query = 'SELECT title, published FROM '; $query .= $this->db->fullTableName('articles'); $query .= ' WHERE ' . $this->db->fullTableName('articles'); $query .= '.id = ? AND ' . $this->db->fullTableName('articles') . '.published = ?'; $params = array(1, 'Y'); $result = $Article->query($query, $params); $expected = array( '0' => array( $this->db->fullTableName('articles', false) => array( 'title' => 'First Article', 'published' => 'Y') )); if (isset($result[0][0])) { $expected[0][0] = $expected[0][$this->db->fullTableName('articles', false)]; unset($expected[0][$this->db->fullTableName('articles', false)]); } $this->assertEqual($result, $expected); $this->assertTrue(isset($this->db->_queryCache[$finalQuery])); $finalQuery = 'SELECT id, created FROM '; $finalQuery .= $this->db->fullTableName('articles'); $finalQuery .= ' WHERE ' . $this->db->fullTableName('articles'); $finalQuery .= '.title = ' . $this->db->value('First Article'); $query = 'SELECT id, created FROM '; $query .= $this->db->fullTableName('articles'); $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title = ?'; $params = array('First Article'); $result = $Article->query($query, $params, false); $this->assertTrue(is_array($result)); $this->assertTrue( isset($result[0][$this->db->fullTableName('articles', false)]) || isset($result[0][0]) ); $this->assertFalse(isset($this->db->_queryCache[$finalQuery])); $query = 'SELECT title FROM '; $query .= $this->db->fullTableName('articles'); $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title LIKE ?'; $params = array('%First%'); $result = $Article->query($query, $params); $this->assertTrue(is_array($result)); $this->assertTrue( isset($result[0][$this->db->fullTableName('articles', false)]['title']) || isset($result[0][0]['title']) ); //related to ticket #5035 $query = 'SELECT title FROM '; $query .= $this->db->fullTableName('articles') . ' WHERE title = ? AND published = ?'; $params = array('First? Article', 'Y'); $Article->query($query, $params); $expected = 'SELECT title FROM '; $expected .= $this->db->fullTableName('articles'); $expected .= " WHERE title = 'First? Article' AND published = 'Y'"; $this->assertTrue(isset($this->db->_queryCache[$expected])); }
testPreparedQuery method @access public @return void
testPreparedQuery
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testParameterMismatch() { $this->loadFixtures('Article'); $Article =& new Article(); $query = 'SELECT * FROM ' . $this->db->fullTableName('articles'); $query .= ' WHERE ' . $this->db->fullTableName('articles'); $query .= '.published = ? AND ' . $this->db->fullTableName('articles') . '.user_id = ?'; $params = array('Y'); $this->expectError(); ob_start(); $result = $Article->query($query, $params); ob_end_clean(); $this->assertEqual($result, null); }
testParameterMismatch method @access public @return void
testParameterMismatch
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testVeryStrangeUseCase() { $message = "%s skipping SELECT * FROM ? WHERE ? = ? AND ? = ?; prepared query."; $message .= " MSSQL is incompatible with this test."; if ($this->skipIf($this->db->config['driver'] == 'mssql', $message)) { return; } $this->loadFixtures('Article'); $Article =& new Article(); $query = 'SELECT * FROM ? WHERE ? = ? AND ? = ?'; $param = array( $this->db->fullTableName('articles'), $this->db->fullTableName('articles') . '.user_id', '3', $this->db->fullTableName('articles') . '.published', 'Y' ); $this->expectError(); ob_start(); $result = $Article->query($query, $param); ob_end_clean(); }
testVeryStrangeUseCase method @access public @return void
testVeryStrangeUseCase
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testRecursiveUnbind() { $this->loadFixtures('Apple', 'Sample'); $TestModel =& new Apple(); $TestModel->recursive = 2; $result = $TestModel->find('all'); $expected = array( array( 'Apple' => array ( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => 2, 'apple_id' => 2, 'name' => 'sample2' ), 'Child' => array( array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' =>'', 'apple_id' => '', 'name' => '' ), 'Child' => array( array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => 2, 'apple_id' => 2, 'name' => 'sample2' ), 'Child' => array( array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ))))), array( 'Apple' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Sample' => array(), 'Child' => array( array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => 2, 'apple_id' => 2, 'name' => 'sample2', 'Apple' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' )), 'Child' => array( array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Sample' => array(), 'Child' => array( array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ))), array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => 1, 'apple_id' => 3, 'name' => 'sample1' )), array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => 3, 'apple_id' => 4, 'name' => 'sample3' ), 'Child' => array( array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17' ))))), array( 'Apple' => array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => 2, 'apple_id' => 2, 'name' => 'sample2' ), 'Child' => array( array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => 1, 'apple_id' => 3, 'name' => 'sample1', 'Apple' => array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' )), 'Child' => array() ), array( 'Apple' => array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'), 'Child' => array( array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => 3, 'apple_id' => 4, 'name' => 'sample3', 'Apple' => array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' )), 'Child' => array( array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ), 'Sample' => array(), 'Child' => array( array( 'id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17' ))))), array( 'Apple' => array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => 4, 'apple_id' => 5, 'name' => 'sample4' ), 'Child' => array( array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => 4, 'apple_id' => 5, 'name' => 'sample4', 'Apple' => array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' )), 'Child' => array( array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => 4, 'apple_id' => 5, 'name' => 'sample4' ), 'Child' => array( array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ))))), array( 'Apple' => array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => 3, 'apple_id' => 4, 'name' => 'sample3' ), 'Child' => array( array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => '', 'apple_id' => '', 'name' => '' ), 'Child' => array( array( 'id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17' ), 'Sample' => array() ))), array( 'Apple' => array( 'id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ), 'Sample' => array(), 'Child' => array( array( 'id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => '', 'apple_id' => '', 'name' => '' ), 'Child' => array())); $this->assertEqual($result, $expected); $result = $TestModel->Parent->unbindModel(array('hasOne' => array('Sample'))); $this->assertTrue($result); $result = $TestModel->find('all'); $expected = array( array( 'Apple' => array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), 'Child' => array( array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' =>'', 'apple_id' => '', 'name' => '' ), 'Child' => array( array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => 2, 'apple_id' => 2, 'name' => 'sample2' ), 'Child' => array( array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ))))), array( 'Apple' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Child' => array( array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => 2, 'apple_id' => 2, 'name' => 'sample2', 'Apple' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' )), 'Child' => array( array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Sample' => array(), 'Child' => array( array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ))), array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => 1, 'apple_id' => 3, 'name' => 'sample1' )), array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => 3, 'apple_id' => 4, 'name' => 'sample3' ), 'Child' => array( array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17' ))))), array( 'Apple' => array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), 'Child' => array( array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => 1, 'apple_id' => 3, 'name' => 'sample1', 'Apple' => array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' )), 'Child' => array() ), array( 'Apple' => array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), 'Child' => array( array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => 3, 'apple_id' => 4, 'name' => 'sample3', 'Apple' => array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' )), 'Child' => array( array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ), 'Sample' => array(), 'Child' => array( array( 'id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17' ))))), array( 'Apple' => array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ), 'Child' => array( array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => 4, 'apple_id' => 5, 'name' => 'sample4', 'Apple' => array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' )), 'Child' => array( array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => 4, 'apple_id' => 5, 'name' => 'sample4' ), 'Child' => array( array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ))))), array( 'Apple' => array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Child' => array( array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => '', 'apple_id' => '', 'name' => '' ), 'Child' => array( array( 'id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17' ), 'Sample' => array() ))), array( 'Apple' => array( 'id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ), 'Child' => array( array( 'id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => '', 'apple_id' => '', 'name' => '' ), 'Child' => array() )); $this->assertEqual($result, $expected); $result = $TestModel->Parent->unbindModel(array('hasOne' => array('Sample'))); $this->assertTrue($result); $result = $TestModel->unbindModel(array('hasMany' => array('Child'))); $this->assertTrue($result); $result = $TestModel->find('all'); $expected = array( array( 'Apple' => array ( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), 'Child' => array( array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' =>'', 'apple_id' => '', 'name' => '' )), array( 'Apple' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Child' => array( array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => 2, 'apple_id' => 2, 'name' => 'sample2', 'Apple' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ))), array( 'Apple' => array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), 'Child' => array( array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => 1, 'apple_id' => 3, 'name' => 'sample1', 'Apple' => array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ))), array( 'Apple' => array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), 'Child' => array( array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => 3, 'apple_id' => 4, 'name' => 'sample3', 'Apple' => array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ))), array( 'Apple' => array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ), 'Child' => array( array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => 4, 'apple_id' => 5, 'name' => 'sample4', 'Apple' => array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ))), array( 'Apple' => array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Child' => array( array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => '', 'apple_id' => '', 'name' => '' )), array( 'Apple' => array( 'id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ), 'Child' => array( array( 'id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => '', 'apple_id' => '', 'name' => '' ))); $this->assertEqual($result, $expected); $result = $TestModel->unbindModel(array('hasMany' => array('Child'))); $this->assertTrue($result); $result = $TestModel->Sample->unbindModel(array('belongsTo' => array('Apple'))); $this->assertTrue($result); $result = $TestModel->find('all'); $expected = array( array( 'Apple' => array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => 2, 'apple_id' => 2, 'name' => 'sample2' ), 'Child' => array( array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' =>'', 'apple_id' => '', 'name' => '' )), array( 'Apple' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Sample' => array(), 'Child' => array( array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => 2, 'apple_id' => 2, 'name' => 'sample2' )), array( 'Apple' => array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => 2, 'apple_id' => 2, 'name' => 'sample2' ), 'Child' => array( array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => 1, 'apple_id' => 3, 'name' => 'sample1' )), array( 'Apple' => array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => 2, 'apple_id' => 2, 'name' => 'sample2' ), 'Child' => array( array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => 3, 'apple_id' => 4, 'name' => 'sample3' )), array( 'Apple' => array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => 4, 'apple_id' => 5, 'name' => 'sample4' ), 'Child' => array( array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => 4, 'apple_id' => 5, 'name' => 'sample4' )), array( 'Apple' => array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => 3, 'apple_id' => 4, 'name' => 'sample3' ), 'Child' => array( array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => '', 'apple_id' => '', 'name' => '' )), array( 'Apple' => array( 'id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17', 'Parent' => array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ), 'Sample' => array(), 'Child' => array( array( 'id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => '', 'apple_id' => '', 'name' => '' ))); $this->assertEqual($result, $expected); $result = $TestModel->Parent->unbindModel(array('belongsTo' => array('Parent'))); $this->assertTrue($result); $result = $TestModel->unbindModel(array('hasMany' => array('Child'))); $this->assertTrue($result); $result = $TestModel->find('all'); $expected = array( array( 'Apple' => array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', 'Sample' => array( 'id' => 2, 'apple_id' => 2, 'name' => 'sample2' ), 'Child' => array( array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' =>'', 'apple_id' => '', 'name' => '' )), array( 'Apple' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17', 'Sample' => array(), 'Child' => array( array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => 2, 'apple_id' => 2, 'name' => 'sample2', 'Apple' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ))), array( 'Apple' => array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', 'Sample' => array( 'id' => 2, 'apple_id' => 2, 'name' => 'sample2' ), 'Child' => array( array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => 1, 'apple_id' => 3, 'name' => 'sample1', 'Apple' => array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ))), array( 'Apple' => array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', 'Sample' => array( 'id' => 2, 'apple_id' => 2, 'name' => 'sample2' ), 'Child' => array( array( 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => 3, 'apple_id' => 4, 'name' => 'sample3', 'Apple' => array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ))), array( 'Apple' => array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17', 'Sample' => array( 'id' => 4, 'apple_id' => 5, 'name' => 'sample4' ), 'Child' => array( array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => 4, 'apple_id' => 5, 'name' => 'sample4', 'Apple' => array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ))), array( 'Apple' => array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17'), 'Parent' => array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17', 'Sample' => array( 'id' => 3, 'apple_id' => 4, 'name' => 'sample3' ), 'Child' => array( array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => '', 'apple_id' => '', 'name' => '' )), array( 'Apple' => array( 'id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17', 'Sample' => array(), 'Child' => array( array( 'id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17' ))), 'Sample' => array( 'id' => '', 'apple_id' => '', 'name' => '' ))); $this->assertEqual($result, $expected); }
testRecursiveUnbind method @access public @return void
testRecursiveUnbind
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testSelfAssociationAfterFind() { $this->loadFixtures('Apple'); $afterFindModel = new NodeAfterFind(); $afterFindModel->recursive = 3; $afterFindData = $afterFindModel->find('all'); $duplicateModel = new NodeAfterFind(); $duplicateModel->recursive = 3; $duplicateModelData = $duplicateModel->find('all'); $noAfterFindModel = new NodeNoAfterFind(); $noAfterFindModel->recursive = 3; $noAfterFindData = $noAfterFindModel->find('all'); $this->assertFalse($afterFindModel == $noAfterFindModel); // Limitation of PHP 4 and PHP 5 > 5.1.6 when comparing recursive objects if (PHP_VERSION === '5.1.6') { $this->assertFalse($afterFindModel != $duplicateModel); } $this->assertEqual($afterFindData, $noAfterFindData); }
testSelfAssociationAfterFind method @access public @return void
testSelfAssociationAfterFind
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testFindAllThreaded() { $this->loadFixtures('Category'); $TestModel =& new Category(); $result = $TestModel->find('threaded'); $expected = array( array( 'Category' => array( 'id' => '1', 'parent_id' => '0', 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'children' => array( array( 'Category' => array( 'id' => '2', 'parent_id' => '1', 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'children' => array( array('Category' => array( 'id' => '7', 'parent_id' => '2', 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array()), array('Category' => array( 'id' => '8', 'parent_id' => '2', 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array())) ), array( 'Category' => array( 'id' => '3', 'parent_id' => '1', 'name' => 'Category 1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'children' => array() ) ) ), array( 'Category' => array( 'id' => '4', 'parent_id' => '0', 'name' => 'Category 2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'children' => array() ), array( 'Category' => array( 'id' => '5', 'parent_id' => '0', 'name' => 'Category 3', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'children' => array( array( 'Category' => array( 'id' => '6', 'parent_id' => '5', 'name' => 'Category 3.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'children' => array() ) ) ) ); $this->assertEqual($result, $expected); $result = $TestModel->find('threaded', array( 'conditions' => array('Category.name LIKE' => 'Category 1%') )); $expected = array( array( 'Category' => array( 'id' => '1', 'parent_id' => '0', 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'children' => array( array( 'Category' => array( 'id' => '2', 'parent_id' => '1', 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'children' => array( array('Category' => array( 'id' => '7', 'parent_id' => '2', 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array()), array('Category' => array( 'id' => '8', 'parent_id' => '2', 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array())) ), array( 'Category' => array( 'id' => '3', 'parent_id' => '1', 'name' => 'Category 1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'children' => array() ) ) ) ); $this->assertEqual($result, $expected); $result = $TestModel->find('threaded', array( 'fields' => 'id, parent_id, name' )); $expected = array( array( 'Category' => array( 'id' => '1', 'parent_id' => '0', 'name' => 'Category 1' ), 'children' => array( array( 'Category' => array( 'id' => '2', 'parent_id' => '1', 'name' => 'Category 1.1' ), 'children' => array( array('Category' => array( 'id' => '7', 'parent_id' => '2', 'name' => 'Category 1.1.1'), 'children' => array()), array('Category' => array( 'id' => '8', 'parent_id' => '2', 'name' => 'Category 1.1.2'), 'children' => array())) ), array( 'Category' => array( 'id' => '3', 'parent_id' => '1', 'name' => 'Category 1.2' ), 'children' => array() ) ) ), array( 'Category' => array( 'id' => '4', 'parent_id' => '0', 'name' => 'Category 2' ), 'children' => array() ), array( 'Category' => array( 'id' => '5', 'parent_id' => '0', 'name' => 'Category 3' ), 'children' => array( array( 'Category' => array( 'id' => '6', 'parent_id' => '5', 'name' => 'Category 3.1' ), 'children' => array() ) ) ) ); $this->assertEqual($result, $expected); $result = $TestModel->find('threaded', array('order' => 'id DESC')); $expected = array( array( 'Category' => array( 'id' => 5, 'parent_id' => 0, 'name' => 'Category 3', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'children' => array( array( 'Category' => array( 'id' => 6, 'parent_id' => 5, 'name' => 'Category 3.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'children' => array() ) ) ), array( 'Category' => array( 'id' => 4, 'parent_id' => 0, 'name' => 'Category 2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'children' => array() ), array( 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'children' => array( array( 'Category' => array( 'id' => 3, 'parent_id' => 1, 'name' => 'Category 1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'children' => array() ), array( 'Category' => array( 'id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'children' => array( array('Category' => array( 'id' => '8', 'parent_id' => '2', 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array()), array('Category' => array( 'id' => '7', 'parent_id' => '2', 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array())) ) ) ) ); $this->assertEqual($result, $expected); $result = $TestModel->find('threaded', array( 'conditions' => array('Category.name LIKE' => 'Category 3%') )); $expected = array( array( 'Category' => array( 'id' => '5', 'parent_id' => '0', 'name' => 'Category 3', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'children' => array( array( 'Category' => array( 'id' => '6', 'parent_id' => '5', 'name' => 'Category 3.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'children' => array() ) ) ) ); $this->assertEqual($result, $expected); $result = $TestModel->find('threaded', array( 'conditions' => array('Category.name LIKE' => 'Category 1.1%') )); $expected = array( array('Category' => array( 'id' => '2', 'parent_id' => '1', 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array( array('Category' => array( 'id' => '7', 'parent_id' => '2', 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array()), array('Category' => array( 'id' => '8', 'parent_id' => '2', 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), 'children' => array())))); $this->assertEqual($result, $expected); $result = $TestModel->find('threaded', array( 'fields' => 'id, parent_id, name', 'conditions' => array('Category.id !=' => 2) )); $expected = array( array( 'Category' => array( 'id' => '1', 'parent_id' => '0', 'name' => 'Category 1' ), 'children' => array( array( 'Category' => array( 'id' => '3', 'parent_id' => '1', 'name' => 'Category 1.2' ), 'children' => array() ) ) ), array( 'Category' => array( 'id' => '4', 'parent_id' => '0', 'name' => 'Category 2' ), 'children' => array() ), array( 'Category' => array( 'id' => '5', 'parent_id' => '0', 'name' => 'Category 3' ), 'children' => array( array( 'Category' => array( 'id' => '6', 'parent_id' => '5', 'name' => 'Category 3.1' ), 'children' => array() ) ) ) ); $this->assertEqual($result, $expected); $result = $TestModel->find('all', array( 'fields' => 'id, name, parent_id', 'conditions' => array('Category.id !=' => 1) )); $expected = array ( array ('Category' => array( 'id' => '2', 'name' => 'Category 1.1', 'parent_id' => '1' )), array ('Category' => array( 'id' => '3', 'name' => 'Category 1.2', 'parent_id' => '1' )), array ('Category' => array( 'id' => '4', 'name' => 'Category 2', 'parent_id' => '0' )), array ('Category' => array( 'id' => '5', 'name' => 'Category 3', 'parent_id' => '0' )), array ('Category' => array( 'id' => '6', 'name' => 'Category 3.1', 'parent_id' => '5' )), array ('Category' => array( 'id' => '7', 'name' => 'Category 1.1.1', 'parent_id' => '2' )), array ('Category' => array( 'id' => '8', 'name' => 'Category 1.1.2', 'parent_id' => '2' ))); $this->assertEqual($result, $expected); $result = $TestModel->find('threaded', array( 'fields' => 'id, parent_id, name', 'conditions' => array('Category.id !=' => 1) )); $expected = array( array( 'Category' => array( 'id' => '2', 'parent_id' => '1', 'name' => 'Category 1.1' ), 'children' => array( array('Category' => array( 'id' => '7', 'parent_id' => '2', 'name' => 'Category 1.1.1'), 'children' => array()), array('Category' => array( 'id' => '8', 'parent_id' => '2', 'name' => 'Category 1.1.2'), 'children' => array())) ), array( 'Category' => array( 'id' => '3', 'parent_id' => '1', 'name' => 'Category 1.2' ), 'children' => array() ) ); $this->assertEqual($result, $expected); }
testFindAllThreaded method @access public @return void
testFindAllThreaded
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testFindNeighbors() { $this->loadFixtures('User', 'Article'); $TestModel =& new Article(); $TestModel->id = 1; $result = $TestModel->find('neighbors', array('fields' => array('id'))); $expected = array( 'prev' => null, 'next' => array( 'Article' => array('id' => 2) )); $this->assertEqual($result, $expected); $TestModel->id = 2; $result = $TestModel->find('neighbors', array( 'fields' => array('id') )); $expected = array( 'prev' => array( 'Article' => array( 'id' => 1 )), 'next' => array( 'Article' => array( 'id' => 3 ))); $this->assertEqual($result, $expected); $TestModel->id = 3; $result = $TestModel->find('neighbors', array('fields' => array('id'))); $expected = array( 'prev' => array( 'Article' => array( 'id' => 2 )), 'next' => null ); $this->assertEqual($result, $expected); $TestModel->id = 1; $result = $TestModel->find('neighbors', array('recursive' => -1)); $expected = array( 'prev' => null, 'next' => 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' ) ) ); $this->assertEqual($result, $expected); $TestModel->id = 2; $result = $TestModel->find('neighbors', array('recursive' => -1)); $expected = array( 'prev' => 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' ) ), 'next' => 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); $TestModel->id = 3; $result = $TestModel->find('neighbors', array('recursive' => -1)); $expected = array( 'prev' => 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' ) ), 'next' => null ); $this->assertEqual($result, $expected); $TestModel->recursive = 0; $TestModel->id = 1; $one = $TestModel->read(); $TestModel->id = 2; $two = $TestModel->read(); $TestModel->id = 3; $three = $TestModel->read(); $TestModel->id = 1; $result = $TestModel->find('neighbors'); $expected = array('prev' => null, 'next' => $two); $this->assertEqual($result, $expected); $TestModel->id = 2; $result = $TestModel->find('neighbors'); $expected = array('prev' => $one, 'next' => $three); $this->assertEqual($result, $expected); $TestModel->id = 3; $result = $TestModel->find('neighbors'); $expected = array('prev' => $two, 'next' => null); $this->assertEqual($result, $expected); $TestModel->recursive = 2; $TestModel->id = 1; $one = $TestModel->read(); $TestModel->id = 2; $two = $TestModel->read(); $TestModel->id = 3; $three = $TestModel->read(); $TestModel->id = 1; $result = $TestModel->find('neighbors', array('recursive' => 2)); $expected = array('prev' => null, 'next' => $two); $this->assertEqual($result, $expected); $TestModel->id = 2; $result = $TestModel->find('neighbors', array('recursive' => 2)); $expected = array('prev' => $one, 'next' => $three); $this->assertEqual($result, $expected); $TestModel->id = 3; $result = $TestModel->find('neighbors', array('recursive' => 2)); $expected = array('prev' => $two, 'next' => null); $this->assertEqual($result, $expected); }
test find('neighbors') @return void @access public
testFindNeighbors
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testFindCombinedRelations() { $this->loadFixtures('Apple', 'Sample'); $TestModel =& new Apple(); $result = $TestModel->find('all'); $expected = array( array( 'Apple' => array( 'id' => '1', 'apple_id' => '2', 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => '2', 'apple_id' => '1', 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => null, 'apple_id' => null, 'name' => null ), 'Child' => array( array( 'id' => '2', 'apple_id' => '1', 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ))), array( 'Apple' => array( 'id' => '2', 'apple_id' => '1', 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => '1', 'apple_id' => '2', 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => '2', 'apple_id' => '2', 'name' => 'sample2' ), 'Child' => array( array( 'id' => '1', 'apple_id' => '2', 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17' ), array( 'id' => '3', 'apple_id' => '2', 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), array( 'id' => '4', 'apple_id' => '2', 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ))), array( 'Apple' => array( 'id' => '3', 'apple_id' => '2', 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => '2', 'apple_id' => '1', 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => '1', 'apple_id' => '3', 'name' => 'sample1' ), 'Child' => array() ), array( 'Apple' => array( 'id' => '4', 'apple_id' => '2', 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => '2', 'apple_id' => '1', 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => '3', 'apple_id' => '4', 'name' => 'sample3' ), 'Child' => array( array( 'id' => '6', 'apple_id' => '4', 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17' ))), array( 'Apple' => array( 'id' => '5', 'apple_id' => '5', 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => '5', 'apple_id' => '5', 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => '4', 'apple_id' => '5', 'name' => 'sample4' ), 'Child' => array( array( 'id' => '5', 'apple_id' => '5', 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' ))), array( 'Apple' => array( 'id' => '6', 'apple_id' => '4', 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => '4', 'apple_id' => '2', 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => null, 'apple_id' => null, 'name' => null ), 'Child' => array( array( 'id' => '7', 'apple_id' => '6', 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17' ))), array( 'Apple' => array( 'id' => '7', 'apple_id' => '6', 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17' ), 'Parent' => array( 'id' => '6', 'apple_id' => '4', 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17' ), 'Sample' => array( 'id' => null, 'apple_id' => null, 'name' => null ), 'Child' => array() )); $this->assertEqual($result, $expected); }
testFindCombinedRelations method @access public @return void
testFindCombinedRelations
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testSaveEmpty() { $this->loadFixtures('Thread'); $TestModel =& new Thread(); $data = array(); $expected = $TestModel->save($data); $this->assertFalse($expected); }
testSaveEmpty method @access public @return void
testSaveEmpty
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testFindAllWithConditionInChildQuery() { $this->loadFixtures('Basket', 'FilmFile'); $TestModel =& new Basket(); $recursive = 3; $result = $TestModel->find('all', compact('conditions', 'recursive')); $expected = array( array( 'Basket' => array( 'id' => 1, 'type' => 'nonfile', 'name' => 'basket1', 'object_id' => 1, 'user_id' => 1, ), 'FilmFile' => array( 'id' => '', 'name' => '', ) ), array( 'Basket' => array( 'id' => 2, 'type' => 'file', 'name' => 'basket2', 'object_id' => 2, 'user_id' => 1, ), 'FilmFile' => array( 'id' => 2, 'name' => 'two', ) ), ); $this->assertEqual($result, $expected); }
testFindAllWithConditionInChildQuery @todo external conditions like this are going to need to be revisited at some point @access public @return void
testFindAllWithConditionInChildQuery
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testFindAllWithConditionsHavingMixedDataTypes() { $this->loadFixtures('Article'); $TestModel =& new Article(); $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' ) ) ); $conditions = array('id' => array('1', 2)); $recursive = -1; $order = 'Article.id ASC'; $result = $TestModel->find('all', compact('conditions', 'recursive', 'order')); $this->assertEqual($result, $expected); if ($this->skipIf($this->db->config['driver'] == 'postgres', 'The rest of testFindAllWithConditionsHavingMixedDataTypes test is not compatible with Postgres')) { return; } $conditions = array('id' => array('1', 2, '3.0')); $order = 'Article.id ASC'; $result = $TestModel->find('all', compact('recursive', 'conditions', 'order')); $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); }
testFindAllWithConditionsHavingMixedDataTypes method @access public @return void
testFindAllWithConditionsHavingMixedDataTypes
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testBindUnbind() { $this->loadFixtures('User', 'Comment', 'FeatureSet'); $TestModel =& new User(); $result = $TestModel->hasMany; $expected = array(); $this->assertEqual($result, $expected); $result = $TestModel->bindModel(array('hasMany' => array('Comment'))); $this->assertTrue($result); $result = $TestModel->find('all', array( 'fields' => 'User.id, User.user' )); $expected = array( array( 'User' => array( 'id' => '1', 'user' => 'mariano' ), '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( 'User' => array( 'id' => '2', 'user' => 'nate' ), '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' => '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( 'User' => array( 'id' => '3', 'user' => 'larry' ), 'Comment' => array() ), array( 'User' => array( 'id' => '4', 'user' => 'garrett' ), 'Comment' => 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' )))); $this->assertEqual($result, $expected); $TestModel->resetAssociations(); $result = $TestModel->hasMany; $this->assertEqual($result, array()); $result = $TestModel->bindModel(array('hasMany' => array('Comment')), false); $this->assertTrue($result); $result = $TestModel->find('all', array( 'fields' => 'User.id, User.user' )); $expected = array( array( 'User' => array( 'id' => '1', 'user' => 'mariano' ), '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( 'User' => array( 'id' => '2', 'user' => 'nate' ), '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' => '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( 'User' => array( 'id' => '3', 'user' => 'larry' ), 'Comment' => array() ), array( 'User' => array( 'id' => '4', 'user' => 'garrett' ), 'Comment' => 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' )))); $this->assertEqual($result, $expected); $result = $TestModel->hasMany; $expected = array( 'Comment' => array( 'className' => 'Comment', 'foreignKey' => 'user_id', 'conditions' => null, 'fields' => null, 'order' => null, 'limit' => null, 'offset' => null, 'dependent' => null, 'exclusive' => null, 'finderQuery' => null, 'counterQuery' => null )); $this->assertEqual($result, $expected); $result = $TestModel->unbindModel(array('hasMany' => array('Comment'))); $this->assertTrue($result); $result = $TestModel->hasMany; $expected = array(); $this->assertEqual($result, $expected); $result = $TestModel->find('all', array( 'fields' => 'User.id, User.user' )); $expected = array( array('User' => array('id' => '1', 'user' => 'mariano')), array('User' => array('id' => '2', 'user' => 'nate')), array('User' => array('id' => '3', 'user' => 'larry')), array('User' => array('id' => '4', 'user' => 'garrett'))); $this->assertEqual($result, $expected); $result = $TestModel->find('all', array( 'fields' => 'User.id, User.user' )); $expected = array( array( 'User' => array( 'id' => '1', 'user' => 'mariano' ), '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( 'User' => array( 'id' => '2', 'user' => 'nate' ), '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' => '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( 'User' => array( 'id' => '3', 'user' => 'larry' ), 'Comment' => array() ), array( 'User' => array( 'id' => '4', 'user' => 'garrett' ), 'Comment' => 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' )))); $this->assertEqual($result, $expected); $result = $TestModel->unbindModel(array('hasMany' => array('Comment')), false); $this->assertTrue($result); $result = $TestModel->find('all', array('fields' => 'User.id, User.user')); $expected = array( array('User' => array('id' => '1', 'user' => 'mariano')), array('User' => array('id' => '2', 'user' => 'nate')), array('User' => array('id' => '3', 'user' => 'larry')), array('User' => array('id' => '4', 'user' => 'garrett'))); $this->assertEqual($result, $expected); $result = $TestModel->hasMany; $expected = array(); $this->assertEqual($result, $expected); $result = $TestModel->bindModel(array('hasMany' => array( 'Comment' => array('className' => 'Comment', 'conditions' => 'Comment.published = \'Y\'') ))); $this->assertTrue($result); $result = $TestModel->find('all', array('fields' => 'User.id, User.user')); $expected = array( array( 'User' => array( 'id' => '1', 'user' => 'mariano' ), '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' => '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( 'User' => array( 'id' => '2', 'user' => 'nate' ), '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' => '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( 'User' => array( 'id' => '3', 'user' => 'larry' ), 'Comment' => array() ), array( 'User' => array( 'id' => '4', 'user' => 'garrett' ), 'Comment' => 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' )))); $this->assertEqual($result, $expected); $TestModel2 =& new DeviceType(); $expected = array( 'className' => 'FeatureSet', 'foreignKey' => 'feature_set_id', 'conditions' => '', 'fields' => '', 'order' => '', 'counterCache' => '' ); $this->assertEqual($TestModel2->belongsTo['FeatureSet'], $expected); $TestModel2->bindModel(array( 'belongsTo' => array( 'FeatureSet' => array( 'className' => 'FeatureSet', 'conditions' => array('active' => true) ) ) )); $expected['conditions'] = array('active' => true); $this->assertEqual($TestModel2->belongsTo['FeatureSet'], $expected); $TestModel2->bindModel(array( 'belongsTo' => array( 'FeatureSet' => array( 'className' => 'FeatureSet', 'foreignKey' => false, 'conditions' => array('Feature.name' => 'DeviceType.name') ) ) )); $expected['conditions'] = array('Feature.name' => 'DeviceType.name'); $expected['foreignKey'] = false; $this->assertEqual($TestModel2->belongsTo['FeatureSet'], $expected); $TestModel2->bindModel(array( 'hasMany' => array( 'NewFeatureSet' => array( 'className' => 'FeatureSet', 'conditions' => array('active' => true) ) ) )); $expected = array( 'className' => 'FeatureSet', 'conditions' => array('active' => true), 'foreignKey' => 'device_type_id', 'fields' => '', 'order' => '', 'limit' => '', 'offset' => '', 'dependent' => '', 'exclusive' => '', 'finderQuery' => '', 'counterQuery' => '' ); $this->assertEqual($TestModel2->hasMany['NewFeatureSet'], $expected); $this->assertTrue(is_object($TestModel2->NewFeatureSet)); }
testBindUnbind method @access public @return void
testBindUnbind
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testBindMultipleTimes() { $this->loadFixtures('User', 'Comment', 'Article'); $TestModel =& new User(); $result = $TestModel->hasMany; $expected = array(); $this->assertEqual($result, $expected); $result = $TestModel->bindModel(array( 'hasMany' => array( 'Items' => array('className' => 'Comment') ))); $this->assertTrue($result); $result = $TestModel->find('all', array( 'fields' => 'User.id, User.user' )); $expected = array( array( 'User' => array( 'id' => '1', 'user' => 'mariano' ), 'Items' => 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( 'User' => array( 'id' => '2', 'user' => 'nate' ), 'Items' => 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' => '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( 'User' => array( 'id' => '3', 'user' => 'larry' ), 'Items' => array() ), array( 'User' => array( 'id' => '4', 'user' => 'garrett'), 'Items' => 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' )))); $this->assertEqual($result, $expected); $result = $TestModel->bindModel(array( 'hasMany' => array( 'Items' => array('className' => 'Article') ))); $this->assertTrue($result); $result = $TestModel->find('all', array( 'fields' => 'User.id, User.user' )); $expected = array( array( 'User' => array( 'id' => '1', 'user' => 'mariano' ), 'Items' => 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( 'User' => array( 'id' => '2', 'user' => 'nate' ), 'Items' => array() ), array( 'User' => array( 'id' => '3', 'user' => 'larry' ), 'Items' => 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( 'User' => array( 'id' => '4', 'user' => 'garrett' ), 'Items' => array() )); $this->assertEqual($result, $expected); }
testBindMultipleTimes method @access public @return void
testBindMultipleTimes
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testBindModelMultipleTimesResetCorrectly() { $this->loadFixtures('User', 'Comment', 'Article'); $TestModel =& new User(); $TestModel->bindModel(array('hasMany' => array('Comment'))); $TestModel->bindModel(array('hasMany' => array('Comment'))); $TestModel->resetAssociations(); $this->assertFalse(isset($TestModel->hasMany['Comment']), 'Association left behind'); }
test that multiple reset = true calls to bindModel() result in the original associations. @return void
testBindModelMultipleTimesResetCorrectly
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testBindMultipleTimesWithDifferentResetSettings() { $this->loadFixtures('User', 'Comment', 'Article'); $TestModel =& new User(); $result = $TestModel->hasMany; $expected = array(); $this->assertEqual($result, $expected); $result = $TestModel->bindModel(array( 'hasMany' => array('Comment') )); $this->assertTrue($result); $result = $TestModel->bindModel( array('hasMany' => array('Article')), false ); $this->assertTrue($result); $result = array_keys($TestModel->hasMany); $expected = array('Comment', 'Article'); $this->assertEqual($result, $expected); $TestModel->resetAssociations(); $result = array_keys($TestModel->hasMany); $expected = array('Article'); $this->assertEqual($result, $expected); }
testBindMultipleTimes method with different reset settings @access public @return void
testBindMultipleTimesWithDifferentResetSettings
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testBindWithCustomPrimaryKey() { $this->loadFixtures('Story', 'StoriesTag', 'Tag'); $Model =& ClassRegistry::init('StoriesTag'); $Model->bindModel(array( 'belongsTo' => array( 'Tag' => array( 'className' => 'Tag', 'foreignKey' => 'story' )))); $result = $Model->find('all'); $this->assertFalse(empty($result)); }
test that bindModel behaves with Custom primary Key associations @return void
testBindWithCustomPrimaryKey
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testUnbindMultipleTimesResetCorrectly() { $this->loadFixtures('User', 'Comment', 'Article'); $TestModel =& new Article10(); $TestModel->unbindModel(array('hasMany' => array('Comment'))); $TestModel->unbindModel(array('hasMany' => array('Comment'))); $TestModel->resetAssociations(); $this->assertTrue(isset($TestModel->hasMany['Comment']), 'Association permanently removed'); }
test that calling unbindModel() with reset == true multiple times leaves associations in the correct state. @return void
testUnbindMultipleTimesResetCorrectly
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testUnBindMultipleTimesWithDifferentResetSettings() { $this->loadFixtures('User', 'Comment', 'Article'); $TestModel =& new Comment(); $result = array_keys($TestModel->belongsTo); $expected = array('Article', 'User'); $this->assertEqual($result, $expected); $result = $TestModel->unbindModel(array( 'belongsTo' => array('User') )); $this->assertTrue($result); $result = $TestModel->unbindModel( array('belongsTo' => array('Article')), false ); $this->assertTrue($result); $result = array_keys($TestModel->belongsTo); $expected = array(); $this->assertEqual($result, $expected); $TestModel->resetAssociations(); $result = array_keys($TestModel->belongsTo); $expected = array('User'); $this->assertEqual($result, $expected); }
testBindMultipleTimes method with different reset settings @access public @return void
testUnBindMultipleTimesWithDifferentResetSettings
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testAssociationAfterFind() { $this->loadFixtures('Post', 'Author', 'Comment'); $TestModel =& new Post(); $result = $TestModel->find('all'); $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' ), 'Author' => array( 'id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'test' => 'working' )), 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' ), 'Author' => array( 'id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31', 'test' => 'working' )), 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' ), 'Author' => array( 'id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'test' => 'working' ))); $this->assertEqual($result, $expected); unset($TestModel); $Author =& new Author(); $Author->Post->bindModel(array( 'hasMany' => array( 'Comment' => array( 'className' => 'ModifiedComment', 'foreignKey' => 'article_id', ) ))); $result = $Author->find('all', array( 'conditions' => array('Author.id' => 1), 'recursive' => 2 )); $expected = 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', 'callback' => 'Fire' ); $this->assertEqual($result[0]['Post'][0]['Comment'][0], $expected); }
testAssociationAfterFind method @access public @return void
testAssociationAfterFind
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testCallbackDisabling() { $this->loadFixtures('Author'); $TestModel = new ModifiedAuthor(); $result = Set::extract($TestModel->find('all'), '/Author/user'); $expected = array('mariano (CakePHP)', 'nate (CakePHP)', 'larry (CakePHP)', 'garrett (CakePHP)'); $this->assertEqual($result, $expected); $result = Set::extract($TestModel->find('all', array('callbacks' => 'after')), '/Author/user'); $expected = array('mariano (CakePHP)', 'nate (CakePHP)', 'larry (CakePHP)', 'garrett (CakePHP)'); $this->assertEqual($result, $expected); $result = Set::extract($TestModel->find('all', array('callbacks' => 'before')), '/Author/user'); $expected = array('mariano', 'nate', 'larry', 'garrett'); $this->assertEqual($result, $expected); $result = Set::extract($TestModel->find('all', array('callbacks' => false)), '/Author/user'); $expected = array('mariano', 'nate', 'larry', 'garrett'); $this->assertEqual($result, $expected); }
Tests that callbacks can be properly disabled @access public @return void
testCallbackDisabling
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testCallbackSourceChange() { $this->loadFixtures('Post'); $TestModel = new Post(); $this->assertEqual(3, count($TestModel->find('all'))); $this->expectError(new PatternExpectation('/Non-existent data source foo/i')); $this->assertFalse($TestModel->find('all', array('connection' => 'foo'))); }
Tests that the database configuration assigned to the model can be changed using (before|after)Find callbacks @access public @return void
testCallbackSourceChange
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testMultipleBelongsToWithSameClass() { $this->loadFixtures( 'DeviceType', 'DeviceTypeCategory', 'FeatureSet', 'ExteriorTypeCategory', 'Document', 'Device', 'DocumentDirectory' ); $DeviceType =& new DeviceType(); $DeviceType->recursive = 2; $result = $DeviceType->read(null, 1); $expected = array( 'DeviceType' => array( 'id' => 1, 'device_type_category_id' => 1, 'feature_set_id' => 1, 'exterior_type_category_id' => 1, 'image_id' => 1, 'extra1_id' => 1, 'extra2_id' => 1, 'name' => 'DeviceType 1', 'order' => 0 ), 'Image' => array( 'id' => 1, 'document_directory_id' => 1, 'name' => 'Document 1', 'DocumentDirectory' => array( 'id' => 1, 'name' => 'DocumentDirectory 1' )), 'Extra1' => array( 'id' => 1, 'document_directory_id' => 1, 'name' => 'Document 1', 'DocumentDirectory' => array( 'id' => 1, 'name' => 'DocumentDirectory 1' )), 'Extra2' => array( 'id' => 1, 'document_directory_id' => 1, 'name' => 'Document 1', 'DocumentDirectory' => array( 'id' => 1, 'name' => 'DocumentDirectory 1' )), 'DeviceTypeCategory' => array( 'id' => 1, 'name' => 'DeviceTypeCategory 1' ), 'FeatureSet' => array( 'id' => 1, 'name' => 'FeatureSet 1' ), 'ExteriorTypeCategory' => array( 'id' => 1, 'image_id' => 1, 'name' => 'ExteriorTypeCategory 1', 'Image' => array( 'id' => 1, 'device_type_id' => 1, 'name' => 'Device 1', 'typ' => 1 )), 'Device' => array( array( 'id' => 1, 'device_type_id' => 1, 'name' => 'Device 1', 'typ' => 1 ), array( 'id' => 2, 'device_type_id' => 1, 'name' => 'Device 2', 'typ' => 1 ), array( 'id' => 3, 'device_type_id' => 1, 'name' => 'Device 3', 'typ' => 2 ))); $this->assertEqual($result, $expected); }
testMultipleBelongsToWithSameClass method @access public @return void
testMultipleBelongsToWithSameClass
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testHabtmRecursiveBelongsTo() { $this->loadFixtures('Portfolio', 'Item', 'ItemsPortfolio', 'Syfile', 'Image'); $Portfolio =& new Portfolio(); $result = $Portfolio->find(array('id' => 2), null, null, 3); $expected = array( 'Portfolio' => array( 'id' => 2, 'seller_id' => 1, 'name' => 'Portfolio 2' ), 'Item' => array( array( 'id' => 2, 'syfile_id' => 2, 'published' => 0, 'name' => 'Item 2', 'ItemsPortfolio' => array( 'id' => 2, 'item_id' => 2, 'portfolio_id' => 2 ), 'Syfile' => array( 'id' => 2, 'image_id' => 2, 'name' => 'Syfile 2', 'item_count' => null, 'Image' => array( 'id' => 2, 'name' => 'Image 2' ) )), array( 'id' => 6, 'syfile_id' => 6, 'published' => 0, 'name' => 'Item 6', 'ItemsPortfolio' => array( 'id' => 6, 'item_id' => 6, 'portfolio_id' => 2 ), 'Syfile' => array( 'id' => 6, 'image_id' => null, 'name' => 'Syfile 6', 'item_count' => null, 'Image' => array() )))); $this->assertEqual($result, $expected); }
testHabtmRecursiveBelongsTo method @access public @return void
testHabtmRecursiveBelongsTo
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testHabtmFinderQuery() { $this->loadFixtures('Article', 'Tag', 'ArticlesTag'); $Article =& new Article(); $sql = $this->db->buildStatement( array( 'fields' => $this->db->fields($Article->Tag, null, array( 'Tag.id', 'Tag.tag', 'ArticlesTag.article_id', 'ArticlesTag.tag_id' )), 'table' => $this->db->fullTableName('tags'), 'alias' => 'Tag', 'limit' => null, 'offset' => null, 'group' => null, 'joins' => array(array( 'alias' => 'ArticlesTag', 'table' => 'articles_tags', 'conditions' => array( array("ArticlesTag.article_id" => '{$__cakeID__$}'), array("ArticlesTag.tag_id" => $this->db->identifier('Tag.id')) ) )), 'conditions' => array(), 'order' => null ), $Article ); $Article->hasAndBelongsToMany['Tag']['finderQuery'] = $sql; $result = $Article->find('first'); $expected = array( array( 'id' => '1', 'tag' => 'tag1' ), array( 'id' => '2', 'tag' => 'tag2' )); $this->assertEqual($result['Tag'], $expected); }
testHabtmFinderQuery method @access public @return void
testHabtmFinderQuery
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testFindAllRecursiveSelfJoin() { $this->loadFixtures('Home', 'AnotherArticle', 'Advertisement'); $TestModel =& new Home(); $TestModel->recursive = 2; $result = $TestModel->find('all'); $expected = array( array( 'Home' => array( 'id' => '1', 'another_article_id' => '1', 'advertisement_id' => '1', 'title' => 'First Home', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), 'AnotherArticle' => array( 'id' => '1', 'title' => 'First Article', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Home' => array( array( 'id' => '1', 'another_article_id' => '1', 'advertisement_id' => '1', 'title' => 'First Home', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ))), 'Advertisement' => array( 'id' => '1', 'title' => 'First Ad', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Home' => array( array( 'id' => '1', 'another_article_id' => '1', 'advertisement_id' => '1', 'title' => 'First Home', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), array( 'id' => '2', 'another_article_id' => '3', 'advertisement_id' => '1', 'title' => 'Second Home', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' )))), array( 'Home' => array( 'id' => '2', 'another_article_id' => '3', 'advertisement_id' => '1', 'title' => 'Second Home', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ), 'AnotherArticle' => array( 'id' => '3', 'title' => 'Third Article', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', 'Home' => array( array( 'id' => '2', 'another_article_id' => '3', 'advertisement_id' => '1', 'title' => 'Second Home', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ))), 'Advertisement' => array( 'id' => '1', 'title' => 'First Ad', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', 'Home' => array( array( 'id' => '1', 'another_article_id' => '1', 'advertisement_id' => '1', 'title' => 'First Home', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), array( 'id' => '2', 'another_article_id' => '3', 'advertisement_id' => '1', 'title' => 'Second Home', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' ))))); $this->assertEqual($result, $expected); }
testFindAllRecursiveSelfJoin method @access public @return void
testFindAllRecursiveSelfJoin
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testFindAllRecursiveWithHabtm() { $this->loadFixtures( 'MyCategoriesMyUsers', 'MyCategoriesMyProducts', 'MyCategory', 'MyUser', 'MyProduct' ); $MyUser =& new MyUser(); $MyUser->recursive = 2; $result = $MyUser->find('all'); $expected = array( array( 'MyUser' => array('id' => '1', 'firstname' => 'userA'), 'MyCategory' => array( array( 'id' => '1', 'name' => 'A', 'MyProduct' => array( array( 'id' => '1', 'name' => 'book' ))), array( 'id' => '3', 'name' => 'C', 'MyProduct' => array( array( 'id' => '2', 'name' => 'computer' ))))), array( 'MyUser' => array( 'id' => '2', 'firstname' => 'userB' ), 'MyCategory' => array( array( 'id' => '1', 'name' => 'A', 'MyProduct' => array( array( 'id' => '1', 'name' => 'book' ))), array( 'id' => '2', 'name' => 'B', 'MyProduct' => array( array( 'id' => '1', 'name' => 'book' ), array( 'id' => '2', 'name' => 'computer' )))))); $this->assertIdentical($result, $expected); }
testFindAllRecursiveWithHabtm method @return void @access public
testFindAllRecursiveWithHabtm
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testReadFakeThread() { $this->loadFixtures('CategoryThread'); $TestModel =& new CategoryThread(); $fullDebug = $this->db->fullDebug; $this->db->fullDebug = true; $TestModel->recursive = 6; $TestModel->id = 7; $result = $TestModel->read(); $expected = array( 'CategoryThread' => array( 'id' => 7, 'parent_id' => 6, 'name' => 'Category 2.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'ParentCategory' => array( 'id' => 6, 'parent_id' => 5, 'name' => 'Category 2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 5, 'parent_id' => 4, 'name' => 'Category 1.1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 4, 'parent_id' => 3, 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 3, 'parent_id' => 2, 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ))))))); $this->db->fullDebug = $fullDebug; $this->assertEqual($result, $expected); }
testReadFakeThread method @access public @return void
testReadFakeThread
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testFindFakeThread() { $this->loadFixtures('CategoryThread'); $TestModel =& new CategoryThread(); $fullDebug = $this->db->fullDebug; $this->db->fullDebug = true; $TestModel->recursive = 6; $result = $TestModel->find(array('CategoryThread.id' => 7)); $expected = array( 'CategoryThread' => array( 'id' => 7, 'parent_id' => 6, 'name' => 'Category 2.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'ParentCategory' => array( 'id' => 6, 'parent_id' => 5, 'name' => 'Category 2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 5, 'parent_id' => 4, 'name' => 'Category 1.1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 4, 'parent_id' => 3, 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 3, 'parent_id' => 2, 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ))))))); $this->db->fullDebug = $fullDebug; $this->assertEqual($result, $expected); }
testFindFakeThread method @access public @return void
testFindFakeThread
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testFindAllFakeThread() { $this->loadFixtures('CategoryThread'); $TestModel =& new CategoryThread(); $fullDebug = $this->db->fullDebug; $this->db->fullDebug = true; $TestModel->recursive = 6; $result = $TestModel->find('all', null, null, 'CategoryThread.id ASC'); $expected = array( array( 'CategoryThread' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'ParentCategory' => array( 'id' => null, 'parent_id' => null, 'name' => null, 'created' => null, 'updated' => null, 'ParentCategory' => array() )), array( 'CategoryThread' => array( 'id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'ParentCategory' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array() )), array( 'CategoryThread' => array( 'id' => 3, 'parent_id' => 2, 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'ParentCategory' => array( 'id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array() ))), array( 'CategoryThread' => array( 'id' => 4, 'parent_id' => 3, 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'ParentCategory' => array( 'id' => 3, 'parent_id' => 2, 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array() )))), array( 'CategoryThread' => array( 'id' => 5, 'parent_id' => 4, 'name' => 'Category 1.1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'ParentCategory' => array( 'id' => 4, 'parent_id' => 3, 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 3, 'parent_id' => 2, 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array() ))))), array( 'CategoryThread' => array( 'id' => 6, 'parent_id' => 5, 'name' => 'Category 2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'ParentCategory' => array( 'id' => 5, 'parent_id' => 4, 'name' => 'Category 1.1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 4, 'parent_id' => 3, 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 3, 'parent_id' => 2, 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array() )))))), array( 'CategoryThread' => array( 'id' => 7, 'parent_id' => 6, 'name' => 'Category 2.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' ), 'ParentCategory' => array( 'id' => 6, 'parent_id' => 5, 'name' => 'Category 2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 5, 'parent_id' => 4, 'name' => 'Category 1.1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 4, 'parent_id' => 3, 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 3, 'parent_id' => 2, 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' )))))))); $this->db->fullDebug = $fullDebug; $this->assertEqual($result, $expected); }
testFindAllFakeThread method @access public @return void
testFindAllFakeThread
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testConditionalNumerics() { $this->loadFixtures('NumericArticle'); $NumericArticle =& new NumericArticle(); $data = array('title' => '12345abcde'); $result = $NumericArticle->find($data); $this->assertTrue(!empty($result)); $data = array('title' => '12345'); $result = $NumericArticle->find($data); $this->assertTrue(empty($result)); }
testConditionalNumerics method @access public @return void
testConditionalNumerics
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testFindAll() { $this->loadFixtures('User'); $TestModel =& new User(); $TestModel->cacheQueries = false; $result = $TestModel->find('all'); $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' )), array( 'User' => array( 'id' => '2', 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' )), array( 'User' => array( 'id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' )), array( 'User' => array( 'id' => '4', 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ))); $this->assertEqual($result, $expected); $result = $TestModel->find('all', array('conditions' => 'User.id > 2')); $expected = array( array( 'User' => array( 'id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' )), array( 'User' => array( 'id' => '4', 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ))); $this->assertEqual($result, $expected); $result = $TestModel->find('all', array( 'conditions' => array('User.id !=' => '0', 'User.user LIKE' => '%arr%') )); $expected = array( array( 'User' => array( 'id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' )), array( 'User' => array( 'id' => '4', 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ))); $this->assertEqual($result, $expected); $result = $TestModel->find('all', array('conditions' => array('User.id' => '0'))); $expected = array(); $this->assertEqual($result, $expected); $result = $TestModel->find('all', array( 'conditions' => array('or' => array('User.id' => '0', 'User.user LIKE' => '%a%') ))); $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' )), array( 'User' => array( 'id' => '2', 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' )), array( 'User' => array( 'id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' )), array( 'User' => array( 'id' => '4', 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ))); $this->assertEqual($result, $expected); $result = $TestModel->find('all', array('fields' => 'User.id, User.user')); $expected = array( array('User' => array('id' => '1', 'user' => 'mariano')), array('User' => array('id' => '2', 'user' => 'nate')), array('User' => array('id' => '3', 'user' => 'larry')), array('User' => array('id' => '4', 'user' => 'garrett'))); $this->assertEqual($result, $expected); $result = $TestModel->find('all', array('fields' => 'User.user', 'order' => 'User.user ASC')); $expected = array( array('User' => array('user' => 'garrett')), array('User' => array('user' => 'larry')), array('User' => array('user' => 'mariano')), array('User' => array('user' => 'nate'))); $this->assertEqual($result, $expected); $result = $TestModel->find('all', array('fields' => 'User.user', 'order' => 'User.user DESC')); $expected = array( array('User' => array('user' => 'nate')), array('User' => array('user' => 'mariano')), array('User' => array('user' => 'larry')), array('User' => array('user' => 'garrett'))); $this->assertEqual($result, $expected); $result = $TestModel->find('all', array('limit' => 3, 'page' => 1)); $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' )), array( 'User' => array( 'id' => '2', 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' )), array( 'User' => array( 'id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' ))); $this->assertEqual($result, $expected); $ids = array(4 => 1, 5 => 3); $result = $TestModel->find('all', array( 'conditions' => array('User.id' => $ids), 'order' => 'User.id' )); $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' )), array( 'User' => array( 'id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31' ))); $this->assertEqual($result, $expected); // These tests are expected to fail on SQL Server since the LIMIT/OFFSET // hack can't handle small record counts. if ($this->db->config['driver'] != 'mssql') { $result = $TestModel->find('all', array('limit' => 3, 'page' => 2)); $expected = array( array( 'User' => array( 'id' => '4', 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31' ))); $this->assertEqual($result, $expected); $result = $TestModel->find('all', array('limit' => 3, 'page' => 3)); $expected = array(); $this->assertEqual($result, $expected); } }
test find('all') method @access public @return void
testFindAll
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testGenerateFindList() { $this->loadFixtures('Article', 'Apple', 'Post', 'Author', 'User'); $TestModel =& new Article(); $TestModel->displayField = 'title'; $result = $TestModel->find('list', array( 'order' => 'Article.title ASC' )); $expected = array( 1 => 'First Article', 2 => 'Second Article', 3 => 'Third Article' ); $this->assertEqual($result, $expected); $db =& ConnectionManager::getDataSource('test_suite'); if ($db->config['driver'] == 'mysql') { $result = $TestModel->find('list', array( 'order' => array('FIELD(Article.id, 3, 2) ASC', 'Article.title ASC') )); $expected = array( 1 => 'First Article', 3 => 'Third Article', 2 => 'Second Article' ); $this->assertEqual($result, $expected); } $result = Set::combine( $TestModel->find('all', array( 'order' => 'Article.title ASC', 'fields' => array('id', 'title') )), '{n}.Article.id', '{n}.Article.title' ); $expected = array( 1 => 'First Article', 2 => 'Second Article', 3 => 'Third Article' ); $this->assertEqual($result, $expected); $result = Set::combine( $TestModel->find('all', array( 'order' => 'Article.title ASC' )), '{n}.Article.id', '{n}.Article' ); $expected = array( 1 => 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' ), 2 => 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' ), 3 => 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 = Set::combine( $TestModel->find('all', array( 'order' => 'Article.title ASC' )), '{n}.Article.id', '{n}.Article', '{n}.Article.user_id' ); $expected = array( 1 => array( 1 => 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' ), 3 => 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' )), 3 => array( 2 => 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' ))); $this->assertEqual($result, $expected); $result = Set::combine( $TestModel->find('all', array( 'order' => 'Article.title ASC', 'fields' => array('id', 'title', 'user_id') )), '{n}.Article.id', '{n}.Article.title', '{n}.Article.user_id' ); $expected = array( 1 => array( 1 => 'First Article', 3 => 'Third Article' ), 3 => array( 2 => 'Second Article' )); $this->assertEqual($result, $expected); $TestModel =& new Apple(); $expected = array( 1 => 'Red Apple 1', 2 => 'Bright Red Apple', 3 => 'green blue', 4 => 'Test Name', 5 => 'Blue Green', 6 => 'My new apple', 7 => 'Some odd color' ); $this->assertEqual($TestModel->find('list'), $expected); $this->assertEqual($TestModel->Parent->find('list'), $expected); $TestModel =& new Post(); $result = $TestModel->find('list', array( 'fields' => 'Post.title' )); $expected = array( 1 => 'First Post', 2 => 'Second Post', 3 => 'Third Post' ); $this->assertEqual($result, $expected); $result = $TestModel->find('list', array( 'fields' => 'title' )); $expected = array( 1 => 'First Post', 2 => 'Second Post', 3 => 'Third Post' ); $this->assertEqual($result, $expected); $result = $TestModel->find('list', array( 'fields' => array('title', 'id') )); $expected = array( 'First Post' => '1', 'Second Post' => '2', 'Third Post' => '3' ); $this->assertEqual($result, $expected); $result = $TestModel->find('list', array( 'fields' => array('title', 'id', 'created') )); $expected = array( '2007-03-18 10:39:23' => array( 'First Post' => '1' ), '2007-03-18 10:41:23' => array( 'Second Post' => '2' ), '2007-03-18 10:43:23' => array( 'Third Post' => '3' ), ); $this->assertEqual($result, $expected); $result = $TestModel->find('list', array( 'fields' => array('Post.body') )); $expected = array( 1 => 'First Post Body', 2 => 'Second Post Body', 3 => 'Third Post Body' ); $this->assertEqual($result, $expected); $result = $TestModel->find('list', array( 'fields' => array('Post.title', 'Post.body') )); $expected = array( 'First Post' => 'First Post Body', 'Second Post' => 'Second Post Body', 'Third Post' => 'Third Post Body' ); $this->assertEqual($result, $expected); $result = $TestModel->find('list', array( 'fields' => array('Post.id', 'Post.title', 'Author.user'), 'recursive' => 1 )); $expected = array( 'mariano' => array( 1 => 'First Post', 3 => 'Third Post' ), 'larry' => array( 2 => 'Second Post' )); $this->assertEqual($result, $expected); $TestModel =& new User(); $result = $TestModel->find('list', array( 'fields' => array('User.user', 'User.password') )); $expected = array( 'mariano' => '5f4dcc3b5aa765d61d8327deb882cf99', 'nate' => '5f4dcc3b5aa765d61d8327deb882cf99', 'larry' => '5f4dcc3b5aa765d61d8327deb882cf99', 'garrett' => '5f4dcc3b5aa765d61d8327deb882cf99' ); $this->assertEqual($result, $expected); $TestModel =& new ModifiedAuthor(); $result = $TestModel->find('list', array( 'fields' => array('Author.id', 'Author.user') )); $expected = array( 1 => 'mariano (CakePHP)', 2 => 'nate (CakePHP)', 3 => 'larry (CakePHP)', 4 => 'garrett (CakePHP)' ); $this->assertEqual($result, $expected); $TestModel =& new Article(); $TestModel->displayField = 'title'; $result = $TestModel->find('list', array( 'conditions' => array('User.user' => 'mariano'), 'recursive' => 0 )); $expected = array( 1 => 'First Article', 3 => 'Third Article' ); $this->assertEqual($result, $expected); }
test find('list') method @access public @return void
testGenerateFindList
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testFindField() { $this->loadFixtures('User'); $TestModel =& new User(); $TestModel->id = 1; $result = $TestModel->field('user'); $this->assertEqual($result, 'mariano'); $result = $TestModel->field('User.user'); $this->assertEqual($result, 'mariano'); $TestModel->id = false; $result = $TestModel->field('user', array( 'user' => 'mariano' )); $this->assertEqual($result, 'mariano'); $result = $TestModel->field('COUNT(*) AS count', true); $this->assertEqual($result, 4); $result = $TestModel->field('COUNT(*)', true); $this->assertEqual($result, 4); }
testFindField method @access public @return void
testFindField
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testFindUnique() { $this->loadFixtures('User'); $TestModel =& new User(); $this->assertFalse($TestModel->isUnique(array( 'user' => 'nate' ))); $TestModel->id = 2; $this->assertTrue($TestModel->isUnique(array( 'user' => 'nate' ))); $this->assertFalse($TestModel->isUnique(array( 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ))); }
testFindUnique method @access public @return void
testFindUnique
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testFindCount() { $this->loadFixtures('User', 'Project'); $TestModel =& new User(); $result = $TestModel->find('count'); $this->assertEqual($result, 4); $fullDebug = $this->db->fullDebug; $this->db->fullDebug = true; $TestModel->order = 'User.id'; $this->db->_queriesLog = array(); $result = $TestModel->find('count'); $this->assertEqual($result, 4); $this->assertTrue(isset($this->db->_queriesLog[0]['query'])); $this->assertNoPattern('/ORDER\s+BY/', $this->db->_queriesLog[0]['query']); }
test find('count') method @access public @return void
testFindCount
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testFindFirstNoIdUsed() { $this->loadFixtures('Project'); $Project =& new Project(); $Project->id = 3; $result = $Project->find('first'); $this->assertEqual($result['Project']['name'], 'Project 1', 'Wrong record retrieved'); }
Test that find('first') does not use the id set to the object. @return void
testFindFirstNoIdUsed
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testFindCountDistinct() { $skip = $this->skipIf( $this->db->config['driver'] == 'sqlite', 'SELECT COUNT(DISTINCT field) is not compatible with SQLite' ); if ($skip) { return; } $this->loadFixtures('Project'); $TestModel =& new Project(); $TestModel->create(array('name' => 'project')) && $TestModel->save(); $TestModel->create(array('name' => 'project')) && $TestModel->save(); $TestModel->create(array('name' => 'project')) && $TestModel->save(); $result = $TestModel->find('count', array('fields' => 'DISTINCT name')); $this->assertEqual($result, 4); }
test find with COUNT(DISTINCT field) @return void
testFindCountDistinct
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testFindCountWithDbExpressions() { if ($this->skipIf($this->db->config['driver'] == 'postgres', '%s testFindCountWithExpressions is not compatible with Postgres')) { return; } $this->loadFixtures('Project'); $db = ConnectionManager::getDataSource('test_suite'); $TestModel =& new Project(); $result = $TestModel->find('count', array('conditions' => array( $db->expression('Project.name = \'Project 3\'') ))); $this->assertEqual($result, 1); $result = $TestModel->find('count', array('conditions' => array( 'Project.name' => $db->expression('\'Project 3\'') ))); $this->assertEqual($result, 1); }
Test find(count) with Db::expression @access public @return void
testFindCountWithDbExpressions
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testFindMagic() { $this->loadFixtures('User'); $TestModel =& new User(); $result = $TestModel->findByUser('mariano'); $expected = array( '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 = $TestModel->findByPassword('5f4dcc3b5aa765d61d8327deb882cf99'); $expected = array('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); }
testFindMagic method @access public @return void
testFindMagic
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testRead() { $this->loadFixtures('User', 'Article'); $TestModel =& new User(); $result = $TestModel->read(); $this->assertFalse($result); $TestModel->id = 2; $result = $TestModel->read(); $expected = array( 'User' => array( 'id' => '2', 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' )); $this->assertEqual($result, $expected); $result = $TestModel->read(null, 2); $expected = array( 'User' => array( 'id' => '2', 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' )); $this->assertEqual($result, $expected); $TestModel->id = 2; $result = $TestModel->read(array('id', 'user')); $expected = array('User' => array('id' => '2', 'user' => 'nate')); $this->assertEqual($result, $expected); $result = $TestModel->read('id, user', 2); $expected = array( 'User' => array( 'id' => '2', 'user' => 'nate' )); $this->assertEqual($result, $expected); $result = $TestModel->bindModel(array('hasMany' => array('Article'))); $this->assertTrue($result); $TestModel->id = 1; $result = $TestModel->read('id, user'); $expected = array( 'User' => array( 'id' => '1', 'user' => 'mariano' ), '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' ))); $this->assertEqual($result, $expected); }
testRead method @access public @return void
testRead
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testRecursiveRead() { $this->loadFixtures( 'User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Featured', 'ArticleFeatured' ); $TestModel =& new User(); $result = $TestModel->bindModel(array('hasMany' => array('Article')), false); $this->assertTrue($result); $TestModel->recursive = 0; $result = $TestModel->read('id, user', 1); $expected = array( 'User' => array('id' => '1', 'user' => 'mariano'), ); $this->assertEqual($result, $expected); $TestModel->recursive = 1; $result = $TestModel->read('id, user', 1); $expected = array( 'User' => array( 'id' => '1', 'user' => 'mariano' ), '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' ))); $this->assertEqual($result, $expected); $TestModel->recursive = 2; $result = $TestModel->read('id, user', 3); $expected = array( 'User' => array( 'id' => '3', 'user' => 'larry' ), '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', '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' )), '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' ))))); $this->assertEqual($result, $expected); }
testRecursiveRead method @access public @return void
testRecursiveRead
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testFindQueryTypeInCallbacks() { $this->loadFixtures('Comment'); $Comment =& new AgainModifiedComment(); $comments = $Comment->find('all'); $this->assertEqual($comments[0]['Comment']['querytype'], 'all'); $comments = $Comment->find('first'); $this->assertEqual($comments['Comment']['querytype'], 'first'); }
Testing availability of $this->findQueryType in Model callbacks @return void
testFindQueryTypeInCallbacks
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testVirtualFields() { $this->loadFixtures('Post', 'Author'); $Post =& ClassRegistry::init('Post'); $Post->virtualFields = array('two' => "1 + 1"); $result = $Post->find('first'); $this->assertEqual($result['Post']['two'], 2); $Post->Author->virtualFields = array('false' => '1 = 2'); $result = $Post->find('first'); $this->assertEqual($result['Post']['two'], 2); $this->assertEqual($result['Author']['false'], false); $result = $Post->find('first',array('fields' => array('author_id'))); $this->assertFalse(isset($result['Post']['two'])); $this->assertFalse(isset($result['Author']['false'])); $result = $Post->find('first',array('fields' => array('author_id', 'two'))); $this->assertEqual($result['Post']['two'], 2); $this->assertFalse(isset($result['Author']['false'])); $result = $Post->find('first',array('fields' => array('two'))); $this->assertEqual($result['Post']['two'], 2); $Post->id = 1; $result = $Post->field('two'); $this->assertEqual($result, 2); $result = $Post->find('first',array( 'conditions' => array('two' => 2), 'limit' => 1 )); $this->assertEqual($result['Post']['two'], 2); $result = $Post->find('first',array( 'conditions' => array('two <' => 3), 'limit' => 1 )); $this->assertEqual($result['Post']['two'], 2); $result = $Post->find('first',array( 'conditions' => array('NOT' => array('two >' => 3)), 'limit' => 1 )); $this->assertEqual($result['Post']['two'], 2); $dbo =& $Post->getDataSource(); $Post->virtualFields = array('other_field' => 'Post.id + 1'); $result = $Post->find('first', array( 'conditions' => array('other_field' => 3), 'limit' => 1 )); $this->assertEqual($result['Post']['id'], 2); $Post->virtualFields = array('other_field' => 'Post.id + 1'); $result = $Post->find('all', array( 'fields' => array($dbo->calculate($Post, 'max', array('other_field'))) )); $this->assertEqual($result[0][0]['other_field'], 4); ClassRegistry::flush(); $Writing =& ClassRegistry::init(array('class' => 'Post', 'alias' => 'Writing'), 'Model'); $Writing->virtualFields = array('two' => "1 + 1"); $result = $Writing->find('first'); $this->assertEqual($result['Writing']['two'], 2); $Post->create(); $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1'); $result = $Post->field('other_field'); $this->assertEqual($result, 4); if ($this->skipIf($this->db->config['driver'] == 'postgres', 'The rest of virtualFieds test is not compatible with Postgres')) { return; } ClassRegistry::flush(); $Post =& ClassRegistry::init('Post'); $Post->create(); $Post->virtualFields = array( 'year' => 'YEAR(Post.created)', 'unique_test_field' => 'COUNT(Post.id)' ); $expectation = array( 'Post' => array( 'year' => 2007, 'unique_test_field' => 3 ) ); $result = $Post->find('first', array( 'fields' => array_keys($Post->virtualFields), 'group' => array('year') )); $this->assertEqual($result, $expectation); $Author =& ClassRegistry::init('Author'); $Author->virtualFields = array( 'full_name' => 'CONCAT(Author.user, " ", Author.id)' ); $result = $Author->find('first', array( 'conditions' => array('Author.user' => 'mariano'), 'fields' => array('Author.password', 'Author.full_name'), 'recursive' => -1 )); $this->assertTrue(isset($result['Author']['full_name'])); $result = $Author->find('first', array( 'conditions' => array('Author.user' => 'mariano'), 'fields' => array('Author.full_name', 'Author.password'), 'recursive' => -1 )); $this->assertTrue(isset($result['Author']['full_name'])); }
testVirtualFields() Test correct fetching of virtual fields currently is not possible to do Relation.virtualField @access public @return void
testVirtualFields
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testVirtualFieldAsAConstant() { $this->loadFixtures('Post', 'Author'); $Post =& ClassRegistry::init('Post'); $Post->virtualFields = array('empty' => "NULL"); $result = $Post->find('first'); $this->assertNull($result['Post']['empty']); }
Test that virtual fields work with SQL constants @return void
testVirtualFieldAsAConstant
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testVirtualFieldAsAString() { $this->loadFixtures('Post', 'Author'); $Post =& new Post(); $Post->virtualFields = array( 'writer' => 'Author.user' ); $result = $Post->find('first'); $this->assertTrue(isset($result['Post']['writer']), 'virtual field not fetched %s'); }
test that virtual fields work when they don't contain functions. @return void
testVirtualFieldAsAString
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testIsVirtualField() { $this->loadFixtures('Post'); $Post =& ClassRegistry::init('Post'); $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1'); $this->assertTrue($Post->isVirtualField('other_field')); $this->assertTrue($Post->isVirtualField('Post.other_field')); $this->assertFalse($Post->isVirtualField('Comment.other_field'), 'Other models should not match.'); $this->assertFalse($Post->isVirtualField('id')); $this->assertFalse($Post->isVirtualField('Post.id')); $this->assertFalse($Post->isVirtualField(array())); }
test that isVirtualField will accept both aliased and non aliased fieldnames @return void
testIsVirtualField
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testGetVirtualField() { $this->loadFixtures('Post'); $Post =& ClassRegistry::init('Post'); $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1'); $this->assertEqual($Post->getVirtualField('other_field'), $Post->virtualFields['other_field']); $this->assertEqual($Post->getVirtualField('Post.other_field'), $Post->virtualFields['other_field']); }
test that getting virtual fields works with and without model alias attached @return void
testGetVirtualField
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_read.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_read.test.php
MIT
function testValidationParams() { $TestModel =& new ValidationTest1(); $TestModel->validate['title'] = array( 'rule' => 'customValidatorWithParams', 'required' => true ); $TestModel->create(array('title' => 'foo')); $TestModel->invalidFields(); $expected = array( 'data' => array( 'title' => 'foo' ), 'validator' => array( 'rule' => 'customValidatorWithParams', 'on' => null, 'last' => false, 'allowEmpty' => false, 'required' => true ), 'or' => true, 'ignore_on_same' => 'id' ); $this->assertEqual($TestModel->validatorParams, $expected); $TestModel->validate['title'] = array( 'rule' => 'customValidatorWithMessage', 'required' => true ); $expected = array( 'title' => 'This field will *never* validate! Muhahaha!' ); $this->assertEqual($TestModel->invalidFields(), $expected); $TestModel->validate['title'] = array( 'rule' => array('customValidatorWithSixParams', 'one', 'two', null, 'four'), 'required' => true ); $TestModel->create(array('title' => 'foo')); $TestModel->invalidFields(); $expected = array( 'data' => array( 'title' => 'foo' ), 'one' => 'one', 'two' => 'two', 'three' => null, 'four' => 'four', 'five' => array( 'rule' => array(1 => 'one', 2 => 'two', 3 => null, 4 => 'four'), 'on' => null, 'last' => false, 'allowEmpty' => false, 'required' => true ), 'six' => 6 ); $this->assertEqual($TestModel->validatorParams, $expected); $TestModel->validate['title'] = array( 'rule' => array('customValidatorWithSixParams', 'one', array('two'), null, 'four', array('five' => 5)), 'required' => true ); $TestModel->create(array('title' => 'foo')); $TestModel->invalidFields(); $expected = array( 'data' => array( 'title' => 'foo' ), 'one' => 'one', 'two' => array('two'), 'three' => null, 'four' => 'four', 'five' => array('five' => 5), 'six' => array( 'rule' => array(1 => 'one', 2 => array('two'), 3 => null, 4 => 'four', 5 => array('five' => 5)), 'on' => null, 'last' => false, 'allowEmpty' => false, 'required' => true ) ); $this->assertEqual($TestModel->validatorParams, $expected); }
Tests validation parameter order in custom validation methods @access public @return void
testValidationParams
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_validation.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_validation.test.php
MIT
function testInvalidFieldsWithFieldListParams() { $TestModel =& new ValidationTest1(); $TestModel->validate = $validate = array( 'title' => array( 'rule' => 'alphaNumeric', 'required' => true ), 'name' => array( 'rule' => 'alphaNumeric', 'required' => true )); $TestModel->set(array('title' => '$$', 'name' => '##')); $TestModel->invalidFields(array('fieldList' => array('title'))); $expected = array( 'title' => 'This field cannot be left blank' ); $this->assertEqual($TestModel->validationErrors, $expected); $TestModel->validationErrors = array(); $TestModel->invalidFields(array('fieldList' => array('name'))); $expected = array( 'name' => 'This field cannot be left blank' ); $this->assertEqual($TestModel->validationErrors, $expected); $TestModel->validationErrors = array(); $TestModel->invalidFields(array('fieldList' => array('name', 'title'))); $expected = array( 'name' => 'This field cannot be left blank', 'title' => 'This field cannot be left blank' ); $this->assertEqual($TestModel->validationErrors, $expected); $TestModel->validationErrors = array(); $TestModel->whitelist = array('name'); $TestModel->invalidFields(); $expected = array('name' => 'This field cannot be left blank'); $this->assertEqual($TestModel->validationErrors, $expected); $this->assertEqual($TestModel->validate, $validate); }
Tests validation parameter fieldList in invalidFields @access public @return void
testInvalidFieldsWithFieldListParams
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_validation.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_validation.test.php
MIT
function testInvalidFieldsWhitelist() { $TestModel =& new ValidationTest1(); $TestModel->validate = array( 'title' => array( 'rule' => 'alphaNumeric', 'required' => true ), 'name' => array( 'rule' => 'alphaNumeric', 'required' => true )); $TestModel->whitelist = array('name'); $TestModel->save(array('name' => '#$$#', 'title' => '$$$$')); $expected = array('name' => 'This field cannot be left blank'); $this->assertEqual($TestModel->validationErrors, $expected); }
Test that invalidFields() integrates well with save(). And that fieldList can be an empty type. @return void
testInvalidFieldsWhitelist
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_validation.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_validation.test.php
MIT
function testValidates() { $TestModel =& new TestValidate(); $TestModel->validate = array( 'user_id' => 'numeric', 'title' => array('allowEmpty' => false, 'rule' => 'notEmpty'), 'body' => 'notEmpty' ); $data = array('TestValidate' => array( 'user_id' => '1', 'title' => '', 'body' => 'body' )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); $data = array('TestValidate' => array( 'user_id' => '1', 'title' => 'title', 'body' => 'body' )); $result = $TestModel->create($data) && $TestModel->validates(); $this->assertTrue($result); $data = array('TestValidate' => array( 'user_id' => '1', 'title' => '0', 'body' => 'body' )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertTrue($result); $data = array('TestValidate' => array( 'user_id' => '1', 'title' => 0, 'body' => 'body' )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertTrue($result); $TestModel->validate['modified'] = array('allowEmpty' => true, 'rule' => 'date'); $data = array('TestValidate' => array( 'user_id' => '1', 'title' => 0, 'body' => 'body', 'modified' => '' )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertTrue($result); $data = array('TestValidate' => array( 'user_id' => '1', 'title' => 0, 'body' => 'body', 'modified' => '2007-05-01' )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertTrue($result); $data = array('TestValidate' => array( 'user_id' => '1', 'title' => 0, 'body' => 'body', 'modified' => 'invalid-date-here' )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); $data = array('TestValidate' => array( 'user_id' => '1', 'title' => 0, 'body' => 'body', 'modified' => 0 )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); $data = array('TestValidate' => array( 'user_id' => '1', 'title' => 0, 'body' => 'body', 'modified' => '0' )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); $TestModel->validate['modified'] = array('allowEmpty' => false, 'rule' => 'date'); $data = array('TestValidate' => array('modified' => null)); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); $data = array('TestValidate' => array('modified' => false)); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); $data = array('TestValidate' => array('modified' => '')); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); $data = array('TestValidate' => array( 'modified' => '2007-05-01' )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertTrue($result); $TestModel->validate['slug'] = array('allowEmpty' => false, 'rule' => array('maxLength', 45)); $data = array('TestValidate' => array( 'user_id' => '1', 'title' => 0, 'body' => 'body', 'slug' => '' )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); $data = array('TestValidate' => array( 'user_id' => '1', 'title' => 0, 'body' => 'body', 'slug' => 'slug-right-here' )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertTrue($result); $data = array('TestValidate' => array( 'user_id' => '1', 'title' => 0, 'body' => 'body', 'slug' => 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz' )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); $TestModel->validate = array( 'number' => array( 'rule' => 'validateNumber', 'min' => 3, 'max' => 5 ), 'title' => array( 'allowEmpty' => false, 'rule' => 'notEmpty' )); $data = array('TestValidate' => array( 'title' => 'title', 'number' => '0' )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); $data = array('TestValidate' => array( 'title' => 'title', 'number' => 0 )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); $data = array('TestValidate' => array( 'title' => 'title', 'number' => '3' )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertTrue($result); $data = array('TestValidate' => array( 'title' => 'title', 'number' => 3 )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertTrue($result); $TestModel->validate = array( 'number' => array( 'rule' => 'validateNumber', 'min' => 5, 'max' => 10 ), 'title' => array( 'allowEmpty' => false, 'rule' => 'notEmpty' )); $data = array('TestValidate' => array( 'title' => 'title', 'number' => '3' )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); $data = array('TestValidate' => array( 'title' => 'title', 'number' => 3 )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); $TestModel->validate = array( 'title' => array( 'allowEmpty' => false, 'rule' => 'validateTitle' )); $data = array('TestValidate' => array('title' => '')); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); $data = array('TestValidate' => array('title' => 'new title')); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); $data = array('TestValidate' => array('title' => 'title-new')); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertTrue($result); $TestModel->validate = array('title' => array( 'allowEmpty' => true, 'rule' => 'validateTitle' )); $data = array('TestValidate' => array('title' => '')); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertTrue($result); $TestModel->validate = array( 'title' => array( 'length' => array( 'allowEmpty' => true, 'rule' => array('maxLength', 10) ))); $data = array('TestValidate' => array('title' => '')); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertTrue($result); $TestModel->validate = array( 'title' => array( 'rule' => array('userDefined', 'Article', 'titleDuplicate') )); $data = array('TestValidate' => array('title' => 'My Article Title')); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); $data = array('TestValidate' => array( 'title' => 'My Article With a Different Title' )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertTrue($result); $TestModel->validate = array( 'title' => array( 'tooShort' => array('rule' => array('minLength', 50)), 'onlyLetters' => array('rule' => '/^[a-z]+$/i') ), ); $data = array('TestValidate' => array( 'title' => 'I am a short string' )); $TestModel->create($data); $result = $TestModel->validates(); $this->assertFalse($result); $result = $TestModel->validationErrors; $expected = array( 'title' => 'onlyLetters' ); $this->assertEqual($result, $expected); $TestModel->validate = array( 'title' => array( 'tooShort' => array( 'rule' => array('minLength', 50), 'last' => true ), 'onlyLetters' => array('rule' => '/^[a-z]+$/i') ), ); $data = array('TestValidate' => array( 'title' => 'I am a short string' )); $TestModel->create($data); $result = $TestModel->validates(); $this->assertFalse($result); $result = $TestModel->validationErrors; $expected = array( 'title' => 'tooShort' ); $this->assertEqual($result, $expected); }
testValidates method @access public @return void
testValidates
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_validation.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_validation.test.php
MIT
function testValidatesWithAssociations() { $data = array( 'Something' => array( 'id' => 5, 'title' => 'Extra Fields', 'body' => 'Extra Fields Body', 'published' => '1' ), 'SomethingElse' => array( array('something_else_id' => 1, 'doomed' => '') ) ); $Something =& new Something(); $JoinThing =& $Something->JoinThing; $JoinThing->validate = array('doomed' => array('rule' => 'notEmpty')); $expectedError = array('doomed' => 'This field cannot be left blank'); $Something->create(); $result = $Something->save($data); $this->assertFalse($result, 'Save occured even when with models failed. %s'); $this->assertEqual($JoinThing->validationErrors, $expectedError); $count = $Something->find('count', array('conditions' => array('Something.id' => $data['Something']['id']))); $this->assertIdentical($count, 0); $data = array( 'Something' => array( 'id' => 5, 'title' => 'Extra Fields', 'body' => 'Extra Fields Body', 'published' => '1' ), 'SomethingElse' => array( array('something_else_id' => 1, 'doomed' => 1), array('something_else_id' => 1, 'doomed' => '') ) ); $Something->create(); $result = $Something->save($data); $this->assertFalse($result, 'Save occured even when with models failed. %s'); $joinRecords = $JoinThing->find('count', array( 'conditions' => array('JoinThing.something_id' => $data['Something']['id']) )); $this->assertEqual($joinRecords, 0, 'Records were saved on the join table. %s'); }
test that validates() checks all the 'with' associations as well for validation as this can cause partial/wrong data insertion. @return void
testValidatesWithAssociations
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_validation.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_validation.test.php
MIT
function testValidatesWithModelsAndSaveAll() { $data = array( 'Something' => array( 'id' => 5, 'title' => 'Extra Fields', 'body' => 'Extra Fields Body', 'published' => '1' ), 'SomethingElse' => array( array('something_else_id' => 1, 'doomed' => '') ) ); $Something =& new Something(); $JoinThing =& $Something->JoinThing; $JoinThing->validate = array('doomed' => array('rule' => 'notEmpty')); $expectedError = array('doomed' => 'This field cannot be left blank'); $Something->create(); $result = $Something->saveAll($data, array('validate' => 'only')); $this->assertFalse($result); $this->assertEqual($JoinThing->validationErrors, $expectedError); $Something->create(); $result = $Something->saveAll($data, array('validate' => 'first')); $this->assertFalse($result); $this->assertEqual($JoinThing->validationErrors, $expectedError); $count = $Something->find('count', array('conditions' => array('Something.id' => $data['Something']['id']))); $this->assertIdentical($count, 0); $joinRecords = $JoinThing->find('count', array( 'conditions' => array('JoinThing.something_id' => $data['Something']['id']) )); $this->assertEqual($joinRecords, 0, 'Records were saved on the join table. %s'); }
test that saveAll and with models with validation interact well @return void
testValidatesWithModelsAndSaveAll
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_validation.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_validation.test.php
MIT
function testValidatesWithModelsAndSaveAllWithoutId() { $data = array( 'Article' => array( 'title' => 'Extra Fields', 'body' => 'Extra Fields Body', 'published' => '1' ), 'Comment' => array( array('word' => 'Hello'), array('word' => 'World'), ) ); $Article =& new Article(); $Comment =& $Article->Comment; $Comment->validate = array('article_id' => array('rule' => 'numeric')); $Article->create(); $result = $Article->saveAll($data, array('validate' => 'only')); $this->assertTrue($result); $Article->create(); $result = $Article->saveAll($data, array('validate' => 'first')); $this->assertTrue($result); $this->assertFalse(is_null($Article->id)); $id = $Article->id; $count = $Article->find('count', array('conditions' => array('Article.id' => $id))); $this->assertIdentical($count, 1); $count = $Comment->find('count', array( 'conditions' => array('Comment.article_id' => $id) )); $this->assertEqual($count, count($data['Comment'])); }
test that saveAll and with models at initial insert (no id has set yet) with validation interact well @return void
testValidatesWithModelsAndSaveAllWithoutId
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_validation.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_validation.test.php
MIT
function testMissingValidationErrorTriggering() { $restore = Configure::read('debug'); Configure::write('debug', 2); $TestModel =& new ValidationTest1(); $TestModel->create(array('title' => 'foo')); $TestModel->validate = array( 'title' => array( 'rule' => array('thisOneBringsThePain'), 'required' => true ) ); $this->expectError(new PatternExpectation('/thisOneBringsThePain for title/i')); $TestModel->invalidFields(array('fieldList' => array('title'))); Configure::write('debug', 0); $this->assertNoErrors(); $TestModel->invalidFields(array('fieldList' => array('title'))); Configure::write('debug', $restore); }
Test that missing validation methods trigger errors in development mode. Helps to make developement easier. @return void
testMissingValidationErrorTriggering
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_validation.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_validation.test.php
MIT
function testStateValidation() { $Article =& new Article(); $data = array( 'Article' => array( 'title' => '', 'body' => 'Extra Fields Body', 'published' => '1' ) ); $Article->validate = array( 'title' => array( 'notempty' => array( 'rule' => 'notEmpty', 'on' => 'create' ) ), 'published' => array( 'notempty' => array( 'rule' => 'notEmpty', ) ) ); $Article->create($data); $this->assertFalse($Article->validates()); $Article->save(null, array('validate' => false)); $data['Article']['id'] = $Article->id; $Article->set($data); $this->assertTrue($Article->validates()); $Article->data['Article']['published'] = null; $this->assertFalse($Article->validates()); unset($data['Article']['id']); $Article->data['Article']['published'] = '1'; $Article->validate = array( 'title' => array( 'notempty' => array( 'rule' => 'notEmpty', 'on' => 'update' ) ), 'published' => array( 'notempty' => array( 'rule' => 'notEmpty', ) ) ); $Article->create($data); $this->assertTrue($Article->validates()); $Article->save(null, array('validate' => false)); $data['Article']['id'] = $Article->id; $Article->set($data); $this->assertFalse($Article->validates()); }
Test for 'on' => [create|update] in validation rules. @return void
testStateValidation
php
Datawalke/Coordino
cake/tests/cases/libs/model/model_validation.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/model_validation.test.php
MIT
function testInsertAnotherHabtmRecordWithSameForeignKey() { $this->loadFixtures('JoinA', 'JoinB', 'JoinAB'); $TestModel = new JoinA(); $result = $TestModel->JoinAsJoinB->findById(1); $expected = array( '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' )); $this->assertEqual($result, $expected); $TestModel->JoinAsJoinB->create(); $result = $TestModel->JoinAsJoinB->save(array( 'join_a_id' => 1, 'join_b_id' => 1, 'other' => 'Data for Join A 1 Join B 1', 'created' => '2008-01-03 10:56:44', 'updated' => '2008-01-03 10:56:44' )); $this->assertTrue($result); $lastInsertId = $TestModel->JoinAsJoinB->getLastInsertID(); $this->assertTrue($lastInsertId != null); $result = $TestModel->JoinAsJoinB->findById(1); $expected = array( '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' )); $this->assertEqual($result, $expected); $updatedValue = 'UPDATED Data for Join A 1 Join B 2'; $TestModel->JoinAsJoinB->id = 1; $result = $TestModel->JoinAsJoinB->saveField('other', $updatedValue, false); $this->assertTrue($result); $result = $TestModel->JoinAsJoinB->findById(1); $this->assertEqual($result['JoinAsJoinB']['other'], $updatedValue); }
testInsertAnotherHabtmRecordWithSameForeignKey method @access public @return void
testInsertAnotherHabtmRecordWithSameForeignKey
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 testSaveDateAsFirstEntry() { $this->loadFixtures('Article'); $Article =& new Article(); $data = array( 'Article' => array( 'created' => array( 'day' => '1', 'month' => '1', 'year' => '2008' ), 'title' => 'Test Title', 'user_id' => 1 )); $Article->create(); $this->assertTrue($Article->save($data)); $testResult = $Article->find(array('Article.title' => 'Test Title')); $this->assertEqual($testResult['Article']['title'], $data['Article']['title']); $this->assertEqual($testResult['Article']['created'], '2008-01-01 00:00:00'); }
testSaveDateAsFirstEntry method @access public @return void
testSaveDateAsFirstEntry
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 testUnderscoreFieldSave() { $this->loadFixtures('UnderscoreField'); $UnderscoreField =& new UnderscoreField(); $currentCount = $UnderscoreField->find('count'); $this->assertEqual($currentCount, 3); $data = array('UnderscoreField' => array( 'user_id' => '1', 'my_model_has_a_field' => 'Content here', 'body' => 'Body', 'published' => 'Y', 'another_field' => 4 )); $ret = $UnderscoreField->save($data); $this->assertTrue($ret); $currentCount = $UnderscoreField->find('count'); $this->assertEqual($currentCount, 4); }
testUnderscoreFieldSave method @access public @return void
testUnderscoreFieldSave
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 testAutoSaveUuid() { // SQLite does not support non-integer primary keys $this->skipIf($this->db->config['driver'] == 'sqlite'); $this->loadFixtures('Uuid'); $TestModel =& new Uuid(); $TestModel->save(array('title' => 'Test record')); $result = $TestModel->findByTitle('Test record'); $this->assertEqual( array_keys($result['Uuid']), array('id', 'title', 'count', 'created', 'updated') ); $this->assertEqual(strlen($result['Uuid']['id']), 36); }
testAutoSaveUuid method @access public @return void
testAutoSaveUuid
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 testSaveUuidNull() { // SQLite does not support non-integer primary keys $this->skipIf($this->db->config['driver'] == 'sqlite'); $this->loadFixtures('Uuid'); $TestModel =& new Uuid(); $TestModel->save(array('title' => 'Test record', 'id' => null)); $result = $TestModel->findByTitle('Test record'); $this->assertEqual( array_keys($result['Uuid']), array('id', 'title', 'count', 'created', 'updated') ); $this->assertEqual(strlen($result['Uuid']['id']), 36); }
Ensure that if the id key is null but present the save doesn't fail (with an x sql error: "Column id specified twice") @return void @access public
testSaveUuidNull
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 testZeroDefaultFieldValue() { $this->skipIf( $this->db->config['driver'] == 'sqlite', '%s SQLite uses loose typing, this operation is unsupported' ); $this->loadFixtures('DataTest'); $TestModel =& new DataTest(); $TestModel->create(array()); $TestModel->save(); $result = $TestModel->findById($TestModel->id); $this->assertIdentical($result['DataTest']['count'], '0'); $this->assertIdentical($result['DataTest']['float'], '0'); }
testZeroDefaultFieldValue method @access public @return void
testZeroDefaultFieldValue
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 testNonNumericHabtmJoinKey() { $this->loadFixtures('Post', 'Tag', 'PostsTag'); $Post =& new Post(); $Post->bindModel(array( 'hasAndBelongsToMany' => array('Tag') )); $Post->Tag->primaryKey = 'tag'; $result = $Post->find('all'); $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' ), 'Author' => array( 'id' => null, 'user' => null, 'password' => null, 'created' => null, 'updated' => null, 'test' => 'working' ), '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( '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' ), 'Author' => array( 'id' => null, 'user' => null, 'password' => null, 'created' => null, 'updated' => null, 'test' => 'working' ), '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( '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' ), 'Author' => array( 'id' => null, 'user' => null, 'password' => null, 'created' => null, 'updated' => null, 'test' => 'working' ), 'Tag' => array() )); $this->assertEqual($result, $expected); }
testNonNumericHabtmJoinKey method @access public @return void
testNonNumericHabtmJoinKey
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 testAllowSimulatedFields() { $TestModel =& new ValidationTest1(); $TestModel->create(array( 'title' => 'foo', 'bar' => 'baz' )); $expected = array( 'ValidationTest1' => array( 'title' => 'foo', 'bar' => 'baz' )); $this->assertEqual($TestModel->data, $expected); }
Tests validation parameter order in custom validation methods @access public @return void
testAllowSimulatedFields
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 testCacheClearOnSave() { $_back = array( 'check' => Configure::read('Cache.check'), 'disable' => Configure::read('Cache.disable'), ); Configure::write('Cache.check', true); Configure::write('Cache.disable', false); $this->loadFixtures('OverallFavorite'); $OverallFavorite =& new OverallFavorite(); touch(CACHE . 'views' . DS . 'some_dir_overallfavorites_index.php'); touch(CACHE . 'views' . DS . 'some_dir_overall_favorites_index.php'); $data = array( 'OverallFavorite' => array( 'id' => 22, 'model_type' => '8-track', 'model_id' => '3', 'priority' => '1' ) ); $OverallFavorite->create($data); $OverallFavorite->save(); $this->assertFalse(file_exists(CACHE . 'views' . DS . 'some_dir_overallfavorites_index.php')); $this->assertFalse(file_exists(CACHE . 'views' . DS . 'some_dir_overall_favorites_index.php')); Configure::write('Cache.check', $_back['check']); Configure::write('Cache.disable', $_back['disable']); }
test that Caches are getting cleared on save(). ensure that both inflections of controller names are getting cleared as url for controller could be either overallFavorites/index or overall_favorites/index @return void
testCacheClearOnSave
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 testSaveWithCounterCache() { $this->loadFixtures('Syfile', 'Item'); $TestModel =& new Syfile(); $TestModel2 =& new Item(); $result = $TestModel->findById(1); $this->assertIdentical($result['Syfile']['item_count'], null); $TestModel2->save(array( 'name' => 'Item 7', 'syfile_id' => 1, 'published' => false )); $result = $TestModel->findById(1); $this->assertIdentical($result['Syfile']['item_count'], '2'); $TestModel2->delete(1); $result = $TestModel->findById(1); $this->assertIdentical($result['Syfile']['item_count'], '1'); $TestModel2->id = 2; $TestModel2->saveField('syfile_id', 1); $result = $TestModel->findById(1); $this->assertIdentical($result['Syfile']['item_count'], '2'); $result = $TestModel->findById(2); $this->assertIdentical($result['Syfile']['item_count'], '0'); }
testSaveWithCounterCache method @access public @return void
testSaveWithCounterCache
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 testCounterCacheIncrease() { $this->loadFixtures('CounterCacheUser', 'CounterCachePost'); $User = new CounterCacheUser(); $Post = new CounterCachePost(); $data = array('Post' => array( 'id' => 22, 'title' => 'New Post', 'user_id' => 66 )); $Post->save($data); $user = $User->find('first', array( 'conditions' => array('id' => 66), 'recursive' => -1 )); $result = $user[$User->alias]['post_count']; $expected = 3; $this->assertEqual($result, $expected); }
Tests that counter caches are updated when records are added @access public @return void
testCounterCacheIncrease
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 testCounterCacheDecrease() { $this->loadFixtures('CounterCacheUser', 'CounterCachePost'); $User = new CounterCacheUser(); $Post = new CounterCachePost(); $Post->delete(2); $user = $User->find('first', array( 'conditions' => array('id' => 66), 'recursive' => -1 )); $result = $user[$User->alias]['post_count']; $expected = 1; $this->assertEqual($result, $expected); }
Tests that counter caches are updated when records are deleted @access public @return void
testCounterCacheDecrease
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 testCounterCacheUpdated() { $this->loadFixtures('CounterCacheUser', 'CounterCachePost'); $User = new CounterCacheUser(); $Post = new CounterCachePost(); $data = $Post->find('first', array( 'conditions' => array('id' => 1), 'recursive' => -1 )); $data[$Post->alias]['user_id'] = 301; $Post->save($data); $users = $User->find('all',array('order' => 'User.id')); $this->assertEqual($users[0]['User']['post_count'], 1); $this->assertEqual($users[1]['User']['post_count'], 2); }
Tests that counter caches are updated when foreign keys of counted records change @access public @return void
testCounterCacheUpdated
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 testCounterCacheWithNonstandardPrimaryKey() { $this->loadFixtures( 'CounterCacheUserNonstandardPrimaryKey', 'CounterCachePostNonstandardPrimaryKey' ); $User = new CounterCacheUserNonstandardPrimaryKey(); $Post = new CounterCachePostNonstandardPrimaryKey(); $data = $Post->find('first', array( 'conditions' => array('pid' => 1), 'recursive' => -1 )); $data[$Post->alias]['uid'] = 301; $Post->save($data); $users = $User->find('all',array('order' => 'User.uid')); $this->assertEqual($users[0]['User']['post_count'], 1); $this->assertEqual($users[1]['User']['post_count'], 2); }
Test counter cache with models that use a non-standard (i.e. not using 'id') as their primary key. @access public @return void
testCounterCacheWithNonstandardPrimaryKey
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 testCounterCacheWithSelfJoin() { $skip = $this->skipIf( ($this->db->config['driver'] == 'sqlite'), 'SQLite 2.x does not support ALTER TABLE ADD COLUMN' ); if ($skip) { return; } $this->loadFixtures('CategoryThread'); $this->db->query('ALTER TABLE '. $this->db->fullTableName('category_threads') . " ADD COLUMN child_count INTEGER"); $Category =& new CategoryThread(); $result = $Category->updateAll(array('CategoryThread.name' => "'updated'"), array('CategoryThread.parent_id' => 5)); $this->assertTrue($result); $Category =& new CategoryThread(); $Category->belongsTo['ParentCategory']['counterCache'] = 'child_count'; $Category->updateCounterCache(array('parent_id' => 5)); $result = Set::extract($Category->find('all', array('conditions' => array('CategoryThread.id' => 5))), '{n}.CategoryThread.child_count'); $expected = array_fill(0, 1, 1); $this->assertEqual($result, $expected); }
test Counter Cache With Self Joining table @return void @access public
testCounterCacheWithSelfJoin
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 testSaveWithCounterCacheScope() { $this->loadFixtures('Syfile', 'Item'); $TestModel =& new Syfile(); $TestModel2 =& new Item(); $TestModel2->belongsTo['Syfile']['counterCache'] = true; $TestModel2->belongsTo['Syfile']['counterScope'] = array('published' => true); $result = $TestModel->findById(1); $this->assertIdentical($result['Syfile']['item_count'], null); $TestModel2->save(array( 'name' => 'Item 7', 'syfile_id' => 1, 'published'=> true )); $result = $TestModel->findById(1); $this->assertIdentical($result['Syfile']['item_count'], '1'); $TestModel2->id = 1; $TestModel2->saveField('published', true); $result = $TestModel->findById(1); $this->assertIdentical($result['Syfile']['item_count'], '2'); $TestModel2->save(array( 'id' => 1, 'syfile_id' => 1, 'published'=> false )); $result = $TestModel->findById(1); $this->assertIdentical($result['Syfile']['item_count'], '1'); }
testSaveWithCounterCacheScope method @access public @return void
testSaveWithCounterCacheScope
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 testBeforeValidateSaveAbortion() { $Model =& new CallbackPostTestModel(); $Model->beforeValidateReturn = false; $data = array( 'title' => 'new article', 'body' => 'this is some text.' ); $Model->create(); $result = $Model->save($data); $this->assertFalse($result); }
test that beforeValidate returning false can abort saves. @return void
testBeforeValidateSaveAbortion
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 testBeforeSaveSaveAbortion() { $Model =& new CallbackPostTestModel(); $Model->beforeSaveReturn = false; $data = array( 'title' => 'new article', 'body' => 'this is some text.' ); $Model->create(); $result = $Model->save($data); $this->assertFalse($result); }
test that beforeSave returning false can abort saves. @return void
testBeforeSaveSaveAbortion
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 testSaveField() { $this->loadFixtures('Article'); $TestModel =& new Article(); $TestModel->id = 1; $result = $TestModel->saveField('title', 'New First Article'); $this->assertTrue($result); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body'), 1); $expected = array('Article' => array( 'id' => '1', 'user_id' => '1', 'title' => 'New First Article', 'body' => 'First Article Body' )); $this->assertEqual($result, $expected); $TestModel->id = 1; $result = $TestModel->saveField('title', ''); $this->assertTrue($result); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body'), 1); $expected = array('Article' => array( 'id' => '1', 'user_id' => '1', 'title' => '', 'body' => 'First Article Body' )); $result['Article']['title'] = trim($result['Article']['title']); $this->assertEqual($result, $expected); $TestModel->id = 1; $TestModel->set('body', 'Messed up data'); $this->assertTrue($TestModel->saveField('title', 'First Article')); $result = $TestModel->read(array('id', 'user_id', 'title', 'body'), 1); $expected = array('Article' => array( 'id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body' )); $this->assertEqual($result, $expected); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body'), 1); $TestModel->id = 1; $result = $TestModel->saveField('title', '', true); $this->assertFalse($result); $this->loadFixtures('Node', 'Dependency'); $Node =& new Node(); $Node->set('id', 1); $result = $Node->read(); $this->assertEqual(Set::extract('/ParentNode/name', $result), array('Second')); $Node->saveField('state', 10); $result = $Node->read(); $this->assertEqual(Set::extract('/ParentNode/name', $result), array('Second')); }
testSaveField method @access public @return void
testSaveField
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 testSaveWithCreate() { $this->loadFixtures( 'User', 'Article', 'User', 'Comment', 'Tag', 'ArticlesTag', 'Attachment' ); $TestModel =& new User(); $data = array('User' => array( 'user' => 'user', 'password' => '' )); $result = $TestModel->save($data); $this->assertFalse($result); $this->assertTrue(!empty($TestModel->validationErrors)); $TestModel =& new Article(); $data = array('Article' => array( 'user_id' => '', 'title' => '', 'body' => '' )); $result = $TestModel->create($data) && $TestModel->save(); $this->assertFalse($result); $this->assertTrue(!empty($TestModel->validationErrors)); $data = array('Article' => array( 'id' => 1, 'user_id' => '1', 'title' => 'New First Article', 'body' => '' )); $result = $TestModel->create($data) && $TestModel->save(); $this->assertFalse($result); $data = array('Article' => array( 'id' => 1, 'title' => 'New First Article' )); $result = $TestModel->create() && $TestModel->save($data, false); $this->assertTrue($result); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 1); $expected = array('Article' => array( 'id' => '1', 'user_id' => '1', 'title' => 'New First Article', 'body' => 'First Article Body', 'published' => 'N' )); $this->assertEqual($result, $expected); $data = array('Article' => array( 'id' => 1, 'user_id' => '2', 'title' => 'First Article', 'body' => 'New First Article Body', 'published' => 'Y' )); $result = $TestModel->create() && $TestModel->save($data, true, array('id', 'title', 'published')); $this->assertTrue($result); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 1); $expected = array('Article' => array( 'id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y' )); $this->assertEqual($result, $expected); $data = array( 'Article' => array( 'user_id' => '2', 'title' => 'New Article', 'body' => 'New Article Body', 'created' => '2007-03-18 14:55:23', 'updated' => '2007-03-18 14:57:31' ), 'Tag' => array('Tag' => array(1, 3)) ); $TestModel->create(); $result = $TestModel->create() && $TestModel->save($data); $this->assertTrue($result); $TestModel->recursive = 2; $result = $TestModel->read(null, 4); $expected = array( 'Article' => array( 'id' => '4', 'user_id' => '2', 'title' => 'New Article', 'body' => 'New Article Body', 'published' => 'N', 'created' => '2007-03-18 14:55:23', 'updated' => '2007-03-18 14:57:31' ), 'User' => array( 'id' => '2', 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' ), 'Comment' => 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' ))); $this->assertEqual($result, $expected); $data = array('Comment' => array( 'article_id' => '4', 'user_id' => '1', 'comment' => 'Comment New Article', 'published' => 'Y', 'created' => '2007-03-18 14:57:23', 'updated' => '2007-03-18 14:59:31' )); $result = $TestModel->Comment->create() && $TestModel->Comment->save($data); $this->assertTrue($result); $data = array('Attachment' => array( 'comment_id' => '7', 'attachment' => 'newattachment.zip', 'created' => '2007-03-18 15:02:23', 'updated' => '2007-03-18 15:04:31' )); $result = $TestModel->Comment->Attachment->save($data); $this->assertTrue($result); $TestModel->recursive = 2; $result = $TestModel->read(null, 4); $expected = array( 'Article' => array( 'id' => '4', 'user_id' => '2', 'title' => 'New Article', 'body' => 'New Article Body', 'published' => 'N', 'created' => '2007-03-18 14:55:23', 'updated' => '2007-03-18 14:57:31' ), 'User' => array( 'id' => '2', 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31' ), 'Comment' => array( array( 'id' => '7', 'article_id' => '4', 'user_id' => '1', 'comment' => 'Comment New Article', 'published' => 'Y', 'created' => '2007-03-18 14:57:23', 'updated' => '2007-03-18 14:59:31', 'Article' => array( 'id' => '4', 'user_id' => '2', 'title' => 'New Article', 'body' => 'New Article Body', 'published' => 'N', 'created' => '2007-03-18 14:55:23', 'updated' => '2007-03-18 14:57:31' ), 'User' => array( 'id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ), 'Attachment' => array( 'id' => '2', 'comment_id' => '7', 'attachment' => 'newattachment.zip', 'created' => '2007-03-18 15:02:23', 'updated' => '2007-03-18 15:04:31' ))), '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' ))); $this->assertEqual($result, $expected); }
testSaveWithCreate method @access public @return void
testSaveWithCreate
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 testSaveWithNullId() { $this->loadFixtures('User'); $User =& new User(); $User->read(null, 1); $User->data['User']['id'] = null; $this->assertTrue($User->save(array('password' => 'test'))); $this->assertTrue($User->id > 0); $result = $User->read(null, 2); $User->data['User']['id'] = null; $this->assertTrue($User->save(array('password' => 'test'))); $this->assertTrue($User->id > 0); $User->data['User'] = array('password' => 'something'); $this->assertTrue($User->save()); $result = $User->read(); $this->assertEqual($User->data['User']['password'], 'something'); }
test that a null Id doesn't cause errors @return void
testSaveWithNullId
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 testSaveWithSet() { $this->loadFixtures('Article'); $TestModel =& new Article(); // Create record we will be updating later $data = array('Article' => array( 'user_id' => '1', 'title' => 'Fourth Article', 'body' => 'Fourth Article Body', 'published' => 'Y' )); $result = $TestModel->create() && $TestModel->save($data); $this->assertTrue($result); // Check record we created $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 4); $expected = array('Article' => array( 'id' => '4', 'user_id' => '1', 'title' => 'Fourth Article', 'body' => 'Fourth Article Body', 'published' => 'Y' )); $this->assertEqual($result, $expected); // Create new record just to overlap Model->id on previously created record $data = array('Article' => array( 'user_id' => '4', 'title' => 'Fifth Article', 'body' => 'Fifth Article Body', 'published' => 'Y' )); $result = $TestModel->create() && $TestModel->save($data); $this->assertTrue($result); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 5); $expected = array('Article' => array( 'id' => '5', 'user_id' => '4', 'title' => 'Fifth Article', 'body' => 'Fifth Article Body', 'published' => 'Y' )); $this->assertEqual($result, $expected); // Go back and edit the first article we created, starting by checking it's still there $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 4); $expected = array('Article' => array( 'id' => '4', 'user_id' => '1', 'title' => 'Fourth Article', 'body' => 'Fourth Article Body', 'published' => 'Y' )); $this->assertEqual($result, $expected); // And now do the update with set() $data = array('Article' => array( 'id' => '4', 'title' => 'Fourth Article - New Title', 'published' => 'N' )); $result = $TestModel->set($data) && $TestModel->save(); $this->assertTrue($result); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 4); $expected = array('Article' => array( 'id' => '4', 'user_id' => '1', 'title' => 'Fourth Article - New Title', 'body' => 'Fourth Article Body', 'published' => 'N' )); $this->assertEqual($result, $expected); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 5); $expected = array('Article' => array( 'id' => '5', 'user_id' => '4', 'title' => 'Fifth Article', 'body' => 'Fifth Article Body', 'published' => 'Y' )); $this->assertEqual($result, $expected); $data = array('Article' => array('id' => '5', 'title' => 'Fifth Article - New Title 5')); $result = ($TestModel->set($data) && $TestModel->save()); $this->assertTrue($result); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 5); $expected = array('Article' => array( 'id' => '5', 'user_id' => '4', 'title' => 'Fifth Article - New Title 5', 'body' => 'Fifth Article Body', 'published' => 'Y' )); $this->assertEqual($result, $expected); $TestModel->recursive = -1; $result = $TestModel->find('all', array('fields' => array('id', 'title'))); $expected = array( array('Article' => array('id' => 1, 'title' => 'First Article' )), array('Article' => array('id' => 2, 'title' => 'Second Article' )), array('Article' => array('id' => 3, 'title' => 'Third Article' )), array('Article' => array('id' => 4, 'title' => 'Fourth Article - New Title' )), array('Article' => array('id' => 5, 'title' => 'Fifth Article - New Title 5' )) ); $this->assertEqual($result, $expected); }
testSaveWithSet method @access public @return void
testSaveWithSet
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 testSaveWithNonExistentFields() { $this->loadFixtures('Article'); $TestModel =& new Article(); $TestModel->recursive = -1; $data = array( 'non_existent' => 'This field does not exist', 'user_id' => '1', 'title' => 'Fourth Article - New Title', 'body' => 'Fourth Article Body', 'published' => 'N' ); $result = $TestModel->create() && $TestModel->save($data); $this->assertTrue($result); $expected = array('Article' => array( 'id' => '4', 'user_id' => '1', 'title' => 'Fourth Article - New Title', 'body' => 'Fourth Article Body', 'published' => 'N' )); $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 4); $this->assertEqual($result, $expected); $data = array( 'user_id' => '1', 'non_existent' => 'This field does not exist', 'title' => 'Fiveth Article - New Title', 'body' => 'Fiveth Article Body', 'published' => 'N' ); $result = $TestModel->create() && $TestModel->save($data); $this->assertTrue($result); $expected = array('Article' => array( 'id' => '5', 'user_id' => '1', 'title' => 'Fiveth Article - New Title', 'body' => 'Fiveth Article Body', 'published' => 'N' )); $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 5); $this->assertEqual($result, $expected); }
testSaveWithNonExistentFields method @access public @return void
testSaveWithNonExistentFields
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 testSaveFromXml() { $this->loadFixtures('Article'); App::import('Core', 'Xml'); $Article = new Article(); $Article->save(new Xml('<article title="test xml" user_id="5" />')); $this->assertTrue($Article->save(new Xml('<article title="test xml" user_id="5" />'))); $results = $Article->find(array('Article.title' => 'test xml')); $this->assertTrue($results); }
testSaveFromXml method @access public @return void
testSaveFromXml
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 testSaveHabtm() { $this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'ArticlesTag'); $TestModel =& new Article(); $result = $TestModel->findById(2); $expected = 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' )), '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' ) ) ); $this->assertEqual($result, $expected); $data = array( 'Article' => array( 'id' => '2', 'title' => 'New Second Article' ), 'Tag' => array('Tag' => array(1, 2)) ); $this->assertTrue($TestModel->set($data)); $this->assertTrue($TestModel->save()); $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); $result = $TestModel->find(array('Article.id' => 2), array('id', 'user_id', 'title', 'body')); $expected = array( 'Article' => array( 'id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body' ), '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' ))); $this->assertEqual($result, $expected); $data = array('Article' => array('id' => '2'), 'Tag' => array('Tag' => array(2, 3))); $result = $TestModel->set($data); $this->assertTrue($result); $result = $TestModel->save(); $this->assertTrue($result); $TestModel->unbindModel(array( 'belongsTo' => array('User'), 'hasMany' => array('Comment') )); $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); $expected = array( 'Article' => array( 'id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body' ), 'Tag' => array( array( 'id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31' ), array( 'id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31' ))); $this->assertEqual($result, $expected); $data = array('Tag' => array('Tag' => array(1, 2, 3))); $result = $TestModel->set($data); $this->assertTrue($result); $result = $TestModel->save(); $this->assertTrue($result); $TestModel->unbindModel(array( 'belongsTo' => array('User'), 'hasMany' => array('Comment') )); $result = $TestModel->find(array('Article.id' => 2), array('id', 'user_id', 'title', 'body')); $expected = array( 'Article' => array( 'id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body' ), '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( 'id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31' ))); $this->assertEqual($result, $expected); $data = array('Tag' => array('Tag' => array())); $result = $TestModel->set($data); $this->assertTrue($result); $result = $TestModel->save(); $this->assertTrue($result); $data = array('Tag' => array('Tag' => '')); $result = $TestModel->set($data); $this->assertTrue($result); $result = $TestModel->save(); $this->assertTrue($result); $TestModel->unbindModel(array( 'belongsTo' => array('User'), 'hasMany' => array('Comment') )); $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); $expected = array( 'Article' => array( 'id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body' ), 'Tag' => array() ); $this->assertEqual($result, $expected); $data = array('Tag' => array('Tag' => array(2, 3))); $result = $TestModel->set($data); $this->assertTrue($result); $result = $TestModel->save(); $this->assertTrue($result); $TestModel->unbindModel(array( 'belongsTo' => array('User'), 'hasMany' => array('Comment') )); $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); $expected = array( 'Article' => array( 'id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body' ), 'Tag' => array( array( 'id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31' ), array( 'id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31' ))); $this->assertEqual($result, $expected); $data = array( 'Tag' => array( 'Tag' => array(1, 2) ), 'Article' => array( 'id' => '2', 'title' => 'New Second Article' )); $this->assertTrue($TestModel->set($data)); $this->assertTrue($TestModel->save()); $TestModel->unbindModel(array( 'belongsTo' => array('User'), 'hasMany' => array('Comment') )); $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); $expected = array( 'Article' => array( 'id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body' ), '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' ))); $this->assertEqual($result, $expected); $data = array( 'Tag' => array( 'Tag' => array(1, 2) ), 'Article' => array( 'id' => '2', 'title' => 'New Second Article Title' )); $result = $TestModel->set($data); $this->assertTrue($result); $this->assertTrue($TestModel->save()); $TestModel->unbindModel(array( 'belongsTo' => array('User'), 'hasMany' => array('Comment') )); $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); $expected = array( 'Article' => array( 'id' => '2', 'user_id' => '3', 'title' => 'New Second Article Title', 'body' => 'Second Article Body' ), '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' ) ) ); $this->assertEqual($result, $expected); $data = array( 'Tag' => array( 'Tag' => array(2, 3) ), 'Article' => array( 'id' => '2', 'title' => 'Changed Second Article' )); $this->assertTrue($TestModel->set($data)); $this->assertTrue($TestModel->save()); $TestModel->unbindModel(array( 'belongsTo' => array('User'), 'hasMany' => array('Comment') )); $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); $expected = array( 'Article' => array( 'id' => '2', 'user_id' => '3', 'title' => 'Changed Second Article', 'body' => 'Second Article Body' ), 'Tag' => array( array( 'id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31' ), array( 'id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31' ) ) ); $this->assertEqual($result, $expected); $data = array( 'Tag' => array( 'Tag' => array(1, 3) ), 'Article' => array('id' => '2'), ); $result = $TestModel->set($data); $this->assertTrue($result); $result = $TestModel->save(); $this->assertTrue($result); $TestModel->unbindModel(array( 'belongsTo' => array('User'), 'hasMany' => array('Comment') )); $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); $expected = array( 'Article' => array( 'id' => '2', 'user_id' => '3', 'title' => 'Changed Second Article', 'body' => 'Second Article Body' ), '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' ))); $this->assertEqual($result, $expected); $data = array( 'Article' => array( 'id' => 10, 'user_id' => '2', 'title' => 'New Article With Tags and fieldList', 'body' => 'New Article Body with Tags and fieldList', 'created' => '2007-03-18 14:55:23', 'updated' => '2007-03-18 14:57:31' ), 'Tag' => array( 'Tag' => array(1, 2, 3) )); $result = $TestModel->create() && $TestModel->save($data, true, array('user_id', 'title', 'published')); $this->assertTrue($result); $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); $result = $TestModel->read(); $expected = array( 'Article' => array( 'id' => 4, 'user_id' => 2, 'title' => 'New Article With Tags and fieldList', 'body' => '', 'published' => 'N', 'created' => '', 'updated' => '' ), 'Tag' => array( 0 => array( 'id' => 1, 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31' ), 1 => array( 'id' => 2, 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31' ), 2 => array( 'id' => 3, 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31' ))); $this->assertEqual($result, $expected); $this->loadFixtures('JoinA', 'JoinC', 'JoinAC', 'JoinB', 'JoinAB'); $TestModel = new JoinA(); $TestModel->hasBelongsToMany['JoinC']['unique'] = true; $data = array( 'JoinA' => array( 'id' => 1, 'name' => 'Join A 1', 'body' => 'Join A 1 Body', ), 'JoinC' => array( 'JoinC' => array( array('join_c_id' => 2, 'other' => 'new record'), array('join_c_id' => 3, 'other' => 'new record') ) ) ); $TestModel->save($data); $result = $TestModel->read(null, 1); $expected = array(4, 5); $this->assertEqual(Set::extract('/JoinC/JoinAsJoinC/id', $result), $expected); $expected = array('new record', 'new record'); $this->assertEqual(Set::extract('/JoinC/JoinAsJoinC/other', $result), $expected); }
testSaveHabtm method @access public @return void
testSaveHabtm
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 testSaveHabtmCustomKeys() { $this->loadFixtures('Story', 'StoriesTag', 'Tag'); $Story =& new Story(); $data = array( 'Story' => array('story' => '1'), 'Tag' => array( 'Tag' => array(2, 3) )); $result = $Story->set($data); $this->assertTrue($result); $result = $Story->save(); $this->assertTrue($result); $result = $Story->find('all', array('order' => array('Story.story'))); $expected = array( array( 'Story' => array( 'story' => 1, 'title' => 'First Story' ), 'Tag' => array( array( 'id' => 2, 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31' ), array( 'id' => 3, 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31' ))), array( 'Story' => array( 'story' => 2, 'title' => 'Second Story' ), 'Tag' => array() )); $this->assertEqual($result, $expected); }
testSaveHabtmCustomKeys method @access public @return void
testSaveHabtmCustomKeys
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 testHabtmSaveWithConditionsInAssociation() { $this->loadFixtures('JoinThing', 'Something', 'SomethingElse'); $Something =& new Something(); $Something->unbindModel(array('hasAndBelongsToMany' => array('SomethingElse')), false); $Something->bindModel(array( 'hasAndBelongsToMany' => array( 'DoomedSomethingElse' => array( 'className' => 'SomethingElse', 'joinTable' => 'join_things', 'conditions' => 'JoinThing.doomed = true', 'unique' => true ), 'NotDoomedSomethingElse' => array( 'className' => 'SomethingElse', 'joinTable' => 'join_things', 'conditions' => array('JoinThing.doomed' => 0), 'unique' => true ) ) ), false); $result = $Something->read(null, 1); $this->assertTrue(empty($result['NotDoomedSomethingElse'])); $this->assertEqual(count($result['DoomedSomethingElse']), 1); $data = array( 'Something' => array('id' => 1), 'NotDoomedSomethingElse' => array( 'NotDoomedSomethingElse' => array( array('something_else_id' => 2, 'doomed' => 0), array('something_else_id' => 3, 'doomed' => 0) ) ) ); $Something->create($data); $result = $Something->save(); $this->assertTrue($result); $result = $Something->read(null, 1); $this->assertEqual(count($result['NotDoomedSomethingElse']), 2); $this->assertEqual(count($result['DoomedSomethingElse']), 1); }
test that saving habtm records respects conditions set in the 'conditions' key for the association. @return void
testHabtmSaveWithConditionsInAssociation
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 testHabtmSaveKeyResolution() { $this->loadFixtures('Apple', 'Device', 'ThePaperMonkies'); $ThePaper =& new ThePaper(); $ThePaper->id = 1; $ThePaper->save(array('Monkey' => array(2, 3))); $result = $ThePaper->findById(1); $expected = array( array( 'id' => '2', 'device_type_id' => '1', 'name' => 'Device 2', 'typ' => '1' ), array( 'id' => '3', 'device_type_id' => '1', 'name' => 'Device 3', 'typ' => '2' )); $this->assertEqual($result['Monkey'], $expected); $ThePaper->id = 2; $ThePaper->save(array('Monkey' => array(1, 2, 3))); $result = $ThePaper->findById(2); $expected = array( array( 'id' => '1', 'device_type_id' => '1', 'name' => 'Device 1', 'typ' => '1' ), array( 'id' => '2', 'device_type_id' => '1', 'name' => 'Device 2', 'typ' => '1' ), array( 'id' => '3', 'device_type_id' => '1', 'name' => 'Device 3', 'typ' => '2' )); $this->assertEqual($result['Monkey'], $expected); $ThePaper->id = 2; $ThePaper->save(array('Monkey' => array(1, 3))); $result = $ThePaper->findById(2); $expected = array( array( 'id' => '1', 'device_type_id' => '1', 'name' => 'Device 1', 'typ' => '1' ), array( 'id' => '3', 'device_type_id' => '1', 'name' => 'Device 3', 'typ' => '2' )); $this->assertEqual($result['Monkey'], $expected); $result = $ThePaper->findById(1); $expected = array( array( 'id' => '2', 'device_type_id' => '1', 'name' => 'Device 2', 'typ' => '1' ), array( 'id' => '3', 'device_type_id' => '1', 'name' => 'Device 3', 'typ' => '2' )); $this->assertEqual($result['Monkey'], $expected); }
testHabtmSaveKeyResolution method @access public @return void
testHabtmSaveKeyResolution
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 testCreationOfEmptyRecord() { $this->loadFixtures('Author'); $TestModel =& new Author(); $this->assertEqual($TestModel->find('count'), 4); $TestModel->deleteAll(true, false, false); $this->assertEqual($TestModel->find('count'), 0); $result = $TestModel->save(); $this->assertTrue(isset($result['Author']['created'])); $this->assertTrue(isset($result['Author']['updated'])); $this->assertEqual($TestModel->find('count'), 1); }
testCreationOfEmptyRecord method @access public @return void
testCreationOfEmptyRecord
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 testCreateWithPKFiltering() { $TestModel =& new Article(); $data = array( 'id' => 5, 'user_id' => 2, 'title' => 'My article', 'body' => 'Some text' ); $result = $TestModel->create($data); $expected = array( 'Article' => array( 'published' => 'N', 'id' => 5, 'user_id' => 2, 'title' => 'My article', 'body' => 'Some text' )); $this->assertEqual($result, $expected); $this->assertEqual($TestModel->id, 5); $result = $TestModel->create($data, true); $expected = array( 'Article' => array( 'published' => 'N', 'id' => false, 'user_id' => 2, 'title' => 'My article', 'body' => 'Some text' )); $this->assertEqual($result, $expected); $this->assertFalse($TestModel->id); $result = $TestModel->create(array('Article' => $data), true); $expected = array( 'Article' => array( 'published' => 'N', 'id' => false, 'user_id' => 2, 'title' => 'My article', 'body' => 'Some text' )); $this->assertEqual($result, $expected); $this->assertFalse($TestModel->id); $data = array( 'id' => 6, 'user_id' => 2, 'title' => 'My article', 'body' => 'Some text', 'created' => '1970-01-01 00:00:00', 'updated' => '1970-01-01 12:00:00', 'modified' => '1970-01-01 12:00:00' ); $result = $TestModel->create($data); $expected = array( 'Article' => array( 'published' => 'N', 'id' => 6, 'user_id' => 2, 'title' => 'My article', 'body' => 'Some text', 'created' => '1970-01-01 00:00:00', 'updated' => '1970-01-01 12:00:00', 'modified' => '1970-01-01 12:00:00' )); $this->assertEqual($result, $expected); $this->assertEqual($TestModel->id, 6); $result = $TestModel->create(array( 'Article' => array_diff_key($data, array( 'created' => true, 'updated' => true, 'modified' => true ))), true); $expected = array( 'Article' => array( 'published' => 'N', 'id' => false, 'user_id' => 2, 'title' => 'My article', 'body' => 'Some text' )); $this->assertEqual($result, $expected); $this->assertFalse($TestModel->id); }
testCreateWithPKFiltering method @access public @return void
testCreateWithPKFiltering
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 testCreationWithMultipleData() { $this->loadFixtures('Article', 'Comment'); $Article =& new Article(); $Comment =& new Comment(); $articles = $Article->find('all', array( 'fields' => array('id','title'), 'recursive' => -1 )); $comments = $Comment->find('all', array( 'fields' => array('id','article_id','user_id','comment','published'), 'recursive' => -1)); $this->assertEqual($articles, array( array('Article' => array( 'id' => 1, 'title' => 'First Article' )), array('Article' => array( 'id' => 2, 'title' => 'Second Article' )), array('Article' => array( 'id' => 3, 'title' => 'Third Article' )))); $this->assertEqual($comments, array( array('Comment' => array( 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y' )), array('Comment' => array( 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y' )), array('Comment' => array( 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y' )), array('Comment' => array( 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N' )), array('Comment' => array( 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y' )), array('Comment' => array( 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y' )))); $data = array( 'Comment' => array( 'article_id' => 2, 'user_id' => 4, 'comment' => 'Brand New Comment', 'published' => 'N' ), 'Article' => array( 'id' => 2, 'title' => 'Second Article Modified' )); $result = $Comment->create($data); $this->assertTrue($result); $result = $Comment->save(); $this->assertTrue($result); $articles = $Article->find('all', array( 'fields' => array('id','title'), 'recursive' => -1 )); $comments = $Comment->find('all', array( 'fields' => array('id','article_id','user_id','comment','published'), 'recursive' => -1 )); $this->assertEqual($articles, array( array('Article' => array( 'id' => 1, 'title' => 'First Article' )), array('Article' => array( 'id' => 2, 'title' => 'Second Article' )), array('Article' => array( 'id' => 3, 'title' => 'Third Article' )))); $this->assertEqual($comments, array( array('Comment' => array( 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y' )), array('Comment' => array( 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y' )), array('Comment' => array( 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y' )), array('Comment' => array( 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N' )), array('Comment' => array( 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y' )), array('Comment' => array( 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y' )), array('Comment' => array( 'id' => 7, 'article_id' => 2, 'user_id' => 4, 'comment' => 'Brand New Comment', 'published' => 'N' )))); }
testCreationWithMultipleData method @access public @return void
testCreationWithMultipleData
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 testCreationWithMultipleDataSameModel() { $this->loadFixtures('Article'); $Article =& new Article(); $SecondaryArticle =& new Article(); $result = $Article->field('title', array('id' => 1)); $this->assertEqual($result, 'First Article'); $data = array( 'Article' => array( 'user_id' => 2, 'title' => 'Brand New Article', 'body' => 'Brand New Article Body', 'published' => 'Y' ), 'SecondaryArticle' => array( 'id' => 1 )); $Article->create(); $result = $Article->save($data); $this->assertTrue($result); $result = $Article->getInsertID(); $this->assertTrue(!empty($result)); $result = $Article->field('title', array('id' => 1)); $this->assertEqual($result, 'First Article'); $articles = $Article->find('all', array( 'fields' => array('id','title'), 'recursive' => -1 )); $this->assertEqual($articles, array( array('Article' => array( 'id' => 1, 'title' => 'First Article' )), array('Article' => array( 'id' => 2, 'title' => 'Second Article' )), array('Article' => array( 'id' => 3, 'title' => 'Third Article' )), array('Article' => array( 'id' => 4, 'title' => 'Brand New Article' )))); }
testCreationWithMultipleDataSameModel method @access public @return void
testCreationWithMultipleDataSameModel
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 testCreationWithMultipleDataSameModelManualInstances() { $this->loadFixtures('PrimaryModel'); $Primary =& new PrimaryModel(); $Secondary =& new PrimaryModel(); $result = $Primary->field('primary_name', array('id' => 1)); $this->assertEqual($result, 'Primary Name Existing'); $data = array( 'PrimaryModel' => array( 'primary_name' => 'Primary Name New' ), 'SecondaryModel' => array( 'id' => array(1) )); $Primary->create(); $result = $Primary->save($data); $this->assertTrue($result); $result = $Primary->field('primary_name', array('id' => 1)); $this->assertEqual($result, 'Primary Name Existing'); $result = $Primary->getInsertID(); $this->assertTrue(!empty($result)); $result = $Primary->field('primary_name', array('id' => $result)); $this->assertEqual($result, 'Primary Name New'); $result = $Primary->find('count'); $this->assertEqual($result, 2); }
testCreationWithMultipleDataSameModelManualInstances method @access public @return void
testCreationWithMultipleDataSameModelManualInstances
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 testRecordExists() { $this->loadFixtures('User'); $TestModel =& new User(); $this->assertFalse($TestModel->exists()); $TestModel->read(null, 1); $this->assertTrue($TestModel->exists()); $TestModel->create(); $this->assertFalse($TestModel->exists()); $TestModel->id = 4; $this->assertTrue($TestModel->exists()); $TestModel =& new TheVoid(); $this->assertFalse($TestModel->exists()); $TestModel->id = 5; $this->expectError(); ob_start(); $this->assertFalse($TestModel->exists()); $output = ob_get_clean(); }
testRecordExists method @access public @return void
testRecordExists
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