PageRenderTime 70ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/cake/tests/lib/cake_test_case.php

https://github.com/hardsshah/bookmarks
PHP | 757 lines | 477 code | 56 blank | 224 comment | 104 complexity | 4b3ecbec6b880de2f8c08135f0aed665 MD5 | raw file
  1. <?php
  2. /* SVN FILE: $Id$ */
  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$
  23. * @modifiedby $LastChangedBy$
  24. * @lastmodified $Date$
  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) && $this->dropTables) {
  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. * Params:
  221. * - 'return' has several possible values:
  222. * 1. 'result': Whatever the action returns (and also specifies $this->params['requested'] for controller)
  223. * 2. 'view': The rendered view, without the layout
  224. * 3. 'contents': The rendered view, within the layout.
  225. * 4. 'vars': the view vars
  226. *
  227. * - 'fixturize' - Set to true if you want to copy model data from 'connection' to the test_suite connection
  228. * - 'data' - The data you want to insert into $this->data in the controller.
  229. * - 'connection' - Which connection to use in conjunction with fixturize (defaults to 'default')
  230. * - 'method' - What type of HTTP method to simulate (defaults to post)
  231. *
  232. * @param string $url Cake URL to execute (e.g: /articles/view/455)
  233. * @param mixed $params Parameters (see above), or simply a string of what to return
  234. * @return mixed Whatever is returned depending of requested result
  235. * @access public
  236. */
  237. function testAction($url, $params = array()) {
  238. $default = array(
  239. 'return' => 'result',
  240. 'fixturize' => false,
  241. 'data' => array(),
  242. 'method' => 'post',
  243. 'connection' => 'default'
  244. );
  245. if (is_string($params)) {
  246. $params = array('return' => $params);
  247. }
  248. $params = array_merge($default, $params);
  249. $toSave = array(
  250. 'case' => null,
  251. 'group' => null,
  252. 'app' => null,
  253. 'output' => null,
  254. 'show' => null,
  255. 'plugin' => null
  256. );
  257. $this->__savedGetData = (empty($this->__savedGetData))
  258. ? array_intersect_key($_GET, $toSave)
  259. : $this->__savedGetData;
  260. $data = (!empty($params['data'])) ? $params['data'] : array();
  261. if (strtolower($params['method']) == 'get') {
  262. $_GET = array_merge($this->__savedGetData, $data);
  263. $_POST = array();
  264. } else {
  265. $_POST = array('data' => $data);
  266. $_GET = $this->__savedGetData;
  267. }
  268. $return = $params['return'];
  269. $params = array_diff_key($params, array('data' => null, 'method' => null, 'return' => null));
  270. $dispatcher =& new CakeTestDispatcher();
  271. $dispatcher->testCase($this);
  272. if ($return != 'result') {
  273. if ($return != 'contents') {
  274. $params['layout'] = false;
  275. }
  276. ob_start();
  277. @$dispatcher->dispatch($url, $params);
  278. $result = ob_get_clean();
  279. if ($return == 'vars') {
  280. $view =& ClassRegistry::getObject('view');
  281. $viewVars = $view->getVars();
  282. $result = array();
  283. foreach ($viewVars as $var) {
  284. $result[$var] = $view->getVar($var);
  285. }
  286. if (!empty($view->pageTitle)) {
  287. $result = array_merge($result, array('title' => $view->pageTitle));
  288. }
  289. }
  290. } else {
  291. $params['return'] = 1;
  292. $params['bare'] = 1;
  293. $params['requested'] = 1;
  294. $result = @$dispatcher->dispatch($url, $params);
  295. }
  296. if (isset($this->_actionFixtures)) {
  297. unset($this->_actionFixtures);
  298. }
  299. ClassRegistry::flush();
  300. return $result;
  301. }
  302. /**
  303. * Announces the start of a test.
  304. *
  305. * @param string $method Test method just started.
  306. *
  307. * @access public
  308. */
  309. function before($method) {
  310. parent::before($method);
  311. if (isset($this->fixtures) && (!is_array($this->fixtures) || empty($this->fixtures))) {
  312. unset($this->fixtures);
  313. }
  314. // Set up DB connection
  315. if (isset($this->fixtures) && strtolower($method) == 'start') {
  316. $this->_initDb();
  317. $this->_loadFixtures();
  318. }
  319. // Create records
  320. if (isset($this->_fixtures) && isset($this->db) && !in_array(strtolower($method), array('start', 'end')) && $this->__truncated && $this->autoFixtures == true) {
  321. foreach ($this->_fixtures as $fixture) {
  322. $inserts = $fixture->insert($this->db);
  323. }
  324. }
  325. if (!in_array(strtolower($method), $this->methods)) {
  326. $this->startTest($method);
  327. }
  328. }
  329. /**
  330. * Runs as first test to create tables.
  331. *
  332. * @access public
  333. */
  334. function start() {
  335. if (isset($this->_fixtures) && isset($this->db)) {
  336. Configure::write('Cache.disable', true);
  337. $cacheSources = $this->db->cacheSources;
  338. $this->db->cacheSources = false;
  339. $sources = $this->db->listSources();
  340. $this->db->cacheSources = $cacheSources;
  341. if (!$this->dropTables) {
  342. return;
  343. }
  344. foreach ($this->_fixtures as $fixture) {
  345. if (in_array($fixture->table, $sources)) {
  346. $fixture->drop($this->db);
  347. $fixture->create($this->db);
  348. } elseif (!in_array($fixture->table, $sources)) {
  349. $fixture->create($this->db);
  350. }
  351. }
  352. }
  353. }
  354. /**
  355. * Runs as last test to drop tables.
  356. *
  357. * @access public
  358. */
  359. function end() {
  360. if (isset($this->_fixtures) && isset($this->db)) {
  361. if ($this->dropTables) {
  362. foreach (array_reverse($this->_fixtures) as $fixture) {
  363. $fixture->drop($this->db);
  364. }
  365. }
  366. $this->db->sources(true);
  367. Configure::write('Cache.disable', false);
  368. }
  369. if (class_exists('ClassRegistry')) {
  370. ClassRegistry::flush();
  371. }
  372. }
  373. /**
  374. * Announces the end of a test.
  375. *
  376. * @param string $method Test method just finished.
  377. *
  378. * @access public
  379. */
  380. function after($method) {
  381. $isTestMethod = !in_array(strtolower($method), array('start', 'end'));
  382. if (isset($this->_fixtures) && isset($this->db) && $isTestMethod) {
  383. foreach ($this->_fixtures as $fixture) {
  384. $fixture->truncate($this->db);
  385. }
  386. $this->__truncated = true;
  387. } else {
  388. $this->__truncated = false;
  389. }
  390. if (!in_array(strtolower($method), $this->methods)) {
  391. $this->endTest($method);
  392. }
  393. $this->_should_skip = false;
  394. parent::after($method);
  395. }
  396. /**
  397. * Gets a list of test names. Normally that will be all internal methods that start with the
  398. * name "test". This method should be overridden if you want a different rule.
  399. *
  400. * @return array List of test names.
  401. *
  402. * @access public
  403. */
  404. function getTests() {
  405. return array_merge(
  406. array('start', 'startCase'),
  407. array_diff(parent::getTests(), array('testAction', 'testaction')),
  408. array('endCase', 'end')
  409. );
  410. }
  411. /**
  412. * Chooses which fixtures to load for a given test
  413. *
  414. * @param string $fixture Each parameter is a model name that corresponds to a
  415. * fixture, i.e. 'Post', 'Author', etc.
  416. * @access public
  417. * @see CakeTestCase::$autoFixtures
  418. */
  419. function loadFixtures() {
  420. $args = func_get_args();
  421. foreach ($args as $class) {
  422. if (isset($this->_fixtureClassMap[$class])) {
  423. $fixture = $this->_fixtures[$this->_fixtureClassMap[$class]];
  424. $fixture->truncate($this->db);
  425. $fixture->insert($this->db);
  426. } else {
  427. trigger_error("Referenced fixture class {$class} not found", E_USER_WARNING);
  428. }
  429. }
  430. }
  431. /**
  432. * Takes an array $expected and generates a regex from it to match the provided $string.
  433. * Samples for $expected:
  434. *
  435. * Checks for an input tag with a name attribute (contains any non-empty value) and an id
  436. * attribute that contains 'my-input':
  437. * array('input' => array('name', 'id' => 'my-input'))
  438. *
  439. * Checks for two p elements with some text in them:
  440. * array(
  441. * array('p' => true),
  442. * 'textA',
  443. * '/p',
  444. * array('p' => true),
  445. * 'textB',
  446. * '/p'
  447. * )
  448. *
  449. * You can also specify a pattern expression as part of the attribute values, or the tag
  450. * being defined, if you prepend the value with preg: and enclose it with slashes, like so:
  451. * array(
  452. * array('input' => array('name', 'id' => 'preg:/FieldName\d+/')),
  453. * 'preg:/My\s+field/'
  454. * )
  455. *
  456. * Important: This function is very forgiving about whitespace and also accepts any
  457. * permutation of attribute order. It will also allow whitespaces between specified tags.
  458. *
  459. * @param string $string An HTML/XHTML/XML string
  460. * @param array $expected An array, see above
  461. * @param string $message SimpleTest failure output string
  462. * @access public
  463. */
  464. function assertTags($string, $expected, $fullDebug = false) {
  465. $regex = array();
  466. $normalized = array();
  467. foreach ((array) $expected as $key => $val) {
  468. if (!is_numeric($key)) {
  469. $normalized[] = array($key => $val);
  470. } else {
  471. $normalized[] = $val;
  472. }
  473. }
  474. $i = 0;
  475. foreach ($normalized as $tags) {
  476. $i++;
  477. if (is_string($tags) && $tags{0} == '<') {
  478. $tags = array(substr($tags, 1) => array());
  479. } elseif (is_string($tags)) {
  480. $tagsTrimmed = preg_replace('/\s+/m', '', $tags);
  481. if (preg_match('/^\*?\//', $tags, $match) && $tagsTrimmed !== '//') {
  482. $prefix = array(null, null);
  483. if ($match[0] == '*/') {
  484. $prefix = array('Anything, ', '.*?');
  485. }
  486. $regex[] = array(
  487. sprintf('%sClose %s tag', $prefix[0], substr($tags, strlen($match[0]))),
  488. sprintf('%s<[\s]*\/[\s]*%s[\s]*>[\n\r]*', $prefix[1], substr($tags, strlen($match[0]))),
  489. $i,
  490. );
  491. continue;
  492. }
  493. if (!empty($tags) && preg_match('/^preg\:\/(.+)\/$/i', $tags, $matches)) {
  494. $tags = $matches[1];
  495. $type = 'Regex matches';
  496. } else {
  497. $tags = preg_quote($tags, '/');
  498. $type = 'Text equals';
  499. }
  500. $regex[] = array(
  501. sprintf('%s "%s"', $type, $tags),
  502. $tags,
  503. $i,
  504. );
  505. continue;
  506. }
  507. foreach ($tags as $tag => $attributes) {
  508. $regex[] = array(
  509. sprintf('Open %s tag', $tag),
  510. sprintf('[\s]*<%s', preg_quote($tag, '/')),
  511. $i,
  512. );
  513. if ($attributes === true) {
  514. $attributes = array();
  515. }
  516. $attrs = array();
  517. $explanations = array();
  518. foreach ($attributes as $attr => $val) {
  519. if (is_numeric($attr) && preg_match('/^preg\:\/(.+)\/$/i', $val, $matches)) {
  520. $attrs[] = $matches[1];
  521. $explanations[] = sprintf('Regex "%s" matches', $matches[1]);
  522. continue;
  523. } else {
  524. $quotes = '"';
  525. if (is_numeric($attr)) {
  526. $attr = $val;
  527. $val = '.+?';
  528. $explanations[] = sprintf('Attribute "%s" present', $attr);
  529. } elseif (!empty($val) && preg_match('/^preg\:\/(.+)\/$/i', $val, $matches)) {
  530. $quotes = '"?';
  531. $val = $matches[1];
  532. $explanations[] = sprintf('Attribute "%s" matches "%s"', $attr, $val);
  533. } else {
  534. $explanations[] = sprintf('Attribute "%s" == "%s"', $attr, $val);
  535. $val = preg_quote($val, '/');
  536. }
  537. $attrs[] = '[\s]+'.preg_quote($attr, '/').'='.$quotes.$val.$quotes;
  538. }
  539. }
  540. if ($attrs) {
  541. $permutations = $this->__array_permute($attrs);
  542. $permutationTokens = array();
  543. foreach ($permutations as $permutation) {
  544. $permutationTokens[] = join('', $permutation);
  545. }
  546. $regex[] = array(
  547. sprintf('%s', join(', ', $explanations)),
  548. $permutationTokens,
  549. $i,
  550. );
  551. }
  552. $regex[] = array(
  553. sprintf('End %s tag', $tag),
  554. '[\s]*\/?[\s]*>[\n\r]*',
  555. $i,
  556. );
  557. }
  558. }
  559. foreach ($regex as $i => $assertation) {
  560. list($description, $expressions, $itemNum) = $assertation;
  561. $matches = false;
  562. foreach ((array)$expressions as $expression) {
  563. if (preg_match(sprintf('/^%s/s', $expression), $string, $match)) {
  564. $matches = true;
  565. $string = substr($string, strlen($match[0]));
  566. break;
  567. }
  568. }
  569. if (!$matches) {
  570. $this->assert(new TrueExpectation(), false, sprintf('Item #%d / regex #%d failed: %s', $itemNum, $i, $description));
  571. if ($fullDebug) {
  572. debug($string, true);
  573. debug($regex, true);
  574. }
  575. return false;
  576. }
  577. }
  578. return $this->assert(new TrueExpectation(), true, '%s');
  579. }
  580. /**
  581. * Generates all permutation of an array $items and returns them in a new array.
  582. *
  583. * @param array $items An array of items
  584. * @return array
  585. * @access public
  586. */
  587. function __array_permute($items, $perms = array()) {
  588. static $permuted;
  589. if (empty($perms)) {
  590. $permuted = array();
  591. }
  592. if (empty($items)) {
  593. $permuted[] = $perms;
  594. } else {
  595. $numItems = count($items) - 1;
  596. for ($i = $numItems; $i >= 0; --$i) {
  597. $newItems = $items;
  598. $newPerms = $perms;
  599. list($tmp) = array_splice($newItems, $i, 1);
  600. array_unshift($newPerms, $tmp);
  601. $this->__array_permute($newItems, $newPerms);
  602. }
  603. return $permuted;
  604. }
  605. }
  606. /**
  607. * Initialize DB connection.
  608. *
  609. * @access protected
  610. */
  611. function _initDb() {
  612. $testDbAvailable = in_array('test', array_keys(ConnectionManager::enumConnectionObjects()));
  613. $_prefix = null;
  614. if ($testDbAvailable) {
  615. // Try for test DB
  616. restore_error_handler();
  617. @$db =& ConnectionManager::getDataSource('test');
  618. set_error_handler('simpleTestErrorHandler');
  619. $testDbAvailable = $db->isConnected();
  620. }
  621. // Try for default DB
  622. if (!$testDbAvailable) {
  623. $db =& ConnectionManager::getDataSource('default');
  624. $_prefix = $db->config['prefix'];
  625. $db->config['prefix'] = 'test_suite_';
  626. }
  627. ConnectionManager::create('test_suite', $db->config);
  628. $db->config['prefix'] = $_prefix;
  629. // Get db connection
  630. $this->db =& ConnectionManager::getDataSource('test_suite');
  631. $this->db->cacheSources = false;
  632. ClassRegistry::config(array('ds' => 'test_suite'));
  633. }
  634. /**
  635. * Load fixtures specified in var $fixtures.
  636. *
  637. * @access private
  638. */
  639. function _loadFixtures() {
  640. if (!isset($this->fixtures) || empty($this->fixtures)) {
  641. return;
  642. }
  643. if (!is_array($this->fixtures)) {
  644. $this->fixtures = array_map('trim', explode(',', $this->fixtures));
  645. }
  646. $this->_fixtures = array();
  647. foreach ($this->fixtures as $index => $fixture) {
  648. $fixtureFile = null;
  649. if (strpos($fixture, 'core.') === 0) {
  650. $fixture = substr($fixture, strlen('core.'));
  651. foreach (Configure::corePaths('cake') as $key => $path) {
  652. $fixturePaths[] = $path . 'tests' . DS . 'fixtures';
  653. }
  654. } elseif (strpos($fixture, 'app.') === 0) {
  655. $fixture = substr($fixture, strlen('app.'));
  656. $fixturePaths = array(
  657. TESTS . 'fixtures',
  658. VENDORS . 'tests' . DS . 'fixtures'
  659. );
  660. } elseif (strpos($fixture, 'plugin.') === 0) {
  661. $parts = explode('.', $fixture, 3);
  662. $pluginName = $parts[1];
  663. $fixture = $parts[2];
  664. $fixturePaths = array(
  665. APP . 'plugins' . DS . $pluginName . DS . 'tests' . DS . 'fixtures',
  666. TESTS . 'fixtures',
  667. VENDORS . 'tests' . DS . 'fixtures'
  668. );
  669. $pluginPaths = Configure::read('pluginPaths');
  670. foreach ($pluginPaths as $path) {
  671. if (file_exists($path . $pluginName . DS . 'tests' . DS. 'fixtures')) {
  672. $fixturePaths[0] = $path . $pluginName . DS . 'tests' . DS. 'fixtures';
  673. break;
  674. }
  675. }
  676. } else {
  677. $fixturePaths = array(
  678. TESTS . 'fixtures',
  679. VENDORS . 'tests' . DS . 'fixtures',
  680. TEST_CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'tests' . DS . 'fixtures'
  681. );
  682. }
  683. foreach ($fixturePaths as $path) {
  684. if (is_readable($path . DS . $fixture . '_fixture.php')) {
  685. $fixtureFile = $path . DS . $fixture . '_fixture.php';
  686. break;
  687. }
  688. }
  689. if (isset($fixtureFile)) {
  690. require_once($fixtureFile);
  691. $fixtureClass = Inflector::camelize($fixture) . 'Fixture';
  692. $this->_fixtures[$this->fixtures[$index]] =& new $fixtureClass($this->db);
  693. $this->_fixtureClassMap[Inflector::camelize($fixture)] = $this->fixtures[$index];
  694. }
  695. }
  696. if (empty($this->_fixtures)) {
  697. unset($this->_fixtures);
  698. }
  699. }
  700. }
  701. ?>