cakephp2-php8/lib/Cake/TestSuite/Fixture/CakeTestModel.php

58 lines
1.8 KiB
PHP
Raw Normal View History

<?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)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
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
* @package Cake.TestSuite.Fixture
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
2010-12-08 06:19:36 +00:00
App::uses('Model', 'Model');
/**
* A model to extend from to help you during testing.
*
* @package Cake.TestSuite.Fixture
*/
class CakeTestModel extends Model {
public $useDbConfig = 'test';
public $cacheSources = false;
/**
* Sets default order for the model to avoid failing tests caused by
* 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
*
* @param array $queryData
* @return array $queryData
*/
public function beforeFind($queryData) {
$pk = $this->primaryKey;
$aliasedPk = $this->alias . '.' . $this->primaryKey;
2011-11-30 15:44:11 +00:00
switch (true) {
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;
}
return $queryData;
}
}