PageRenderTime 35ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Cake/TestSuite/Fixture/CakeTestModel.php

https://bitbucket.org/udeshika/fake_twitter
PHP | 55 lines | 25 code | 4 blank | 26 comment | 7 complexity | d90c26fe1c3075cdb3fa5882863539d7 MD5 | raw file
  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. App::uses('Model', 'Model');
  16. /**
  17. * A model to extend from to help you during testing.
  18. *
  19. * @package Cake.TestSuite.Fixture
  20. */
  21. class CakeTestModel extends Model {
  22. public $useDbConfig = 'test';
  23. public $cacheSources = false;
  24. /**
  25. * Sets default order for the model to avoid failing tests caused by
  26. * incorrect order when no order has been defined in the finds.
  27. * Postgres can return the results in any order it considers appropriate if none is specified
  28. *
  29. * @param array $queryData
  30. * @return array $queryData
  31. */
  32. public function beforeFind($queryData) {
  33. $pk = $this->primaryKey;
  34. $aliasedPk = $this->alias . '.' . $this->primaryKey;
  35. switch (true) {
  36. case !$pk:
  37. case !$this->useTable:
  38. case !$this->schema('id'):
  39. case !empty($queryData['order'][0]):
  40. case !empty($queryData['group']):
  41. case
  42. (is_string($queryData['fields']) && !($queryData['fields'] == $pk || $queryData['fields'] == $aliasedPk)) ||
  43. (is_array($queryData['fields']) && !(array_key_exists($pk, $queryData['fields']) || array_key_exists($aliasedPk, $queryData['fields']))):
  44. break;
  45. default:
  46. $queryData['order'] = array($this->alias . '.' . $this->primaryKey => 'ASC');
  47. break;
  48. }
  49. return $queryData;
  50. }
  51. }