Adding test to show afterFind being called from Model::find('list'), closes #4456

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6684 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mariano.iglesias 2008-04-17 22:30:25 +00:00
parent 5f967487bb
commit 5f8641aac9
2 changed files with 22 additions and 1 deletions

View file

@ -37,7 +37,6 @@ require_once dirname(__FILE__) . DS . 'models.php';
* @subpackage cake.tests.cases.libs.model * @subpackage cake.tests.cases.libs.model
*/ */
class ModelTest extends CakeTestCase { class ModelTest extends CakeTestCase {
var $autoFixtures = false; var $autoFixtures = false;
var $fixtures = array( var $fixtures = array(
@ -752,6 +751,7 @@ class ModelTest extends CakeTestCase {
function testGenerateList() { function testGenerateList() {
$this->loadFixtures('Article', 'Apple', 'Post', 'Author', 'User'); $this->loadFixtures('Article', 'Apple', 'Post', 'Author', 'User');
$this->model =& new Article(); $this->model =& new Article();
$this->model->displayField = 'title'; $this->model->displayField = 'title';
@ -808,6 +808,11 @@ class ModelTest extends CakeTestCase {
$result = $this->model->find('list', array('fields' => array('User.user', 'User.password'))); $result = $this->model->find('list', array('fields' => array('User.user', 'User.password')));
$expected = array('mariano' => '5f4dcc3b5aa765d61d8327deb882cf99', 'nate' => '5f4dcc3b5aa765d61d8327deb882cf99', 'larry' => '5f4dcc3b5aa765d61d8327deb882cf99', 'garrett' => '5f4dcc3b5aa765d61d8327deb882cf99'); $expected = array('mariano' => '5f4dcc3b5aa765d61d8327deb882cf99', 'nate' => '5f4dcc3b5aa765d61d8327deb882cf99', 'larry' => '5f4dcc3b5aa765d61d8327deb882cf99', 'garrett' => '5f4dcc3b5aa765d61d8327deb882cf99');
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$this->model =& new ModifiedAuthor();
$result = $this->model->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);
} }
function testRecordExists() { function testRecordExists() {

View file

@ -289,6 +289,22 @@ class Author extends CakeTestModel {
return $results; return $results;
} }
} }
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.model
*/
class ModifiedAuthor extends Author {
var $name = 'Author';
function afterFind($results) {
foreach($results as $index => $result) {
$results[$index]['Author']['user'] .= ' (CakePHP)';
}
return $results;
}
}
/** /**
* Short description for class. * Short description for class.
* *