2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2012-03-13 02:46:07 +00:00
|
|
|
* Copyright 2005-2012, 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
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-03-13 02:46:07 +00:00
|
|
|
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-05-19 01:15:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing 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
|
|
|
|
* @param mixed $validate
|
|
|
|
* @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-03-28 15:49:41 +00:00
|
|
|
}
|