1: <?php
2: /**
3: * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
4: * Copyright 2005-2012, 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-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
10: * @link http://book.cakephp.org/2.0/en/development/testing.html 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:
25: public $useDbConfig = 'test';
26:
27: public $cacheSources = false;
28:
29: /**
30: * Sets default order for the model to avoid failing tests caused by
31: * incorrect order when no order has been defined in the finds.
32: * Postgres can return the results in any order it considers appropriate if none is specified
33: *
34: * @param array $queryData
35: * @return array $queryData
36: */
37: public function beforeFind($queryData) {
38: $pk = $this->primaryKey;
39: $aliasedPk = $this->alias . '.' . $this->primaryKey;
40: switch (true) {
41: case !$pk:
42: case !$this->useTable:
43: case !$this->schema('id'):
44: case !empty($queryData['order'][0]):
45: case !empty($queryData['group']):
46: case
47: (is_string($queryData['fields']) && !($queryData['fields'] == $pk || $queryData['fields'] == $aliasedPk)) ||
48: (is_array($queryData['fields']) && !(array_key_exists($pk, $queryData['fields']) || array_key_exists($aliasedPk, $queryData['fields']))):
49: break;
50: default:
51: $queryData['order'] = array($this->alias . '.' . $this->primaryKey => 'ASC');
52: break;
53: }
54: return $queryData;
55: }
56: /**
57: * Overriding save() to set CakeTestSuiteDispatcher::date() as formatter for created, modified and updated fields
58: *
59: * @param array $data
60: * @param mixed $validate
61: * @param array $fieldList
62: */
63:
64: public function save($data = null, $validate = true, $fieldList = array()) {
65: $db = $this->getDataSource();
66: $db->columns['datetime']['formatter'] = 'CakeTestSuiteDispatcher::date';
67: return parent::save($data, $validate, $fieldList);
68: }
69:
70: }