1: <?php
2: /**
3: * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
4: * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
5: *
6: * Licensed under The MIT License
7: * Redistributions of files must retain the above copyright notice
8: *
9: * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
10: * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
11: * @package Cake.TestSuite.Fixture
12: * @since CakePHP(tm) v 1.2.0.4667
13: * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
14: */
15:
16: App::uses('Model', 'Model');
17:
18: /**
19: * A model to extend from to help you during testing.
20: *
21: * @package Cake.TestSuite.Fixture
22: */
23: class CakeTestModel extends Model {
24: public $useDbConfig = 'test';
25: public $cacheSources = false;
26:
27: /**
28: * Sets default order for the model to avoid failing tests caused by
29: * incorrect order when no order has been defined in the finds.
30: * Postgres can return the results in any order it considers appropriate if none is specified
31: *
32: * @param array $queryData
33: * @return array $queryData
34: */
35: public function beforeFind($queryData) {
36: $pk = $this->primaryKey;
37: $aliasedPk = $this->alias . '.' . $this->primaryKey;
38: switch (true) {
39: case !$pk:
40: case !$this->useTable:
41: case !$this->schema('id'):
42: case !empty($queryData['order'][0]):
43: case !empty($queryData['group']):
44: case
45: (is_string($queryData['fields']) && !($queryData['fields'] == $pk || $queryData['fields'] == $aliasedPk)) ||
46: (is_array($queryData['fields']) && !(array_key_exists($pk, $queryData['fields']) || array_key_exists($aliasedPk, $queryData['fields']))):
47: break;
48: default:
49: $queryData['order'] = array($this->alias . '.' . $this->primaryKey => 'ASC');
50: break;
51: }
52: return $queryData;
53: }
54:
55: }
56: