PageRenderTime 50ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/cake/tests/lib/cake_test_case.php

https://github.com/MrRio/wildflower
PHP | 741 lines | 473 code | 54 blank | 214 comment | 104 complexity | ec04dc2bd1aec36c3956c92a8185c265 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /* SVN FILE: $Id: cake_test_case.php 8004 2009-01-16 20:15:21Z gwoo $ */
  3. /**
  4. * Short description for file.
  5. *
  6. * Long description for file
  7. *
  8. * PHP versions 4 and 5
  9. *
  10. * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
  11. * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
  12. *
  13. * Licensed under The Open Group Test Suite License
  14. * Redistributions of files must retain the above copyright notice.
  15. *
  16. * @filesource
  17. * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
  18. * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
  19. * @package cake
  20. * @subpackage cake.cake.tests.libs
  21. * @since CakePHP(tm) v 1.2.0.4667
  22. * @version $Revision: 8004 $
  23. * @modifiedby $LastChangedBy: gwoo $
  24. * @lastmodified $Date: 2009-01-16 12:15:21 -0800 (Fri, 16 Jan 2009) $
  25. * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  26. */
  27. if (!class_exists('dispatcher')) {
  28. require CAKE . 'dispatcher.php';
  29. }
  30. require_once CAKE_TESTS_LIB . 'cake_test_model.php';
  31. require_once CAKE_TESTS_LIB . 'cake_test_fixture.php';
  32. App::import('Vendor', 'simpletest' . DS . 'unit_tester');
  33. /**
  34. * Short description for class.
  35. *
  36. * @package cake
  37. * @subpackage cake.cake.tests.lib
  38. */
  39. class CakeTestDispatcher extends Dispatcher {
  40. var $controller;
  41. var $testCase;
  42. function testCase(&$testCase) {
  43. $this->testCase =& $testCase;
  44. }
  45. function _invoke (&$controller, $params, $missingAction = false) {
  46. $this->controller =& $controller;
  47. if (isset($this->testCase) && method_exists($this->testCase, 'startController')) {
  48. $this->testCase->startController($this->controller, $params);
  49. }
  50. $result = parent::_invoke($this->controller, $params, $missingAction);
  51. if (isset($this->testCase) && method_exists($this->testCase, 'endController')) {
  52. $this->testCase->endController($this->controller, $params);
  53. }
  54. return $result;
  55. }
  56. }
  57. /**
  58. * Short description for class.
  59. *
  60. * @package cake
  61. * @subpackage cake.cake.tests.lib
  62. */
  63. class CakeTestCase extends UnitTestCase {
  64. /**
  65. * Methods used internally.
  66. *
  67. * @var array
  68. * @access private
  69. */
  70. var $methods = array('start', 'end', 'startcase', 'endcase', 'starttest', 'endtest');
  71. var $__truncated = true;
  72. var $__savedGetData = array();
  73. /**
  74. * By default, all fixtures attached to this class will be truncated and reloaded after each test.
  75. * Set this to false to handle manually
  76. *
  77. * @var array
  78. * @access public
  79. */
  80. var $autoFixtures = true;
  81. /**
  82. * Set this to false to avoid tables to be dropped if they already exist
  83. *
  84. * @var boolean
  85. * @access public
  86. */
  87. var $dropTables = true;
  88. /**
  89. * Maps fixture class names to fixture identifiers as included in CakeTestCase::$fixtures
  90. *
  91. * @var array
  92. * @access protected
  93. */
  94. var $_fixtureClassMap = array();
  95. /**
  96. * Called when a test case (group of methods) is about to start (to be overriden when needed.)
  97. *
  98. * @param string $method Test method about to get executed.
  99. *
  100. * @access protected
  101. */
  102. function startCase() {
  103. }
  104. /**
  105. * Called when a test case (group of methods) has been executed (to be overriden when needed.)
  106. *
  107. * @param string $method Test method about that was executed.
  108. *
  109. * @access protected
  110. */
  111. function endCase() {
  112. }
  113. /**
  114. * Called when a test case method is about to start (to be overriden when needed.)
  115. *
  116. * @param string $method Test method about to get executed.
  117. *
  118. * @access protected
  119. */
  120. function startTest($method) {
  121. }
  122. /**
  123. * Called when a test case method has been executed (to be overriden when needed.)
  124. *
  125. * @param string $method Test method about that was executed.
  126. *
  127. * @access protected
  128. */
  129. function endTest($method) {
  130. }
  131. /**
  132. * Overrides SimpleTestCase::assert to enable calling of skipIf() from within tests
  133. */
  134. function assert(&$expectation, $compare, $message = '%s') {
  135. if ($this->_should_skip) {
  136. return;
  137. }
  138. return parent::assert($expectation, $compare, $message);
  139. }
  140. /**
  141. * Overrides SimpleTestCase::skipIf to provide a boolean return value
  142. */
  143. function skipIf($shouldSkip, $message = '%s') {
  144. parent::skipIf($shouldSkip, $message);
  145. return $shouldSkip;
  146. }
  147. /**
  148. * Callback issued when a controller's action is about to be invoked through testAction().
  149. *
  150. * @param Controller $controller Controller that's about to be invoked.
  151. * @param array $params Additional parameters as sent by testAction().
  152. */
  153. function startController(&$controller, $params = array()) {
  154. if (isset($params['fixturize']) && ((is_array($params['fixturize']) && !empty($params['fixturize'])) || $params['fixturize'] === true)) {
  155. if (!isset($this->db)) {
  156. $this->_initDb();
  157. }
  158. if ($controller->uses === false) {
  159. $list = array($controller->modelClass);
  160. } else {
  161. $list = is_array($controller->uses) ? $controller->uses : array($controller->uses);
  162. }
  163. $models = array();
  164. ClassRegistry::config(array('ds' => $params['connection']));
  165. foreach ($list as $name) {
  166. if ((is_array($params['fixturize']) && in_array($name, $params['fixturize'])) || $params['fixturize'] === true) {
  167. if (class_exists($name) || App::import('Model', $name)) {
  168. $object =& ClassRegistry::init($name);
  169. //switch back to specified datasource.
  170. $object->setDataSource($params['connection']);
  171. $db =& ConnectionManager::getDataSource($object->useDbConfig);
  172. $db->cacheSources = false;
  173. $models[$object->alias] = array(
  174. 'table' => $object->table,
  175. 'model' => $object->alias,
  176. 'key' => strtolower($name),
  177. );
  178. }
  179. }
  180. }
  181. ClassRegistry::config(array('ds' => 'test_suite'));
  182. if (!empty($models) && isset($this->db)) {
  183. $this->_actionFixtures = array();
  184. foreach ($models as $model) {
  185. $fixture =& new CakeTestFixture($this->db);
  186. $fixture->name = $model['model'] . 'Test';
  187. $fixture->table = $model['table'];
  188. $fixture->import = array('model' => $model['model'], 'records' => true);
  189. $fixture->init();
  190. $fixture->create($this->db);
  191. $fixture->insert($this->db);
  192. $this->_actionFixtures[] =& $fixture;
  193. }
  194. foreach ($models as $model) {
  195. $object =& ClassRegistry::getObject($model['key']);
  196. if ($object !== false) {
  197. $object->setDataSource('test_suite');
  198. $object->cacheSources = false;
  199. }
  200. }
  201. }
  202. }
  203. }
  204. /**
  205. * Callback issued when a controller's action has been invoked through testAction().
  206. *
  207. * @param Controller $controller Controller that has been invoked.
  208. * * @param array $params Additional parameters as sent by testAction().
  209. */
  210. function endController(&$controller, $params = array()) {
  211. if (isset($this->db) && isset($this->_actionFixtures) && !empty($this->_actionFixtures)) {
  212. foreach ($this->_actionFixtures as $fixture) {
  213. $fixture->drop($this->db);
  214. }
  215. }
  216. }
  217. /**
  218. * Executes a Cake URL, and can get (depending on the $params['return'] value):
  219. *
  220. * 1. 'result': Whatever the action returns (and also specifies $this->params['requested'] for controller)
  221. * 2. 'view': The rendered view, without the layout
  222. * 3. 'contents': The rendered view, within the layout.
  223. * 4. 'vars': the view vars
  224. *
  225. * @param string $url Cake URL to execute (e.g: /articles/view/455)
  226. * @param array $params Parameters, or simply a string of what to return
  227. * @return mixed Whatever is returned depending of requested result
  228. * @access public
  229. */
  230. function testAction($url, $params = array()) {
  231. $default = array(
  232. 'return' => 'result',
  233. 'fixturize' => false,
  234. 'data' => array(),
  235. 'method' => 'post',
  236. 'connection' => 'default'
  237. );
  238. if (is_string($params)) {
  239. $params = array('return' => $params);
  240. }
  241. $params = array_merge($default, $params);
  242. $toSave = array(
  243. 'case' => null,
  244. 'group' => null,
  245. 'app' => null,
  246. 'output' => null,
  247. 'show' => null,
  248. 'plugin' => null
  249. );
  250. $this->__savedGetData = (empty($this->__savedGetData))
  251. ? array_intersect_key($_GET, $toSave)
  252. : $this->__savedGetData;
  253. $data = (!empty($params['data'])) ? $params['data'] : array();
  254. if (strtolower($params['method']) == 'get') {
  255. $_GET = array_merge($this->__savedGetData, $data);
  256. $_POST = array();
  257. } else {
  258. $_POST = array('data' => $data);
  259. $_GET = $this->__savedGetData;
  260. }
  261. $return = $params['return'];
  262. $params = array_diff_key($params, array('data' => null, 'method' => null, 'return' => null));
  263. $dispatcher =& new CakeTestDispatcher();
  264. $dispatcher->testCase($this);
  265. if ($return != 'result') {
  266. if ($return != 'contents') {
  267. $params['layout'] = false;
  268. }
  269. ob_start();
  270. @$dispatcher->dispatch($url, $params);
  271. $result = ob_get_clean();
  272. if ($return == 'vars') {
  273. $view =& ClassRegistry::getObject('view');
  274. $viewVars = $view->getVars();
  275. $result = array();
  276. foreach ($viewVars as $var) {
  277. $result[$var] = $view->getVar($var);
  278. }
  279. if (!empty($view->pageTitle)) {
  280. $result = array_merge($result, array('title' => $view->pageTitle));
  281. }
  282. }
  283. } else {
  284. $params['return'] = 1;
  285. $params['bare'] = 1;
  286. $params['requested'] = 1;
  287. $result = @$dispatcher->dispatch($url, $params);
  288. }
  289. if (isset($this->_actionFixtures)) {
  290. unset($this->_actionFixtures);
  291. }
  292. ClassRegistry::flush();
  293. return $result;
  294. }
  295. /**
  296. * Announces the start of a test.
  297. *
  298. * @param string $method Test method just started.
  299. *
  300. * @access public
  301. */
  302. function before($method) {
  303. parent::before($method);
  304. if (isset($this->fixtures) && (!is_array($this->fixtures) || empty($this->fixtures))) {
  305. unset($this->fixtures);
  306. }
  307. // Set up DB connection
  308. if (isset($this->fixtures) && strtolower($method) == 'start') {
  309. $this->_initDb();
  310. $this->_loadFixtures();
  311. }
  312. // Create records
  313. if (isset($this->_fixtures) && isset($this->db) && !in_array(strtolower($method), array('start', 'end')) && $this->__truncated && $this->autoFixtures == true) {
  314. foreach ($this->_fixtures as $fixture) {
  315. $inserts = $fixture->insert($this->db);
  316. }
  317. }
  318. if (!in_array(strtolower($method), $this->methods)) {
  319. $this->startTest($method);
  320. }
  321. }
  322. /**
  323. * Runs as first test to create tables.
  324. *
  325. * @access public
  326. */
  327. function start() {
  328. if (isset($this->_fixtures) && isset($this->db)) {
  329. Configure::write('Cache.disable', true);
  330. $cacheSources = $this->db->cacheSources;
  331. $this->db->cacheSources = false;
  332. $sources = $this->db->listSources();
  333. $this->db->cacheSources = $cacheSources;
  334. if (!$this->dropTables) {
  335. return;
  336. }
  337. foreach ($this->_fixtures as $fixture) {
  338. if (in_array($fixture->table, $sources)) {
  339. $fixture->drop($this->db);
  340. $fixture->create($this->db);
  341. } elseif (!in_array($fixture->table, $sources)) {
  342. $fixture->create($this->db);
  343. }
  344. }
  345. }
  346. }
  347. /**
  348. * Runs as last test to drop tables.
  349. *
  350. * @access public
  351. */
  352. function end() {
  353. if (isset($this->_fixtures) && isset($this->db)) {
  354. if ($this->dropTables) {
  355. foreach (array_reverse($this->_fixtures) as $fixture) {
  356. $fixture->drop($this->db);
  357. }
  358. }
  359. $this->db->sources(true);
  360. Configure::write('Cache.disable', false);
  361. }
  362. if (class_exists('ClassRegistry')) {
  363. ClassRegistry::flush();
  364. }
  365. }
  366. /**
  367. * Announces the end of a test.
  368. *
  369. * @param string $method Test method just finished.
  370. *
  371. * @access public
  372. */
  373. function after($method) {
  374. if (isset($this->_fixtures) && isset($this->db) && !in_array(strtolower($method), array('start', 'end'))) {
  375. foreach ($this->_fixtures as $fixture) {
  376. $fixture->truncate($this->db);
  377. }
  378. $this->__truncated = true;
  379. } else {
  380. $this->__truncated = false;
  381. }
  382. if (!in_array(strtolower($method), $this->methods)) {
  383. $this->endTest($method);
  384. }
  385. $this->_should_skip = false;
  386. parent::after($method);
  387. }
  388. /**
  389. * Gets a list of test names. Normally that will be all internal methods that start with the
  390. * name "test". This method should be overridden if you want a different rule.
  391. *
  392. * @return array List of test names.
  393. *
  394. * @access public
  395. */
  396. function getTests() {
  397. $methods = array_diff(parent::getTests(), array('testAction', 'testaction'));
  398. $methods = array_merge(array_merge(array('start', 'startCase'), $methods), array('endCase', 'end'));
  399. return $methods;
  400. }
  401. /**
  402. * Chooses which fixtures to load for a given test
  403. *
  404. * @param string $fixture Each parameter is a model name that corresponds to a fixture, i.e. 'Post', 'Author', etc.
  405. * @access public
  406. * @see CakeTestCase::$autoFixtures
  407. */
  408. function loadFixtures() {
  409. $args = func_get_args();
  410. foreach ($args as $class) {
  411. if (isset($this->_fixtureClassMap[$class])) {
  412. $fixture = $this->_fixtures[$this->_fixtureClassMap[$class]];
  413. $fixture->truncate($this->db);
  414. $fixture->insert($this->db);
  415. } else {
  416. trigger_error("Non-existent fixture class {$class} referenced in test", E_USER_WARNING);
  417. }
  418. }
  419. }
  420. /**
  421. * Takes an array $expected and generates a regex from it to match the provided $string. Samples for $expected:
  422. *
  423. * Checks for an input tag with a name attribute (contains any non-empty value) and an id attribute that contains 'my-input':
  424. * array('input' => array('name', 'id' => 'my-input'))
  425. *
  426. * Checks for two p elements with some text in them:
  427. * array(
  428. * array('p' => true),
  429. * 'textA',
  430. * '/p',
  431. * array('p' => true),
  432. * 'textB',
  433. * '/p'
  434. * )
  435. *
  436. * You can also specify a pattern expression as part of the attribute values, or the tag being defined,
  437. * if you prepend the value with preg: and enclose it with slashes, like so:
  438. * array(
  439. * array('input' => array('name', 'id' => 'preg:/FieldName\d+/')),
  440. * 'preg:/My\s+field/'
  441. * )
  442. *
  443. * Important: This function is very forgiving about whitespace and also accepts any permutation of attribute order.
  444. * It will also allow whitespaces between specified tags.
  445. *
  446. * @param string $string An HTML/XHTML/XML string
  447. * @param array $expected An array, see above
  448. * @param string $message SimpleTest failure output string
  449. * @access public
  450. */
  451. function assertTags($string, $expected, $fullDebug = false) {
  452. $regex = array();
  453. $normalized = array();
  454. foreach ((array) $expected as $key => $val) {
  455. if (!is_numeric($key)) {
  456. $normalized[] = array($key => $val);
  457. } else {
  458. $normalized[] = $val;
  459. }
  460. }
  461. $i = 0;
  462. foreach ($normalized as $tags) {
  463. $i++;
  464. if (is_string($tags) && $tags{0} == '<') {
  465. $tags = array(substr($tags, 1) => array());
  466. } elseif (is_string($tags)) {
  467. if (preg_match('/^\*?\//', $tags, $match)) {
  468. $prefix = array(null, null);
  469. if ($match[0] == '*/') {
  470. $prefix = array('Anything, ', '.*?');
  471. }
  472. $regex[] = array(
  473. sprintf('%sClose %s tag', $prefix[0], substr($tags, strlen($match[0]))),
  474. sprintf('%s<[\s]*\/[\s]*%s[\s]*>[\n\r]*', $prefix[1], substr($tags, strlen($match[0]))),
  475. $i,
  476. );
  477. continue;
  478. }
  479. if (!empty($tags) && preg_match('/^preg\:\/(.+)\/$/i', $tags, $matches)) {
  480. $tags = $matches[1];
  481. $type = 'Regex matches';
  482. } else {
  483. $tags = preg_quote($tags, '/');
  484. $type = 'Text equals';
  485. }
  486. $regex[] = array(
  487. sprintf('%s "%s"', $type, $tags),
  488. $tags,
  489. $i,
  490. );
  491. continue;
  492. }
  493. foreach ($tags as $tag => $attributes) {
  494. $regex[] = array(
  495. sprintf('Open %s tag', $tag),
  496. sprintf('[\s]*<%s', preg_quote($tag, '/')),
  497. $i,
  498. );
  499. if ($attributes === true) {
  500. $attributes = array();
  501. }
  502. $attrs = array();
  503. $explanations = array();
  504. foreach ($attributes as $attr => $val) {
  505. if (is_numeric($attr) && preg_match('/^preg\:\/(.+)\/$/i', $val, $matches)) {
  506. $attrs[] = $matches[1];
  507. $explanations[] = sprintf('Regex "%s" matches', $matches[1]);
  508. continue;
  509. } else {
  510. $quotes = '"';
  511. if (is_numeric($attr)) {
  512. $attr = $val;
  513. $val = '.+?';
  514. $explanations[] = sprintf('Attribute "%s" present', $attr);
  515. } else if (!empty($val) && preg_match('/^preg\:\/(.+)\/$/i', $val, $matches)) {
  516. $quotes = '"?';
  517. $val = $matches[1];
  518. $explanations[] = sprintf('Attribute "%s" matches "%s"', $attr, $val);
  519. } else {
  520. $explanations[] = sprintf('Attribute "%s" == "%s"', $attr, $val);
  521. $val = preg_quote($val, '/');
  522. }
  523. $attrs[] = '[\s]+'.preg_quote($attr, '/').'='.$quotes.$val.$quotes;
  524. }
  525. }
  526. if ($attrs) {
  527. $permutations = $this->__array_permute($attrs);
  528. $permutationTokens = array();
  529. foreach ($permutations as $permutation) {
  530. $permutationTokens[] = join('', $permutation);
  531. }
  532. $regex[] = array(
  533. sprintf('%s', join(', ', $explanations)),
  534. $permutationTokens,
  535. $i,
  536. );
  537. }
  538. $regex[] = array(
  539. sprintf('End %s tag', $tag),
  540. '[\s]*\/?[\s]*>[\n\r]*',
  541. $i,
  542. );
  543. }
  544. }
  545. foreach ($regex as $i => $assertation) {
  546. list($description, $expressions, $itemNum) = $assertation;
  547. $matches = false;
  548. foreach ((array)$expressions as $expression) {
  549. if (preg_match(sprintf('/^%s/s', $expression), $string, $match)) {
  550. $matches = true;
  551. $string = substr($string, strlen($match[0]));
  552. break;
  553. }
  554. }
  555. if (!$matches) {
  556. $this->assert(new TrueExpectation(), false, sprintf('Item #%d / regex #%d failed: %s', $itemNum, $i, $description));
  557. if ($fullDebug) {
  558. debug($string, true);
  559. debug($regex, true);
  560. }
  561. return false;
  562. }
  563. }
  564. return $this->assert(new TrueExpectation(), true, '%s');
  565. }
  566. /**
  567. * Generates all permutation of an array $items and returns them in a new array.
  568. *
  569. * @param array $items An array of items
  570. * @return array
  571. * @access public
  572. */
  573. function __array_permute($items, $perms = array()) {
  574. static $permuted;
  575. if (empty($perms)) {
  576. $permuted = array();
  577. }
  578. if (empty($items)) {
  579. $permuted[] = $perms;
  580. } else {
  581. $numItems = count($items) - 1;
  582. for ($i = $numItems; $i >= 0; --$i) {
  583. $newItems = $items;
  584. $newPerms = $perms;
  585. list($tmp) = array_splice($newItems, $i, 1);
  586. array_unshift($newPerms, $tmp);
  587. $this->__array_permute($newItems, $newPerms);
  588. }
  589. return $permuted;
  590. }
  591. }
  592. /**
  593. * Initialize DB connection.
  594. *
  595. * @access protected
  596. */
  597. function _initDb() {
  598. $testDbAvailable = in_array('test', array_keys(ConnectionManager::enumConnectionObjects()));
  599. $_prefix = null;
  600. if ($testDbAvailable) {
  601. // Try for test DB
  602. restore_error_handler();
  603. @$db =& ConnectionManager::getDataSource('test');
  604. set_error_handler('simpleTestErrorHandler');
  605. $testDbAvailable = $db->isConnected();
  606. }
  607. // Try for default DB
  608. if (!$testDbAvailable) {
  609. $db =& ConnectionManager::getDataSource('default');
  610. $_prefix = $db->config['prefix'];
  611. $db->config['prefix'] = 'test_suite_';
  612. }
  613. ConnectionManager::create('test_suite', $db->config);
  614. $db->config['prefix'] = $_prefix;
  615. // Get db connection
  616. $this->db =& ConnectionManager::getDataSource('test_suite');
  617. $this->db->cacheSources = false;
  618. ClassRegistry::config(array('ds' => 'test_suite'));
  619. }
  620. /**
  621. * Load fixtures specified in var $fixtures.
  622. *
  623. * @access private
  624. */
  625. function _loadFixtures() {
  626. if (!isset($this->fixtures) || empty($this->fixtures)) {
  627. return;
  628. }
  629. if (!is_array($this->fixtures)) {
  630. $this->fixtures = array_map('trim', explode(',', $this->fixtures));
  631. }
  632. $this->_fixtures = array();
  633. foreach ($this->fixtures as $index => $fixture) {
  634. $fixtureFile = null;
  635. if (strpos($fixture, 'core.') === 0) {
  636. $fixture = substr($fixture, strlen('core.'));
  637. foreach (Configure::corePaths('cake') as $key => $path) {
  638. $fixturePaths[] = $path . 'tests' . DS . 'fixtures';
  639. }
  640. } elseif (strpos($fixture, 'app.') === 0) {
  641. $fixture = substr($fixture, strlen('app.'));
  642. $fixturePaths = array(
  643. TESTS . 'fixtures',
  644. VENDORS . 'tests' . DS . 'fixtures'
  645. );
  646. } elseif (strpos($fixture, 'plugin.') === 0) {
  647. $parts = explode('.', $fixture, 3);
  648. $pluginName = $parts[1];
  649. $fixture = $parts[2];
  650. $fixturePaths = array(
  651. APP . 'plugins' . DS . $pluginName . DS . 'tests' . DS . 'fixtures',
  652. TESTS . 'fixtures',
  653. VENDORS . 'tests' . DS . 'fixtures'
  654. );
  655. $pluginPaths = Configure::read('pluginPaths');
  656. foreach ($pluginPaths as $path) {
  657. if (file_exists($path . $pluginName . DS . 'tests' . DS. 'fixtures')) {
  658. $fixturePaths[0] = $path . $pluginName . DS . 'tests' . DS. 'fixtures';
  659. break;
  660. }
  661. }
  662. } else {
  663. $fixturePaths = array(
  664. TESTS . 'fixtures',
  665. VENDORS . 'tests' . DS . 'fixtures',
  666. TEST_CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'tests' . DS . 'fixtures'
  667. );
  668. }
  669. foreach ($fixturePaths as $path) {
  670. if (is_readable($path . DS . $fixture . '_fixture.php')) {
  671. $fixtureFile = $path . DS . $fixture . '_fixture.php';
  672. break;
  673. }
  674. }
  675. if (isset($fixtureFile)) {
  676. require_once($fixtureFile);
  677. $fixtureClass = Inflector::camelize($fixture) . 'Fixture';
  678. $this->_fixtures[$this->fixtures[$index]] =& new $fixtureClass($this->db);
  679. $this->_fixtureClassMap[Inflector::camelize($fixture)] = $this->fixtures[$index];
  680. }
  681. }
  682. if (empty($this->_fixtures)) {
  683. unset($this->_fixtures);
  684. }
  685. }
  686. }
  687. ?>