Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -2,19 +2,18 @@
/**
* A factory class to manage the life cycle of test fixtures
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.TestSuite.Fixture
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('ConnectionManager', 'Model');
@ -30,7 +29,7 @@ class CakeFixtureManager {
/**
* Was this class already initialized?
*
* @var boolean
* @var bool
*/
protected $_initialized = false;
@ -96,6 +95,23 @@ class CakeFixtureManager {
$this->_initialized = true;
}
/**
* Parse the fixture path included in test cases, to get the fixture class name, and the
* real fixture path including sub-directories
*
* @param string $fixturePath the fixture path to parse
* @return array containing fixture class name and optional additional path
*/
protected function _parseFixturePath($fixturePath) {
$pathTokenArray = explode('/', $fixturePath);
$fixture = array_pop($pathTokenArray);
$additionalPath = '';
foreach ($pathTokenArray as $pathToken) {
$additionalPath .= DS . $pathToken;
}
return array('fixture' => $fixture, 'additionalPath' => $additionalPath);
}
/**
* Looks for fixture files and instantiates the classes accordingly
*
@ -104,7 +120,7 @@ class CakeFixtureManager {
* @throws UnexpectedValueException when a referenced fixture does not exist.
*/
protected function _loadFixtures($fixtures) {
foreach ($fixtures as $index => $fixture) {
foreach ($fixtures as $fixture) {
$fixtureFile = null;
$fixtureIndex = $fixture;
if (isset($this->_loaded[$fixture])) {
@ -115,17 +131,20 @@ class CakeFixtureManager {
$fixture = substr($fixture, strlen('core.'));
$fixturePaths[] = CAKE . 'Test' . DS . 'Fixture';
} elseif (strpos($fixture, 'app.') === 0) {
$fixture = substr($fixture, strlen('app.'));
$fixturePrefixLess = substr($fixture, strlen('app.'));
$fixtureParsedPath = $this->_parseFixturePath($fixturePrefixLess);
$fixture = $fixtureParsedPath['fixture'];
$fixturePaths = array(
TESTS . 'Fixture'
TESTS . 'Fixture' . $fixtureParsedPath['additionalPath']
);
} elseif (strpos($fixture, 'plugin.') === 0) {
$parts = explode('.', $fixture, 3);
$pluginName = $parts[1];
$fixture = $parts[2];
$explodedFixture = explode('.', $fixture, 3);
$pluginName = $explodedFixture[1];
$fixtureParsedPath = $this->_parseFixturePath($explodedFixture[2]);
$fixture = $fixtureParsedPath['fixture'];
$fixturePaths = array(
CakePlugin::path(Inflector::camelize($pluginName)) . 'Test' . DS . 'Fixture',
TESTS . 'Fixture'
CakePlugin::path(Inflector::camelize($pluginName)) . 'Test' . DS . 'Fixture' . $fixtureParsedPath['additionalPath'],
TESTS . 'Fixture' . $fixtureParsedPath['additionalPath']
);
} else {
$fixturePaths = array(
@ -160,7 +179,7 @@ class CakeFixtureManager {
*
* @param CakeTestFixture $fixture the fixture object to create
* @param DataSource $db the datasource instance to use
* @param boolean $drop whether drop the fixture if it is already created or not
* @param bool $drop whether drop the fixture if it is already created or not
* @return void
*/
protected function _setupTable($fixture, $db = null, $drop = true) {
@ -175,7 +194,7 @@ class CakeFixtureManager {
return;
}
$sources = $db->listSources();
$sources = (array)$db->listSources();
$table = $db->config['prefix'] . $fixture->table;
$exists = in_array($table, $sources);
@ -200,7 +219,7 @@ class CakeFixtureManager {
return;
}
$fixtures = $test->fixtures;
if (empty($fixtures) || $test->autoFixtures == false) {
if (empty($fixtures) || !$test->autoFixtures) {
return;
}
@ -210,6 +229,7 @@ class CakeFixtureManager {
$db = ConnectionManager::getDataSource($fixture->useDbConfig);
$db->begin();
$this->_setupTable($fixture, $db, $test->dropTables);
$fixture->truncate($db);
$fixture->insert($db);
$db->commit();
}
@ -242,17 +262,18 @@ class CakeFixtureManager {
*
* @param string $name of the fixture
* @param DataSource $db DataSource instance or leave null to get DataSource from the fixture
* @param bool $dropTables Whether or not tables should be dropped and re-created.
* @return void
* @throws UnexpectedValueException if $name is not a previously loaded class
*/
public function loadSingle($name, $db = null) {
public function loadSingle($name, $db = null, $dropTables = true) {
$name .= 'Fixture';
if (isset($this->_fixtureMap[$name])) {
$fixture = $this->_fixtureMap[$name];
if (!$db) {
$db = ConnectionManager::getDataSource($fixture->useDbConfig);
}
$this->_setupTable($fixture, $db);
$this->_setupTable($fixture, $db, $dropTables);
$fixture->truncate($db);
$fixture->insert($db);
} else {
@ -263,9 +284,15 @@ class CakeFixtureManager {
/**
* Drop all fixture tables loaded by this class
*
* This will also close the session, as failing to do so will cause
* fatal errors with database sessions.
*
* @return void
*/
public function shutDown() {
if (session_id()) {
session_write_close();
}
foreach ($this->_loaded as $fixture) {
if (!empty($fixture->created)) {
foreach ($fixture->created as $ds) {