Permalink
Browse files

Add test for find() and array conditions.

Add a test for conditions using an array with only one element.

Closes #4848
  • Loading branch information...
markstory committed Oct 9, 2014
1 parent 51fb003 commit 0ff9545e5adab509153551596a0be81a6a1493bd
Showing with 58 additions and 1 deletion.
  1. +58 −1 lib/Cake/Test/Case/Model/ModelReadTest.php
@@ -6550,12 +6550,43 @@ public function testFindAll() {
}
}
/**
* Test that find() with array conditions works when there is only one element.
*
* @return void
*/
public function testFindAllArrayConditions() {
$this->loadFixtures('User');
$TestModel = new User();
$TestModel->cacheQueries = false;
$result = $TestModel->find('all', array(
'conditions' => array('User.id' => array(3)),
));
$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'
))
);
$this->assertEquals($expected, $result);
$result = $TestModel->find('all', array(
'conditions' => array('User.user' => array('larry')),
));
$this->assertEquals($expected, $result);
}
/**
* test find('list') method
*
* @return void
*/
public function testGenerateFindList() {
public function testFindList() {
$this->loadFixtures('Article', 'Apple', 'Post', 'Author', 'User', 'Comment');
$TestModel = new Article();
@@ -6825,6 +6856,32 @@ public function testGenerateFindList() {
$this->assertEquals($expected, $result);
}
/**
* Test that find(list) works with array conditions that have only one element.
*
* @return void
*/
public function testFindListArrayCondition() {
$this->loadFixtures('User');
$TestModel = new User();
$TestModel->cacheQueries = false;
$result = $TestModel->find('list', array(
'fields' => array('id', 'user'),
'conditions' => array('User.id' => array(3)),
));
$expected = array(
3 => 'larry'
);
$this->assertEquals($expected, $result);
$result = $TestModel->find('list', array(
'fields' => array('id', 'user'),
'conditions' => array('User.user' => array('larry')),
));
$this->assertEquals($expected, $result);
}
/**
* testFindField method
*

0 comments on commit 0ff9545

Please sign in to comment.