From 5f8641aac9403637fd6202e3e1388758e6263b8c Mon Sep 17 00:00:00 2001 From: "mariano.iglesias" Date: Thu, 17 Apr 2008 22:30:25 +0000 Subject: [PATCH] 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 --- cake/tests/cases/libs/model/model.test.php | 7 ++++++- cake/tests/cases/libs/model/models.php | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 750fad482..39532ccd3 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -37,7 +37,6 @@ require_once dirname(__FILE__) . DS . 'models.php'; * @subpackage cake.tests.cases.libs.model */ class ModelTest extends CakeTestCase { - var $autoFixtures = false; var $fixtures = array( @@ -752,6 +751,7 @@ class ModelTest extends CakeTestCase { function testGenerateList() { $this->loadFixtures('Article', 'Apple', 'Post', 'Author', 'User'); + $this->model =& new Article(); $this->model->displayField = 'title'; @@ -808,6 +808,11 @@ class ModelTest extends CakeTestCase { $result = $this->model->find('list', array('fields' => array('User.user', 'User.password'))); $expected = array('mariano' => '5f4dcc3b5aa765d61d8327deb882cf99', 'nate' => '5f4dcc3b5aa765d61d8327deb882cf99', 'larry' => '5f4dcc3b5aa765d61d8327deb882cf99', 'garrett' => '5f4dcc3b5aa765d61d8327deb882cf99'); $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() { diff --git a/cake/tests/cases/libs/model/models.php b/cake/tests/cases/libs/model/models.php index 4cfec73f8..81d3472df 100644 --- a/cake/tests/cases/libs/model/models.php +++ b/cake/tests/cases/libs/model/models.php @@ -289,6 +289,22 @@ class Author extends CakeTestModel { 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. *