2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2012-04-27 02:49:18 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-10-03 16:31:21 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2012-04-27 02:49:18 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.TestSuite.Fixture
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.4667
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-08 06:19:36 +00:00
|
|
|
|
|
|
|
App::uses('Model', 'Model');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2011-12-08 15:35:02 +00:00
|
|
|
* A model to extend from to help you during testing.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.TestSuite.Fixture
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class CakeTestModel extends Model {
|
2012-03-05 02:51:44 +00:00
|
|
|
|
2010-09-20 02:41:31 +00:00
|
|
|
public $useDbConfig = 'test';
|
2012-03-05 02:51:44 +00:00
|
|
|
|
2010-04-04 07:14:00 +00:00
|
|
|
public $cacheSources = false;
|
2011-11-22 20:50:17 +00:00
|
|
|
|
|
|
|
/**
|
2011-11-24 21:12:39 +00:00
|
|
|
* Sets default order for the model to avoid failing tests caused by
|
2011-11-22 20:50:17 +00:00
|
|
|
* incorrect order when no order has been defined in the finds.
|
|
|
|
* Postgres can return the results in any order it considers appropriate if none is specified
|
|
|
|
*
|
2011-11-24 21:12:39 +00:00
|
|
|
* @param array $queryData
|
|
|
|
* @return array $queryData
|
2011-11-22 20:50:17 +00:00
|
|
|
*/
|
2011-11-24 21:12:39 +00:00
|
|
|
public function beforeFind($queryData) {
|
|
|
|
$pk = $this->primaryKey;
|
|
|
|
$aliasedPk = $this->alias . '.' . $this->primaryKey;
|
2011-11-30 15:44:11 +00:00
|
|
|
switch (true) {
|
2011-11-24 21:12:39 +00:00
|
|
|
case !$pk:
|
|
|
|
case !$this->useTable:
|
|
|
|
case !$this->schema('id'):
|
|
|
|
case !empty($queryData['order'][0]):
|
|
|
|
case !empty($queryData['group']):
|
|
|
|
case
|
|
|
|
(is_string($queryData['fields']) && !($queryData['fields'] == $pk || $queryData['fields'] == $aliasedPk)) ||
|
|
|
|
(is_array($queryData['fields']) && !(array_key_exists($pk, $queryData['fields']) || array_key_exists($aliasedPk, $queryData['fields']))):
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$queryData['order'] = array($this->alias . '.' . $this->primaryKey => 'ASC');
|
|
|
|
break;
|
2011-11-22 20:50:17 +00:00
|
|
|
}
|
2011-11-24 21:12:39 +00:00
|
|
|
return $queryData;
|
2011-11-22 20:50:17 +00:00
|
|
|
}
|
2012-03-28 15:49:41 +00:00
|
|
|
/**
|
|
|
|
* Overriding save() to set CakeTestSuiteDispatcher::date() as formatter for created, modified and updated fields
|
|
|
|
*
|
|
|
|
* @param array $data
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param boolean|array $validate
|
2012-03-28 15:49:41 +00:00
|
|
|
* @param array $fieldList
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function save($data = null, $validate = true, $fieldList = array()) {
|
|
|
|
$db = $this->getDataSource();
|
|
|
|
$db->columns['datetime']['formatter'] = 'CakeTestSuiteDispatcher::date';
|
|
|
|
return parent::save($data, $validate, $fieldList);
|
|
|
|
}
|
2011-11-22 20:50:17 +00:00
|
|
|
|
2012-12-05 14:00:24 +00:00
|
|
|
}
|