mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge branch '2.0' into 2.0-request
Conflicts: cake/libs/router.php cake/tests/cases/dispatcher.test.php cake/tests/cases/libs/controller/components/auth.test.php cake/tests/cases/libs/controller/components/request_handler.test.php cake/tests/cases/libs/controller/controller.test.php cake/tests/cases/libs/router.test.php cake/tests/cases/libs/view/helpers/html.test.php cake/tests/cases/libs/view/helpers/js.test.php
This commit is contained in:
commit
7c0cda7ce5
170 changed files with 7480 additions and 8180 deletions
|
@ -19,6 +19,7 @@
|
||||||
* @since CakePHP(tm) v 1.2.0.5012
|
* @since CakePHP(tm) v 1.2.0.5012
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
|
App::import('Core', 'File');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API shell to show method signatures of CakePHP core classes.
|
* API shell to show method signatures of CakePHP core classes.
|
||||||
|
@ -91,7 +92,7 @@ class ApiShell extends Shell {
|
||||||
$this->_stop();
|
$this->_stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
$parsed = $this->__parseClass($path . $file .'.php');
|
$parsed = $this->__parseClass($path . $file .'.php', $class);
|
||||||
|
|
||||||
if (!empty($parsed)) {
|
if (!empty($parsed)) {
|
||||||
if (isset($this->params['m'])) {
|
if (isset($this->params['m'])) {
|
||||||
|
@ -116,7 +117,7 @@ class ApiShell extends Shell {
|
||||||
while ($number = strtolower($this->in(__('Select a number to see the more information about a specific method. q to quit. l to list.'), null, 'q'))) {
|
while ($number = strtolower($this->in(__('Select a number to see the more information about a specific method. q to quit. l to list.'), null, 'q'))) {
|
||||||
if ($number === 'q') {
|
if ($number === 'q') {
|
||||||
$this->out(__('Done'));
|
$this->out(__('Done'));
|
||||||
$this->_stop();
|
return $this->_stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($number === 'l') {
|
if ($number === 'l') {
|
||||||
|
@ -180,30 +181,35 @@ class ApiShell extends Shell {
|
||||||
* @return array Methods and signatures indexed by method name
|
* @return array Methods and signatures indexed by method name
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __parseClass($path) {
|
function __parseClass($path, $class) {
|
||||||
$parsed = array();
|
$parsed = array();
|
||||||
|
|
||||||
$File = new File($path);
|
if (!include_once($path)) {
|
||||||
if (!$File->exists()) {
|
$this->err(sprintf(__('%s could not be found'), $path));
|
||||||
$this->err(sprintf(__('%s could not be found'), $File->name));
|
|
||||||
$this->_stop();
|
|
||||||
}
|
}
|
||||||
|
$reflection = new ReflectionClass($class);
|
||||||
|
|
||||||
$contents = $File->read();
|
foreach ($reflection->getMethods() as $method) {
|
||||||
|
if (!$method->isPublic() || strpos($method->getName(), '_') === 0) {
|
||||||
if (preg_match_all('%(/\\*\\*[\\s\\S]*?\\*/)(\\s+function\\s+\\w+)(\\(.*\\))%', $contents, $result, PREG_PATTERN_ORDER)) {
|
continue;
|
||||||
foreach ($result[2] as $key => $method) {
|
}
|
||||||
$method = str_replace('function ', '', trim($method));
|
if ($method->getDeclaringClass()->getName() != $class) {
|
||||||
|
continue;
|
||||||
if (strpos($method, '__') === false && $method[0] != '_') {
|
}
|
||||||
$parsed[$method] = array(
|
$args = array();
|
||||||
'comment' => str_replace(array('/*', '*/', '*'), '', trim($result[1][$key])),
|
foreach ($method->getParameters() as $param) {
|
||||||
'method' => $method,
|
$paramString = '$' . $param->getName();
|
||||||
'parameters' => trim($result[3][$key])
|
if ($param->isDefaultValueAvailable()) {
|
||||||
|
$paramString .= ' = ' . str_replace("\n", '', var_export($param->getDefaultValue(), true));
|
||||||
|
}
|
||||||
|
$args[] = $paramString;
|
||||||
|
}
|
||||||
|
$parsed[$method->getName()] = array(
|
||||||
|
'comment' => str_replace(array('/*', '*/', '*'), '', $method->getDocComment()),
|
||||||
|
'method' => $method->getName(),
|
||||||
|
'parameters' => '(' . implode(', ', $args) . ')'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
ksort($parsed);
|
ksort($parsed);
|
||||||
return $parsed;
|
return $parsed;
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,7 +157,7 @@ class SchemaShell extends Shell {
|
||||||
$numToUse = $this->params['s'];
|
$numToUse = $this->params['s'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = 1;
|
$count = 0;
|
||||||
if (!empty($result[1])) {
|
if (!empty($result[1])) {
|
||||||
foreach ($result[1] as $file) {
|
foreach ($result[1] as $file) {
|
||||||
if (preg_match('/schema(?:[_\d]*)?\.php$/', $file)) {
|
if (preg_match('/schema(?:[_\d]*)?\.php$/', $file)) {
|
||||||
|
|
|
@ -411,10 +411,9 @@ class ControllerTask extends BakeTask {
|
||||||
|
|
||||||
while ($enteredController == '') {
|
while ($enteredController == '') {
|
||||||
$enteredController = $this->in(__("Enter a number from the list above,\ntype in the name of another controller, or 'q' to exit"), null, 'q');
|
$enteredController = $this->in(__("Enter a number from the list above,\ntype in the name of another controller, or 'q' to exit"), null, 'q');
|
||||||
|
|
||||||
if ($enteredController === 'q') {
|
if ($enteredController === 'q') {
|
||||||
$this->out(__('Exit'));
|
$this->out(__('Exit'));
|
||||||
$this->_stop();
|
return $this->_stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($enteredController == '' || intval($enteredController) > count($controllers)) {
|
if ($enteredController == '' || intval($enteredController) > count($controllers)) {
|
||||||
|
|
|
@ -40,7 +40,7 @@ class DbConfigTask extends Shell {
|
||||||
* @var array
|
* @var array
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
private $__defaultConfig = array(
|
protected $_defaultConfig = array(
|
||||||
'name' => 'default', 'driver'=> 'mysql', 'persistent'=> 'false', 'host'=> 'localhost',
|
'name' => 'default', 'driver'=> 'mysql', 'persistent'=> 'false', 'host'=> 'localhost',
|
||||||
'login'=> 'root', 'password'=> 'password', 'database'=> 'project_name',
|
'login'=> 'root', 'password'=> 'password', 'database'=> 'project_name',
|
||||||
'schema'=> null, 'prefix'=> null, 'encoding' => null, 'port' => null
|
'schema'=> null, 'prefix'=> null, 'encoding' => null, 'port' => null
|
||||||
|
@ -174,9 +174,10 @@ class DbConfigTask extends Shell {
|
||||||
|
|
||||||
$config = compact('name', 'driver', 'persistent', 'host', 'login', 'password', 'database', 'prefix', 'encoding', 'port', 'schema');
|
$config = compact('name', 'driver', 'persistent', 'host', 'login', 'password', 'database', 'prefix', 'encoding', 'port', 'schema');
|
||||||
|
|
||||||
while ($this->__verify($config) == false) {
|
while ($this->_verify($config) == false) {
|
||||||
$this->_interactive();
|
$this->_interactive();
|
||||||
}
|
}
|
||||||
|
|
||||||
$dbConfigs[] = $config;
|
$dbConfigs[] = $config;
|
||||||
$doneYet = $this->in('Do you wish to add another database configuration?', null, 'n');
|
$doneYet = $this->in('Do you wish to add another database configuration?', null, 'n');
|
||||||
|
|
||||||
|
@ -195,8 +196,8 @@ class DbConfigTask extends Shell {
|
||||||
*
|
*
|
||||||
* @return boolean True if user says it looks good, false otherwise
|
* @return boolean True if user says it looks good, false otherwise
|
||||||
*/
|
*/
|
||||||
private function __verify($config) {
|
protected function _verify($config) {
|
||||||
$config = array_merge($this->__defaultConfig, $config);
|
$config = array_merge($this->_defaultConfig, $config);
|
||||||
extract($config);
|
extract($config);
|
||||||
$this->out();
|
$this->out();
|
||||||
$this->hr();
|
$this->hr();
|
||||||
|
@ -257,7 +258,7 @@ class DbConfigTask extends Shell {
|
||||||
$temp = get_class_vars(get_class($db));
|
$temp = get_class_vars(get_class($db));
|
||||||
|
|
||||||
foreach ($temp as $configName => $info) {
|
foreach ($temp as $configName => $info) {
|
||||||
$info = array_merge($this->__defaultConfig, $info);
|
$info = array_merge($this->_defaultConfig, $info);
|
||||||
|
|
||||||
if (!isset($info['schema'])) {
|
if (!isset($info['schema'])) {
|
||||||
$info['schema'] = null;
|
$info['schema'] = null;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* @since CakePHP(tm) v 1.2.0.5012
|
* @since CakePHP(tm) v 1.2.0.5012
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
|
App::import('Core', 'File');
|
||||||
/**
|
/**
|
||||||
* Language string extractor
|
* Language string extractor
|
||||||
*
|
*
|
||||||
|
|
|
@ -22,52 +22,11 @@
|
||||||
class TestSuiteShell extends Shell {
|
class TestSuiteShell extends Shell {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The test category, "app", "core" or the name of a plugin
|
* Dispatcher object for the run.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var CakeTestDispatcher
|
||||||
* @access public
|
|
||||||
*/
|
*/
|
||||||
public $category = '';
|
protected $_dispatcher = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* "group", "case" or "all"
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
public $type = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Path to the test case/group file
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
public $file = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Storage for plugins that have tests
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
public $plugins = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience variable to avoid duplicated code
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
public $isPluginTest = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stores if the user wishes to get a code coverage analysis report
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
public $doCoverage = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialization method installs Simpletest and loads all plugins
|
* Initialization method installs Simpletest and loads all plugins
|
||||||
|
@ -75,69 +34,59 @@ class TestSuiteShell extends Shell {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function initialize() {
|
public function initialize() {
|
||||||
|
require_once CAKE . 'tests' . DS . 'lib' . DS . 'cake_test_suite_dispatcher.php';
|
||||||
|
|
||||||
$corePath = App::core('cake');
|
$corePath = App::core('cake');
|
||||||
if (isset($corePath[0])) {
|
if (isset($corePath[0])) {
|
||||||
define('TEST_CAKE_CORE_INCLUDE_PATH', rtrim($corePath[0], DS) . DS);
|
define('TEST_CAKE_CORE_INCLUDE_PATH', rtrim($corePath[0], DS) . DS);
|
||||||
} else {
|
} else {
|
||||||
define('TEST_CAKE_CORE_INCLUDE_PATH', CAKE_CORE_INCLUDE_PATH);
|
define('TEST_CAKE_CORE_INCLUDE_PATH', CAKE_CORE_INCLUDE_PATH);
|
||||||
}
|
}
|
||||||
|
$params = $this->parseArgs();
|
||||||
|
|
||||||
$this->__installSimpleTest();
|
$this->_dispatcher = new CakeTestSuiteDispatcher();
|
||||||
|
$this->_dispatcher->setParams($params);
|
||||||
require_once CAKE . 'tests' . DS . 'lib' . DS . 'test_manager.php';
|
|
||||||
require_once CAKE . 'tests' . DS . 'lib' . DS . 'reporter' . DS . 'cake_cli_reporter.php';
|
|
||||||
|
|
||||||
$plugins = App::objects('plugin');
|
|
||||||
foreach ($plugins as $p) {
|
|
||||||
$this->plugins[] = Inflector::underscore($p);
|
|
||||||
}
|
|
||||||
$this->parseArgs();
|
|
||||||
$this->getManager();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the arguments given into the Shell object properties.
|
* Parse the CLI options into an array CakeTestDispatcher can use.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return array Array of params for CakeTestDispatcher
|
||||||
*/
|
*/
|
||||||
public function parseArgs() {
|
public function parseArgs() {
|
||||||
if (empty($this->args)) {
|
if (empty($this->args)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->category = $this->args[0];
|
$params = array(
|
||||||
|
'app' => false,
|
||||||
|
'plugin' => null,
|
||||||
|
'output' => 'text',
|
||||||
|
'codeCoverage' => false,
|
||||||
|
'filter' => false,
|
||||||
|
'case' => null
|
||||||
|
);
|
||||||
|
|
||||||
if (!in_array($this->category, array('app', 'core'))) {
|
$category = $this->args[0];
|
||||||
$this->isPluginTest = true;
|
|
||||||
|
if ($category == 'app') {
|
||||||
|
$params['app'] = true;
|
||||||
|
} elseif ($category != 'core') {
|
||||||
|
$params['plugin'] = $category;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->args[1])) {
|
if (isset($this->args[1])) {
|
||||||
$this->type = $this->args[1];
|
$params['case'] = Inflector::underscore($this->args[1]) . '.test.php';
|
||||||
}
|
}
|
||||||
|
if (isset($this->args[2]) && $this->args[2] == 'cov') {
|
||||||
if (isset($this->args[2])) {
|
$params['codeCoverage'] = true;
|
||||||
if ($this->args[2] == 'cov') {
|
|
||||||
$this->doCoverage = true;
|
|
||||||
} else {
|
|
||||||
$this->file = Inflector::underscore($this->args[2]);
|
|
||||||
}
|
}
|
||||||
|
if (isset($this->params['filter'])) {
|
||||||
|
$params['filter'] = $this->params['filter'];
|
||||||
}
|
}
|
||||||
|
if (isset($this->params['coverage'])) {
|
||||||
if (isset($this->args[3]) && $this->args[3] == 'cov') {
|
$params['codeCoverage'] = true;
|
||||||
$this->doCoverage = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a manager instance, and set the app/plugin properties.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function getManager() {
|
|
||||||
$this->Manager = new TestManager();
|
|
||||||
$this->Manager->appTest = ($this->category === 'app');
|
|
||||||
if ($this->isPluginTest) {
|
|
||||||
$this->Manager->pluginTest = $this->category;
|
|
||||||
}
|
}
|
||||||
|
return $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -153,18 +102,12 @@ class TestSuiteShell extends Shell {
|
||||||
$this->error(__('Sorry, you did not pass any arguments!'));
|
$this->error(__('Sorry, you did not pass any arguments!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->__canRun()) {
|
$result = $this->_dispatcher->dispatch();
|
||||||
$message = sprintf(__('Running %s %s %s'), $this->category, $this->type, $this->file);
|
$exit = 0;
|
||||||
$this->out($message);
|
if ($result instanceof PHPUnit_Framework_TestResult) {
|
||||||
|
$exit = ($result->errorCount() + $result->failureCount()) > 0;
|
||||||
$exitCode = 0;
|
|
||||||
if (!$this->__run()) {
|
|
||||||
$exitCode = 1;
|
|
||||||
}
|
|
||||||
$this->_stop($exitCode);
|
|
||||||
} else {
|
|
||||||
$this->error(__('Sorry, the tests could not be found.'));
|
|
||||||
}
|
}
|
||||||
|
$this->_stop($exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -173,194 +116,36 @@ class TestSuiteShell extends Shell {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function help() {
|
public function help() {
|
||||||
$this->out('Usage: ');
|
$help = <<<TEXT
|
||||||
$this->out("\tcake testsuite category test_type file");
|
Usage:
|
||||||
$this->out("\t\t- category - \"app\", \"core\" or name of a plugin");
|
-----
|
||||||
$this->out("\t\t- test_type - \"case\", \"group\" or \"all\"");
|
cake testsuite <category> <file> [params]
|
||||||
$this->out("\t\t- test_file - file name with folder prefix and without the (test|group).php suffix");
|
- category - "app", "core" or name of a plugin
|
||||||
$this->out();
|
- file - file name with folder prefix and without the test.php suffix.
|
||||||
$this->out('Examples: ');
|
|
||||||
$this->out("\t\tcake testsuite app all");
|
|
||||||
$this->out("\t\tcake testsuite core all");
|
|
||||||
$this->out();
|
|
||||||
$this->out("\t\tcake testsuite app case behaviors/debuggable");
|
|
||||||
$this->out("\t\tcake testsuite app case models/my_model");
|
|
||||||
$this->out("\t\tcake testsuite app case controllers/my_controller");
|
|
||||||
$this->out();
|
|
||||||
$this->out("\t\tcake testsuite core case file");
|
|
||||||
$this->out("\t\tcake testsuite core case router");
|
|
||||||
$this->out("\t\tcake testsuite core case set");
|
|
||||||
$this->out();
|
|
||||||
$this->out("\t\tcake testsuite app group mygroup");
|
|
||||||
$this->out("\t\tcake testsuite core group acl");
|
|
||||||
$this->out("\t\tcake testsuite core group socket");
|
|
||||||
$this->out();
|
|
||||||
$this->out("\t\tcake testsuite bugs case models/bug");
|
|
||||||
$this->out("\t\t // for the plugin 'bugs' and its test case 'models/bug'");
|
|
||||||
$this->out("\t\tcake testsuite bugs group bug");
|
|
||||||
$this->out("\t\t // for the plugin bugs and its test group 'bug'");
|
|
||||||
$this->out();
|
|
||||||
$this->out('Code Coverage Analysis: ');
|
|
||||||
$this->out("\n\nAppend 'cov' to any of the above in order to enable code coverage analysis");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
Params:
|
||||||
* Checks if the arguments supplied point to a valid test file and thus the shell can be run.
|
-------
|
||||||
*
|
-filter
|
||||||
* @return bool true if it's a valid test file, false otherwise
|
The -filter option allows you supply a pattern that is used to match
|
||||||
* @access private
|
test method names. This can be a regular expression.
|
||||||
*/
|
|
||||||
function __canRun() {
|
|
||||||
$isNeitherAppNorCore = !in_array($this->category, array('app', 'core'));
|
|
||||||
$isPlugin = in_array(Inflector::underscore($this->category), $this->plugins);
|
|
||||||
|
|
||||||
if ($isNeitherAppNorCore && !$isPlugin) {
|
-coverage
|
||||||
$message = sprintf(
|
Enable code coverage for this run.
|
||||||
__('%s is an invalid test category (either "app", "core" or name of a plugin)'),
|
|
||||||
$this->category
|
|
||||||
);
|
|
||||||
$this->error($message);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$folder = $this->__findFolderByCategory($this->category);
|
Examples:
|
||||||
if (!file_exists($folder)) {
|
---------
|
||||||
$this->err(sprintf(__('%s not found'), $folder));
|
cake testsuite app behaviors/debuggable;
|
||||||
return false;
|
cake testsuite app models/my_model;
|
||||||
}
|
cake testsuite app controllers/my_controller
|
||||||
|
|
||||||
if (!in_array($this->type, array('all', 'group', 'case'))) {
|
cake testsuite core libs/file
|
||||||
$this->err(sprintf(__('%s is invalid. Should be case, group or all'), $this->type));
|
cake testsuite core libs/router
|
||||||
return false;
|
cake testsuite core libs/set
|
||||||
}
|
|
||||||
|
|
||||||
$fileName = $this->__getFileName($folder, $this->isPluginTest);
|
cake testsuite bugs models/bug
|
||||||
if ($fileName === true || file_exists($folder . $fileName)) {
|
// for the plugin 'bugs' and its test case 'models/bug'
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$message = sprintf(
|
TEXT;
|
||||||
__('%s %s %s is an invalid test identifier'),
|
$this->out($help);
|
||||||
$this->category, $this->type, $this->file
|
|
||||||
);
|
|
||||||
$this->err($message);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Executes the tests depending on our settings
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
function __run() {
|
|
||||||
$Reporter = new CakeCliReporter('utf-8', array(
|
|
||||||
'app' => $this->Manager->appTest,
|
|
||||||
'plugin' => $this->Manager->pluginTest,
|
|
||||||
'group' => ($this->type === 'group'),
|
|
||||||
'codeCoverage' => $this->doCoverage
|
|
||||||
));
|
|
||||||
|
|
||||||
if ($this->type == 'all') {
|
|
||||||
return $this->Manager->runAllTests($Reporter);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->doCoverage) {
|
|
||||||
if (!extension_loaded('xdebug')) {
|
|
||||||
$this->out(__('You must install Xdebug to use the CakePHP(tm) Code Coverage Analyzation. Download it from http://www.xdebug.org/docs/install'));
|
|
||||||
$this->_stop(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->type == 'group') {
|
|
||||||
$ucFirstGroup = ucfirst($this->file);
|
|
||||||
if ($this->doCoverage) {
|
|
||||||
require_once CAKE . 'tests' . DS . 'lib' . DS . 'code_coverage_manager.php';
|
|
||||||
CodeCoverageManager::init($ucFirstGroup, $Reporter);
|
|
||||||
CodeCoverageManager::start();
|
|
||||||
}
|
|
||||||
$result = $this->Manager->runGroupTest($ucFirstGroup, $Reporter);
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
$folder = $folder = $this->__findFolderByCategory($this->category);
|
|
||||||
$case = $this->__getFileName($folder, $this->isPluginTest);
|
|
||||||
|
|
||||||
if ($this->doCoverage) {
|
|
||||||
require_once CAKE . 'tests' . DS . 'lib' . DS . 'code_coverage_manager.php';
|
|
||||||
CodeCoverageManager::init($case, $Reporter);
|
|
||||||
CodeCoverageManager::start();
|
|
||||||
}
|
|
||||||
$result = $this->Manager->runTestCase($case, $Reporter);
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the concrete filename for the inputted test name and category/type
|
|
||||||
*
|
|
||||||
* @param string $folder Folder name to look for files in.
|
|
||||||
* @param boolean $isPlugin If the test case is a plugin.
|
|
||||||
* @return mixed Either string filename or boolean false on failure. Or true if the type is 'all'
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
function __getFileName($folder, $isPlugin) {
|
|
||||||
$ext = $this->Manager->getExtension($this->type);
|
|
||||||
switch ($this->type) {
|
|
||||||
case 'all':
|
|
||||||
return true;
|
|
||||||
case 'group':
|
|
||||||
return $this->file . $ext;
|
|
||||||
case 'case':
|
|
||||||
if ($this->category == 'app' || $isPlugin) {
|
|
||||||
return $this->file . $ext;
|
|
||||||
}
|
|
||||||
$coreCase = $this->file . $ext;
|
|
||||||
$coreLibCase = 'libs' . DS . $this->file . $ext;
|
|
||||||
|
|
||||||
if ($this->category == 'core' && file_exists($folder . DS . $coreCase)) {
|
|
||||||
return $coreCase;
|
|
||||||
} elseif ($this->category == 'core' && file_exists($folder . DS . $coreLibCase)) {
|
|
||||||
return $coreLibCase;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds the correct folder to look for tests for based on the input category and type.
|
|
||||||
*
|
|
||||||
* @param string $category The category of the test. Either 'app', 'core' or a plugin name.
|
|
||||||
* @return string the folder path
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
function __findFolderByCategory($category) {
|
|
||||||
$folder = '';
|
|
||||||
$paths = array(
|
|
||||||
'core' => CAKE,
|
|
||||||
'app' => APP
|
|
||||||
);
|
|
||||||
$typeDir = $this->type === 'group' ? 'groups' : 'cases';
|
|
||||||
|
|
||||||
if (array_key_exists($category, $paths)) {
|
|
||||||
$folder = $paths[$category] . 'tests' . DS . $typeDir . DS;
|
|
||||||
} else {
|
|
||||||
$pluginPath = App::pluginPath($category);
|
|
||||||
if (is_dir($pluginPath . 'tests')) {
|
|
||||||
$folder = $pluginPath . 'tests' . DS . $typeDir . DS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $folder;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* tries to install simpletest and exits gracefully if it is not there
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
function __installSimpleTest() {
|
|
||||||
if (!App::import('Vendor', 'simpletest' . DS . 'reporter')) {
|
|
||||||
$this->err(__('Sorry, Simpletest could not be found. Download it from http://simpletest.org and install it to your vendors directory.'));
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -408,6 +408,8 @@ class Dispatcher extends Object {
|
||||||
if ($ext === 'css' || $ext === 'js') {
|
if ($ext === 'css' || $ext === 'js') {
|
||||||
include($assetFile);
|
include($assetFile);
|
||||||
} else {
|
} else {
|
||||||
|
ob_clean();
|
||||||
|
flush();
|
||||||
readfile($assetFile);
|
readfile($assetFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
8
cake/libs/cache/xcache.php
vendored
8
cake/libs/cache/xcache.php
vendored
|
@ -49,8 +49,10 @@ class XcacheEngine extends CacheEngine {
|
||||||
*/
|
*/
|
||||||
public function init($settings) {
|
public function init($settings) {
|
||||||
parent::init(array_merge(array(
|
parent::init(array_merge(array(
|
||||||
'engine' => 'Xcache', 'prefix' => Inflector::slug(APP_DIR) . '_
|
'engine' => 'Xcache',
|
||||||
PHP_AUTH_USER' => 'user', 'PHP_AUTH_PW' => 'password'
|
'prefix' => Inflector::slug(APP_DIR) . '_',
|
||||||
|
'PHP_AUTH_USER' => 'user',
|
||||||
|
'PHP_AUTH_PW' => 'password'
|
||||||
), $settings)
|
), $settings)
|
||||||
);
|
);
|
||||||
return function_exists('xcache_info');
|
return function_exists('xcache_info');
|
||||||
|
@ -128,7 +130,7 @@ class XcacheEngine extends CacheEngine {
|
||||||
*
|
*
|
||||||
* @return boolean True if the cache was succesfully cleared, false otherwise
|
* @return boolean True if the cache was succesfully cleared, false otherwise
|
||||||
*/
|
*/
|
||||||
public function clear() {
|
public function clear($check) {
|
||||||
$this->__auth();
|
$this->__auth();
|
||||||
$max = xcache_count(XC_TYPE_VAR);
|
$max = xcache_count(XC_TYPE_VAR);
|
||||||
for ($i = 0; $i < $max; $i++) {
|
for ($i = 0; $i < $max; $i++) {
|
||||||
|
|
|
@ -262,8 +262,8 @@ class DbAcl extends Object implements AclInterface {
|
||||||
if (!class_exists('AclNode')) {
|
if (!class_exists('AclNode')) {
|
||||||
require LIBS . 'model' . DS . 'db_acl.php';
|
require LIBS . 'model' . DS . 'db_acl.php';
|
||||||
}
|
}
|
||||||
$this->Aro =& ClassRegistry::init(array('class' => 'Aro', 'alias' => 'Aro'));
|
$this->Aro = ClassRegistry::init(array('class' => 'Aro', 'alias' => 'Aro'));
|
||||||
$this->Aco =& ClassRegistry::init(array('class' => 'Aco', 'alias' => 'Aco'));
|
$this->Aco = ClassRegistry::init(array('class' => 'Aco', 'alias' => 'Aco'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -925,4 +925,18 @@ class AuthComponent extends Object {
|
||||||
$this->Session->delete('Auth.redirect');
|
$this->Session->delete('Auth.redirect');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets or gets whether the user is logged in
|
||||||
|
*
|
||||||
|
* @param boolean $logged sets the status of the user, true to logged in, false to logged out
|
||||||
|
* @return boolean true if the user is logged in, false otherwise
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
public function loggedIn($logged = null) {
|
||||||
|
if (!is_null($logged)) {
|
||||||
|
$this->_loggedIn = $logged;
|
||||||
|
}
|
||||||
|
return $this->_loggedIn;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -270,33 +270,33 @@ class EmailComponent extends Object{
|
||||||
* Temporary store of message header lines
|
* Temporary store of message header lines
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
* @access private
|
* @access protected
|
||||||
*/
|
*/
|
||||||
private $__header = array();
|
protected $_header = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If set, boundary to use for multipart mime messages
|
* If set, boundary to use for multipart mime messages
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* @access private
|
* @access protected
|
||||||
*/
|
*/
|
||||||
private $__boundary = null;
|
protected $_boundary = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Temporary store of message lines
|
* Temporary store of message lines
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
* @access private
|
* @access protected
|
||||||
*/
|
*/
|
||||||
private $__message = array();
|
protected $_message = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Variable that holds SMTP connection
|
* Variable that holds SMTP connection
|
||||||
*
|
*
|
||||||
* @var resource
|
* @var resource
|
||||||
* @access private
|
* @access protected
|
||||||
*/
|
*/
|
||||||
private $__smtpConnection = null;
|
protected $_smtpConnection = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize component
|
* Initialize component
|
||||||
|
@ -304,7 +304,7 @@ class EmailComponent extends Object{
|
||||||
* @param object $controller Instantiating controller
|
* @param object $controller Instantiating controller
|
||||||
*/
|
*/
|
||||||
public function initialize(&$controller, $settings = array()) {
|
public function initialize(&$controller, $settings = array()) {
|
||||||
$this->Controller =& $controller;
|
$this->Controller = $controller;
|
||||||
if (Configure::read('App.encoding') !== null) {
|
if (Configure::read('App.encoding') !== null) {
|
||||||
$this->charset = Configure::read('App.encoding');
|
$this->charset = Configure::read('App.encoding');
|
||||||
}
|
}
|
||||||
|
@ -366,24 +366,24 @@ class EmailComponent extends Object{
|
||||||
}
|
}
|
||||||
|
|
||||||
$message[] = '';
|
$message[] = '';
|
||||||
$this->__message = $message;
|
$this->_message = $message;
|
||||||
|
|
||||||
if (!empty($this->attachments)) {
|
if (!empty($this->attachments)) {
|
||||||
$this->_attachFiles();
|
$this->_attachFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_null($this->__boundary)) {
|
if (!is_null($this->_boundary)) {
|
||||||
$this->__message[] = '';
|
$this->_message[] = '';
|
||||||
$this->__message[] = '--' . $this->__boundary . '--';
|
$this->_message[] = '--' . $this->_boundary . '--';
|
||||||
$this->__message[] = '';
|
$this->_message[] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$_method = '_' . $this->delivery;
|
$_method = '_' . $this->delivery;
|
||||||
$sent = $this->$_method();
|
$sent = $this->$_method();
|
||||||
|
|
||||||
$this->__header = array();
|
$this->_header = array();
|
||||||
$this->__message = array();
|
$this->_message = array();
|
||||||
|
|
||||||
return $sent;
|
return $sent;
|
||||||
}
|
}
|
||||||
|
@ -408,9 +408,9 @@ class EmailComponent extends Object{
|
||||||
$this->htmlMessage = null;
|
$this->htmlMessage = null;
|
||||||
$this->textMessage = null;
|
$this->textMessage = null;
|
||||||
$this->messageId = true;
|
$this->messageId = true;
|
||||||
$this->__header = array();
|
$this->_header = array();
|
||||||
$this->__boundary = null;
|
$this->_boundary = null;
|
||||||
$this->__message = array();
|
$this->_message = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -438,11 +438,11 @@ class EmailComponent extends Object{
|
||||||
if ($this->sendAs === 'both') {
|
if ($this->sendAs === 'both') {
|
||||||
$htmlContent = $content;
|
$htmlContent = $content;
|
||||||
if (!empty($this->attachments)) {
|
if (!empty($this->attachments)) {
|
||||||
$msg[] = '--' . $this->__boundary;
|
$msg[] = '--' . $this->_boundary;
|
||||||
$msg[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"';
|
$msg[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->_boundary . '"';
|
||||||
$msg[] = '';
|
$msg[] = '';
|
||||||
}
|
}
|
||||||
$msg[] = '--alt-' . $this->__boundary;
|
$msg[] = '--alt-' . $this->_boundary;
|
||||||
$msg[] = 'Content-Type: text/plain; charset=' . $this->charset;
|
$msg[] = 'Content-Type: text/plain; charset=' . $this->charset;
|
||||||
$msg[] = 'Content-Transfer-Encoding: 7bit';
|
$msg[] = 'Content-Transfer-Encoding: 7bit';
|
||||||
$msg[] = '';
|
$msg[] = '';
|
||||||
|
@ -454,7 +454,7 @@ class EmailComponent extends Object{
|
||||||
$msg = array_merge($msg, $content);
|
$msg = array_merge($msg, $content);
|
||||||
|
|
||||||
$msg[] = '';
|
$msg[] = '';
|
||||||
$msg[] = '--alt-' . $this->__boundary;
|
$msg[] = '--alt-' . $this->_boundary;
|
||||||
$msg[] = 'Content-Type: text/html; charset=' . $this->charset;
|
$msg[] = 'Content-Type: text/html; charset=' . $this->charset;
|
||||||
$msg[] = 'Content-Transfer-Encoding: 7bit';
|
$msg[] = 'Content-Transfer-Encoding: 7bit';
|
||||||
$msg[] = '';
|
$msg[] = '';
|
||||||
|
@ -464,7 +464,7 @@ class EmailComponent extends Object{
|
||||||
$htmlContent = explode("\n", $this->htmlMessage = str_replace(array("\r\n", "\r"), "\n", $View->renderLayout($htmlContent)));
|
$htmlContent = explode("\n", $this->htmlMessage = str_replace(array("\r\n", "\r"), "\n", $View->renderLayout($htmlContent)));
|
||||||
$msg = array_merge($msg, $htmlContent);
|
$msg = array_merge($msg, $htmlContent);
|
||||||
$msg[] = '';
|
$msg[] = '';
|
||||||
$msg[] = '--alt-' . $this->__boundary . '--';
|
$msg[] = '--alt-' . $this->_boundary . '--';
|
||||||
$msg[] = '';
|
$msg[] = '';
|
||||||
|
|
||||||
return $msg;
|
return $msg;
|
||||||
|
@ -473,12 +473,12 @@ class EmailComponent extends Object{
|
||||||
if (!empty($this->attachments)) {
|
if (!empty($this->attachments)) {
|
||||||
if ($this->sendAs === 'html') {
|
if ($this->sendAs === 'html') {
|
||||||
$msg[] = '';
|
$msg[] = '';
|
||||||
$msg[] = '--' . $this->__boundary;
|
$msg[] = '--' . $this->_boundary;
|
||||||
$msg[] = 'Content-Type: text/html; charset=' . $this->charset;
|
$msg[] = 'Content-Type: text/html; charset=' . $this->charset;
|
||||||
$msg[] = 'Content-Transfer-Encoding: 7bit';
|
$msg[] = 'Content-Transfer-Encoding: 7bit';
|
||||||
$msg[] = '';
|
$msg[] = '';
|
||||||
} else {
|
} else {
|
||||||
$msg[] = '--' . $this->__boundary;
|
$msg[] = '--' . $this->_boundary;
|
||||||
$msg[] = 'Content-Type: text/plain; charset=' . $this->charset;
|
$msg[] = 'Content-Type: text/plain; charset=' . $this->charset;
|
||||||
$msg[] = 'Content-Transfer-Encoding: 7bit';
|
$msg[] = 'Content-Transfer-Encoding: 7bit';
|
||||||
$msg[] = '';
|
$msg[] = '';
|
||||||
|
@ -506,7 +506,7 @@ class EmailComponent extends Object{
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function _createboundary() {
|
function _createboundary() {
|
||||||
$this->__boundary = md5(uniqid(time()));
|
$this->_boundary = md5(uniqid(time()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -517,7 +517,7 @@ class EmailComponent extends Object{
|
||||||
*/
|
*/
|
||||||
function header($headers) {
|
function header($headers) {
|
||||||
foreach ($headers as $header => $value) {
|
foreach ($headers as $header => $value) {
|
||||||
$this->__header[] = sprintf('%s: %s', trim($header), trim($value));
|
$this->_header[] = sprintf('%s: %s', trim($header), trim($value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -578,7 +578,7 @@ class EmailComponent extends Object{
|
||||||
if (!empty($this->attachments)) {
|
if (!empty($this->attachments)) {
|
||||||
$this->_createBoundary();
|
$this->_createBoundary();
|
||||||
$headers['MIME-Version'] = '1.0';
|
$headers['MIME-Version'] = '1.0';
|
||||||
$headers['Content-Type'] = 'multipart/mixed; boundary="' . $this->__boundary . '"';
|
$headers['Content-Type'] = 'multipart/mixed; boundary="' . $this->_boundary . '"';
|
||||||
$headers[] = 'This part of the E-mail should never be seen. If';
|
$headers[] = 'This part of the E-mail should never be seen. If';
|
||||||
$headers[] = 'you are reading this, consider upgrading your e-mail';
|
$headers[] = 'you are reading this, consider upgrading your e-mail';
|
||||||
$headers[] = 'client to a MIME-compatible client.';
|
$headers[] = 'client to a MIME-compatible client.';
|
||||||
|
@ -587,7 +587,7 @@ class EmailComponent extends Object{
|
||||||
} elseif ($this->sendAs === 'html') {
|
} elseif ($this->sendAs === 'html') {
|
||||||
$headers['Content-Type'] = 'text/html; charset=' . $this->charset;
|
$headers['Content-Type'] = 'text/html; charset=' . $this->charset;
|
||||||
} elseif ($this->sendAs === 'both') {
|
} elseif ($this->sendAs === 'both') {
|
||||||
$headers['Content-Type'] = 'multipart/alternative; boundary="alt-' . $this->__boundary . '"';
|
$headers['Content-Type'] = 'multipart/alternative; boundary="alt-' . $this->_boundary . '"';
|
||||||
}
|
}
|
||||||
|
|
||||||
$headers['Content-Transfer-Encoding'] = '7bit';
|
$headers['Content-Transfer-Encoding'] = '7bit';
|
||||||
|
@ -603,13 +603,13 @@ class EmailComponent extends Object{
|
||||||
*/
|
*/
|
||||||
function _formatMessage($message) {
|
function _formatMessage($message) {
|
||||||
if (!empty($this->attachments)) {
|
if (!empty($this->attachments)) {
|
||||||
$prefix = array('--' . $this->__boundary);
|
$prefix = array('--' . $this->_boundary);
|
||||||
if ($this->sendAs === 'text') {
|
if ($this->sendAs === 'text') {
|
||||||
$prefix[] = 'Content-Type: text/plain; charset=' . $this->charset;
|
$prefix[] = 'Content-Type: text/plain; charset=' . $this->charset;
|
||||||
} elseif ($this->sendAs === 'html') {
|
} elseif ($this->sendAs === 'html') {
|
||||||
$prefix[] = 'Content-Type: text/html; charset=' . $this->charset;
|
$prefix[] = 'Content-Type: text/html; charset=' . $this->charset;
|
||||||
} elseif ($this->sendAs === 'both') {
|
} elseif ($this->sendAs === 'both') {
|
||||||
$prefix[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"';
|
$prefix[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->_boundary . '"';
|
||||||
}
|
}
|
||||||
$prefix[] = 'Content-Transfer-Encoding: 7bit';
|
$prefix[] = 'Content-Transfer-Encoding: 7bit';
|
||||||
$prefix[] = '';
|
$prefix[] = '';
|
||||||
|
@ -642,13 +642,13 @@ class EmailComponent extends Object{
|
||||||
$data = chunk_split(base64_encode($data)) ;
|
$data = chunk_split(base64_encode($data)) ;
|
||||||
fclose($handle);
|
fclose($handle);
|
||||||
|
|
||||||
$this->__message[] = '--' . $this->__boundary;
|
$this->_message[] = '--' . $this->_boundary;
|
||||||
$this->__message[] = 'Content-Type: application/octet-stream';
|
$this->_message[] = 'Content-Type: application/octet-stream';
|
||||||
$this->__message[] = 'Content-Transfer-Encoding: base64';
|
$this->_message[] = 'Content-Transfer-Encoding: base64';
|
||||||
$this->__message[] = 'Content-Disposition: attachment; filename="' . basename($filename) . '"';
|
$this->_message[] = 'Content-Disposition: attachment; filename="' . basename($filename) . '"';
|
||||||
$this->__message[] = '';
|
$this->_message[] = '';
|
||||||
$this->__message[] = $data;
|
$this->_message[] = $data;
|
||||||
$this->__message[] = '';
|
$this->_message[] = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -770,8 +770,8 @@ class EmailComponent extends Object{
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function _mail() {
|
function _mail() {
|
||||||
$header = implode("\n", $this->__header);
|
$header = implode("\n", $this->_header);
|
||||||
$message = implode("\n", $this->__message);
|
$message = implode("\n", $this->_message);
|
||||||
if (is_array($this->to)) {
|
if (is_array($this->to)) {
|
||||||
$to = implode(', ', array_map(array($this, '_formatAddress'), $this->to));
|
$to = implode(', ', array_map(array($this, '_formatAddress'), $this->to));
|
||||||
} else {
|
} else {
|
||||||
|
@ -799,10 +799,10 @@ class EmailComponent extends Object{
|
||||||
'timeout' => 30
|
'timeout' => 30
|
||||||
);
|
);
|
||||||
$this->smtpOptions = array_merge($defaults, $this->smtpOptions);
|
$this->smtpOptions = array_merge($defaults, $this->smtpOptions);
|
||||||
$this->__smtpConnection =& new CakeSocket($this->smtpOptions);
|
$this->_smtpConnection = new CakeSocket($this->smtpOptions);
|
||||||
|
|
||||||
if (!$this->__smtpConnection->connect()) {
|
if (!$this->_smtpConnection->connect()) {
|
||||||
$this->smtpError = $this->__smtpConnection->lastError();
|
$this->smtpError = $this->_smtpConnection->lastError();
|
||||||
return false;
|
return false;
|
||||||
} elseif (!$this->_smtpSend(null, '220')) {
|
} elseif (!$this->_smtpSend(null, '220')) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -866,14 +866,14 @@ class EmailComponent extends Object{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$header = implode("\r\n", $this->__header);
|
$header = implode("\r\n", $this->_header);
|
||||||
$message = implode("\r\n", $this->__message);
|
$message = implode("\r\n", $this->_message);
|
||||||
if (!$this->_smtpSend($header . "\r\n\r\n" . $message . "\r\n\r\n\r\n.")) {
|
if (!$this->_smtpSend($header . "\r\n\r\n" . $message . "\r\n\r\n\r\n.")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->_smtpSend('QUIT', false);
|
$this->_smtpSend('QUIT', false);
|
||||||
|
|
||||||
$this->__smtpConnection->disconnect();
|
$this->_smtpConnection->disconnect();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -887,13 +887,13 @@ class EmailComponent extends Object{
|
||||||
*/
|
*/
|
||||||
function _smtpSend($data, $checkCode = '250') {
|
function _smtpSend($data, $checkCode = '250') {
|
||||||
if (!is_null($data)) {
|
if (!is_null($data)) {
|
||||||
$this->__smtpConnection->write($data . "\r\n");
|
$this->_smtpConnection->write($data . "\r\n");
|
||||||
}
|
}
|
||||||
while ($checkCode !== false) {
|
while ($checkCode !== false) {
|
||||||
$response = '';
|
$response = '';
|
||||||
$startTime = time();
|
$startTime = time();
|
||||||
while (substr($response, -2) !== "\r\n" && ((time() - $startTime) < $this->smtpOptions['timeout'])) {
|
while (substr($response, -2) !== "\r\n" && ((time() - $startTime) < $this->smtpOptions['timeout'])) {
|
||||||
$response .= $this->__smtpConnection->read();
|
$response .= $this->_smtpConnection->read();
|
||||||
}
|
}
|
||||||
if (substr($response, -2) !== "\r\n") {
|
if (substr($response, -2) !== "\r\n") {
|
||||||
$this->smtpError = 'timeout';
|
$this->smtpError = 'timeout';
|
||||||
|
@ -921,8 +921,8 @@ class EmailComponent extends Object{
|
||||||
*/
|
*/
|
||||||
function _debug() {
|
function _debug() {
|
||||||
$nl = "\n";
|
$nl = "\n";
|
||||||
$header = implode($nl, $this->__header);
|
$header = implode($nl, $this->_header);
|
||||||
$message = implode($nl, $this->__message);
|
$message = implode($nl, $this->_message);
|
||||||
$fm = '<pre>';
|
$fm = '<pre>';
|
||||||
|
|
||||||
if (is_array($this->to)) {
|
if (is_array($this->to)) {
|
||||||
|
|
|
@ -458,6 +458,7 @@ class RequestHandlerComponent extends Object {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -54,7 +54,7 @@ class SessionComponent extends CakeSession {
|
||||||
*
|
*
|
||||||
* @param string $base The base path for the Session
|
* @param string $base The base path for the Session
|
||||||
*/
|
*/
|
||||||
function __construct($base = null) {
|
public function __construct($base = null) {
|
||||||
if (Configure::read('Session.start') === true) {
|
if (Configure::read('Session.start') === true) {
|
||||||
parent::__construct($base);
|
parent::__construct($base);
|
||||||
} else {
|
} else {
|
||||||
|
@ -70,7 +70,7 @@ class SessionComponent extends CakeSession {
|
||||||
*/
|
*/
|
||||||
public function startup(&$controller) {
|
public function startup(&$controller) {
|
||||||
if ($this->started() === false && $this->__active === true) {
|
if ($this->started() === false && $this->__active === true) {
|
||||||
$this->__start();
|
$this->_start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,6 +88,28 @@ class SessionComponent extends CakeSession {
|
||||||
$this->__active = true;
|
$this->__active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the session is active. Returns the private __active flag.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function active() {
|
||||||
|
return $this->__active;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get / Set the userAgent
|
||||||
|
*
|
||||||
|
* @param string $userAgent Set the userAgent
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function userAgent($userAgent = null) {
|
||||||
|
if ($userAgent) {
|
||||||
|
$this->_userAgent = $userAgent;
|
||||||
|
}
|
||||||
|
return $this->_userAgent;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to write a value to a session key.
|
* Used to write a value to a session key.
|
||||||
*
|
*
|
||||||
|
@ -101,7 +123,7 @@ class SessionComponent extends CakeSession {
|
||||||
*/
|
*/
|
||||||
public function write($name, $value = null) {
|
public function write($name, $value = null) {
|
||||||
if ($this->__active === true) {
|
if ($this->__active === true) {
|
||||||
$this->__start();
|
$this->_start();
|
||||||
if (is_array($name)) {
|
if (is_array($name)) {
|
||||||
foreach ($name as $key => $value) {
|
foreach ($name as $key => $value) {
|
||||||
if (parent::write($key, $value) === false) {
|
if (parent::write($key, $value) === false) {
|
||||||
|
@ -130,7 +152,7 @@ class SessionComponent extends CakeSession {
|
||||||
*/
|
*/
|
||||||
public function read($name = null) {
|
public function read($name = null) {
|
||||||
if ($this->__active === true) {
|
if ($this->__active === true) {
|
||||||
$this->__start();
|
$this->_start();
|
||||||
return parent::read($name);
|
return parent::read($name);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -147,7 +169,7 @@ class SessionComponent extends CakeSession {
|
||||||
*/
|
*/
|
||||||
public function delete($name) {
|
public function delete($name) {
|
||||||
if ($this->__active === true) {
|
if ($this->__active === true) {
|
||||||
$this->__start();
|
$this->_start();
|
||||||
return parent::delete($name);
|
return parent::delete($name);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -164,7 +186,7 @@ class SessionComponent extends CakeSession {
|
||||||
*/
|
*/
|
||||||
public function check($name) {
|
public function check($name) {
|
||||||
if ($this->__active === true) {
|
if ($this->__active === true) {
|
||||||
$this->__start();
|
$this->_start();
|
||||||
return parent::check($name);
|
return parent::check($name);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -180,7 +202,7 @@ class SessionComponent extends CakeSession {
|
||||||
*/
|
*/
|
||||||
public function error() {
|
public function error() {
|
||||||
if ($this->__active === true) {
|
if ($this->__active === true) {
|
||||||
$this->__start();
|
$this->_start();
|
||||||
return parent::error();
|
return parent::error();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -201,7 +223,7 @@ class SessionComponent extends CakeSession {
|
||||||
*/
|
*/
|
||||||
public function setFlash($message, $element = 'default', $params = array(), $key = 'flash') {
|
public function setFlash($message, $element = 'default', $params = array(), $key = 'flash') {
|
||||||
if ($this->__active === true) {
|
if ($this->__active === true) {
|
||||||
$this->__start();
|
$this->_start();
|
||||||
$this->write('Message.' . $key, compact('message', 'element', 'params'));
|
$this->write('Message.' . $key, compact('message', 'element', 'params'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -215,7 +237,7 @@ class SessionComponent extends CakeSession {
|
||||||
*/
|
*/
|
||||||
public function renew() {
|
public function renew() {
|
||||||
if ($this->__active === true) {
|
if ($this->__active === true) {
|
||||||
$this->__start();
|
$this->_start();
|
||||||
parent::renew();
|
parent::renew();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -229,7 +251,7 @@ class SessionComponent extends CakeSession {
|
||||||
*/
|
*/
|
||||||
public function valid() {
|
public function valid() {
|
||||||
if ($this->__active === true) {
|
if ($this->__active === true) {
|
||||||
$this->__start();
|
$this->_start();
|
||||||
return parent::valid();
|
return parent::valid();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -245,7 +267,7 @@ class SessionComponent extends CakeSession {
|
||||||
*/
|
*/
|
||||||
public function destroy() {
|
public function destroy() {
|
||||||
if ($this->__active === true) {
|
if ($this->__active === true) {
|
||||||
$this->__start();
|
$this->_start();
|
||||||
parent::destroy();
|
parent::destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,9 +290,9 @@ class SessionComponent extends CakeSession {
|
||||||
* or is called from
|
* or is called from
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
* @access private
|
* @access protected
|
||||||
*/
|
*/
|
||||||
function __start() {
|
protected function _start() {
|
||||||
if ($this->started() === false) {
|
if ($this->started() === false) {
|
||||||
if (!$this->id() && parent::start()) {
|
if (!$this->id() && parent::start()) {
|
||||||
parent::_checkValid();
|
parent::_checkValid();
|
||||||
|
@ -280,4 +302,14 @@ class SessionComponent extends CakeSession {
|
||||||
}
|
}
|
||||||
return $this->started();
|
return $this->started();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the session is active or not
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
public function isActive() {
|
||||||
|
return $this->__active;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ class Folder {
|
||||||
* @var array
|
* @var array
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
private $__errors = false;
|
private $__errors = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds array of complete directory paths.
|
* Holds array of complete directory paths.
|
||||||
|
@ -678,11 +678,14 @@ class Folder {
|
||||||
$to = $options;
|
$to = $options;
|
||||||
$options = (array)$options;
|
$options = (array)$options;
|
||||||
}
|
}
|
||||||
$options = array_merge(array('to' => $to, 'from' => $this->path, 'mode' => $this->mode, 'skip' => array()), $options);
|
$options = array_merge(
|
||||||
|
array('to' => $to, 'from' => $this->path, 'mode' => $this->mode, 'skip' => array()),
|
||||||
|
$options
|
||||||
|
);
|
||||||
|
|
||||||
if ($this->copy($options)) {
|
if ($this->copy($options)) {
|
||||||
if ($this->delete($options['from'])) {
|
if ($this->delete($options['from'])) {
|
||||||
return $this->cd($options['to']);
|
return (bool)$this->cd($options['to']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -176,7 +176,7 @@ class CakeSchema extends Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (class_exists($class)) {
|
if (class_exists($class)) {
|
||||||
$Schema =& new $class($options);
|
$Schema = new $class($options);
|
||||||
return $Schema;
|
return $Schema;
|
||||||
}
|
}
|
||||||
$false = false;
|
$false = false;
|
||||||
|
@ -204,7 +204,7 @@ class CakeSchema extends Object {
|
||||||
),
|
),
|
||||||
$options
|
$options
|
||||||
));
|
));
|
||||||
$db =& ConnectionManager::getDataSource($connection);
|
$db = ConnectionManager::getDataSource($connection);
|
||||||
|
|
||||||
App::import('Model', 'AppModel');
|
App::import('Model', 'AppModel');
|
||||||
if (isset($this->plugin)) {
|
if (isset($this->plugin)) {
|
||||||
|
@ -232,11 +232,7 @@ class CakeSchema extends Object {
|
||||||
if (isset($this->plugin)) {
|
if (isset($this->plugin)) {
|
||||||
$model = $this->plugin . '.' . $model;
|
$model = $this->plugin . '.' . $model;
|
||||||
}
|
}
|
||||||
if (PHP5) {
|
|
||||||
$Object = ClassRegistry::init(array('class' => $model, 'ds' => null));
|
$Object = ClassRegistry::init(array('class' => $model, 'ds' => null));
|
||||||
} else {
|
|
||||||
$Object =& ClassRegistry::init(array('class' => $model, 'ds' => null));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_object($Object) && $Object->useTable !== false) {
|
if (is_object($Object) && $Object->useTable !== false) {
|
||||||
$Object->setDataSource($connection);
|
$Object->setDataSource($connection);
|
||||||
|
@ -358,11 +354,9 @@ class CakeSchema extends Object {
|
||||||
}
|
}
|
||||||
$out .= "}\n";
|
$out .= "}\n";
|
||||||
|
|
||||||
$File =& new File($path . DS . $file, true);
|
$file = new SplFileObject($path . DS . $file, 'w+');
|
||||||
$header = '$Id';
|
$content = "<?php \n/* {$name} schema generated on: " . date('Y-m-d H:m:s') . " : ". time() . "*/\n{$out}?>";
|
||||||
$content = "<?php \n/* SVN FILE: {$header}$ */\n/* {$name} schema generated on: " . date('Y-m-d H:m:s') . " : ". time() . "*/\n{$out}?>";
|
if ($file->fwrite($content)) {
|
||||||
$content = $File->prepare($content);
|
|
||||||
if ($File->write($content)) {
|
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -423,7 +417,7 @@ class CakeSchema extends Object {
|
||||||
*/
|
*/
|
||||||
public function compare($old, $new = null) {
|
public function compare($old, $new = null) {
|
||||||
if (empty($new)) {
|
if (empty($new)) {
|
||||||
$new =& $this;
|
$new = $this;
|
||||||
}
|
}
|
||||||
if (is_array($new)) {
|
if (is_array($new)) {
|
||||||
if (isset($new['tables'])) {
|
if (isset($new['tables'])) {
|
||||||
|
@ -528,7 +522,7 @@ class CakeSchema extends Object {
|
||||||
* @return array Formatted columns
|
* @return array Formatted columns
|
||||||
*/
|
*/
|
||||||
public function __columns(&$Obj) {
|
public function __columns(&$Obj) {
|
||||||
$db =& ConnectionManager::getDataSource($Obj->useDbConfig);
|
$db = ConnectionManager::getDataSource($Obj->useDbConfig);
|
||||||
$fields = $Obj->schema(true);
|
$fields = $Obj->schema(true);
|
||||||
$columns = $props = array();
|
$columns = $props = array();
|
||||||
foreach ($fields as $name => $value) {
|
foreach ($fields as $name => $value) {
|
||||||
|
|
|
@ -701,7 +701,7 @@ class DboMssql extends DboSource {
|
||||||
* @param string $fields
|
* @param string $fields
|
||||||
* @param array $values
|
* @param array $values
|
||||||
*/
|
*/
|
||||||
protected function insertMulti($table, $fields, $values) {
|
public function insertMulti($table, $fields, $values) {
|
||||||
$primaryKey = $this->_getPrimaryKey($table);
|
$primaryKey = $this->_getPrimaryKey($table);
|
||||||
$hasPrimaryKey = $primaryKey != null && (
|
$hasPrimaryKey = $primaryKey != null && (
|
||||||
(is_array($fields) && in_array($primaryKey, $fields)
|
(is_array($fields) && in_array($primaryKey, $fields)
|
||||||
|
|
|
@ -125,7 +125,6 @@ class DboSqlite extends DboSource {
|
||||||
*/
|
*/
|
||||||
function connect() {
|
function connect() {
|
||||||
$config = $this->config;
|
$config = $this->config;
|
||||||
|
|
||||||
if (!$config['persistent']) {
|
if (!$config['persistent']) {
|
||||||
$this->connection = sqlite_open($config['database']);
|
$this->connection = sqlite_open($config['database']);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -388,10 +388,8 @@ class DboSource extends DataSource {
|
||||||
* @return array Array of resultset rows, or false if no rows matched
|
* @return array Array of resultset rows, or false if no rows matched
|
||||||
*/
|
*/
|
||||||
public function fetchAll($sql, $cache = true, $modelName = null) {
|
public function fetchAll($sql, $cache = true, $modelName = null) {
|
||||||
if ($cache && isset($this->_queryCache[$sql])) {
|
if ($cache && ($cached = $this->getQueryCache($sql)) !== false) {
|
||||||
if (preg_match('/^\s*select/i', $sql)) {
|
return $cached;
|
||||||
return $this->_queryCache[$sql];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->execute($sql)) {
|
if ($this->execute($sql)) {
|
||||||
|
@ -407,9 +405,7 @@ class DboSource extends DataSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cache) {
|
if ($cache) {
|
||||||
if (strpos(trim(strtolower($sql)), 'select') !== false) {
|
$this->_writeQueryCache($sql, $out);
|
||||||
$this->_queryCache[$sql] = $out;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (empty($out) && is_bool($this->_result)) {
|
if (empty($out) && is_bool($this->_result)) {
|
||||||
return $this->_result;
|
return $this->_result;
|
||||||
|
@ -2854,4 +2850,31 @@ class DboSource extends DataSource {
|
||||||
}
|
}
|
||||||
return 'string';
|
return 'string';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes a new key for the in memory sql query cache
|
||||||
|
*
|
||||||
|
* @param string $sql SQL query
|
||||||
|
* @param mixed $data result of $sql query
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function _writeQueryCache($sql, $data) {
|
||||||
|
if (strpos(trim(strtolower($sql)), 'select') !== false) {
|
||||||
|
$this->_queryCache[$sql] = $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the result for a sql query if it is already cached
|
||||||
|
*
|
||||||
|
* @param string $sql SQL query
|
||||||
|
* @return mixed results for query if it is cached, false otherwise
|
||||||
|
*/
|
||||||
|
public function getQueryCache($sql = null) {
|
||||||
|
if (isset($this->_queryCache[$sql]) && preg_match('/^\s*select/i', $sql)) {
|
||||||
|
return $this->_queryCache[$sql];
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1725,6 +1725,7 @@ class Model extends Object {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -60,7 +60,7 @@ class Router {
|
||||||
* @var array
|
* @var array
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
protected static $_validExtensions = null;
|
protected static $_validExtensions = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 'Constant' regular expression definitions for named route elements
|
* 'Constant' regular expression definitions for named route elements
|
||||||
|
|
|
@ -191,6 +191,7 @@ class Validation {
|
||||||
return self::luhn($check, $deep);
|
return self::luhn($check, $deep);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -578,6 +578,41 @@ class HtmlHelper extends AppHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns breadcrumbs as a (x)html list
|
||||||
|
*
|
||||||
|
* This method uses HtmlHelper::tag() to generate list and its elements. Works
|
||||||
|
* similiary to HtmlHelper::getCrumbs(), so it uses options which every
|
||||||
|
* crumb was added with.
|
||||||
|
*
|
||||||
|
* @param array $options Array of html attributes to apply to the generated list elements.
|
||||||
|
* @return string breadcrumbs html list
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function getCrumbList($options = array()) {
|
||||||
|
if (!empty($this->_crumbs)) {
|
||||||
|
$result = '';
|
||||||
|
$crumbCount = count($this->_crumbs);
|
||||||
|
foreach ($this->_crumbs as $which => $crumb) {
|
||||||
|
$options = array();
|
||||||
|
if (empty($crumb[1])) {
|
||||||
|
$elementContent = $crumb[0];
|
||||||
|
} else {
|
||||||
|
$elementContent = $this->link($crumb[0], $crumb[1], $crumb[2]);
|
||||||
|
}
|
||||||
|
if ($which == 0) {
|
||||||
|
$options['class'] = 'first';
|
||||||
|
} elseif ($which == $crumbCount - 1) {
|
||||||
|
$options['class'] = 'last';
|
||||||
|
}
|
||||||
|
$result .= $this->tag('li', $elementContent, $options);
|
||||||
|
}
|
||||||
|
return $this->tag('ul', $result, $options);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a formatted IMG element. If `$options['url']` is provided, an image link will be
|
* Creates a formatted IMG element. If `$options['url']` is provided, an image link will be
|
||||||
* generated with the link pointed at `$options['url']`. This method will set an empty
|
* generated with the link pointed at `$options['url']`. This method will set an empty
|
||||||
|
|
|
@ -91,8 +91,9 @@ class PaginatorHelper extends AppHelper {
|
||||||
$ajaxProvider = isset($config['ajax']) ? $config['ajax'] : 'Js';
|
$ajaxProvider = isset($config['ajax']) ? $config['ajax'] : 'Js';
|
||||||
$this->helpers[] = $ajaxProvider;
|
$this->helpers[] = $ajaxProvider;
|
||||||
$this->_ajaxHelperClass = $ajaxProvider;
|
$this->_ajaxHelperClass = $ajaxProvider;
|
||||||
|
if (!class_exists($ajaxProvider . 'Helper')) {
|
||||||
App::import('Helper', $ajaxProvider);
|
App::import('Helper', $ajaxProvider);
|
||||||
|
}
|
||||||
$classname = $ajaxProvider . 'Helper';
|
$classname = $ajaxProvider . 'Helper';
|
||||||
if (!method_exists($classname, 'link')) {
|
if (!method_exists($classname, 'link')) {
|
||||||
throw new Exception(sprintf(
|
throw new Exception(sprintf(
|
||||||
|
|
|
@ -152,7 +152,7 @@ class BasicsTest extends CakeTestCase {
|
||||||
|
|
||||||
$_SERVER = $_ENV = array();
|
$_SERVER = $_ENV = array();
|
||||||
|
|
||||||
$this->assertFalse(env('TEST_ME'));
|
$this->assertNull(env('TEST_ME'));
|
||||||
|
|
||||||
$_ENV['TEST_ME'] = 'a';
|
$_ENV['TEST_ME'] = 'a';
|
||||||
$this->assertEqual(env('TEST_ME'), 'a');
|
$this->assertEqual(env('TEST_ME'), 'a');
|
||||||
|
@ -237,7 +237,7 @@ class BasicsTest extends CakeTestCase {
|
||||||
|
|
||||||
Configure::write('Cache.disable', false);
|
Configure::write('Cache.disable', false);
|
||||||
$result = cache('basics_test', 'simple cache write');
|
$result = cache('basics_test', 'simple cache write');
|
||||||
$this->assertTrue($result);
|
$this->assertTrue((boolean)$result);
|
||||||
$this->assertTrue(file_exists(CACHE . 'basics_test'));
|
$this->assertTrue(file_exists(CACHE . 'basics_test'));
|
||||||
|
|
||||||
$result = cache('basics_test');
|
$result = cache('basics_test');
|
||||||
|
|
48
cake/tests/cases/console/all_shells.test.php
Normal file
48
cake/tests/cases/console/all_shells.test.php
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AllShellsTest file
|
||||||
|
*
|
||||||
|
* PHP 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||||
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases
|
||||||
|
* @since CakePHP(tm) v 2.0
|
||||||
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AllShellsTest class
|
||||||
|
*
|
||||||
|
* This test group will run all top level shell classes.
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases.console
|
||||||
|
*/
|
||||||
|
class AllShellsTest extends PHPUnit_Framework_TestSuite {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* suite method, defines tests for this suite.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function suite() {
|
||||||
|
$suite = new PHPUnit_Framework_TestSuite('All shell classes');
|
||||||
|
|
||||||
|
$path = CORE_TEST_CASES . DS . 'console' . DS . 'libs' . DS;
|
||||||
|
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'console' . DS . 'cake.test.php');
|
||||||
|
$tasks = array('acl', 'api', 'bake', 'schema', 'shell');
|
||||||
|
foreach ($tasks as $task) {
|
||||||
|
$suite->addTestFile($path . $task . '.test.php');
|
||||||
|
}
|
||||||
|
return $suite;
|
||||||
|
}
|
||||||
|
}
|
|
@ -191,7 +191,7 @@ class ShellDispatcherTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testParseParams() {
|
public function testParseParams() {
|
||||||
$Dispatcher =& new TestShellDispatcher();
|
$Dispatcher = new TestShellDispatcher();
|
||||||
|
|
||||||
$params = array(
|
$params = array(
|
||||||
'/cake/1.2.x.x/cake/console/cake.php',
|
'/cake/1.2.x.x/cake/console/cake.php',
|
||||||
|
@ -285,14 +285,14 @@ class ShellDispatcherTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'app' => 'new',
|
'app' => 'new',
|
||||||
'webroot' => 'webroot',
|
'dry' => true,
|
||||||
'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'new'),
|
'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'new'),
|
||||||
'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH),
|
'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH),
|
||||||
'dry' => 1
|
'webroot' => 'webroot'
|
||||||
);
|
);
|
||||||
$Dispatcher->params = $Dispatcher->args = array();
|
$Dispatcher->params = $Dispatcher->args = array();
|
||||||
$Dispatcher->parseParams($params);
|
$Dispatcher->parseParams($params);
|
||||||
$this->assertEqual($expected, $Dispatcher->params);
|
$this->assertEquals($expected, $Dispatcher->params);
|
||||||
|
|
||||||
$params = array(
|
$params = array(
|
||||||
'./console/cake.php',
|
'./console/cake.php',
|
||||||
|
@ -311,8 +311,8 @@ class ShellDispatcherTest extends CakeTestCase {
|
||||||
'webroot' => 'webroot',
|
'webroot' => 'webroot',
|
||||||
'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'app'),
|
'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'app'),
|
||||||
'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH),
|
'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH),
|
||||||
'dry' => 1,
|
'dry' => true,
|
||||||
'f' => 1,
|
'f' => true,
|
||||||
'name' => 'DbAcl'
|
'name' => 'DbAcl'
|
||||||
);
|
);
|
||||||
$Dispatcher->params = $Dispatcher->args = array();
|
$Dispatcher->params = $Dispatcher->args = array();
|
||||||
|
@ -338,7 +338,7 @@ class ShellDispatcherTest extends CakeTestCase {
|
||||||
'webroot' => 'webroot',
|
'webroot' => 'webroot',
|
||||||
'working' => '/cake/1.2.x.x/app',
|
'working' => '/cake/1.2.x.x/app',
|
||||||
'root' => '/cake/1.2.x.x',
|
'root' => '/cake/1.2.x.x',
|
||||||
'dry' => 1,
|
'dry' => true,
|
||||||
'name' => 'DbAcl'
|
'name' => 'DbAcl'
|
||||||
);
|
);
|
||||||
$Dispatcher->params = $Dispatcher->args = array();
|
$Dispatcher->params = $Dispatcher->args = array();
|
||||||
|
@ -449,7 +449,7 @@ class ShellDispatcherTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testBuildPaths() {
|
public function testBuildPaths() {
|
||||||
$Dispatcher =& new TestShellDispatcher();
|
$Dispatcher = new TestShellDispatcher();
|
||||||
|
|
||||||
$result = $Dispatcher->shellPaths;
|
$result = $Dispatcher->shellPaths;
|
||||||
|
|
||||||
|
@ -474,7 +474,7 @@ class ShellDispatcherTest extends CakeTestCase {
|
||||||
$this->skipIf(class_exists('SampleShell'), '%s SampleShell Class already loaded');
|
$this->skipIf(class_exists('SampleShell'), '%s SampleShell Class already loaded');
|
||||||
$this->skipIf(class_exists('ExampleShell'), '%s ExampleShell Class already loaded');
|
$this->skipIf(class_exists('ExampleShell'), '%s ExampleShell Class already loaded');
|
||||||
|
|
||||||
$Dispatcher =& new TestShellDispatcher();
|
$Dispatcher = new TestShellDispatcher();
|
||||||
|
|
||||||
$Dispatcher->shell = 'sample';
|
$Dispatcher->shell = 'sample';
|
||||||
$Dispatcher->shellName = 'Sample';
|
$Dispatcher->shellName = 'Sample';
|
||||||
|
@ -483,7 +483,7 @@ class ShellDispatcherTest extends CakeTestCase {
|
||||||
$result = $Dispatcher->getShell();
|
$result = $Dispatcher->getShell();
|
||||||
$this->assertIsA($result, 'SampleShell');
|
$this->assertIsA($result, 'SampleShell');
|
||||||
|
|
||||||
$Dispatcher =& new TestShellDispatcher();
|
$Dispatcher = new TestShellDispatcher();
|
||||||
|
|
||||||
$Dispatcher->shell = 'example';
|
$Dispatcher->shell = 'example';
|
||||||
$Dispatcher->shellName = 'Example';
|
$Dispatcher->shellName = 'Example';
|
||||||
|
@ -499,84 +499,86 @@ class ShellDispatcherTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testDispatchShellWithMain() {
|
public function testDispatchShellWithMain() {
|
||||||
Mock::generate('Shell', 'MockWithMainShell', array('main', '_secret'));
|
$Dispatcher = new TestShellDispatcher();
|
||||||
|
$methods = get_class_methods('Shell');
|
||||||
|
array_push($methods, 'main', '_secret');
|
||||||
|
$Mock = $this->getMock('Shell', $methods, array(&$Dispatcher), 'MockWithMainShell');
|
||||||
|
|
||||||
$Dispatcher =& new TestShellDispatcher();
|
$Mock->expects($this->once())->method('main')->will($this->returnValue(true));
|
||||||
|
$Mock->expects($this->once())->method('initialize');
|
||||||
$Shell = new MockWithMainShell();
|
$Mock->expects($this->once())->method('loadTasks');
|
||||||
$Shell->setReturnValue('main', true);
|
$Mock->expects($this->once())->method('startup');
|
||||||
$Shell->expectOnce('initialize');
|
$Dispatcher->TestShell = $Mock;
|
||||||
$Shell->expectOnce('loadTasks');
|
|
||||||
$Shell->expectOnce('startup');
|
|
||||||
$Shell->expectOnce('main');
|
|
||||||
$Dispatcher->TestShell =& $Shell;
|
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_with_main');
|
$Dispatcher->args = array('mock_with_main');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertEqual($Dispatcher->args, array());
|
$this->assertEqual($Dispatcher->args, array());
|
||||||
|
|
||||||
$Shell = new MockWithMainShell();
|
$Shell = new MockWithMainShell($Dispatcher);
|
||||||
$Shell->setReturnValue('main', true);
|
$this->mockObjects[] = $Shell;
|
||||||
$Shell->expectOnce('startup');
|
$Shell->expects($this->once())->method('main')->will($this->returnValue(true));
|
||||||
$Shell->expectOnce('main');
|
$Shell->expects($this->once())->method('startup');
|
||||||
$Dispatcher->TestShell =& $Shell;
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_with_main', 'initdb');
|
$Dispatcher->args = array('mock_with_main', 'initdb');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertEqual($Dispatcher->args, array('initdb'));
|
$this->assertEqual($Dispatcher->args, array('initdb'));
|
||||||
|
|
||||||
$Shell = new MockWithMainShell();
|
$Shell = new MockWithMainShell($Dispatcher);
|
||||||
$Shell->setReturnValue('main', true);
|
$this->mockObjects[] = $Shell;
|
||||||
$Shell->expectOnce('startup');
|
$Shell->expects($this->once())->method('startup');
|
||||||
$Shell->expectOnce('help');
|
$Shell->expects($this->once())->method('help');
|
||||||
$Dispatcher->TestShell =& $Shell;
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_with_main', 'help');
|
$Dispatcher->args = array('mock_with_main', 'help');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
$this->assertNull($result);
|
$this->assertNull($result);
|
||||||
$this->assertEqual($Dispatcher->args, array());
|
$this->assertEqual($Dispatcher->args, array());
|
||||||
|
|
||||||
$Shell = new MockWithMainShell();
|
$Shell = new MockWithMainShell($Dispatcher);
|
||||||
$Shell->setReturnValue('main', true);
|
$this->mockObjects[] = $Shell;
|
||||||
$Shell->expectNever('hr');
|
|
||||||
$Shell->expectOnce('startup');
|
$Shell->expects($this->once())->method('main')->will($this->returnValue(true));
|
||||||
$Shell->expectOnce('main');
|
$Shell->expects($this->never())->method('hr');
|
||||||
$Dispatcher->TestShell =& $Shell;
|
$Shell->expects($this->once())->method('startup');
|
||||||
|
$Shell->expects($this->once())->method('main');
|
||||||
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_with_main', 'hr');
|
$Dispatcher->args = array('mock_with_main', 'hr');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertEqual($Dispatcher->args, array('hr'));
|
$this->assertEqual($Dispatcher->args, array('hr'));
|
||||||
|
|
||||||
$Shell = new MockWithMainShell();
|
$Shell = new MockWithMainShell($Dispatcher);
|
||||||
$Shell->setReturnValue('main', true);
|
$this->mockObjects[] = $Shell;
|
||||||
$Shell->expectOnce('startup');
|
$Shell->expects($this->once())->method('main')->will($this->returnValue(true));
|
||||||
$Shell->expectOnce('main');
|
$Shell->expects($this->once())->method('startup');
|
||||||
$Dispatcher->TestShell =& $Shell;
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_with_main', 'dispatch');
|
$Dispatcher->args = array('mock_with_main', 'dispatch');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertEqual($Dispatcher->args, array('dispatch'));
|
$this->assertEqual($Dispatcher->args, array('dispatch'));
|
||||||
|
|
||||||
$Shell = new MockWithMainShell();
|
$Shell = new MockWithMainShell($Dispather);
|
||||||
$Shell->setReturnValue('main', true);
|
$this->mockObjects[] = $Shell;
|
||||||
$Shell->expectOnce('startup');
|
$Shell->expects($this->once())->method('main')->will($this->returnValue(true));
|
||||||
$Shell->expectOnce('main');
|
$Shell->expects($this->once())->method('startup');
|
||||||
$Dispatcher->TestShell =& $Shell;
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_with_main', 'idontexist');
|
$Dispatcher->args = array('mock_with_main', 'idontexist');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertEqual($Dispatcher->args, array('idontexist'));
|
$this->assertEqual($Dispatcher->args, array('idontexist'));
|
||||||
|
|
||||||
$Shell = new MockWithMainShell();
|
$Shell = new MockWithMainShell($Dispather);
|
||||||
$Shell->expectNever('startup');
|
$this->mockObjects[] = $Shell;
|
||||||
$Shell->expectNever('main');
|
$Shell->expects($this->never())->method('main');
|
||||||
$Shell->expectNever('_secret');
|
$Shell->expects($this->never())->method('startup');
|
||||||
$Dispatcher->TestShell =& $Shell;
|
$Shell->expects($this->never())->method('_secret');
|
||||||
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_with_main', '_secret');
|
$Dispatcher->args = array('mock_with_main', '_secret');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
|
@ -589,65 +591,69 @@ class ShellDispatcherTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testDispatchShellWithoutMain() {
|
public function testDispatchShellWithoutMain() {
|
||||||
Mock::generate('Shell', 'MockWithoutMainShell', array('initDb', '_secret'));
|
$Dispatcher = new TestShellDispatcher();
|
||||||
|
$methods = get_class_methods('Shell');
|
||||||
|
array_push($methods, 'initDb', '_secret');
|
||||||
|
$Shell = $this->getMock('Shell', $methods, array(&$Dispatcher), 'MockWithoutMainShell');
|
||||||
|
|
||||||
$Dispatcher =& new TestShellDispatcher();
|
$Shell->expects($this->once())->method('initialize');
|
||||||
|
$Shell->expects($this->once())->method('loadTasks');
|
||||||
$Shell = new MockWithoutMainShell();
|
$Shell->expects($this->never())->method('startup');
|
||||||
$Shell->setReturnValue('initDb', true);
|
$Dispatcher->TestShell = $Shell;
|
||||||
$Shell->expectOnce('initialize');
|
|
||||||
$Shell->expectOnce('loadTasks');
|
|
||||||
$Shell->expectNever('startup');
|
|
||||||
$Dispatcher->TestShell =& $Shell;
|
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_without_main');
|
$Dispatcher->args = array('mock_without_main');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
$this->assertEqual($Dispatcher->args, array());
|
$this->assertEqual($Dispatcher->args, array());
|
||||||
|
|
||||||
$Shell = new MockWithoutMainShell();
|
|
||||||
$Shell->setReturnValue('initDb', true);
|
$Shell = new MockWithoutMainShell($Dispather);
|
||||||
$Shell->expectOnce('startup');
|
$this->mockObjects[] = $Shell;
|
||||||
$Shell->expectOnce('initDb');
|
$Shell->expects($this->once())->method('initDb')->will($this->returnValue(true));
|
||||||
$Dispatcher->TestShell =& $Shell;
|
$Shell->expects($this->once())->method('initialize');
|
||||||
|
$Shell->expects($this->once())->method('loadTasks');
|
||||||
|
$Shell->expects($this->once())->method('startup');
|
||||||
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_without_main', 'initdb');
|
$Dispatcher->args = array('mock_without_main', 'initdb');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertEqual($Dispatcher->args, array());
|
$this->assertEqual($Dispatcher->args, array());
|
||||||
|
|
||||||
$Shell = new MockWithoutMainShell();
|
$Shell = new MockWithoutMainShell($Dispather);
|
||||||
$Shell->setReturnValue('initDb', true);
|
$this->mockObjects[] = $Shell;
|
||||||
$Shell->expectNever('startup');
|
$Shell->expects($this->never())->method('hr');
|
||||||
$Shell->expectNever('hr');
|
$Shell->expects($this->never())->method('startup');
|
||||||
$Dispatcher->TestShell =& $Shell;
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_without_main', 'hr');
|
$Dispatcher->args = array('mock_without_main', 'hr');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
$this->assertEqual($Dispatcher->args, array('hr'));
|
$this->assertEqual($Dispatcher->args, array('hr'));
|
||||||
|
|
||||||
$Shell = new MockWithoutMainShell();
|
$Shell = new MockWithoutMainShell($Dispather);
|
||||||
$Shell->setReturnValue('initDb', true);
|
$this->mockObjects[] = $Shell;
|
||||||
$Shell->expectNever('startup');
|
$Shell->expects($this->never())->method('startup');
|
||||||
$Dispatcher->TestShell =& $Shell;
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_without_main', 'dispatch');
|
$Dispatcher->args = array('mock_without_main', 'dispatch');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
|
|
||||||
$Shell = new MockWithoutMainShell();
|
$Shell = new MockWithoutMainShell($Dispather);
|
||||||
$Shell->expectNever('startup');
|
$this->mockObjects[] = $Shell;
|
||||||
$Dispatcher->TestShell =& $Shell;
|
$Shell->expects($this->never())->method('startup');
|
||||||
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_without_main', 'idontexist');
|
$Dispatcher->args = array('mock_without_main', 'idontexist');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
|
|
||||||
$Shell = new MockWithoutMainShell();
|
$Shell = new MockWithoutMainShell($Dispather);
|
||||||
$Shell->expectNever('startup');
|
$this->mockObjects[] = $Shell;
|
||||||
$Shell->expectNever('_secret');
|
$Shell->expects($this->never())->method('startup');
|
||||||
$Dispatcher->TestShell =& $Shell;
|
$Shell->expects($this->never())->method('_secret');
|
||||||
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_without_main', '_secret');
|
$Dispatcher->args = array('mock_without_main', '_secret');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
|
@ -660,73 +666,72 @@ class ShellDispatcherTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testDispatchNotAShellWithMain() {
|
public function testDispatchNotAShellWithMain() {
|
||||||
Mock::generate('Object', 'MockWithMainNotAShell',
|
$Dispatcher = new TestShellDispatcher();
|
||||||
array('main', 'initialize', 'loadTasks', 'startup', '_secret'));
|
$methods = get_class_methods('Object');
|
||||||
|
array_push($methods, 'main', 'initdb', 'initialize', 'loadTasks', 'startup', '_secret');
|
||||||
|
$Shell = $this->getMock('Object', $methods, array(&$Dispatcher), 'MockWithMainNotAShell');
|
||||||
|
|
||||||
$Dispatcher =& new TestShellDispatcher();
|
$Shell->expects($this->never())->method('initialize');
|
||||||
|
$Shell->expects($this->never())->method('loadTasks');
|
||||||
$Shell = new MockWithMainNotAShell();
|
$Shell->expects($this->once())->method('startup');
|
||||||
$Shell->setReturnValue('main', true);
|
$Shell->expects($this->once())->method('main')->will($this->returnValue(true));
|
||||||
$Shell->expectNever('initialize');
|
$Dispatcher->TestShell = $Shell;
|
||||||
$Shell->expectNever('loadTasks');
|
|
||||||
$Shell->expectOnce('startup');
|
|
||||||
$Shell->expectOnce('main');
|
|
||||||
$Dispatcher->TestShell =& $Shell;
|
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_with_main_not_a');
|
$Dispatcher->args = array('mock_with_main_not_a');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertEqual($Dispatcher->args, array());
|
$this->assertEqual($Dispatcher->args, array());
|
||||||
|
|
||||||
$Shell = new MockWithMainNotAShell();
|
$Shell = new MockWithMainNotAShell($Dispatcher);
|
||||||
$Shell->setReturnValue('main', true);
|
$this->mockObjects[] = $Shell;
|
||||||
$Shell->expectOnce('startup');
|
$Shell->expects($this->once())->method('initdb')->will($this->returnValue(true));
|
||||||
$Shell->expectOnce('main');
|
$Shell->expects($this->once())->method('startup');
|
||||||
$Dispatcher->TestShell =& $Shell;
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_with_main_not_a', 'initdb');
|
$Dispatcher->args = array('mock_with_main_not_a', 'initdb');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertEqual($Dispatcher->args, array('initdb'));
|
|
||||||
|
|
||||||
$Shell = new MockWithMainNotAShell();
|
$Shell = new MockWithMainNotAShell($Dispatcher);
|
||||||
$Shell->setReturnValue('main', true);
|
$this->mockObjects[] = $Shell;
|
||||||
$Shell->expectOnce('startup');
|
$Shell->expects($this->once())->method('main')->will($this->returnValue(true));
|
||||||
$Shell->expectOnce('main');
|
$Shell->expects($this->once())->method('startup');
|
||||||
$Dispatcher->TestShell =& $Shell;
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_with_main_not_a', 'hr');
|
$Dispatcher->args = array('mock_with_main_not_a', 'hr');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertEqual($Dispatcher->args, array('hr'));
|
$this->assertEqual($Dispatcher->args, array('hr'));
|
||||||
|
|
||||||
$Shell = new MockWithMainNotAShell();
|
|
||||||
$Shell->setReturnValue('main', true);
|
$Shell = new MockWithMainNotAShell($Dispatcher);
|
||||||
$Shell->expectOnce('startup');
|
$this->mockObjects[] = $Shell;
|
||||||
$Shell->expectOnce('main');
|
$Shell->expects($this->once())->method('main')->will($this->returnValue(true));
|
||||||
$Dispatcher->TestShell =& $Shell;
|
$Shell->expects($this->once())->method('startup');
|
||||||
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_with_main_not_a', 'dispatch');
|
$Dispatcher->args = array('mock_with_main_not_a', 'dispatch');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertEqual($Dispatcher->args, array('dispatch'));
|
$this->assertEqual($Dispatcher->args, array('dispatch'));
|
||||||
|
|
||||||
$Shell = new MockWithMainNotAShell();
|
$Shell = new MockWithMainNotAShell($Dispatcher);
|
||||||
$Shell->setReturnValue('main', true);
|
$this->mockObjects[] = $Shell;
|
||||||
$Shell->expectOnce('startup');
|
$Shell->expects($this->once())->method('main')->will($this->returnValue(true));
|
||||||
$Shell->expectOnce('main');
|
$Shell->expects($this->once())->method('startup');
|
||||||
$Dispatcher->TestShell =& $Shell;
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_with_main_not_a', 'idontexist');
|
$Dispatcher->args = array('mock_with_main_not_a', 'idontexist');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertEqual($Dispatcher->args, array('idontexist'));
|
$this->assertEqual($Dispatcher->args, array('idontexist'));
|
||||||
|
|
||||||
$Shell = new MockWithMainNotAShell();
|
$Shell = new MockWithMainNotAShell($Dispatcher);
|
||||||
$Shell->expectNever('startup');
|
$this->mockObjects[] = $Shell;
|
||||||
$Shell->expectNever('main');
|
$Shell->expects($this->never())->method('_secret');
|
||||||
$Shell->expectNever('_secret');
|
$Shell->expects($this->never())->method('main');
|
||||||
$Dispatcher->TestShell =& $Shell;
|
$Shell->expects($this->never())->method('startup');
|
||||||
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_with_main_not_a', '_secret');
|
$Dispatcher->args = array('mock_with_main_not_a', '_secret');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
|
@ -739,63 +744,72 @@ class ShellDispatcherTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testDispatchNotAShellWithoutMain() {
|
public function testDispatchNotAShellWithoutMain() {
|
||||||
Mock::generate('Object', 'MockWithoutMainNotAShell',
|
$Dispatcher = new TestShellDispatcher();
|
||||||
array('initDb', 'initialize', 'loadTasks', 'startup', '_secret'));
|
$methods = get_class_methods('Object');
|
||||||
|
array_push($methods, 'main', 'initdb', 'initialize', 'loadTasks', 'startup', '_secret');
|
||||||
|
$Shell = $this->getMock('Object', $methods, array(&$Dispatcher), 'MockWithoutMainNotAShell');
|
||||||
|
|
||||||
$Dispatcher =& new TestShellDispatcher();
|
$Shell->expects($this->never())->method('initialize');
|
||||||
|
$Shell->expects($this->never())->method('loadTasks');
|
||||||
$Shell = new MockWithoutMainNotAShell();
|
$Shell->expects($this->once())->method('startup');
|
||||||
$Shell->setReturnValue('initDb', true);
|
$Shell->expects($this->once())->method('main')->will($this->returnValue(true));
|
||||||
$Shell->expectNever('initialize');
|
$Dispatcher->TestShell = $Shell;
|
||||||
$Shell->expectNever('loadTasks');
|
|
||||||
$Shell->expectNever('startup');
|
|
||||||
$Dispatcher->TestShell =& $Shell;
|
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_without_main_not_a');
|
$Dispatcher->args = array('mock_without_main_not_a');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
$this->assertFalse($result);
|
|
||||||
|
|
||||||
$Shell = new MockWithoutMainNotAShell();
|
|
||||||
$Shell->setReturnValue('initDb', true);
|
|
||||||
$Shell->expectOnce('startup');
|
|
||||||
$Shell->expectOnce('initDb');
|
|
||||||
$Dispatcher->TestShell =& $Shell;
|
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_without_main_not_a', 'initdb');
|
|
||||||
$result = $Dispatcher->dispatch();
|
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertEqual($Dispatcher->args, array());
|
$this->assertEqual($Dispatcher->args, array());
|
||||||
|
|
||||||
$Shell = new MockWithoutMainNotAShell();
|
$Shell = new MockWithoutMainNotAShell($Dispatcher);
|
||||||
$Shell->setReturnValue('initDb', true);
|
$this->mockObjects[] = $Shell;
|
||||||
$Shell->expectNever('startup');
|
$Shell->expects($this->once())->method('initdb')->will($this->returnValue(true));
|
||||||
$Dispatcher->TestShell =& $Shell;
|
$Shell->expects($this->once())->method('startup');
|
||||||
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
|
$Dispatcher->args = array('mock_without_main_not_a', 'initdb');
|
||||||
|
$result = $Dispatcher->dispatch();
|
||||||
|
$this->assertTrue($result);
|
||||||
|
|
||||||
|
$Shell = new MockWithoutMainNotAShell($Dispatcher);
|
||||||
|
$this->mockObjects[] = $Shell;
|
||||||
|
$Shell->expects($this->once())->method('main')->will($this->returnValue(true));
|
||||||
|
$Shell->expects($this->once())->method('startup');
|
||||||
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_without_main_not_a', 'hr');
|
$Dispatcher->args = array('mock_without_main_not_a', 'hr');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
$this->assertFalse($result);
|
$this->assertTrue($result);
|
||||||
|
$this->assertEqual($Dispatcher->args, array('hr'));
|
||||||
|
|
||||||
$Shell = new MockWithoutMainNotAShell();
|
|
||||||
$Shell->setReturnValue('initDb', true);
|
$Shell = new MockWithoutMainNotAShell($Dispatcher);
|
||||||
$Shell->expectNever('startup');
|
$this->mockObjects[] = $Shell;
|
||||||
$Dispatcher->TestShell =& $Shell;
|
$Shell->expects($this->once())->method('main')->will($this->returnValue(true));
|
||||||
|
$Shell->expects($this->once())->method('startup');
|
||||||
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_without_main_not_a', 'dispatch');
|
$Dispatcher->args = array('mock_without_main_not_a', 'dispatch');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
$this->assertFalse($result);
|
$this->assertTrue($result);
|
||||||
|
$this->assertEqual($Dispatcher->args, array('dispatch'));
|
||||||
|
|
||||||
$Shell = new MockWithoutMainNotAShell();
|
$Shell = new MockWithoutMainNotAShell($Dispatcher);
|
||||||
$Shell->expectNever('startup');
|
$this->mockObjects[] = $Shell;
|
||||||
$Dispatcher->TestShell =& $Shell;
|
$Shell->expects($this->once())->method('main')->will($this->returnValue(true));
|
||||||
|
$Shell->expects($this->once())->method('startup');
|
||||||
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_without_main_not_a', 'idontexist');
|
$Dispatcher->args = array('mock_without_main_not_a', 'idontexist');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
$this->assertFalse($result);
|
$this->assertTrue($result);
|
||||||
|
$this->assertEqual($Dispatcher->args, array('idontexist'));
|
||||||
|
|
||||||
$Shell = new MockWithoutMainNotAShell();
|
$Shell = new MockWithoutMainNotAShell($Dispatcher);
|
||||||
$Shell->expectNever('startup');
|
$this->mockObjects[] = $Shell;
|
||||||
$Shell->expectNever('_secret');
|
$Shell->expects($this->never())->method('_secret');
|
||||||
$Dispatcher->TestShell =& $Shell;
|
$Shell->expects($this->never())->method('main');
|
||||||
|
$Shell->expects($this->never())->method('startup');
|
||||||
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_without_main_not_a', '_secret');
|
$Dispatcher->args = array('mock_without_main_not_a', '_secret');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
|
@ -809,41 +823,48 @@ class ShellDispatcherTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testDispatchTask() {
|
public function testDispatchTask() {
|
||||||
Mock::generate('Shell', 'MockWeekShell', array('main'));
|
$Dispatcher = new TestShellDispatcher();
|
||||||
Mock::generate('Shell', 'MockOnSundayTask', array('execute'));
|
$mainMethods = $executeMethods = get_class_methods('Shell');
|
||||||
|
array_push($mainMethods, 'main');
|
||||||
|
array_push($executeMethods, 'execute');
|
||||||
|
|
||||||
$Dispatcher =& new TestShellDispatcher();
|
$Week = $this->getMock('Shell', $mainMethods, array(&$Dispatcher), 'MockWeekShell');
|
||||||
|
$Sunday = $this->getMock('Shell', $executeMethods, array(&$Dispatcher), 'MockOnSundayTask');
|
||||||
|
|
||||||
$Shell = new MockWeekShell();
|
$Shell = new MockWeekShell($Dispather);
|
||||||
$Shell->expectOnce('initialize');
|
$this->mockObjects[] = $Shell;
|
||||||
$Shell->expectOnce('loadTasks');
|
$Shell->expects($this->once())->method('initialize');
|
||||||
$Shell->expectNever('startup');
|
$Shell->expects($this->once())->method('loadTasks');
|
||||||
$Shell->expectNever('main');
|
$Shell->expects($this->never())->method('startup');
|
||||||
|
$Shell->expects($this->never())->method('main');
|
||||||
|
|
||||||
$Task = new MockOnSundayTask();
|
$Task = new MockOnSundayTask($Dispatcher);
|
||||||
$Task->setReturnValue('execute', true);
|
$this->mockObjects[] = $Task;
|
||||||
$Task->expectOnce('initialize');
|
$Task->expects($this->once())->method('execute')->will($this->returnValue(true));
|
||||||
$Task->expectOnce('loadTasks');
|
$Task->expects($this->once())->method('initialize');;
|
||||||
$Task->expectOnce('startup');
|
$Task->expects($this->once())->method('loadTasks');
|
||||||
$Task->expectOnce('execute');
|
$Task->expects($this->once())->method('startup');
|
||||||
|
$Task->expects($this->once())->method('execute');
|
||||||
|
|
||||||
$Shell->MockOnSunday =& $Task;
|
$Shell->MockOnSunday = $Task;
|
||||||
$Shell->taskNames = array('MockOnSunday');
|
$Shell->taskNames = array('MockOnSunday');
|
||||||
$Dispatcher->TestShell =& $Shell;
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_week', 'mock_on_sunday');
|
$Dispatcher->args = array('mock_week', 'mock_on_sunday');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertEqual($Dispatcher->args, array());
|
$this->assertEqual($Dispatcher->args, array());
|
||||||
|
|
||||||
$Shell = new MockWeekShell();
|
$Shell = new MockWeekShell($Dispatcher);
|
||||||
$Task = new MockOnSundayTask();
|
$Task = new MockOnSundayTask($Dispatcher);
|
||||||
$Task->expectNever('execute');
|
array_push($this->mockObjects, $Shell, $Task);
|
||||||
$Task->expectOnce('help');
|
|
||||||
|
|
||||||
$Shell->MockOnSunday =& $Task;
|
$Task->expects($this->never())->method('execute');
|
||||||
|
$Task->expects($this->once())->method('help');
|
||||||
|
|
||||||
|
$Shell->MockOnSunday = $Task;
|
||||||
$Shell->taskNames = array('MockOnSunday');
|
$Shell->taskNames = array('MockOnSunday');
|
||||||
$Dispatcher->TestShell =& $Shell;
|
$Dispatcher->TestShell = $Shell;
|
||||||
|
|
||||||
$Dispatcher->args = array('mock_week', 'mock_on_sunday', 'help');
|
$Dispatcher->args = array('mock_week', 'mock_on_sunday', 'help');
|
||||||
$result = $Dispatcher->dispatch();
|
$result = $Dispatcher->dispatch();
|
||||||
|
@ -856,7 +877,7 @@ class ShellDispatcherTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testShiftArgs() {
|
public function testShiftArgs() {
|
||||||
$Dispatcher =& new TestShellDispatcher();
|
$Dispatcher = new TestShellDispatcher();
|
||||||
|
|
||||||
$Dispatcher->args = array('a', 'b', 'c');
|
$Dispatcher->args = array('a', 'b', 'c');
|
||||||
$this->assertEqual($Dispatcher->shiftArgs(), 'a');
|
$this->assertEqual($Dispatcher->shiftArgs(), 'a');
|
||||||
|
@ -885,7 +906,7 @@ class ShellDispatcherTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testHelpCommand() {
|
public function testHelpCommand() {
|
||||||
$Dispatcher =& new TestShellDispatcher();
|
$Dispatcher = new TestShellDispatcher();
|
||||||
|
|
||||||
$expected = "/example \[.*TestPlugin, TestPluginTwo.*\]/";
|
$expected = "/example \[.*TestPlugin, TestPluginTwo.*\]/";
|
||||||
$this->assertPattern($expected, $Dispatcher->stdout);
|
$this->assertPattern($expected, $Dispatcher->stdout);
|
||||||
|
|
|
@ -34,17 +34,6 @@ if (!class_exists('AclShell')) {
|
||||||
require CAKE . 'console' . DS . 'libs' . DS . 'acl.php';
|
require CAKE . 'console' . DS . 'libs' . DS . 'acl.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ShellDispatcher', 'TestAclShellMockShellDispatcher',
|
|
||||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'dispatch')
|
|
||||||
);
|
|
||||||
Mock::generatePartial(
|
|
||||||
'AclShell', 'MockAclShell',
|
|
||||||
array('in', 'out', 'hr', 'createFile', 'error', 'err')
|
|
||||||
);
|
|
||||||
|
|
||||||
Mock::generate('AclComponent', 'MockAclShellAclComponent');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AclShellTest class
|
* AclShellTest class
|
||||||
*
|
*
|
||||||
|
@ -61,42 +50,30 @@ class AclShellTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public $fixtures = array('core.aco', 'core.aro', 'core.aros_aco');
|
public $fixtures = array('core.aco', 'core.aro', 'core.aros_aco');
|
||||||
|
|
||||||
/**
|
|
||||||
* configure Configure for testcase
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function startCase() {
|
|
||||||
$this->_aclDb = Configure::read('Acl.database');
|
|
||||||
$this->_aclClass = Configure::read('Acl.classname');
|
|
||||||
|
|
||||||
Configure::write('Acl.database', 'test_suite');
|
|
||||||
Configure::write('Acl.classname', 'DbAcl');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* restore Environment settings
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function endCase() {
|
|
||||||
Configure::write('Acl.database', $this->_aclDb);
|
|
||||||
Configure::write('Acl.classname', $this->_aclClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* startTest method
|
* startTest method
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function startTest() {
|
public function startTest() {
|
||||||
$this->Dispatcher =& new TestAclShellMockShellDispatcher();
|
$this->_aclDb = Configure::read('Acl.database');
|
||||||
$this->Task =& new MockAclShell($this->Dispatcher);
|
$this->_aclClass = Configure::read('Acl.classname');
|
||||||
$this->Task->Dispatch =& $this->Dispatcher;
|
|
||||||
|
Configure::write('Acl.database', 'test_suite');
|
||||||
|
Configure::write('Acl.classname', 'DbAcl');
|
||||||
|
|
||||||
|
$this->Dispatcher = $this->getMock(
|
||||||
|
'ShellDispather',
|
||||||
|
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'dispatch')
|
||||||
|
);
|
||||||
|
$this->Task = $this->getMock(
|
||||||
|
'AclShell',
|
||||||
|
array('in', 'out', 'hr', 'createFile', 'error', 'err'),
|
||||||
|
array(&$this->Dispatcher)
|
||||||
|
);
|
||||||
|
$this->Task->Acl = new AclComponent();
|
||||||
|
|
||||||
$this->Task->params['datasource'] = 'test_suite';
|
$this->Task->params['datasource'] = 'test_suite';
|
||||||
$this->Task->Acl =& new AclComponent();
|
|
||||||
$controller = null;
|
|
||||||
$this->Task->Acl->startup($controller);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -106,6 +83,8 @@ class AclShellTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function endTest() {
|
public function endTest() {
|
||||||
ClassRegistry::flush();
|
ClassRegistry::flush();
|
||||||
|
Configure::write('Acl.database', $this->_aclDb);
|
||||||
|
Configure::write('Acl.classname', $this->_aclClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,10 +104,15 @@ class AclShellTest extends CakeTestCase {
|
||||||
$this->Task->Acl->Aro->save();
|
$this->Task->Acl->Aro->save();
|
||||||
$this->Task->args[0] = 'aro';
|
$this->Task->args[0] = 'aro';
|
||||||
|
|
||||||
$this->Task->expectAt(0, 'out', array('Aro tree:'));
|
$this->Task->expects($this->at(0))->method('out')->with('Aro tree:');
|
||||||
$this->Task->expectAt(1, 'out', array(new PatternExpectation('/\[1\] ROOT/')));
|
$this->Task->expects($this->at(2))->method('out')
|
||||||
$this->Task->expectAt(3, 'out', array(new PatternExpectation('/\[3\] Gandalf/')));
|
->with(new PHPUnit_Framework_Constraint_PCREMatch('/\[1\] ROOT/'));
|
||||||
$this->Task->expectAt(5, 'out', array(new PatternExpectation('/\[5\] MyModel.2/')));
|
|
||||||
|
$this->Task->expects($this->at(4))->method('out')
|
||||||
|
->with(new PHPUnit_Framework_Constraint_PCREMatch('/\[3\] Gandalf/'));
|
||||||
|
|
||||||
|
$this->Task->expects($this->at(6))->method('out')
|
||||||
|
->with(new PHPUnit_Framework_Constraint_PCREMatch('/\[5\] MyModel\.2/'));
|
||||||
|
|
||||||
$this->Task->view();
|
$this->Task->view();
|
||||||
}
|
}
|
||||||
|
@ -140,10 +124,12 @@ class AclShellTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testViewWithArgument() {
|
public function testViewWithArgument() {
|
||||||
$this->Task->args = array('aro', 'admins');
|
$this->Task->args = array('aro', 'admins');
|
||||||
$this->Task->expectAt(0, 'out', array('Aro tree:'));
|
|
||||||
$this->Task->expectAt(1, 'out', array(' [2] admins'));
|
$this->Task->expects($this->at(0))->method('out')->with('Aro tree:');
|
||||||
$this->Task->expectAt(2, 'out', array(' [3] Gandalf'));
|
$this->Task->expects($this->at(2))->method('out')->with(' [2] admins');
|
||||||
$this->Task->expectAt(3, 'out', array(' [4] Elrond'));
|
$this->Task->expects($this->at(3))->method('out')->with(' [3] Gandalf');
|
||||||
|
$this->Task->expects($this->at(4))->method('out')->with(' [4] Elrond');
|
||||||
|
|
||||||
$this->Task->view();
|
$this->Task->view();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,10 +156,13 @@ class AclShellTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testCreate() {
|
public function testCreate() {
|
||||||
$this->Task->args = array('aro', 'root', 'User.1');
|
$this->Task->args = array('aro', 'root', 'User.1');
|
||||||
$this->Task->expectAt(0, 'out', array(new PatternExpectation('/created/'), '*'));
|
$this->Task->expects($this->at(0))->method('out')->with("New Aro 'User.1' created.\n", true);
|
||||||
|
$this->Task->expects($this->at(1))->method('out')->with("New Aro 'User.3' created.\n", true);
|
||||||
|
$this->Task->expects($this->at(2))->method('out')->with("New Aro 'somealias' created.\n", true);
|
||||||
|
|
||||||
$this->Task->create();
|
$this->Task->create();
|
||||||
|
|
||||||
$Aro =& ClassRegistry::init('Aro');
|
$Aro = ClassRegistry::init('Aro');
|
||||||
$Aro->cacheQueries = false;
|
$Aro->cacheQueries = false;
|
||||||
$result = $Aro->read();
|
$result = $Aro->read();
|
||||||
$this->assertEqual($result['Aro']['model'], 'User');
|
$this->assertEqual($result['Aro']['model'], 'User');
|
||||||
|
@ -182,20 +171,18 @@ class AclShellTest extends CakeTestCase {
|
||||||
$id = $result['Aro']['id'];
|
$id = $result['Aro']['id'];
|
||||||
|
|
||||||
$this->Task->args = array('aro', 'User.1', 'User.3');
|
$this->Task->args = array('aro', 'User.1', 'User.3');
|
||||||
$this->Task->expectAt(1, 'out', array(new PatternExpectation('/created/'), '*'));
|
|
||||||
$this->Task->create();
|
$this->Task->create();
|
||||||
|
|
||||||
$Aro =& ClassRegistry::init('Aro');
|
$Aro = ClassRegistry::init('Aro');
|
||||||
$result = $Aro->read();
|
$result = $Aro->read();
|
||||||
$this->assertEqual($result['Aro']['model'], 'User');
|
$this->assertEqual($result['Aro']['model'], 'User');
|
||||||
$this->assertEqual($result['Aro']['foreign_key'], 3);
|
$this->assertEqual($result['Aro']['foreign_key'], 3);
|
||||||
$this->assertEqual($result['Aro']['parent_id'], $id);
|
$this->assertEqual($result['Aro']['parent_id'], $id);
|
||||||
|
|
||||||
$this->Task->args = array('aro', 'root', 'somealias');
|
$this->Task->args = array('aro', 'root', 'somealias');
|
||||||
$this->Task->expectAt(2, 'out', array(new PatternExpectation('/created/'), '*'));
|
|
||||||
$this->Task->create();
|
$this->Task->create();
|
||||||
|
|
||||||
$Aro =& ClassRegistry::init('Aro');
|
$Aro = ClassRegistry::init('Aro');
|
||||||
$result = $Aro->read();
|
$result = $Aro->read();
|
||||||
$this->assertEqual($result['Aro']['alias'], 'somealias');
|
$this->assertEqual($result['Aro']['alias'], 'somealias');
|
||||||
$this->assertEqual($result['Aro']['model'], null);
|
$this->assertEqual($result['Aro']['model'], null);
|
||||||
|
@ -210,11 +197,12 @@ class AclShellTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testDelete() {
|
public function testDelete() {
|
||||||
$this->Task->args = array('aro', 'AuthUser.1');
|
$this->Task->args = array('aro', 'AuthUser.1');
|
||||||
$this->Task->expectAt(0, 'out', array(new NoPatternExpectation('/not/'), true));
|
$this->Task->expects($this->at(0))->method('out')
|
||||||
|
->with("Aro deleted.\n", true);
|
||||||
$this->Task->delete();
|
$this->Task->delete();
|
||||||
|
|
||||||
$Aro =& ClassRegistry::init('Aro');
|
$Aro = ClassRegistry::init('Aro');
|
||||||
$result = $Aro->read(null, 3);
|
$result = $Aro->findById(3);
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,7 +215,7 @@ class AclShellTest extends CakeTestCase {
|
||||||
$this->Task->args = array('aro', 'AuthUser.2', 'root');
|
$this->Task->args = array('aro', 'AuthUser.2', 'root');
|
||||||
$this->Task->setParent();
|
$this->Task->setParent();
|
||||||
|
|
||||||
$Aro =& ClassRegistry::init('Aro');
|
$Aro = ClassRegistry::init('Aro');
|
||||||
$result = $Aro->read(null, 4);
|
$result = $Aro->read(null, 4);
|
||||||
$this->assertEqual($result['Aro']['parent_id'], null);
|
$this->assertEqual($result['Aro']['parent_id'], null);
|
||||||
}
|
}
|
||||||
|
@ -239,7 +227,8 @@ class AclShellTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testGrant() {
|
public function testGrant() {
|
||||||
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create');
|
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create');
|
||||||
$this->Task->expectAt(0, 'out', array(new PatternExpectation('/Permission granted/'), true));
|
$this->Task->expects($this->at(0))->method('out')
|
||||||
|
->with(new PHPUnit_Framework_Constraint_PCREMatch('/Permission granted/'), true);
|
||||||
$this->Task->grant();
|
$this->Task->grant();
|
||||||
|
|
||||||
$node = $this->Task->Acl->Aro->read(null, 4);
|
$node = $this->Task->Acl->Aro->read(null, 4);
|
||||||
|
@ -254,7 +243,9 @@ class AclShellTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testDeny() {
|
public function testDeny() {
|
||||||
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create');
|
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create');
|
||||||
$this->Task->expectAt(0, 'out', array(new PatternExpectation('/Permission denied/'), true));
|
$this->Task->expects($this->at(0))->method('out')
|
||||||
|
->with(new PHPUnit_Framework_Constraint_PCREMatch('/Permission denied/'), true);
|
||||||
|
|
||||||
$this->Task->deny();
|
$this->Task->deny();
|
||||||
|
|
||||||
$node = $this->Task->Acl->Aro->read(null, 4);
|
$node = $this->Task->Acl->Aro->read(null, 4);
|
||||||
|
@ -268,20 +259,25 @@ class AclShellTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testCheck() {
|
public function testCheck() {
|
||||||
|
$this->Task->expects($this->at(0))->method('out')
|
||||||
|
->with(new PHPUnit_Framework_Constraint_PCREMatch('/not allowed/'), true);
|
||||||
|
$this->Task->expects($this->at(1))->method('out')
|
||||||
|
->with(new PHPUnit_Framework_Constraint_PCREMatch('/Permission granted/'), true);
|
||||||
|
$this->Task->expects($this->at(2))->method('out')
|
||||||
|
->with(new PHPUnit_Framework_Constraint_PCREMatch('/is allowed/'), true);
|
||||||
|
$this->Task->expects($this->at(3))->method('out')
|
||||||
|
->with(new PHPUnit_Framework_Constraint_PCREMatch('/not allowed/'), true);
|
||||||
|
|
||||||
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', '*');
|
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', '*');
|
||||||
$this->Task->expectAt(0, 'out', array(new PatternExpectation('/not allowed/'), true));
|
|
||||||
$this->Task->check();
|
$this->Task->check();
|
||||||
|
|
||||||
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create');
|
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create');
|
||||||
$this->Task->expectAt(1, 'out', array(new PatternExpectation('/Permission granted/'), true));
|
|
||||||
$this->Task->grant();
|
$this->Task->grant();
|
||||||
|
|
||||||
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create');
|
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create');
|
||||||
$this->Task->expectAt(2, 'out', array(new PatternExpectation('/is allowed/'), true));
|
|
||||||
$this->Task->check();
|
$this->Task->check();
|
||||||
|
|
||||||
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', '*');
|
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', '*');
|
||||||
$this->Task->expectAt(3, 'out', array(new PatternExpectation('/not allowed/'), true));
|
|
||||||
$this->Task->check();
|
$this->Task->check();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,12 +287,15 @@ class AclShellTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testInherit() {
|
public function testInherit() {
|
||||||
|
$this->Task->expects($this->at(0))->method('out')
|
||||||
|
->with(new PHPUnit_Framework_Constraint_PCREMatch('/Permission granted/'), true);
|
||||||
|
$this->Task->expects($this->at(1))->method('out')
|
||||||
|
->with(new PHPUnit_Framework_Constraint_PCREMatch('/Permission inherited/'), true);
|
||||||
|
|
||||||
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create');
|
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create');
|
||||||
$this->Task->expectAt(0, 'out', array(new PatternExpectation('/Permission granted/'), true));
|
|
||||||
$this->Task->grant();
|
$this->Task->grant();
|
||||||
|
|
||||||
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'all');
|
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'all');
|
||||||
$this->Task->expectAt(1, 'out', array(new PatternExpectation('/permission inherited/i'), true));
|
|
||||||
$this->Task->inherit();
|
$this->Task->inherit();
|
||||||
|
|
||||||
$node = $this->Task->Acl->Aro->read(null, 4);
|
$node = $this->Task->Acl->Aro->read(null, 4);
|
||||||
|
@ -311,9 +310,9 @@ class AclShellTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testGetPath() {
|
public function testGetPath() {
|
||||||
$this->Task->args = array('aro', 'AuthUser.2');
|
$this->Task->args = array('aro', 'AuthUser.2');
|
||||||
$this->Task->expectAt(1, 'out', array('[1] ROOT'));
|
$this->Task->expects($this->at(2))->method('out')->with('[1] ROOT');
|
||||||
$this->Task->expectAt(2, 'out', array(' [2] admins'));
|
$this->Task->expects($this->at(3))->method('out')->with(' [2] admins');
|
||||||
$this->Task->expectAt(3, 'out', array(' [4] Elrond'));
|
$this->Task->expects($this->at(4))->method('out')->with(' [4] Elrond');
|
||||||
$this->Task->getPath();
|
$this->Task->getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,7 +322,7 @@ class AclShellTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testInitDb() {
|
function testInitDb() {
|
||||||
$this->Task->Dispatch->expectOnce('dispatch');
|
$this->Task->Dispatch->expects($this->once())->method('dispatch');
|
||||||
$this->Task->initdb();
|
$this->Task->initdb();
|
||||||
|
|
||||||
$this->assertEqual($this->Task->Dispatch->args, array('schema', 'create', 'DbAcl'));
|
$this->assertEqual($this->Task->Dispatch->args, array('schema', 'create', 'DbAcl'));
|
||||||
|
|
49
cake/tests/cases/console/libs/all_bake_tasks.test.php
Normal file
49
cake/tests/cases/console/libs/all_bake_tasks.test.php
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AllBakeTasksTest file
|
||||||
|
*
|
||||||
|
* PHP 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||||
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases
|
||||||
|
* @since CakePHP(tm) v 2.0
|
||||||
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AllBakeTasksTest class
|
||||||
|
*
|
||||||
|
* This test group will run bake and its task's tests.
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.groups
|
||||||
|
*/
|
||||||
|
class AllBakeTasksTest extends PHPUnit_Framework_TestSuite {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* suite method, defines tests for this suite.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function suite() {
|
||||||
|
$suite = new PHPUnit_Framework_TestSuite('Bake and its task tests');
|
||||||
|
|
||||||
|
$path = CORE_TEST_CASES . DS . 'console' . DS . 'libs' . DS . 'tasks' . DS;
|
||||||
|
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'console' . DS . 'libs' . DS . 'bake.test.php');
|
||||||
|
$tasks = array('controller', 'model', 'view', 'fixture', 'test', 'db_config', 'project', 'plugin');
|
||||||
|
foreach ($tasks as $task) {
|
||||||
|
$suite->addTestFile($path . $task . '.test.php');
|
||||||
|
}
|
||||||
|
return $suite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -34,15 +34,6 @@ if (!class_exists('ApiShell')) {
|
||||||
require CAKE . 'console' . DS . 'libs' . DS . 'api.php';
|
require CAKE . 'console' . DS . 'libs' . DS . 'api.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ShellDispatcher', 'ApiShellMockShellDispatcher',
|
|
||||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
|
||||||
);
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ApiShell', 'MockApiShell',
|
|
||||||
array('in', 'out', 'createFile', 'hr', '_stop')
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ApiShellTest class
|
* ApiShellTest class
|
||||||
*
|
*
|
||||||
|
@ -52,14 +43,20 @@ Mock::generatePartial(
|
||||||
class ApiShellTest extends CakeTestCase {
|
class ApiShellTest extends CakeTestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setUp method
|
* startTest method
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function startTest() {
|
public function startTest() {
|
||||||
$this->Dispatcher =& new ApiShellMockShellDispatcher();
|
$this->Dispatcher = $this->getMock(
|
||||||
$this->Shell =& new MockApiShell($this->Dispatcher);
|
'ShellDispatcher',
|
||||||
$this->Shell->Dispatch =& $this->Dispatcher;
|
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'dispatch')
|
||||||
|
);
|
||||||
|
$this->Shell = $this->getMock(
|
||||||
|
'ApiShell',
|
||||||
|
array('in', 'out', 'createFile', 'hr', '_stop'),
|
||||||
|
array(&$this->Dispatcher)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,10 +74,10 @@ class ApiShellTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testMethodNameDetection () {
|
public function testMethodNameDetection () {
|
||||||
$this->Shell->setReturnValueAt(0, 'in', 'q');
|
$this->Shell->expects($this->any())->method('in')->will($this->returnValue('q'));
|
||||||
$this->Shell->expectAt(0, 'out', array('Controller'));
|
$this->Shell->expects($this->at(0))->method('out')->with('Controller');
|
||||||
|
|
||||||
$expected = array(
|
$expected = array(
|
||||||
array(
|
|
||||||
'1. afterFilter()',
|
'1. afterFilter()',
|
||||||
'2. beforeFilter()',
|
'2. beforeFilter()',
|
||||||
'3. beforeRender()',
|
'3. beforeRender()',
|
||||||
|
@ -88,23 +85,22 @@ class ApiShellTest extends CakeTestCase {
|
||||||
'5. disableCache()',
|
'5. disableCache()',
|
||||||
'6. flash($message, $url, $pause = 1, $layout = \'flash\')',
|
'6. flash($message, $url, $pause = 1, $layout = \'flash\')',
|
||||||
'7. header($status)',
|
'7. header($status)',
|
||||||
'8. httpCodes($code = null)',
|
'8. httpCodes($code = NULL)',
|
||||||
'9. isAuthorized()',
|
'9. isAuthorized()',
|
||||||
'10. loadModel($modelClass = null, $id = null)',
|
'10. loadModel($modelClass = NULL, $id = NULL)',
|
||||||
'11. paginate($object = null, $scope = array(), $whitelist = array())',
|
'11. paginate($object = NULL, $scope = array (), $whitelist = array ())',
|
||||||
'12. postConditions($data = array(), $op = null, $bool = \'AND\', $exclusive = false)',
|
'12. postConditions($data = array (), $op = NULL, $bool = \'AND\', $exclusive = false)',
|
||||||
'13. redirect($url, $status = null, $exit = true)',
|
'13. redirect($url, $status = NULL, $exit = true)',
|
||||||
'14. referer($default = null, $local = false)',
|
'14. referer($default = NULL, $local = false)',
|
||||||
'15. render($action = null, $layout = null, $file = null)',
|
'15. render($action = NULL, $layout = NULL, $file = NULL)',
|
||||||
'16. set($one, $two = null)',
|
'16. set($one, $two = NULL)',
|
||||||
'17. setAction($action)',
|
'17. setAction($action)',
|
||||||
'18. shutdownProcess()',
|
'18. shutdownProcess()',
|
||||||
'19. startupProcess()',
|
'19. startupProcess()',
|
||||||
'20. validate()',
|
'20. validate()',
|
||||||
'21. validateErrors()'
|
'21. validateErrors()'
|
||||||
)
|
|
||||||
);
|
);
|
||||||
$this->Shell->expectAt(1, 'out', $expected);
|
$this->Shell->expects($this->at(2))->method('out')->with($expected);
|
||||||
|
|
||||||
$this->Shell->args = array('controller');
|
$this->Shell->args = array('controller');
|
||||||
$this->Shell->paths['controller'] = CAKE_CORE_INCLUDE_PATH . DS . LIBS . 'controller' . DS;
|
$this->Shell->paths['controller'] = CAKE_CORE_INCLUDE_PATH . DS . LIBS . 'controller' . DS;
|
||||||
|
|
|
@ -36,26 +36,13 @@ require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php';
|
||||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'controller.php';
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'controller.php';
|
||||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'db_config.php';
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'db_config.php';
|
||||||
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ShellDispatcher', 'BakeShellMockShellDispatcher',
|
|
||||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
|
||||||
);
|
|
||||||
Mock::generatePartial(
|
|
||||||
'BakeShell', 'MockBakeShell',
|
|
||||||
array('in', 'hr', 'out', 'err', 'createFile', '_stop', '_checkUnitTest')
|
|
||||||
);
|
|
||||||
|
|
||||||
Mock::generate('DbConfigTask', 'BakeShellMockDbConfigTask');
|
|
||||||
Mock::generate('ModelTask', 'BakeShellMockModelTask');
|
|
||||||
Mock::generate('ControllerTask', 'BakeShellMockControllerTask');
|
|
||||||
|
|
||||||
if (!class_exists('UsersController')) {
|
if (!class_exists('UsersController')) {
|
||||||
class UsersController extends Controller {
|
class UsersController extends Controller {
|
||||||
public $name = 'Users';
|
public $name = 'Users';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BakeShellTestCase extends CakeTestCase {
|
class BakeShellTest extends CakeTestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fixtures
|
* fixtures
|
||||||
|
@ -71,9 +58,15 @@ class BakeShellTestCase extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function startTest() {
|
public function startTest() {
|
||||||
$this->Dispatch =& new BakeShellMockShellDispatcher();
|
$this->Dispatcher = $this->getMock(
|
||||||
$this->Shell =& new MockBakeShell();
|
'ShellDispatcher',
|
||||||
$this->Shell->Dispatch =& $this->Dispatch;
|
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
||||||
|
);
|
||||||
|
$this->Shell = $this->getMock(
|
||||||
|
'BakeShell',
|
||||||
|
array('in', 'out', 'hr', 'err', 'createFile', '_stop', '_checkUnitTest'),
|
||||||
|
array(&$this->Dispatcher)
|
||||||
|
);
|
||||||
$this->Shell->Dispatch->shellPaths = App::path('shells');
|
$this->Shell->Dispatch->shellPaths = App::path('shells');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,28 +90,24 @@ class BakeShellTestCase extends CakeTestCase {
|
||||||
if ($this->skipIf($userExists, 'User class exists, cannot test `bake all [param]`. %s')) {
|
if ($this->skipIf($userExists, 'User class exists, cannot test `bake all [param]`. %s')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->Shell->Model =& new BakeShellMockModelTask();
|
$this->Shell->Model = $this->getMock('ModelTask', array(), array(&$this->Dispatch));
|
||||||
$this->Shell->Controller =& new BakeShellMockControllerTask();
|
$this->Shell->Controller = $this->getMock('ControllerTask', array(), array(&$this->Dispatch));
|
||||||
$this->Shell->View =& new BakeShellMockModelTask();
|
$this->Shell->View = $this->getMock('ModelTask', array(), array(&$this->Dispatch));
|
||||||
$this->Shell->DbConfig =& new BakeShellMockDbConfigTask();
|
$this->Shell->DbConfig = $this->getMock('DbConfigTask', array(), array(&$this->Dispatch));
|
||||||
|
|
||||||
$this->Shell->DbConfig->expectOnce('getConfig');
|
$this->Shell->DbConfig->expects($this->once())->method('getConfig')->will($this->returnValue('test_suite'));
|
||||||
$this->Shell->DbConfig->setReturnValue('getConfig', 'test_suite');
|
|
||||||
|
|
||||||
$this->Shell->Model->setReturnValue('bake', true);
|
$this->Shell->Model->expects($this->never())->method('getName');
|
||||||
$this->Shell->Model->expectNever('getName');
|
$this->Shell->Model->expects($this->once())->method('bake')->will($this->returnValue(true));
|
||||||
$this->Shell->Model->expectOnce('bake');
|
|
||||||
|
|
||||||
$this->Shell->Controller->expectOnce('bake');
|
$this->Shell->Controller->expects($this->once())->method('bake')->will($this->returnValue(true));
|
||||||
$this->Shell->Controller->setReturnValue('bake', true);
|
$this->Shell->View->expects($this->once())->method('execute');
|
||||||
|
|
||||||
$this->Shell->View->expectOnce('execute');
|
$this->Shell->expects($this->at(1))->method('out')->with('Bake All');
|
||||||
|
$this->Shell->expects($this->at(3))->method('out')->with('User Model was baked.');
|
||||||
$this->Shell->expectAt(0, 'out', array('Bake All'));
|
$this->Shell->expects($this->at(5))->method('out')->with('User Controller was baked.');
|
||||||
$this->Shell->expectAt(1, 'out', array('User Model was baked.'));
|
$this->Shell->expects($this->at(7))->method('out')->with('User Views were baked.');
|
||||||
$this->Shell->expectAt(2, 'out', array('User Controller was baked.'));
|
$this->Shell->expects($this->at(8))->method('out')->with('Bake All complete');
|
||||||
$this->Shell->expectAt(3, 'out', array('User Views were baked.'));
|
|
||||||
$this->Shell->expectAt(4, 'out', array('Bake All complete'));
|
|
||||||
|
|
||||||
$this->Shell->params = array();
|
$this->Shell->params = array();
|
||||||
$this->Shell->args = array('User');
|
$this->Shell->args = array('User');
|
||||||
|
|
|
@ -35,17 +35,6 @@ if (!class_exists('SchemaShell')) {
|
||||||
require CAKE . 'console' . DS . 'libs' . DS . 'schema.php';
|
require CAKE . 'console' . DS . 'libs' . DS . 'schema.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ShellDispatcher', 'TestSchemaShellMockShellDispatcher',
|
|
||||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
|
||||||
);
|
|
||||||
Mock::generatePartial(
|
|
||||||
'SchemaShell', 'MockSchemaShell',
|
|
||||||
array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop')
|
|
||||||
);
|
|
||||||
|
|
||||||
Mock::generate('CakeSchema', 'MockSchemaCakeSchema');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for Schema database management
|
* Test for Schema database management
|
||||||
*
|
*
|
||||||
|
@ -131,9 +120,15 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function startTest() {
|
public function startTest() {
|
||||||
$this->Dispatcher =& new TestSchemaShellMockShellDispatcher();
|
$this->Dispatcher = $this->getMock(
|
||||||
$this->Shell =& new MockSchemaShell($this->Dispatcher);
|
'ShellDispatcher',
|
||||||
$this->Shell->Dispatch =& $this->Dispatcher;
|
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
||||||
|
);
|
||||||
|
$this->Shell = $this->getMock(
|
||||||
|
'SchemaShell',
|
||||||
|
array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop'),
|
||||||
|
array(&$this->Dispatcher)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -189,8 +184,8 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
$this->Shell->startup();
|
$this->Shell->startup();
|
||||||
$this->Shell->Schema->path = APP . 'config' . DS . 'schema';
|
$this->Shell->Schema->path = APP . 'config' . DS . 'schema';
|
||||||
$this->Shell->params['file'] = 'i18n.php';
|
$this->Shell->params['file'] = 'i18n.php';
|
||||||
$this->Shell->expectOnce('_stop');
|
$this->Shell->expects($this->once())->method('_stop');
|
||||||
$this->Shell->expectOnce('out');
|
$this->Shell->expects($this->once())->method('out');
|
||||||
$this->Shell->view();
|
$this->Shell->view();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,8 +200,8 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
));
|
));
|
||||||
$this->Shell->args = array('TestPlugin.schema');
|
$this->Shell->args = array('TestPlugin.schema');
|
||||||
$this->Shell->startup();
|
$this->Shell->startup();
|
||||||
$this->Shell->expectCallCount('_stop', 2);
|
$this->Shell->expects($this->exactly(2))->method('_stop');
|
||||||
$this->Shell->expectCallCount('out', 2);
|
$this->Shell->expects($this->exactly(2))->method('out');
|
||||||
$this->Shell->view();
|
$this->Shell->view();
|
||||||
|
|
||||||
$this->Shell->args = array();
|
$this->Shell->args = array();
|
||||||
|
@ -227,7 +222,7 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
'name' => 'i18n',
|
'name' => 'i18n',
|
||||||
'write' => TMP . 'tests' . DS . 'i18n.sql'
|
'write' => TMP . 'tests' . DS . 'i18n.sql'
|
||||||
);
|
);
|
||||||
$this->Shell->expectOnce('_stop');
|
$this->Shell->expects($this->once())->method('_stop');
|
||||||
$this->Shell->startup();
|
$this->Shell->startup();
|
||||||
$this->Shell->dump();
|
$this->Shell->dump();
|
||||||
|
|
||||||
|
@ -260,7 +255,7 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
'write' => TMP . 'tests' . DS . 'dump_test.sql'
|
'write' => TMP . 'tests' . DS . 'dump_test.sql'
|
||||||
);
|
);
|
||||||
$this->Shell->startup();
|
$this->Shell->startup();
|
||||||
$this->Shell->expectOnce('_stop');
|
$this->Shell->expects($this->once())->method('_stop');
|
||||||
$this->Shell->dump();
|
$this->Shell->dump();
|
||||||
|
|
||||||
$file =& new File(TMP . 'tests' . DS . 'dump_test.sql');
|
$file =& new File(TMP . 'tests' . DS . 'dump_test.sql');
|
||||||
|
@ -279,16 +274,16 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testGenerateSnaphot() {
|
public function testGenerateSnapshot() {
|
||||||
$this->Shell->path = TMP;
|
$this->Shell->path = TMP;
|
||||||
$this->Shell->params['file'] = 'schema.php';
|
$this->Shell->params['file'] = 'schema.php';
|
||||||
$this->Shell->args = array('snapshot');
|
$this->Shell->args = array('snapshot');
|
||||||
$this->Shell->Schema =& new MockSchemaCakeSchema();
|
$this->Shell->Schema = $this->getMock('CakeSchema');
|
||||||
$this->Shell->Schema->setReturnValue('read', array('schema data'));
|
$this->Shell->Schema->expects($this->at(0))->method('read')->will($this->returnValue(array('schema data')));
|
||||||
$this->Shell->Schema->setReturnValue('write', true);
|
$this->Shell->Schema->expects($this->at(0))->method('write')->will($this->returnValue(true));
|
||||||
|
|
||||||
$this->Shell->Schema->expectOnce('read');
|
$this->Shell->Schema->expects($this->at(1))->method('read');
|
||||||
$this->Shell->Schema->expectOnce('write', array(array('schema data', 'file' => 'schema_1.php')));
|
$this->Shell->Schema->expects($this->at(1))->method('write')->with(array('schema data', 'file' => 'schema_1.php'));
|
||||||
|
|
||||||
$this->Shell->generate();
|
$this->Shell->generate();
|
||||||
}
|
}
|
||||||
|
@ -303,10 +298,10 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
$this->Shell->params['file'] = 'schema.php';
|
$this->Shell->params['file'] = 'schema.php';
|
||||||
$this->Shell->args = array();
|
$this->Shell->args = array();
|
||||||
|
|
||||||
$this->Shell->setReturnValue('in', 'q');
|
$this->Shell->expects($this->once())->method('in')->will($this->returnValue('q'));
|
||||||
$this->Shell->Schema =& new MockSchemaCakeSchema();
|
$this->Shell->Schema = $this->getMock('CakeSchema');
|
||||||
$this->Shell->Schema->path = TMP;
|
$this->Shell->Schema->path = TMP;
|
||||||
$this->Shell->Schema->expectNever('read');
|
$this->Shell->Schema->expects($this->never())->method('read');
|
||||||
|
|
||||||
$result = $this->Shell->generate();
|
$result = $this->Shell->generate();
|
||||||
unlink(TMP . 'schema.php');
|
unlink(TMP . 'schema.php');
|
||||||
|
@ -322,15 +317,19 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
$this->Shell->params['file'] = 'schema.php';
|
$this->Shell->params['file'] = 'schema.php';
|
||||||
$this->Shell->args = array();
|
$this->Shell->args = array();
|
||||||
|
|
||||||
$this->Shell->setReturnValue('in', 'o');
|
$this->Shell->expects($this->once())->method('in')->will($this->returnValue('o'));
|
||||||
$this->Shell->expectAt(1, 'out', array(new PatternExpectation('/Schema file:\s[a-z\.]+\sgenerated/')));
|
|
||||||
$this->Shell->Schema =& new MockSchemaCakeSchema();
|
|
||||||
$this->Shell->Schema->path = TMP;
|
|
||||||
$this->Shell->Schema->setReturnValue('read', array('schema data'));
|
|
||||||
$this->Shell->Schema->setReturnValue('write', true);
|
|
||||||
|
|
||||||
$this->Shell->Schema->expectOnce('read');
|
$this->Shell->expects($this->at(2))->method('out')
|
||||||
$this->Shell->Schema->expectOnce('write', array(array('schema data', 'file' => 'schema.php')));
|
->with(new PHPUnit_Framework_Constraint_PCREMatch('/Schema file:\s[a-z\.]+\sgenerated/'));
|
||||||
|
|
||||||
|
$this->Shell->Schema = $this->getMock('CakeSchema');
|
||||||
|
$this->Shell->Schema->path = TMP;
|
||||||
|
$this->Shell->Schema->expects($this->once())->method('read')->will($this->returnValue(array('schema data')));
|
||||||
|
$this->Shell->Schema->expects($this->once())->method('write')->will($this->returnValue(true));
|
||||||
|
|
||||||
|
$this->Shell->Schema->expects($this->once())->method('read');
|
||||||
|
$this->Shell->Schema->expects($this->once())->method('write')
|
||||||
|
->with(array('schema data', 'file' => 'schema.php'));
|
||||||
|
|
||||||
$this->Shell->generate();
|
$this->Shell->generate();
|
||||||
unlink(TMP . 'schema.php');
|
unlink(TMP . 'schema.php');
|
||||||
|
@ -354,7 +353,7 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
$this->Shell->Schema->path = TMP . 'tests' . DS;
|
$this->Shell->Schema->path = TMP . 'tests' . DS;
|
||||||
|
|
||||||
$this->Shell->generate();
|
$this->Shell->generate();
|
||||||
$file =& new File(TMP . 'tests' . DS . 'schema.php');
|
$file = new File(TMP . 'tests' . DS . 'schema.php');
|
||||||
$contents = $file->read();
|
$contents = $file->read();
|
||||||
|
|
||||||
$this->assertPattern('/var \$posts/', $contents);
|
$this->assertPattern('/var \$posts/', $contents);
|
||||||
|
@ -380,14 +379,14 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$this->Shell->args = array('i18n');
|
$this->Shell->args = array('i18n');
|
||||||
$this->Shell->startup();
|
$this->Shell->startup();
|
||||||
$this->Shell->setReturnValue('in', 'y');
|
$this->Shell->expects($this->any())->method('in')->will($this->returnValue('y'));
|
||||||
$this->Shell->create();
|
$this->Shell->create();
|
||||||
|
|
||||||
$db =& ConnectionManager::getDataSource('test_suite');
|
$db = ConnectionManager::getDataSource('test_suite');
|
||||||
$sources = $db->listSources();
|
$sources = $db->listSources();
|
||||||
$this->assertTrue(in_array($db->config['prefix'] . 'i18n', $sources));
|
$this->assertTrue(in_array($db->config['prefix'] . 'i18n', $sources));
|
||||||
|
|
||||||
$schema =& new i18nSchema();
|
$schema = new i18nSchema();
|
||||||
$db->execute($db->dropSchema($schema));
|
$db->execute($db->dropSchema($schema));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -404,7 +403,7 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$this->Shell->args = array('DbAcl', 'acos');
|
$this->Shell->args = array('DbAcl', 'acos');
|
||||||
$this->Shell->startup();
|
$this->Shell->startup();
|
||||||
$this->Shell->setReturnValue('in', 'y');
|
$this->Shell->expects($this->any())->method('in')->will($this->returnValue('y'));
|
||||||
$this->Shell->create();
|
$this->Shell->create();
|
||||||
|
|
||||||
$db =& ConnectionManager::getDataSource('test_suite');
|
$db =& ConnectionManager::getDataSource('test_suite');
|
||||||
|
@ -428,15 +427,13 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$this->Shell->args = array('SchemaShellTest', 'articles');
|
$this->Shell->args = array('SchemaShellTest', 'articles');
|
||||||
$this->Shell->startup();
|
$this->Shell->startup();
|
||||||
$this->Shell->setReturnValue('in', 'y');
|
$this->Shell->expects($this->any())->method('in')->will($this->returnValue('y'));
|
||||||
$this->Shell->update();
|
$this->Shell->update();
|
||||||
|
|
||||||
$article =& new Model(array('name' => 'Article', 'ds' => 'test_suite'));
|
$article =& new Model(array('name' => 'Article', 'ds' => 'test_suite'));
|
||||||
$fields = $article->schema();
|
$fields = $article->schema();
|
||||||
$this->assertTrue(isset($fields['summary']));
|
$this->assertTrue(isset($fields['summary']));
|
||||||
|
|
||||||
$this->_fixtures['core.article']->drop($this->db);
|
|
||||||
$this->_fixtures['core.article']->create($this->db);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -473,7 +470,7 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$this->Shell->args = array('TestPlugin.TestPluginApp');
|
$this->Shell->args = array('TestPlugin.TestPluginApp');
|
||||||
$this->Shell->startup();
|
$this->Shell->startup();
|
||||||
$this->Shell->setReturnValue('in', 'y');
|
$this->Shell->expects($this->any())->method('in')->will($this->returnValue('y'));
|
||||||
$this->Shell->create();
|
$this->Shell->create();
|
||||||
|
|
||||||
$db =& ConnectionManager::getDataSource('test_suite');
|
$db =& ConnectionManager::getDataSource('test_suite');
|
||||||
|
|
|
@ -34,9 +34,6 @@ if (!class_exists('ShellDispatcher')) {
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
Mock::generatePartial('ShellDispatcher', 'TestShellMockShellDispatcher', array(
|
|
||||||
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment'
|
|
||||||
));
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TestShell class
|
* TestShell class
|
||||||
|
@ -115,7 +112,12 @@ class ShellTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
$this->Dispatcher =& new TestShellMockShellDispatcher();
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->Dispatcher = $this->getMock(
|
||||||
|
'ShellDispatcher',
|
||||||
|
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
||||||
|
);
|
||||||
$this->Shell =& new TestShell($this->Dispatcher);
|
$this->Shell =& new TestShell($this->Dispatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,6 +127,7 @@ class ShellTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function tearDown() {
|
public function tearDown() {
|
||||||
|
parent::tearDown();
|
||||||
ClassRegistry::flush();
|
ClassRegistry::flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +137,7 @@ class ShellTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testConstruct() {
|
public function testConstruct() {
|
||||||
$this->assertIsA($this->Shell->Dispatch, 'TestShellMockShellDispatcher');
|
$this->assertEquals($this->Dispatcher, $this->Shell->Dispatch);
|
||||||
$this->assertEqual($this->Shell->name, 'TestShell');
|
$this->assertEqual($this->Shell->name, 'TestShell');
|
||||||
$this->assertEqual($this->Shell->alias, 'TestShell');
|
$this->assertEqual($this->Shell->alias, 'TestShell');
|
||||||
}
|
}
|
||||||
|
@ -177,28 +180,43 @@ class ShellTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testIn() {
|
public function testIn() {
|
||||||
$this->Shell->Dispatch->setReturnValueAt(0, 'getInput', 'n');
|
$this->Dispatcher->expects($this->at(0))
|
||||||
$this->Shell->Dispatch->expectAt(0, 'getInput', array('Just a test?', array('y', 'n'), 'n'));
|
->method('getInput')
|
||||||
|
->with('Just a test?', array('y', 'n'), 'n')
|
||||||
|
->will($this->returnValue('n'));
|
||||||
|
|
||||||
|
$this->Dispatcher->expects($this->at(1))
|
||||||
|
->method('getInput')
|
||||||
|
->with('Just a test?', array('y', 'n'), 'n')
|
||||||
|
->will($this->returnValue('Y'));
|
||||||
|
|
||||||
|
$this->Dispatcher->expects($this->at(2))
|
||||||
|
->method('getInput')
|
||||||
|
->with('Just a test?', 'y,n', 'n')
|
||||||
|
->will($this->returnValue('y'));
|
||||||
|
|
||||||
|
$this->Dispatcher->expects($this->at(3))
|
||||||
|
->method('getInput')
|
||||||
|
->with('Just a test?', 'y/n', 'n')
|
||||||
|
->will($this->returnValue('y'));
|
||||||
|
|
||||||
|
$this->Dispatcher->expects($this->at(4))
|
||||||
|
->method('getInput')
|
||||||
|
->with('Just a test?', 'y', 'y')
|
||||||
|
->will($this->returnValue('y'));
|
||||||
|
|
||||||
$result = $this->Shell->in('Just a test?', array('y', 'n'), 'n');
|
$result = $this->Shell->in('Just a test?', array('y', 'n'), 'n');
|
||||||
$this->assertEqual($result, 'n');
|
$this->assertEqual($result, 'n');
|
||||||
|
|
||||||
$this->Shell->Dispatch->setReturnValueAt(1, 'getInput', 'Y');
|
|
||||||
$this->Shell->Dispatch->expectAt(1, 'getInput', array('Just a test?', array('y', 'n'), 'n'));
|
|
||||||
$result = $this->Shell->in('Just a test?', array('y', 'n'), 'n');
|
$result = $this->Shell->in('Just a test?', array('y', 'n'), 'n');
|
||||||
$this->assertEqual($result, 'Y');
|
$this->assertEqual($result, 'Y');
|
||||||
|
|
||||||
$this->Shell->Dispatch->setReturnValueAt(2, 'getInput', 'y');
|
|
||||||
$this->Shell->Dispatch->expectAt(2, 'getInput', array('Just a test?', 'y,n', 'n'));
|
|
||||||
$result = $this->Shell->in('Just a test?', 'y,n', 'n');
|
$result = $this->Shell->in('Just a test?', 'y,n', 'n');
|
||||||
$this->assertEqual($result, 'y');
|
$this->assertEqual($result, 'y');
|
||||||
|
|
||||||
$this->Shell->Dispatch->setReturnValueAt(3, 'getInput', 'y');
|
|
||||||
$this->Shell->Dispatch->expectAt(3, 'getInput', array('Just a test?', 'y/n', 'n'));
|
|
||||||
$result = $this->Shell->in('Just a test?', 'y/n', 'n');
|
$result = $this->Shell->in('Just a test?', 'y/n', 'n');
|
||||||
$this->assertEqual($result, 'y');
|
$this->assertEqual($result, 'y');
|
||||||
|
|
||||||
$this->Shell->Dispatch->setReturnValueAt(4, 'getInput', 'y');
|
|
||||||
$this->Shell->Dispatch->expectAt(4, 'getInput', array('Just a test?', 'y', 'y'));
|
|
||||||
$result = $this->Shell->in('Just a test?', 'y', 'y');
|
$result = $this->Shell->in('Just a test?', 'y', 'y');
|
||||||
$this->assertEqual($result, 'y');
|
$this->assertEqual($result, 'y');
|
||||||
|
|
||||||
|
@ -214,16 +232,28 @@ class ShellTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testOut() {
|
public function testOut() {
|
||||||
$this->Shell->Dispatch->expectAt(0, 'stdout', array("Just a test\n", false));
|
$this->Shell->Dispatch->expects($this->at(0))
|
||||||
|
->method('stdout')
|
||||||
|
->with("Just a test\n", false);
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(1))
|
||||||
|
->method('stdout')
|
||||||
|
->with("Just\na\ntest\n", false);
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(2))
|
||||||
|
->method('stdout')
|
||||||
|
->with("Just\na\ntest\n\n", false);
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(3))
|
||||||
|
->method('stdout')
|
||||||
|
->with("\n", false);
|
||||||
|
|
||||||
$this->Shell->out('Just a test');
|
$this->Shell->out('Just a test');
|
||||||
|
|
||||||
$this->Shell->Dispatch->expectAt(1, 'stdout', array("Just\na\ntest\n", false));
|
|
||||||
$this->Shell->out(array('Just', 'a', 'test'));
|
$this->Shell->out(array('Just', 'a', 'test'));
|
||||||
|
|
||||||
$this->Shell->Dispatch->expectAt(2, 'stdout', array("Just\na\ntest\n\n", false));
|
|
||||||
$this->Shell->out(array('Just', 'a', 'test'), 2);
|
$this->Shell->out(array('Just', 'a', 'test'), 2);
|
||||||
|
|
||||||
$this->Shell->Dispatch->expectAt(3, 'stdout', array("\n", false));
|
|
||||||
$this->Shell->out();
|
$this->Shell->out();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,16 +263,28 @@ class ShellTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testErr() {
|
public function testErr() {
|
||||||
$this->Shell->Dispatch->expectAt(0, 'stderr', array("Just a test\n"));
|
$this->Shell->Dispatch->expects($this->at(0))
|
||||||
|
->method('stderr')
|
||||||
|
->with("Just a test\n");
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(1))
|
||||||
|
->method('stderr')
|
||||||
|
->with("Just\na\ntest\n");
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(2))
|
||||||
|
->method('stderr')
|
||||||
|
->with("Just\na\ntest\n\n");
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(3))
|
||||||
|
->method('stderr')
|
||||||
|
->with("\n");
|
||||||
|
|
||||||
$this->Shell->err('Just a test');
|
$this->Shell->err('Just a test');
|
||||||
|
|
||||||
$this->Shell->Dispatch->expectAt(1, 'stderr', array("Just\na\ntest\n"));
|
|
||||||
$this->Shell->err(array('Just', 'a', 'test'));
|
$this->Shell->err(array('Just', 'a', 'test'));
|
||||||
|
|
||||||
$this->Shell->Dispatch->expectAt(2, 'stderr', array("Just\na\ntest\n\n"));
|
|
||||||
$this->Shell->err(array('Just', 'a', 'test'), 2);
|
$this->Shell->err(array('Just', 'a', 'test'), 2);
|
||||||
|
|
||||||
$this->Shell->Dispatch->expectAt(3, 'stderr', array("\n"));
|
|
||||||
$this->Shell->err();
|
$this->Shell->err();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,19 +309,22 @@ class ShellTest extends CakeTestCase {
|
||||||
public function testHr() {
|
public function testHr() {
|
||||||
$bar = '---------------------------------------------------------------';
|
$bar = '---------------------------------------------------------------';
|
||||||
|
|
||||||
$this->Shell->Dispatch->expectAt(0, 'stdout', array('', false));
|
$this->Shell->Dispatch->expects($this->at(0))->method('stdout')->with('', false);
|
||||||
$this->Shell->Dispatch->expectAt(1, 'stdout', array($bar . "\n", false));
|
$this->Shell->Dispatch->expects($this->at(1))->method('stdout')->with($bar . "\n", false);
|
||||||
$this->Shell->Dispatch->expectAt(2, 'stdout', array('', false));
|
$this->Shell->Dispatch->expects($this->at(2))->method('stdout')->with('', false);
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(3))->method('stdout')->with("\n", false);
|
||||||
|
$this->Shell->Dispatch->expects($this->at(4))->method('stdout')->with($bar . "\n", false);
|
||||||
|
$this->Shell->Dispatch->expects($this->at(5))->method('stdout')->with("\n", false);
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(6))->method('stdout')->with("\n\n", false);
|
||||||
|
$this->Shell->Dispatch->expects($this->at(7))->method('stdout')->with($bar . "\n", false);
|
||||||
|
$this->Shell->Dispatch->expects($this->at(8))->method('stdout')->with("\n\n", false);
|
||||||
|
|
||||||
$this->Shell->hr();
|
$this->Shell->hr();
|
||||||
|
|
||||||
$this->Shell->Dispatch->expectAt(3, 'stdout', array("\n", false));
|
|
||||||
$this->Shell->Dispatch->expectAt(4, 'stdout', array($bar . "\n", false));
|
|
||||||
$this->Shell->Dispatch->expectAt(5, 'stdout', array("\n", false));
|
|
||||||
$this->Shell->hr(true);
|
$this->Shell->hr(true);
|
||||||
|
|
||||||
$this->Shell->Dispatch->expectAt(3, 'stdout', array("\n\n", false));
|
|
||||||
$this->Shell->Dispatch->expectAt(4, 'stdout', array($bar . "\n", false));
|
|
||||||
$this->Shell->Dispatch->expectAt(5, 'stdout', array("\n\n", false));
|
|
||||||
$this->Shell->hr(2);
|
$this->Shell->hr(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,14 +334,23 @@ class ShellTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testError() {
|
public function testError() {
|
||||||
$this->Shell->Dispatch->expectAt(0, 'stderr', array("Error: Foo Not Found\n"));
|
$this->Shell->Dispatch->expects($this->at(0))
|
||||||
|
->method('stderr')
|
||||||
|
->with("Error: Foo Not Found\n");
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(1))
|
||||||
|
->method('stderr')
|
||||||
|
->with("Error: Foo Not Found\n");
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(2))
|
||||||
|
->method('stderr')
|
||||||
|
->with("Searched all...\n");
|
||||||
|
|
||||||
$this->Shell->error('Foo Not Found');
|
$this->Shell->error('Foo Not Found');
|
||||||
$this->assertIdentical($this->Shell->stopped, 1);
|
$this->assertIdentical($this->Shell->stopped, 1);
|
||||||
|
|
||||||
$this->Shell->stopped = null;
|
$this->Shell->stopped = null;
|
||||||
|
|
||||||
$this->Shell->Dispatch->expectAt(1, 'stderr', array("Error: Foo Not Found\n"));
|
|
||||||
$this->Shell->Dispatch->expectAt(2, 'stderr', array("Searched all...\n"));
|
|
||||||
$this->Shell->error('Foo Not Found', 'Searched all...');
|
$this->Shell->error('Foo Not Found', 'Searched all...');
|
||||||
$this->assertIdentical($this->Shell->stopped, 1);
|
$this->assertIdentical($this->Shell->stopped, 1);
|
||||||
}
|
}
|
||||||
|
@ -389,13 +443,13 @@ class ShellTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testCreateFile() {
|
public function testCreateFileNonInteractive() {
|
||||||
$this->skipIf(DIRECTORY_SEPARATOR === '\\', '%s Not supported on Windows');
|
$this->skipIf(DIRECTORY_SEPARATOR === '\\', '%s Not supported on Windows');
|
||||||
|
|
||||||
$path = TMP . 'shell_test';
|
$path = TMP . 'shell_test';
|
||||||
$file = $path . DS . 'file1.php';
|
$file = $path . DS . 'file1.php';
|
||||||
|
|
||||||
new Folder($path, true);
|
$Folder = new Folder($path, true);
|
||||||
|
|
||||||
$this->Shell->interactive = false;
|
$this->Shell->interactive = false;
|
||||||
|
|
||||||
|
@ -411,26 +465,54 @@ class ShellTest extends CakeTestCase {
|
||||||
$this->assertTrue(file_exists($file));
|
$this->assertTrue(file_exists($file));
|
||||||
$this->assertEqual(file_get_contents($file), $contents);
|
$this->assertEqual(file_get_contents($file), $contents);
|
||||||
|
|
||||||
|
$Folder->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test createFile when the shell is interactive.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testCreateFileInteractive() {
|
||||||
|
$this->skipIf(DIRECTORY_SEPARATOR === '\\', '%s Not supported on Windows');
|
||||||
|
|
||||||
|
$path = TMP . 'shell_test';
|
||||||
|
$file = $path . DS . 'file1.php';
|
||||||
|
$Folder = new Folder($path, true);
|
||||||
|
|
||||||
$this->Shell->interactive = true;
|
$this->Shell->interactive = true;
|
||||||
|
|
||||||
$this->Shell->Dispatch->setReturnValueAt(0, 'getInput', 'n');
|
$this->Shell->Dispatch->expects($this->at(5))
|
||||||
$this->Shell->Dispatch->expectAt(1, 'stdout', array('File exists, overwrite?', '*'));
|
->method('getInput')
|
||||||
|
->withAnyParameters()
|
||||||
|
->will($this->returnValue('n'));
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(9))
|
||||||
|
->method('getInput')
|
||||||
|
->withAnyParameters()
|
||||||
|
->will($this->returnValue('y'));
|
||||||
|
|
||||||
|
|
||||||
$contents = "<?php\necho 'yet another test';\n\$te = 'st';\n?>";
|
$contents = "<?php\necho 'yet another test';\n\$te = 'st';\n?>";
|
||||||
$result = $this->Shell->createFile($file, $contents);
|
|
||||||
$this->assertFalse($result);
|
|
||||||
$this->assertTrue(file_exists($file));
|
|
||||||
$this->assertNotEqual(file_get_contents($file), $contents);
|
|
||||||
|
|
||||||
$this->Shell->Dispatch->setReturnValueAt(1, 'getInput', 'y');
|
|
||||||
$this->Shell->Dispatch->expectAt(3, 'stdout', array('File exists, overwrite?', '*'));
|
|
||||||
|
|
||||||
$result = $this->Shell->createFile($file, $contents);
|
$result = $this->Shell->createFile($file, $contents);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertTrue(file_exists($file));
|
$this->assertTrue(file_exists($file));
|
||||||
$this->assertEqual(file_get_contents($file), $contents);
|
$this->assertEqual(file_get_contents($file), $contents);
|
||||||
|
|
||||||
$Folder = new Folder($path);
|
// no overwrite
|
||||||
|
$contents = 'new contents';
|
||||||
|
$result = $this->Shell->createFile($file, $contents);
|
||||||
|
$this->assertFalse($result);
|
||||||
|
$this->assertTrue(file_exists($file));
|
||||||
|
$this->assertNotEqual($contents, file_get_contents($file));
|
||||||
|
|
||||||
|
// overwrite
|
||||||
|
$contents = 'more new contents';
|
||||||
|
$result = $this->Shell->createFile($file, $contents);
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$this->assertTrue(file_exists($file));
|
||||||
|
$this->assertEquals($contents, file_get_contents($file));
|
||||||
|
|
||||||
$Folder->delete();
|
$Folder->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,13 +521,13 @@ class ShellTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testCreateFileWindows() {
|
public function testCreateFileWindowsNonInteractive() {
|
||||||
$this->skipUnless(DIRECTORY_SEPARATOR === '\\', 'testCreateFileWindows supported on Windows only');
|
$this->skipIf(DIRECTORY_SEPARATOR === '/', 'testCreateFileWindows supported on Windows only');
|
||||||
|
|
||||||
$path = TMP . 'shell_test';
|
$path = TMP . 'shell_test';
|
||||||
$file = $path . DS . 'file1.php';
|
$file = $path . DS . 'file1.php';
|
||||||
|
|
||||||
new Folder($path, true);
|
$Folder = new Folder($path, true);
|
||||||
|
|
||||||
$this->Shell->interactive = false;
|
$this->Shell->interactive = false;
|
||||||
|
|
||||||
|
@ -461,10 +543,32 @@ class ShellTest extends CakeTestCase {
|
||||||
$this->assertTrue(file_exists($file));
|
$this->assertTrue(file_exists($file));
|
||||||
$this->assertEqual(file_get_contents($file), $contents);
|
$this->assertEqual(file_get_contents($file), $contents);
|
||||||
|
|
||||||
|
$Folder = new Folder($path);
|
||||||
|
$Folder->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test createFile on windows with interactive on.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testCreateFileWindowsInteractive() {
|
||||||
|
$this->skipIf(DIRECTORY_SEPARATOR === '/', 'testCreateFileWindowsInteractive supported on Windows only');
|
||||||
|
|
||||||
|
$path = TMP . 'shell_test';
|
||||||
|
$file = $path . DS . 'file1.php';
|
||||||
|
|
||||||
|
$Folder = new Folder($path, true);
|
||||||
|
|
||||||
$this->Shell->interactive = true;
|
$this->Shell->interactive = true;
|
||||||
|
|
||||||
$this->Shell->Dispatch->setReturnValueAt(0, 'getInput', 'n');
|
$this->Shell->Dispatch->expects($this->at(5))
|
||||||
$this->Shell->Dispatch->expectAt(1, 'stdout', array('File exists, overwrite?'));
|
->method('getInput')
|
||||||
|
->will($this->returnValue('y'));
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(9))
|
||||||
|
->method('getInput')
|
||||||
|
->will($this->returnValue('n'));
|
||||||
|
|
||||||
$contents = "<?php\necho 'yet another test';\r\n\$te = 'st';\r\n?>";
|
$contents = "<?php\necho 'yet another test';\r\n\$te = 'st';\r\n?>";
|
||||||
$result = $this->Shell->createFile($file, $contents);
|
$result = $this->Shell->createFile($file, $contents);
|
||||||
|
@ -472,15 +576,11 @@ class ShellTest extends CakeTestCase {
|
||||||
$this->assertTrue(file_exists($file));
|
$this->assertTrue(file_exists($file));
|
||||||
$this->assertNotEqual(file_get_contents($file), $contents);
|
$this->assertNotEqual(file_get_contents($file), $contents);
|
||||||
|
|
||||||
$this->Shell->Dispatch->setReturnValueAt(1, 'getInput', 'y');
|
|
||||||
$this->Shell->Dispatch->expectAt(3, 'stdout', array('File exists, overwrite?'));
|
|
||||||
|
|
||||||
$result = $this->Shell->createFile($file, $contents);
|
$result = $this->Shell->createFile($file, $contents);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertTrue(file_exists($file));
|
$this->assertTrue(file_exists($file));
|
||||||
$this->assertEqual(file_get_contents($file), $contents);
|
$this->assertEqual(file_get_contents($file), $contents);
|
||||||
|
|
||||||
$Folder = new Folder($path);
|
|
||||||
$Folder->delete();
|
$Folder->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,27 +38,6 @@ require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php';
|
||||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
||||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'test.php';
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'test.php';
|
||||||
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ShellDispatcher', 'TestControllerTaskMockShellDispatcher',
|
|
||||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
|
||||||
);
|
|
||||||
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ControllerTask', 'MockControllerTask',
|
|
||||||
array('in', 'hr', 'out', 'err', 'createFile', '_stop', '_checkUnitTest')
|
|
||||||
);
|
|
||||||
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ModelTask', 'ControllerMockModelTask',
|
|
||||||
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest')
|
|
||||||
);
|
|
||||||
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ProjectTask', 'ControllerMockProjectTask',
|
|
||||||
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest', 'getPrefix')
|
|
||||||
);
|
|
||||||
|
|
||||||
Mock::generate('TestTask', 'ControllerMockTestTask');
|
|
||||||
|
|
||||||
$imported = App::import('Model', 'Article');
|
$imported = App::import('Model', 'Article');
|
||||||
$imported = $imported || App::import('Model', 'Comment');
|
$imported = $imported || App::import('Model', 'Comment');
|
||||||
|
@ -98,16 +77,27 @@ class ControllerTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function startTest() {
|
public function startTest() {
|
||||||
$this->Dispatcher =& new TestControllerTaskMockShellDispatcher();
|
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
|
||||||
$this->Task =& new MockControllerTask($this->Dispatcher);
|
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment'
|
||||||
|
));
|
||||||
|
$this->Task = $this->getMock('ControllerTask',
|
||||||
|
array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'),
|
||||||
|
array(&$this->Dispatcher)
|
||||||
|
);
|
||||||
$this->Task->name = 'ControllerTask';
|
$this->Task->name = 'ControllerTask';
|
||||||
$this->Task->Dispatch =& $this->Dispatcher;
|
|
||||||
$this->Task->Dispatch->shellPaths = App::path('shells');
|
$this->Task->Dispatch->shellPaths = App::path('shells');
|
||||||
$this->Task->Template =& new TemplateTask($this->Task->Dispatch);
|
$this->Task->Template =& new TemplateTask($this->Task->Dispatch);
|
||||||
$this->Task->Template->params['theme'] = 'default';
|
$this->Task->Template->params['theme'] = 'default';
|
||||||
$this->Task->Model =& new ControllerMockModelTask($this->Task->Dispatch);
|
|
||||||
$this->Task->Project =& new ControllerMockProjectTask($this->Task->Dispatch);
|
$this->Task->Model = $this->getMock('ModelTask',
|
||||||
$this->Task->Test =& new ControllerMockTestTask();
|
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest'),
|
||||||
|
array(&$this->Dispatcher)
|
||||||
|
);
|
||||||
|
$this->Task->Project = $this->getMock('ProjectTask',
|
||||||
|
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest', 'getPrefix'),
|
||||||
|
array(&$this->Dispatcher)
|
||||||
|
);
|
||||||
|
$this->Task->Test = $this->getMock('TestTask', array(), array(&$this->Dispatcher));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -128,20 +118,15 @@ class ControllerTaskTest extends CakeTestCase {
|
||||||
public function testListAll() {
|
public function testListAll() {
|
||||||
$this->Task->connection = 'test_suite';
|
$this->Task->connection = 'test_suite';
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
$this->Task->expectAt(1, 'out', array('1. Articles'));
|
$this->Task->expects($this->at(1))->method('out')->with('1. Articles');
|
||||||
$this->Task->expectAt(2, 'out', array('2. ArticlesTags'));
|
$this->Task->expects($this->at(2))->method('out')->with('2. ArticlesTags');
|
||||||
$this->Task->expectAt(3, 'out', array('3. Comments'));
|
$this->Task->expects($this->at(3))->method('out')->with('3. Comments');
|
||||||
$this->Task->expectAt(4, 'out', array('4. Tags'));
|
$this->Task->expects($this->at(4))->method('out')->with('4. Tags');
|
||||||
|
|
||||||
$expected = array('Articles', 'ArticlesTags', 'Comments', 'Tags');
|
$expected = array('Articles', 'ArticlesTags', 'Comments', 'Tags');
|
||||||
$result = $this->Task->listAll('test_suite');
|
$result = $this->Task->listAll('test_suite');
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$this->Task->expectAt(6, 'out', array('1. Articles'));
|
|
||||||
$this->Task->expectAt(7, 'out', array('2. ArticlesTags'));
|
|
||||||
$this->Task->expectAt(8, 'out', array('4. Comments'));
|
|
||||||
$this->Task->expectAt(9, 'out', array('5. Tags'));
|
|
||||||
|
|
||||||
$this->Task->interactive = false;
|
$this->Task->interactive = false;
|
||||||
$result = $this->Task->listAll();
|
$result = $this->Task->listAll();
|
||||||
|
|
||||||
|
@ -154,27 +139,32 @@ class ControllerTaskTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testGetName() {
|
public function testGetNameValidIndex() {
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
$this->Task->setReturnValue('in', 1);
|
$this->Task->expects($this->at(5))->method('in')->will($this->returnValue(3));
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'q');
|
|
||||||
$this->Task->expectOnce('_stop');
|
|
||||||
$this->Task->getName('test_suite');
|
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(1, 'in', 1);
|
|
||||||
$result = $this->Task->getName('test_suite');
|
|
||||||
$expected = 'Articles';
|
|
||||||
$this->assertEqual($result, $expected);
|
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(2, 'in', 3);
|
|
||||||
$result = $this->Task->getName('test_suite');
|
$result = $this->Task->getName('test_suite');
|
||||||
$expected = 'Comments';
|
$expected = 'Comments';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(3, 'in', 10);
|
$this->Task->expects($this->at(7))->method('in')->will($this->returnValue(1));
|
||||||
$result = $this->Task->getName('test_suite');
|
$result = $this->Task->getName('test_suite');
|
||||||
$this->Task->expectOnce('err');
|
$expected = 'Articles';
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test getting invalid indexes.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testGetNameInvalidIndex() {
|
||||||
|
$this->Task->interactive = true;
|
||||||
|
$this->Task->expects($this->at(5))->method('in')->will($this->returnValue(10));
|
||||||
|
$this->Task->expects($this->at(7))->method('in')->will($this->returnValue('q'));
|
||||||
|
$this->Task->expects($this->once())->method('err');
|
||||||
|
$this->Task->expects($this->once())->method('_stop');
|
||||||
|
|
||||||
|
$this->Task->getName('test_suite');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -182,19 +172,33 @@ class ControllerTaskTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testDoHelpers() {
|
public function testDoHelpersNo() {
|
||||||
$this->Task->setReturnValue('in', 'n');
|
$this->Task->expects($this->any())->method('in')->will($this->returnValue('n'));
|
||||||
$result = $this->Task->doHelpers();
|
$result = $this->Task->doHelpers();
|
||||||
$this->assertEqual($result, array());
|
$this->assertEqual($result, array());
|
||||||
|
}
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
/**
|
||||||
$this->Task->setReturnValueAt(2, 'in', ' Javascript, Ajax, CustomOne ');
|
* test getting helper values
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testDoHelpersTrailingSpace() {
|
||||||
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
|
||||||
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Javascript, Ajax, CustomOne '));
|
||||||
$result = $this->Task->doHelpers();
|
$result = $this->Task->doHelpers();
|
||||||
$expected = array('Javascript', 'Ajax', 'CustomOne');
|
$expected = array('Javascript', 'Ajax', 'CustomOne');
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(3, 'in', 'y');
|
/**
|
||||||
$this->Task->setReturnValueAt(4, 'in', ' Javascript, Ajax, CustomOne, , ');
|
* test doHelpers with extra commas
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testDoHelpersTrailingCommas() {
|
||||||
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
|
||||||
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Javascript, Ajax, CustomOne, , '));
|
||||||
$result = $this->Task->doHelpers();
|
$result = $this->Task->doHelpers();
|
||||||
$expected = array('Javascript', 'Ajax', 'CustomOne');
|
$expected = array('Javascript', 'Ajax', 'CustomOne');
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
@ -205,19 +209,35 @@ class ControllerTaskTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testDoComponents() {
|
public function testDoComponentsNo() {
|
||||||
$this->Task->setReturnValue('in', 'n');
|
$this->Task->expects($this->any())->method('in')->will($this->returnValue('n'));
|
||||||
$result = $this->Task->doComponents();
|
$result = $this->Task->doComponents();
|
||||||
$this->assertEqual($result, array());
|
$this->assertEqual($result, array());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test components with spaces
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testDoComponentsTrailingSpaces() {
|
||||||
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
|
||||||
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' RequestHandler, Security '));
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
|
||||||
$this->Task->setReturnValueAt(2, 'in', ' RequestHandler, Security ');
|
|
||||||
$result = $this->Task->doComponents();
|
$result = $this->Task->doComponents();
|
||||||
$expected = array('RequestHandler', 'Security');
|
$expected = array('RequestHandler', 'Security');
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test components with commas
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testDoComponentsTrailingCommas() {
|
||||||
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
|
||||||
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' RequestHandler, Security, , '));
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(3, 'in', 'y');
|
|
||||||
$this->Task->setReturnValueAt(4, 'in', ' RequestHandler, Security, , ');
|
|
||||||
$result = $this->Task->doComponents();
|
$result = $this->Task->doComponents();
|
||||||
$expected = array('RequestHandler', 'Security');
|
$expected = array('RequestHandler', 'Security');
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
@ -235,9 +255,9 @@ class ControllerTaskTest extends CakeTestCase {
|
||||||
$components = array('Acl', 'Auth');
|
$components = array('Acl', 'Auth');
|
||||||
$uses = array('Comment', 'User');
|
$uses = array('Comment', 'User');
|
||||||
|
|
||||||
$this->Task->expectAt(2, 'out', array("Controller Name:\n\t$controller"));
|
$this->Task->expects($this->at(4))->method('out')->with("Controller Name:\n\t$controller");
|
||||||
$this->Task->expectAt(3, 'out', array("Helpers:\n\tAjax, Time"));
|
$this->Task->expects($this->at(5))->method('out')->with("Helpers:\n\tAjax, Time");
|
||||||
$this->Task->expectAt(4, 'out', array("Components:\n\tAcl, Auth"));
|
$this->Task->expects($this->at(6))->method('out')->with("Components:\n\tAcl, Auth");
|
||||||
$this->Task->confirmController($controller, $scaffold, $helpers, $components);
|
$this->Task->confirmController($controller, $scaffold, $helpers, $components);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,7 +269,7 @@ class ControllerTaskTest extends CakeTestCase {
|
||||||
public function testBake() {
|
public function testBake() {
|
||||||
$helpers = array('Ajax', 'Time');
|
$helpers = array('Ajax', 'Time');
|
||||||
$components = array('Acl', 'Auth');
|
$components = array('Acl', 'Auth');
|
||||||
$this->Task->setReturnValue('createFile', true);
|
$this->Task->expects($this->any())->method('createFile')->will($this->returnValue(true));
|
||||||
|
|
||||||
$result = $this->Task->bake('Articles', '--actions--', $helpers, $components);
|
$result = $this->Task->bake('Articles', '--actions--', $helpers, $components);
|
||||||
$this->assertPattern('/class ArticlesController extends AppController/', $result);
|
$this->assertPattern('/class ArticlesController extends AppController/', $result);
|
||||||
|
@ -282,13 +302,20 @@ class ControllerTaskTest extends CakeTestCase {
|
||||||
$uses = array('Comment', 'User');
|
$uses = array('Comment', 'User');
|
||||||
|
|
||||||
$path = APP . 'plugins' . DS . 'controller_test' . DS . 'controllers' . DS . 'articles_controller.php';
|
$path = APP . 'plugins' . DS . 'controller_test' . DS . 'controllers' . DS . 'articles_controller.php';
|
||||||
$this->Task->expectAt(0, 'createFile', array($path, '*'));
|
|
||||||
|
$this->Task->expects($this->at(0))->method('createFile')->with(
|
||||||
|
$path,
|
||||||
|
new PHPUnit_Framework_Constraint_IsAnything()
|
||||||
|
);
|
||||||
|
$this->Task->expects($this->at(1))->method('createFile')->with(
|
||||||
|
$path,
|
||||||
|
new PHPUnit_Framework_Constraint_PCREMatch('/ArticlesController extends ControllerTestAppController/')
|
||||||
|
);
|
||||||
|
|
||||||
$this->Task->bake('Articles', '--actions--', array(), array(), array());
|
$this->Task->bake('Articles', '--actions--', array(), array(), array());
|
||||||
|
|
||||||
$this->Task->plugin = 'controllerTest';
|
$this->Task->plugin = 'controllerTest';
|
||||||
$path = APP . 'plugins' . DS . 'controller_test' . DS . 'controllers' . DS . 'articles_controller.php';
|
$path = APP . 'plugins' . DS . 'controller_test' . DS . 'controllers' . DS . 'articles_controller.php';
|
||||||
$this->Task->expectAt(1, 'createFile', array(
|
|
||||||
$path, new PatternExpectation('/ArticlesController extends ControllerTestAppController/')));
|
|
||||||
$this->Task->bake('Articles', '--actions--', array(), array(), array());
|
$this->Task->bake('Articles', '--actions--', array(), array(), array());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,6 +385,7 @@ class ControllerTaskTest extends CakeTestCase {
|
||||||
$this->assertTrue(strpos($result, 'function add()') !== false);
|
$this->assertTrue(strpos($result, 'function add()') !== false);
|
||||||
$this->assertTrue(strpos($result, 'if (!empty($this->data))') !== false);
|
$this->assertTrue(strpos($result, 'if (!empty($this->data))') !== false);
|
||||||
$this->assertTrue(strpos($result, 'if ($this->Article->save($this->data))') !== false);
|
$this->assertTrue(strpos($result, 'if ($this->Article->save($this->data))') !== false);
|
||||||
|
|
||||||
$this->assertTrue(strpos($result, "\$this->flash(__('The article has been saved.'), array('action' => 'index'))") !== false);
|
$this->assertTrue(strpos($result, "\$this->flash(__('The article has been saved.'), array('action' => 'index'))") !== false);
|
||||||
|
|
||||||
$this->assertTrue(strpos($result, 'function edit($id = null)') !== false);
|
$this->assertTrue(strpos($result, 'function edit($id = null)') !== false);
|
||||||
|
@ -379,7 +407,7 @@ class ControllerTaskTest extends CakeTestCase {
|
||||||
$this->Task->connection = 'test_suite';
|
$this->Task->connection = 'test_suite';
|
||||||
$this->Task->interactive = false;
|
$this->Task->interactive = false;
|
||||||
|
|
||||||
$this->Task->Test->expectOnce('bake', array('Controller', 'Articles'));
|
$this->Task->Test->expects($this->once())->method('bake')->with('Controller', 'Articles');
|
||||||
$this->Task->bakeTest('Articles');
|
$this->Task->bakeTest('Articles');
|
||||||
|
|
||||||
$this->assertEqual($this->Task->plugin, $this->Task->Test->plugin);
|
$this->assertEqual($this->Task->plugin, $this->Task->Test->plugin);
|
||||||
|
@ -394,21 +422,27 @@ class ControllerTaskTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testInteractive() {
|
public function testInteractive() {
|
||||||
$this->Task->connection = 'test_suite';
|
$this->Task->connection = 'test_suite';
|
||||||
$this->Task->path = '/my/path';
|
$this->Task->path = '/my/path/';
|
||||||
$this->Task->setReturnValue('in', '1');
|
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'y'); // build interactive
|
|
||||||
$this->Task->setReturnValueAt(2, 'in', 'n'); // build no scaffolds
|
|
||||||
$this->Task->setReturnValueAt(3, 'in', 'y'); // build normal methods
|
|
||||||
$this->Task->setReturnValueAt(4, 'in', 'n'); // build admin methods
|
|
||||||
$this->Task->setReturnValueAt(5, 'in', 'n'); // helpers?
|
|
||||||
$this->Task->setReturnValueAt(6, 'in', 'n'); // components?
|
|
||||||
$this->Task->setReturnValueAt(7, 'in', 'y'); // use sessions
|
|
||||||
$this->Task->setReturnValueAt(8, 'in', 'y'); // looks good
|
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->expects($this->any())->method('in')
|
||||||
|
->will($this->onConsecutiveCalls(
|
||||||
|
'1',
|
||||||
|
'y', // build interactive
|
||||||
|
'n', // build no scaffolds
|
||||||
|
'y', // build normal methods
|
||||||
|
'n', // build admin methods
|
||||||
|
'n', // helpers?
|
||||||
|
'n', // components?
|
||||||
|
'y', // sessions ?
|
||||||
|
'y' // looks good?
|
||||||
|
));
|
||||||
|
|
||||||
$filename = '/my/path/articles_controller.php';
|
$filename = '/my/path/articles_controller.php';
|
||||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticlesController/')));
|
$this->Task->expects($this->once())->method('createFile')->with(
|
||||||
|
$filename,
|
||||||
|
new PHPUnit_Framework_Constraint_PCREMatch('/class ArticlesController/')
|
||||||
|
);
|
||||||
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -417,27 +451,36 @@ class ControllerTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function testInteractiveAdminMethodsNotInteractive() {
|
function testInteractiveAdminMethodsNotInteractive() {
|
||||||
$this->Task->connection = 'test_suite';
|
$this->Task->connection = 'test_suite';
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
$this->Task->path = '/my/path';
|
$this->Task->path = '/my/path/';
|
||||||
$this->Task->setReturnValue('in', '1');
|
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'y'); // build interactive
|
$this->Task->expects($this->any())->method('in')
|
||||||
$this->Task->setReturnValueAt(2, 'in', 'n'); // build no scaffolds
|
->will($this->onConsecutiveCalls(
|
||||||
$this->Task->setReturnValueAt(3, 'in', 'y'); // build normal methods
|
'1',
|
||||||
$this->Task->setReturnValueAt(4, 'in', 'y'); // build admin methods
|
'y', // build interactive
|
||||||
$this->Task->setReturnValueAt(5, 'in', 'n'); // helpers?
|
'n', // build no scaffolds
|
||||||
$this->Task->setReturnValueAt(6, 'in', 'n'); // components?
|
'y', // build normal methods
|
||||||
$this->Task->setReturnValueAt(7, 'in', 'y'); // use sessions
|
'y', // build admin methods
|
||||||
$this->Task->setReturnValueAt(8, 'in', 'y'); // looks good
|
'n', // helpers?
|
||||||
$this->Task->setReturnValue('createFile', true);
|
'n', // components?
|
||||||
$this->Task->Project->setReturnValue('getPrefix', 'admin_');
|
'y', // sessions ?
|
||||||
|
'y' // looks good?
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->Task->Project->expects($this->any())
|
||||||
|
->method('getPrefix')
|
||||||
|
->will($this->returnValue('admin_'));
|
||||||
|
|
||||||
|
$filename = '/my/path/articles_controller.php';
|
||||||
|
$this->Task->expects($this->once())->method('createFile')->with(
|
||||||
|
$filename,
|
||||||
|
new PHPUnit_Framework_Constraint_PCREMatch('/class ArticlesController/')
|
||||||
|
)->will($this->returnValue(true));
|
||||||
|
|
||||||
$result = $this->Task->execute();
|
$result = $this->Task->execute();
|
||||||
$this->assertPattern('/admin_index/', $result);
|
$this->assertPattern('/admin_index/', $result);
|
||||||
|
|
||||||
$filename = '/my/path/articles_controller.php';
|
|
||||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticlesController/')));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -455,12 +498,14 @@ class ControllerTaskTest extends CakeTestCase {
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
$this->Task->args = array('all');
|
$this->Task->args = array('all');
|
||||||
|
|
||||||
$this->Task->setReturnValue('createFile', true);
|
$this->Task->expects($this->any())->method('_checkUnitTest')->will($this->returnValue(true));
|
||||||
$this->Task->setReturnValue('_checkUnitTest', true);
|
$this->Task->Test->expects($this->once())->method('bake');
|
||||||
$this->Task->Test->expectCallCount('bake', 1);
|
|
||||||
|
|
||||||
$filename = '/my/path/articles_controller.php';
|
$filename = '/my/path/articles_controller.php';
|
||||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticlesController/')));
|
$this->Task->expects($this->once())->method('createFile')->with(
|
||||||
|
$filename,
|
||||||
|
new PHPUnit_Framework_Constraint_PCREMatch('/class ArticlesController/')
|
||||||
|
)->will($this->returnValue(true));
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
@ -481,19 +526,32 @@ class ControllerTaskTest extends CakeTestCase {
|
||||||
$this->Task->args = array('Articles');
|
$this->Task->args = array('Articles');
|
||||||
|
|
||||||
$filename = '/my/path/articles_controller.php';
|
$filename = '/my/path/articles_controller.php';
|
||||||
$this->Task->expectAt(0, 'createFile', array(
|
$this->Task->expects($this->once())->method('createFile')->with(
|
||||||
$filename, new PatternExpectation('/\$scaffold/')
|
$filename,
|
||||||
));
|
new PHPUnit_Framework_Constraint_PCREMatch('/\$scaffold/')
|
||||||
|
);
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test that both plural and singular forms work for controller baking.
|
* data provider for testExecuteWithControllerNameVariations
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testExecuteWithControllerNameVariations() {
|
static function nameVariations() {
|
||||||
|
return array(
|
||||||
|
array('Articles'), array('Article'), array('article'), array('articles')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that both plural and singular forms work for controller baking.
|
||||||
|
*
|
||||||
|
* @dataProvider nameVariations
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testExecuteWithControllerNameVariations($name) {
|
||||||
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
|
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
|
||||||
'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s');
|
'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s');
|
||||||
if ($skip) {
|
if ($skip) {
|
||||||
|
@ -501,41 +559,12 @@ class ControllerTaskTest extends CakeTestCase {
|
||||||
}
|
}
|
||||||
$this->Task->connection = 'test_suite';
|
$this->Task->connection = 'test_suite';
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
$this->Task->args = array('Articles');
|
$this->Task->args = array($name);
|
||||||
|
|
||||||
$filename = '/my/path/articles_controller.php';
|
$filename = '/my/path/articles_controller.php';
|
||||||
$this->Task->expectAt(0, 'createFile', array(
|
$this->Task->expects($this->once())->method('createFile')->with(
|
||||||
$filename, new PatternExpectation('/\$scaffold/')
|
$filename, new PHPUnit_Framework_Constraint_PCREMatch('/\$scaffold/')
|
||||||
));
|
);
|
||||||
|
|
||||||
$this->Task->execute();
|
|
||||||
|
|
||||||
$this->Task->args = array('Article');
|
|
||||||
$filename = '/my/path/articles_controller.php';
|
|
||||||
$this->Task->expectAt(1, 'createFile', array(
|
|
||||||
$filename, new PatternExpectation('/class ArticlesController/')
|
|
||||||
));
|
|
||||||
$this->Task->execute();
|
|
||||||
|
|
||||||
$this->Task->args = array('article');
|
|
||||||
$filename = '/my/path/articles_controller.php';
|
|
||||||
$this->Task->expectAt(2, 'createFile', array(
|
|
||||||
$filename, new PatternExpectation('/class ArticlesController/')
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->Task->args = array('articles');
|
|
||||||
$filename = '/my/path/articles_controller.php';
|
|
||||||
$this->Task->expectAt(3, 'createFile', array(
|
|
||||||
$filename, new PatternExpectation('/class ArticlesController/')
|
|
||||||
));
|
|
||||||
$this->Task->execute();
|
|
||||||
|
|
||||||
$this->Task->args = array('Articles');
|
|
||||||
$filename = '/my/path/articles_controller.php';
|
|
||||||
$this->Task->expectAt(4, 'createFile', array(
|
|
||||||
$filename, new PatternExpectation('/class ArticlesController/')
|
|
||||||
));
|
|
||||||
$this->Task->execute();
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -555,10 +584,10 @@ class ControllerTaskTest extends CakeTestCase {
|
||||||
$this->Task->args = array('Articles', 'public');
|
$this->Task->args = array('Articles', 'public');
|
||||||
|
|
||||||
$filename = '/my/path/articles_controller.php';
|
$filename = '/my/path/articles_controller.php';
|
||||||
$this->Task->expectAt(0, 'createFile', array(
|
$expected = new PHPUnit_Framework_Constraint_Not(new PHPUnit_Framework_Constraint_PCREMatch('/\$scaffold/'));
|
||||||
$filename, new NoPatternExpectation('/var \$scaffold/')
|
$this->Task->expects($this->once())->method('createFile')->with(
|
||||||
));
|
$filename, $expected
|
||||||
|
);
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -573,16 +602,15 @@ class ControllerTaskTest extends CakeTestCase {
|
||||||
if ($skip) {
|
if ($skip) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->Task->Project->setReturnValue('getPrefix', 'admin_');
|
$this->Task->Project->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_'));
|
||||||
$this->Task->connection = 'test_suite';
|
$this->Task->connection = 'test_suite';
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
$this->Task->args = array('Articles', 'public', 'admin');
|
$this->Task->args = array('Articles', 'public', 'admin');
|
||||||
|
|
||||||
$filename = '/my/path/articles_controller.php';
|
$filename = '/my/path/articles_controller.php';
|
||||||
$this->Task->expectAt(0, 'createFile', array(
|
$this->Task->expects($this->once())->method('createFile')->with(
|
||||||
$filename, new PatternExpectation('/admin_index/')
|
$filename, new PHPUnit_Framework_Constraint_PCREMatch('/admin_index/')
|
||||||
));
|
);
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -597,16 +625,15 @@ class ControllerTaskTest extends CakeTestCase {
|
||||||
if ($skip) {
|
if ($skip) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->Task->Project->setReturnValue('getPrefix', 'admin_');
|
$this->Task->Project->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_'));
|
||||||
$this->Task->connection = 'test_suite';
|
$this->Task->connection = 'test_suite';
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
$this->Task->args = array('Articles', 'admin');
|
$this->Task->args = array('Articles', 'admin');
|
||||||
|
|
||||||
$filename = '/my/path/articles_controller.php';
|
$filename = '/my/path/articles_controller.php';
|
||||||
$this->Task->expectAt(0, 'createFile', array(
|
$this->Task->expects($this->once())->method('createFile')->with(
|
||||||
$filename, new PatternExpectation('/admin_index/')
|
$filename, new PHPUnit_Framework_Constraint_PCREMatch('/admin_index/')
|
||||||
));
|
);
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,17 +31,7 @@ if (!class_exists('ShellDispatcher')) {
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'db_config.php';
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'db_config.php';
|
||||||
//require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
|
||||||
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ShellDispatcher', 'TestDbConfigTaskMockShellDispatcher',
|
|
||||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
|
||||||
);
|
|
||||||
|
|
||||||
Mock::generatePartial(
|
|
||||||
'DbConfigTask', 'MockDbConfigTask',
|
|
||||||
array('in', 'hr', 'out', 'err', 'createFile', '_stop', '_checkUnitTest')
|
|
||||||
);
|
|
||||||
|
|
||||||
class TEST_DATABASE_CONFIG {
|
class TEST_DATABASE_CONFIG {
|
||||||
public $default = array(
|
public $default = array(
|
||||||
|
@ -79,9 +69,13 @@ class DbConfigTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function startTest() {
|
public function startTest() {
|
||||||
$this->Dispatcher =& new TestDbConfigTaskMockShellDispatcher();
|
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
|
||||||
$this->Task =& new MockDbConfigTask($this->Dispatcher);
|
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment'
|
||||||
$this->Task->Dispatch =& $this->Dispatcher;
|
));
|
||||||
|
$this->Task = $this->getMock('DbConfigTask',
|
||||||
|
array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest', '_verify'),
|
||||||
|
array(&$this->Dispatcher)
|
||||||
|
);
|
||||||
$this->Task->Dispatch->shellPaths = App::path('shells');
|
$this->Task->Dispatch->shellPaths = App::path('shells');
|
||||||
|
|
||||||
$this->Task->params['working'] = rtrim(APP, DS);
|
$this->Task->params['working'] = rtrim(APP, DS);
|
||||||
|
@ -104,7 +98,7 @@ class DbConfigTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testGetConfig() {
|
public function testGetConfig() {
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'otherOne');
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('otherOne'));
|
||||||
$result = $this->Task->getConfig();
|
$result = $this->Task->getConfig();
|
||||||
$this->assertEqual($result, 'otherOne');
|
$this->assertEqual($result, 'otherOne');
|
||||||
}
|
}
|
||||||
|
@ -129,21 +123,21 @@ class DbConfigTaskTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testExecuteIntoInteractive() {
|
public function testExecuteIntoInteractive() {
|
||||||
$this->Task->initialize();
|
$this->Task->initialize();
|
||||||
|
$this->Task = $this->getMock('DbConfigTask', array('in', '_stop', 'createFile'), array(&$this->Dispatcher));
|
||||||
|
|
||||||
$this->Task->expectOnce('_stop');
|
$this->Task->expects($this->once())->method('_stop');
|
||||||
$this->Task->setReturnValue('in', 'y');
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('default')); //name
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'default');
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('mysql')); //db type
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'n');
|
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('n')); //persistant
|
||||||
$this->Task->setReturnValueAt(2, 'in', 'localhost');
|
$this->Task->expects($this->at(3))->method('in')->will($this->returnValue('localhost')); //server
|
||||||
$this->Task->setReturnValueAt(3, 'in', 'n');
|
$this->Task->expects($this->at(4))->method('in')->will($this->returnValue('n')); //port
|
||||||
$this->Task->setReturnValueAt(4, 'in', 'root');
|
$this->Task->expects($this->at(5))->method('in')->will($this->returnValue('root')); //user
|
||||||
$this->Task->setReturnValueAt(5, 'in', 'password');
|
$this->Task->expects($this->at(6))->method('in')->will($this->returnValue('password')); //password
|
||||||
$this->Task->setReturnValueAt(6, 'in', 'cake_test');
|
$this->Task->expects($this->at(10))->method('in')->will($this->returnValue('cake_test')); //db
|
||||||
$this->Task->setReturnValueAt(7, 'in', 'n');
|
$this->Task->expects($this->at(11))->method('in')->will($this->returnValue('n')); //prefix
|
||||||
$this->Task->setReturnValueAt(8, 'in', 'y');
|
$this->Task->expects($this->at(12))->method('in')->will($this->returnValue('n')); //encoding
|
||||||
$this->Task->setReturnValueAt(9, 'in', 'y');
|
$this->Task->expects($this->at(13))->method('in')->will($this->returnValue('y')); //looks good
|
||||||
$this->Task->setReturnValueAt(10, 'in', 'y');
|
$this->Task->expects($this->at(14))->method('in')->will($this->returnValue('n')); //another
|
||||||
$this->Task->setReturnValueAt(11, 'in', 'n');
|
|
||||||
|
|
||||||
$result = $this->Task->execute();
|
$result = $this->Task->execute();
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,12 +35,6 @@ if (!class_exists('ShellDispatcher')) {
|
||||||
|
|
||||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'extract.php';
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'extract.php';
|
||||||
|
|
||||||
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ShellDispatcher', 'TestExtractTaskMockShellDispatcher',
|
|
||||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ExtractTaskTest class
|
* ExtractTaskTest class
|
||||||
*
|
*
|
||||||
|
@ -55,7 +49,9 @@ class ExtractTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
$this->Dispatcher =& new TestExtractTaskMockShellDispatcher();
|
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
|
||||||
|
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment'
|
||||||
|
));
|
||||||
$this->Task =& new ExtractTask($this->Dispatcher);
|
$this->Task =& new ExtractTask($this->Dispatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,8 +77,9 @@ class ExtractTaskTest extends CakeTestCase {
|
||||||
|
|
||||||
$this->Task->params['paths'] = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'pages';
|
$this->Task->params['paths'] = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'pages';
|
||||||
$this->Task->params['output'] = $path . DS;
|
$this->Task->params['output'] = $path . DS;
|
||||||
$this->Task->Dispatch->expectNever('stderr');
|
$this->Dispatcher->expects($this->never())->method('stderr');
|
||||||
$this->Task->Dispatch->expectNever('_stop');
|
$this->Dispatcher->expects($this->never())->method('_stop');
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
$this->assertTrue(file_exists($path . DS . 'default.pot'));
|
$this->assertTrue(file_exists($path . DS . 'default.pot'));
|
||||||
$result = file_get_contents($path . DS . 'default.pot');
|
$result = file_get_contents($path . DS . 'default.pot');
|
||||||
|
@ -132,7 +129,7 @@ class ExtractTaskTest extends CakeTestCase {
|
||||||
$this->assertPattern($pattern, $result);
|
$this->assertPattern($pattern, $result);
|
||||||
|
|
||||||
$pattern = '/\#: (\\\\|\/)extract\.ctp:14\n';
|
$pattern = '/\#: (\\\\|\/)extract\.ctp:14\n';
|
||||||
$pattern .= '\#: (\\\\|\/)home\.ctp:74\n';
|
$pattern .= '\#: (\\\\|\/)home\.ctp:66\n';
|
||||||
$pattern .= 'msgid "Editing this Page"\nmsgstr ""/';
|
$pattern .= 'msgid "Editing this Page"\nmsgstr ""/';
|
||||||
$this->assertPattern($pattern, $result);
|
$this->assertPattern($pattern, $result);
|
||||||
|
|
||||||
|
|
|
@ -33,21 +33,6 @@ if (!class_exists('ShellDispatcher')) {
|
||||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
||||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'fixture.php';
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'fixture.php';
|
||||||
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ShellDispatcher', 'TestFixtureTaskMockShellDispatcher',
|
|
||||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
|
||||||
);
|
|
||||||
|
|
||||||
Mock::generatePartial(
|
|
||||||
'FixtureTask', 'MockFixtureTask',
|
|
||||||
array('in', 'out', 'err', 'createFile', '_stop')
|
|
||||||
);
|
|
||||||
|
|
||||||
Mock::generatePartial(
|
|
||||||
'Shell', 'MockFixtureModelTask',
|
|
||||||
array('in', 'out', 'err', 'createFile', '_stop', 'getName', 'getTable', 'listAll')
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FixtureTaskTest class
|
* FixtureTaskTest class
|
||||||
*
|
*
|
||||||
|
@ -70,11 +55,18 @@ class FixtureTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function startTest() {
|
public function startTest() {
|
||||||
$this->Dispatcher =& new TestFixtureTaskMockShellDispatcher();
|
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
|
||||||
$this->Task =& new MockFixtureTask();
|
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment'
|
||||||
$this->Task->Model =& new MockFixtureModelTask();
|
));
|
||||||
$this->Task->Dispatch =& $this->Dispatcher;
|
$this->Task = $this->getMock('FixtureTask',
|
||||||
$this->Task->Template =& new TemplateTask($this->Task->Dispatch);
|
array('in', 'err', 'createFile', '_stop'),
|
||||||
|
array(&$this->Dispatcher)
|
||||||
|
);
|
||||||
|
$this->Task->Model = $this->getMock('Shell',
|
||||||
|
array('in', 'out', 'erro', 'createFile', 'getName', 'getTable', 'listAll'),
|
||||||
|
array(&$this->Dispatcher)
|
||||||
|
);
|
||||||
|
$this->Task->Template =& new TemplateTask($this->Dispatcher);
|
||||||
$this->Task->Dispatch->shellPaths = App::path('shells');
|
$this->Task->Dispatch->shellPaths = App::path('shells');
|
||||||
$this->Task->Template->initialize();
|
$this->Task->Template->initialize();
|
||||||
}
|
}
|
||||||
|
@ -96,7 +88,7 @@ class FixtureTaskTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testConstruct() {
|
public function testConstruct() {
|
||||||
$this->Dispatch->params['working'] = DS . 'my' . DS . 'path';
|
$this->Dispatch->params['working'] = DS . 'my' . DS . 'path';
|
||||||
$Task =& new FixtureTask($this->Dispatch);
|
$Task = new FixtureTask($this->Dispatch);
|
||||||
|
|
||||||
$expected = DS . 'my' . DS . 'path' . DS . 'tests' . DS . 'fixtures' . DS;
|
$expected = DS . 'my' . DS . 'path' . DS . 'tests' . DS . 'fixtures' . DS;
|
||||||
$this->assertEqual($Task->path, $expected);
|
$this->assertEqual($Task->path, $expected);
|
||||||
|
@ -107,25 +99,39 @@ class FixtureTaskTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testImportOptions() {
|
public function testImportOptionsSchemaRecords() {
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'y');
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y'));
|
||||||
|
|
||||||
$result = $this->Task->importOptions('Article');
|
$result = $this->Task->importOptions('Article');
|
||||||
$expected = array('schema' => 'Article', 'records' => true);
|
$expected = array('schema' => 'Article', 'records' => true);
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(2, 'in', 'n');
|
/**
|
||||||
$this->Task->setReturnValueAt(3, 'in', 'n');
|
* test importOptions choosing nothing.
|
||||||
$this->Task->setReturnValueAt(4, 'in', 'n');
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testImportOptionsNothing() {
|
||||||
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
|
||||||
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('n'));
|
||||||
|
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('n'));
|
||||||
|
|
||||||
$result = $this->Task->importOptions('Article');
|
$result = $this->Task->importOptions('Article');
|
||||||
$expected = array();
|
$expected = array();
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(5, 'in', 'n');
|
/**
|
||||||
$this->Task->setReturnValueAt(6, 'in', 'n');
|
* test importOptions choosing from Table.
|
||||||
$this->Task->setReturnValueAt(7, 'in', 'y');
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testImportOptionsTable() {
|
||||||
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
|
||||||
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('n'));
|
||||||
|
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('y'));
|
||||||
$result = $this->Task->importOptions('Article');
|
$result = $this->Task->importOptions('Article');
|
||||||
$expected = array('fromTable' => true);
|
$expected = array('fromTable' => true);
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
@ -138,10 +144,15 @@ class FixtureTaskTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testImportRecordsFromDatabaseWithConditions() {
|
public function testImportRecordsFromDatabaseWithConditions() {
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'WHERE 1=1 LIMIT 10');
|
$this->Task->expects($this->at(0))->method('in')
|
||||||
|
->will($this->returnValue('WHERE 1=1 LIMIT 10'));
|
||||||
|
|
||||||
$this->Task->connection = 'test_suite';
|
$this->Task->connection = 'test_suite';
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
$result = $this->Task->bake('Article', false, array('fromTable' => true, 'schema' => 'Article', 'records' => false));
|
|
||||||
|
$result = $this->Task->bake('Article', false, array(
|
||||||
|
'fromTable' => true, 'schema' => 'Article', 'records' => false
|
||||||
|
));
|
||||||
|
|
||||||
$this->assertPattern('/class ArticleFixture extends CakeTestFixture/', $result);
|
$this->assertPattern('/class ArticleFixture extends CakeTestFixture/', $result);
|
||||||
$this->assertPattern('/public \$records/', $result);
|
$this->assertPattern('/public \$records/', $result);
|
||||||
|
@ -161,37 +172,39 @@ class FixtureTaskTest extends CakeTestCase {
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
$this->Task->args = array('article');
|
$this->Task->args = array('article');
|
||||||
$filename = '/my/path/article_fixture.php';
|
$filename = '/my/path/article_fixture.php';
|
||||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticleFixture/')));
|
|
||||||
|
$this->Task->expects($this->at(0))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class ArticleFixture/'));
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* data provider for model name variations.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function modelNameProvider() {
|
||||||
|
return array(
|
||||||
|
array('article'), array('articles'), array('Articles'), array('Article')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test that execute passes runs bake depending with named model.
|
* test that execute passes runs bake depending with named model.
|
||||||
*
|
*
|
||||||
|
* @dataProvider modelNameProvider
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testExecuteWithNamedModelVariations() {
|
public function testExecuteWithNamedModelVariations($modelName) {
|
||||||
$this->Task->connection = 'test_suite';
|
$this->Task->connection = 'test_suite';
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
|
|
||||||
$this->Task->args = array('article');
|
$this->Task->args = array($modelName);
|
||||||
$filename = '/my/path/article_fixture.php';
|
$filename = '/my/path/article_fixture.php';
|
||||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticleFixture/')));
|
$this->Task->expects($this->once())->method('createFile')
|
||||||
$this->Task->execute();
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class ArticleFixture/'));
|
||||||
|
|
||||||
$this->Task->args = array('articles');
|
|
||||||
$filename = '/my/path/article_fixture.php';
|
|
||||||
$this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/class ArticleFixture/')));
|
|
||||||
$this->Task->execute();
|
|
||||||
|
|
||||||
$this->Task->args = array('Articles');
|
|
||||||
$filename = '/my/path/article_fixture.php';
|
|
||||||
$this->Task->expectAt(2, 'createFile', array($filename, new PatternExpectation('/class ArticleFixture/')));
|
|
||||||
$this->Task->execute();
|
|
||||||
|
|
||||||
$this->Task->args = array('Article');
|
|
||||||
$filename = '/my/path/article_fixture.php';
|
|
||||||
$this->Task->expectAt(3, 'createFile', array($filename, new PatternExpectation('/class ArticleFixture/')));
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,14 +217,17 @@ class FixtureTaskTest extends CakeTestCase {
|
||||||
$this->Task->connection = 'test_suite';
|
$this->Task->connection = 'test_suite';
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
$this->Task->args = array('all');
|
$this->Task->args = array('all');
|
||||||
$this->Task->Model->setReturnValue('listAll', array('articles', 'comments'));
|
$this->Task->Model->expects($this->any())->method('listAll')
|
||||||
|
->will($this->returnValue(array('articles', 'comments')));
|
||||||
|
|
||||||
$filename = '/my/path/article_fixture.php';
|
$filename = '/my/path/article_fixture.php';
|
||||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticleFixture/')));
|
$this->Task->expects($this->at(0))->method('createFile')
|
||||||
$this->Task->execute();
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class ArticleFixture/'));
|
||||||
|
|
||||||
$filename = '/my/path/comment_fixture.php';
|
$filename = '/my/path/comment_fixture.php';
|
||||||
$this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/class CommentFixture/')));
|
$this->Task->expects($this->at(1))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class CommentFixture/'));
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,14 +241,19 @@ class FixtureTaskTest extends CakeTestCase {
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
$this->Task->args = array('all');
|
$this->Task->args = array('all');
|
||||||
$this->Task->params = array('count' => 10, 'records' => true);
|
$this->Task->params = array('count' => 10, 'records' => true);
|
||||||
$this->Task->Model->setReturnValue('listAll', array('articles', 'comments'));
|
|
||||||
|
$this->Task->Model->expects($this->any())->method('listAll')
|
||||||
|
->will($this->returnValue(array('articles', 'comments')));
|
||||||
|
|
||||||
$filename = '/my/path/article_fixture.php';
|
$filename = '/my/path/article_fixture.php';
|
||||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/title\' => \'Third Article\'/')));
|
$this->Task->expects($this->at(0))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/title\' => \'Third Article\'/'));
|
||||||
|
|
||||||
$filename = '/my/path/comment_fixture.php';
|
$filename = '/my/path/comment_fixture.php';
|
||||||
$this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/comment\' => \'First Comment for First Article/')));
|
$this->Task->expects($this->at(1))->method('createFile')
|
||||||
$this->Task->expectCallCount('createFile', 2);
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/comment\' => \'First Comment for First Article/'));
|
||||||
|
$this->Task->expects($this->exactly(2))->method('createFile');
|
||||||
|
|
||||||
$this->Task->all();
|
$this->Task->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,12 +266,16 @@ class FixtureTaskTest extends CakeTestCase {
|
||||||
$this->Task->connection = 'test_suite';
|
$this->Task->connection = 'test_suite';
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
|
|
||||||
$this->Task->setReturnValue('in', 'y');
|
$this->Task->expects($this->any())->method('in')->will($this->returnValue('y'));
|
||||||
$this->Task->Model->setReturnValue('getName', 'Article');
|
$this->Task->Model->expects($this->any())->method('getName')->will($this->returnValue('Article'));
|
||||||
$this->Task->Model->setReturnValue('getTable', 'articles', array('Article'));
|
$this->Task->Model->expects($this->any())->method('getTable')
|
||||||
|
->with('Article')
|
||||||
|
->will($this->returnValue('articles'));
|
||||||
|
|
||||||
$filename = '/my/path/article_fixture.php';
|
$filename = '/my/path/article_fixture.php';
|
||||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticleFixture/')));
|
$this->Task->expects($this->once())->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class ArticleFixture/'));
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,10 +340,14 @@ class FixtureTaskTest extends CakeTestCase {
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
$filename = '/my/path/article_fixture.php';
|
$filename = '/my/path/article_fixture.php';
|
||||||
|
|
||||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/Article/')));
|
$this->Task->expects($this->at(0))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/Article/'));
|
||||||
|
|
||||||
|
$this->Task->expects($this->at(1))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/\<\?php(.*)\?\>/ms'));
|
||||||
|
|
||||||
$result = $this->Task->generateFixtureFile('Article', array());
|
$result = $this->Task->generateFixtureFile('Article', array());
|
||||||
|
|
||||||
$this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/\<\?php(.*)\?\>/ms')));
|
|
||||||
$result = $this->Task->generateFixtureFile('Article', array());
|
$result = $this->Task->generateFixtureFile('Article', array());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,7 +362,9 @@ class FixtureTaskTest extends CakeTestCase {
|
||||||
$this->Task->plugin = 'TestFixture';
|
$this->Task->plugin = 'TestFixture';
|
||||||
$filename = APP . 'plugins' . DS . 'test_fixture' . DS . 'tests' . DS . 'fixtures' . DS . 'article_fixture.php';
|
$filename = APP . 'plugins' . DS . 'test_fixture' . DS . 'tests' . DS . 'fixtures' . DS . 'article_fixture.php';
|
||||||
|
|
||||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/Article/')));
|
$this->Task->expects($this->at(0))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/Article/'));
|
||||||
|
|
||||||
$result = $this->Task->generateFixtureFile('Article', array());
|
$result = $this->Task->generateFixtureFile('Article', array());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,23 +36,6 @@ require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php';
|
||||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'fixture.php';
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'fixture.php';
|
||||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
||||||
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ShellDispatcher', 'TestModelTaskMockShellDispatcher',
|
|
||||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
|
||||||
);
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ModelTask', 'MockModelTask',
|
|
||||||
array('in', 'out', 'hr', 'err', 'createFile', '_stop', '_checkUnitTest')
|
|
||||||
);
|
|
||||||
|
|
||||||
Mock::generate(
|
|
||||||
'Model', 'MockModelTaskModel'
|
|
||||||
);
|
|
||||||
|
|
||||||
Mock::generate(
|
|
||||||
'FixtureTask', 'MockModelTaskFixtureTask'
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ModelTaskTest class
|
* ModelTaskTest class
|
||||||
*
|
*
|
||||||
|
@ -75,15 +58,42 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function startTest() {
|
public function startTest() {
|
||||||
$this->Dispatcher =& new TestModelTaskMockShellDispatcher();
|
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
|
||||||
$this->Task =& new MockModelTask($this->Dispatcher);
|
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment'
|
||||||
|
));
|
||||||
|
$this->Task = $this->getMock('ModelTask',
|
||||||
|
array('in', 'err', 'createFile', '_stop', '_checkUnitTest'),
|
||||||
|
array(&$this->Dispatcher)
|
||||||
|
);
|
||||||
|
$this->_setupOtherMocks();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup a mock that has out mocked. Normally this is not used as it makes $this->at() really tricky.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function _useMockedOut() {
|
||||||
|
$this->Task = $this->getMock('ModelTask',
|
||||||
|
array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'),
|
||||||
|
array(&$this->Dispatcher)
|
||||||
|
);
|
||||||
|
$this->_setupOtherMocks();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets up the rest of the dependencies for Model Task
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function _setupOtherMocks() {
|
||||||
|
$this->Task->Fixture = $this->getMock('FixtureTask', array(), array(&$this->Dispatcher));
|
||||||
|
$this->Task->Test = $this->getMock('FixtureTask', array(), array(&$this->Dispatcher));
|
||||||
|
$this->Task->Template =& new TemplateTask($this->Task->Dispatch);
|
||||||
|
|
||||||
$this->Task->name = 'ModelTask';
|
$this->Task->name = 'ModelTask';
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
$this->Task->Dispatch =& $this->Dispatcher;
|
|
||||||
$this->Task->Dispatch->shellPaths = App::path('shells');
|
$this->Task->Dispatch->shellPaths = App::path('shells');
|
||||||
$this->Task->Template =& new TemplateTask($this->Task->Dispatch);
|
|
||||||
$this->Task->Fixture =& new MockModelTaskFixtureTask();
|
|
||||||
$this->Task->Test =& new MockModelTaskFixtureTask();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,21 +112,24 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testListAll() {
|
public function testListAll() {
|
||||||
$this->Task->expectAt(1, 'out', array('1. Article'));
|
$this->_useMockedOut();
|
||||||
$this->Task->expectAt(2, 'out', array('2. ArticlesTag'));
|
|
||||||
$this->Task->expectAt(3, 'out', array('3. CategoryThread'));
|
$this->Task->expects($this->at(1))->method('out')->with('1. Article');
|
||||||
$this->Task->expectAt(4, 'out', array('4. Comment'));
|
$this->Task->expects($this->at(2))->method('out')->with('2. ArticlesTag');
|
||||||
$this->Task->expectAt(5, 'out', array('5. Tag'));
|
$this->Task->expects($this->at(3))->method('out')->with('3. CategoryThread');
|
||||||
|
$this->Task->expects($this->at(4))->method('out')->with('4. Comment');
|
||||||
|
$this->Task->expects($this->at(5))->method('out')->with('5. Tag');
|
||||||
|
|
||||||
|
$this->Task->expects($this->at(7))->method('out')->with('1. Article');
|
||||||
|
$this->Task->expects($this->at(8))->method('out')->with('2. ArticlesTag');
|
||||||
|
$this->Task->expects($this->at(9))->method('out')->with('3. CategoryThread');
|
||||||
|
$this->Task->expects($this->at(10))->method('out')->with('4. Comment');
|
||||||
|
$this->Task->expects($this->at(11))->method('out')->with('5. Tag');
|
||||||
|
|
||||||
$result = $this->Task->listAll('test_suite');
|
$result = $this->Task->listAll('test_suite');
|
||||||
$expected = array('articles', 'articles_tags', 'category_threads', 'comments', 'tags');
|
$expected = array('articles', 'articles_tags', 'category_threads', 'comments', 'tags');
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$this->Task->expectAt(7, 'out', array('1. Article'));
|
|
||||||
$this->Task->expectAt(8, 'out', array('2. ArticlesTag'));
|
|
||||||
$this->Task->expectAt(9, 'out', array('3. CategoryThread'));
|
|
||||||
$this->Task->expectAt(10, 'out', array('4. Comment'));
|
|
||||||
$this->Task->expectAt(11, 'out', array('5. Tag'));
|
|
||||||
|
|
||||||
$this->Task->connection = 'test_suite';
|
$this->Task->connection = 'test_suite';
|
||||||
$result = $this->Task->listAll();
|
$result = $this->Task->listAll();
|
||||||
$expected = array('articles', 'articles_tags', 'category_threads', 'comments', 'tags');
|
$expected = array('articles', 'articles_tags', 'category_threads', 'comments', 'tags');
|
||||||
|
@ -128,26 +141,41 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testGetName() {
|
public function testGetNameQuit() {
|
||||||
$this->Task->setReturnValue('in', 1);
|
$this->Task->expects($this->once())->method('in')->will($this->returnValue('q'));
|
||||||
|
$this->Task->expects($this->once())->method('_stop');
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'q');
|
|
||||||
$this->Task->expectOnce('_stop');
|
|
||||||
$this->Task->getName('test_suite');
|
$this->Task->getName('test_suite');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test getName with a valid option.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testGetNameValidOption() {
|
||||||
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue(1));
|
||||||
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(4));
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(1, 'in', 1);
|
|
||||||
$result = $this->Task->getName('test_suite');
|
$result = $this->Task->getName('test_suite');
|
||||||
$expected = 'Article';
|
$expected = 'Article';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(2, 'in', 4);
|
|
||||||
$result = $this->Task->getName('test_suite');
|
$result = $this->Task->getName('test_suite');
|
||||||
$expected = 'Comment';
|
$expected = 'Comment';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that an out of bounds option causes an error.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testGetNameWithOutOfBoundsOption() {
|
||||||
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue(10));
|
||||||
|
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue(1));
|
||||||
|
$this->Task->expects($this->once())->method('err');
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(3, 'in', 10);
|
|
||||||
$result = $this->Task->getName('test_suite');
|
$result = $this->Task->getName('test_suite');
|
||||||
$this->Task->expectOnce('err');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -156,13 +184,20 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testGetTableName() {
|
public function testGetTableName() {
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'y');
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
|
||||||
$result = $this->Task->getTable('Article', 'test_suite');
|
$result = $this->Task->getTable('Article', 'test_suite');
|
||||||
$expected = 'articles';
|
$expected = 'articles';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'n');
|
/**
|
||||||
$this->Task->setReturnValueAt(2, 'in', 'my_table');
|
* test gettting a custom table name.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testGetTableNameCustom() {
|
||||||
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
|
||||||
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('my_table'));
|
||||||
$result = $this->Task->getTable('Article', 'test_suite');
|
$result = $this->Task->getTable('Article', 'test_suite');
|
||||||
$expected = 'my_table';
|
$expected = 'my_table';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
@ -215,10 +250,8 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
public function testInteractiveFieldValidation() {
|
public function testInteractiveFieldValidation() {
|
||||||
$this->Task->initValidations();
|
$this->Task->initValidations();
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
$this->Task->setReturnValueAt(0, 'in', '20');
|
$this->Task->expects($this->any())->method('in')
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
->will($this->onConsecutiveCalls('20', 'y', '16', 'n'));
|
||||||
$this->Task->setReturnValueAt(2, 'in', '16');
|
|
||||||
$this->Task->setReturnValueAt(3, 'in', 'n');
|
|
||||||
|
|
||||||
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
||||||
$expected = array('notempty' => 'notempty', 'maxlength' => 'maxlength');
|
$expected = array('notempty' => 'notempty', 'maxlength' => 'maxlength');
|
||||||
|
@ -231,12 +264,15 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testInteractiveFieldValidationWithBogusResponse() {
|
function testInteractiveFieldValidationWithBogusResponse() {
|
||||||
|
$this->_useMockedOut();
|
||||||
$this->Task->initValidations();
|
$this->Task->initValidations();
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
$this->Task->setReturnValueAt(0, 'in', '999999');
|
|
||||||
$this->Task->setReturnValueAt(1, 'in', '20');
|
$this->Task->expects($this->any())->method('in')
|
||||||
$this->Task->setReturnValueAt(2, 'in', 'n');
|
->will($this->onConsecutiveCalls('999999', '20', 'n'));
|
||||||
$this->Task->expectAt(4, 'out', array(new PatternExpectation('/make a valid/')));
|
|
||||||
|
$this->Task->expects($this->at(7))->method('out')
|
||||||
|
->with(new PHPUnit_Framework_Constraint_PCREMatch('/make a valid/'));
|
||||||
|
|
||||||
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
||||||
$expected = array('notempty' => 'notempty');
|
$expected = array('notempty' => 'notempty');
|
||||||
|
@ -251,8 +287,8 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
function testInteractiveFieldValidationWithRegexp() {
|
function testInteractiveFieldValidationWithRegexp() {
|
||||||
$this->Task->initValidations();
|
$this->Task->initValidations();
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
$this->Task->setReturnValueAt(0, 'in', '/^[a-z]{0,9}$/');
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('/^[a-z]{0,9}$/'));
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'n');
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('n'));
|
||||||
|
|
||||||
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
||||||
$expected = array('a_z_0_9' => '/^[a-z]{0,9}$/');
|
$expected = array('a_z_0_9' => '/^[a-z]{0,9}$/');
|
||||||
|
@ -265,9 +301,9 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testNonInteractiveDoValidation() {
|
public function testNonInteractiveDoValidation() {
|
||||||
$Model =& new MockModelTaskModel();
|
$Model = $this->getMock('Model');
|
||||||
$Model->primaryKey = 'id';
|
$Model->primaryKey = 'id';
|
||||||
$Model->setReturnValue('schema', array(
|
$Model->expects($this->any())->method('schema')->will($this->returnValue(array(
|
||||||
'id' => array(
|
'id' => array(
|
||||||
'type' => 'integer',
|
'type' => 'integer',
|
||||||
'length' => 11,
|
'length' => 11,
|
||||||
|
@ -299,7 +335,7 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
'length' => '',
|
'length' => '',
|
||||||
'null' => false,
|
'null' => false,
|
||||||
)
|
)
|
||||||
));
|
)));
|
||||||
$this->Task->interactive = false;
|
$this->Task->interactive = false;
|
||||||
|
|
||||||
$result = $this->Task->doValidation($Model);
|
$result = $this->Task->doValidation($Model);
|
||||||
|
@ -331,8 +367,11 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
'two' => array(),
|
'two' => array(),
|
||||||
'key' => array('key' => 'primary')
|
'key' => array('key' => 'primary')
|
||||||
);
|
);
|
||||||
$this->Task->expectAt(0, 'in', array('*', null, 'key'));
|
$anything = new PHPUnit_Framework_Constraint_IsAnything();
|
||||||
$this->Task->setReturnValue('in', 'my_field');
|
$this->Task->expects($this->once())->method('in')
|
||||||
|
->with($anything, null, 'key')
|
||||||
|
->will($this->returnValue('my_field'));
|
||||||
|
|
||||||
$result = $this->Task->findPrimaryKey($fields);
|
$result = $this->Task->findPrimaryKey($fields);
|
||||||
$expected = 'my_field';
|
$expected = 'my_field';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
@ -343,17 +382,28 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testFindDisplayField() {
|
public function testFindDisplayFieldNone() {
|
||||||
$fields = array('id' => array(), 'tagname' => array(), 'body' => array(),
|
$fields = array(
|
||||||
'created' => array(), 'modified' => array());
|
'id' => array(), 'tagname' => array(), 'body' => array(),
|
||||||
|
'created' => array(), 'modified' => array()
|
||||||
$this->Task->setReturnValue('in', 'n');
|
);
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'n');
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
|
||||||
$result = $this->Task->findDisplayField($fields);
|
$result = $this->Task->findDisplayField($fields);
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
|
}
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
/**
|
||||||
$this->Task->setReturnValueAt(2, 'in', 2);
|
* Test finding a displayname from user input
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testFindDisplayName() {
|
||||||
|
$fields = array(
|
||||||
|
'id' => array(), 'tagname' => array(), 'body' => array(),
|
||||||
|
'created' => array(), 'modified' => array()
|
||||||
|
);
|
||||||
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
|
||||||
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(2));
|
||||||
$result = $this->Task->findDisplayField($fields);
|
$result = $this->Task->findDisplayField($fields);
|
||||||
$this->assertEqual($result, 'tagname');
|
$this->assertEqual($result, 'tagname');
|
||||||
}
|
}
|
||||||
|
@ -507,7 +557,7 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
public function testBakeFixture() {
|
public function testBakeFixture() {
|
||||||
$this->Task->plugin = 'test_plugin';
|
$this->Task->plugin = 'test_plugin';
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
$this->Task->Fixture->expectAt(0, 'bake', array('Article', 'articles'));
|
$this->Task->Fixture->expects($this->at(0))->method('bake')->with('Article', 'articles');
|
||||||
$this->Task->bakeFixture('Article', 'articles');
|
$this->Task->bakeFixture('Article', 'articles');
|
||||||
|
|
||||||
$this->assertEqual($this->Task->plugin, $this->Task->Fixture->plugin);
|
$this->assertEqual($this->Task->plugin, $this->Task->Fixture->plugin);
|
||||||
|
@ -523,7 +573,7 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
public function testBakeTest() {
|
public function testBakeTest() {
|
||||||
$this->Task->plugin = 'test_plugin';
|
$this->Task->plugin = 'test_plugin';
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
$this->Task->Test->expectAt(0, 'bake', array('Model', 'Article'));
|
$this->Task->Test->expects($this->at(0))->method('bake')->with('Model', 'Article');
|
||||||
$this->Task->bakeTest('Article');
|
$this->Task->bakeTest('Article');
|
||||||
|
|
||||||
$this->assertEqual($this->Task->plugin, $this->Task->Test->plugin);
|
$this->assertEqual($this->Task->plugin, $this->Task->Test->plugin);
|
||||||
|
@ -562,11 +612,13 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$model = new Model(array('ds' => 'test_suite', 'name' => 'CategoryThread'));
|
$model = new Model(array('ds' => 'test_suite', 'name' => 'CategoryThread'));
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'y');
|
|
||||||
|
$this->Task->expects($this->any())->method('in')
|
||||||
|
->will($this->onConsecutiveCalls('n', 'y', 'n', 'n', 'n'));
|
||||||
|
|
||||||
$result = $this->Task->confirmAssociations($model, $associations);
|
$result = $this->Task->confirmAssociations($model, $associations);
|
||||||
$this->assertTrue(empty($result['hasOne']));
|
$this->assertTrue(empty($result['hasOne']));
|
||||||
|
|
||||||
$this->Task->setReturnValue('in', 'n');
|
|
||||||
$result = $this->Task->confirmAssociations($model, $associations);
|
$result = $this->Task->confirmAssociations($model, $associations);
|
||||||
$this->assertTrue(empty($result['hasMany']));
|
$this->assertTrue(empty($result['hasMany']));
|
||||||
$this->assertTrue(empty($result['hasOne']));
|
$this->assertTrue(empty($result['hasOne']));
|
||||||
|
@ -578,16 +630,18 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testInOptions() {
|
public function testInOptions() {
|
||||||
$options = array('one', 'two', 'three');
|
$this->_useMockedOut();
|
||||||
$this->Task->expectAt(0, 'out', array('1. one'));
|
|
||||||
$this->Task->expectAt(1, 'out', array('2. two'));
|
|
||||||
$this->Task->expectAt(2, 'out', array('3. three'));
|
|
||||||
$this->Task->setReturnValueAt(0, 'in', 10);
|
|
||||||
|
|
||||||
$this->Task->expectAt(3, 'out', array('1. one'));
|
$options = array('one', 'two', 'three');
|
||||||
$this->Task->expectAt(4, 'out', array('2. two'));
|
$this->Task->expects($this->at(0))->method('out')->with('1. one');
|
||||||
$this->Task->expectAt(5, 'out', array('3. three'));
|
$this->Task->expects($this->at(1))->method('out')->with('2. two');
|
||||||
$this->Task->setReturnValueAt(1, 'in', 2);
|
$this->Task->expects($this->at(2))->method('out')->with('3. three');
|
||||||
|
$this->Task->expects($this->at(3))->method('in')->will($this->returnValue(10));
|
||||||
|
|
||||||
|
$this->Task->expects($this->at(4))->method('out')->with('1. one');
|
||||||
|
$this->Task->expects($this->at(5))->method('out')->with('2. two');
|
||||||
|
$this->Task->expects($this->at(6))->method('out')->with('3. three');
|
||||||
|
$this->Task->expects($this->at(7))->method('in')->will($this->returnValue(2));
|
||||||
$result = $this->Task->inOptions($options, 'Pick a number');
|
$result = $this->Task->inOptions($options, 'Pick a number');
|
||||||
$this->assertEqual($result, 1);
|
$this->assertEqual($result, 1);
|
||||||
}
|
}
|
||||||
|
@ -690,17 +744,12 @@ STRINGEND;
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testBakeWithPlugin() {
|
public function testBakeWithPlugin() {
|
||||||
$this->Task->plugin = 'ControllerTest';
|
|
||||||
|
|
||||||
$path = APP . 'plugins' . DS . 'controller_test' . DS . 'models' . DS . 'article.php';
|
|
||||||
$this->Task->expectAt(0, 'createFile', array($path, '*'));
|
|
||||||
$this->Task->bake('Article', array(), array());
|
|
||||||
|
|
||||||
$this->Task->plugin = 'controllerTest';
|
$this->Task->plugin = 'controllerTest';
|
||||||
|
|
||||||
$path = APP . 'plugins' . DS . 'controller_test' . DS . 'models' . DS . 'article.php';
|
$path = APP . 'plugins' . DS . 'controller_test' . DS . 'models' . DS . 'article.php';
|
||||||
$this->Task->expectAt(1, 'createFile', array(
|
$this->Task->expects($this->once())->method('createFile')
|
||||||
$path, new PatternExpectation('/Article extends ControllerTestAppModel/')));
|
->with($path, new PHPUnit_Framework_Constraint_PCREMatch('/Article extends ControllerTestAppModel/'));
|
||||||
|
|
||||||
$this->Task->bake('Article', array(), array());
|
$this->Task->bake('Article', array(), array());
|
||||||
|
|
||||||
$this->assertEqual(count(ClassRegistry::keys()), 0);
|
$this->assertEqual(count(ClassRegistry::keys()), 0);
|
||||||
|
@ -717,8 +766,11 @@ STRINGEND;
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
$this->Task->args = array('article');
|
$this->Task->args = array('article');
|
||||||
$filename = '/my/path/article.php';
|
$filename = '/my/path/article.php';
|
||||||
$this->Task->setReturnValue('_checkUnitTest', 1);
|
|
||||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article extends AppModel/')));
|
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(1));
|
||||||
|
$this->Task->expects($this->once())->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class Article extends AppModel/'));
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
|
|
||||||
$this->assertEqual(count(ClassRegistry::keys()), 0);
|
$this->assertEqual(count(ClassRegistry::keys()), 0);
|
||||||
|
@ -726,27 +778,32 @@ STRINGEND;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test that execute passes with different inflections of the same name.
|
* data provider for testExecuteWithNamedModelVariations
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testExecuteWithNamedModelVariations() {
|
static function nameVariations() {
|
||||||
|
return array(
|
||||||
|
array('Articles'), array('Article'), array('article'), array('articles')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that execute passes with different inflections of the same name.
|
||||||
|
*
|
||||||
|
* @dataProvider nameVariations
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testExecuteWithNamedModelVariations($name) {
|
||||||
$this->Task->connection = 'test_suite';
|
$this->Task->connection = 'test_suite';
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
$this->Task->setReturnValue('_checkUnitTest', 1);
|
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(1));
|
||||||
|
|
||||||
$this->Task->args = array('article');
|
$this->Task->args = array($name);
|
||||||
$filename = '/my/path/article.php';
|
$filename = '/my/path/article.php';
|
||||||
|
|
||||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article extends AppModel/')));
|
$this->Task->expects($this->at(0))->method('createFile')
|
||||||
$this->Task->execute();
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class Article extends AppModel/'));
|
||||||
|
|
||||||
$this->Task->args = array('Articles');
|
|
||||||
$this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/class Article extends AppModel/')));
|
|
||||||
$this->Task->execute();
|
|
||||||
|
|
||||||
$this->Task->args = array('articles');
|
|
||||||
$this->Task->expectAt(2, 'createFile', array($filename, new PatternExpectation('/class Article extends AppModel/')));
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -760,8 +817,11 @@ STRINGEND;
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
$this->Task->args = array('article');
|
$this->Task->args = array('article');
|
||||||
$filename = '/my/path/article.php';
|
$filename = '/my/path/article.php';
|
||||||
$this->Task->setReturnValue('_checkUnitTest', 1);
|
|
||||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation("/'Comment' \=\> array\(/")));
|
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(1));
|
||||||
|
$this->Task->expects($this->at(0))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch("/'Comment' \=\> array\(/"));
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -774,25 +834,30 @@ STRINGEND;
|
||||||
$this->Task->connection = 'test_suite';
|
$this->Task->connection = 'test_suite';
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
$this->Task->args = array('all');
|
$this->Task->args = array('all');
|
||||||
$this->Task->setReturnValue('_checkUnitTest', true);
|
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
|
||||||
|
|
||||||
$this->Task->Fixture->expectCallCount('bake', 5);
|
$this->Task->Fixture->expects($this->exactly(5))->method('bake');
|
||||||
$this->Task->Test->expectCallCount('bake', 5);
|
$this->Task->Test->expects($this->exactly(5))->method('bake');
|
||||||
|
|
||||||
$filename = '/my/path/article.php';
|
$filename = '/my/path/article.php';
|
||||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article/')));
|
$this->Task->expects($this->at(1))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class Article/'));
|
||||||
|
|
||||||
$filename = '/my/path/articles_tag.php';
|
$filename = '/my/path/articles_tag.php';
|
||||||
$this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/class ArticlesTag/')));
|
$this->Task->expects($this->at(2))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class ArticlesTag/'));
|
||||||
|
|
||||||
$filename = '/my/path/category_thread.php';
|
$filename = '/my/path/category_thread.php';
|
||||||
$this->Task->expectAt(2, 'createFile', array($filename, new PatternExpectation('/class CategoryThread/')));
|
$this->Task->expects($this->at(3))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class CategoryThread/'));
|
||||||
|
|
||||||
$filename = '/my/path/comment.php';
|
$filename = '/my/path/comment.php';
|
||||||
$this->Task->expectAt(3, 'createFile', array($filename, new PatternExpectation('/class Comment/')));
|
$this->Task->expects($this->at(4))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class Comment/'));
|
||||||
|
|
||||||
$filename = '/my/path/tag.php';
|
$filename = '/my/path/tag.php';
|
||||||
$this->Task->expectAt(4, 'createFile', array($filename, new PatternExpectation('/class Tag/')));
|
$this->Task->expects($this->at(5))
|
||||||
|
->method('createFile')->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class Tag/'));
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
|
|
||||||
|
@ -809,23 +874,27 @@ STRINGEND;
|
||||||
$this->Task->connection = 'test_suite';
|
$this->Task->connection = 'test_suite';
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
$this->Task->args = array('all');
|
$this->Task->args = array('all');
|
||||||
$this->Task->setReturnValue('_checkUnitTest', true);
|
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
|
||||||
$this->Task->skipTables = array('tags');
|
$this->Task->skipTables = array('tags');
|
||||||
|
|
||||||
$this->Task->Fixture->expectCallCount('bake', 4);
|
$this->Task->Fixture->expects($this->exactly(4))->method('bake');
|
||||||
$this->Task->Test->expectCallCount('bake', 4);
|
$this->Task->Test->expects($this->exactly(4))->method('bake');
|
||||||
|
|
||||||
$filename = '/my/path/article.php';
|
$filename = '/my/path/article.php';
|
||||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article/')));
|
$this->Task->expects($this->at(1))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class Article/'));
|
||||||
|
|
||||||
$filename = '/my/path/articles_tag.php';
|
$filename = '/my/path/articles_tag.php';
|
||||||
$this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/class ArticlesTag/')));
|
$this->Task->expects($this->at(2))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class ArticlesTag/'));
|
||||||
|
|
||||||
$filename = '/my/path/category_thread.php';
|
$filename = '/my/path/category_thread.php';
|
||||||
$this->Task->expectAt(2, 'createFile', array($filename, new PatternExpectation('/class CategoryThread/')));
|
$this->Task->expects($this->at(3))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class CategoryThread/'));
|
||||||
|
|
||||||
$filename = '/my/path/comment.php';
|
$filename = '/my/path/comment.php';
|
||||||
$this->Task->expectAt(3, 'createFile', array($filename, new PatternExpectation('/class Comment/')));
|
$this->Task->expects($this->at(4))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class Comment/'));
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
@ -840,22 +909,27 @@ STRINGEND;
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(0, 'in', '1'); //choose article
|
$this->Task->expects($this->any())->method('in')
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'n'); //no validation
|
->will($this->onConsecutiveCalls(
|
||||||
$this->Task->setReturnValueAt(2, 'in', 'y'); //yes to associations
|
'1', // article
|
||||||
$this->Task->setReturnValueAt(3, 'in', 'y'); //yes to comment relation
|
'n', // no validation
|
||||||
$this->Task->setReturnValueAt(4, 'in', 'y'); //yes to user relation
|
'y', // associations
|
||||||
$this->Task->setReturnValueAt(5, 'in', 'y'); //yes to tag relation
|
'y', // comment relation
|
||||||
$this->Task->setReturnValueAt(6, 'in', 'n'); //no to additional assocs
|
'y', // user relation
|
||||||
$this->Task->setReturnValueAt(7, 'in', 'y'); //yes to looksGood?
|
'y', // tag relation
|
||||||
$this->Task->setReturnValue('_checkUnitTest', true);
|
'n', // additional assocs
|
||||||
|
'y' // looks good?
|
||||||
|
));
|
||||||
|
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
|
||||||
|
|
||||||
$this->Task->Test->expectOnce('bake');
|
$this->Task->Test->expects($this->once())->method('bake');
|
||||||
$this->Task->Fixture->expectOnce('bake');
|
$this->Task->Fixture->expects($this->once())->method('bake');
|
||||||
|
|
||||||
$filename = '/my/path/article.php';
|
$filename = '/my/path/article.php';
|
||||||
$this->Task->expectOnce('createFile');
|
|
||||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article/')));
|
$this->Task->expects($this->once())->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class Article/'));
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
|
|
||||||
$this->assertEqual(count(ClassRegistry::keys()), 0);
|
$this->assertEqual(count(ClassRegistry::keys()), 0);
|
||||||
|
@ -871,11 +945,11 @@ STRINGEND;
|
||||||
$this->Task->connection = 'test_suite';
|
$this->Task->connection = 'test_suite';
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
|
|
||||||
$this->Task->expectOnce('_stop');
|
$this->Task->expects($this->once())->method('_stop');
|
||||||
$this->Task->expectOnce('err');
|
$this->Task->expects($this->once())->method('err');
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'Foobar');
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('Foobar'));
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y'));
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
App::import('Shell', 'Shell', false);
|
App::import('Shell', 'Shell', false);
|
||||||
|
App::import('Core', array('File'));
|
||||||
|
|
||||||
if (!defined('DISABLE_AUTO_DISPATCH')) {
|
if (!defined('DISABLE_AUTO_DISPATCH')) {
|
||||||
define('DISABLE_AUTO_DISPATCH', true);
|
define('DISABLE_AUTO_DISPATCH', true);
|
||||||
|
@ -35,17 +36,6 @@ if (!class_exists('ShellDispatcher')) {
|
||||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'plugin.php';
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'plugin.php';
|
||||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php';
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php';
|
||||||
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ShellDispatcher', 'TestPluginTaskMockShellDispatcher',
|
|
||||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
|
||||||
);
|
|
||||||
Mock::generatePartial(
|
|
||||||
'PluginTask', 'MockPluginTask',
|
|
||||||
array('in', '_stop', 'err', 'out', 'createFile')
|
|
||||||
);
|
|
||||||
|
|
||||||
Mock::generate('ModelTask', 'PluginTestMockModelTask');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PluginTaskPlugin class
|
* PluginTaskPlugin class
|
||||||
*
|
*
|
||||||
|
@ -54,16 +44,23 @@ Mock::generate('ModelTask', 'PluginTestMockModelTask');
|
||||||
*/
|
*/
|
||||||
class PluginTaskTest extends CakeTestCase {
|
class PluginTaskTest extends CakeTestCase {
|
||||||
|
|
||||||
|
public static $_paths = array();
|
||||||
|
|
||||||
|
public static $_testPath = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* startTest method
|
* startTest method
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function startTest() {
|
public function startTest() {
|
||||||
$this->Dispatcher =& new TestPluginTaskMockShellDispatcher();
|
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
|
||||||
$this->Dispatcher->shellPaths = App::path('shells');
|
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment'
|
||||||
$this->Task =& new MockPluginTask($this->Dispatcher);
|
));
|
||||||
$this->Task->Dispatch =& $this->Dispatcher;
|
$this->Task = $this->getMock('PluginTask',
|
||||||
|
array('in', 'err', 'createFile', '_stop'),
|
||||||
|
array(&$this->Dispatcher)
|
||||||
|
);
|
||||||
$this->Task->path = TMP . 'tests' . DS;
|
$this->Task->path = TMP . 'tests' . DS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,9 +69,9 @@ class PluginTaskTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function startCase() {
|
public static function setUpBeforeClass() {
|
||||||
$this->_paths = $paths = App::path('plugins');
|
self::$_paths = $paths = App::path('plugins');
|
||||||
$this->_testPath = array_push($paths, TMP . 'tests' . DS);
|
self::$_testPath = array_push($paths, TMP . 'tests' . DS);
|
||||||
App::build(array('plugins' => $paths));
|
App::build(array('plugins' => $paths));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,8 +80,8 @@ class PluginTaskTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function endCase() {
|
public static function tearDownAfterClass() {
|
||||||
App::build(array('plugins' => $this->_paths));
|
App::build(array('plugins' => self::$_paths));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,8 +99,19 @@ class PluginTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testBakeFoldersAndFiles() {
|
public function testBakeFoldersAndFiles() {
|
||||||
$this->Task->setReturnValueAt(0, 'in', $this->_testPath);
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue(self::$_testPath));
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y'));
|
||||||
|
|
||||||
|
$path = $this->Task->path . 'bake_test_plugin';
|
||||||
|
|
||||||
|
$file = $path . DS . 'bake_test_plugin_app_controller.php';
|
||||||
|
$this->Task->expects($this->at(3))->method('createFile')
|
||||||
|
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
|
||||||
|
|
||||||
|
$file = $path . DS . 'bake_test_plugin_app_model.php';
|
||||||
|
$this->Task->expects($this->at(4))->method('createFile')
|
||||||
|
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
|
||||||
|
|
||||||
$this->Task->bake('BakeTestPlugin');
|
$this->Task->bake('BakeTestPlugin');
|
||||||
|
|
||||||
$path = $this->Task->path . 'bake_test_plugin';
|
$path = $this->Task->path . 'bake_test_plugin';
|
||||||
|
@ -173,13 +181,7 @@ class PluginTaskTest extends CakeTestCase {
|
||||||
$this->assertTrue(is_dir($path . DS . 'libs'), 'No libs dir %s');
|
$this->assertTrue(is_dir($path . DS . 'libs'), 'No libs dir %s');
|
||||||
$this->assertTrue(is_dir($path . DS . 'webroot'), 'No webroot dir %s');
|
$this->assertTrue(is_dir($path . DS . 'webroot'), 'No webroot dir %s');
|
||||||
|
|
||||||
$file = $path . DS . 'bake_test_plugin_app_controller.php';
|
$Folder = new Folder($this->Task->path . 'bake_test_plugin');
|
||||||
$this->Task->expectAt(0, 'createFile', array($file, '*'), 'No AppController %s');
|
|
||||||
|
|
||||||
$file = $path . DS . 'bake_test_plugin_app_model.php';
|
|
||||||
$this->Task->expectAt(1, 'createFile', array($file, '*'), 'No AppModel %s');
|
|
||||||
|
|
||||||
$Folder =& new Folder($this->Task->path . 'bake_test_plugin');
|
|
||||||
$Folder->delete();
|
$Folder->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,22 +191,24 @@ class PluginTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testExecuteWithNoArgs() {
|
public function testExecuteWithNoArgs() {
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'TestPlugin');
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestPlugin'));
|
||||||
$this->Task->setReturnValueAt(1, 'in', '3');
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('3'));
|
||||||
$this->Task->setReturnValueAt(2, 'in', 'y');
|
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('y'));
|
||||||
$this->Task->setReturnValueAt(3, 'in', 'n');
|
$this->Task->expects($this->at(3))->method('in')->will($this->returnValue('n'));
|
||||||
|
|
||||||
$path = $this->Task->path . 'test_plugin';
|
$path = $this->Task->path . 'test_plugin';
|
||||||
$file = $path . DS . 'test_plugin_app_controller.php';
|
$file = $path . DS . 'test_plugin_app_controller.php';
|
||||||
$this->Task->expectAt(0, 'createFile', array($file, '*'), 'No AppController %s');
|
$this->Task->expects($this->at(4))->method('createFile')
|
||||||
|
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
|
||||||
|
|
||||||
$file = $path . DS . 'test_plugin_app_model.php';
|
$file = $path . DS . 'test_plugin_app_model.php';
|
||||||
$this->Task->expectAt(1, 'createFile', array($file, '*'), 'No AppModel %s');
|
$this->Task->expects($this->at(5))->method('createFile')
|
||||||
|
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
|
||||||
|
|
||||||
$this->Task->args = array();
|
$this->Task->args = array();
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
|
|
||||||
$Folder =& new Folder($path);
|
$Folder = new Folder($path);
|
||||||
$Folder->delete();
|
$Folder->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,21 +218,27 @@ class PluginTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testExecuteWithOneArg() {
|
public function testExecuteWithOneArg() {
|
||||||
$this->Task->setReturnValueAt(0, 'in', $this->_testPath);
|
$this->Task->expects($this->at(0))->method('in')
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
->will($this->returnValue(self::$_testPath));
|
||||||
$this->Task->Dispatch->args = array('BakeTestPlugin');
|
$this->Task->expects($this->at(1))->method('in')
|
||||||
$this->Task->args =& $this->Task->Dispatch->args;
|
->will($this->returnValue('y'));
|
||||||
|
|
||||||
$path = $this->Task->path . 'bake_test_plugin';
|
$path = $this->Task->path . 'bake_test_plugin';
|
||||||
$file = $path . DS . 'bake_test_plugin_app_controller.php';
|
$file = $path . DS . 'bake_test_plugin_app_controller.php';
|
||||||
$this->Task->expectAt(0, 'createFile', array($file, '*'), 'No AppController %s');
|
$this->Task->expects($this->at(3))->method('createFile')
|
||||||
|
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
|
||||||
|
|
||||||
|
$path = $this->Task->path . 'bake_test_plugin';
|
||||||
$file = $path . DS . 'bake_test_plugin_app_model.php';
|
$file = $path . DS . 'bake_test_plugin_app_model.php';
|
||||||
$this->Task->expectAt(1, 'createFile', array($file, '*'), 'No AppModel %s');
|
$this->Task->expects($this->at(4))->method('createFile')
|
||||||
|
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
|
||||||
|
|
||||||
|
$this->Task->Dispatch->args = array('BakeTestPlugin');
|
||||||
|
$this->Task->args =& $this->Task->Dispatch->args;
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
|
|
||||||
$Folder =& new Folder($this->Task->path . 'bake_test_plugin');
|
$Folder = new Folder($this->Task->path . 'bake_test_plugin');
|
||||||
$Folder->delete();
|
$Folder->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,17 +248,18 @@ class PluginTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testExecuteWithTwoArgs() {
|
public function testExecuteWithTwoArgs() {
|
||||||
$this->Task->Model =& new PluginTestMockModelTask();
|
$this->Task->Model = $this->getMock('ModelTask', array(), array(&$this->Dispatcher));
|
||||||
$this->Task->setReturnValueAt(0, 'in', $this->_testPath);
|
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
|
||||||
|
|
||||||
$Folder =& new Folder($this->Task->path . 'bake_test_plugin', true);
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue(self::$_testPath));
|
||||||
|
|
||||||
|
$this->Task->Model->expects($this->once())->method('loadTasks');
|
||||||
|
$this->Task->Model->expects($this->once())->method('execute');
|
||||||
|
|
||||||
|
$Folder = new Folder($this->Task->path . 'bake_test_plugin', true);
|
||||||
|
|
||||||
$this->Task->Dispatch->args = array('BakeTestPlugin', 'model');
|
$this->Task->Dispatch->args = array('BakeTestPlugin', 'model');
|
||||||
$this->Task->args =& $this->Task->Dispatch->args;
|
$this->Task->args = $this->Task->Dispatch->args;
|
||||||
|
|
||||||
$this->Task->Model->expectOnce('loadTasks');
|
|
||||||
$this->Task->Model->expectOnce('execute');
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
$Folder->delete();
|
$Folder->delete();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
App::import('Shell', 'Shell', false);
|
App::import('Shell', 'Shell', false);
|
||||||
|
App::import('Core', 'File');
|
||||||
|
|
||||||
|
|
||||||
if (!defined('DISABLE_AUTO_DISPATCH')) {
|
if (!defined('DISABLE_AUTO_DISPATCH')) {
|
||||||
define('DISABLE_AUTO_DISPATCH', true);
|
define('DISABLE_AUTO_DISPATCH', true);
|
||||||
|
@ -34,15 +36,6 @@ if (!class_exists('ShellDispatcher')) {
|
||||||
|
|
||||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'project.php';
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'project.php';
|
||||||
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ShellDispatcher', 'TestProjectTaskMockShellDispatcher',
|
|
||||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
|
||||||
);
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ProjectTask', 'MockProjectTask',
|
|
||||||
array('in', '_stop', 'err', 'out', 'createFile')
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ProjectTask Test class
|
* ProjectTask Test class
|
||||||
*
|
*
|
||||||
|
@ -57,10 +50,14 @@ class ProjectTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function startTest() {
|
public function startTest() {
|
||||||
$this->Dispatcher =& new TestProjectTaskMockShellDispatcher();
|
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
|
||||||
|
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment'
|
||||||
|
));
|
||||||
|
$this->Task = $this->getMock('ProjectTask',
|
||||||
|
array('in', 'err', 'createFile', '_stop'),
|
||||||
|
array(&$this->Dispatcher)
|
||||||
|
);
|
||||||
$this->Dispatcher->shellPaths = App::path('shells');
|
$this->Dispatcher->shellPaths = App::path('shells');
|
||||||
$this->Task =& new MockProjectTask($this->Dispatcher);
|
|
||||||
$this->Task->Dispatch =& $this->Dispatcher;
|
|
||||||
$this->Task->path = TMP . 'tests' . DS;
|
$this->Task->path = TMP . 'tests' . DS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,8 +69,9 @@ class ProjectTaskTest extends CakeTestCase {
|
||||||
public function endTest() {
|
public function endTest() {
|
||||||
ClassRegistry::flush();
|
ClassRegistry::flush();
|
||||||
|
|
||||||
$Folder =& new Folder($this->Task->path . 'bake_test_app');
|
$Folder = new Folder($this->Task->path . 'bake_test_app');
|
||||||
$Folder->delete();
|
$Folder->delete();
|
||||||
|
unset($this->Dispatcher, $this->Task);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,8 +81,8 @@ class ProjectTaskTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
protected function _setupTestProject() {
|
protected function _setupTestProject() {
|
||||||
$skel = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS . 'templates' . DS . 'skel';
|
$skel = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS . 'templates' . DS . 'skel';
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'y');
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'n');
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('n'));
|
||||||
$this->Task->bake($this->Task->path . 'bake_test_app', $skel);
|
$this->Task->bake($this->Task->path . 'bake_test_app', $skel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,12 +160,12 @@ class ProjectTaskTest extends CakeTestCase {
|
||||||
$result = $this->Task->securitySalt($path);
|
$result = $this->Task->securitySalt($path);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
$file =& new File($path . 'config' . DS . 'core.php');
|
$file = new File($path . 'config' . DS . 'core.php');
|
||||||
$contents = $file->read();
|
$contents = $file->read();
|
||||||
$this->assertNoPattern('/DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi/', $contents, 'Default Salt left behind. %s');
|
$this->assertNoPattern('/DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi/', $contents, 'Default Salt left behind. %s');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test generation of Security.cipherSeed
|
* test generation of Security.cipherSeed
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
@ -179,7 +177,7 @@ class ProjectTaskTest extends CakeTestCase {
|
||||||
$result = $this->Task->securityCipherSeed($path);
|
$result = $this->Task->securityCipherSeed($path);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
$file =& new File($path . 'config' . DS . 'core.php');
|
$file = new File($path . 'config' . DS . 'core.php');
|
||||||
$contents = $file->read();
|
$contents = $file->read();
|
||||||
$this->assertNoPattern('/76859309657453542496749683645/', $contents, 'Default CipherSeed left behind. %s');
|
$this->assertNoPattern('/76859309657453542496749683645/', $contents, 'Default CipherSeed left behind. %s');
|
||||||
}
|
}
|
||||||
|
@ -195,11 +193,11 @@ class ProjectTaskTest extends CakeTestCase {
|
||||||
$path = $this->Task->path . 'bake_test_app' . DS;
|
$path = $this->Task->path . 'bake_test_app' . DS;
|
||||||
$this->Task->corePath($path);
|
$this->Task->corePath($path);
|
||||||
|
|
||||||
$file =& new File($path . 'webroot' . DS . 'index.php');
|
$file = new File($path . 'webroot' . DS . 'index.php');
|
||||||
$contents = $file->read();
|
$contents = $file->read();
|
||||||
$this->assertNoPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', \'ROOT/', $contents);
|
$this->assertNoPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', \'ROOT/', $contents);
|
||||||
|
|
||||||
$file =& new File($path . 'webroot' . DS . 'test.php');
|
$file = new File($path . 'webroot' . DS . 'test.php');
|
||||||
$contents = $file->read();
|
$contents = $file->read();
|
||||||
$this->assertNoPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', \'ROOT/', $contents);
|
$this->assertNoPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', \'ROOT/', $contents);
|
||||||
}
|
}
|
||||||
|
@ -217,12 +215,12 @@ class ProjectTaskTest extends CakeTestCase {
|
||||||
Configure::write('Routing.prefixes', null);
|
Configure::write('Routing.prefixes', null);
|
||||||
$this->_setupTestProject();
|
$this->_setupTestProject();
|
||||||
$this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'config' . DS;
|
$this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'config' . DS;
|
||||||
$this->Task->setReturnValue('in', 'super_duper_admin');
|
$this->Task->expects($this->once())->method('in')->will($this->returnValue('super_duper_admin'));
|
||||||
|
|
||||||
$result = $this->Task->getPrefix();
|
$result = $this->Task->getPrefix();
|
||||||
$this->assertEqual($result, 'super_duper_admin_');
|
$this->assertEqual($result, 'super_duper_admin_');
|
||||||
|
|
||||||
$file =& new File($this->Task->configPath . 'core.php');
|
$file = new File($this->Task->configPath . 'core.php');
|
||||||
$file->delete();
|
$file->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,9 +230,9 @@ class ProjectTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testCakeAdmin() {
|
public function testCakeAdmin() {
|
||||||
$file =& new File(CONFIGS . 'core.php');
|
$file = new File(CONFIGS . 'core.php');
|
||||||
$contents = $file->read();;
|
$contents = $file->read();;
|
||||||
$file =& new File(TMP . 'tests' . DS . 'core.php');
|
$file = new File(TMP . 'tests' . DS . 'core.php');
|
||||||
$file->write($contents);
|
$file->write($contents);
|
||||||
|
|
||||||
Configure::write('Routing.prefixes', null);
|
Configure::write('Routing.prefixes', null);
|
||||||
|
@ -255,7 +253,7 @@ class ProjectTaskTest extends CakeTestCase {
|
||||||
Configure::write('Routing.prefixes', array('admin', 'ninja', 'shinobi'));
|
Configure::write('Routing.prefixes', array('admin', 'ninja', 'shinobi'));
|
||||||
$this->_setupTestProject();
|
$this->_setupTestProject();
|
||||||
$this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'config' . DS;
|
$this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'config' . DS;
|
||||||
$this->Task->setReturnValue('in', 2);
|
$this->Task->expects($this->once())->method('in')->will($this->returnValue(2));
|
||||||
|
|
||||||
$result = $this->Task->getPrefix();
|
$result = $this->Task->getPrefix();
|
||||||
$this->assertEqual($result, 'ninja_');
|
$this->assertEqual($result, 'ninja_');
|
||||||
|
@ -271,8 +269,8 @@ class ProjectTaskTest extends CakeTestCase {
|
||||||
$this->Task->params['working'] = TMP . 'tests' . DS;
|
$this->Task->params['working'] = TMP . 'tests' . DS;
|
||||||
|
|
||||||
$path = $this->Task->path . 'bake_test_app';
|
$path = $this->Task->path . 'bake_test_app';
|
||||||
$this->Task->setReturnValue('in', 'y');
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue($path));
|
||||||
$this->Task->setReturnValueAt(0, 'in', $path);
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y'));
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
$this->assertTrue(is_dir($path), 'No project dir %s');
|
$this->assertTrue(is_dir($path), 'No project dir %s');
|
||||||
|
|
|
@ -35,16 +35,6 @@ if (!class_exists('ShellDispatcher')) {
|
||||||
|
|
||||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
||||||
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ShellDispatcher', 'TestTemplateTaskMockShellDispatcher',
|
|
||||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
|
||||||
);
|
|
||||||
|
|
||||||
Mock::generatePartial(
|
|
||||||
'TemplateTask', 'MockTemplateTask',
|
|
||||||
array('in', 'out', 'err', 'createFile', '_stop')
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TemplateTaskTest class
|
* TemplateTaskTest class
|
||||||
*
|
*
|
||||||
|
@ -59,9 +49,13 @@ class TemplateTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function startTest() {
|
public function startTest() {
|
||||||
$this->Dispatcher =& new TestTemplateTaskMockShellDispatcher();
|
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
|
||||||
$this->Task =& new MockTemplateTask($this->Dispatcher);
|
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment'
|
||||||
$this->Task->Dispatch =& $this->Dispatcher;
|
));
|
||||||
|
$this->Task = $this->getMock('TemplateTask',
|
||||||
|
array('in', 'err', 'createFile', '_stop'),
|
||||||
|
array(&$this->Dispatcher)
|
||||||
|
);
|
||||||
$this->Task->Dispatch->shellPaths = App::path('shells');
|
$this->Task->Dispatch->shellPaths = App::path('shells');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +107,8 @@ class TemplateTaskTest extends CakeTestCase {
|
||||||
public function testGetThemePath() {
|
public function testGetThemePath() {
|
||||||
$defaultTheme = CAKE_CORE_INCLUDE_PATH . DS . dirname(CONSOLE_LIBS) . 'templates' . DS . 'default' .DS;
|
$defaultTheme = CAKE_CORE_INCLUDE_PATH . DS . dirname(CONSOLE_LIBS) . 'templates' . DS . 'default' .DS;
|
||||||
$this->Task->templatePaths = array('default' => $defaultTheme);
|
$this->Task->templatePaths = array('default' => $defaultTheme);
|
||||||
$this->Task->expectCallCount('in', 1);
|
|
||||||
|
$this->Task->expects($this->exactly(1))->method('in')->will($this->returnValue('1'));
|
||||||
|
|
||||||
$result = $this->Task->getThemePath();
|
$result = $this->Task->getThemePath();
|
||||||
$this->assertEqual($result, $defaultTheme);
|
$this->assertEqual($result, $defaultTheme);
|
||||||
|
@ -124,7 +119,6 @@ class TemplateTaskTest extends CakeTestCase {
|
||||||
$this->assertEqual($result, '/some/path');
|
$this->assertEqual($result, '/some/path');
|
||||||
|
|
||||||
$this->Task->params = array();
|
$this->Task->params = array();
|
||||||
$this->Task->setReturnValueAt(0, 'in', '1');
|
|
||||||
$result = $this->Task->getThemePath();
|
$result = $this->Task->getThemePath();
|
||||||
$this->assertEqual($result, $defaultTheme);
|
$this->assertEqual($result, $defaultTheme);
|
||||||
$this->assertEqual($this->Dispatcher->params['theme'], 'default');
|
$this->assertEqual($this->Dispatcher->params['theme'], 'default');
|
||||||
|
@ -142,7 +136,8 @@ class TemplateTaskTest extends CakeTestCase {
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
$this->Task->initialize();
|
$this->Task->initialize();
|
||||||
$this->Task->setReturnValue('in', 1);
|
$this->Task->expects($this->any())->method('in')->will($this->returnValue(1));
|
||||||
|
|
||||||
$result = $this->Task->generate('classes', 'test_object', array('test' => 'foo'));
|
$result = $this->Task->generate('classes', 'test_object', array('test' => 'foo'));
|
||||||
$expected = "I got rendered\nfoo";
|
$expected = "I got rendered\nfoo";
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
|
@ -37,16 +37,6 @@ if (!class_exists('ShellDispatcher')) {
|
||||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'test.php';
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'test.php';
|
||||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
||||||
|
|
||||||
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ShellDispatcher', 'TestTestTaskMockShellDispatcher',
|
|
||||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
|
||||||
);
|
|
||||||
Mock::generatePartial(
|
|
||||||
'TestTask', 'MockTestTask',
|
|
||||||
array('in', '_stop', 'err', 'out', 'createFile', 'isLoadableClass')
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test Article model
|
* Test Article model
|
||||||
*
|
*
|
||||||
|
@ -258,11 +248,15 @@ class TestTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function startTest() {
|
public function startTest() {
|
||||||
$this->Dispatcher =& new TestTestTaskMockShellDispatcher();
|
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
|
||||||
|
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment'
|
||||||
|
));
|
||||||
|
$this->Task = $this->getMock('TestTask',
|
||||||
|
array('in', 'err', 'createFile', '_stop', 'isLoadableClass'),
|
||||||
|
array(&$this->Dispatcher)
|
||||||
|
);
|
||||||
$this->Dispatcher->shellPaths = App::path('shells');
|
$this->Dispatcher->shellPaths = App::path('shells');
|
||||||
$this->Task =& new MockTestTask($this->Dispatcher);
|
|
||||||
$this->Task->name = 'TestTask';
|
$this->Task->name = 'TestTask';
|
||||||
$this->Task->Dispatch =& $this->Dispatcher;
|
|
||||||
$this->Task->Template =& new TemplateTask($this->Dispatcher);
|
$this->Task->Template =& new TemplateTask($this->Dispatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,21 +274,24 @@ class TestTaskTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testFilePathGeneration() {
|
public function testFilePathGenerationModelRepeated() {
|
||||||
|
$this->Task->Dispatch->expects($this->never())->method('stderr');
|
||||||
|
$this->Task->Dispatch->expects($this->never())->method('_stop');
|
||||||
|
|
||||||
$file = TESTS . 'cases' . DS . 'models' . DS . 'my_class.test.php';
|
$file = TESTS . 'cases' . DS . 'models' . DS . 'my_class.test.php';
|
||||||
|
|
||||||
$this->Task->Dispatch->expectNever('stderr');
|
$this->Task->expects($this->at(1))->method('createFile')
|
||||||
$this->Task->Dispatch->expectNever('_stop');
|
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
|
||||||
|
|
||||||
$this->Task->setReturnValue('in', 'y');
|
$this->Task->expects($this->at(3))->method('createFile')
|
||||||
$this->Task->expectAt(0, 'createFile', array($file, '*'));
|
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
|
||||||
$this->Task->bake('Model', 'MyClass');
|
|
||||||
|
|
||||||
$this->Task->expectAt(1, 'createFile', array($file, '*'));
|
|
||||||
$this->Task->bake('Model', 'MyClass');
|
|
||||||
|
|
||||||
$file = TESTS . 'cases' . DS . 'controllers' . DS . 'comments_controller.test.php';
|
$file = TESTS . 'cases' . DS . 'controllers' . DS . 'comments_controller.test.php';
|
||||||
$this->Task->expectAt(2, 'createFile', array($file, '*'));
|
$this->Task->expects($this->at(5))->method('createFile')
|
||||||
|
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
|
||||||
|
|
||||||
|
$this->Task->bake('Model', 'MyClass');
|
||||||
|
$this->Task->bake('Model', 'MyClass');
|
||||||
$this->Task->bake('Controller', 'Comments');
|
$this->Task->bake('Controller', 'Comments');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,11 +341,12 @@ class TestTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testGetObjectType() {
|
public function testGetObjectType() {
|
||||||
$this->Task->expectOnce('_stop');
|
$this->Task->expects($this->once())->method('_stop');
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'q');
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('q'));
|
||||||
|
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue(2));
|
||||||
|
|
||||||
$this->Task->getObjectType();
|
$this->Task->getObjectType();
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(1, 'in', 2);
|
|
||||||
$result = $this->Task->getObjectType();
|
$result = $this->Task->getObjectType();
|
||||||
$this->assertEqual($result, $this->Task->classTypes[1]);
|
$this->assertEqual($result, $this->Task->classTypes[1]);
|
||||||
}
|
}
|
||||||
|
@ -388,11 +386,12 @@ class TestTaskTest extends CakeTestCase {
|
||||||
if ($skip) {
|
if ($skip) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'MyCustomClass');
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('MyCustomClass'));
|
||||||
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(1));
|
||||||
|
|
||||||
$result = $this->Task->getClassName('Model');
|
$result = $this->Task->getClassName('Model');
|
||||||
$this->assertEqual($result, 'MyCustomClass');
|
$this->assertEqual($result, 'MyCustomClass');
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(1, 'in', 1);
|
|
||||||
$result = $this->Task->getClassName('Model');
|
$result = $this->Task->getClassName('Model');
|
||||||
$options = App::objects('model');
|
$options = App::objects('model');
|
||||||
$this->assertEqual($result, $options[0]);
|
$this->assertEqual($result, $options[0]);
|
||||||
|
@ -404,8 +403,10 @@ class TestTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testGetUserFixtures() {
|
public function testGetUserFixtures() {
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'y');
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'app.pizza, app.topping, app.side_dish');
|
$this->Task->expects($this->at(1))->method('in')
|
||||||
|
->will($this->returnValue('app.pizza, app.topping, app.side_dish'));
|
||||||
|
|
||||||
$result = $this->Task->getUserFixtures();
|
$result = $this->Task->getUserFixtures();
|
||||||
$expected = array('app.pizza', 'app.topping', 'app.side_dish');
|
$expected = array('app.pizza', 'app.topping', 'app.side_dish');
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
@ -440,8 +441,8 @@ class TestTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testBakeModelTest() {
|
public function testBakeModelTest() {
|
||||||
$this->Task->setReturnValue('createFile', true);
|
$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
|
||||||
$this->Task->setReturnValue('isLoadableClass', true);
|
$this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
|
||||||
|
|
||||||
$result = $this->Task->bake('Model', 'TestTaskArticle');
|
$result = $this->Task->bake('Model', 'TestTaskArticle');
|
||||||
|
|
||||||
|
@ -458,9 +459,7 @@ class TestTaskTest extends CakeTestCase {
|
||||||
$this->assertPattern('/function testDoSomethingElse\(\)/i', $result);
|
$this->assertPattern('/function testDoSomethingElse\(\)/i', $result);
|
||||||
|
|
||||||
$this->assertPattern("/'app\.test_task_article'/", $result);
|
$this->assertPattern("/'app\.test_task_article'/", $result);
|
||||||
if (PHP5) {
|
|
||||||
$this->assertPattern("/'plugin\.test_task\.test_task_comment'/", $result);
|
$this->assertPattern("/'plugin\.test_task\.test_task_comment'/", $result);
|
||||||
}
|
|
||||||
$this->assertPattern("/'app\.test_task_tag'/", $result);
|
$this->assertPattern("/'app\.test_task_tag'/", $result);
|
||||||
$this->assertPattern("/'app\.articles_tag'/", $result);
|
$this->assertPattern("/'app\.articles_tag'/", $result);
|
||||||
}
|
}
|
||||||
|
@ -473,8 +472,8 @@ class TestTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testBakeControllerTest() {
|
public function testBakeControllerTest() {
|
||||||
$this->Task->setReturnValue('createFile', true);
|
$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
|
||||||
$this->Task->setReturnValue('isLoadableClass', true);
|
$this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
|
||||||
|
|
||||||
$result = $this->Task->bake('Controller', 'TestTaskComments');
|
$result = $this->Task->bake('Controller', 'TestTaskComments');
|
||||||
|
|
||||||
|
@ -493,9 +492,7 @@ class TestTaskTest extends CakeTestCase {
|
||||||
$this->assertPattern('/unset\(\$this->TestTaskComments\)/', $result);
|
$this->assertPattern('/unset\(\$this->TestTaskComments\)/', $result);
|
||||||
|
|
||||||
$this->assertPattern("/'app\.test_task_article'/", $result);
|
$this->assertPattern("/'app\.test_task_article'/", $result);
|
||||||
if (PHP5) {
|
|
||||||
$this->assertPattern("/'plugin\.test_task\.test_task_comment'/", $result);
|
$this->assertPattern("/'plugin\.test_task\.test_task_comment'/", $result);
|
||||||
}
|
|
||||||
$this->assertPattern("/'app\.test_task_tag'/", $result);
|
$this->assertPattern("/'app\.test_task_tag'/", $result);
|
||||||
$this->assertPattern("/'app\.articles_tag'/", $result);
|
$this->assertPattern("/'app\.articles_tag'/", $result);
|
||||||
}
|
}
|
||||||
|
@ -538,7 +535,9 @@ class TestTaskTest extends CakeTestCase {
|
||||||
$this->Task->plugin = 'TestTest';
|
$this->Task->plugin = 'TestTest';
|
||||||
|
|
||||||
$path = APP . 'plugins' . DS . 'test_test' . DS . 'tests' . DS . 'cases' . DS . 'helpers' . DS . 'form.test.php';
|
$path = APP . 'plugins' . DS . 'test_test' . DS . 'tests' . DS . 'cases' . DS . 'helpers' . DS . 'form.test.php';
|
||||||
$this->Task->expectAt(0, 'createFile', array($path, '*'));
|
$this->Task->expects($this->once())->method('createFile')
|
||||||
|
->with($path, new PHPUnit_Framework_Constraint_IsAnything());
|
||||||
|
|
||||||
$this->Task->bake('Helper', 'Form');
|
$this->Task->bake('Helper', 'Form');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -583,9 +582,13 @@ class TestTaskTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testExecuteWithOneArg() {
|
public function testExecuteWithOneArg() {
|
||||||
$this->Task->args[0] = 'Model';
|
$this->Task->args[0] = 'Model';
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'TestTaskTag');
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
|
||||||
$this->Task->setReturnValue('isLoadableClass', true);
|
$this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
|
||||||
$this->Task->expectAt(0, 'createFile', array('*', new PatternExpectation('/class TestTaskTagTestCase extends CakeTestCase/')));
|
$this->Task->expects($this->once())->method('createFile')
|
||||||
|
->with(
|
||||||
|
new PHPUnit_Framework_Constraint_IsAnything(),
|
||||||
|
new PHPUnit_Framework_Constraint_PCREMatch('/class TestTaskTagTestCase extends CakeTestCase/')
|
||||||
|
);
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -596,9 +599,13 @@ class TestTaskTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testExecuteWithTwoArgs() {
|
public function testExecuteWithTwoArgs() {
|
||||||
$this->Task->args = array('Model', 'TestTaskTag');
|
$this->Task->args = array('Model', 'TestTaskTag');
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'TestTaskTag');
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
|
||||||
$this->Task->setReturnValue('isLoadableClass', true);
|
$this->Task->expects($this->once())->method('createFile')
|
||||||
$this->Task->expectAt(0, 'createFile', array('*', new PatternExpectation('/class TestTaskTagTestCase extends CakeTestCase/')));
|
->with(
|
||||||
|
new PHPUnit_Framework_Constraint_IsAnything(),
|
||||||
|
new PHPUnit_Framework_Constraint_PCREMatch('/class TestTaskTagTestCase extends CakeTestCase/')
|
||||||
|
);
|
||||||
|
$this->Task->expects($this->any())->method('isLoadableClass')->will($this->returnValue(true));
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,17 +37,6 @@ require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'controller.p
|
||||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
||||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'project.php';
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'project.php';
|
||||||
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ShellDispatcher', 'TestViewTaskMockShellDispatcher',
|
|
||||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
|
||||||
);
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ViewTask', 'MockViewTask',
|
|
||||||
array('in', '_stop', 'err', 'out', 'createFile')
|
|
||||||
);
|
|
||||||
|
|
||||||
Mock::generate('ControllerTask', 'ViewTaskMockControllerTask');
|
|
||||||
Mock::generate('ProjectTask', 'ViewTaskMockProjectTask');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test View Task Comment Model
|
* Test View Task Comment Model
|
||||||
|
@ -242,14 +231,18 @@ class ViewTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function startTest() {
|
public function startTest() {
|
||||||
$this->Dispatcher =& new TestViewTaskMockShellDispatcher();
|
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
|
||||||
|
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment'
|
||||||
|
));
|
||||||
|
$this->Task = $this->getMock('ViewTask',
|
||||||
|
array('in', 'err', 'createFile', '_stop'),
|
||||||
|
array(&$this->Dispatcher)
|
||||||
|
);
|
||||||
|
$this->Task->Template = new TemplateTask($this->Dispatcher);
|
||||||
|
$this->Task->Controller = $this->getMock('ControllerTask', array(), array(&$this->Dispatcher));
|
||||||
|
$this->Task->Project = $this->getMock('ProjectTask', array(), array(&$this->Dispatcher));
|
||||||
|
|
||||||
$this->Dispatcher->shellPaths = App::path('shells');
|
$this->Dispatcher->shellPaths = App::path('shells');
|
||||||
$this->Task =& new MockViewTask($this->Dispatcher);
|
|
||||||
$this->Task->name = 'ViewTask';
|
|
||||||
$this->Task->Dispatch =& $this->Dispatcher;
|
|
||||||
$this->Task->Template =& new TemplateTask($this->Dispatcher);
|
|
||||||
$this->Task->Controller =& new ViewTaskMockControllerTask();
|
|
||||||
$this->Task->Project =& new ViewTaskMockProjectTask();
|
|
||||||
$this->Task->path = TMP;
|
$this->Task->path = TMP;
|
||||||
$this->Task->Template->params['theme'] = 'default';
|
$this->Task->Template->params['theme'] = 'default';
|
||||||
|
|
||||||
|
@ -340,23 +333,50 @@ class ViewTaskTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testBake() {
|
public function testBakeView() {
|
||||||
$this->Task->controllerName = 'ViewTaskComments';
|
$this->Task->controllerName = 'ViewTaskComments';
|
||||||
$this->Task->controllerPath = 'view_task_comments';
|
$this->Task->controllerPath = 'view_task_comments';
|
||||||
|
|
||||||
$this->Task->expectAt(0, 'createFile', array(
|
$this->Task->expects($this->at(0))->method('createFile')
|
||||||
|
->with(
|
||||||
TMP . 'view_task_comments' . DS . 'view.ctp',
|
TMP . 'view_task_comments' . DS . 'view.ctp',
|
||||||
new PatternExpectation('/View Task Articles/')
|
new PHPUnit_Framework_Constraint_PCREMatch('/View Task Articles/')
|
||||||
));
|
);
|
||||||
|
|
||||||
$this->Task->bake('view', true);
|
$this->Task->bake('view', true);
|
||||||
|
}
|
||||||
|
|
||||||
$this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_comments' . DS . 'edit.ctp', '*'));
|
/**
|
||||||
|
* test baking an edit file
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testBakeEdit() {
|
||||||
|
$this->Task->controllerName = 'ViewTaskComments';
|
||||||
|
$this->Task->controllerPath = 'view_task_comments';
|
||||||
|
|
||||||
|
$this->Task->expects($this->at(0))->method('createFile')
|
||||||
|
->with(
|
||||||
|
TMP . 'view_task_comments' . DS . 'edit.ctp',
|
||||||
|
new PHPUnit_Framework_Constraint_IsAnything()
|
||||||
|
);
|
||||||
$this->Task->bake('edit', true);
|
$this->Task->bake('edit', true);
|
||||||
|
}
|
||||||
|
|
||||||
$this->Task->expectAt(2, 'createFile', array(
|
/**
|
||||||
|
* test baking an index
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testBakeIndex() {
|
||||||
|
$this->Task->controllerName = 'ViewTaskComments';
|
||||||
|
$this->Task->controllerPath = 'view_task_comments';
|
||||||
|
|
||||||
|
$this->Task->expects($this->at(0))->method('createFile')
|
||||||
|
->with(
|
||||||
TMP . 'view_task_comments' . DS . 'index.ctp',
|
TMP . 'view_task_comments' . DS . 'index.ctp',
|
||||||
new PatternExpectation('/\$viewTaskComment\[\'Article\'\]\[\'title\'\]/')
|
new PHPUnit_Framework_Constraint_PCREMatch('/\$viewTaskComment\[\'Article\'\]\[\'title\'\]/')
|
||||||
));
|
);
|
||||||
$this->Task->bake('index', true);
|
$this->Task->bake('index', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,9 +389,12 @@ class ViewTaskTest extends CakeTestCase {
|
||||||
$this->Task->controllerName = 'ViewTaskComments';
|
$this->Task->controllerName = 'ViewTaskComments';
|
||||||
$this->Task->controllerPath = 'view_task_comments';
|
$this->Task->controllerPath = 'view_task_comments';
|
||||||
$this->Task->plugin = 'TestTest';
|
$this->Task->plugin = 'TestTest';
|
||||||
|
$this->Task->name = 'ViewTask';
|
||||||
|
|
||||||
$path = APP . 'plugins' . DS . 'test_test' . DS . 'views' . DS . 'view_task_comments' . DS . 'view.ctp';
|
$path = APP . 'plugins' . DS . 'test_test' . DS . 'views' . DS . 'view_task_comments' . DS . 'view.ctp';
|
||||||
$this->Task->expectAt(0, 'createFile', array($path, '*'));
|
$this->Task->expects($this->once())->method('createFile')
|
||||||
|
->with($path, new PHPUnit_Framework_Constraint_IsAnything());
|
||||||
|
|
||||||
$this->Task->bake('view', true);
|
$this->Task->bake('view', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,18 +407,21 @@ class ViewTaskTest extends CakeTestCase {
|
||||||
$this->Task->controllerName = 'ViewTaskComments';
|
$this->Task->controllerName = 'ViewTaskComments';
|
||||||
$this->Task->controllerPath = 'view_task_comments';
|
$this->Task->controllerPath = 'view_task_comments';
|
||||||
|
|
||||||
$this->Task->expectAt(0, 'createFile', array(
|
$this->Task->expects($this->at(0))->method('createFile')
|
||||||
|
->with(
|
||||||
TMP . 'view_task_comments' . DS . 'view.ctp',
|
TMP . 'view_task_comments' . DS . 'view.ctp',
|
||||||
new PatternExpectation('/View Task Comments/')
|
new PHPUnit_Framework_Constraint_PCREMatch('/View Task Comments/')
|
||||||
));
|
);
|
||||||
$this->Task->expectAt(1, 'createFile', array(
|
$this->Task->expects($this->at(1))->method('createFile')
|
||||||
|
->with(
|
||||||
TMP . 'view_task_comments' . DS . 'edit.ctp',
|
TMP . 'view_task_comments' . DS . 'edit.ctp',
|
||||||
new PatternExpectation('/Edit View Task Comment/')
|
new PHPUnit_Framework_Constraint_PCREMatch('/Edit View Task Comment/')
|
||||||
));
|
);
|
||||||
$this->Task->expectAt(2, 'createFile', array(
|
$this->Task->expects($this->at(2))->method('createFile')
|
||||||
|
->with(
|
||||||
TMP . 'view_task_comments' . DS . 'index.ctp',
|
TMP . 'view_task_comments' . DS . 'index.ctp',
|
||||||
new PatternExpectation('/ViewTaskComment/')
|
new PHPUnit_Framework_Constraint_PCREMatch('/ViewTaskComment/')
|
||||||
));
|
);
|
||||||
|
|
||||||
$this->Task->bakeActions(array('view', 'edit', 'index'), array());
|
$this->Task->bakeActions(array('view', 'edit', 'index'), array());
|
||||||
}
|
}
|
||||||
|
@ -410,10 +436,14 @@ class ViewTaskTest extends CakeTestCase {
|
||||||
$this->Task->controllerPath = 'view_task_comments';
|
$this->Task->controllerPath = 'view_task_comments';
|
||||||
$this->Task->params['app'] = APP;
|
$this->Task->params['app'] = APP;
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(0, 'in', '');
|
$this->Task->expects($this->any())->method('in')
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'my_action');
|
->will($this->onConsecutiveCalls('', 'my_action', 'y'));
|
||||||
$this->Task->setReturnValueAt(2, 'in', 'y');
|
|
||||||
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'my_action.ctp', '*'));
|
$this->Task->expects($this->once())->method('createFile')
|
||||||
|
->with(
|
||||||
|
TMP . 'view_task_comments' . DS . 'my_action.ctp',
|
||||||
|
new PHPUnit_Framework_Constraint_IsAnything()
|
||||||
|
);
|
||||||
|
|
||||||
$this->Task->customAction();
|
$this->Task->customAction();
|
||||||
}
|
}
|
||||||
|
@ -426,12 +456,20 @@ class ViewTaskTest extends CakeTestCase {
|
||||||
public function testExecuteIntoAll() {
|
public function testExecuteIntoAll() {
|
||||||
$this->Task->args[0] = 'all';
|
$this->Task->args[0] = 'all';
|
||||||
|
|
||||||
$this->Task->Controller->setReturnValue('listAll', array('view_task_comments'));
|
$this->Task->Controller->expects($this->once())->method('listAll')
|
||||||
$this->Task->Controller->expectOnce('listAll');
|
->will($this->returnValue(array('view_task_comments')));
|
||||||
|
|
||||||
$this->Task->expectCallCount('createFile', 2);
|
$this->Task->expects($this->at(0))->method('createFile')
|
||||||
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'index.ctp', '*'));
|
->with(
|
||||||
$this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_comments' . DS . 'add.ctp', '*'));
|
TMP . 'view_task_comments' . DS . 'index.ctp',
|
||||||
|
new PHPUnit_Framework_Constraint_IsAnything()
|
||||||
|
);
|
||||||
|
$this->Task->expects($this->at(1))->method('createFile')
|
||||||
|
->with(
|
||||||
|
TMP . 'view_task_comments' . DS . 'add.ctp',
|
||||||
|
new PHPUnit_Framework_Constraint_IsAnything()
|
||||||
|
);
|
||||||
|
$this->Task->expects($this->exactly(2))->method('createFile');
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
@ -444,11 +482,14 @@ class ViewTaskTest extends CakeTestCase {
|
||||||
public function testExecuteIntoAllWithActionName() {
|
public function testExecuteIntoAllWithActionName() {
|
||||||
$this->Task->args = array('all', 'index');
|
$this->Task->args = array('all', 'index');
|
||||||
|
|
||||||
$this->Task->Controller->setReturnValue('listAll', array('view_task_comments'));
|
$this->Task->Controller->expects($this->once())->method('listAll')
|
||||||
$this->Task->Controller->expectOnce('listAll');
|
->will($this->returnValue(array('view_task_comments')));
|
||||||
|
|
||||||
$this->Task->expectCallCount('createFile', 1);
|
$this->Task->expects($this->once())->method('createFile')
|
||||||
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'index.ctp', '*'));
|
->with(
|
||||||
|
TMP . 'view_task_comments' . DS . 'index.ctp',
|
||||||
|
new PHPUnit_Framework_Constraint_IsAnything()
|
||||||
|
);
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
@ -462,8 +503,11 @@ class ViewTaskTest extends CakeTestCase {
|
||||||
$this->Task->args[0] = 'ViewTaskComments';
|
$this->Task->args[0] = 'ViewTaskComments';
|
||||||
$this->Task->args[1] = 'view';
|
$this->Task->args[1] = 'view';
|
||||||
|
|
||||||
$this->Task->expectCallCount('createFile', 1);
|
$this->Task->expects($this->once())->method('createFile')
|
||||||
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'view.ctp', '*'));
|
->with(
|
||||||
|
TMP . 'view_task_comments' . DS . 'view.ctp',
|
||||||
|
new PHPUnit_Framework_Constraint_IsAnything()
|
||||||
|
);
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -476,29 +520,49 @@ class ViewTaskTest extends CakeTestCase {
|
||||||
public function testExecuteWithController() {
|
public function testExecuteWithController() {
|
||||||
$this->Task->args[0] = 'ViewTaskComments';
|
$this->Task->args[0] = 'ViewTaskComments';
|
||||||
|
|
||||||
$this->Task->expectCallCount('createFile', 2);
|
$this->Task->expects($this->at(0))->method('createFile')
|
||||||
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'index.ctp', '*'));
|
->with(
|
||||||
$this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_comments' . DS . 'add.ctp', '*'));
|
TMP . 'view_task_comments' . DS . 'index.ctp',
|
||||||
|
new PHPUnit_Framework_Constraint_IsAnything()
|
||||||
|
);
|
||||||
|
$this->Task->expects($this->at(1))->method('createFile')
|
||||||
|
->with(
|
||||||
|
TMP . 'view_task_comments' . DS . 'add.ctp',
|
||||||
|
new PHPUnit_Framework_Constraint_IsAnything()
|
||||||
|
);
|
||||||
|
$this->Task->expects($this->exactly(2))->method('createFile');
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test that both plural and singular forms can be used for baking views.
|
* static dataprovider for test cases
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testExecuteWithControllerVariations() {
|
public static function nameVariations() {
|
||||||
$this->Task->args = array('ViewTaskComments');
|
return array(array('ViewTaskComments'), array('ViewTaskComment'), array('view_task_comment'));
|
||||||
|
}
|
||||||
|
|
||||||
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'index.ctp', '*'));
|
/**
|
||||||
$this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_comments' . DS . 'add.ctp', '*'));
|
* test that both plural and singular forms can be used for baking views.
|
||||||
$this->Task->execute();
|
*
|
||||||
|
* @dataProvider nameVariations
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testExecuteWithControllerVariations($name) {
|
||||||
|
$this->Task->args = array($name);
|
||||||
|
|
||||||
$this->Task->args = array('ViewTaskComment');
|
$this->Task->expects($this->at(0))->method('createFile')
|
||||||
|
->with(
|
||||||
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'index.ctp', '*'));
|
TMP . 'view_task_comments' . DS . 'index.ctp',
|
||||||
$this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_comments' . DS . 'add.ctp', '*'));
|
new PHPUnit_Framework_Constraint_IsAnything()
|
||||||
|
);
|
||||||
|
$this->Task->expects($this->at(1))->method('createFile')
|
||||||
|
->with(
|
||||||
|
TMP . 'view_task_comments' . DS . 'add.ctp',
|
||||||
|
new PHPUnit_Framework_Constraint_IsAnything()
|
||||||
|
);
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -513,14 +577,19 @@ class ViewTaskTest extends CakeTestCase {
|
||||||
Configure::write('Routing.prefixes', array('admin'));
|
Configure::write('Routing.prefixes', array('admin'));
|
||||||
$this->Task->args[0] = 'ViewTaskArticles';
|
$this->Task->args[0] = 'ViewTaskArticles';
|
||||||
$this->Task->params['admin'] = 1;
|
$this->Task->params['admin'] = 1;
|
||||||
$this->Task->Project->setReturnValue('getPrefix', 'admin_');
|
|
||||||
|
|
||||||
$this->Task->expectCallCount('createFile', 4);
|
$this->Task->Project->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_'));
|
||||||
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_articles' . DS . 'admin_index.ctp', '*'));
|
|
||||||
$this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_articles' . DS . 'admin_add.ctp', '*'));
|
|
||||||
$this->Task->expectAt(2, 'createFile', array(TMP . 'view_task_articles' . DS . 'admin_view.ctp', '*'));
|
|
||||||
$this->Task->expectAt(3, 'createFile', array(TMP . 'view_task_articles' . DS . 'admin_edit.ctp', '*'));
|
|
||||||
|
|
||||||
|
$this->Task->expects($this->exactly(4))->method('createFile');
|
||||||
|
|
||||||
|
$views = array('admin_index.ctp', 'admin_add.ctp', 'admin_view.ctp', 'admin_edit.ctp');
|
||||||
|
foreach ($views as $i => $view) {
|
||||||
|
$this->Task->expects($this->at($i))->method('createFile')
|
||||||
|
->with(
|
||||||
|
TMP . 'view_task_articles' . DS . $view,
|
||||||
|
new PHPUnit_Framework_Constraint_IsAnything()
|
||||||
|
);
|
||||||
|
}
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
Configure::write('Routing', $_back);
|
Configure::write('Routing', $_back);
|
||||||
}
|
}
|
||||||
|
@ -535,30 +604,38 @@ class ViewTaskTest extends CakeTestCase {
|
||||||
$this->Task->args = array();
|
$this->Task->args = array();
|
||||||
$this->Task->params = array();
|
$this->Task->params = array();
|
||||||
|
|
||||||
$this->Task->Controller->setReturnValue('getName', 'ViewTaskComments');
|
$this->Task->Controller->expects($this->once())->method('getName')
|
||||||
$this->Task->setReturnValue('in', 'y');
|
->will($this->returnValue('ViewTaskComments'));
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'y');
|
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
|
||||||
$this->Task->setReturnValueAt(2, 'in', 'n');
|
|
||||||
|
|
||||||
$this->Task->expectCallCount('createFile', 4);
|
$this->Task->expects($this->any())->method('in')
|
||||||
$this->Task->expectAt(0, 'createFile', array(
|
->will($this->onConsecutiveCalls('y', 'y', 'n'));
|
||||||
|
|
||||||
|
|
||||||
|
$this->Task->expects($this->at(3))->method('createFile')
|
||||||
|
->with(
|
||||||
TMP . 'view_task_comments' . DS . 'index.ctp',
|
TMP . 'view_task_comments' . DS . 'index.ctp',
|
||||||
new PatternExpectation('/ViewTaskComment/')
|
new PHPUnit_Framework_Constraint_PCREMatch('/ViewTaskComment/')
|
||||||
));
|
);
|
||||||
$this->Task->expectAt(1, 'createFile', array(
|
|
||||||
TMP . 'view_task_comments' . DS . 'view.ctp',
|
|
||||||
new PatternExpectation('/ViewTaskComment/')
|
|
||||||
));
|
|
||||||
$this->Task->expectAt(2, 'createFile', array(
|
|
||||||
TMP . 'view_task_comments' . DS . 'add.ctp',
|
|
||||||
new PatternExpectation('/Add View Task Comment/')
|
|
||||||
));
|
|
||||||
$this->Task->expectAt(3, 'createFile', array(
|
|
||||||
TMP . 'view_task_comments' . DS . 'edit.ctp',
|
|
||||||
new PatternExpectation('/Edit View Task Comment/')
|
|
||||||
));
|
|
||||||
|
|
||||||
|
$this->Task->expects($this->at(4))->method('createFile')
|
||||||
|
->with(
|
||||||
|
TMP . 'view_task_comments' . DS . 'view.ctp',
|
||||||
|
new PHPUnit_Framework_Constraint_PCREMatch('/ViewTaskComment/')
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->Task->expects($this->at(5))->method('createFile')
|
||||||
|
->with(
|
||||||
|
TMP . 'view_task_comments' . DS . 'add.ctp',
|
||||||
|
new PHPUnit_Framework_Constraint_PCREMatch('/Add View Task Comment/')
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->Task->expects($this->at(6))->method('createFile')
|
||||||
|
->with(
|
||||||
|
TMP . 'view_task_comments' . DS . 'edit.ctp',
|
||||||
|
new PHPUnit_Framework_Constraint_PCREMatch('/Edit View Task Comment/')
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->Task->expects($this->exactly(4))->method('createFile');
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -572,11 +649,11 @@ class ViewTaskTest extends CakeTestCase {
|
||||||
$this->Task->args = array('ViewTaskComments', 'index', 'list');
|
$this->Task->args = array('ViewTaskComments', 'index', 'list');
|
||||||
$this->Task->params = array();
|
$this->Task->params = array();
|
||||||
|
|
||||||
$this->Task->expectCallCount('createFile', 1);
|
$this->Task->expects($this->once())->method('createFile')
|
||||||
$this->Task->expectAt(0, 'createFile', array(
|
->with(
|
||||||
TMP . 'view_task_comments' . DS . 'list.ctp',
|
TMP . 'view_task_comments' . DS . 'list.ctp',
|
||||||
new PatternExpectation('/ViewTaskComment/')
|
new PHPUnit_Framework_Constraint_PCREMatch('/ViewTaskComment/')
|
||||||
));
|
);
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -590,30 +667,40 @@ class ViewTaskTest extends CakeTestCase {
|
||||||
$this->Task->connection = 'test_suite';
|
$this->Task->connection = 'test_suite';
|
||||||
$this->Task->args = array();
|
$this->Task->args = array();
|
||||||
|
|
||||||
$this->Task->Controller->setReturnValue('getName', 'ViewTaskComments');
|
$this->Task->Controller->expects($this->once())->method('getName')
|
||||||
$this->Task->Project->setReturnValue('getPrefix', 'admin_');
|
->will($this->returnValue('ViewTaskComments'));
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'y');
|
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'n');
|
|
||||||
$this->Task->setReturnValueAt(2, 'in', 'y');
|
|
||||||
|
|
||||||
$this->Task->expectCallCount('createFile', 4);
|
$this->Task->Project->expects($this->once())->method('getPrefix')
|
||||||
$this->Task->expectAt(0, 'createFile', array(
|
->will($this->returnValue('admin_'));
|
||||||
|
|
||||||
|
$this->Task->expects($this->any())->method('in')
|
||||||
|
->will($this->onConsecutiveCalls('y', 'n', 'y'));
|
||||||
|
|
||||||
|
$this->Task->expects($this->at(3))->method('createFile')
|
||||||
|
->with(
|
||||||
TMP . 'view_task_comments' . DS . 'admin_index.ctp',
|
TMP . 'view_task_comments' . DS . 'admin_index.ctp',
|
||||||
new PatternExpectation('/ViewTaskComment/')
|
new PHPUnit_Framework_Constraint_PCREMatch('/ViewTaskComment/')
|
||||||
));
|
);
|
||||||
$this->Task->expectAt(1, 'createFile', array(
|
|
||||||
TMP . 'view_task_comments' . DS . 'admin_view.ctp',
|
|
||||||
new PatternExpectation('/ViewTaskComment/')
|
|
||||||
));
|
|
||||||
$this->Task->expectAt(2, 'createFile', array(
|
|
||||||
TMP . 'view_task_comments' . DS . 'admin_add.ctp',
|
|
||||||
new PatternExpectation('/Add View Task Comment/')
|
|
||||||
));
|
|
||||||
$this->Task->expectAt(3, 'createFile', array(
|
|
||||||
TMP . 'view_task_comments' . DS . 'admin_edit.ctp',
|
|
||||||
new PatternExpectation('/Edit View Task Comment/')
|
|
||||||
));
|
|
||||||
|
|
||||||
|
$this->Task->expects($this->at(4))->method('createFile')
|
||||||
|
->with(
|
||||||
|
TMP . 'view_task_comments' . DS . 'admin_view.ctp',
|
||||||
|
new PHPUnit_Framework_Constraint_PCREMatch('/ViewTaskComment/')
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->Task->expects($this->at(5))->method('createFile')
|
||||||
|
->with(
|
||||||
|
TMP . 'view_task_comments' . DS . 'admin_add.ctp',
|
||||||
|
new PHPUnit_Framework_Constraint_PCREMatch('/Add View Task Comment/')
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->Task->expects($this->at(6))->method('createFile')
|
||||||
|
->with(
|
||||||
|
TMP . 'view_task_comments' . DS . 'admin_edit.ctp',
|
||||||
|
new PHPUnit_Framework_Constraint_PCREMatch('/Edit View Task Comment/')
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->Task->expects($this->exactly(4))->method('createFile');
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,14 +42,11 @@ class TestDispatcher extends Dispatcher {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function _invoke(&$controller, $params) {
|
protected function _invoke(&$controller, $params) {
|
||||||
restore_error_handler();
|
|
||||||
if ($result = parent::_invoke($controller, $params)) {
|
if ($result = parent::_invoke($controller, $params)) {
|
||||||
if ($result[0] === 'missingAction') {
|
if ($result[0] === 'missingAction') {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
set_error_handler('simpleTestErrorHandler');
|
|
||||||
|
|
||||||
return $controller;
|
return $controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -537,7 +534,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function startTest() {
|
public function setUp() {
|
||||||
$this->_get = $_GET;
|
$this->_get = $_GET;
|
||||||
$_GET = array();
|
$_GET = array();
|
||||||
$this->_post = $_POST;
|
$this->_post = $_POST;
|
||||||
|
@ -563,7 +560,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function endTest() {
|
public function tearDown() {
|
||||||
$_GET = $this->_get;
|
$_GET = $this->_get;
|
||||||
$_POST = $this->_post;
|
$_POST = $this->_post;
|
||||||
$_FILES = $this->_files;
|
$_FILES = $this->_files;
|
||||||
|
@ -581,6 +578,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testParseParamsWithoutZerosAndEmptyPost() {
|
public function testParseParamsWithoutZerosAndEmptyPost() {
|
||||||
$Dispatcher = new Dispatcher();
|
$Dispatcher = new Dispatcher();
|
||||||
|
|
||||||
$test = $Dispatcher->parseParams(new CakeRequest("/testcontroller/testaction/params1/params2/params3"));
|
$test = $Dispatcher->parseParams(new CakeRequest("/testcontroller/testaction/params1/params2/params3"));
|
||||||
$this->assertIdentical($test['controller'], 'testcontroller');
|
$this->assertIdentical($test['controller'], 'testcontroller');
|
||||||
$this->assertIdentical($test['action'], 'testaction');
|
$this->assertIdentical($test['action'], 'testaction');
|
||||||
|
@ -600,8 +598,8 @@ class DispatcherTest extends CakeTestCase {
|
||||||
$Dispatcher = new Dispatcher();
|
$Dispatcher = new Dispatcher();
|
||||||
|
|
||||||
$test = $Dispatcher->parseParams(new CakeRequest("/"));
|
$test = $Dispatcher->parseParams(new CakeRequest("/"));
|
||||||
$this->assertTrue(isset($test['form']), "Parsed URL not returning post data");
|
$this->assertFalse(empty($test['form']), "Parsed URL not returning post data");
|
||||||
$this->assertIdentical($test['form']['testdata'], "My Posted Content");
|
$this->assertEquals($test['form']['testdata'], "My Posted Content");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -659,6 +657,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl() {
|
public function testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl() {
|
||||||
$Dispatcher = new Dispatcher();
|
$Dispatcher = new Dispatcher();
|
||||||
|
|
||||||
$request = new CakeRequest("/testcontroller/testaction/01/0403/04010/000002/000030/0000400");
|
$request = new CakeRequest("/testcontroller/testaction/01/0403/04010/000002/000030/0000400");
|
||||||
$test = $Dispatcher->parseParams($request);
|
$test = $Dispatcher->parseParams($request);
|
||||||
$this->assertPattern('/\\A(?:01)\\z/', $test['pass'][0]);
|
$this->assertPattern('/\\A(?:01)\\z/', $test['pass'][0]);
|
||||||
|
@ -690,6 +689,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
|
|
||||||
$Dispatcher = new Dispatcher();
|
$Dispatcher = new Dispatcher();
|
||||||
$uri = new CakeRequest('/?coffee=life&sleep=sissy');
|
$uri = new CakeRequest('/?coffee=life&sleep=sissy');
|
||||||
|
|
||||||
$result = $Dispatcher->parseParams($uri);
|
$result = $Dispatcher->parseParams($uri);
|
||||||
$this->assertPattern('/pages/', $result['controller']);
|
$this->assertPattern('/pages/', $result['controller']);
|
||||||
$this->assertPattern('/display/', $result['action']);
|
$this->assertPattern('/display/', $result['action']);
|
||||||
|
@ -704,7 +704,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testPrivate() {
|
public function testPrivate() {
|
||||||
$Dispatcher =& new TestDispatcher();
|
$Dispatcher = new TestDispatcher();
|
||||||
Configure::write('App.baseUrl','/index.php');
|
Configure::write('App.baseUrl','/index.php');
|
||||||
$url = 'some_pages/_protected/param:value/param2:value2';
|
$url = 'some_pages/_protected/param:value/param2:value2';
|
||||||
|
|
||||||
|
@ -726,7 +726,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testMissingAction() {
|
public function testMissingAction() {
|
||||||
$Dispatcher =& new TestDispatcher();
|
$Dispatcher = new TestDispatcher();
|
||||||
Configure::write('App.baseUrl', '/index.php');
|
Configure::write('App.baseUrl', '/index.php');
|
||||||
$url = 'some_pages/home/param:value/param2:value2';
|
$url = 'some_pages/home/param:value/param2:value2';
|
||||||
|
|
||||||
|
@ -741,7 +741,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
)));
|
)));
|
||||||
$this->assertEqual($expected, $controller);
|
$this->assertEqual($expected, $controller);
|
||||||
|
|
||||||
$Dispatcher =& new TestDispatcher();
|
$Dispatcher = new TestDispatcher();
|
||||||
Configure::write('App.baseUrl','/index.php');
|
Configure::write('App.baseUrl','/index.php');
|
||||||
$url = 'some_pages/redirect/param:value/param2:value2';
|
$url = 'some_pages/redirect/param:value/param2:value2';
|
||||||
|
|
||||||
|
@ -763,6 +763,9 @@ class DispatcherTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testDispatch() {
|
public function testDispatch() {
|
||||||
|
App::build(array(
|
||||||
|
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
|
||||||
|
));
|
||||||
$Dispatcher = new TestDispatcher();
|
$Dispatcher = new TestDispatcher();
|
||||||
Configure::write('App.baseUrl','/index.php');
|
Configure::write('App.baseUrl','/index.php');
|
||||||
$url = 'pages/home/param:value/param2:value2';
|
$url = 'pages/home/param:value/param2:value2';
|
||||||
|
@ -823,6 +826,9 @@ class DispatcherTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testDispatchWithArray() {
|
public function testDispatchWithArray() {
|
||||||
|
App::build(array(
|
||||||
|
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
|
||||||
|
));
|
||||||
Router::reload();
|
Router::reload();
|
||||||
Configure::write('App.baseUrl', '/index.php');
|
Configure::write('App.baseUrl', '/index.php');
|
||||||
$Dispatcher = new TestDispatcher();
|
$Dispatcher = new TestDispatcher();
|
||||||
|
@ -890,7 +896,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'pass' => array('home'),
|
'pass' => array('home'),
|
||||||
'named' => array('param'=> 'value', 'param2'=> 'value2'), 'plugin'=> 'my_plugin',
|
'named' => array('param'=> 'value', 'param2'=> 'value2'), 'plugin'=> 'my_plugin',
|
||||||
'controller'=> 'some_pages', 'action'=> 'display', 'form'=> null,
|
'controller'=> 'some_pages', 'action'=> 'display', 'form'=> array(),
|
||||||
'url'=> array('url'=> 'my_plugin/some_pages/home/param:value/param2:value2'),
|
'url'=> array('url'=> 'my_plugin/some_pages/home/param:value/param2:value2'),
|
||||||
);
|
);
|
||||||
foreach ($expected as $key => $value) {
|
foreach ($expected as $key => $value) {
|
||||||
|
@ -919,7 +925,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
|
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
|
||||||
|
|
||||||
Router::reload();
|
Router::reload();
|
||||||
$Dispatcher =& new TestDispatcher();
|
$Dispatcher = new TestDispatcher();
|
||||||
Router::connect(
|
Router::connect(
|
||||||
'/my_plugin/:controller/:action/*',
|
'/my_plugin/:controller/:action/*',
|
||||||
array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'display')
|
array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'display')
|
||||||
|
@ -1053,7 +1059,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
App::setObjects('plugin', $plugins);
|
App::setObjects('plugin', $plugins);
|
||||||
Router::reload();
|
Router::reload();
|
||||||
|
|
||||||
$Dispatcher =& new TestDispatcher();
|
$Dispatcher = new TestDispatcher();
|
||||||
$Dispatcher->base = false;
|
$Dispatcher->base = false;
|
||||||
|
|
||||||
$url = 'my_plugin/';
|
$url = 'my_plugin/';
|
||||||
|
@ -1081,7 +1087,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
), true);
|
), true);
|
||||||
App::objects('plugin', null, false);
|
App::objects('plugin', null, false);
|
||||||
|
|
||||||
$Dispatcher =& new TestDispatcher();
|
$Dispatcher = new TestDispatcher();
|
||||||
$Dispatcher->base = false;
|
$Dispatcher->base = false;
|
||||||
|
|
||||||
$url = 'test_plugin/';
|
$url = 'test_plugin/';
|
||||||
|
@ -1118,7 +1124,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
|
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
|
||||||
|
|
||||||
Router::reload();
|
Router::reload();
|
||||||
$Dispatcher =& new TestDispatcher();
|
$Dispatcher = new TestDispatcher();
|
||||||
$Dispatcher->base = false;
|
$Dispatcher->base = false;
|
||||||
|
|
||||||
$url = 'my_plugin/not_here/param:value/param2:value2';
|
$url = 'my_plugin/not_here/param:value/param2:value2';
|
||||||
|
@ -1134,7 +1140,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
$this->assertIdentical($expected, $controller);
|
$this->assertIdentical($expected, $controller);
|
||||||
|
|
||||||
Router::reload();
|
Router::reload();
|
||||||
$Dispatcher =& new TestDispatcher();
|
$Dispatcher = new TestDispatcher();
|
||||||
$Dispatcher->base = false;
|
$Dispatcher->base = false;
|
||||||
|
|
||||||
$url = 'my_plugin/param:value/param2:value2';
|
$url = 'my_plugin/param:value/param2:value2';
|
||||||
|
@ -1212,7 +1218,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testChangingParamsFromBeforeFilter() {
|
public function testChangingParamsFromBeforeFilter() {
|
||||||
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
|
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
|
||||||
$Dispatcher =& new TestDispatcher();
|
$Dispatcher = new TestDispatcher();
|
||||||
$url = 'some_posts/index/param:value/param2:value2';
|
$url = 'some_posts/index/param:value/param2:value2';
|
||||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||||
|
|
||||||
|
@ -1261,12 +1267,12 @@ class DispatcherTest extends CakeTestCase {
|
||||||
ob_start();
|
ob_start();
|
||||||
$Dispatcher->dispatch('theme/test_theme/../webroot/css/test_asset.css');
|
$Dispatcher->dispatch('theme/test_theme/../webroot/css/test_asset.css');
|
||||||
$result = ob_get_clean();
|
$result = ob_get_clean();
|
||||||
$this->assertFalse($result);
|
$this->assertEquals($result, '');
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
$Dispatcher->dispatch('theme/test_theme/pdfs');
|
$Dispatcher->dispatch('theme/test_theme/pdfs');
|
||||||
$result = ob_get_clean();
|
$result = ob_get_clean();
|
||||||
$this->assertFalse($result);
|
$this->assertEquals($result, '');
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
$Dispatcher->dispatch('theme/test_theme/flash/theme_test.swf');
|
$Dispatcher->dispatch('theme/test_theme/flash/theme_test.swf');
|
||||||
|
@ -1379,7 +1385,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testMissingAssetProcessor404() {
|
function testMissingAssetProcessor404() {
|
||||||
$Dispatcher =& new TestDispatcher();
|
$Dispatcher = new TestDispatcher();
|
||||||
Configure::write('Asset.filter', array(
|
Configure::write('Asset.filter', array(
|
||||||
'js' => '',
|
'js' => '',
|
||||||
'css' => null
|
'css' => null
|
||||||
|
@ -1400,7 +1406,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testAssetFilterForThemeAndPlugins() {
|
function testAssetFilterForThemeAndPlugins() {
|
||||||
$Dispatcher =& new TestDispatcher();
|
$Dispatcher = new TestDispatcher();
|
||||||
Configure::write('Asset.filter', array(
|
Configure::write('Asset.filter', array(
|
||||||
'js' => '',
|
'js' => '',
|
||||||
'css' => ''
|
'css' => ''
|
||||||
|
@ -1449,7 +1455,6 @@ class DispatcherTest extends CakeTestCase {
|
||||||
), true);
|
), true);
|
||||||
|
|
||||||
$dispatcher = new TestDispatcher();
|
$dispatcher = new TestDispatcher();
|
||||||
|
|
||||||
$url = '/';
|
$url = '/';
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
@ -1584,7 +1589,7 @@ class DispatcherTest extends CakeTestCase {
|
||||||
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
|
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
|
||||||
));
|
));
|
||||||
|
|
||||||
$dispatcher =& new TestDispatcher();
|
$dispatcher = new TestDispatcher();
|
||||||
$dispatcher->base = false;
|
$dispatcher->base = false;
|
||||||
|
|
||||||
$url = 'test_cached_pages/cache_form';
|
$url = 'test_cached_pages/cache_form';
|
||||||
|
|
47
cake/tests/cases/libs/all_behaviors.test.php
Normal file
47
cake/tests/cases/libs/all_behaviors.test.php
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AllBehaviorsTest file
|
||||||
|
*
|
||||||
|
* PHP 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||||
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases
|
||||||
|
* @since CakePHP(tm) v 2.0
|
||||||
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* AllBehaviorsTest class
|
||||||
|
*
|
||||||
|
* This test group will run all test in the cases/libs/models/behaviors directory
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.groups
|
||||||
|
*/
|
||||||
|
class AllBehaviorsTest extends PHPUnit_Framework_TestSuite {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Suite define the tests for this suite
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function suite() {
|
||||||
|
$suite = new PHPUnit_Framework_TestSuite('Model Behavior and all behaviors');
|
||||||
|
|
||||||
|
$path = CORE_TEST_CASES . DS . 'libs' . DS . 'model' . DS . 'behaviors' . DS;
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'model' . DS . 'model_behavior.test.php');
|
||||||
|
|
||||||
|
$suite->addTestFile($path . 'acl.test.php');
|
||||||
|
// $suite->addTestFile($path . 'containable.test.php');
|
||||||
|
$suite->addTestFile($path . 'translate.test.php');
|
||||||
|
$suite->addTestFile($path . 'tree.test.php');
|
||||||
|
return $suite;
|
||||||
|
}
|
||||||
|
}
|
49
cake/tests/cases/libs/all_cache_engines.test.php
Normal file
49
cake/tests/cases/libs/all_cache_engines.test.php
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AllCacheEnginesTest file
|
||||||
|
*
|
||||||
|
* PHP 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||||
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases
|
||||||
|
* @since CakePHP(tm) v 2.0
|
||||||
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AllCacheEnginesTest class
|
||||||
|
*
|
||||||
|
* This test group will run cache engine tests.
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.groups
|
||||||
|
*/
|
||||||
|
class AllCacheEnginesTest extends PHPUnit_Framework_TestSuite {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* suite method, defines tests for this suite.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function suite() {
|
||||||
|
$suite = new PHPUnit_Framework_TestSuite('All Cache related class tests');
|
||||||
|
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'cache.test.php');
|
||||||
|
|
||||||
|
$cacheIterator = new DirectoryIterator(CORE_TEST_CASES . DS . 'libs' . DS . 'cache');
|
||||||
|
foreach ($cacheIterator as $i => $file) {
|
||||||
|
if (!$file->isDot()) {
|
||||||
|
$suite->addTestfile($file->getPathname());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $suite;
|
||||||
|
}
|
||||||
|
}
|
43
cake/tests/cases/libs/all_configure.test.php
Normal file
43
cake/tests/cases/libs/all_configure.test.php
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AllConfigureTest file
|
||||||
|
*
|
||||||
|
* PHP 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||||
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases
|
||||||
|
* @since CakePHP(tm) v 2.0
|
||||||
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AllConfigureTest class
|
||||||
|
*
|
||||||
|
* This test group will run cache engine tests.
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.groups
|
||||||
|
*/
|
||||||
|
class AllConfigureTest extends PHPUnit_Framework_TestSuite {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* suite method, defines tests for this suite.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function suite() {
|
||||||
|
$suite = new PHPUnit_Framework_TestSuite('All Configure, App and ClassRegistry related tests');
|
||||||
|
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'configure.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'class_registry.test.php');
|
||||||
|
return $suite;
|
||||||
|
}
|
||||||
|
}
|
46
cake/tests/cases/libs/all_controllers.test.php
Normal file
46
cake/tests/cases/libs/all_controllers.test.php
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AllControllersTest file
|
||||||
|
*
|
||||||
|
* PHP 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||||
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases
|
||||||
|
* @since CakePHP(tm) v 2.0
|
||||||
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AllControllersTest class
|
||||||
|
*
|
||||||
|
* This test group will run cache engine tests.
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.groups
|
||||||
|
*/
|
||||||
|
class AllControllersTest extends PHPUnit_Framework_TestSuite {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* suite method, defines tests for this suite.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function suite() {
|
||||||
|
$suite = new PHPUnit_Framework_TestSuite('All Controller related class tests');
|
||||||
|
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'controller' . DS . 'controller.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'controller' . DS . 'scaffold.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'controller' . DS . 'pages_controller.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'controller' . DS . 'component.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'controller' . DS . 'controller_merge_vars.test.php');
|
||||||
|
return $suite;
|
||||||
|
}
|
||||||
|
}
|
47
cake/tests/cases/libs/all_database.test.php
Normal file
47
cake/tests/cases/libs/all_database.test.php
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AllDatabaseTest file
|
||||||
|
*
|
||||||
|
* PHP 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||||
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases
|
||||||
|
* @since CakePHP(tm) v 2.0
|
||||||
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AllDatabaseTest class
|
||||||
|
*
|
||||||
|
* This test group will run database tests not in model or behavior group.
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.groups
|
||||||
|
*/
|
||||||
|
class AllDatabaseTest extends PHPUnit_Framework_TestSuite {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* suite method, defines tests for this suite.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function suite() {
|
||||||
|
$suite = new PHPUnit_Framework_TestSuite('Datasources, Schema and DbAcl tests');
|
||||||
|
|
||||||
|
$path = CORE_TEST_CASES . DS . 'libs' . DS . 'model' . DS;
|
||||||
|
|
||||||
|
$tasks = array('db_acl', 'cake_schema', 'connection_manager', 'datasources' . DS . 'dbo_source');
|
||||||
|
foreach ($tasks as $task) {
|
||||||
|
$suite->addTestFile($path . $task . '.test.php');
|
||||||
|
}
|
||||||
|
return $suite;
|
||||||
|
}
|
||||||
|
}
|
54
cake/tests/cases/libs/all_helpers.test.php
Normal file
54
cake/tests/cases/libs/all_helpers.test.php
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* HelpersGroupTest file
|
||||||
|
*
|
||||||
|
* PHP 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||||
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases
|
||||||
|
* @since CakePHP(tm) v 2.0
|
||||||
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HelpersGroupTest class
|
||||||
|
*
|
||||||
|
* This test group will run all test in the cases/libs/view/helpers directory.
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.groups
|
||||||
|
*/
|
||||||
|
class AllHelpersTest extends PHPUnit_Framework_TestSuite {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* suite declares tests to run
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function suite() {
|
||||||
|
$suite = new PHPUnit_Framework_TestSuite('All Helper tests');
|
||||||
|
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'view' . DS . 'helper.test.php');
|
||||||
|
|
||||||
|
$helperIterator = new DirectoryIterator(CORE_TEST_CASES . DS . 'libs' . DS . 'view' . DS . 'helpers' . DS);
|
||||||
|
|
||||||
|
// The following test cases cause segfaults for me.
|
||||||
|
$segfaulty = array('form.test.php', 'cache.test.php', 'session.test.php');
|
||||||
|
|
||||||
|
foreach ($helperIterator as $i => $file) {
|
||||||
|
if (!$file->isDot() && !in_array($file->getFilename(), $segfaulty)) {
|
||||||
|
$suite->addTestfile($file->getPathname());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $suite;
|
||||||
|
}
|
||||||
|
}
|
46
cake/tests/cases/libs/all_js_helpers.test.php
Normal file
46
cake/tests/cases/libs/all_js_helpers.test.php
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AllJavascriptHelpersTest file
|
||||||
|
*
|
||||||
|
* PHP 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||||
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases
|
||||||
|
* @since CakePHP(tm) v 2.0
|
||||||
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* AllJavascriptHelpersTest class
|
||||||
|
*
|
||||||
|
* This test group will run all test in the cases/libs/view/helpers directory related
|
||||||
|
* to Js helper and its engines
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.groups
|
||||||
|
*/
|
||||||
|
class AllJavascriptHelpersTest extends PHPUnit_Framework_TestSuite {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Suite define the tests for this suite
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function suite() {
|
||||||
|
$suite = new PHPUnit_Framework_TestSuite('Js Helper and all Engine Helpers');
|
||||||
|
|
||||||
|
$helperTestPath = CORE_TEST_CASES . DS . 'libs' . DS . 'view' . DS . 'helpers' . DS;
|
||||||
|
$suite->addTestFile($helperTestPath . 'js.test.php');
|
||||||
|
$suite->addTestFile($helperTestPath . 'jquery_engine.test.php');
|
||||||
|
$suite->addTestFile($helperTestPath . 'mootools_engine.test.php');
|
||||||
|
$suite->addTestFile($helperTestPath . 'prototype_engine.test.php');
|
||||||
|
return $suite;
|
||||||
|
}
|
||||||
|
}
|
54
cake/tests/cases/libs/all_libs.test.php
Normal file
54
cake/tests/cases/libs/all_libs.test.php
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AllLibsTest file
|
||||||
|
*
|
||||||
|
* PHP 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||||
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases
|
||||||
|
* @since CakePHP(tm) v 2.0
|
||||||
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AllLibsTest class
|
||||||
|
*
|
||||||
|
* This test group will run all non mvc related lib class tests
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases
|
||||||
|
*/
|
||||||
|
class AllLibsTest extends PHPUnit_Framework_TestSuite {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* suite method, defines tests for this suite.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function suite() {
|
||||||
|
$suite = new PHPUnit_Framework_TestSuite('All non-MVC lib class tests');
|
||||||
|
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'basics.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'cake_session.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'debugger.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'error.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'file.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'folder.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'log' . DS . 'file_log.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'cake_log.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'class_registry.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'sanitize.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'set.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'string.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'validation.test.php');
|
||||||
|
return $suite;
|
||||||
|
}
|
||||||
|
}
|
44
cake/tests/cases/libs/all_localization.test.php
Normal file
44
cake/tests/cases/libs/all_localization.test.php
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AllLocalizationTest file
|
||||||
|
*
|
||||||
|
* PHP 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||||
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases
|
||||||
|
* @since CakePHP(tm) v 2.0
|
||||||
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AllLocalizationTest class
|
||||||
|
*
|
||||||
|
* This test group will run i18n/l10n tests
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases
|
||||||
|
*/
|
||||||
|
class AllLocalizationTest extends PHPUnit_Framework_TestSuite {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* suite method, defines tests for this suite.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function suite() {
|
||||||
|
$suite = new PHPUnit_Framework_TestSuite('All localization class tests');
|
||||||
|
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'i18n.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'l10n.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'multibyte.test.php');
|
||||||
|
return $suite;
|
||||||
|
}
|
||||||
|
}
|
46
cake/tests/cases/libs/all_model.test.php
Normal file
46
cake/tests/cases/libs/all_model.test.php
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AllModelTest file
|
||||||
|
*
|
||||||
|
* PHP 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||||
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases
|
||||||
|
* @since CakePHP(tm) v 2.0
|
||||||
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AllModelTest class
|
||||||
|
*
|
||||||
|
* This test group will run model class tests
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.groups
|
||||||
|
*/
|
||||||
|
class AllModelTest extends PHPUnit_Framework_TestSuite {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* suite method, defines tests for this suite.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function suite() {
|
||||||
|
$suite = new PHPUnit_Framework_TestSuite('All Model related class tests');
|
||||||
|
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'model' . DS . 'model_behavior.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'model' . DS . 'model_read.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'model' . DS . 'model_write.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'model' . DS . 'model_validation.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'model' . DS . 'model_integration.test.php');
|
||||||
|
return $suite;
|
||||||
|
}
|
||||||
|
}
|
43
cake/tests/cases/libs/all_routing.test.php
Normal file
43
cake/tests/cases/libs/all_routing.test.php
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AllRoutingTest file
|
||||||
|
*
|
||||||
|
* PHP 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||||
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases
|
||||||
|
* @since CakePHP(tm) v 2.0
|
||||||
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AllRoutingTest class
|
||||||
|
*
|
||||||
|
* This test group will run view class tests (view, theme)
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.groups
|
||||||
|
*/
|
||||||
|
class AllRoutingTest extends PHPUnit_Framework_TestSuite {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* suite method, defines tests for this suite.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function suite() {
|
||||||
|
$suite = new PHPUnit_Framework_TestSuite('All Router and Dispatcher class tests');
|
||||||
|
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'router.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'dispatcher.test.php');
|
||||||
|
return $suite;
|
||||||
|
}
|
||||||
|
}
|
43
cake/tests/cases/libs/all_socket.test.php
Normal file
43
cake/tests/cases/libs/all_socket.test.php
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AllSocketTest file
|
||||||
|
*
|
||||||
|
* PHP 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||||
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases
|
||||||
|
* @since CakePHP(tm) v 2.0
|
||||||
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AllSocketTest class
|
||||||
|
*
|
||||||
|
* This test group will run socket class tests
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.groups
|
||||||
|
*/
|
||||||
|
class AllSocketTest extends PHPUnit_Framework_TestSuite {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* suite method, defines tests for this suite.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function suite() {
|
||||||
|
$suite = new PHPUnit_Framework_TestSuite('All Socket related class tests');
|
||||||
|
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'cake_socket.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'http_socket.test.php');
|
||||||
|
return $suite;
|
||||||
|
}
|
||||||
|
}
|
45
cake/tests/cases/libs/all_test_suite.test.php
Normal file
45
cake/tests/cases/libs/all_test_suite.test.php
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AllTestSuiteTest file
|
||||||
|
*
|
||||||
|
* PHP 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||||
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases
|
||||||
|
* @since CakePHP(tm) v 2.0
|
||||||
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AllTestSuiteTest class
|
||||||
|
*
|
||||||
|
* This test group will run socket class tests
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.groups
|
||||||
|
*/
|
||||||
|
class AllTestSuiteTest extends PHPUnit_Framework_TestSuite {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* suite method, defines tests for this suite.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function suite() {
|
||||||
|
$suite = new PHPUnit_Framework_TestSuite('All Test Suite classes tests');
|
||||||
|
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'test_manager.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'cake_test_case.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'cake_test_fixture.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'html_coverage_report.test.php');
|
||||||
|
return $suite;
|
||||||
|
}
|
||||||
|
}
|
43
cake/tests/cases/libs/all_views.test.php
Normal file
43
cake/tests/cases/libs/all_views.test.php
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AllViewsTest file
|
||||||
|
*
|
||||||
|
* PHP 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||||
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases
|
||||||
|
* @since CakePHP(tm) v 2.0
|
||||||
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AllViewsTest class
|
||||||
|
*
|
||||||
|
* This test group will run view class tests (view, theme)
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.groups
|
||||||
|
*/
|
||||||
|
class AllViewsTest extends PHPUnit_Framework_TestSuite {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* suite method, defines tests for this suite.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function suite() {
|
||||||
|
$suite = new PHPUnit_Framework_TestSuite('All View class tests');
|
||||||
|
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'view' . DS . 'view.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'view' . DS . 'theme.test.php');
|
||||||
|
return $suite;
|
||||||
|
}
|
||||||
|
}
|
44
cake/tests/cases/libs/all_xml.test.php
Normal file
44
cake/tests/cases/libs/all_xml.test.php
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AllXmlTest file
|
||||||
|
*
|
||||||
|
* PHP 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||||
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases
|
||||||
|
* @since CakePHP(tm) v 2.0
|
||||||
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AllXmlTest class
|
||||||
|
*
|
||||||
|
* This test group will run xml class tests
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.groups
|
||||||
|
*/
|
||||||
|
class AllXmlTest extends PHPUnit_Framework_TestSuite {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* suite method, defines tests for this suite.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function suite() {
|
||||||
|
$suite = new PHPUnit_Framework_TestSuite('All Xml related class tests');
|
||||||
|
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'xml.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'view' . DS . 'helpers' . DS . 'rss.test.php');
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'view' . DS . 'helpers' . DS . 'xml.test.php');
|
||||||
|
return $suite;
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,8 +21,6 @@ if (!class_exists('Cache')) {
|
||||||
require LIBS . 'cache.php';
|
require LIBS . 'cache.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
Mock::generate('StdClass', 'RubbishEngine');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CacheTest class
|
* CacheTest class
|
||||||
*
|
*
|
||||||
|
@ -139,6 +137,7 @@ class CacheTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testAttemptingToConfigureANonCacheEngineClass() {
|
function testAttemptingToConfigureANonCacheEngineClass() {
|
||||||
|
$this->getMock('StdClass', array(), array(), 'RubbishEngine');
|
||||||
$this->expectException();
|
$this->expectException();
|
||||||
Cache::config('Garbage', array(
|
Cache::config('Garbage', array(
|
||||||
'engine' => 'Rubbish'
|
'engine' => 'Rubbish'
|
||||||
|
|
|
@ -205,7 +205,7 @@ class MemcacheEngineTest extends CakeTestCase {
|
||||||
$this->assertEqual($result, $expecting);
|
$this->assertEqual($result, $expecting);
|
||||||
|
|
||||||
$result = Cache::read('long_expiry_test');
|
$result = Cache::read('long_expiry_test');
|
||||||
$this->assertTrue($result);
|
$this->assertEquals($expecting, $result);
|
||||||
|
|
||||||
Cache::config('memcache', array('duration' => 3600));
|
Cache::config('memcache', array('duration' => 3600));
|
||||||
}
|
}
|
||||||
|
|
17
cake/tests/cases/libs/cache/xcache.test.php
vendored
17
cake/tests/cases/libs/cache/xcache.test.php
vendored
|
@ -27,21 +27,7 @@ if (!class_exists('Cache')) {
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.tests.cases.libs.cache
|
* @subpackage cake.tests.cases.libs.cache
|
||||||
*/
|
*/
|
||||||
class XcacheEngineTest extends UnitTestCase {
|
class XcacheEngineTest extends CakeTestCase {
|
||||||
|
|
||||||
/**
|
|
||||||
* skip method
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function skip() {
|
|
||||||
$skip = true;
|
|
||||||
if (function_exists('xcache_set')) {
|
|
||||||
$skip = false;
|
|
||||||
}
|
|
||||||
$this->skipIf($skip, '%s Xcache is not installed or configured properly');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setUp method
|
* setUp method
|
||||||
|
@ -50,6 +36,7 @@ class XcacheEngineTest extends UnitTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function setUp() {
|
function setUp() {
|
||||||
|
$this->skipUnless(function_exists('xcache_set'), 'Xcache is not installed or configured properly');
|
||||||
$this->_cacheDisable = Configure::read('Cache.disable');
|
$this->_cacheDisable = Configure::read('Cache.disable');
|
||||||
Configure::write('Cache.disable', false);
|
Configure::write('Cache.disable', false);
|
||||||
Cache::config('xcache', array('engine' => 'Xcache', 'prefix' => 'cake_'));
|
Cache::config('xcache', array('engine' => 'Xcache', 'prefix' => 'cake_'));
|
||||||
|
|
|
@ -69,20 +69,20 @@ class CakeLogTest extends CakeTestCase {
|
||||||
/**
|
/**
|
||||||
* test all the errors from failed logger imports
|
* test all the errors from failed logger imports
|
||||||
*
|
*
|
||||||
|
* @expectedException Exception
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testImportingLoggerFailure() {
|
function testImportingLoggerFailure() {
|
||||||
$this->expectException();
|
|
||||||
CakeLog::config('fail', array());
|
CakeLog::config('fail', array());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test that loggers have to implement the correct interface.
|
* test that loggers have to implement the correct interface.
|
||||||
*
|
*
|
||||||
|
* @expectedException Exception
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testNotImplementingInterface() {
|
function testNotImplementingInterface() {
|
||||||
$this->expectException();
|
|
||||||
CakeLog::config('fail', array('engine' => 'stdClass'));
|
CakeLog::config('fail', array('engine' => 'stdClass'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -226,7 +226,7 @@ class CakeSessionTest extends CakeTestCase {
|
||||||
|
|
||||||
$this->Session->write('Watching', "I'm watching you");
|
$this->Session->write('Watching', "I'm watching you");
|
||||||
$this->Session->watch('Watching');
|
$this->Session->watch('Watching');
|
||||||
$this->expectError('Writing session key {Watching}: "They found us!"');
|
$this->expectError();
|
||||||
$this->Session->write('Watching', 'They found us!');
|
$this->Session->write('Watching', 'They found us!');
|
||||||
|
|
||||||
$this->expectError('Deleting session key {Watching}');
|
$this->expectError('Deleting session key {Watching}');
|
||||||
|
@ -390,7 +390,7 @@ class CakeSessionTest extends CakeTestCase {
|
||||||
$this->assertEqual($this->Session->read('SessionTestCase'), 'This was updated');
|
$this->assertEqual($this->Session->read('SessionTestCase'), 'This was updated');
|
||||||
|
|
||||||
$this->Session->destroy();
|
$this->Session->destroy();
|
||||||
$this->assertFalse($this->Session->read('SessionTestCase'));
|
$this->assertNull($this->Session->read('SessionTestCase'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -427,7 +427,7 @@ class CakeSessionTest extends CakeTestCase {
|
||||||
$this->assertEqual($this->Session->read('SessionTestCase'), 'This was updated');
|
$this->assertEqual($this->Session->read('SessionTestCase'), 'This was updated');
|
||||||
|
|
||||||
$this->Session->destroy();
|
$this->Session->destroy();
|
||||||
$this->assertFalse($this->Session->read('SessionTestCase'));
|
$this->assertNull($this->Session->read('SessionTestCase'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -465,7 +465,7 @@ class CakeSessionTest extends CakeTestCase {
|
||||||
$this->assertEqual($this->Session->read('SessionTestCase'), 'Some additional data');
|
$this->assertEqual($this->Session->read('SessionTestCase'), 'Some additional data');
|
||||||
|
|
||||||
$this->Session->destroy();
|
$this->Session->destroy();
|
||||||
$this->assertFalse($this->Session->read('SessionTestCase'));
|
$this->assertNull($this->Session->read('SessionTestCase'));
|
||||||
session_write_close();
|
session_write_close();
|
||||||
|
|
||||||
unset($_SESSION);
|
unset($_SESSION);
|
||||||
|
|
|
@ -131,7 +131,7 @@ class CakeSocketTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testSocketWriting() {
|
function testSocketWriting() {
|
||||||
$request = "GET / HTTP/1.1\r\nConnection: close\r\n\r\n";
|
$request = "GET / HTTP/1.1\r\nConnection: close\r\n\r\n";
|
||||||
$this->assertTrue($this->Socket->write($request));
|
$this->assertTrue((bool)$this->Socket->write($request));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* Test Case for CakeTestCase class
|
* Test Case for CakeTestCase class
|
||||||
*
|
*
|
||||||
* PHP versions 4 and 5
|
* PHP version 5
|
||||||
*
|
*
|
||||||
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
||||||
* Copyright 2006-2010, Cake Software Foundation, Inc.
|
* Copyright 2006-2010, Cake Software Foundation, Inc.
|
||||||
|
@ -19,7 +19,6 @@
|
||||||
* @since CakePHP v 1.2.0.4487
|
* @since CakePHP v 1.2.0.4487
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
App::import('Core', 'CakeTestCase');
|
|
||||||
|
|
||||||
if (!class_exists('AppController')) {
|
if (!class_exists('AppController')) {
|
||||||
require_once LIBS . 'controller' . DS . 'app_controller.php';
|
require_once LIBS . 'controller' . DS . 'app_controller.php';
|
||||||
|
@ -27,41 +26,6 @@ if (!class_exists('AppController')) {
|
||||||
define('APP_CONTROLLER_EXISTS', true);
|
define('APP_CONTROLLER_EXISTS', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mock::generate('CakeHtmlReporter');
|
|
||||||
Mock::generate('CakeTestCase', 'CakeDispatcherMockTestCase');
|
|
||||||
|
|
||||||
SimpleTest::ignore('SubjectCakeTestCase');
|
|
||||||
SimpleTest::ignore('CakeDispatcherMockTestCase');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SubjectCakeTestCase
|
|
||||||
*
|
|
||||||
* @package cake
|
|
||||||
* @subpackage cake.tests.cases.libs
|
|
||||||
*/
|
|
||||||
class SubjectCakeTestCase extends CakeTestCase {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Feed a Mocked Reporter to the subject case
|
|
||||||
* prevents its pass/fails from affecting the real test
|
|
||||||
*
|
|
||||||
* @param string $reporter
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function setReporter(&$reporter) {
|
|
||||||
$this->_reporter = &$reporter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testDummy method
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testDummy() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CakeTestCaseTest
|
* CakeTestCaseTest
|
||||||
*
|
*
|
||||||
|
@ -70,6 +34,11 @@ class SubjectCakeTestCase extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
class CakeTestCaseTest extends CakeTestCase {
|
class CakeTestCaseTest extends CakeTestCase {
|
||||||
|
|
||||||
|
public static function setUpBeforeClass() {
|
||||||
|
require_once TEST_CAKE_CORE_INCLUDE_PATH . DS . 'tests' . DS . 'fixtures' . DS . 'assert_tags_test_case.php';
|
||||||
|
require_once TEST_CAKE_CORE_INCLUDE_PATH . DS . 'tests' . DS . 'fixtures' . DS . 'fixturized_test_case.php';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setUp
|
* setUp
|
||||||
*
|
*
|
||||||
|
@ -78,10 +47,7 @@ class CakeTestCaseTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function setUp() {
|
function setUp() {
|
||||||
$this->_debug = Configure::read('debug');
|
$this->_debug = Configure::read('debug');
|
||||||
$this->Case =& new SubjectCakeTestCase();
|
$this->Reporter = $this->getMock('CakeHtmlReporter');
|
||||||
$reporter =& new MockCakeHtmlReporter();
|
|
||||||
$this->Case->setReporter($reporter);
|
|
||||||
$this->Reporter = $reporter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -93,104 +59,22 @@ class CakeTestCaseTest extends CakeTestCase {
|
||||||
function tearDown() {
|
function tearDown() {
|
||||||
Configure::write('debug', $this->_debug);
|
Configure::write('debug', $this->_debug);
|
||||||
unset($this->Case);
|
unset($this->Case);
|
||||||
|
unset($this->Result);
|
||||||
unset($this->Reporter);
|
unset($this->Reporter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* endTest
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function endTest() {
|
|
||||||
App::build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testAssertGoodTags
|
* testAssertGoodTags
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
|
||||||
function testAssertGoodTags() {
|
|
||||||
$this->Reporter->expectAtLeastOnce('paintPass');
|
|
||||||
$this->Reporter->expectNever('paintFail');
|
|
||||||
|
|
||||||
$input = '<p>Text</p>';
|
|
||||||
$pattern = array(
|
|
||||||
'<p',
|
|
||||||
'Text',
|
|
||||||
'/p',
|
|
||||||
);
|
|
||||||
$this->assertTrue($this->Case->assertTags($input, $pattern));
|
|
||||||
|
|
||||||
$input = '<a href="/test.html" class="active">My link</a>';
|
|
||||||
$pattern = array(
|
|
||||||
'a' => array('href' => '/test.html', 'class' => 'active'),
|
|
||||||
'My link',
|
|
||||||
'/a'
|
|
||||||
);
|
|
||||||
$this->assertTrue($this->Case->assertTags($input, $pattern));
|
|
||||||
|
|
||||||
$pattern = array(
|
|
||||||
'a' => array('class' => 'active', 'href' => '/test.html'),
|
|
||||||
'My link',
|
|
||||||
'/a'
|
|
||||||
);
|
|
||||||
$this->assertTrue($this->Case->assertTags($input, $pattern), 'Attributes in wrong order. %s');
|
|
||||||
|
|
||||||
$input = "<a href=\"/test.html\"\t\n\tclass=\"active\"\tid=\"primary\">\t<span>My link</span></a>";
|
|
||||||
$pattern = array(
|
|
||||||
'a' => array('id' => 'primary', 'href' => '/test.html', 'class' => 'active'),
|
|
||||||
'<span',
|
|
||||||
'My link',
|
|
||||||
'/span',
|
|
||||||
'/a'
|
|
||||||
);
|
|
||||||
$this->assertTrue($this->Case->assertTags($input, $pattern), 'Whitespace consumption %s');
|
|
||||||
|
|
||||||
$input = '<p class="info"><a href="/test.html" class="active"><strong onClick="alert(\'hey\');">My link</strong></a></p>';
|
|
||||||
$pattern = array(
|
|
||||||
'p' => array('class' => 'info'),
|
|
||||||
'a' => array('class' => 'active', 'href' => '/test.html' ),
|
|
||||||
'strong' => array('onClick' => 'alert(\'hey\');'),
|
|
||||||
'My link',
|
|
||||||
'/strong',
|
|
||||||
'/a',
|
|
||||||
'/p'
|
|
||||||
);
|
|
||||||
$this->assertTrue($this->Case->assertTags($input, $pattern));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* test that assertTags knows how to handle correct quoting.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
function testAssertTagsQuotes() {
|
function testAssertTagsQuotes() {
|
||||||
$input = '<a href="/test.html" class="active">My link</a>';
|
$test = new AssertTagsTestCase('testAssertTagsQuotes');
|
||||||
$pattern = array(
|
$result = $test->run();
|
||||||
'a' => array('href' => '/test.html', 'class' => 'active'),
|
$this->assertEquals(0, $result->errorCount());
|
||||||
'My link',
|
$this->assertTrue($result->wasSuccessful());
|
||||||
'/a'
|
$this->assertEquals(0, $result->failureCount());
|
||||||
);
|
|
||||||
$this->assertTrue($this->Case->assertTags($input, $pattern), 'Double quoted attributes %s');
|
|
||||||
|
|
||||||
$input = "<a href='/test.html' class='active'>My link</a>";
|
|
||||||
$pattern = array(
|
|
||||||
'a' => array('href' => '/test.html', 'class' => 'active'),
|
|
||||||
'My link',
|
|
||||||
'/a'
|
|
||||||
);
|
|
||||||
$this->assertTrue($this->Case->assertTags($input, $pattern), 'Single quoted attributes %s');
|
|
||||||
|
|
||||||
$input = "<a href='/test.html' class='active'>My link</a>";
|
|
||||||
$pattern = array(
|
|
||||||
'a' => array('href' => 'preg:/.*\.html/', 'class' => 'active'),
|
|
||||||
'My link',
|
|
||||||
'/a'
|
|
||||||
);
|
|
||||||
$this->assertTrue($this->Case->assertTags($input, $pattern), 'Single quoted attributes %s');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -200,109 +84,31 @@ class CakeTestCaseTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testNumericValuesInExpectationForAssertTags() {
|
function testNumericValuesInExpectationForAssertTags() {
|
||||||
$value = 220985;
|
$test = new AssertTagsTestCase('testNumericValuesInExpectationForAssertTags');
|
||||||
|
$result = $test->run();
|
||||||
$input = '<p><strong>' . $value . '</strong></p>';
|
$this->assertEquals(0, $result->errorCount());
|
||||||
$pattern = array(
|
$this->assertTrue($result->wasSuccessful());
|
||||||
'<p',
|
$this->assertEquals(0, $result->failureCount());
|
||||||
'<strong',
|
|
||||||
$value,
|
|
||||||
'/strong',
|
|
||||||
'/p'
|
|
||||||
);
|
|
||||||
$this->assertTrue($this->Case->assertTags($input, $pattern));
|
|
||||||
|
|
||||||
$input = '<p><strong>' . $value . '</strong></p><p><strong>' . $value . '</strong></p>';
|
|
||||||
$pattern = array(
|
|
||||||
'<p',
|
|
||||||
'<strong',
|
|
||||||
$value,
|
|
||||||
'/strong',
|
|
||||||
'/p',
|
|
||||||
'<p',
|
|
||||||
'<strong',
|
|
||||||
$value,
|
|
||||||
'/strong',
|
|
||||||
'/p',
|
|
||||||
);
|
|
||||||
$this->assertTrue($this->Case->assertTags($input, $pattern));
|
|
||||||
|
|
||||||
$input = '<p><strong>' . $value . '</strong></p><p id="' . $value . '"><strong>' . $value . '</strong></p>';
|
|
||||||
$pattern = array(
|
|
||||||
'<p',
|
|
||||||
'<strong',
|
|
||||||
$value,
|
|
||||||
'/strong',
|
|
||||||
'/p',
|
|
||||||
'p' => array('id' => $value),
|
|
||||||
'<strong',
|
|
||||||
$value,
|
|
||||||
'/strong',
|
|
||||||
'/p',
|
|
||||||
);
|
|
||||||
$this->assertTrue($this->Case->assertTags($input, $pattern));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testBadAssertTags
|
* testBadAssertTags
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testBadAssertTags() {
|
function testBadAssertTags() {
|
||||||
$this->Reporter->expectAtLeastOnce('paintFail');
|
$test = new AssertTagsTestCase('testBadAssertTags');
|
||||||
$this->Reporter->expectNever('paintPass');
|
$result = $test->run();
|
||||||
|
$this->assertEquals(0, $result->errorCount());
|
||||||
|
$this->assertFalse($result->wasSuccessful());
|
||||||
|
$this->assertEquals(1, $result->failureCount());
|
||||||
|
|
||||||
$input = '<a href="/test.html" class="active">My link</a>';
|
$test = new AssertTagsTestCase('testBadAssertTags2');
|
||||||
$pattern = array(
|
$result = $test->run();
|
||||||
'a' => array('hRef' => '/test.html', 'clAss' => 'active'),
|
$this->assertEquals(0, $result->errorCount());
|
||||||
'My link',
|
$this->assertFalse($result->wasSuccessful());
|
||||||
'/a'
|
$this->assertEquals(1, $result->failureCount());
|
||||||
);
|
|
||||||
$this->assertFalse($this->Case->assertTags($input, $pattern));
|
|
||||||
|
|
||||||
$input = '<a href="/test.html" class="active">My link</a>';
|
|
||||||
$pattern = array(
|
|
||||||
'<a' => array('href' => '/test.html', 'class' => 'active'),
|
|
||||||
'My link',
|
|
||||||
'/a'
|
|
||||||
);
|
|
||||||
$this->assertFalse($this->Case->assertTags($input, $pattern));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testBefore
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testBefore() {
|
|
||||||
$this->Case->before('testDummy');
|
|
||||||
$this->assertFalse(isset($this->Case->db));
|
|
||||||
|
|
||||||
$this->Case->fixtures = array('core.post');
|
|
||||||
$this->Case->before('start');
|
|
||||||
$this->assertTrue(isset($this->Case->db));
|
|
||||||
$this->assertTrue(isset($this->Case->_fixtures['core.post']));
|
|
||||||
$this->assertTrue(is_a($this->Case->_fixtures['core.post'], 'CakeTestFixture'));
|
|
||||||
$this->assertEqual($this->Case->_fixtureClassMap['Post'], 'core.post');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testAfter
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testAfter() {
|
|
||||||
$this->Case->after('testDummy');
|
|
||||||
$this->assertFalse($this->Case->getTruncated());
|
|
||||||
|
|
||||||
$this->Case->fixtures = array('core.post');
|
|
||||||
$this->Case->before('start');
|
|
||||||
$this->Case->start();
|
|
||||||
$this->Case->after('testDummy');
|
|
||||||
$this->assertTrue($this->Case->getTruncated());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -312,189 +118,80 @@ class CakeTestCaseTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testLoadFixtures() {
|
function testLoadFixtures() {
|
||||||
$this->Case->fixtures = array('core.post');
|
$test = new FixturizedTestCase('testFixturePresent');
|
||||||
$this->Case->autoFixtures = false;
|
$manager = $this->getMock('CakeFixtureManager');
|
||||||
$this->Case->before('start');
|
$manager->fixturize($test);
|
||||||
$this->expectError();
|
$test->sharedFixture = $manager;
|
||||||
$this->Case->loadFixtures('Wrong!');
|
$manager->expects($this->once())->method('load');
|
||||||
$this->Case->end();
|
$manager->expects($this->once())->method('unload');
|
||||||
|
$result = $test->run();
|
||||||
|
$this->assertEquals(0, $result->errorCount());
|
||||||
|
$this->assertTrue($result->wasSuccessful());
|
||||||
|
$this->assertEquals(0, $result->failureCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testGetTests Method
|
* testLoadFixturesOnDemand
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testGetTests() {
|
|
||||||
$result = $this->Case->getTests();
|
|
||||||
$this->assertEqual(array_slice($result, 0, 2), array('start', 'startCase'));
|
|
||||||
$this->assertEqual(array_slice($result, -2), array('endCase', 'end'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TestTestAction
|
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testTestAction() {
|
function testLoadFixturesOnDemand() {
|
||||||
App::build(array(
|
$test = new FixturizedTestCase('testFixtureLoadOnDemand');
|
||||||
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
|
$test->autoFixtures = false;
|
||||||
'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS),
|
$manager = $this->getMock('CakeFixtureManager');
|
||||||
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS),
|
$manager->fixturize($test);
|
||||||
'controllers' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'controllers' . DS)
|
$test->sharedFixture = $manager;
|
||||||
), true);
|
$manager->expects($this->once())->method('loadSingle');
|
||||||
|
$result = $test->run();
|
||||||
$result = $this->Case->testAction('/tests_apps/index', array('return' => 'view'));
|
$this->assertEquals(0, $result->errorCount());
|
||||||
$this->assertPattern('/This is the TestsAppsController index view/', $result);
|
|
||||||
|
|
||||||
$result = $this->Case->testAction('/tests_apps/index', array('return' => 'contents'));
|
|
||||||
$this->assertPattern('/This is the TestsAppsController index view/', $result);
|
|
||||||
$this->assertPattern('/<html/', $result);
|
|
||||||
$this->assertPattern('/<\/html>/', $result);
|
|
||||||
|
|
||||||
$result = $this->Case->testAction('/tests_apps/some_method', array('return' => 'result'));
|
|
||||||
$this->assertEqual($result, 5);
|
|
||||||
|
|
||||||
$result = $this->Case->testAction('/tests_apps/set_action', array('return' => 'vars'));
|
|
||||||
$this->assertEqual($result, array('var' => 'string'));
|
|
||||||
|
|
||||||
$db =& ConnectionManager::getDataSource('test_suite');
|
|
||||||
$fixture =& new PostFixture();
|
|
||||||
$fixture->create($db);
|
|
||||||
|
|
||||||
$result = $this->Case->testAction('/tests_apps_posts/add', array('return' => 'vars'));
|
|
||||||
$this->assertTrue(array_key_exists('posts', $result));
|
|
||||||
$this->assertEqual(count($result['posts']), 1);
|
|
||||||
|
|
||||||
$result = $this->Case->testAction('/tests_apps_posts/url_var/var1:value1/var2:val2', array(
|
|
||||||
'return' => 'vars',
|
|
||||||
'method' => 'get',
|
|
||||||
));
|
|
||||||
$this->assertTrue(isset($result['params']['url']['url']));
|
|
||||||
$this->assertEqual(array_keys($result['params']['named']), array('var1', 'var2'));
|
|
||||||
|
|
||||||
$result = $this->Case->testAction('/tests_apps_posts/url_var/gogo/val2', array(
|
|
||||||
'return' => 'vars',
|
|
||||||
'method' => 'get',
|
|
||||||
));
|
|
||||||
$this->assertEqual($result['params']['pass'], array('gogo', 'val2'));
|
|
||||||
|
|
||||||
|
|
||||||
$result = $this->Case->testAction('/tests_apps_posts/url_var', array(
|
|
||||||
'return' => 'vars',
|
|
||||||
'method' => 'get',
|
|
||||||
'data' => array(
|
|
||||||
'red' => 'health',
|
|
||||||
'blue' => 'mana'
|
|
||||||
)
|
|
||||||
));
|
|
||||||
$this->assertTrue(isset($result['params']['url']['red']));
|
|
||||||
$this->assertTrue(isset($result['params']['url']['blue']));
|
|
||||||
$this->assertTrue(isset($result['params']['url']['url']));
|
|
||||||
|
|
||||||
$result = $this->Case->testAction('/tests_apps_posts/post_var', array(
|
|
||||||
'return' => 'vars',
|
|
||||||
'method' => 'post',
|
|
||||||
'data' => array(
|
|
||||||
'name' => 'is jonas',
|
|
||||||
'pork' => 'and beans',
|
|
||||||
)
|
|
||||||
));
|
|
||||||
$this->assertEqual(array_keys($result['data']), array('name', 'pork'));
|
|
||||||
$fixture->drop($db);
|
|
||||||
|
|
||||||
$db =& ConnectionManager::getDataSource('test_suite');
|
|
||||||
$_backPrefix = $db->config['prefix'];
|
|
||||||
$db->config['prefix'] = 'cake_testaction_test_suite_';
|
|
||||||
|
|
||||||
$config = $db->config;
|
|
||||||
$config['prefix'] = 'cake_testcase_test_';
|
|
||||||
|
|
||||||
ConnectionManager::create('cake_test_case', $config);
|
|
||||||
$db2 =& ConnectionManager::getDataSource('cake_test_case');
|
|
||||||
|
|
||||||
$fixture =& new PostFixture($db2);
|
|
||||||
$fixture->create($db2);
|
|
||||||
$fixture->insert($db2);
|
|
||||||
|
|
||||||
$result = $this->Case->testAction('/tests_apps_posts/fixtured', array(
|
|
||||||
'return' => 'vars',
|
|
||||||
'fixturize' => true,
|
|
||||||
'connection' => 'cake_test_case',
|
|
||||||
));
|
|
||||||
$this->assertTrue(isset($result['posts']));
|
|
||||||
$this->assertEqual(count($result['posts']), 3);
|
|
||||||
$tables = $db2->listSources();
|
|
||||||
$this->assertFalse(in_array('cake_testaction_test_suite_posts', $tables));
|
|
||||||
|
|
||||||
$fixture->drop($db2);
|
|
||||||
|
|
||||||
$db =& ConnectionManager::getDataSource('test_suite');
|
|
||||||
|
|
||||||
//test that drop tables behaves as exepected with testAction
|
|
||||||
$db =& ConnectionManager::getDataSource('test_suite');
|
|
||||||
$_backPrefix = $db->config['prefix'];
|
|
||||||
$db->config['prefix'] = 'cake_testaction_test_suite_';
|
|
||||||
|
|
||||||
$config = $db->config;
|
|
||||||
$config['prefix'] = 'cake_testcase_test_';
|
|
||||||
|
|
||||||
ConnectionManager::create('cake_test_case', $config);
|
|
||||||
$db =& ConnectionManager::getDataSource('cake_test_case');
|
|
||||||
$fixture =& new PostFixture($db);
|
|
||||||
$fixture->create($db);
|
|
||||||
$fixture->insert($db);
|
|
||||||
|
|
||||||
$this->Case->dropTables = false;
|
|
||||||
$result = $this->Case->testAction('/tests_apps_posts/fixtured', array(
|
|
||||||
'return' => 'vars',
|
|
||||||
'fixturize' => true,
|
|
||||||
'connection' => 'cake_test_case',
|
|
||||||
));
|
|
||||||
|
|
||||||
$tables = $db->listSources();
|
|
||||||
$this->assertTrue(in_array('cake_testaction_test_suite_posts', $tables));
|
|
||||||
|
|
||||||
$fixture->drop($db);
|
|
||||||
$db =& ConnectionManager::getDataSource('test_suite');
|
|
||||||
$db->config['prefix'] = $_backPrefix;
|
|
||||||
$fixture->drop($db);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testLoadFixturesOnDemand
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testUnoadFixturesAfterFailure() {
|
||||||
|
$test = new FixturizedTestCase('testFixtureLoadOnDemand');
|
||||||
|
$test->autoFixtures = false;
|
||||||
|
$manager = $this->getMock('CakeFixtureManager');
|
||||||
|
$manager->fixturize($test);
|
||||||
|
$test->sharedFixture = $manager;
|
||||||
|
$manager->expects($this->once())->method('loadSingle');
|
||||||
|
$result = $test->run();
|
||||||
|
$this->assertEquals(0, $result->errorCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testThrowException
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testThrowException() {
|
||||||
|
$test = new FixturizedTestCase('testThrowException');
|
||||||
|
$test->autoFixtures = false;
|
||||||
|
$manager = $this->getMock('CakeFixtureManager');
|
||||||
|
$manager->fixturize($test);
|
||||||
|
$test->sharedFixture = $manager;
|
||||||
|
$manager->expects($this->once())->method('unload');
|
||||||
|
$result = $test->run();
|
||||||
|
$this->assertEquals(1, $result->errorCount());
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* testSkipIf
|
* testSkipIf
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testSkipIf() {
|
function testSkipIf() {
|
||||||
$this->assertTrue($this->Case->skipIf(true));
|
$test = new FixturizedTestCase('testSkipIfTrue');
|
||||||
$this->assertFalse($this->Case->skipIf(false));
|
$result = $test->run();
|
||||||
}
|
$this->assertEquals(1, $result->skippedCount());
|
||||||
|
|
||||||
/**
|
$test = new FixturizedTestCase('testSkipIfFalse');
|
||||||
* testTestDispatcher
|
$result = $test->run();
|
||||||
*
|
$this->assertEquals(0, $result->skippedCount());
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testTestDispatcher() {
|
|
||||||
App::build(array(
|
|
||||||
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
|
|
||||||
'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS),
|
|
||||||
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS),
|
|
||||||
'controllers' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'controllers' . DS)
|
|
||||||
), true);
|
|
||||||
|
|
||||||
$Dispatcher =& new CakeTestDispatcher();
|
|
||||||
$Case =& new CakeDispatcherMockTestCase();
|
|
||||||
|
|
||||||
$Case->expectOnce('startController');
|
|
||||||
$Case->expectOnce('endController');
|
|
||||||
|
|
||||||
$Dispatcher->testCase($Case);
|
|
||||||
$this->assertTrue(isset($Dispatcher->testCase));
|
|
||||||
|
|
||||||
$return = $Dispatcher->dispatch('/tests_apps/index', array('autoRender' => 0, 'return' => 1, 'requested' => 1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ class CakeTestFixtureImportFixture extends CakeTestFixture {
|
||||||
*
|
*
|
||||||
* @var mixed
|
* @var mixed
|
||||||
*/
|
*/
|
||||||
public $import = array('table' => 'fixture_tests', 'connection' => 'test_suite');
|
public $import = array('table' => 'fixture_tests', 'connection' => 'fixture_test_suite');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -122,8 +122,6 @@ class FixturePrefixTest extends Model {
|
||||||
public $useDbConfig = 'test_suite';
|
public $useDbConfig = 'test_suite';
|
||||||
}
|
}
|
||||||
|
|
||||||
Mock::generate('DboSource', 'FixtureMockDboSource');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test case for CakeTestFixture
|
* Test case for CakeTestFixture
|
||||||
*
|
*
|
||||||
|
@ -139,8 +137,14 @@ class CakeTestFixtureTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function setUp() {
|
function setUp() {
|
||||||
$this->criticDb =& new FixtureMockDboSource();
|
$this->criticDb = $this->getMock('DboSource');
|
||||||
$this->criticDb->fullDebug = true;
|
$this->criticDb->fullDebug = true;
|
||||||
|
|
||||||
|
$dbs = ConnectionManager::enumConnectionObjects();
|
||||||
|
if (!isset($dbs['test_suite'])) {
|
||||||
|
$db = ConnectionManager::getDatasource('test');
|
||||||
|
ConnectionManager::create('test_suite', $db->config);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -160,34 +164,35 @@ class CakeTestFixtureTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testInit() {
|
function testInit() {
|
||||||
$Fixture =& new CakeTestFixtureTestFixture();
|
$Fixture = new CakeTestFixtureTestFixture();
|
||||||
unset($Fixture->table);
|
unset($Fixture->table);
|
||||||
$Fixture->init();
|
$Fixture->init();
|
||||||
$this->assertEqual($Fixture->table, 'fixture_tests');
|
$this->assertEqual($Fixture->table, 'fixture_tests');
|
||||||
$this->assertEqual($Fixture->primaryKey, 'id');
|
$this->assertEqual($Fixture->primaryKey, 'id');
|
||||||
|
|
||||||
$Fixture =& new CakeTestFixtureTestFixture();
|
$Fixture = new CakeTestFixtureTestFixture();
|
||||||
$Fixture->primaryKey = 'my_random_key';
|
$Fixture->primaryKey = 'my_random_key';
|
||||||
$Fixture->init();
|
$Fixture->init();
|
||||||
$this->assertEqual($Fixture->primaryKey, 'my_random_key');
|
$this->assertEqual($Fixture->primaryKey, 'my_random_key');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test that init() correctly sets the fixture table when the connection or model have prefixes defined.
|
* test that init() correctly sets the fixture table when the connection or model have prefixes defined.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testInitDbPrefix() {
|
function testInitDbPrefix() {
|
||||||
$this->_initDb();
|
$db = ConnectionManager::getDataSource('test_suite');
|
||||||
$Source =& new CakeTestFixtureTestFixture();
|
$Source = new CakeTestFixtureTestFixture();
|
||||||
$Source->create($this->db);
|
$Source->drop($db);
|
||||||
$Source->insert($this->db);
|
$Source->create($db);
|
||||||
|
$Source->insert($db);
|
||||||
|
|
||||||
$Fixture =& new CakeTestFixtureImportFixture();
|
$Fixture = new CakeTestFixtureTestFixture();
|
||||||
$expected = array('id', 'name', 'created');
|
$expected = array('id', 'name', 'created');
|
||||||
$this->assertEqual(array_keys($Fixture->fields), $expected);
|
$this->assertEqual(array_keys($Fixture->fields), $expected);
|
||||||
|
|
||||||
$db =& ConnectionManager::getDataSource('test_suite');
|
|
||||||
$config = $db->config;
|
$config = $db->config;
|
||||||
$config['prefix'] = 'fixture_test_suite_';
|
$config['prefix'] = 'fixture_test_suite_';
|
||||||
ConnectionManager::create('fixture_test_suite', $config);
|
ConnectionManager::create('fixture_test_suite', $config);
|
||||||
|
@ -196,17 +201,19 @@ class CakeTestFixtureTest extends CakeTestCase {
|
||||||
$Fixture->import = array('table' => 'fixture_tests', 'connection' => 'test_suite', 'records' => true);
|
$Fixture->import = array('table' => 'fixture_tests', 'connection' => 'test_suite', 'records' => true);
|
||||||
$Fixture->init();
|
$Fixture->init();
|
||||||
$this->assertEqual(count($Fixture->records), count($Source->records));
|
$this->assertEqual(count($Fixture->records), count($Source->records));
|
||||||
|
$Fixture->create(ConnectionManager::getDataSource('fixture_test_suite'));
|
||||||
|
|
||||||
$Fixture =& new CakeTestFixtureImportFixture();
|
$Fixture2 = new CakeTestFixtureImportFixture();
|
||||||
$Fixture->fields = $Fixture->records = null;
|
$Fixture2->fields = $Fixture->records = null;
|
||||||
$Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'test_suite');
|
$Fixture2->import = array('model' => 'FixtureImportTestModel', 'connection' => 'fixture_test_suite');
|
||||||
$Fixture->init();
|
$Fixture2->init();
|
||||||
$this->assertEqual(array_keys($Fixture->fields), array('id', 'name', 'created'));
|
$this->assertEqual(array_keys($Fixture2->fields), array('id', 'name', 'created'));
|
||||||
|
|
||||||
$keys = array_flip(ClassRegistry::keys());
|
$keys = array_flip(ClassRegistry::keys());
|
||||||
$this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys));
|
$this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys));
|
||||||
|
|
||||||
$Source->drop($this->db);
|
$Fixture->drop(ConnectionManager::getDataSource('fixture_test_suite'));
|
||||||
|
$Source->drop($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -215,12 +222,13 @@ class CakeTestFixtureTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testInitModelTablePrefix() {
|
function testInitModelTablePrefix() {
|
||||||
$this->_initDb();
|
$db = ConnectionManager::getDataSource('test_suite');
|
||||||
$Source =& new CakeTestFixtureTestFixture();
|
|
||||||
$Source->create($this->db);
|
|
||||||
$Source->insert($this->db);
|
|
||||||
|
|
||||||
$Fixture =& new CakeTestFixtureImportFixture();
|
$Source =& new CakeTestFixtureTestFixture();
|
||||||
|
$Source->create($db);
|
||||||
|
$Source->insert($db);
|
||||||
|
|
||||||
|
$Fixture =& new CakeTestFixtureTestFixture();
|
||||||
unset($Fixture->table);
|
unset($Fixture->table);
|
||||||
$Fixture->fields = $Fixture->records = null;
|
$Fixture->fields = $Fixture->records = null;
|
||||||
$Fixture->import = array('model' => 'FixturePrefixTest', 'connection' => 'test_suite', 'records' => false);
|
$Fixture->import = array('model' => 'FixturePrefixTest', 'connection' => 'test_suite', 'records' => false);
|
||||||
|
@ -230,7 +238,7 @@ class CakeTestFixtureTest extends CakeTestCase {
|
||||||
$keys = array_flip(ClassRegistry::keys());
|
$keys = array_flip(ClassRegistry::keys());
|
||||||
$this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys));
|
$this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys));
|
||||||
|
|
||||||
$Source->drop($this->db);
|
$Source->drop($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -240,22 +248,20 @@ class CakeTestFixtureTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testImport() {
|
function testImport() {
|
||||||
$this->_initDb();
|
$defaultDb = ConnectionManager::getDataSource('default');
|
||||||
|
$testSuiteDb = ConnectionManager::getDataSource('test_suite');
|
||||||
$defaultDb =& ConnectionManager::getDataSource('default');
|
|
||||||
$testSuiteDb =& ConnectionManager::getDataSource('test_suite');
|
|
||||||
$defaultConfig = $defaultDb->config;
|
$defaultConfig = $defaultDb->config;
|
||||||
$testSuiteConfig = $testSuiteDb->config;
|
$testSuiteConfig = $testSuiteDb->config;
|
||||||
ConnectionManager::create('new_test_suite', array_merge($testSuiteConfig, array('prefix' => 'new_' . $testSuiteConfig['prefix'])));
|
ConnectionManager::create('new_test_suite', array_merge($testSuiteConfig, array('prefix' => 'new_' . $testSuiteConfig['prefix'])));
|
||||||
$newTestSuiteDb =& ConnectionManager::getDataSource('new_test_suite');
|
$newTestSuiteDb = ConnectionManager::getDataSource('new_test_suite');
|
||||||
|
|
||||||
$Source =& new CakeTestFixtureTestFixture();
|
$Source = new CakeTestFixtureTestFixture();
|
||||||
$Source->create($newTestSuiteDb);
|
$Source->create($newTestSuiteDb);
|
||||||
$Source->insert($newTestSuiteDb);
|
$Source->insert($newTestSuiteDb);
|
||||||
|
|
||||||
$defaultDb->config = $newTestSuiteDb->config;
|
$defaultDb->config = $newTestSuiteDb->config;
|
||||||
|
|
||||||
$Fixture =& new CakeTestFixtureDefaultImportFixture();
|
$Fixture = new CakeTestFixtureDefaultImportFixture();
|
||||||
$Fixture->fields = $Fixture->records = null;
|
$Fixture->fields = $Fixture->records = null;
|
||||||
$Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'new_test_suite');
|
$Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'new_test_suite');
|
||||||
$Fixture->init();
|
$Fixture->init();
|
||||||
|
@ -276,22 +282,21 @@ class CakeTestFixtureTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testImportWithRecords() {
|
function testImportWithRecords() {
|
||||||
$this->_initDb();
|
|
||||||
|
|
||||||
$defaultDb =& ConnectionManager::getDataSource('default');
|
$defaultDb = ConnectionManager::getDataSource('default');
|
||||||
$testSuiteDb =& ConnectionManager::getDataSource('test_suite');
|
$testSuiteDb = ConnectionManager::getDataSource('test_suite');
|
||||||
$defaultConfig = $defaultDb->config;
|
$defaultConfig = $defaultDb->config;
|
||||||
$testSuiteConfig = $testSuiteDb->config;
|
$testSuiteConfig = $testSuiteDb->config;
|
||||||
ConnectionManager::create('new_test_suite', array_merge($testSuiteConfig, array('prefix' => 'new_' . $testSuiteConfig['prefix'])));
|
ConnectionManager::create('new_test_suite', array_merge($testSuiteConfig, array('prefix' => 'new_' . $testSuiteConfig['prefix'])));
|
||||||
$newTestSuiteDb =& ConnectionManager::getDataSource('new_test_suite');
|
$newTestSuiteDb = ConnectionManager::getDataSource('new_test_suite');
|
||||||
|
|
||||||
$Source =& new CakeTestFixtureTestFixture();
|
$Source = new CakeTestFixtureTestFixture();
|
||||||
$Source->create($newTestSuiteDb);
|
$Source->create($newTestSuiteDb);
|
||||||
$Source->insert($newTestSuiteDb);
|
$Source->insert($newTestSuiteDb);
|
||||||
|
|
||||||
$defaultDb->config = $newTestSuiteDb->config;
|
$defaultDb->config = $newTestSuiteDb->config;
|
||||||
|
|
||||||
$Fixture =& new CakeTestFixtureDefaultImportFixture();
|
$Fixture = new CakeTestFixtureDefaultImportFixture();
|
||||||
$Fixture->fields = $Fixture->records = null;
|
$Fixture->fields = $Fixture->records = null;
|
||||||
$Fixture->import = array(
|
$Fixture->import = array(
|
||||||
'model' => 'FixtureImportTestModel', 'connection' => 'new_test_suite', 'records' => true
|
'model' => 'FixtureImportTestModel', 'connection' => 'new_test_suite', 'records' => true
|
||||||
|
@ -313,9 +318,9 @@ class CakeTestFixtureTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testCreate() {
|
function testCreate() {
|
||||||
$Fixture =& new CakeTestFixtureTestFixture();
|
$Fixture = new CakeTestFixtureTestFixture();
|
||||||
$this->criticDb->expectAtLeastOnce('execute');
|
$this->criticDb->expects($this->atLeastOnce())->method('execute');
|
||||||
$this->criticDb->expectAtLeastOnce('createSchema');
|
$this->criticDb->expects($this->atLeastOnce())->method('createSchema');
|
||||||
$return = $Fixture->create($this->criticDb);
|
$return = $Fixture->create($this->criticDb);
|
||||||
$this->assertTrue($this->criticDb->fullDebug);
|
$this->assertTrue($this->criticDb->fullDebug);
|
||||||
$this->assertTrue($return);
|
$this->assertTrue($return);
|
||||||
|
@ -332,9 +337,8 @@ class CakeTestFixtureTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testInsert() {
|
function testInsert() {
|
||||||
$Fixture =& new CakeTestFixtureTestFixture();
|
$Fixture = new CakeTestFixtureTestFixture();
|
||||||
$this->criticDb->setReturnValue('insertMulti', true);
|
$this->criticDb->expects($this->atLeastOnce())->method('insertMulti')->will($this->returnValue(true));
|
||||||
$this->criticDb->expectAtLeastOnce('insertMulti');
|
|
||||||
|
|
||||||
$return = $Fixture->insert($this->criticDb);
|
$return = $Fixture->insert($this->criticDb);
|
||||||
$this->assertTrue($this->criticDb->fullDebug);
|
$this->assertTrue($this->criticDb->fullDebug);
|
||||||
|
@ -348,16 +352,15 @@ class CakeTestFixtureTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testDrop() {
|
function testDrop() {
|
||||||
$Fixture =& new CakeTestFixtureTestFixture();
|
$Fixture = new CakeTestFixtureTestFixture();
|
||||||
$this->criticDb->setReturnValueAt(0, 'execute', true);
|
$this->criticDb->expects($this->at(1))->method('execute')->will($this->returnValue(true));
|
||||||
$this->criticDb->expectAtLeastOnce('execute');
|
$this->criticDb->expects($this->at(3))->method('execute')->will($this->returnValue(false));
|
||||||
$this->criticDb->expectAtLeastOnce('dropSchema');
|
$this->criticDb->expects($this->exactly(2))->method('dropSchema');
|
||||||
|
|
||||||
$return = $Fixture->drop($this->criticDb);
|
$return = $Fixture->drop($this->criticDb);
|
||||||
$this->assertTrue($this->criticDb->fullDebug);
|
$this->assertTrue($this->criticDb->fullDebug);
|
||||||
$this->assertTrue($return);
|
$this->assertTrue($return);
|
||||||
|
|
||||||
$this->criticDb->setReturnValueAt(1, 'execute', false);
|
|
||||||
$return = $Fixture->drop($this->criticDb);
|
$return = $Fixture->drop($this->criticDb);
|
||||||
$this->assertFalse($return);
|
$this->assertFalse($return);
|
||||||
}
|
}
|
||||||
|
@ -369,8 +372,8 @@ class CakeTestFixtureTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testTruncate() {
|
function testTruncate() {
|
||||||
$Fixture =& new CakeTestFixtureTestFixture();
|
$Fixture = new CakeTestFixtureTestFixture();
|
||||||
$this->criticDb->expectAtLeastOnce('truncate');
|
$this->criticDb->expects($this->atLeastOnce())->method('truncate');
|
||||||
$Fixture->truncate($this->criticDb);
|
$Fixture->truncate($this->criticDb);
|
||||||
$this->assertTrue($this->criticDb->fullDebug);
|
$this->assertTrue($this->criticDb->fullDebug);
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,69 +165,42 @@ class ClassRegistryTest extends CakeTestCase {
|
||||||
|
|
||||||
$Tag->name = 'SomeNewName';
|
$Tag->name = 'SomeNewName';
|
||||||
|
|
||||||
if (PHP5) {
|
|
||||||
$TagCopy = ClassRegistry::getObject('RegisterArticleTag');
|
$TagCopy = ClassRegistry::getObject('RegisterArticleTag');
|
||||||
} else {
|
|
||||||
$TagCopy =& ClassRegistry::getObject('RegisterArticleTag');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->assertTrue(is_a($TagCopy, 'RegisterArticleTag'));
|
$this->assertTrue(is_a($TagCopy, 'RegisterArticleTag'));
|
||||||
$this->assertIdentical($Tag, $TagCopy);
|
$this->assertSame($Tag, $TagCopy);
|
||||||
|
|
||||||
if (PHP5) {
|
|
||||||
$NewTag = ClassRegistry::init(array('class' => 'RegisterArticleTag', 'alias' => 'NewTag'));
|
$NewTag = ClassRegistry::init(array('class' => 'RegisterArticleTag', 'alias' => 'NewTag'));
|
||||||
} else {
|
|
||||||
$NewTag =& ClassRegistry::init(array('class' => 'RegisterArticleTag', 'alias' => 'NewTag'));
|
|
||||||
}
|
|
||||||
$this->assertTrue(is_a($Tag, 'RegisterArticleTag'));
|
$this->assertTrue(is_a($Tag, 'RegisterArticleTag'));
|
||||||
|
|
||||||
if (PHP5) {
|
|
||||||
$NewTagCopy = ClassRegistry::init(array('class' => 'RegisterArticleTag', 'alias' => 'NewTag'));
|
|
||||||
} else {
|
|
||||||
$NewTagCopy =& ClassRegistry::init(array('class' => 'RegisterArticleTag', 'alias' => 'NewTag'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->assertNotIdentical($Tag, $NewTag);
|
$NewTagCopy = ClassRegistry::init(array('class' => 'RegisterArticleTag', 'alias' => 'NewTag'));
|
||||||
$this->assertIdentical($NewTag, $NewTagCopy);
|
|
||||||
|
$this->assertNotSame($Tag, $NewTag);
|
||||||
|
$this->assertSame($NewTag, $NewTagCopy);
|
||||||
|
|
||||||
$NewTag->name = 'SomeOtherName';
|
$NewTag->name = 'SomeOtherName';
|
||||||
$this->assertNotIdentical($Tag, $NewTag);
|
$this->assertNotSame($Tag, $NewTag);
|
||||||
$this->assertIdentical($NewTag, $NewTagCopy);
|
$this->assertSame($NewTag, $NewTagCopy);
|
||||||
|
|
||||||
$Tag->name = 'SomeOtherName';
|
$Tag->name = 'SomeOtherName';
|
||||||
$this->assertNotIdentical($Tag, $NewTag);
|
$this->assertNotSame($Tag, $NewTag);
|
||||||
|
|
||||||
$this->assertTrue($TagCopy->name === 'SomeOtherName');
|
$this->assertTrue($TagCopy->name === 'SomeOtherName');
|
||||||
|
|
||||||
if (PHP5) {
|
|
||||||
$User = ClassRegistry::init(array('class' => 'RegisterUser', 'alias' => 'User', 'table' => false));
|
$User = ClassRegistry::init(array('class' => 'RegisterUser', 'alias' => 'User', 'table' => false));
|
||||||
} else {
|
|
||||||
$User =& ClassRegistry::init(array('class' => 'RegisterUser', 'alias' => 'User', 'table' => false));
|
|
||||||
}
|
|
||||||
$this->assertTrue(is_a($User, 'AppModel'));
|
$this->assertTrue(is_a($User, 'AppModel'));
|
||||||
|
|
||||||
if (PHP5) {
|
|
||||||
$UserCopy = ClassRegistry::init(array('class' => 'RegisterUser', 'alias' => 'User', 'table' => false));
|
$UserCopy = ClassRegistry::init(array('class' => 'RegisterUser', 'alias' => 'User', 'table' => false));
|
||||||
} else {
|
|
||||||
$UserCopy =& ClassRegistry::init(array('class' => 'RegisterUser', 'alias' => 'User', 'table' => false));
|
|
||||||
}
|
|
||||||
$this->assertTrue(is_a($UserCopy, 'AppModel'));
|
$this->assertTrue(is_a($UserCopy, 'AppModel'));
|
||||||
$this->assertIdentical($User, $UserCopy);
|
$this->assertEquals($User, $UserCopy);
|
||||||
|
|
||||||
if (PHP5) {
|
|
||||||
$Category = ClassRegistry::init(array('class' => 'RegisterCategory'));
|
$Category = ClassRegistry::init(array('class' => 'RegisterCategory'));
|
||||||
} else {
|
|
||||||
$Category =& ClassRegistry::init(array('class' => 'RegisterCategory'));
|
|
||||||
}
|
|
||||||
$this->assertTrue(is_a($Category, 'RegisterCategory'));
|
$this->assertTrue(is_a($Category, 'RegisterCategory'));
|
||||||
|
|
||||||
if (PHP5) {
|
|
||||||
$ParentCategory = ClassRegistry::init(array('class' => 'RegisterCategory', 'alias' => 'ParentCategory'));
|
$ParentCategory = ClassRegistry::init(array('class' => 'RegisterCategory', 'alias' => 'ParentCategory'));
|
||||||
} else {
|
|
||||||
$ParentCategory =& ClassRegistry::init(array('class' => 'RegisterCategory', 'alias' => 'ParentCategory'));
|
|
||||||
}
|
|
||||||
$this->assertTrue(is_a($ParentCategory, 'RegisterCategory'));
|
$this->assertTrue(is_a($ParentCategory, 'RegisterCategory'));
|
||||||
$this->assertNotIdentical($Category, $ParentCategory);
|
$this->assertNotSame($Category, $ParentCategory);
|
||||||
|
|
||||||
$this->assertNotEqual($Category->alias, $ParentCategory->alias);
|
$this->assertNotEqual($Category->alias, $ParentCategory->alias);
|
||||||
$this->assertEqual('RegisterCategory', $Category->alias);
|
$this->assertEqual('RegisterCategory', $Category->alias);
|
||||||
|
@ -307,19 +280,11 @@ class ClassRegistryTest extends CakeTestCase {
|
||||||
|
|
||||||
$this->assertEqual($TestRegistryPluginModel->tablePrefix, 'something_');
|
$this->assertEqual($TestRegistryPluginModel->tablePrefix, 'something_');
|
||||||
|
|
||||||
if (PHP5) {
|
|
||||||
$PluginUser = ClassRegistry::init(array('class' => 'RegistryPlugin.RegisterUser', 'alias' => 'RegistryPluginUser', 'table' => false));
|
$PluginUser = ClassRegistry::init(array('class' => 'RegistryPlugin.RegisterUser', 'alias' => 'RegistryPluginUser', 'table' => false));
|
||||||
} else {
|
|
||||||
$PluginUser =& ClassRegistry::init(array('class' => 'RegistryPlugin.RegisterUser', 'alias' => 'RegistryPluginUser', 'table' => false));
|
|
||||||
}
|
|
||||||
$this->assertTrue(is_a($PluginUser, 'RegistryPluginAppModel'));
|
$this->assertTrue(is_a($PluginUser, 'RegistryPluginAppModel'));
|
||||||
|
|
||||||
if (PHP5) {
|
|
||||||
$PluginUserCopy = ClassRegistry::getObject('RegistryPluginUser');
|
$PluginUserCopy = ClassRegistry::getObject('RegistryPluginUser');
|
||||||
} else {
|
|
||||||
$PluginUserCopy =& ClassRegistry::getObject('RegistryPluginUser');
|
|
||||||
}
|
|
||||||
$this->assertTrue(is_a($PluginUserCopy, 'RegistryPluginAppModel'));
|
$this->assertTrue(is_a($PluginUserCopy, 'RegistryPluginAppModel'));
|
||||||
$this->assertIdentical($PluginUser, $PluginUserCopy);
|
$this->assertSame($PluginUser, $PluginUserCopy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,512 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* CodeCoverageManagerTest file
|
|
||||||
*
|
|
||||||
* PHP versions 4 and 5
|
|
||||||
*
|
|
||||||
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
|
||||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
||||||
*
|
|
||||||
* Licensed under The Open Group Test Suite License
|
|
||||||
* Redistributions of files must retain the above copyright notice.
|
|
||||||
*
|
|
||||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
||||||
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
|
||||||
* @package cake
|
|
||||||
* @subpackage cake.tests.cases.libs
|
|
||||||
* @since CakePHP(tm) v 1.2.0.4206
|
|
||||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
|
||||||
*/
|
|
||||||
require_once CAKE . 'tests' . DS . 'lib' . DS . 'code_coverage_manager.php';
|
|
||||||
require_once CAKE . 'tests' . DS . 'lib' . DS . 'reporter' . DS . 'cake_cli_reporter.php';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CodeCoverageManagerTest class
|
|
||||||
*
|
|
||||||
* @package cake
|
|
||||||
* @subpackage cake.tests.cases.libs
|
|
||||||
*/
|
|
||||||
class CodeCoverageManagerTest extends CakeTestCase {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Skip if XDebug not installed
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function skip() {
|
|
||||||
$this->skipIf(!extension_loaded('xdebug'), '%s XDebug not installed');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* startTest Method
|
|
||||||
* Store reference of $_GET to restore later.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function startCase() {
|
|
||||||
$this->_get = $_GET;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* End Case - restore GET vars.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function endCase() {
|
|
||||||
$_GET = $this->_get;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testNoTestCaseSupplied method
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testNoTestCaseSupplied() {
|
|
||||||
if ($this->skipIf(PHP_SAPI == 'cli', 'Is cli, cannot run this test %s')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$reporter =& new CakeHtmlReporter(null, array('group' => false, 'app' => false, 'plugin' => false));
|
|
||||||
|
|
||||||
CodeCoverageManager::init(substr(md5(microtime()), 0, 5), $reporter);
|
|
||||||
CodeCoverageManager::report(false);
|
|
||||||
$this->assertError();
|
|
||||||
|
|
||||||
CodeCoverageManager::init('tests' . DS . 'lib' . DS . basename(__FILE__), $reporter);
|
|
||||||
CodeCoverageManager::report(false);
|
|
||||||
$this->assertError();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that test cases don't cause errors
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testNoTestCaseSuppliedNoErrors() {
|
|
||||||
if ($this->skipIf(PHP_SAPI == 'cli', 'Is cli, cannot run this test %s')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$reporter =& new CakeHtmlReporter(null, array('group' => false, 'app' => false, 'plugin' => false));
|
|
||||||
$path = LIBS;
|
|
||||||
if (strpos(LIBS, ROOT) === false) {
|
|
||||||
$path = ROOT.DS.LIBS;
|
|
||||||
}
|
|
||||||
App::import('Core', 'Folder');
|
|
||||||
$folder = new Folder();
|
|
||||||
$folder->cd($path);
|
|
||||||
$contents = $folder->read();
|
|
||||||
|
|
||||||
$contents[1] = array_filter($contents[1], array(&$this, '_basenameFilter'));
|
|
||||||
|
|
||||||
foreach ($contents[1] as $file) {
|
|
||||||
CodeCoverageManager::init('libs' . DS . $file, $reporter);
|
|
||||||
CodeCoverageManager::report(false);
|
|
||||||
$this->assertNoErrors('libs' . DS . $file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove file names that don't share a basename with the current file.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function _basenameFilter($var) {
|
|
||||||
return ($var != basename(__FILE__));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testGetTestObjectFileNameFromTestCaseFile method
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testGetTestObjectFileNameFromTestCaseFile() {
|
|
||||||
$manager =& CodeCoverageManager::getInstance();
|
|
||||||
$manager->reporter = new CakeHtmlReporter();
|
|
||||||
|
|
||||||
$expected = $manager->__testObjectFileFromCaseFile('models/some_file.test.php', true);
|
|
||||||
$this->assertIdentical(APP.'models'.DS.'some_file.php', $expected);
|
|
||||||
|
|
||||||
$expected = $manager->__testObjectFileFromCaseFile('models/datasources/some_file.test.php', true);
|
|
||||||
$this->assertIdentical(APP.'models'.DS.'datasources'.DS.'some_file.php', $expected);
|
|
||||||
|
|
||||||
$expected = $manager->__testObjectFileFromCaseFile('controllers/some_file.test.php', true);
|
|
||||||
$this->assertIdentical(APP.'controllers'.DS.'some_file.php', $expected);
|
|
||||||
|
|
||||||
$expected = $manager->__testObjectFileFromCaseFile('views/some_file.test.php', true);
|
|
||||||
$this->assertIdentical(APP.'views'.DS.'some_file.php', $expected);
|
|
||||||
|
|
||||||
$expected = $manager->__testObjectFileFromCaseFile('behaviors/some_file.test.php', true);
|
|
||||||
$this->assertIdentical(APP.'models'.DS.'behaviors'.DS.'some_file.php', $expected);
|
|
||||||
|
|
||||||
$expected = $manager->__testObjectFileFromCaseFile('components/some_file.test.php', true);
|
|
||||||
$this->assertIdentical(APP.'controllers'.DS.'components'.DS.'some_file.php', $expected);
|
|
||||||
|
|
||||||
$expected = $manager->__testObjectFileFromCaseFile('helpers/some_file.test.php', true);
|
|
||||||
$this->assertIdentical(APP.'views'.DS.'helpers'.DS.'some_file.php', $expected);
|
|
||||||
|
|
||||||
$manager->pluginTest = 'bugs';
|
|
||||||
$expected = $manager->__testObjectFileFromCaseFile('models/some_file.test.php', false);
|
|
||||||
$this->assertIdentical(APP.'plugins'.DS.'bugs'.DS.'models'.DS.'some_file.php', $expected);
|
|
||||||
|
|
||||||
$manager->pluginTest = false;
|
|
||||||
$manager->reporter = new CakeCliReporter;
|
|
||||||
$expected = $manager->__testObjectFileFromCaseFile('libs/set.test.php', false);
|
|
||||||
$this->assertIdentical(ROOT.DS.'cake'.DS.'libs'.DS.'set.php', $expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testOfHtmlDiffReport method
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testOfHtmlDiffReport() {
|
|
||||||
$manager =& CodeCoverageManager::getInstance();
|
|
||||||
$code = <<<PHP
|
|
||||||
/**
|
|
||||||
* Set class
|
|
||||||
*
|
|
||||||
* @package cake
|
|
||||||
* @subpackage cake.tests.cases.libs
|
|
||||||
*/
|
|
||||||
class Set extends Object {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Value of the Set object.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
var \$value = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor. Defaults to an empty array.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function __construct() {
|
|
||||||
if (func_num_args() == 1 && is_array(func_get_arg(0))) {
|
|
||||||
\$this->value = func_get_arg(0);
|
|
||||||
} else {
|
|
||||||
\$this->value = func_get_args();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the contents of the Set object
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function &get() {
|
|
||||||
return \$this->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function can be thought of as a hybrid between PHP's array_merge and array_merge_recursive. The difference
|
|
||||||
* to the two is that if an array key contains another array then the function behaves recursive (unlike array_merge)
|
|
||||||
* but does not do if for keys containing strings (unlike array_merge_recursive). See the unit test for more information.
|
|
||||||
*
|
|
||||||
* Note: This function will work with an unlimited amount of arguments and typecasts non-array parameters into arrays.
|
|
||||||
*
|
|
||||||
* @param array \$arr1 Array to be merged
|
|
||||||
* @param array \$arr2 Array to merge with
|
|
||||||
* @return array Merged array
|
|
||||||
*/
|
|
||||||
public function merge(\$arr1, \$arr2 = null) {
|
|
||||||
\$args = func_get_args();
|
|
||||||
|
|
||||||
if (isset(\$this) && is_a(\$this, 'set')) {
|
|
||||||
\$backtrace = debug_backtrace();
|
|
||||||
\$previousCall = strtolower(\$backtrace[1]['class'].'::'.\$backtrace[1]['function']);
|
|
||||||
if (\$previousCall != 'set::merge') {
|
|
||||||
\$r =& \$this->value;
|
|
||||||
array_unshift(\$args, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!isset(\$r)) {
|
|
||||||
\$r = (array)current(\$args);
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((\$arg = next(\$args)) !== false) {
|
|
||||||
if (is_a(\$arg, 'set')) {
|
|
||||||
\$arg = \$arg->get();
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ((array)\$arg as \$key => \$val) {
|
|
||||||
if (is_array(\$val) && isset(\$r[\$key]) && is_array(\$r[\$key])) {
|
|
||||||
\$r[\$key] = Set::merge(\$r[\$key], \$val);
|
|
||||||
} elseif (is_int(\$key)) {
|
|
||||||
|
|
||||||
} else {
|
|
||||||
\$r[\$key] = \$val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return \$r;
|
|
||||||
}
|
|
||||||
PHP;
|
|
||||||
|
|
||||||
$testObjectFile = explode("\n", $code);
|
|
||||||
$coverageData = array(
|
|
||||||
0 => 1,
|
|
||||||
1 => 1,
|
|
||||||
2 => -2,
|
|
||||||
3 => -2,
|
|
||||||
4 => -2,
|
|
||||||
5 => -2,
|
|
||||||
6 => -2,
|
|
||||||
7 => -2,
|
|
||||||
8 => -1,
|
|
||||||
9 => -2,
|
|
||||||
10 => -2,
|
|
||||||
11 => -2,
|
|
||||||
12 => -2,
|
|
||||||
13 => -2,
|
|
||||||
14 => 1,
|
|
||||||
15 => 1,
|
|
||||||
16 => -1,
|
|
||||||
17 => 1,
|
|
||||||
18 => 1,
|
|
||||||
19 => -1,
|
|
||||||
20 => 1,
|
|
||||||
21 => -2,
|
|
||||||
22 => -2,
|
|
||||||
23 => -2,
|
|
||||||
24 => -2,
|
|
||||||
25 => -2,
|
|
||||||
26 => -2,
|
|
||||||
27 => 1,
|
|
||||||
28 => -1,
|
|
||||||
29 => 1,
|
|
||||||
30 => 1,
|
|
||||||
31 => -2,
|
|
||||||
32 => -2,
|
|
||||||
33 => -2,
|
|
||||||
34 => -2,
|
|
||||||
35 => -2,
|
|
||||||
36 => -2,
|
|
||||||
37 => -2,
|
|
||||||
38 => -2,
|
|
||||||
39 => -2,
|
|
||||||
40 => -2,
|
|
||||||
41 => -2,
|
|
||||||
42 => -2,
|
|
||||||
43 => -1,
|
|
||||||
44 => -2,
|
|
||||||
45 => -2,
|
|
||||||
46 => -2,
|
|
||||||
47 => -2,
|
|
||||||
48 => 1,
|
|
||||||
49 => 1,
|
|
||||||
50 => -1,
|
|
||||||
51 => 1,
|
|
||||||
52 => 1,
|
|
||||||
53 => -2,
|
|
||||||
54 => -2,
|
|
||||||
55 => 1,
|
|
||||||
56 => 1,
|
|
||||||
57 => 1,
|
|
||||||
58 => 1,
|
|
||||||
59 => -1,
|
|
||||||
60 => 1,
|
|
||||||
61 => 1,
|
|
||||||
62 => -2,
|
|
||||||
63 => -2,
|
|
||||||
64 => 1,
|
|
||||||
65 => -2,
|
|
||||||
66 => 1,
|
|
||||||
67 => -1,
|
|
||||||
68 => -2,
|
|
||||||
69 => -1,
|
|
||||||
70 => -1,
|
|
||||||
71 => 1,
|
|
||||||
72 => -2,
|
|
||||||
);
|
|
||||||
$expected = array(
|
|
||||||
0 => 'ignored',
|
|
||||||
1 => 'ignored',
|
|
||||||
2 => 'ignored',
|
|
||||||
3 => 'ignored',
|
|
||||||
4 => 'ignored',
|
|
||||||
5 => 'ignored show start realstart',
|
|
||||||
6 => 'ignored show',
|
|
||||||
7 => 'ignored show',
|
|
||||||
8 => 'uncovered show',
|
|
||||||
9 => 'ignored show',
|
|
||||||
10 => 'ignored show',
|
|
||||||
11 => 'ignored show end',
|
|
||||||
12 => 'ignored',
|
|
||||||
13 => 'ignored show start',
|
|
||||||
14 => 'covered show',
|
|
||||||
15 => 'covered show',
|
|
||||||
16 => 'uncovered show',
|
|
||||||
17 => 'covered show show',
|
|
||||||
18 => 'covered show show',
|
|
||||||
19 => 'uncovered show',
|
|
||||||
20 => 'covered show',
|
|
||||||
21 => 'ignored show',
|
|
||||||
22 => 'ignored show end',
|
|
||||||
23 => 'ignored',
|
|
||||||
24 => 'ignored',
|
|
||||||
25 => 'ignored show start',
|
|
||||||
26 => 'ignored show',
|
|
||||||
27 => 'covered show',
|
|
||||||
28 => 'uncovered show',
|
|
||||||
29 => 'covered show',
|
|
||||||
30 => 'covered show',
|
|
||||||
31 => 'ignored show end',
|
|
||||||
32 => 'ignored',
|
|
||||||
33 => 'ignored',
|
|
||||||
34 => 'ignored',
|
|
||||||
35 => 'ignored',
|
|
||||||
36 => 'ignored',
|
|
||||||
37 => 'ignored',
|
|
||||||
38 => 'ignored',
|
|
||||||
39 => 'ignored',
|
|
||||||
40 => 'ignored show start',
|
|
||||||
41 => 'ignored show',
|
|
||||||
42 => 'ignored show',
|
|
||||||
43 => 'uncovered show',
|
|
||||||
41 => 'ignored show',
|
|
||||||
42 => 'ignored show',
|
|
||||||
43 => 'uncovered show',
|
|
||||||
44 => 'ignored show',
|
|
||||||
45 => 'ignored show',
|
|
||||||
46 => 'ignored show',
|
|
||||||
47 => 'ignored show',
|
|
||||||
48 => 'covered show',
|
|
||||||
49 => 'covered show',
|
|
||||||
50 => 'uncovered show',
|
|
||||||
51 => 'covered show',
|
|
||||||
52 => 'covered show',
|
|
||||||
53 => 'ignored show end',
|
|
||||||
54 => 'ignored',
|
|
||||||
55 => 'covered',
|
|
||||||
56 => 'covered show start',
|
|
||||||
57 => 'covered show',
|
|
||||||
58 => 'covered show',
|
|
||||||
59 => 'uncovered show',
|
|
||||||
60 => 'covered show',
|
|
||||||
61 => 'covered show',
|
|
||||||
62 => 'ignored show end',
|
|
||||||
63 => 'ignored',
|
|
||||||
64 => 'covered show start',
|
|
||||||
65 => 'ignored show',
|
|
||||||
66 => 'covered show show',
|
|
||||||
67 => 'uncovered show',
|
|
||||||
68 => 'ignored show',
|
|
||||||
69 => 'uncovered show',
|
|
||||||
70 => 'uncovered show',
|
|
||||||
71 => 'covered show',
|
|
||||||
72 => 'ignored show',
|
|
||||||
73 => 'ignored show end end',
|
|
||||||
);
|
|
||||||
$execCodeLines = range(0, 72);
|
|
||||||
$result = explode("</div>", $report = $manager->reportCaseHtmlDiff($testObjectFile, $coverageData, $execCodeLines, 3));
|
|
||||||
|
|
||||||
foreach ($result as $line) {
|
|
||||||
preg_match('/<span class="line-num">(.*?)<\/span>/', $line, $matches);
|
|
||||||
if (!isset($matches[1])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$num = $matches[1];
|
|
||||||
$class = $expected[$num];
|
|
||||||
$pattern = '/<div class="code-line '.$class.'">/';
|
|
||||||
$this->assertPattern($pattern, $line, $num.': '.$line." fails");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testArrayStrrpos method
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testArrayStrrpos() {
|
|
||||||
$manager =& CodeCoverageManager::getInstance();
|
|
||||||
|
|
||||||
$a = array(
|
|
||||||
'apples',
|
|
||||||
'bananas',
|
|
||||||
'oranges'
|
|
||||||
);
|
|
||||||
$this->assertEqual(1, $manager->__array_strpos($a, 'ba', true));
|
|
||||||
$this->assertEqual(2, $manager->__array_strpos($a, 'range', true));
|
|
||||||
$this->assertEqual(0, $manager->__array_strpos($a, 'pp', true));
|
|
||||||
$this->assertFalse($manager->__array_strpos('', 'ba', true));
|
|
||||||
$this->assertFalse($manager->__array_strpos(false, 'ba', true));
|
|
||||||
$this->assertFalse($manager->__array_strpos(array(), 'ba', true));
|
|
||||||
|
|
||||||
$a = array(
|
|
||||||
'rang',
|
|
||||||
'orange',
|
|
||||||
'oranges'
|
|
||||||
);
|
|
||||||
$this->assertEqual(0, $manager->__array_strpos($a, 'rang'));
|
|
||||||
$this->assertEqual(2, $manager->__array_strpos($a, 'rang', true));
|
|
||||||
$this->assertEqual(1, $manager->__array_strpos($a, 'orange', false));
|
|
||||||
$this->assertEqual(1, $manager->__array_strpos($a, 'orange'));
|
|
||||||
$this->assertEqual(2, $manager->__array_strpos($a, 'orange', true));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testGetExecutableLines method
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testGetExecutableLines() {
|
|
||||||
$manager =& CodeCoverageManager::getInstance();
|
|
||||||
$code = <<<HTML
|
|
||||||
\$manager =& CodeCoverageManager::getInstance();
|
|
||||||
HTML;
|
|
||||||
$result = $manager->__getExecutableLines($code);
|
|
||||||
foreach ($result as $line) {
|
|
||||||
$this->assertNotIdentical($line, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
$code = <<<HTML
|
|
||||||
{
|
|
||||||
}
|
|
||||||
<?php?>
|
|
||||||
?>
|
|
||||||
<?
|
|
||||||
}
|
|
||||||
{{}}
|
|
||||||
(())
|
|
||||||
@codeCoverageIgnoreStart
|
|
||||||
some
|
|
||||||
more
|
|
||||||
code
|
|
||||||
here
|
|
||||||
@codeCoverageIgnoreEnd
|
|
||||||
HTML;
|
|
||||||
$result = $manager->__getExecutableLines($code);
|
|
||||||
foreach ($result as $line) {
|
|
||||||
$this->assertIdentical(trim($line), '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testCalculateCodeCoverage method
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testCalculateCodeCoverage() {
|
|
||||||
$manager =& CodeCoverageManager::getInstance();
|
|
||||||
$data = array(
|
|
||||||
'25' => array(100, 25),
|
|
||||||
'50' => array(100, 50),
|
|
||||||
'0' => array(0, 0),
|
|
||||||
'0' => array(100, 0),
|
|
||||||
'100' => array(100, 100),
|
|
||||||
);
|
|
||||||
foreach ($data as $coverage => $lines) {
|
|
||||||
$this->assertEqual($coverage, $manager->__calcCoverage($lines[0], $lines[1]));
|
|
||||||
}
|
|
||||||
|
|
||||||
$manager->__calcCoverage(100, 1000);
|
|
||||||
$this->assertError();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -648,14 +648,14 @@ class AppImportTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testFileLoadingReturnValue () {
|
function testFileLoadingReturnValue () {
|
||||||
$file = App::import('File', 'Name', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php', true);
|
$file = App::import('File', 'Name', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php', true);
|
||||||
$this->assertTrue($file);
|
$this->assertTrue(!empty($file));
|
||||||
|
|
||||||
$this->assertTrue(isset($file['Cake.version']));
|
$this->assertTrue(isset($file['Cake.version']));
|
||||||
|
|
||||||
$type = array('type' => 'File', 'name' => 'OtherName', 'parent' => false,
|
$type = array('type' => 'File', 'name' => 'OtherName', 'parent' => false,
|
||||||
'file' => TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php', 'return' => true);
|
'file' => TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php', 'return' => true);
|
||||||
$file = App::import($type);
|
$file = App::import($type);
|
||||||
$this->assertTrue($file);
|
$this->assertTrue(!empty($file));
|
||||||
|
|
||||||
$this->assertTrue(isset($file['Cake.version']));
|
$this->assertTrue(isset($file['Cake.version']));
|
||||||
}
|
}
|
||||||
|
|
|
@ -288,7 +288,6 @@ class SomethingWithEmailComponent extends Object {
|
||||||
public $components = array('Email');
|
public $components = array('Email');
|
||||||
}
|
}
|
||||||
|
|
||||||
Mock::generate('Object', 'ComponentMockComponent', array('startup', 'beforeFilter', 'beforeRender', 'other'));
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ComponentTest class
|
* ComponentTest class
|
||||||
|
@ -422,15 +421,22 @@ class ComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testTriggerCallback() {
|
function testTriggerCallback() {
|
||||||
|
$mock = $this->getMock(
|
||||||
|
'Object',
|
||||||
|
array('startup', 'beforeFilter', 'beforeRender', 'other'),
|
||||||
|
array(),
|
||||||
|
'ComponentMockComponent'
|
||||||
|
);
|
||||||
$Controller =& new ComponentTestController();
|
$Controller =& new ComponentTestController();
|
||||||
$Controller->components = array('ComponentMock');
|
$Controller->components = array('ComponentMock');
|
||||||
$Controller->uses = null;
|
$Controller->uses = null;
|
||||||
$Controller->constructClasses();
|
$Controller->constructClasses();
|
||||||
|
|
||||||
$Controller->ComponentMock->expectOnce('beforeRender');
|
$Controller->ComponentMock->expects($this->once())->method('beforeRender');
|
||||||
|
$Controller->ComponentMock->expects($this->never())->method('beforeFilter');
|
||||||
|
|
||||||
$Controller->Component->triggerCallback('beforeRender', $Controller);
|
$Controller->Component->triggerCallback('beforeRender', $Controller);
|
||||||
|
|
||||||
$Controller->ComponentMock->expectNever('beforeFilter');
|
|
||||||
$Controller->ComponentMock->enabled = false;
|
$Controller->ComponentMock->enabled = false;
|
||||||
$Controller->Component->triggerCallback('beforeFilter', $Controller);
|
$Controller->Component->triggerCallback('beforeFilter', $Controller);
|
||||||
}
|
}
|
||||||
|
@ -563,6 +569,54 @@ class ComponentTest extends CakeTestCase {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that components can modify values from beforeRedirect
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testBeforeRedirectModification() {
|
||||||
|
$this->markTestIncomplete('This test needs to be implemented');
|
||||||
|
/*
|
||||||
|
*$MockController = new MockController();
|
||||||
|
$MockController->components = array('MockTest');
|
||||||
|
$MockController->Component = new Component();
|
||||||
|
$MockController->Component->init($MockController);
|
||||||
|
$MockController->MockTest->setReturnValue('beforeRedirect', 'http://book.cakephp.org');
|
||||||
|
$MockController->expectAt(0, 'header', array('HTTP/1.1 301 Moved Permanently'));
|
||||||
|
$MockController->expectAt(1, 'header', array('Location: http://book.cakephp.org'));
|
||||||
|
$MockController->expectCallCount('header', 2);
|
||||||
|
$MockController->redirect('http://cakephp.org', 301, false);
|
||||||
|
|
||||||
|
$MockController = new MockController();
|
||||||
|
$MockController->components = array('MockTest');
|
||||||
|
$MockController->Component = new Component();
|
||||||
|
$MockController->Component->init($MockController);
|
||||||
|
$MockController->MockTest->setReturnValue('beforeRedirect', false);
|
||||||
|
$MockController->expectNever('header');
|
||||||
|
$MockController->redirect('http://cakephp.org', 301, false);
|
||||||
|
|
||||||
|
$MockController = new MockController();
|
||||||
|
$MockController->components = array('MockTest', 'MockTestB');
|
||||||
|
$MockController->Component = new Component();
|
||||||
|
$MockController->Component->init($MockController);
|
||||||
|
$MockController->MockTest->setReturnValue('beforeRedirect', 'http://book.cakephp.org');
|
||||||
|
$MockController->MockTestB->setReturnValue('beforeRedirect', 'http://bakery.cakephp.org');
|
||||||
|
$MockController->expectAt(0, 'header', array('HTTP/1.1 301 Moved Permanently'));
|
||||||
|
$MockController->expectAt(1, 'header', array('Location: http://bakery.cakephp.org'));
|
||||||
|
$MockController->expectCallCount('header', 2);
|
||||||
|
$MockController->redirect('http://cakephp.org', 301, false);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that components can pass modifying values from beforeRedirect
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testBeforeRedirectPass() {
|
||||||
|
$this->markTestIncomplete('This test needs to be implemented');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that SessionComponent doesn't get added if its already in the components array.
|
* Test that SessionComponent doesn't get added if its already in the components array.
|
||||||
*
|
*
|
||||||
|
|
|
@ -181,8 +181,6 @@ class DbAclTwoTest extends DbAcl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Mock::generate('AclInterface', 'MockAclImplementation');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Short description for class.
|
* Short description for class.
|
||||||
*
|
*
|
||||||
|
@ -196,7 +194,10 @@ class AclComponentTest extends CakeTestCase {
|
||||||
* @access public
|
* @access public
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function startTest() {
|
function setUp() {
|
||||||
|
if (!class_exists('MockAclImplementation', false)) {
|
||||||
|
$this->getMock('AclInterface', array(), array(), 'MockAclImplementation');
|
||||||
|
}
|
||||||
Configure::write('Acl.classname', 'MockAclImplementation');
|
Configure::write('Acl.classname', 'MockAclImplementation');
|
||||||
$this->Acl = new AclComponent();
|
$this->Acl = new AclComponent();
|
||||||
}
|
}
|
||||||
|
@ -230,7 +231,7 @@ class AclComponentTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testAdapter() {
|
function testAdapter() {
|
||||||
$implementation = new MockAclImplementation();
|
$implementation = new MockAclImplementation();
|
||||||
$implementation->expectOnce('initialize', array($this->Acl));
|
$implementation->expects($this->once())->method('initialize')->with($this->Acl);
|
||||||
$this->assertNull($this->Acl->adapter($implementation));
|
$this->assertNull($this->Acl->adapter($implementation));
|
||||||
|
|
||||||
$this->assertEqual($this->Acl->adapter(), $implementation, 'Returned object is different %s');
|
$this->assertEqual($this->Acl->adapter(), $implementation, 'Returned object is different %s');
|
||||||
|
@ -264,7 +265,7 @@ class AclComponentTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @package cake.tests.cases.libs.controller.components
|
* @package cake.tests.cases.libs.controller.components
|
||||||
*/
|
*/
|
||||||
class IniAclTestCase extends CakeTestCase {
|
class IniAclTest extends CakeTestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testIniReadConfigFile
|
* testIniReadConfigFile
|
||||||
|
@ -344,7 +345,7 @@ class IniAclTestCase extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @package cake.tests.cases.libs.controller.components
|
* @package cake.tests.cases.libs.controller.components
|
||||||
*/
|
*/
|
||||||
class DbAclTestCase extends CakeTestCase {
|
class DbAclTest extends CakeTestCase {
|
||||||
/**
|
/**
|
||||||
* fixtures property
|
* fixtures property
|
||||||
*
|
*
|
||||||
|
@ -386,24 +387,24 @@ class DbAclTestCase extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testCreate() {
|
function testCreate() {
|
||||||
$this->Acl->Aro->create(array('alias' => 'Chotchkey'));
|
$this->Acl->Aro->create(array('alias' => 'Chotchkey'));
|
||||||
$this->assertTrue($this->Acl->Aro->save());
|
$this->assertTrue((bool)$this->Acl->Aro->save());
|
||||||
|
|
||||||
$parent = $this->Acl->Aro->id;
|
$parent = $this->Acl->Aro->id;
|
||||||
|
|
||||||
$this->Acl->Aro->create(array('parent_id' => $parent, 'alias' => 'Joanna'));
|
$this->Acl->Aro->create(array('parent_id' => $parent, 'alias' => 'Joanna'));
|
||||||
$this->assertTrue($this->Acl->Aro->save());
|
$this->assertTrue((bool)$this->Acl->Aro->save());
|
||||||
|
|
||||||
$this->Acl->Aro->create(array('parent_id' => $parent, 'alias' => 'Stapler'));
|
$this->Acl->Aro->create(array('parent_id' => $parent, 'alias' => 'Stapler'));
|
||||||
$this->assertTrue($this->Acl->Aro->save());
|
$this->assertTrue((bool)$this->Acl->Aro->save());
|
||||||
|
|
||||||
$root = $this->Acl->Aco->node('ROOT');
|
$root = $this->Acl->Aco->node('ROOT');
|
||||||
$parent = $root[0]['AcoTwoTest']['id'];
|
$parent = $root[0]['AcoTwoTest']['id'];
|
||||||
|
|
||||||
$this->Acl->Aco->create(array('parent_id' => $parent, 'alias' => 'Drinks'));
|
$this->Acl->Aco->create(array('parent_id' => $parent, 'alias' => 'Drinks'));
|
||||||
$this->assertTrue($this->Acl->Aco->save());
|
$this->assertTrue((bool)$this->Acl->Aco->save());
|
||||||
|
|
||||||
$this->Acl->Aco->create(array('parent_id' => $parent, 'alias' => 'PiecesOfFlair'));
|
$this->Acl->Aco->create(array('parent_id' => $parent, 'alias' => 'PiecesOfFlair'));
|
||||||
$this->assertTrue($this->Acl->Aco->save());
|
$this->assertTrue((bool)$this->Acl->Aco->save());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -460,11 +461,19 @@ class DbAclTestCase extends CakeTestCase {
|
||||||
// Samir should still have his tpsReports/view permissions, but does not
|
// Samir should still have his tpsReports/view permissions, but does not
|
||||||
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view', 'update'));
|
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view', 'update'));
|
||||||
|
|
||||||
$this->expectError('DbAcl::allow() - Invalid node');
|
$this->expectError();
|
||||||
$this->assertFalse($this->Acl->allow('Lumbergh', 'ROOT/tpsReports/DoesNotExist', 'create'));
|
$this->assertFalse($this->Acl->allow('Lumbergh', 'ROOT/tpsReports/DoesNotExist', 'create'));
|
||||||
|
}
|
||||||
|
|
||||||
$this->expectError('DbAcl::allow() - Invalid node');
|
/**
|
||||||
$this->assertFalse($this->Acl->allow('Homer', 'tpsReports', 'create'));
|
* testAllowInvalidNode method
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testAllowInvalidNode() {
|
||||||
|
$this->expectError();
|
||||||
|
$this->Acl->allow('Homer', 'tpsReports', 'create');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -479,15 +488,6 @@ class DbAclTestCase extends CakeTestCase {
|
||||||
$this->assertFalse($this->Acl->check('Milton', 'smash', 'read'));
|
$this->assertFalse($this->Acl->check('Milton', 'smash', 'read'));
|
||||||
$this->assertFalse($this->Acl->check('Milton', 'current', 'update'));
|
$this->assertFalse($this->Acl->check('Milton', 'current', 'update'));
|
||||||
|
|
||||||
$this->expectError("DbAcl::check() - Failed ARO/ACO node lookup in permissions check. Node references:\nAro: WRONG\nAco: tpsReports");
|
|
||||||
$this->assertFalse($this->Acl->check('WRONG', 'tpsReports', 'read'));
|
|
||||||
|
|
||||||
$this->expectError("ACO permissions key foobar does not exist in DbAcl::check()");
|
|
||||||
$this->assertFalse($this->Acl->check('Lumbergh', 'smash', 'foobar'));
|
|
||||||
|
|
||||||
$this->expectError("DbAcl::check() - Failed ARO/ACO node lookup in permissions check. Node references:\nAro: users\nAco: NonExistant");
|
|
||||||
$this->assertFalse($this->Acl->check('users', 'NonExistant', 'read'));
|
|
||||||
|
|
||||||
$this->assertFalse($this->Acl->check(null, 'printers', 'create'));
|
$this->assertFalse($this->Acl->check(null, 'printers', 'create'));
|
||||||
$this->assertFalse($this->Acl->check('managers', null, 'read'));
|
$this->assertFalse($this->Acl->check('managers', null, 'read'));
|
||||||
|
|
||||||
|
@ -497,6 +497,39 @@ class DbAclTestCase extends CakeTestCase {
|
||||||
$this->assertFalse($this->Acl->check('root/users/Milton', 'smash', 'delete'));
|
$this->assertFalse($this->Acl->check('root/users/Milton', 'smash', 'delete'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testCheckInvalidNode method
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCheckInvalidNode() {
|
||||||
|
$this->expectError();
|
||||||
|
$this->assertFalse($this->Acl->check('WRONG', 'tpsReports', 'read'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testCheckInvalidPermission method
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCheckInvalidPermission() {
|
||||||
|
$this->expectError();
|
||||||
|
$this->assertFalse($this->Acl->check('Lumbergh', 'smash', 'foobar'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testCheckMissingPermission method
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCheckMissingPermission() {
|
||||||
|
$this->expectError();
|
||||||
|
$this->assertFalse($this->Acl->check('users', 'NonExistant', 'read'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testDbAclCascadingDeny function
|
* testDbAclCascadingDeny function
|
||||||
*
|
*
|
||||||
|
@ -541,7 +574,7 @@ class DbAclTestCase extends CakeTestCase {
|
||||||
$expected = '-1';
|
$expected = '-1';
|
||||||
$this->assertEqual($result[0]['PermissionTwoTest']['_delete'], $expected);
|
$this->assertEqual($result[0]['PermissionTwoTest']['_delete'], $expected);
|
||||||
|
|
||||||
$this->expectError('DbAcl::allow() - Invalid node');
|
$this->expectError();
|
||||||
$this->assertFalse($this->Acl->deny('Lumbergh', 'ROOT/tpsReports/DoesNotExist', 'create'));
|
$this->assertFalse($this->Acl->deny('Lumbergh', 'ROOT/tpsReports/DoesNotExist', 'create'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -606,7 +639,7 @@ class DbAclTestCase extends CakeTestCase {
|
||||||
$this->assertTrue($this->Acl->check('Micheal', 'view', 'update'));
|
$this->assertTrue($this->Acl->check('Micheal', 'view', 'update'));
|
||||||
$this->assertFalse($this->Acl->check('Micheal', 'view', 'delete'));
|
$this->assertFalse($this->Acl->check('Micheal', 'view', 'delete'));
|
||||||
|
|
||||||
$this->expectError('DbAcl::allow() - Invalid node');
|
$this->expectError();
|
||||||
$this->assertFalse($this->Acl->allow('Peter', 'ROOT/tpsReports/DoesNotExist', 'create'));
|
$this->assertFalse($this->Acl->allow('Peter', 'ROOT/tpsReports/DoesNotExist', 'create'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -627,7 +660,7 @@ class DbAclTestCase extends CakeTestCase {
|
||||||
$this->assertFalse($this->Acl->check('Samir', 'printers', 'read'));
|
$this->assertFalse($this->Acl->check('Samir', 'printers', 'read'));
|
||||||
$this->assertFalse($this->Acl->check('Peter', 'printers', 'read'));
|
$this->assertFalse($this->Acl->check('Peter', 'printers', 'read'));
|
||||||
|
|
||||||
$this->expectError('DbAcl::allow() - Invalid node');
|
$this->expectError();
|
||||||
$this->assertFalse($this->Acl->deny('Bobs', 'ROOT/printers/DoesNotExist', 'create'));
|
$this->assertFalse($this->Acl->deny('Bobs', 'ROOT/printers/DoesNotExist', 'create'));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AllComponentsTest file
|
||||||
|
*
|
||||||
|
* PHP 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||||
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases
|
||||||
|
* @since CakePHP(tm) v 2.0
|
||||||
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AllComponentsTest class
|
||||||
|
*
|
||||||
|
* This test group will run component class tests
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.cases
|
||||||
|
*/
|
||||||
|
class AllComponentsTest extends PHPUnit_Framework_TestSuite {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* suite method, defines tests for this suite.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function suite() {
|
||||||
|
$suite = new PHPUnit_Framework_TestSuite('All component class tests');
|
||||||
|
|
||||||
|
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'controller' . DS . 'component.test.php');
|
||||||
|
|
||||||
|
$iterator = new DirectoryIterator(CORE_TEST_CASES . DS . 'libs' . DS . 'controller' . DS . 'components');
|
||||||
|
foreach ($iterator as $i => $file) {
|
||||||
|
if (!$file->isDot()) {
|
||||||
|
$suite->addTestfile($file->getPathname());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $suite;
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,8 +21,6 @@ App::import('Component', array('Auth', 'Acl'));
|
||||||
App::import('Model', 'DbAcl');
|
App::import('Model', 'DbAcl');
|
||||||
App::import('Core', 'Xml');
|
App::import('Core', 'Xml');
|
||||||
|
|
||||||
Mock::generate('AclComponent', 'AuthTestMockAclComponent');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TestAuthComponent class
|
* TestAuthComponent class
|
||||||
*
|
*
|
||||||
|
@ -479,12 +477,14 @@ class AuthTest extends CakeTestCase {
|
||||||
* @access public
|
* @access public
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function startTest() {
|
function setUp() {
|
||||||
$this->_server = $_SERVER;
|
$this->_server = $_SERVER;
|
||||||
$this->_env = $_ENV;
|
$this->_env = $_ENV;
|
||||||
|
|
||||||
$this->_securitySalt = Configure::read('Security.salt');
|
$this->_securitySalt = Configure::read('Security.salt');
|
||||||
Configure::write('Security.salt', 'JfIxfs2guVoUubWDYhG93b0qyJfIxfs2guwvniR2G0FgaC9mi');
|
$this->_securityCipher = Configure::read('Security.cipherSeed');
|
||||||
|
Configure::write('Security.salt', 'YJfIxfs2guVoUubWDYhG93b0qyJfIxfs2guwvniR2G0FgaC9mi');
|
||||||
|
Configure::write('Security.cipherSeed', 770011223369876);
|
||||||
|
|
||||||
$this->_acl = Configure::read('Acl');
|
$this->_acl = Configure::read('Acl');
|
||||||
Configure::write('Acl.database', 'test_suite');
|
Configure::write('Acl.database', 'test_suite');
|
||||||
|
@ -513,11 +513,12 @@ class AuthTest extends CakeTestCase {
|
||||||
* @access public
|
* @access public
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function endTest() {
|
function tearDown() {
|
||||||
$_SERVER = $this->_server;
|
$_SERVER = $this->_server;
|
||||||
$_ENV = $this->_env;
|
$_ENV = $this->_env;
|
||||||
Configure::write('Acl', $this->_acl);
|
Configure::write('Acl', $this->_acl);
|
||||||
Configure::write('Security.salt', $this->_securitySalt);
|
Configure::write('Security.salt', $this->_securitySalt);
|
||||||
|
Configure::write('Security.cipherSeed', $this->_securityCipher);
|
||||||
|
|
||||||
$this->Controller->Session->delete('Auth');
|
$this->Controller->Session->delete('Auth');
|
||||||
$this->Controller->Session->delete('Message.auth');
|
$this->Controller->Session->delete('Message.auth');
|
||||||
|
@ -598,7 +599,7 @@ class AuthTest extends CakeTestCase {
|
||||||
$this->Controller->Auth->startup($this->Controller);
|
$this->Controller->Auth->startup($this->Controller);
|
||||||
|
|
||||||
$user = $this->Controller->Auth->user();
|
$user = $this->Controller->Auth->user();
|
||||||
$this->assertFalse($user);
|
$this->assertNull($user);
|
||||||
$this->Controller->Session->delete('Auth');
|
$this->Controller->Session->delete('Auth');
|
||||||
|
|
||||||
$this->Controller->request->data['AuthUser'] = array(
|
$this->Controller->request->data['AuthUser'] = array(
|
||||||
|
@ -608,7 +609,7 @@ class AuthTest extends CakeTestCase {
|
||||||
$this->Controller->Auth->startup($this->Controller);
|
$this->Controller->Auth->startup($this->Controller);
|
||||||
|
|
||||||
$user = $this->Controller->Auth->user();
|
$user = $this->Controller->Auth->user();
|
||||||
$this->assertFalse($user);
|
$this->assertNull($user);
|
||||||
$this->Controller->Session->delete('Auth');
|
$this->Controller->Session->delete('Auth');
|
||||||
|
|
||||||
$this->Controller->request->data['AuthUser'] = array(
|
$this->Controller->request->data['AuthUser'] = array(
|
||||||
|
@ -618,7 +619,7 @@ class AuthTest extends CakeTestCase {
|
||||||
$this->Controller->Auth->startup($this->Controller);
|
$this->Controller->Auth->startup($this->Controller);
|
||||||
|
|
||||||
$user = $this->Controller->Auth->user();
|
$user = $this->Controller->Auth->user();
|
||||||
$this->assertFalse($user);
|
$this->assertNull($user);
|
||||||
$this->Controller->Session->delete('Auth');
|
$this->Controller->Session->delete('Auth');
|
||||||
|
|
||||||
$this->Controller->Auth->userModel = 'UuidUser';
|
$this->Controller->Auth->userModel = 'UuidUser';
|
||||||
|
@ -664,7 +665,7 @@ class AuthTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testAuthorizeFalse() {
|
function testAuthorizeFalse() {
|
||||||
$this->AuthUser =& new AuthUser();
|
$this->AuthUser = new AuthUser();
|
||||||
$user = $this->AuthUser->find();
|
$user = $this->AuthUser->find();
|
||||||
$this->Controller->Session->write('Auth', $user);
|
$this->Controller->Session->write('Auth', $user);
|
||||||
$this->Controller->Auth->userModel = 'AuthUser';
|
$this->Controller->Auth->userModel = 'AuthUser';
|
||||||
|
@ -752,13 +753,13 @@ class AuthTest extends CakeTestCase {
|
||||||
$this->Controller->Acl->Aro->id = null;
|
$this->Controller->Acl->Aro->id = null;
|
||||||
$this->Controller->Acl->Aro->create(array('alias' => 'Roles'));
|
$this->Controller->Acl->Aro->create(array('alias' => 'Roles'));
|
||||||
$result = $this->Controller->Acl->Aro->save();
|
$result = $this->Controller->Acl->Aro->save();
|
||||||
$this->assertTrue($result);
|
$this->assertFalse(empty($result));
|
||||||
|
|
||||||
$parent = $this->Controller->Acl->Aro->id;
|
$parent = $this->Controller->Acl->Aro->id;
|
||||||
|
|
||||||
$this->Controller->Acl->Aro->create(array('parent_id' => $parent, 'alias' => 'Admin'));
|
$this->Controller->Acl->Aro->create(array('parent_id' => $parent, 'alias' => 'Admin'));
|
||||||
$result = $this->Controller->Acl->Aro->save();
|
$result = $this->Controller->Acl->Aro->save();
|
||||||
$this->assertTrue($result);
|
$this->assertFalse(empty($result));
|
||||||
|
|
||||||
$parent = $this->Controller->Acl->Aro->id;
|
$parent = $this->Controller->Acl->Aro->id;
|
||||||
|
|
||||||
|
@ -766,17 +767,17 @@ class AuthTest extends CakeTestCase {
|
||||||
'model' => 'AuthUser', 'parent_id' => $parent, 'foreign_key' => 1, 'alias'=> 'mariano'
|
'model' => 'AuthUser', 'parent_id' => $parent, 'foreign_key' => 1, 'alias'=> 'mariano'
|
||||||
));
|
));
|
||||||
$result = $this->Controller->Acl->Aro->save();
|
$result = $this->Controller->Acl->Aro->save();
|
||||||
$this->assertTrue($result);
|
$this->assertFalse(empty($result));
|
||||||
|
|
||||||
$this->Controller->Acl->Aco->create(array('alias' => 'Root'));
|
$this->Controller->Acl->Aco->create(array('alias' => 'Root'));
|
||||||
$result = $this->Controller->Acl->Aco->save();
|
$result = $this->Controller->Acl->Aco->save();
|
||||||
$this->assertTrue($result);
|
$this->assertFalse(empty($result));
|
||||||
|
|
||||||
$parent = $this->Controller->Acl->Aco->id;
|
$parent = $this->Controller->Acl->Aco->id;
|
||||||
|
|
||||||
$this->Controller->Acl->Aco->create(array('parent_id' => $parent, 'alias' => 'AuthTest'));
|
$this->Controller->Acl->Aco->create(array('parent_id' => $parent, 'alias' => 'AuthTest'));
|
||||||
$result = $this->Controller->Acl->Aco->save();
|
$result = $this->Controller->Acl->Aco->save();
|
||||||
$this->assertTrue($result);
|
$this->assertFalse(empty($result));
|
||||||
|
|
||||||
$this->Controller->Acl->allow('Roles/Admin', 'Root');
|
$this->Controller->Acl->allow('Roles/Admin', 'Root');
|
||||||
$this->Controller->Acl->allow('Roles/Admin', 'Root/AuthTest');
|
$this->Controller->Acl->allow('Roles/Admin', 'Root/AuthTest');
|
||||||
|
@ -807,8 +808,8 @@ class AuthTest extends CakeTestCase {
|
||||||
$this->Controller->request['controller'] = 'auth_test';
|
$this->Controller->request['controller'] = 'auth_test';
|
||||||
$this->Controller->request['action'] = 'add';
|
$this->Controller->request['action'] = 'add';
|
||||||
|
|
||||||
$this->Controller->Acl = new AuthTestMockAclComponent();
|
$this->Controller->Acl = $this->getMock('AclComponent');
|
||||||
$this->Controller->Acl->setReturnValue('check', true);
|
$this->Controller->Acl->expects($this->atLeastOnce())->method('check')->will($this->returnValue(true));
|
||||||
|
|
||||||
$this->Controller->Auth->initialize($this->Controller);
|
$this->Controller->Auth->initialize($this->Controller);
|
||||||
|
|
||||||
|
@ -816,9 +817,7 @@ class AuthTest extends CakeTestCase {
|
||||||
$this->Controller->Auth->authorize = 'actions';
|
$this->Controller->Auth->authorize = 'actions';
|
||||||
$this->Controller->Auth->actionPath = 'Root/';
|
$this->Controller->Auth->actionPath = 'Root/';
|
||||||
|
|
||||||
$this->Controller->Acl->expectAt(0, 'check', array(
|
$this->Controller->Acl->expects($this->at(0))->method('check')->with($user, 'Root/AuthTest/add');
|
||||||
$user, 'Root/AuthTest/add'
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->Controller->Auth->startup($this->Controller);
|
$this->Controller->Auth->startup($this->Controller);
|
||||||
$this->assertTrue($this->Controller->Auth->isAuthorized());
|
$this->assertTrue($this->Controller->Auth->isAuthorized());
|
||||||
|
@ -1398,7 +1397,7 @@ class AuthTest extends CakeTestCase {
|
||||||
), true);
|
), true);
|
||||||
App::objects('plugin', null, false);
|
App::objects('plugin', null, false);
|
||||||
|
|
||||||
$PluginModel =& ClassRegistry::init('TestPlugin.TestPluginAuthUser');
|
$PluginModel = ClassRegistry::init('TestPlugin.TestPluginAuthUser');
|
||||||
$user['id'] = 1;
|
$user['id'] = 1;
|
||||||
$user['username'] = 'gwoo';
|
$user['username'] = 'gwoo';
|
||||||
$user['password'] = Security::hash(Configure::read('Security.salt') . 'cake');
|
$user['password'] = Security::hash(Configure::read('Security.salt') . 'cake');
|
||||||
|
@ -1458,7 +1457,7 @@ class AuthTest extends CakeTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
$Dispatcher =& new Dispatcher();
|
$Dispatcher = new Dispatcher();
|
||||||
$Dispatcher->dispatch('/ajax_auth/add', array('return' => 1));
|
$Dispatcher->dispatch('/ajax_auth/add', array('return' => 1));
|
||||||
$result = ob_get_clean();
|
$result = ob_get_clean();
|
||||||
$this->assertEqual("Ajax!\nthis is the test element", str_replace("\r\n", "\n", $result));
|
$this->assertEqual("Ajax!\nthis is the test element", str_replace("\r\n", "\n", $result));
|
||||||
|
@ -1511,8 +1510,10 @@ class AuthTest extends CakeTestCase {
|
||||||
function testShutDown() {
|
function testShutDown() {
|
||||||
$this->Controller->Auth->initialize($this->Controller, array('_loggedIn' => true));
|
$this->Controller->Auth->initialize($this->Controller, array('_loggedIn' => true));
|
||||||
$this->Controller->Session->write('Auth.redirect', 'foo');
|
$this->Controller->Session->write('Auth.redirect', 'foo');
|
||||||
|
$this->Controller->Auth->loggedIn(true);
|
||||||
|
|
||||||
$this->Controller->Auth->shutdown($this->Controller);
|
$this->Controller->Auth->shutdown($this->Controller);
|
||||||
$this->assertFalse($this->Controller->Session->read('Auth.redirect'));
|
$this->assertNull($this->Controller->Session->read('Auth.redirect'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1542,8 +1543,10 @@ class AuthTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testComponentSettings() {
|
function testComponentSettings() {
|
||||||
|
|
||||||
$request = new CakeRequest(null, false);
|
$request = new CakeRequest(null, false);
|
||||||
$this->Controller = new AuthTestController($request);
|
$this->Controller = new AuthTestController($request);
|
||||||
|
|
||||||
$this->Controller->components = array(
|
$this->Controller->components = array(
|
||||||
'Auth' => array(
|
'Auth' => array(
|
||||||
'fields' => array('username' => 'email', 'password' => 'password'),
|
'fields' => array('username' => 'email', 'password' => 'password'),
|
||||||
|
@ -1557,7 +1560,7 @@ class AuthTest extends CakeTestCase {
|
||||||
$this->Controller->Component->initialize($this->Controller);
|
$this->Controller->Component->initialize($this->Controller);
|
||||||
Router::reload();
|
Router::reload();
|
||||||
|
|
||||||
$this->AuthUserCustomField =& new AuthUserCustomField();
|
$this->AuthUserCustomField = new AuthUserCustomField();
|
||||||
$user = array(
|
$user = array(
|
||||||
'id' => 1, 'email' => 'harking@example.com',
|
'id' => 1, 'email' => 'harking@example.com',
|
||||||
'password' => Security::hash(Configure::read('Security.salt') . 'cake'
|
'password' => Security::hash(Configure::read('Security.salt') . 'cake'
|
||||||
|
|
|
@ -74,13 +74,12 @@ class CookieComponentTest extends CakeTestCase {
|
||||||
* @access public
|
* @access public
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function start() {
|
function setUp() {
|
||||||
$this->Controller = new CookieComponentTestController();
|
$this->Controller = new CookieComponentTestController();
|
||||||
$this->Controller->constructClasses();
|
$this->Controller->constructClasses();
|
||||||
$this->Controller->Component->initialize($this->Controller);
|
$this->Controller->Component->initialize($this->Controller);
|
||||||
$this->Controller->beforeFilter();
|
$this->Controller->beforeFilter();
|
||||||
$this->Controller->Component->startup($this->Controller);
|
$this->Controller->Component->startup($this->Controller);
|
||||||
$this->Controller->Cookie->destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,10 +88,22 @@ class CookieComponentTest extends CakeTestCase {
|
||||||
* @access public
|
* @access public
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function end() {
|
function tearDown() {
|
||||||
$this->Controller->Cookie->destroy();
|
$this->Controller->Cookie->destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function _setCookieData() {
|
||||||
|
$this->Controller->Cookie->write(array('Encrytped_array' => array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')));
|
||||||
|
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.name' => 'CakePHP'));
|
||||||
|
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.version' => '1.2.0.x'));
|
||||||
|
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.tag' => 'CakePHP Rocks!'));
|
||||||
|
|
||||||
|
$this->Controller->Cookie->write(array('Plain_array' => array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')), null, false);
|
||||||
|
$this->Controller->Cookie->write(array('Plain_multi_cookies.name' => 'CakePHP'), null, false);
|
||||||
|
$this->Controller->Cookie->write(array('Plain_multi_cookies.version' => '1.2.0.x'), null, false);
|
||||||
|
$this->Controller->Cookie->write(array('Plain_multi_cookies.tag' => 'CakePHP Rocks!'), null, false);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test that initialize sets settings from components array
|
* test that initialize sets settings from components array
|
||||||
*
|
*
|
||||||
|
@ -118,19 +129,6 @@ class CookieComponentTest extends CakeTestCase {
|
||||||
$this->assertEqual($this->Controller->Cookie->name, 'CakeTestCookie');
|
$this->assertEqual($this->Controller->Cookie->name, 'CakeTestCookie');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* testSettingEncryptedCookieData
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testSettingEncryptedCookieData() {
|
|
||||||
$this->Controller->Cookie->write('Encrytped_array', array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!'));
|
|
||||||
$this->Controller->Cookie->write('Encrytped_multi_cookies.name', 'CakePHP');
|
|
||||||
$this->Controller->Cookie->write('Encrytped_multi_cookies.version', '1.2.0.x');
|
|
||||||
$this->Controller->Cookie->write('Encrytped_multi_cookies.tag', 'CakePHP Rocks!');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testReadEncryptedCookieData
|
* testReadEncryptedCookieData
|
||||||
*
|
*
|
||||||
|
@ -138,6 +136,7 @@ class CookieComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testReadEncryptedCookieData() {
|
function testReadEncryptedCookieData() {
|
||||||
|
$this->_setCookieData();
|
||||||
$data = $this->Controller->Cookie->read('Encrytped_array');
|
$data = $this->Controller->Cookie->read('Encrytped_array');
|
||||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||||
$this->assertEqual($data, $expected);
|
$this->assertEqual($data, $expected);
|
||||||
|
@ -147,19 +146,6 @@ class CookieComponentTest extends CakeTestCase {
|
||||||
$this->assertEqual($data, $expected);
|
$this->assertEqual($data, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* testSettingPlainCookieData
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testSettingPlainCookieData() {
|
|
||||||
$this->Controller->Cookie->write('Plain_array', array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!'), false);
|
|
||||||
$this->Controller->Cookie->write('Plain_multi_cookies.name', 'CakePHP', false);
|
|
||||||
$this->Controller->Cookie->write('Plain_multi_cookies.version', '1.2.0.x', false);
|
|
||||||
$this->Controller->Cookie->write('Plain_multi_cookies.tag', 'CakePHP Rocks!', false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testReadPlainCookieData
|
* testReadPlainCookieData
|
||||||
*
|
*
|
||||||
|
@ -167,6 +153,8 @@ class CookieComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testReadPlainCookieData() {
|
function testReadPlainCookieData() {
|
||||||
|
$this->_setCookieData();
|
||||||
|
|
||||||
$data = $this->Controller->Cookie->read('Plain_array');
|
$data = $this->Controller->Cookie->read('Plain_array');
|
||||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||||
$this->assertEqual($data, $expected);
|
$this->assertEqual($data, $expected);
|
||||||
|
@ -201,6 +189,7 @@ class CookieComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testReadingCookieValue() {
|
function testReadingCookieValue() {
|
||||||
|
$this->_setCookieData();
|
||||||
$data = $this->Controller->Cookie->read();
|
$data = $this->Controller->Cookie->read();
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'Encrytped_array' => array(
|
'Encrytped_array' => array(
|
||||||
|
@ -229,6 +218,7 @@ class CookieComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testDeleteCookieValue() {
|
function testDeleteCookieValue() {
|
||||||
|
$this->_setCookieData();
|
||||||
$this->Controller->Cookie->delete('Encrytped_multi_cookies.name');
|
$this->Controller->Cookie->delete('Encrytped_multi_cookies.name');
|
||||||
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
|
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
|
||||||
$expected = array('version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
$expected = array('version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||||
|
@ -236,8 +226,7 @@ class CookieComponentTest extends CakeTestCase {
|
||||||
|
|
||||||
$this->Controller->Cookie->delete('Encrytped_array');
|
$this->Controller->Cookie->delete('Encrytped_array');
|
||||||
$data = $this->Controller->Cookie->read('Encrytped_array');
|
$data = $this->Controller->Cookie->read('Encrytped_array');
|
||||||
$expected = array();
|
$this->assertNull($data);
|
||||||
$this->assertEqual($data, $expected);
|
|
||||||
|
|
||||||
$this->Controller->Cookie->delete('Plain_multi_cookies.name');
|
$this->Controller->Cookie->delete('Plain_multi_cookies.name');
|
||||||
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
|
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
|
||||||
|
@ -246,28 +235,7 @@ class CookieComponentTest extends CakeTestCase {
|
||||||
|
|
||||||
$this->Controller->Cookie->delete('Plain_array');
|
$this->Controller->Cookie->delete('Plain_array');
|
||||||
$data = $this->Controller->Cookie->read('Plain_array');
|
$data = $this->Controller->Cookie->read('Plain_array');
|
||||||
$expected = array();
|
$this->assertNull($data);
|
||||||
$this->assertEqual($data, $expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* testSettingCookiesWithArray
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testSettingCookiesWithArray() {
|
|
||||||
$this->Controller->Cookie->destroy();
|
|
||||||
|
|
||||||
$this->Controller->Cookie->write(array('Encrytped_array' => array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')));
|
|
||||||
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.name' => 'CakePHP'));
|
|
||||||
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.version' => '1.2.0.x'));
|
|
||||||
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.tag' => 'CakePHP Rocks!'));
|
|
||||||
|
|
||||||
$this->Controller->Cookie->write(array('Plain_array' => array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')), null, false);
|
|
||||||
$this->Controller->Cookie->write(array('Plain_multi_cookies.name' => 'CakePHP'), null, false);
|
|
||||||
$this->Controller->Cookie->write(array('Plain_multi_cookies.version' => '1.2.0.x'), null, false);
|
|
||||||
$this->Controller->Cookie->write(array('Plain_multi_cookies.tag' => 'CakePHP Rocks!'), null, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -277,6 +245,8 @@ class CookieComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testReadingCookieArray() {
|
function testReadingCookieArray() {
|
||||||
|
$this->_setCookieData();
|
||||||
|
|
||||||
$data = $this->Controller->Cookie->read('Encrytped_array.name');
|
$data = $this->Controller->Cookie->read('Encrytped_array.name');
|
||||||
$expected = 'CakePHP';
|
$expected = 'CakePHP';
|
||||||
$this->assertEqual($data, $expected);
|
$this->assertEqual($data, $expected);
|
||||||
|
@ -333,23 +303,18 @@ class CookieComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testReadingCookieDataOnStartup() {
|
function testReadingCookieDataOnStartup() {
|
||||||
$this->Controller->Cookie->destroy();
|
|
||||||
|
|
||||||
$data = $this->Controller->Cookie->read('Encrytped_array');
|
$data = $this->Controller->Cookie->read('Encrytped_array');
|
||||||
$expected = array();
|
$this->assertNull($data);
|
||||||
$this->assertEqual($data, $expected);
|
|
||||||
|
|
||||||
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
|
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
|
||||||
$expected = array();
|
$this->assertNull($data);
|
||||||
$this->assertEqual($data, $expected);
|
|
||||||
|
|
||||||
$data = $this->Controller->Cookie->read('Plain_array');
|
$data = $this->Controller->Cookie->read('Plain_array');
|
||||||
$expected = array();
|
$this->assertNull($data);
|
||||||
$this->assertEqual($data, $expected);
|
|
||||||
|
|
||||||
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
|
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
|
||||||
$expected = array();
|
$this->assertNull($data);
|
||||||
$this->assertEqual($data, $expected);
|
|
||||||
|
|
||||||
$_COOKIE['CakeTestCookie'] = array(
|
$_COOKIE['CakeTestCookie'] = array(
|
||||||
'Encrytped_array' => $this->__encrypt(array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')),
|
'Encrytped_array' => $this->__encrypt(array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')),
|
||||||
|
@ -391,19 +356,19 @@ class CookieComponentTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testReadingCookieDataWithoutStartup() {
|
function testReadingCookieDataWithoutStartup() {
|
||||||
$data = $this->Controller->Cookie->read('Encrytped_array');
|
$data = $this->Controller->Cookie->read('Encrytped_array');
|
||||||
$expected = array();
|
$expected = null;
|
||||||
$this->assertEqual($data, $expected);
|
$this->assertEqual($data, $expected);
|
||||||
|
|
||||||
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
|
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
|
||||||
$expected = array();
|
$expected = null;
|
||||||
$this->assertEqual($data, $expected);
|
$this->assertEqual($data, $expected);
|
||||||
|
|
||||||
$data = $this->Controller->Cookie->read('Plain_array');
|
$data = $this->Controller->Cookie->read('Plain_array');
|
||||||
$expected = array();
|
$expected = null;
|
||||||
$this->assertEqual($data, $expected);
|
$this->assertEqual($data, $expected);
|
||||||
|
|
||||||
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
|
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
|
||||||
$expected = array();
|
$expected = null;
|
||||||
$this->assertEqual($data, $expected);
|
$this->assertEqual($data, $expected);
|
||||||
|
|
||||||
$_COOKIE['CakeTestCookie'] = array(
|
$_COOKIE['CakeTestCookie'] = array(
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||||
*/
|
*/
|
||||||
App::import('Component', 'Email');
|
App::import('Component', 'Email');
|
||||||
|
App::import('Core', 'CakeSocket');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EmailTestComponent class
|
* EmailTestComponent class
|
||||||
|
@ -45,8 +46,8 @@ class EmailTestComponent extends EmailComponent {
|
||||||
* @access public
|
* @access public
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function setConnectionSocket(&$socket) {
|
function setConnectionSocket($socket) {
|
||||||
$this->__smtpConnection = $socket;
|
$this->_smtpConnection = $socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,7 +57,7 @@ class EmailTestComponent extends EmailComponent {
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function getConnectionSocket() {
|
function getConnectionSocket() {
|
||||||
return $this->__smtpConnection;
|
return $this->_smtpConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,7 +67,7 @@ class EmailTestComponent extends EmailComponent {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function setHeaders($headers) {
|
function setHeaders($headers) {
|
||||||
$this->__header += $headers;
|
$this->_header += $headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,7 +77,10 @@ class EmailTestComponent extends EmailComponent {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function getHeaders() {
|
function getHeaders() {
|
||||||
return $this->__header;
|
if (empty($this->_header)) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
return $this->_header;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,7 +90,7 @@ class EmailTestComponent extends EmailComponent {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function setBoundary() {
|
function setBoundary() {
|
||||||
$this->__createBoundary();
|
$this->_createBoundary();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,7 +100,10 @@ class EmailTestComponent extends EmailComponent {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function getBoundary() {
|
function getBoundary() {
|
||||||
return $this->__boundary;
|
if (empty($this->_boundary)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return $this->_boundary;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -106,7 +113,10 @@ class EmailTestComponent extends EmailComponent {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function getMessage() {
|
function getMessage() {
|
||||||
return $this->__message;
|
if (empty($this->_message)) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
return $this->_message;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -116,7 +126,7 @@ class EmailTestComponent extends EmailComponent {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function _getMessage() {
|
function _getMessage() {
|
||||||
return $this->__message;
|
return $this->_message;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -205,11 +215,9 @@ class EmailComponentTest extends CakeTestCase {
|
||||||
$this->_appEncoding = Configure::read('App.encoding');
|
$this->_appEncoding = Configure::read('App.encoding');
|
||||||
Configure::write('App.encoding', 'UTF-8');
|
Configure::write('App.encoding', 'UTF-8');
|
||||||
|
|
||||||
$this->Controller =& new EmailTestController();
|
$this->Controller = new EmailTestController();
|
||||||
|
|
||||||
restore_error_handler();
|
$this->Controller->Component->init($this->Controller);
|
||||||
@$this->Controller->Component->init($this->Controller);
|
|
||||||
set_error_handler('simpleTestErrorHandler');
|
|
||||||
|
|
||||||
$this->Controller->EmailTest->initialize($this->Controller, array());
|
$this->Controller->EmailTest->initialize($this->Controller, array());
|
||||||
ClassRegistry::addObject('view', new View($this->Controller));
|
ClassRegistry::addObject('view', new View($this->Controller));
|
||||||
|
@ -229,7 +237,6 @@ class EmailComponentTest extends CakeTestCase {
|
||||||
Configure::write('App.encoding', $this->_appEncoding);
|
Configure::write('App.encoding', $this->_appEncoding);
|
||||||
App::build();
|
App::build();
|
||||||
$this->Controller->Session->delete('Message');
|
$this->Controller->Session->delete('Message');
|
||||||
restore_error_handler();
|
|
||||||
ClassRegistry::flush();
|
ClassRegistry::flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -635,18 +642,18 @@ TEXTBLOC;
|
||||||
function testSmtpSendSocket() {
|
function testSmtpSendSocket() {
|
||||||
$this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost');
|
$this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost');
|
||||||
|
|
||||||
$this->Controller->EmailTest->smtpOptions['timeout'] = 10;
|
$socket = new CakeSocket(array_merge(array('protocol'=>'smtp'), $this->Controller->EmailTest->smtpOptions));
|
||||||
$socket =& new CakeSocket(array_merge(array('protocol'=>'smtp'), $this->Controller->EmailTest->smtpOptions));
|
|
||||||
$this->Controller->EmailTest->setConnectionSocket($socket);
|
$this->Controller->EmailTest->setConnectionSocket($socket);
|
||||||
|
|
||||||
$this->assertTrue($this->Controller->EmailTest->getConnectionSocket());
|
$this->assertSame($this->Controller->EmailTest->getConnectionSocket(), $socket);
|
||||||
|
|
||||||
$response = $this->Controller->EmailTest->smtpSend('HELO', '250');
|
$response = $this->Controller->EmailTest->smtpSend('HELO', '250');
|
||||||
$this->assertPattern('/501 Syntax: HELO hostname/', $this->Controller->EmailTest->smtpError);
|
$this->assertPattern('/501 Syntax: HELO hostname/', $this->Controller->EmailTest->smtpError);
|
||||||
|
|
||||||
$this->Controller->EmailTest->reset();
|
$this->Controller->EmailTest->reset();
|
||||||
$response = $this->Controller->EmailTest->smtpSend('HELO somehostname', '250');
|
$response = $this->Controller->EmailTest->smtpSend('HELO somehostname', '250');
|
||||||
$this->assertNoPattern('/501 Syntax: HELO hostname/', $this->Controller->EmailTest->smtpError);
|
|
||||||
|
$this->assertNoPattern('/501 Syntax: HELO hostname/', (string)$this->Controller->EmailTest->smtpError);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -682,7 +689,7 @@ TEXTBLOC;
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testSendDebugWithNoSessions() {
|
function testSendDebugWithNoSessions() {
|
||||||
$session =& $this->Controller->Session;
|
$session = $this->Controller->Session;
|
||||||
unset($this->Controller->Session);
|
unset($this->Controller->Session);
|
||||||
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
||||||
$this->Controller->EmailTest->from = 'noreply@example.com';
|
$this->Controller->EmailTest->from = 'noreply@example.com';
|
||||||
|
|
|
@ -20,10 +20,6 @@
|
||||||
App::import('Controller', 'Controller', false);
|
App::import('Controller', 'Controller', false);
|
||||||
App::import('Component', array('RequestHandler'));
|
App::import('Component', array('RequestHandler'));
|
||||||
|
|
||||||
Mock::generatePartial('RequestHandlerComponent', 'NoStopRequestHandler', array('_stop'));
|
|
||||||
Mock::generate('CakeRequest', 'RequestHandlerMockCakeRequest');
|
|
||||||
Mock::generatePartial('Controller', 'RequestHandlerMockController', array('header'));
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RequestHandlerTestController class
|
* RequestHandlerTestController class
|
||||||
*
|
*
|
||||||
|
@ -535,9 +531,9 @@ class RequestHandlerComponentTest extends CakeTestCase {
|
||||||
), true);
|
), true);
|
||||||
|
|
||||||
$this->Controller->request = new CakeRequest('posts/index');
|
$this->Controller->request = new CakeRequest('posts/index');
|
||||||
$this->Controller->RequestHandler = new NoStopRequestHandler($this);
|
$this->Controller->RequestHandler = $this->getMock('RequestHandlerComponent', array('_stop'));
|
||||||
$this->Controller->RequestHandler->request = $this->Controller->request;
|
$this->Controller->RequestHandler->request = $this->Controller->request;
|
||||||
$this->Controller->RequestHandler->expectOnce('_stop');
|
$this->Controller->RequestHandler->expects($this->once())->method('_stop');
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
$this->Controller->RequestHandler->beforeRedirect(
|
$this->Controller->RequestHandler->beforeRedirect(
|
||||||
|
@ -595,7 +591,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
|
||||||
array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/')
|
array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/')
|
||||||
));
|
));
|
||||||
|
|
||||||
$RequestHandler =& new NoStopRequestHandler();
|
$RequestHandler = $this->getMock('RequestHandlerComponent', array('_stop'));
|
||||||
$RequestHandler->request = new CakeRequest('posts/index');
|
$RequestHandler->request = new CakeRequest('posts/index');
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
@ -613,12 +609,16 @@ class RequestHandlerComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testBeforeRedirectCallingHeader() {
|
function testBeforeRedirectCallingHeader() {
|
||||||
$controller =& new RequestHandlerMockController();
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
|
||||||
$RequestHandler =& new NoStopRequestHandler();
|
|
||||||
$RequestHandler->request = new RequestHandlerMockCakeRequest();
|
|
||||||
$RequestHandler->request->setReturnValue('is', true, array('ajax'));
|
|
||||||
|
|
||||||
$controller->expectOnce('header', array('HTTP/1.1 403 Forbidden'));
|
$controller = $this->getMock('Controller', array('header'));
|
||||||
|
$RequestHandler = $this->getMock('RequestHandlerComponent', array('_stop'));
|
||||||
|
$RequestHandler->request = $this->getMock('CakeRequest');
|
||||||
|
$RequestHandler->request->expects($this->once())->method('is')
|
||||||
|
->with('ajax')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
|
$controller->expects($this->once())->method('header')->with('HTTP/1.1 403 Forbidden');
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
$RequestHandler->beforeRedirect($controller, 'request_handler_test/param_method/first/second', 403);
|
$RequestHandler->beforeRedirect($controller, 'request_handler_test/param_method/first/second', 403);
|
||||||
|
|
|
@ -108,20 +108,20 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testSessionAutoStart() {
|
function testSessionAutoStart() {
|
||||||
Configure::write('Session.start', false);
|
Configure::write('Session.start', false);
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
$this->assertFalse($Session->__active);
|
$this->assertFalse($Session->active());
|
||||||
$this->assertFalse($Session->started());
|
$this->assertFalse($Session->started());
|
||||||
$Session->startup(new SessionTestController());
|
$Session->startup(new SessionTestController());
|
||||||
|
|
||||||
Configure::write('Session.start', true);
|
Configure::write('Session.start', true);
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
$this->assertTrue($Session->__active);
|
$this->assertTrue($Session->active());
|
||||||
$this->assertFalse($Session->started());
|
$this->assertFalse($Session->started());
|
||||||
$Session->startup(new SessionTestController());
|
$Session->startup(new SessionTestController());
|
||||||
$this->assertTrue(isset($_SESSION));
|
$this->assertTrue(isset($_SESSION));
|
||||||
|
|
||||||
$Object = new Object();
|
$Object = new Object();
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
$Session->start();
|
$Session->start();
|
||||||
$expected = $Session->id();
|
$expected = $Session->id();
|
||||||
|
|
||||||
|
@ -139,17 +139,17 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testSessionActivate() {
|
function testSessionActivate() {
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
|
|
||||||
$this->assertTrue($Session->__active);
|
$this->assertTrue($Session->active());
|
||||||
$this->assertNull($Session->activate());
|
$this->assertNull($Session->activate());
|
||||||
$this->assertTrue($Session->__active);
|
$this->assertTrue($Session->active());
|
||||||
|
|
||||||
Configure::write('Session.start', false);
|
Configure::write('Session.start', false);
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
$this->assertFalse($Session->__active);
|
$this->assertFalse($Session->active());
|
||||||
$this->assertNull($Session->activate());
|
$this->assertNull($Session->activate());
|
||||||
$this->assertTrue($Session->__active);
|
$this->assertTrue($Session->active());
|
||||||
Configure::write('Session.start', true);
|
Configure::write('Session.start', true);
|
||||||
$Session->destroy();
|
$Session->destroy();
|
||||||
}
|
}
|
||||||
|
@ -161,25 +161,25 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testSessionValid() {
|
function testSessionValid() {
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
|
|
||||||
$this->assertTrue($Session->valid());
|
$this->assertTrue($Session->valid());
|
||||||
|
|
||||||
$Session->_userAgent = 'rweerw';
|
$Session->userAgent('rweerw');
|
||||||
$this->assertFalse($Session->valid());
|
$this->assertFalse($Session->valid());
|
||||||
|
|
||||||
Configure::write('Session.start', false);
|
Configure::write('Session.start', false);
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
$this->assertFalse($Session->__active);
|
$this->assertFalse($Session->active());
|
||||||
$this->assertFalse($Session->valid());
|
$this->assertFalse($Session->valid());
|
||||||
Configure::write('Session.start', true);
|
Configure::write('Session.start', true);
|
||||||
|
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
$Session->time = $Session->read('Config.time') + 1;
|
$Session->time = $Session->read('Config.time') + 1;
|
||||||
$this->assertFalse($Session->valid());
|
$this->assertFalse($Session->valid());
|
||||||
|
|
||||||
Configure::write('Session.checkAgent', false);
|
Configure::write('Session.checkAgent', false);
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
$Session->time = $Session->read('Config.time') + 1;
|
$Session->time = $Session->read('Config.time') + 1;
|
||||||
$this->assertFalse($Session->valid());
|
$this->assertFalse($Session->valid());
|
||||||
Configure::write('Session.checkAgent', true);
|
Configure::write('Session.checkAgent', true);
|
||||||
|
@ -192,13 +192,13 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testSessionError() {
|
function testSessionError() {
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
|
|
||||||
$this->assertFalse($Session->error());
|
$this->assertFalse($Session->error());
|
||||||
|
|
||||||
Configure::write('Session.start', false);
|
Configure::write('Session.start', false);
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
$this->assertFalse($Session->__active);
|
$this->assertFalse($Session->active());
|
||||||
$this->assertFalse($Session->error());
|
$this->assertFalse($Session->error());
|
||||||
Configure::write('Session.start', true);
|
Configure::write('Session.start', true);
|
||||||
}
|
}
|
||||||
|
@ -210,9 +210,9 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testSessionReadWrite() {
|
function testSessionReadWrite() {
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
|
|
||||||
$this->assertFalse($Session->read('Test'));
|
$this->assertNull($Session->read('Test'));
|
||||||
|
|
||||||
$this->assertTrue($Session->write('Test', 'some value'));
|
$this->assertTrue($Session->write('Test', 'some value'));
|
||||||
$this->assertEqual($Session->read('Test'), 'some value');
|
$this->assertEqual($Session->read('Test'), 'some value');
|
||||||
|
@ -237,7 +237,7 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
$Session->delete('Test');
|
$Session->delete('Test');
|
||||||
|
|
||||||
Configure::write('Session.start', false);
|
Configure::write('Session.start', false);
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
$this->assertFalse($Session->write('Test', 'some value'));
|
$this->assertFalse($Session->write('Test', 'some value'));
|
||||||
$Session->write('Test', 'some value');
|
$Session->write('Test', 'some value');
|
||||||
$this->assertFalse($Session->read('Test'));
|
$this->assertFalse($Session->read('Test'));
|
||||||
|
@ -251,7 +251,7 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testSessionDelete() {
|
function testSessionDelete() {
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
|
|
||||||
$this->assertFalse($Session->delete('Test'));
|
$this->assertFalse($Session->delete('Test'));
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
$this->assertTrue($Session->delete('Test'));
|
$this->assertTrue($Session->delete('Test'));
|
||||||
|
|
||||||
Configure::write('Session.start', false);
|
Configure::write('Session.start', false);
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
$Session->write('Test', 'some value');
|
$Session->write('Test', 'some value');
|
||||||
$this->assertFalse($Session->delete('Test'));
|
$this->assertFalse($Session->delete('Test'));
|
||||||
Configure::write('Session.start', true);
|
Configure::write('Session.start', true);
|
||||||
|
@ -272,7 +272,7 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testSessionCheck() {
|
function testSessionCheck() {
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
|
|
||||||
$this->assertFalse($Session->check('Test'));
|
$this->assertFalse($Session->check('Test'));
|
||||||
|
|
||||||
|
@ -281,7 +281,7 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
$Session->delete('Test');
|
$Session->delete('Test');
|
||||||
|
|
||||||
Configure::write('Session.start', false);
|
Configure::write('Session.start', false);
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
$Session->write('Test', 'some value');
|
$Session->write('Test', 'some value');
|
||||||
$this->assertFalse($Session->check('Test'));
|
$this->assertFalse($Session->check('Test'));
|
||||||
Configure::write('Session.start', true);
|
Configure::write('Session.start', true);
|
||||||
|
@ -294,7 +294,7 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testSessionFlash() {
|
function testSessionFlash() {
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
|
|
||||||
$this->assertNull($Session->read('Message.flash'));
|
$this->assertNull($Session->read('Message.flash'));
|
||||||
|
|
||||||
|
@ -321,7 +321,7 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testSessionId() {
|
function testSessionId() {
|
||||||
unset($_SESSION);
|
unset($_SESSION);
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
$this->assertNull($Session->id());
|
$this->assertNull($Session->id());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,7 +332,7 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testSessionDestroy() {
|
function testSessionDestroy() {
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
|
|
||||||
$Session->write('Test', 'some value');
|
$Session->write('Test', 'some value');
|
||||||
$this->assertEqual($Session->read('Test'), 'some value');
|
$this->assertEqual($Session->read('Test'), 'some value');
|
||||||
|
@ -350,7 +350,7 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
|
|
||||||
session_destroy();
|
session_destroy();
|
||||||
Configure::write('Security.level', 'low');
|
Configure::write('Security.level', 'low');
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
$Session->write('Test', 'some value');
|
$Session->write('Test', 'some value');
|
||||||
$this->assertEqual($_SESSION['Config']['timeout'], Security::inactiveMins());
|
$this->assertEqual($_SESSION['Config']['timeout'], Security::inactiveMins());
|
||||||
$this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime);
|
$this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime);
|
||||||
|
@ -359,7 +359,7 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
|
|
||||||
session_destroy();
|
session_destroy();
|
||||||
Configure::write('Security.level', 'medium');
|
Configure::write('Security.level', 'medium');
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
$Session->write('Test', 'some value');
|
$Session->write('Test', 'some value');
|
||||||
$this->assertEqual($_SESSION['Config']['timeout'], Security::inactiveMins());
|
$this->assertEqual($_SESSION['Config']['timeout'], Security::inactiveMins());
|
||||||
$this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime);
|
$this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime);
|
||||||
|
@ -368,7 +368,7 @@ class SessionComponentTest extends CakeTestCase {
|
||||||
|
|
||||||
session_destroy();
|
session_destroy();
|
||||||
Configure::write('Security.level', 'high');
|
Configure::write('Security.level', 'high');
|
||||||
$Session =& new SessionComponent();
|
$Session = new SessionComponent();
|
||||||
$Session->write('Test', 'some value');
|
$Session->write('Test', 'some value');
|
||||||
$this->assertEqual($_SESSION['Config']['timeout'], Security::inactiveMins());
|
$this->assertEqual($_SESSION['Config']['timeout'], Security::inactiveMins());
|
||||||
$this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime);
|
$this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime);
|
||||||
|
|
|
@ -22,8 +22,6 @@ App::import('Core', 'CakeRequest');
|
||||||
App::import('Component', 'Security');
|
App::import('Component', 'Security');
|
||||||
App::import('Component', 'Cookie');
|
App::import('Component', 'Cookie');
|
||||||
|
|
||||||
Mock::generate('CakeRequest', 'ControllerMockCakeRequest');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AppController class
|
* AppController class
|
||||||
*
|
*
|
||||||
|
@ -474,6 +472,7 @@ class ControllerTest extends CakeTestCase {
|
||||||
function testConstructClasses() {
|
function testConstructClasses() {
|
||||||
$request = new CakeRequest('controller_posts/index');
|
$request = new CakeRequest('controller_posts/index');
|
||||||
$Controller = new Controller($request);
|
$Controller = new Controller($request);
|
||||||
|
|
||||||
$Controller->modelClass = 'ControllerPost';
|
$Controller->modelClass = 'ControllerPost';
|
||||||
$Controller->passedArgs[] = '1';
|
$Controller->passedArgs[] = '1';
|
||||||
$Controller->constructClasses();
|
$Controller->constructClasses();
|
||||||
|
@ -530,9 +529,8 @@ class ControllerTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testPersistent() {
|
function testPersistent() {
|
||||||
if ($this->skipIf(true, 'Skipping, private access related issues in Controller cause this to puke.')) {
|
$this->markTestIncomplete('persistModel is totally broken right now.');
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Configure::write('Cache.disable', false);
|
Configure::write('Cache.disable', false);
|
||||||
$Controller = new Controller();
|
$Controller = new Controller();
|
||||||
$Controller->modelClass = 'ControllerPost';
|
$Controller->modelClass = 'ControllerPost';
|
||||||
|
@ -647,6 +645,7 @@ class ControllerTest extends CakeTestCase {
|
||||||
$request->params['pass'] = $request->params['named'] = array();
|
$request->params['pass'] = $request->params['named'] = array();
|
||||||
|
|
||||||
$Controller = new Controller($request);
|
$Controller = new Controller($request);
|
||||||
|
|
||||||
$Controller->uses = array('ControllerPost', 'ControllerComment');
|
$Controller->uses = array('ControllerPost', 'ControllerComment');
|
||||||
$Controller->passedArgs[] = '1';
|
$Controller->passedArgs[] = '1';
|
||||||
$Controller->params['url'] = array();
|
$Controller->params['url'] = array();
|
||||||
|
@ -817,6 +816,7 @@ class ControllerTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testFlash() {
|
function testFlash() {
|
||||||
$request = new CakeRequest('controller_posts/index');
|
$request = new CakeRequest('controller_posts/index');
|
||||||
|
|
||||||
$Controller = new Controller($request);
|
$Controller = new Controller($request);
|
||||||
$Controller->flash('this should work', '/flash');
|
$Controller->flash('this should work', '/flash');
|
||||||
$result = $Controller->output;
|
$result = $Controller->output;
|
||||||
|
@ -857,6 +857,7 @@ class ControllerTest extends CakeTestCase {
|
||||||
function testControllerSet() {
|
function testControllerSet() {
|
||||||
$request = new CakeRequest('controller_posts/index');
|
$request = new CakeRequest('controller_posts/index');
|
||||||
$Controller = new Controller($request);
|
$Controller = new Controller($request);
|
||||||
|
|
||||||
$Controller->set('variable_with_underscores', null);
|
$Controller->set('variable_with_underscores', null);
|
||||||
$this->assertTrue(array_key_exists('variable_with_underscores', $Controller->viewVars));
|
$this->assertTrue(array_key_exists('variable_with_underscores', $Controller->viewVars));
|
||||||
|
|
||||||
|
@ -896,6 +897,7 @@ class ControllerTest extends CakeTestCase {
|
||||||
), true);
|
), true);
|
||||||
$request = new CakeRequest('controller_posts/index');
|
$request = new CakeRequest('controller_posts/index');
|
||||||
|
|
||||||
|
|
||||||
$Controller = new Controller($request);
|
$Controller = new Controller($request);
|
||||||
$Controller->viewPath = 'posts';
|
$Controller->viewPath = 'posts';
|
||||||
|
|
||||||
|
@ -919,6 +921,7 @@ class ControllerTest extends CakeTestCase {
|
||||||
|
|
||||||
$Controller->ControllerComment->validationErrors = array();
|
$Controller->ControllerComment->validationErrors = array();
|
||||||
ClassRegistry::flush();
|
ClassRegistry::flush();
|
||||||
|
|
||||||
App::build();
|
App::build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -938,135 +941,142 @@ class ControllerTest extends CakeTestCase {
|
||||||
$this->assertFalse($Controller->_scaffoldError(''));
|
$this->assertFalse($Controller->_scaffoldError(''));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates status codes for redirect test.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function statusCodeProvider() {
|
||||||
|
return array(
|
||||||
|
array(100, "Continue"),
|
||||||
|
array(101, "Switching Protocols"),
|
||||||
|
array(200, "OK"),
|
||||||
|
array(201, "Created"),
|
||||||
|
array(202, "Accepted"),
|
||||||
|
array(203, "Non-Authoritative Information"),
|
||||||
|
array(204, "No Content"),
|
||||||
|
array(205, "Reset Content"),
|
||||||
|
array(206, "Partial Content"),
|
||||||
|
array(300, "Multiple Choices"),
|
||||||
|
array(301, "Moved Permanently"),
|
||||||
|
array(302, "Found"),
|
||||||
|
array(303, "See Other"),
|
||||||
|
array(304, "Not Modified"),
|
||||||
|
array(305, "Use Proxy"),
|
||||||
|
array(307, "Temporary Redirect"),
|
||||||
|
array(400, "Bad Request"),
|
||||||
|
array(401, "Unauthorized"),
|
||||||
|
array(402, "Payment Required"),
|
||||||
|
array(403, "Forbidden"),
|
||||||
|
array(404, "Not Found"),
|
||||||
|
array(405, "Method Not Allowed"),
|
||||||
|
array(406, "Not Acceptable"),
|
||||||
|
array(407, "Proxy Authentication Required"),
|
||||||
|
array(408, "Request Time-out"),
|
||||||
|
array(409, "Conflict"),
|
||||||
|
array(410, "Gone"),
|
||||||
|
array(411, "Length Required"),
|
||||||
|
array(412, "Precondition Failed"),
|
||||||
|
array(413, "Request Entity Too Large"),
|
||||||
|
array(414, "Request-URI Too Large"),
|
||||||
|
array(415, "Unsupported Media Type"),
|
||||||
|
array(416, "Requested range not satisfiable"),
|
||||||
|
array(417, "Expectation Failed"),
|
||||||
|
array(500, "Internal Server Error"),
|
||||||
|
array(501, "Not Implemented"),
|
||||||
|
array(502, "Bad Gateway"),
|
||||||
|
array(503, "Service Unavailable"),
|
||||||
|
array(504, "Gateway Time-out"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testRedirect method
|
* testRedirect method
|
||||||
*
|
*
|
||||||
|
* @dataProvider statusCodeProvider
|
||||||
* @access public
|
* @access public
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testRedirect() {
|
function testRedirectByCode($code, $msg) {
|
||||||
$codes = array(
|
$Controller = $this->getMock('Controller', array('header'));
|
||||||
100 => "Continue",
|
|
||||||
101 => "Switching Protocols",
|
|
||||||
200 => "OK",
|
|
||||||
201 => "Created",
|
|
||||||
202 => "Accepted",
|
|
||||||
203 => "Non-Authoritative Information",
|
|
||||||
204 => "No Content",
|
|
||||||
205 => "Reset Content",
|
|
||||||
206 => "Partial Content",
|
|
||||||
300 => "Multiple Choices",
|
|
||||||
301 => "Moved Permanently",
|
|
||||||
302 => "Found",
|
|
||||||
303 => "See Other",
|
|
||||||
304 => "Not Modified",
|
|
||||||
305 => "Use Proxy",
|
|
||||||
307 => "Temporary Redirect",
|
|
||||||
400 => "Bad Request",
|
|
||||||
401 => "Unauthorized",
|
|
||||||
402 => "Payment Required",
|
|
||||||
403 => "Forbidden",
|
|
||||||
404 => "Not Found",
|
|
||||||
405 => "Method Not Allowed",
|
|
||||||
406 => "Not Acceptable",
|
|
||||||
407 => "Proxy Authentication Required",
|
|
||||||
408 => "Request Time-out",
|
|
||||||
409 => "Conflict",
|
|
||||||
410 => "Gone",
|
|
||||||
411 => "Length Required",
|
|
||||||
412 => "Precondition Failed",
|
|
||||||
413 => "Request Entity Too Large",
|
|
||||||
414 => "Request-URI Too Large",
|
|
||||||
415 => "Unsupported Media Type",
|
|
||||||
416 => "Requested range not satisfiable",
|
|
||||||
417 => "Expectation Failed",
|
|
||||||
500 => "Internal Server Error",
|
|
||||||
501 => "Not Implemented",
|
|
||||||
502 => "Bad Gateway",
|
|
||||||
503 => "Service Unavailable",
|
|
||||||
504 => "Gateway Time-out"
|
|
||||||
);
|
|
||||||
|
|
||||||
Mock::generatePartial('Controller', 'MockController', array('header'));
|
|
||||||
Mock::generate('TestComponent', 'MockTestComponent');
|
|
||||||
Mock::generate('TestComponent', 'MockTestBComponent');
|
|
||||||
|
|
||||||
App::import('Helper', 'Cache');
|
$Controller->Component = new Component();
|
||||||
|
$Controller->Component->init($Controller);
|
||||||
|
$Controller->expects($this->at(0))->method('header')
|
||||||
|
->with("HTTP/1.1 {$code} {$msg}");
|
||||||
|
|
||||||
foreach ($codes as $code => $msg) {
|
$Controller->expects($this->at(1))->method('header')
|
||||||
$MockController = new MockController();
|
->with('Location: http://cakephp.org');
|
||||||
$MockController->Component = new Component();
|
|
||||||
$MockController->Component->init($MockController);
|
$Controller->expects($this->exactly(2))->method('header');
|
||||||
$MockController->expectAt(0, 'header', array("HTTP/1.1 {$code} {$msg}"));
|
|
||||||
$MockController->expectAt(1, 'header', array('Location: http://cakephp.org'));
|
$Controller->redirect('http://cakephp.org', (int)$code, false);
|
||||||
$MockController->expectCallCount('header', 2);
|
$this->assertFalse($Controller->autoRender);
|
||||||
$MockController->redirect('http://cakephp.org', (int)$code, false);
|
|
||||||
$this->assertFalse($MockController->autoRender);
|
|
||||||
}
|
|
||||||
foreach ($codes as $code => $msg) {
|
|
||||||
$MockController = new MockController();
|
|
||||||
$MockController->Component = new Component();
|
|
||||||
$MockController->Component->init($MockController);
|
|
||||||
$MockController->expectAt(0, 'header', array("HTTP/1.1 {$code} {$msg}"));
|
|
||||||
$MockController->expectAt(1, 'header', array('Location: http://cakephp.org'));
|
|
||||||
$MockController->expectCallCount('header', 2);
|
|
||||||
$MockController->redirect('http://cakephp.org', $msg, false);
|
|
||||||
$this->assertFalse($MockController->autoRender);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$MockController = new MockController();
|
/**
|
||||||
$MockController->Component = new Component();
|
* test redirecting by message
|
||||||
$MockController->Component->init($MockController);
|
*
|
||||||
$MockController->expectAt(0, 'header', array('Location: http://www.example.org/users/login'));
|
* @dataProvider statusCodeProvider
|
||||||
$MockController->expectCallCount('header', 1);
|
* @return void
|
||||||
$MockController->redirect('http://www.example.org/users/login', null, false);
|
*/
|
||||||
|
function testRedirectByMessage($code, $msg) {
|
||||||
|
$Controller = $this->getMock('Controller', array('header'));
|
||||||
|
|
||||||
$MockController = new MockController();
|
$Controller->Component = new Component();
|
||||||
$MockController->Component = new Component();
|
$Controller->Component->init($Controller);
|
||||||
$MockController->Component->init($MockController);
|
|
||||||
$MockController->expectAt(0, 'header', array('HTTP/1.1 301 Moved Permanently'));
|
|
||||||
$MockController->expectAt(1, 'header', array('Location: http://www.example.org/users/login'));
|
|
||||||
$MockController->expectCallCount('header', 2);
|
|
||||||
$MockController->redirect('http://www.example.org/users/login', 301, false);
|
|
||||||
|
|
||||||
$MockController = new MockController();
|
$Controller->expects($this->at(0))->method('header')
|
||||||
$MockController->components = array('MockTest');
|
->with("HTTP/1.1 {$code} {$msg}");
|
||||||
$MockController->Component = new Component();
|
|
||||||
$MockController->Component->init($MockController);
|
|
||||||
$MockController->MockTest->setReturnValue('beforeRedirect', null);
|
|
||||||
$MockController->expectAt(0, 'header', array('HTTP/1.1 301 Moved Permanently'));
|
|
||||||
$MockController->expectAt(1, 'header', array('Location: http://cakephp.org'));
|
|
||||||
$MockController->expectCallCount('header', 2);
|
|
||||||
$MockController->redirect('http://cakephp.org', 301, false);
|
|
||||||
|
|
||||||
$MockController = new MockController();
|
$Controller->expects($this->at(1))->method('header')
|
||||||
$MockController->components = array('MockTest');
|
->with('Location: http://cakephp.org');
|
||||||
$MockController->Component = new Component();
|
|
||||||
$MockController->Component->init($MockController);
|
|
||||||
$MockController->MockTest->setReturnValue('beforeRedirect', 'http://book.cakephp.org');
|
|
||||||
$MockController->expectAt(0, 'header', array('HTTP/1.1 301 Moved Permanently'));
|
|
||||||
$MockController->expectAt(1, 'header', array('Location: http://book.cakephp.org'));
|
|
||||||
$MockController->expectCallCount('header', 2);
|
|
||||||
$MockController->redirect('http://cakephp.org', 301, false);
|
|
||||||
|
|
||||||
$MockController = new MockController();
|
$Controller->expects($this->exactly(2))->method('header');
|
||||||
$MockController->components = array('MockTest');
|
$Controller->redirect('http://cakephp.org', $msg, false);
|
||||||
$MockController->Component = new Component();
|
$this->assertFalse($Controller->autoRender);
|
||||||
$MockController->Component->init($MockController);
|
}
|
||||||
$MockController->MockTest->setReturnValue('beforeRedirect', false);
|
|
||||||
$MockController->expectNever('header');
|
|
||||||
$MockController->redirect('http://cakephp.org', 301, false);
|
|
||||||
|
|
||||||
$MockController = new MockController();
|
/**
|
||||||
$MockController->components = array('MockTest', 'MockTestB');
|
* test that redirect triggers methods on the components.
|
||||||
$MockController->Component = new Component();
|
*
|
||||||
$MockController->Component->init($MockController);
|
* @return void
|
||||||
$MockController->MockTest->setReturnValue('beforeRedirect', 'http://book.cakephp.org');
|
*/
|
||||||
$MockController->MockTestB->setReturnValue('beforeRedirect', 'http://bakery.cakephp.org');
|
function testRedirectTriggeringComponentsReturnNull() {
|
||||||
$MockController->expectAt(0, 'header', array('HTTP/1.1 301 Moved Permanently'));
|
$Controller = $this->getMock('Controller', array('header'));
|
||||||
$MockController->expectAt(1, 'header', array('Location: http://bakery.cakephp.org'));
|
$Controller->Component = $this->getMock('Component');
|
||||||
$MockController->expectCallCount('header', 2);
|
|
||||||
$MockController->redirect('http://cakephp.org', 301, false);
|
$Controller->Component->expects($this->once())->method('beforeRedirect')->will($this->returnValue(null));
|
||||||
|
|
||||||
|
$Controller->expects($this->at(0))->method('header')
|
||||||
|
->with('HTTP/1.1 301 Moved Permanently');
|
||||||
|
|
||||||
|
$Controller->expects($this->at(1))->method('header')
|
||||||
|
->with('Location: http://cakephp.org');
|
||||||
|
|
||||||
|
$Controller->redirect('http://cakephp.org', 301, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that beforeRedirect callback returnning null doesn't affect things.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testRedirectBeforeRedirectModifyingParams() {
|
||||||
|
$Controller = $this->getMock('Controller', array('header'));
|
||||||
|
$Controller->Component = $this->getMock('Component');
|
||||||
|
|
||||||
|
$Controller->Component->expects($this->once())->method('beforeRedirect')
|
||||||
|
->will($this->returnValue(array('http://book.cakephp.org')));
|
||||||
|
|
||||||
|
$Controller->expects($this->at(0))->method('header')
|
||||||
|
->with('HTTP/1.1 301 Moved Permanently');
|
||||||
|
|
||||||
|
$Controller->expects($this->at(1))->method('header')
|
||||||
|
->with('Location: http://book.cakephp.org');
|
||||||
|
|
||||||
|
$Controller->redirect('http://cakephp.org', 301, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1081,6 +1091,7 @@ class ControllerTest extends CakeTestCase {
|
||||||
}
|
}
|
||||||
$request = new CakeRequest('controller_posts/index');
|
$request = new CakeRequest('controller_posts/index');
|
||||||
|
|
||||||
|
|
||||||
$TestController = new TestController($request);
|
$TestController = new TestController($request);
|
||||||
$TestController->constructClasses();
|
$TestController->constructClasses();
|
||||||
|
|
||||||
|
@ -1104,6 +1115,7 @@ class ControllerTest extends CakeTestCase {
|
||||||
$this->assertEqual(count(array_diff($TestController->uses, $uses)), 0);
|
$this->assertEqual(count(array_diff($TestController->uses, $uses)), 0);
|
||||||
$this->assertEqual(count(array_diff_assoc(Set::normalize($TestController->components), Set::normalize($components))), 0);
|
$this->assertEqual(count(array_diff_assoc(Set::normalize($TestController->components), Set::normalize($components))), 0);
|
||||||
|
|
||||||
|
|
||||||
$TestController = new AnotherTestController($request);
|
$TestController = new AnotherTestController($request);
|
||||||
$TestController->constructClasses();
|
$TestController->constructClasses();
|
||||||
|
|
||||||
|
@ -1144,6 +1156,7 @@ class ControllerTest extends CakeTestCase {
|
||||||
$request = new CakeRequest('controller_posts/index');
|
$request = new CakeRequest('controller_posts/index');
|
||||||
|
|
||||||
$TestController = new TestController($request);
|
$TestController = new TestController($request);
|
||||||
|
|
||||||
$expected = array('foo');
|
$expected = array('foo');
|
||||||
$TestController->components = array('Cookie' => $expected);
|
$TestController->components = array('Cookie' => $expected);
|
||||||
$TestController->constructClasses();
|
$TestController->constructClasses();
|
||||||
|
@ -1174,22 +1187,31 @@ class ControllerTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testReferer() {
|
function testReferer() {
|
||||||
$request = new ControllerMockCakeRequest();
|
$request = $this->getMock('CakeRequest');
|
||||||
$request->setReturnValue('referer', 'http://localhost/posts/index', array(false));
|
|
||||||
$request->setReturnValue('referer', '/posts/index', array(true));
|
$request->expects($this->any())->method('referer')
|
||||||
|
->with(true)
|
||||||
|
->will($this->returnValue('/posts/index'));
|
||||||
|
|
||||||
$Controller = new Controller($request);
|
$Controller = new Controller($request);
|
||||||
$result = $Controller->referer(null, true);
|
$result = $Controller->referer(null, true);
|
||||||
$this->assertEqual($result, '/posts/index');
|
$this->assertEqual($result, '/posts/index');
|
||||||
|
|
||||||
$result = $Controller->referer();
|
|
||||||
$this->assertEqual($result, 'http://localhost/posts/index');
|
|
||||||
|
|
||||||
$Controller = new Controller($request);
|
$Controller = new Controller($request);
|
||||||
$request->setReturnValue('referer', '/', array(true));
|
$request->setReturnValue('referer', '/', array(true));
|
||||||
$result = $Controller->referer(array('controller' => 'posts', 'action' => 'index'), true);
|
$result = $Controller->referer(array('controller' => 'posts', 'action' => 'index'), true);
|
||||||
$this->assertEqual($result, '/posts/index');
|
$this->assertEqual($result, '/posts/index');
|
||||||
|
|
||||||
|
$request = $this->getMock('CakeRequest');
|
||||||
|
|
||||||
|
$request->expects($this->any())->method('referer')
|
||||||
|
->with(false)
|
||||||
|
->will($this->returnValue('http://localhost/posts/index'));
|
||||||
|
|
||||||
|
$Controller = new Controller($request);
|
||||||
|
$result = $Controller->referer();
|
||||||
|
$this->assertEqual($result, 'http://localhost/posts/index');
|
||||||
|
|
||||||
$Controller = new Controller(null);
|
$Controller = new Controller(null);
|
||||||
$result = $Controller->referer();
|
$result = $Controller->referer();
|
||||||
$this->assertEqual($result, '/');
|
$this->assertEqual($result, '/');
|
||||||
|
@ -1213,6 +1235,7 @@ class ControllerTest extends CakeTestCase {
|
||||||
/**
|
/**
|
||||||
* testUnimplementedIsAuthorized method
|
* testUnimplementedIsAuthorized method
|
||||||
*
|
*
|
||||||
|
* @expectedException PHPUnit_Framework_Error
|
||||||
* @access public
|
* @access public
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
@ -1221,7 +1244,6 @@ class ControllerTest extends CakeTestCase {
|
||||||
|
|
||||||
$TestController = new TestController($request);
|
$TestController = new TestController($request);
|
||||||
$TestController->isAuthorized();
|
$TestController->isAuthorized();
|
||||||
$this->assertError();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1340,9 +1362,11 @@ class ControllerTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testRequestHandlerPrefers(){
|
function testRequestHandlerPrefers(){
|
||||||
Configure::write('debug', 2);
|
Configure::write('debug', 2);
|
||||||
|
|
||||||
$request = new CakeRequest('controller_posts/index');
|
$request = new CakeRequest('controller_posts/index');
|
||||||
|
|
||||||
$Controller = new Controller($request);
|
$Controller = new Controller($request);
|
||||||
|
|
||||||
$Controller->components = array("RequestHandler");
|
$Controller->components = array("RequestHandler");
|
||||||
$Controller->modelClass='ControllerPost';
|
$Controller->modelClass='ControllerPost';
|
||||||
$Controller->params['url'] = array('ext' => 'rss');
|
$Controller->params['url'] = array('ext' => 'rss');
|
||||||
|
@ -1402,16 +1426,18 @@ class ControllerTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testStartupProcess() {
|
function testStartupProcess() {
|
||||||
Mock::generatePartial('AnotherTestController','MockedController', array('beforeFilter', 'afterFilter'));
|
$this->getMock('TestComponent', array('startup', 'initialize'), array(), 'MockStartupComponent');
|
||||||
Mock::generate('TestComponent', 'MockTestComponent', array('startup', 'initialize'));
|
$Controller = $this->getMock('Controller', array('beforeFilter', 'afterFilter'));
|
||||||
$MockedController = new MockedController();
|
|
||||||
$MockedController->components = array('MockTest');
|
$Controller->components = array('MockStartup');
|
||||||
$MockedController->Component = new Component();
|
$Controller->Component = new Component();
|
||||||
$MockedController->Component->init($MockedController);
|
$Controller->Component->init($Controller);
|
||||||
$MockedController->expectCallCount('beforeFilter', 1);
|
|
||||||
$MockedController->MockTest->expectCallCount('initialize', 1);
|
$Controller->expects($this->once())->method('beforeFilter');
|
||||||
$MockedController->MockTest->expectCallCount('startup', 1);
|
$Controller->MockStartup->expects($this->at(0))->method('initialize');
|
||||||
$MockedController->startupProcess();
|
$Controller->MockStartup->expects($this->at(1))->method('startup');
|
||||||
|
|
||||||
|
$Controller->startupProcess();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Tests that the shutdown process calls the correct functions
|
* Tests that the shutdown process calls the correct functions
|
||||||
|
@ -1420,13 +1446,16 @@ class ControllerTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testShutdownProcess() {
|
function testShutdownProcess() {
|
||||||
Mock::generate('TestComponent', 'MockTestComponent', array('shutdown'));
|
$this->getMock('TestComponent', array('shutdown'), array(), 'MockShutdownComponent');
|
||||||
$MockedController = new MockedController();
|
$Controller = $this->getMock('Controller', array('beforeFilter', 'afterFilter'));
|
||||||
$MockedController->components = array('MockTest');
|
|
||||||
$MockedController->Component = new Component();
|
$Controller->components = array('MockShutdown');
|
||||||
$MockedController->Component->init($MockedController);
|
$Controller->Component = new Component();
|
||||||
$MockedController->expectCallCount('afterFilter', 1);
|
$Controller->Component->init($Controller);
|
||||||
$MockedController->MockTest->expectCallCount('shutdown', 1);
|
|
||||||
$MockedController->shutdownProcess();
|
$Controller->expects($this->once())->method('afterFilter');
|
||||||
|
$Controller->MockShutdown->expects($this->once())->method('shutdown');
|
||||||
|
|
||||||
|
$Controller->shutdownProcess();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,15 +127,7 @@ class MergePostsController extends MergeVarPluginAppController {
|
||||||
*
|
*
|
||||||
* @package cake.tests.cases.libs.controller
|
* @package cake.tests.cases.libs.controller
|
||||||
*/
|
*/
|
||||||
class ControllerMergeVarsTestCase extends CakeTestCase {
|
class ControllerMergeVarsTest extends CakeTestCase {
|
||||||
/**
|
|
||||||
* Skips the case if APP_CONTROLLER_EXISTS is defined
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function skip() {
|
|
||||||
$this->skipIf(defined('APP_CONTROLLER_EXISTS'), 'APP_CONTROLLER_EXISTS cannot run. %s');
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* end test
|
* end test
|
||||||
*
|
*
|
||||||
|
@ -151,6 +143,8 @@ class ControllerMergeVarsTestCase extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testComponentParamMergingNoDuplication() {
|
function testComponentParamMergingNoDuplication() {
|
||||||
|
$this->skipIf(defined('APP_CONTROLLER_EXISTS'), "APP_CONTROLLER_EXISTS cannot run {$this->name}");
|
||||||
|
|
||||||
$Controller =& new MergeVariablesController();
|
$Controller =& new MergeVariablesController();
|
||||||
$Controller->constructClasses();
|
$Controller->constructClasses();
|
||||||
|
|
||||||
|
@ -164,6 +158,8 @@ class ControllerMergeVarsTestCase extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testComponentMergingWithRedeclarations() {
|
function testComponentMergingWithRedeclarations() {
|
||||||
|
$this->skipIf(defined('APP_CONTROLLER_EXISTS'), "APP_CONTROLLER_EXISTS cannot run {$this->name}");
|
||||||
|
|
||||||
$Controller =& new MergeVariablesController();
|
$Controller =& new MergeVariablesController();
|
||||||
$Controller->components['MergeVar'] = array('remote', 'redirect' => true);
|
$Controller->components['MergeVar'] = array('remote', 'redirect' => true);
|
||||||
$Controller->constructClasses();
|
$Controller->constructClasses();
|
||||||
|
@ -178,6 +174,8 @@ class ControllerMergeVarsTestCase extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testHelperSettingMergingNoDuplication() {
|
function testHelperSettingMergingNoDuplication() {
|
||||||
|
$this->skipIf(defined('APP_CONTROLLER_EXISTS'), "APP_CONTROLLER_EXISTS cannot run {$this->name}");
|
||||||
|
|
||||||
$Controller =& new MergeVariablesController();
|
$Controller =& new MergeVariablesController();
|
||||||
$Controller->constructClasses();
|
$Controller->constructClasses();
|
||||||
|
|
||||||
|
@ -191,6 +189,8 @@ class ControllerMergeVarsTestCase extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testMergeVarsWithPlugin() {
|
function testMergeVarsWithPlugin() {
|
||||||
|
$this->skipIf(defined('APP_CONTROLLER_EXISTS'), "APP_CONTROLLER_EXISTS cannot run {$this->name}");
|
||||||
|
|
||||||
$Controller =& new MergePostsController();
|
$Controller =& new MergePostsController();
|
||||||
$Controller->components = array('Email' => array('ports' => 'open'));
|
$Controller->components = array('Email' => array('ports' => 'open'));
|
||||||
$Controller->plugin = 'MergeVarPlugin';
|
$Controller->plugin = 'MergeVarPlugin';
|
||||||
|
@ -228,6 +228,8 @@ class ControllerMergeVarsTestCase extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testMergeVarsNotGreedy() {
|
function testMergeVarsNotGreedy() {
|
||||||
|
$this->skipIf(defined('APP_CONTROLLER_EXISTS'), "APP_CONTROLLER_EXISTS cannot run {$this->name}");
|
||||||
|
|
||||||
$Controller =& new Controller();
|
$Controller =& new Controller();
|
||||||
$Controller->components = array();
|
$Controller->components = array();
|
||||||
$Controller->uses = array();
|
$Controller->uses = array();
|
||||||
|
|
|
@ -46,14 +46,8 @@ class DebuggerTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function setUp() {
|
function setUp() {
|
||||||
|
parent::setup();
|
||||||
Configure::write('log', false);
|
Configure::write('log', false);
|
||||||
if (!defined('SIMPLETESTVENDORPATH')) {
|
|
||||||
if (file_exists(APP . DS . 'vendors' . DS . 'simpletest' . DS . 'reporter.php')) {
|
|
||||||
define('SIMPLETESTVENDORPATH', 'APP' . DS . 'vendors');
|
|
||||||
} else {
|
|
||||||
define('SIMPLETESTVENDORPATH', 'CORE' . DS . 'vendors');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,6 +57,7 @@ class DebuggerTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function tearDown() {
|
function tearDown() {
|
||||||
|
parent::teardown();
|
||||||
Configure::write('log', true);
|
Configure::write('log', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +114,6 @@ class DebuggerTest extends CakeTestCase {
|
||||||
$this->assertEqual($result[0]['error'], 'Notice');
|
$this->assertEqual($result[0]['error'], 'Notice');
|
||||||
$this->assertPattern('/Undefined variable\:\s+out/', $result[0]['description']);
|
$this->assertPattern('/Undefined variable\:\s+out/', $result[0]['description']);
|
||||||
$this->assertPattern('/DebuggerTest::testOutput/i', $result[0]['trace']);
|
$this->assertPattern('/DebuggerTest::testOutput/i', $result[0]['trace']);
|
||||||
$this->assertPattern('/SimpleInvoker::invoke/i', $result[0]['trace']);
|
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
Debugger::output('txt');
|
Debugger::output('txt');
|
||||||
|
@ -129,7 +123,6 @@ class DebuggerTest extends CakeTestCase {
|
||||||
$this->assertPattern('/Undefined variable:\s+other/', $result);
|
$this->assertPattern('/Undefined variable:\s+other/', $result);
|
||||||
$this->assertPattern('/Context:/', $result);
|
$this->assertPattern('/Context:/', $result);
|
||||||
$this->assertPattern('/DebuggerTest::testOutput/i', $result);
|
$this->assertPattern('/DebuggerTest::testOutput/i', $result);
|
||||||
$this->assertPattern('/SimpleInvoker::invoke/i', $result);
|
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
Debugger::output('html');
|
Debugger::output('html');
|
||||||
|
@ -157,7 +150,8 @@ class DebuggerTest extends CakeTestCase {
|
||||||
$this->assertPattern('/Undefined variable:\s+buzz/', $result[1]);
|
$this->assertPattern('/Undefined variable:\s+buzz/', $result[1]);
|
||||||
$this->assertPattern('/<a[^>]+>Code/', $result[1]);
|
$this->assertPattern('/<a[^>]+>Code/', $result[1]);
|
||||||
$this->assertPattern('/<a[^>]+>Context/', $result[2]);
|
$this->assertPattern('/<a[^>]+>Context/', $result[2]);
|
||||||
set_error_handler('simpleTestErrorHandler');
|
|
||||||
|
restore_error_handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -185,17 +179,18 @@ class DebuggerTest extends CakeTestCase {
|
||||||
ob_start();
|
ob_start();
|
||||||
$foo .= '';
|
$foo .= '';
|
||||||
$result = ob_get_clean();
|
$result = ob_get_clean();
|
||||||
set_error_handler('SimpleTestErrorHandler');
|
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'error' => array(),
|
'error' => array(),
|
||||||
'code' => array(), '8', '/code',
|
'code' => array(), '8', '/code',
|
||||||
'file' => array(), 'preg:/[^<]+/', '/file',
|
'file' => array(), 'preg:/[^<]+/', '/file',
|
||||||
'line' => array(), '' . (intval(__LINE__) + -8), '/line',
|
'line' => array(), '' . (intval(__LINE__) - 7), '/line',
|
||||||
'preg:/Undefined variable:\s+foo/',
|
'preg:/Undefined variable:\s+foo/',
|
||||||
'/error'
|
'/error'
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $data, true);
|
$this->assertTags($result, $data, true);
|
||||||
|
|
||||||
|
restore_error_handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -318,16 +313,16 @@ class DebuggerTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testGetInstance() {
|
function testGetInstance() {
|
||||||
$result =& Debugger::getInstance();
|
$result = Debugger::getInstance();
|
||||||
$this->assertIsA($result, 'Debugger');
|
$this->assertIsA($result, 'Debugger');
|
||||||
|
|
||||||
$result =& Debugger::getInstance('DebuggerTestCaseDebugger');
|
$result = Debugger::getInstance('DebuggerTestCaseDebugger');
|
||||||
$this->assertIsA($result, 'DebuggerTestCaseDebugger');
|
$this->assertIsA($result, 'DebuggerTestCaseDebugger');
|
||||||
|
|
||||||
$result =& Debugger::getInstance();
|
$result = Debugger::getInstance();
|
||||||
$this->assertIsA($result, 'DebuggerTestCaseDebugger');
|
$this->assertIsA($result, 'DebuggerTestCaseDebugger');
|
||||||
|
|
||||||
$result =& Debugger::getInstance('Debugger');
|
$result = Debugger::getInstance('Debugger');
|
||||||
$this->assertIsA($result, 'Debugger');
|
$this->assertIsA($result, 'Debugger');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,15 +193,7 @@ class BlueberryController extends AppController {
|
||||||
* @access public
|
* @access public
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public $uses = array('AuthBlueberryUser');
|
public $uses = array();
|
||||||
|
|
||||||
/**
|
|
||||||
* components property
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public $components = array('Auth');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -350,7 +342,7 @@ class ErrorHandlerTest extends CakeTestCase {
|
||||||
$this->assertPattern("/<strong>'\/test_error'<\/strong>/", $result);
|
$this->assertPattern("/<strong>'\/test_error'<\/strong>/", $result);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
$TestErrorHandler =& new TestErrorHandler('error404', array('message' => 'Page not found'));
|
$TestErrorHandler = new TestErrorHandler('error404', array('message' => 'Page not found'));
|
||||||
ob_get_clean();
|
ob_get_clean();
|
||||||
ob_start();
|
ob_start();
|
||||||
$TestErrorHandler->error404(array(
|
$TestErrorHandler->error404(array(
|
||||||
|
@ -477,11 +469,9 @@ class ErrorHandlerTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testMissingView() {
|
function testMissingView() {
|
||||||
restore_error_handler();
|
|
||||||
ob_start();
|
ob_start();
|
||||||
$TestErrorHandler = new TestErrorHandler('missingView', array('className' => 'Pages', 'action' => 'display', 'file' => 'pages/about.ctp', 'base' => ''));
|
$TestErrorHandler = new TestErrorHandler('missingView', array('className' => 'Pages', 'action' => 'display', 'file' => 'pages/about.ctp', 'base' => ''));
|
||||||
$expected = ob_get_clean();
|
$expected = ob_get_clean();
|
||||||
set_error_handler('simpleTestErrorHandler');
|
|
||||||
$this->assertPattern("/PagesController::/", $expected);
|
$this->assertPattern("/PagesController::/", $expected);
|
||||||
$this->assertPattern("/pages\/about.ctp/", $expected);
|
$this->assertPattern("/pages\/about.ctp/", $expected);
|
||||||
}
|
}
|
||||||
|
@ -493,11 +483,9 @@ class ErrorHandlerTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testMissingLayout() {
|
function testMissingLayout() {
|
||||||
restore_error_handler();
|
|
||||||
ob_start();
|
ob_start();
|
||||||
$TestErrorHandler = new TestErrorHandler('missingLayout', array( 'layout' => 'my_layout', 'file' => 'layouts/my_layout.ctp', 'base' => ''));
|
$TestErrorHandler = new TestErrorHandler('missingLayout', array( 'layout' => 'my_layout', 'file' => 'layouts/my_layout.ctp', 'base' => ''));
|
||||||
$expected = ob_get_clean();
|
$expected = ob_get_clean();
|
||||||
set_error_handler('simpleTestErrorHandler');
|
|
||||||
$this->assertPattern("/Missing Layout/", $expected);
|
$this->assertPattern("/Missing Layout/", $expected);
|
||||||
$this->assertPattern("/layouts\/my_layout.ctp/", $expected);
|
$this->assertPattern("/layouts\/my_layout.ctp/", $expected);
|
||||||
}
|
}
|
||||||
|
@ -571,7 +559,6 @@ class ErrorHandlerTest extends CakeTestCase {
|
||||||
ob_start();
|
ob_start();
|
||||||
$TestErrorHandler = new TestErrorHandler('missingBehaviorClass', array('behavior' => 'MyCustom', 'file' => 'my_custom.php'));
|
$TestErrorHandler = new TestErrorHandler('missingBehaviorClass', array('behavior' => 'MyCustom', 'file' => 'my_custom.php'));
|
||||||
$result = ob_get_clean();
|
$result = ob_get_clean();
|
||||||
$this->assertPattern('/<h2>Missing Behavior Class<\/h2>/', $result);
|
|
||||||
$this->assertPattern('/The behavior class <em>MyCustomBehavior<\/em> can not be found or does not exist./', $result);
|
$this->assertPattern('/The behavior class <em>MyCustomBehavior<\/em> can not be found or does not exist./', $result);
|
||||||
$this->assertPattern('/(\/|\\\)my_custom.php/', $result);
|
$this->assertPattern('/(\/|\\\)my_custom.php/', $result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,28 @@ class FileTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public $File = null;
|
public $File = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setup the test case
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
$file = __FILE__;
|
||||||
|
$this->File = new File($file);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tear down for test.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function teardown() {
|
||||||
|
parent::teardown();
|
||||||
|
$this->File->close();
|
||||||
|
unset($this->File);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testBasic method
|
* testBasic method
|
||||||
*
|
*
|
||||||
|
@ -43,7 +65,6 @@ class FileTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testBasic() {
|
function testBasic() {
|
||||||
$file = __FILE__;
|
$file = __FILE__;
|
||||||
$this->File =& new File($file);
|
|
||||||
|
|
||||||
$result = $this->File->pwd();
|
$result = $this->File->pwd();
|
||||||
$expecting = $file;
|
$expecting = $file;
|
||||||
|
@ -213,7 +234,7 @@ class FileTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testCreate() {
|
function testCreate() {
|
||||||
$tmpFile = TMP.'tests'.DS.'cakephp.file.test.tmp';
|
$tmpFile = TMP.'tests'.DS.'cakephp.file.test.tmp';
|
||||||
$File =& new File($tmpFile, true, 0777);
|
$File = new File($tmpFile, true, 0777);
|
||||||
$this->assertTrue($File->exists());
|
$this->assertTrue($File->exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +245,7 @@ class FileTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testOpeningNonExistantFileCreatesIt() {
|
function testOpeningNonExistantFileCreatesIt() {
|
||||||
$someFile =& new File(TMP . 'some_file.txt', false);
|
$someFile = new File(TMP . 'some_file.txt', false);
|
||||||
$this->assertTrue($someFile->open());
|
$this->assertTrue($someFile->open());
|
||||||
$this->assertEqual($someFile->read(), '');
|
$this->assertEqual($someFile->read(), '');
|
||||||
$someFile->close();
|
$someFile->close();
|
||||||
|
@ -259,7 +280,7 @@ class FileTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testReadable() {
|
function testReadable() {
|
||||||
$someFile =& new File(TMP . 'some_file.txt', false);
|
$someFile = new File(TMP . 'some_file.txt', false);
|
||||||
$this->assertTrue($someFile->open());
|
$this->assertTrue($someFile->open());
|
||||||
$this->assertTrue($someFile->readable());
|
$this->assertTrue($someFile->readable());
|
||||||
$someFile->close();
|
$someFile->close();
|
||||||
|
@ -273,7 +294,7 @@ class FileTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testWritable() {
|
function testWritable() {
|
||||||
$someFile =& new File(TMP . 'some_file.txt', false);
|
$someFile = new File(TMP . 'some_file.txt', false);
|
||||||
$this->assertTrue($someFile->open());
|
$this->assertTrue($someFile->open());
|
||||||
$this->assertTrue($someFile->writable());
|
$this->assertTrue($someFile->writable());
|
||||||
$someFile->close();
|
$someFile->close();
|
||||||
|
@ -287,7 +308,7 @@ class FileTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testExecutable() {
|
function testExecutable() {
|
||||||
$someFile =& new File(TMP . 'some_file.txt', false);
|
$someFile = new File(TMP . 'some_file.txt', false);
|
||||||
$this->assertTrue($someFile->open());
|
$this->assertTrue($someFile->open());
|
||||||
$this->assertFalse($someFile->executable());
|
$this->assertFalse($someFile->executable());
|
||||||
$someFile->close();
|
$someFile->close();
|
||||||
|
@ -301,7 +322,7 @@ class FileTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testLastAccess() {
|
function testLastAccess() {
|
||||||
$someFile =& new File(TMP . 'some_file.txt', false);
|
$someFile = new File(TMP . 'some_file.txt', false);
|
||||||
$this->assertFalse($someFile->lastAccess());
|
$this->assertFalse($someFile->lastAccess());
|
||||||
$this->assertTrue($someFile->open());
|
$this->assertTrue($someFile->open());
|
||||||
$this->assertEqual($someFile->lastAccess(), time());
|
$this->assertEqual($someFile->lastAccess(), time());
|
||||||
|
@ -316,7 +337,7 @@ class FileTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testLastChange() {
|
function testLastChange() {
|
||||||
$someFile =& new File(TMP . 'some_file.txt', false);
|
$someFile = new File(TMP . 'some_file.txt', false);
|
||||||
$this->assertFalse($someFile->lastChange());
|
$this->assertFalse($someFile->lastChange());
|
||||||
$this->assertTrue($someFile->open('r+'));
|
$this->assertTrue($someFile->open('r+'));
|
||||||
$this->assertEqual($someFile->lastChange(), time());
|
$this->assertEqual($someFile->lastChange(), time());
|
||||||
|
@ -340,7 +361,7 @@ class FileTest extends CakeTestCase {
|
||||||
unlink($tmpFile);
|
unlink($tmpFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
$TmpFile =& new File($tmpFile);
|
$TmpFile = new File($tmpFile);
|
||||||
$this->assertFalse(file_exists($tmpFile));
|
$this->assertFalse(file_exists($tmpFile));
|
||||||
$this->assertFalse(is_resource($TmpFile->handle));
|
$this->assertFalse(is_resource($TmpFile->handle));
|
||||||
|
|
||||||
|
@ -371,7 +392,7 @@ class FileTest extends CakeTestCase {
|
||||||
unlink($tmpFile);
|
unlink($tmpFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
$TmpFile =& new File($tmpFile);
|
$TmpFile = new File($tmpFile);
|
||||||
$this->assertFalse(file_exists($tmpFile));
|
$this->assertFalse(file_exists($tmpFile));
|
||||||
|
|
||||||
$fragments = array('CakePHP\'s', ' test suite', ' was here ...', '');
|
$fragments = array('CakePHP\'s', ' test suite', ' was here ...', '');
|
||||||
|
@ -400,13 +421,13 @@ class FileTest extends CakeTestCase {
|
||||||
if (!file_exists($tmpFile)) {
|
if (!file_exists($tmpFile)) {
|
||||||
touch($tmpFile);
|
touch($tmpFile);
|
||||||
}
|
}
|
||||||
$TmpFile =& new File($tmpFile);
|
$TmpFile = new File($tmpFile);
|
||||||
$this->assertTrue(file_exists($tmpFile));
|
$this->assertTrue(file_exists($tmpFile));
|
||||||
$result = $TmpFile->delete();
|
$result = $TmpFile->delete();
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertFalse(file_exists($tmpFile));
|
$this->assertFalse(file_exists($tmpFile));
|
||||||
|
|
||||||
$TmpFile =& new File('/this/does/not/exist');
|
$TmpFile = new File('/this/does/not/exist');
|
||||||
$result = $TmpFile->delete();
|
$result = $TmpFile->delete();
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
}
|
}
|
||||||
|
@ -420,7 +441,7 @@ class FileTest extends CakeTestCase {
|
||||||
function testCopy() {
|
function testCopy() {
|
||||||
$dest = TMP . 'tests' . DS . 'cakephp.file.test.tmp';
|
$dest = TMP . 'tests' . DS . 'cakephp.file.test.tmp';
|
||||||
$file = __FILE__;
|
$file = __FILE__;
|
||||||
$this->File =& new File($file);
|
$this->File = new File($file);
|
||||||
$result = $this->File->copy($dest);
|
$result = $this->File->copy($dest);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
|
@ -433,7 +454,7 @@ class FileTest extends CakeTestCase {
|
||||||
$this->File->close();
|
$this->File->close();
|
||||||
unlink($dest);
|
unlink($dest);
|
||||||
|
|
||||||
$TmpFile =& new File('/this/does/not/exist');
|
$TmpFile = new File('/this/does/not/exist');
|
||||||
$result = $TmpFile->copy($dest);
|
$result = $TmpFile->copy($dest);
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ class FolderTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testBasic() {
|
function testBasic() {
|
||||||
$path = dirname(__FILE__);
|
$path = dirname(__FILE__);
|
||||||
$Folder =& new Folder($path);
|
$Folder = new Folder($path);
|
||||||
|
|
||||||
$result = $Folder->pwd();
|
$result = $Folder->pwd();
|
||||||
$this->assertEqual($result, $path);
|
$this->assertEqual($result, $path);
|
||||||
|
@ -62,7 +62,7 @@ class FolderTest extends CakeTestCase {
|
||||||
$path = dirname(dirname(__FILE__));
|
$path = dirname(dirname(__FILE__));
|
||||||
$inside = dirname($path) . DS;
|
$inside = dirname($path) . DS;
|
||||||
|
|
||||||
$Folder =& new Folder($path);
|
$Folder = new Folder($path);
|
||||||
|
|
||||||
$result = $Folder->pwd();
|
$result = $Folder->pwd();
|
||||||
$this->assertEqual($result, $path);
|
$this->assertEqual($result, $path);
|
||||||
|
@ -86,7 +86,7 @@ class FolderTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testCreation() {
|
function testCreation() {
|
||||||
$folder =& new Folder(TMP . 'tests');
|
$folder = new Folder(TMP . 'tests');
|
||||||
$result = $folder->create(TMP . 'tests' . DS . 'first' . DS . 'second' . DS . 'third');
|
$result = $folder->create(TMP . 'tests' . DS . 'first' . DS . 'second' . DS . 'third');
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ class FolderTest extends CakeTestCase {
|
||||||
rmdir(TMP . 'tests' . DS . 'first' . DS . 'second');
|
rmdir(TMP . 'tests' . DS . 'first' . DS . 'second');
|
||||||
rmdir(TMP . 'tests' . DS . 'first');
|
rmdir(TMP . 'tests' . DS . 'first');
|
||||||
|
|
||||||
$folder =& new Folder(TMP . 'tests');
|
$folder = new Folder(TMP . 'tests');
|
||||||
$result = $folder->create(TMP . 'tests' . DS . 'first');
|
$result = $folder->create(TMP . 'tests' . DS . 'first');
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
rmdir(TMP . 'tests' . DS . 'first');
|
rmdir(TMP . 'tests' . DS . 'first');
|
||||||
|
@ -106,13 +106,13 @@ class FolderTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testCreateWithTrailingDs() {
|
function testCreateWithTrailingDs() {
|
||||||
$folder =& new Folder(TMP);
|
$folder = new Folder(TMP);
|
||||||
$path = TMP . 'tests' . DS . 'trailing' . DS . 'dir' . DS;
|
$path = TMP . 'tests' . DS . 'trailing' . DS . 'dir' . DS;
|
||||||
$folder->create($path);
|
$folder->create($path);
|
||||||
|
|
||||||
$this->assertTrue(is_dir($path), 'Folder was not made');
|
$this->assertTrue(is_dir($path), 'Folder was not made');
|
||||||
|
|
||||||
$folder =& new Folder(TMP . 'tests' . DS . 'trailing');
|
$folder = new Folder(TMP . 'tests' . DS . 'trailing');
|
||||||
$this->assertTrue($folder->delete());
|
$this->assertTrue($folder->delete());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,11 +129,13 @@ class FolderTest extends CakeTestCase {
|
||||||
mkdir($path);
|
mkdir($path);
|
||||||
chmod($path, '0444');
|
chmod($path, '0444');
|
||||||
|
|
||||||
$this->expectError();
|
try {
|
||||||
|
$folder = new Folder($path);
|
||||||
$folder =& new Folder($path);
|
|
||||||
$result = $folder->create($path . DS . 'two' . DS . 'three');
|
$result = $folder->create($path . DS . 'two' . DS . 'three');
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
|
} catch (PHPUnit_Framework_Error $e) {
|
||||||
|
$this->assertTrue(true);
|
||||||
|
}
|
||||||
|
|
||||||
chmod($path, '0777');
|
chmod($path, '0777');
|
||||||
rmdir($path);
|
rmdir($path);
|
||||||
|
@ -146,7 +148,7 @@ class FolderTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testOperations() {
|
function testOperations() {
|
||||||
$path = TEST_CAKE_CORE_INCLUDE_PATH . 'console' . DS . 'templates' . DS . 'skel';
|
$path = TEST_CAKE_CORE_INCLUDE_PATH . 'console' . DS . 'templates' . DS . 'skel';
|
||||||
$Folder =& new Folder($path);
|
$Folder = new Folder($path);
|
||||||
|
|
||||||
$result = is_dir($Folder->pwd());
|
$result = is_dir($Folder->pwd());
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
@ -168,7 +170,7 @@ class FolderTest extends CakeTestCase {
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
$result = $Folder->cd($copy);
|
$result = $Folder->cd($copy);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue((bool)$result);
|
||||||
|
|
||||||
$mv = TMP . 'test_folder_mv';
|
$mv = TMP . 'test_folder_mv';
|
||||||
$result = $Folder->move($mv);
|
$result = $Folder->move($mv);
|
||||||
|
@ -200,12 +202,12 @@ class FolderTest extends CakeTestCase {
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
$result = $Folder->cd($new);
|
$result = $Folder->cd($new);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue((bool)$result);
|
||||||
|
|
||||||
$result = $Folder->delete();
|
$result = $Folder->delete();
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
$Folder =& new Folder('non-existent');
|
$Folder = new Folder('non-existent');
|
||||||
$result = $Folder->pwd();
|
$result = $Folder->pwd();
|
||||||
$this->assertNull($result);
|
$this->assertNull($result);
|
||||||
}
|
}
|
||||||
|
@ -219,7 +221,7 @@ class FolderTest extends CakeTestCase {
|
||||||
$this->skipIf(DIRECTORY_SEPARATOR === '\\', '%s Folder permissions tests not supported on Windows');
|
$this->skipIf(DIRECTORY_SEPARATOR === '\\', '%s Folder permissions tests not supported on Windows');
|
||||||
|
|
||||||
$path = TEST_CAKE_CORE_INCLUDE_PATH . 'console' . DS . 'templates' . DS . 'skel';
|
$path = TEST_CAKE_CORE_INCLUDE_PATH . 'console' . DS . 'templates' . DS . 'skel';
|
||||||
$Folder =& new Folder($path);
|
$Folder = new Folder($path);
|
||||||
|
|
||||||
$subdir = 'test_folder_new';
|
$subdir = 'test_folder_new';
|
||||||
$new = TMP . $subdir;
|
$new = TMP . $subdir;
|
||||||
|
@ -229,7 +231,7 @@ class FolderTest extends CakeTestCase {
|
||||||
$this->assertTrue($Folder->create($new . DS . 'test2'));
|
$this->assertTrue($Folder->create($new . DS . 'test2'));
|
||||||
|
|
||||||
$filePath = $new . DS . 'test1.php';
|
$filePath = $new . DS . 'test1.php';
|
||||||
$File =& new File($filePath);
|
$File = new File($filePath);
|
||||||
$this->assertTrue($File->create());
|
$this->assertTrue($File->create());
|
||||||
$copy = TMP . 'test_folder_copy';
|
$copy = TMP . 'test_folder_copy';
|
||||||
|
|
||||||
|
@ -257,7 +259,7 @@ class FolderTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testZeroAsDirectory() {
|
function testZeroAsDirectory() {
|
||||||
$Folder =& new Folder(TMP);
|
$Folder = new Folder(TMP);
|
||||||
$new = TMP . '0';
|
$new = TMP . '0';
|
||||||
$this->assertTrue($Folder->create($new));
|
$this->assertTrue($Folder->create($new));
|
||||||
|
|
||||||
|
@ -292,7 +294,7 @@ class FolderTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testFolderRead() {
|
function testFolderRead() {
|
||||||
$Folder =& new Folder(TMP);
|
$Folder = new Folder(TMP);
|
||||||
|
|
||||||
$expected = array('cache', 'logs', 'sessions', 'tests');
|
$expected = array('cache', 'logs', 'sessions', 'tests');
|
||||||
$result = $Folder->read(true, true);
|
$result = $Folder->read(true, true);
|
||||||
|
@ -311,7 +313,7 @@ class FolderTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testFolderTree() {
|
function testFolderTree() {
|
||||||
$Folder =& new Folder();
|
$Folder = new Folder();
|
||||||
$expected = array(
|
$expected = array(
|
||||||
array(
|
array(
|
||||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config',
|
TEST_CAKE_CORE_INCLUDE_PATH . 'config',
|
||||||
|
@ -458,7 +460,7 @@ class FolderTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testInCakePath() {
|
function testInCakePath() {
|
||||||
$Folder =& new Folder();
|
$Folder = new Folder();
|
||||||
$Folder->cd(ROOT);
|
$Folder->cd(ROOT);
|
||||||
$path = 'C:\\path\\to\\file';
|
$path = 'C:\\path\\to\\file';
|
||||||
$result = $Folder->inCakePath($path);
|
$result = $Folder->inCakePath($path);
|
||||||
|
@ -483,7 +485,7 @@ class FolderTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testFind() {
|
function testFind() {
|
||||||
$Folder =& new Folder();
|
$Folder = new Folder();
|
||||||
$Folder->cd(TEST_CAKE_CORE_INCLUDE_PATH . 'config');
|
$Folder->cd(TEST_CAKE_CORE_INCLUDE_PATH . 'config');
|
||||||
$result = $Folder->find();
|
$result = $Folder->find();
|
||||||
$expected = array('config.php', 'paths.php');
|
$expected = array('config.php', 'paths.php');
|
||||||
|
@ -536,7 +538,7 @@ class FolderTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testFindRecursive() {
|
function testFindRecursive() {
|
||||||
$Folder =& new Folder();
|
$Folder = new Folder();
|
||||||
$Folder->cd(TEST_CAKE_CORE_INCLUDE_PATH);
|
$Folder->cd(TEST_CAKE_CORE_INCLUDE_PATH);
|
||||||
$result = $Folder->findRecursive('(config|paths)\.php');
|
$result = $Folder->findRecursive('(config|paths)\.php');
|
||||||
$expected = array(
|
$expected = array(
|
||||||
|
@ -556,7 +558,7 @@ class FolderTest extends CakeTestCase {
|
||||||
$Folder->cd(TMP);
|
$Folder->cd(TMP);
|
||||||
$Folder->create($Folder->pwd() . DS . 'testme');
|
$Folder->create($Folder->pwd() . DS . 'testme');
|
||||||
$Folder->cd('testme');
|
$Folder->cd('testme');
|
||||||
$File =& new File($Folder->pwd() . DS . 'paths.php');
|
$File = new File($Folder->pwd() . DS . 'paths.php');
|
||||||
$File->create();
|
$File->create();
|
||||||
$Folder->cd(TMP . 'sessions');
|
$Folder->cd(TMP . 'sessions');
|
||||||
$result = $Folder->findRecursive('paths\.php');
|
$result = $Folder->findRecursive('paths\.php');
|
||||||
|
@ -564,7 +566,7 @@ class FolderTest extends CakeTestCase {
|
||||||
$this->assertIdentical($result, $expected);
|
$this->assertIdentical($result, $expected);
|
||||||
|
|
||||||
$Folder->cd(TMP . 'testme');
|
$Folder->cd(TMP . 'testme');
|
||||||
$File =& new File($Folder->pwd() . DS . 'my.php');
|
$File = new File($Folder->pwd() . DS . 'my.php');
|
||||||
$File->create();
|
$File->create();
|
||||||
$Folder->cd($Folder->pwd() . '/../..');
|
$Folder->cd($Folder->pwd() . '/../..');
|
||||||
|
|
||||||
|
@ -596,7 +598,7 @@ class FolderTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testConstructWithNonExistantPath() {
|
function testConstructWithNonExistantPath() {
|
||||||
$Folder =& new Folder(TMP . 'config_non_existant', true);
|
$Folder = new Folder(TMP . 'config_non_existant', true);
|
||||||
$this->assertTrue(is_dir(TMP . 'config_non_existant'));
|
$this->assertTrue(is_dir(TMP . 'config_non_existant'));
|
||||||
$Folder->cd(TMP);
|
$Folder->cd(TMP);
|
||||||
$Folder->delete($Folder->pwd() . 'config_non_existant');
|
$Folder->delete($Folder->pwd() . 'config_non_existant');
|
||||||
|
@ -609,10 +611,10 @@ class FolderTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testDirSize() {
|
function testDirSize() {
|
||||||
$Folder =& new Folder(TMP . 'config_non_existant', true);
|
$Folder = new Folder(TMP . 'config_non_existant', true);
|
||||||
$this->assertEqual($Folder->dirSize(), 0);
|
$this->assertEqual($Folder->dirSize(), 0);
|
||||||
|
|
||||||
$File =& new File($Folder->pwd() . DS . 'my.php', true, 0777);
|
$File = new File($Folder->pwd() . DS . 'my.php', true, 0777);
|
||||||
$File->create();
|
$File->create();
|
||||||
$File->write('something here');
|
$File->write('something here');
|
||||||
$File->close();
|
$File->close();
|
||||||
|
@ -630,7 +632,7 @@ class FolderTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testDelete() {
|
function testDelete() {
|
||||||
$path = TMP . 'folder_delete_test';
|
$path = TMP . 'folder_delete_test';
|
||||||
$Folder =& new Folder($path, true);
|
$Folder = new Folder($path, true);
|
||||||
touch(TMP . 'folder_delete_test' . DS . 'file1');
|
touch(TMP . 'folder_delete_test' . DS . 'file1');
|
||||||
touch(TMP . 'folder_delete_test' . DS . 'file2');
|
touch(TMP . 'folder_delete_test' . DS . 'file2');
|
||||||
|
|
||||||
|
@ -639,7 +641,7 @@ class FolderTest extends CakeTestCase {
|
||||||
|
|
||||||
$messages = $Folder->messages();
|
$messages = $Folder->messages();
|
||||||
$errors = $Folder->errors();
|
$errors = $Folder->errors();
|
||||||
$this->assertEqual($errors, array());
|
$this->assertEquals($errors, array());
|
||||||
|
|
||||||
$expected = array(
|
$expected = array(
|
||||||
$path . ' created',
|
$path . ' created',
|
||||||
|
@ -677,35 +679,35 @@ class FolderTest extends CakeTestCase {
|
||||||
touch($file1);
|
touch($file1);
|
||||||
touch($file2);
|
touch($file2);
|
||||||
|
|
||||||
$Folder =& new Folder($folder1);
|
$Folder = new Folder($folder1);
|
||||||
$result = $Folder->copy($folder3);
|
$result = $Folder->copy($folder3);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
|
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
|
||||||
$this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php'));
|
$this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php'));
|
||||||
|
|
||||||
$Folder =& new Folder($folder3);
|
$Folder = new Folder($folder3);
|
||||||
$Folder->delete();
|
$Folder->delete();
|
||||||
|
|
||||||
$Folder =& new Folder($folder1);
|
$Folder = new Folder($folder1);
|
||||||
$result = $Folder->copy($folder3);
|
$result = $Folder->copy($folder3);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
|
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
|
||||||
$this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php'));
|
$this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php'));
|
||||||
|
|
||||||
$Folder =& new Folder($folder3);
|
$Folder = new Folder($folder3);
|
||||||
$Folder->delete();
|
$Folder->delete();
|
||||||
|
|
||||||
new Folder($folder3, true);
|
new Folder($folder3, true);
|
||||||
new Folder($folder3 . DS . 'folder2', true);
|
new Folder($folder3 . DS . 'folder2', true);
|
||||||
file_put_contents($folder3 . DS . 'folder2' . DS . 'file2.php', 'untouched');
|
file_put_contents($folder3 . DS . 'folder2' . DS . 'file2.php', 'untouched');
|
||||||
|
|
||||||
$Folder =& new Folder($folder1);
|
$Folder = new Folder($folder1);
|
||||||
$result = $Folder->copy($folder3);
|
$result = $Folder->copy($folder3);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
|
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
|
||||||
$this->assertEqual(file_get_contents($folder3 . DS . 'folder2' . DS . 'file2.php'), 'untouched');
|
$this->assertEqual(file_get_contents($folder3 . DS . 'folder2' . DS . 'file2.php'), 'untouched');
|
||||||
|
|
||||||
$Folder =& new Folder($path);
|
$Folder = new Folder($path);
|
||||||
$Folder->delete();
|
$Folder->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -736,7 +738,7 @@ class FolderTest extends CakeTestCase {
|
||||||
touch($file1);
|
touch($file1);
|
||||||
touch($file2);
|
touch($file2);
|
||||||
|
|
||||||
$Folder =& new Folder($folder1);
|
$Folder = new Folder($folder1);
|
||||||
$result = $Folder->move($folder3);
|
$result = $Folder->move($folder3);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
|
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
|
||||||
|
@ -746,7 +748,7 @@ class FolderTest extends CakeTestCase {
|
||||||
$this->assertFalse(file_exists($folder2));
|
$this->assertFalse(file_exists($folder2));
|
||||||
$this->assertFalse(file_exists($file2));
|
$this->assertFalse(file_exists($file2));
|
||||||
|
|
||||||
$Folder =& new Folder($folder3);
|
$Folder = new Folder($folder3);
|
||||||
$Folder->delete();
|
$Folder->delete();
|
||||||
|
|
||||||
new Folder($folder1, true);
|
new Folder($folder1, true);
|
||||||
|
@ -754,7 +756,7 @@ class FolderTest extends CakeTestCase {
|
||||||
touch($file1);
|
touch($file1);
|
||||||
touch($file2);
|
touch($file2);
|
||||||
|
|
||||||
$Folder =& new Folder($folder1);
|
$Folder = new Folder($folder1);
|
||||||
$result = $Folder->move($folder3);
|
$result = $Folder->move($folder3);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
|
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
|
||||||
|
@ -764,7 +766,7 @@ class FolderTest extends CakeTestCase {
|
||||||
$this->assertFalse(file_exists($folder2));
|
$this->assertFalse(file_exists($folder2));
|
||||||
$this->assertFalse(file_exists($file2));
|
$this->assertFalse(file_exists($file2));
|
||||||
|
|
||||||
$Folder =& new Folder($folder3);
|
$Folder = new Folder($folder3);
|
||||||
$Folder->delete();
|
$Folder->delete();
|
||||||
|
|
||||||
new Folder($folder1, true);
|
new Folder($folder1, true);
|
||||||
|
@ -775,7 +777,7 @@ class FolderTest extends CakeTestCase {
|
||||||
touch($file2);
|
touch($file2);
|
||||||
file_put_contents($folder3 . DS . 'folder2' . DS . 'file2.php', 'untouched');
|
file_put_contents($folder3 . DS . 'folder2' . DS . 'file2.php', 'untouched');
|
||||||
|
|
||||||
$Folder =& new Folder($folder1);
|
$Folder = new Folder($folder1);
|
||||||
$result = $Folder->move($folder3);
|
$result = $Folder->move($folder3);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
|
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
|
||||||
|
@ -784,7 +786,7 @@ class FolderTest extends CakeTestCase {
|
||||||
$this->assertFalse(file_exists($folder2));
|
$this->assertFalse(file_exists($folder2));
|
||||||
$this->assertFalse(file_exists($file2));
|
$this->assertFalse(file_exists($file2));
|
||||||
|
|
||||||
$Folder =& new Folder($path);
|
$Folder = new Folder($path);
|
||||||
$Folder->delete();
|
$Folder->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
268
cake/tests/cases/libs/html_coverage_report.test.php
Normal file
268
cake/tests/cases/libs/html_coverage_report.test.php
Normal file
|
@ -0,0 +1,268 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Test case for HtmlCoverageReport
|
||||||
|
*
|
||||||
|
* PHP5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||||
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.cake
|
||||||
|
* @since CakePHP(tm) v 2.0
|
||||||
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once CAKE . 'tests' . DS . 'lib' . DS . 'coverage' . DS . 'html_coverage_report.php';
|
||||||
|
|
||||||
|
class HtmlCoverageReportTest extends CakeTestCase {
|
||||||
|
/**
|
||||||
|
* setup
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setUp() {
|
||||||
|
$reporter = new CakeBaseReporter();
|
||||||
|
$reporter->params = array('app' => false, 'plugin' => false, 'group' => false);
|
||||||
|
$coverage = array();
|
||||||
|
$this->Coverage = new HtmlCoverageReport($coverage, $reporter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test getting the path filters.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testGetPathFilter() {
|
||||||
|
$this->Coverage->appTest = false;
|
||||||
|
$result = $this->Coverage->getPathFilter();
|
||||||
|
$this->assertEquals(TEST_CAKE_CORE_INCLUDE_PATH, $result);
|
||||||
|
|
||||||
|
$this->Coverage->appTest = true;
|
||||||
|
$result = $this->Coverage->getPathFilter();
|
||||||
|
$this->assertEquals(ROOT . DS . APP_DIR . DS, $result);
|
||||||
|
|
||||||
|
$this->Coverage->appTest = false;
|
||||||
|
$this->Coverage->pluginTest = 'test_plugin';
|
||||||
|
$result = $this->Coverage->getPathFilter();
|
||||||
|
$this->assertEquals(ROOT . DS . APP_DIR . DS . 'plugins' . DS .'test_plugin' . DS, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test filtering coverage data.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testFilterCoverageDataByPathRemovingElements() {
|
||||||
|
$data = array(
|
||||||
|
array(
|
||||||
|
'files' => array(
|
||||||
|
TEST_CAKE_CORE_INCLUDE_PATH . 'dispatcher.php' => array(
|
||||||
|
10 => -1,
|
||||||
|
12 => 1
|
||||||
|
),
|
||||||
|
APP . 'app_model.php' => array(
|
||||||
|
50 => 1,
|
||||||
|
52 => -1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->Coverage->setCoverage($data);
|
||||||
|
$result = $this->Coverage->filterCoverageDataByPath(TEST_CAKE_CORE_INCLUDE_PATH);
|
||||||
|
$this->assertTrue(isset($result[TEST_CAKE_CORE_INCLUDE_PATH . 'dispatcher.php']));
|
||||||
|
$this->assertFalse(isset($result[APP . 'app_model.php']));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that filterCoverageDataByPath correctly merges data sets in each test run.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testFilterCoverageDataCorrectlyMergingValues() {
|
||||||
|
$data = array(
|
||||||
|
array(
|
||||||
|
'files' => array(
|
||||||
|
'/something/dispatcher.php' => array(
|
||||||
|
10 => 1,
|
||||||
|
12 => 1
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'executable' => array(
|
||||||
|
'/something/dispatcher.php' => array(
|
||||||
|
9 => -1
|
||||||
|
)
|
||||||
|
),
|
||||||
|
'dead' => array(
|
||||||
|
'/something/dispatcher.php' => array(
|
||||||
|
22 => -2,
|
||||||
|
23 => -2
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'files' => array(
|
||||||
|
'/something/dispatcher.php' => array(
|
||||||
|
10 => 1,
|
||||||
|
50 => 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'executable' => array(
|
||||||
|
'/something/dispatcher.php' => array(
|
||||||
|
12 => -1,
|
||||||
|
51 => -1
|
||||||
|
)
|
||||||
|
),
|
||||||
|
'dead' => array(
|
||||||
|
'/something/dispatcher.php' => array(
|
||||||
|
13 => -2,
|
||||||
|
42 => -2
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$this->Coverage->setCoverage($data);
|
||||||
|
$result = $this->Coverage->filterCoverageDataByPath('/something/');
|
||||||
|
|
||||||
|
$path = '/something/dispatcher.php';
|
||||||
|
$this->assertTrue(isset($result[$path]));
|
||||||
|
$this->assertEquals(array(10, 12, 50), array_keys($result[$path]['covered']));
|
||||||
|
$this->assertEquals(array(9, 12, 51), array_keys($result[$path]['executable']));
|
||||||
|
$this->assertEquals(array(22, 23, 13, 42), array_keys($result[$path]['dead']));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test generating HTML reports from file arrays.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testGenerateDiff() {
|
||||||
|
$file = array(
|
||||||
|
'line 1',
|
||||||
|
'line 2',
|
||||||
|
'line 3',
|
||||||
|
'line 4',
|
||||||
|
'line 5',
|
||||||
|
'line 6',
|
||||||
|
'line 7',
|
||||||
|
'line 8',
|
||||||
|
'line 9',
|
||||||
|
'line 10',
|
||||||
|
);
|
||||||
|
$coverage = array(
|
||||||
|
'covered' => array(
|
||||||
|
1 => 1,
|
||||||
|
3 => 1,
|
||||||
|
4 => 1,
|
||||||
|
6 => 1,
|
||||||
|
7 => 1,
|
||||||
|
8 => 1,
|
||||||
|
10 => 1
|
||||||
|
),
|
||||||
|
'executable' => array(
|
||||||
|
5 => -1,
|
||||||
|
9 => -1
|
||||||
|
),
|
||||||
|
'dead' => array(
|
||||||
|
2 => -2
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$result = $this->Coverage->generateDiff('myfile.php', $file, $coverage);
|
||||||
|
$this->assertRegExp('/myfile\.php Code coverage\: \d+\.?\d*\%/', $result);
|
||||||
|
$this->assertRegExp('/<div class="code-coverage-results" id\="coverage\-myfile\.php"/', $result);
|
||||||
|
$this->assertRegExp('/<pre>/', $result);
|
||||||
|
foreach ($file as $i => $line) {
|
||||||
|
$this->assertTrue(strpos($line, $result) !== 0, 'Content is missing ' . $i);
|
||||||
|
$class = 'covered';
|
||||||
|
if (in_array($i + 1, array(5, 9, 2))) {
|
||||||
|
$class = 'uncovered';
|
||||||
|
}
|
||||||
|
if ($i + 1 == 2) {
|
||||||
|
$class .= ' dead';
|
||||||
|
}
|
||||||
|
$this->assertTrue(strpos($class, $result) !== 0, 'Class name is wrong ' . $i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that covering methods show up as title attributes for lines.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testCoveredLinesTitleAttributes() {
|
||||||
|
$file = array(
|
||||||
|
'line 1',
|
||||||
|
'line 2',
|
||||||
|
'line 3',
|
||||||
|
'line 4',
|
||||||
|
'line 5',
|
||||||
|
);
|
||||||
|
$mock = $this->getMock('PHPUnit_Framework_TestCase');
|
||||||
|
$mock->expects($this->any())->method('getName')->will($this->returnValue('testAwesomeness'));
|
||||||
|
|
||||||
|
$rawdata = array(
|
||||||
|
array(
|
||||||
|
'test' => $mock,
|
||||||
|
'files' => array(
|
||||||
|
'myfile.php' => array(
|
||||||
|
1 => 1,
|
||||||
|
3 => 1,
|
||||||
|
4 => 1,
|
||||||
|
)
|
||||||
|
),
|
||||||
|
'executable' => array(
|
||||||
|
'myfile.php' => array(
|
||||||
|
5 => -1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$coverage = array(
|
||||||
|
'covered' => array(
|
||||||
|
1 => 1,
|
||||||
|
3 => 1,
|
||||||
|
4 => 1,
|
||||||
|
),
|
||||||
|
'executable' => array(
|
||||||
|
5 => -1,
|
||||||
|
),
|
||||||
|
'dead' => array(
|
||||||
|
2 => -2
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->Coverage->setCoverage($rawdata);
|
||||||
|
$result = $this->Coverage->generateDiff('myfile.php', $file, $coverage);
|
||||||
|
|
||||||
|
$this->assertTrue(
|
||||||
|
strpos($result, "title=\"Covered by:\ntestAwesomeness\n\"><span class=\"line-num\">1") !== false,
|
||||||
|
'Missing method coverage for line 1'
|
||||||
|
);
|
||||||
|
$this->assertTrue(
|
||||||
|
strpos($result, "title=\"Covered by:\ntestAwesomeness\n\"><span class=\"line-num\">3") !== false,
|
||||||
|
'Missing method coverage for line 3'
|
||||||
|
);
|
||||||
|
$this->assertTrue(
|
||||||
|
strpos($result, "title=\"Covered by:\ntestAwesomeness\n\"><span class=\"line-num\">4") !== false,
|
||||||
|
'Missing method coverage for line 4'
|
||||||
|
);
|
||||||
|
$this->assertTrue(
|
||||||
|
strpos($result, "title=\"\"><span class=\"line-num\">5") !== false,
|
||||||
|
'Coverage report is wrong for line 5'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* teardown
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function tearDown() {
|
||||||
|
unset($this->Coverage);
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load diff
|
@ -17,7 +17,7 @@
|
||||||
* @since CakePHP(tm) v 1.3
|
* @since CakePHP(tm) v 1.3
|
||||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||||
*/
|
*/
|
||||||
require_once LIBS . 'log' . DS . 'file_log.php';
|
App::import('Core', 'log/FileLog');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CakeLogTest class
|
* CakeLogTest class
|
||||||
|
|
|
@ -189,7 +189,7 @@ class AclPost extends CakeTestModel {
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.tests.cases.libs.controller.components
|
* @subpackage cake.tests.cases.libs.controller.components
|
||||||
*/
|
*/
|
||||||
class AclBehaviorTestCase extends CakeTestCase {
|
class AclBehaviorTest extends CakeTestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Aco property
|
* Aco property
|
||||||
|
@ -220,11 +220,11 @@ class AclBehaviorTestCase extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function startTest() {
|
public function setUp() {
|
||||||
Configure::write('Acl.database', 'test_suite');
|
Configure::write('Acl.database', 'test_suite');
|
||||||
|
|
||||||
$this->Aco =& new Aco();
|
$this->Aco = new Aco();
|
||||||
$this->Aro =& new Aro();
|
$this->Aro = new Aro();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -243,12 +243,12 @@ class AclBehaviorTestCase extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testSetup() {
|
public function testSetup() {
|
||||||
$User =& new AclUser();
|
$User = new AclUser();
|
||||||
$this->assertTrue(isset($User->Behaviors->Acl->settings['User']));
|
$this->assertTrue(isset($User->Behaviors->Acl->settings['User']));
|
||||||
$this->assertEqual($User->Behaviors->Acl->settings['User']['type'], 'requester');
|
$this->assertEqual($User->Behaviors->Acl->settings['User']['type'], 'requester');
|
||||||
$this->assertTrue(is_object($User->Aro));
|
$this->assertTrue(is_object($User->Aro));
|
||||||
|
|
||||||
$Post =& new AclPost();
|
$Post = new AclPost();
|
||||||
$this->assertTrue(isset($Post->Behaviors->Acl->settings['Post']));
|
$this->assertTrue(isset($Post->Behaviors->Acl->settings['Post']));
|
||||||
$this->assertEqual($Post->Behaviors->Acl->settings['Post']['type'], 'controlled');
|
$this->assertEqual($Post->Behaviors->Acl->settings['Post']['type'], 'controlled');
|
||||||
$this->assertTrue(is_object($Post->Aco));
|
$this->assertTrue(is_object($Post->Aco));
|
||||||
|
@ -260,7 +260,7 @@ class AclBehaviorTestCase extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testAfterSave() {
|
public function testAfterSave() {
|
||||||
$Post =& new AclPost();
|
$Post = new AclPost();
|
||||||
$data = array(
|
$data = array(
|
||||||
'Post' => array(
|
'Post' => array(
|
||||||
'author_id' => 1,
|
'author_id' => 1,
|
||||||
|
@ -284,7 +284,7 @@ class AclBehaviorTestCase extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$this->Aro->save($aroData);
|
$this->Aro->save($aroData);
|
||||||
|
|
||||||
$Person =& new AclPerson();
|
$Person = new AclPerson();
|
||||||
$data = array(
|
$data = array(
|
||||||
'AclPerson' => array(
|
'AclPerson' => array(
|
||||||
'name' => 'Trent',
|
'name' => 'Trent',
|
||||||
|
@ -339,7 +339,7 @@ class AclBehaviorTestCase extends CakeTestCase {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->Aro->save($aroData);
|
$this->Aro->save($aroData);
|
||||||
$Person =& new AclPerson();
|
$Person = new AclPerson();
|
||||||
$data = array(
|
$data = array(
|
||||||
'AclPerson' => array(
|
'AclPerson' => array(
|
||||||
'name' => 'Trent',
|
'name' => 'Trent',
|
||||||
|
@ -384,7 +384,7 @@ class AclBehaviorTestCase extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testNode() {
|
public function testNode() {
|
||||||
$Person =& new AclPerson();
|
$Person = new AclPerson();
|
||||||
$aroData = array(
|
$aroData = array(
|
||||||
'Aro' => array(
|
'Aro' => array(
|
||||||
'model' => 'AclPerson',
|
'model' => 'AclPerson',
|
||||||
|
|
|
@ -53,12 +53,12 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* endTest method
|
* tearDown method
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function endTest() {
|
function tearDown() {
|
||||||
ClassRegistry::flush();
|
ClassRegistry::flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,26 +69,27 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testTranslateModel() {
|
function testTranslateModel() {
|
||||||
$TestModel =& new Tag();
|
$this->loadFixtures('TranslateTable', 'Tag', 'TranslatedItem', 'Translate', 'User', 'TranslatedArticle', 'TranslateArticle');
|
||||||
|
$TestModel = new Tag();
|
||||||
$TestModel->translateTable = 'another_i18n';
|
$TestModel->translateTable = 'another_i18n';
|
||||||
$TestModel->Behaviors->attach('Translate', array('title'));
|
$TestModel->Behaviors->attach('Translate', array('title'));
|
||||||
$translateModel =& $TestModel->Behaviors->Translate->translateModel($TestModel);
|
$translateModel = $TestModel->Behaviors->Translate->translateModel($TestModel);
|
||||||
$this->assertEqual($translateModel->name, 'I18nModel');
|
$this->assertEqual($translateModel->name, 'I18nModel');
|
||||||
$this->assertEqual($translateModel->useTable, 'another_i18n');
|
$this->assertEqual($translateModel->useTable, 'another_i18n');
|
||||||
|
|
||||||
$TestModel =& new User();
|
$TestModel = new User();
|
||||||
$TestModel->Behaviors->attach('Translate', array('title'));
|
$TestModel->Behaviors->attach('Translate', array('title'));
|
||||||
$translateModel =& $TestModel->Behaviors->Translate->translateModel($TestModel);
|
$translateModel = $TestModel->Behaviors->Translate->translateModel($TestModel);
|
||||||
$this->assertEqual($translateModel->name, 'I18nModel');
|
$this->assertEqual($translateModel->name, 'I18nModel');
|
||||||
$this->assertEqual($translateModel->useTable, 'i18n');
|
$this->assertEqual($translateModel->useTable, 'i18n');
|
||||||
|
|
||||||
$TestModel =& new TranslatedArticle();
|
$TestModel = new TranslatedArticle();
|
||||||
$translateModel =& $TestModel->Behaviors->Translate->translateModel($TestModel);
|
$translateModel = $TestModel->Behaviors->Translate->translateModel($TestModel);
|
||||||
$this->assertEqual($translateModel->name, 'TranslateArticleModel');
|
$this->assertEqual($translateModel->name, 'TranslateArticleModel');
|
||||||
$this->assertEqual($translateModel->useTable, 'article_i18n');
|
$this->assertEqual($translateModel->useTable, 'article_i18n');
|
||||||
|
|
||||||
$TestModel =& new TranslatedItem();
|
$TestModel = new TranslatedItem();
|
||||||
$translateModel =& $TestModel->Behaviors->Translate->translateModel($TestModel);
|
$translateModel = $TestModel->Behaviors->Translate->translateModel($TestModel);
|
||||||
$this->assertEqual($translateModel->name, 'TranslateTestModel');
|
$this->assertEqual($translateModel->name, 'TranslateTestModel');
|
||||||
$this->assertEqual($translateModel->useTable, 'i18n');
|
$this->assertEqual($translateModel->useTable, 'i18n');
|
||||||
}
|
}
|
||||||
|
@ -100,9 +101,9 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testLocaleFalsePlain() {
|
function testLocaleFalsePlain() {
|
||||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
$this->loadFixtures('Translate', 'TranslatedItem', 'User');
|
||||||
|
|
||||||
$TestModel =& new TranslatedItem();
|
$TestModel = new TranslatedItem();
|
||||||
$TestModel->locale = false;
|
$TestModel->locale = false;
|
||||||
|
|
||||||
$result = $TestModel->read(null, 1);
|
$result = $TestModel->read(null, 1);
|
||||||
|
@ -127,7 +128,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
function testLocaleFalseAssociations() {
|
function testLocaleFalseAssociations() {
|
||||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||||
|
|
||||||
$TestModel =& new TranslatedItem();
|
$TestModel = new TranslatedItem();
|
||||||
$TestModel->locale = false;
|
$TestModel->locale = false;
|
||||||
$TestModel->unbindTranslation();
|
$TestModel->unbindTranslation();
|
||||||
$translations = array('title' => 'Title', 'content' => 'Content');
|
$translations = array('title' => 'Title', 'content' => 'Content');
|
||||||
|
@ -182,7 +183,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
function testLocaleSingle() {
|
function testLocaleSingle() {
|
||||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||||
|
|
||||||
$TestModel =& new TranslatedItem();
|
$TestModel = new TranslatedItem();
|
||||||
$TestModel->locale = 'eng';
|
$TestModel->locale = 'eng';
|
||||||
$result = $TestModel->read(null, 1);
|
$result = $TestModel->read(null, 1);
|
||||||
$expected = array(
|
$expected = array(
|
||||||
|
@ -238,7 +239,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
function testLocaleSingleWithConditions() {
|
function testLocaleSingleWithConditions() {
|
||||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||||
|
|
||||||
$TestModel =& new TranslatedItem();
|
$TestModel = new TranslatedItem();
|
||||||
$TestModel->locale = 'eng';
|
$TestModel->locale = 'eng';
|
||||||
$result = $TestModel->find('all', array('conditions' => array('slug' => 'first_translated')));
|
$result = $TestModel->find('all', array('conditions' => array('slug' => 'first_translated')));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
|
@ -278,7 +279,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
function testLocaleSingleAssociations() {
|
function testLocaleSingleAssociations() {
|
||||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||||
|
|
||||||
$TestModel =& new TranslatedItem();
|
$TestModel = new TranslatedItem();
|
||||||
$TestModel->locale = 'eng';
|
$TestModel->locale = 'eng';
|
||||||
$TestModel->unbindTranslation();
|
$TestModel->unbindTranslation();
|
||||||
$translations = array('title' => 'Title', 'content' => 'Content');
|
$translations = array('title' => 'Title', 'content' => 'Content');
|
||||||
|
@ -339,7 +340,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
function testLocaleMultiple() {
|
function testLocaleMultiple() {
|
||||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||||
|
|
||||||
$TestModel =& new TranslatedItem();
|
$TestModel = new TranslatedItem();
|
||||||
$TestModel->locale = array('deu', 'eng', 'cze');
|
$TestModel->locale = array('deu', 'eng', 'cze');
|
||||||
$delete = array(
|
$delete = array(
|
||||||
array('locale' => 'deu'),
|
array('locale' => 'deu'),
|
||||||
|
@ -349,7 +350,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
array('foreign_key' => 2, 'field' => 'content', 'locale' => 'eng'),
|
array('foreign_key' => 2, 'field' => 'content', 'locale' => 'eng'),
|
||||||
array('foreign_key' => 3, 'field' => 'title')
|
array('foreign_key' => 3, 'field' => 'title')
|
||||||
);
|
);
|
||||||
$I18nModel =& ClassRegistry::getObject('TranslateTestModel');
|
$I18nModel = ClassRegistry::getObject('TranslateTestModel');
|
||||||
$I18nModel->deleteAll(array('or' => $delete));
|
$I18nModel->deleteAll(array('or' => $delete));
|
||||||
|
|
||||||
$result = $TestModel->read(null, 1);
|
$result = $TestModel->read(null, 1);
|
||||||
|
@ -403,7 +404,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
function testMissingTranslation() {
|
function testMissingTranslation() {
|
||||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||||
|
|
||||||
$TestModel =& new TranslatedItem();
|
$TestModel = new TranslatedItem();
|
||||||
$TestModel->locale = 'rus';
|
$TestModel->locale = 'rus';
|
||||||
$result = $TestModel->read(null, 1);
|
$result = $TestModel->read(null, 1);
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
|
@ -431,7 +432,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
function testTranslatedFindList() {
|
function testTranslatedFindList() {
|
||||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||||
|
|
||||||
$TestModel =& new TranslatedItem();
|
$TestModel = new TranslatedItem();
|
||||||
$TestModel->locale = 'deu';
|
$TestModel->locale = 'deu';
|
||||||
$TestModel->displayField = 'title';
|
$TestModel->displayField = 'title';
|
||||||
$result = $TestModel->find('list', array('recursive' => 1));
|
$result = $TestModel->find('list', array('recursive' => 1));
|
||||||
|
@ -465,7 +466,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
function testReadSelectedFields() {
|
function testReadSelectedFields() {
|
||||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||||
|
|
||||||
$TestModel =& new TranslatedItem();
|
$TestModel = new TranslatedItem();
|
||||||
$TestModel->locale = 'eng';
|
$TestModel->locale = 'eng';
|
||||||
$result = $TestModel->find('all', array('fields' => array('slug', 'TranslatedItem.content')));
|
$result = $TestModel->find('all', array('fields' => array('slug', 'TranslatedItem.content')));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
|
@ -480,7 +481,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
|
|
||||||
$TestModel->locale = array('eng', 'deu', 'cze');
|
$TestModel->locale = array('eng', 'deu', 'cze');
|
||||||
$delete = array(array('locale' => 'deu'), array('field' => 'content', 'locale' => 'eng'));
|
$delete = array(array('locale' => 'deu'), array('field' => 'content', 'locale' => 'eng'));
|
||||||
$I18nModel =& ClassRegistry::getObject('TranslateTestModel');
|
$I18nModel = ClassRegistry::getObject('TranslateTestModel');
|
||||||
$I18nModel->deleteAll(array('or' => $delete));
|
$I18nModel->deleteAll(array('or' => $delete));
|
||||||
|
|
||||||
$result = $TestModel->find('all', array('fields' => array('title', 'content')));
|
$result = $TestModel->find('all', array('fields' => array('title', 'content')));
|
||||||
|
@ -501,7 +502,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
function testSaveCreate() {
|
function testSaveCreate() {
|
||||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||||
|
|
||||||
$TestModel =& new TranslatedItem();
|
$TestModel = new TranslatedItem();
|
||||||
$TestModel->locale = 'spa';
|
$TestModel->locale = 'spa';
|
||||||
$data = array('slug' => 'fourth_translated', 'title' => 'Leyenda #4', 'content' => 'Contenido #4');
|
$data = array('slug' => 'fourth_translated', 'title' => 'Leyenda #4', 'content' => 'Contenido #4');
|
||||||
$TestModel->create($data);
|
$TestModel->create($data);
|
||||||
|
@ -520,7 +521,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
function testSaveUpdate() {
|
function testSaveUpdate() {
|
||||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||||
|
|
||||||
$TestModel =& new TranslatedItem();
|
$TestModel = new TranslatedItem();
|
||||||
$TestModel->locale = 'spa';
|
$TestModel->locale = 'spa';
|
||||||
$oldData = array('slug' => 'fourth_translated', 'title' => 'Leyenda #4');
|
$oldData = array('slug' => 'fourth_translated', 'title' => 'Leyenda #4');
|
||||||
$TestModel->create($oldData);
|
$TestModel->create($oldData);
|
||||||
|
@ -543,7 +544,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
function testMultipleCreate() {
|
function testMultipleCreate() {
|
||||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||||
|
|
||||||
$TestModel =& new TranslatedItem();
|
$TestModel = new TranslatedItem();
|
||||||
$TestModel->locale = 'deu';
|
$TestModel->locale = 'deu';
|
||||||
$data = array(
|
$data = array(
|
||||||
'slug' => 'new_translated',
|
'slug' => 'new_translated',
|
||||||
|
@ -582,7 +583,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
function testMultipleUpdate() {
|
function testMultipleUpdate() {
|
||||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||||
|
|
||||||
$TestModel =& new TranslatedItem();
|
$TestModel = new TranslatedItem();
|
||||||
$TestModel->locale = 'eng';
|
$TestModel->locale = 'eng';
|
||||||
$TestModel->validate['title'] = 'notEmpty';
|
$TestModel->validate['title'] = 'notEmpty';
|
||||||
$data = array('TranslatedItem' => array(
|
$data = array('TranslatedItem' => array(
|
||||||
|
@ -625,7 +626,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
function testMixedCreateUpdateWithArrayLocale() {
|
function testMixedCreateUpdateWithArrayLocale() {
|
||||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||||
|
|
||||||
$TestModel =& new TranslatedItem();
|
$TestModel = new TranslatedItem();
|
||||||
$TestModel->locale = array('cze', 'deu');
|
$TestModel->locale = array('cze', 'deu');
|
||||||
$data = array('TranslatedItem' => array(
|
$data = array('TranslatedItem' => array(
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
|
@ -665,7 +666,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
function testValidation() {
|
function testValidation() {
|
||||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||||
|
|
||||||
$TestModel =& new TranslatedItem();
|
$TestModel = new TranslatedItem();
|
||||||
$TestModel->locale = 'eng';
|
$TestModel->locale = 'eng';
|
||||||
$TestModel->validate['title'] = '/Only this title/';
|
$TestModel->validate['title'] = '/Only this title/';
|
||||||
$data = array('TranslatedItem' => array(
|
$data = array('TranslatedItem' => array(
|
||||||
|
@ -685,7 +686,8 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
'content' => array('eng' => 'New Content #1', 'deu' => 'Neue Inhalt #1', 'cze' => 'Novy Obsah #1')
|
'content' => array('eng' => 'New Content #1', 'deu' => 'Neue Inhalt #1', 'cze' => 'Novy Obsah #1')
|
||||||
));
|
));
|
||||||
$TestModel->create();
|
$TestModel->create();
|
||||||
$this->assertTrue($TestModel->save($data));
|
$result = $TestModel->save($data);
|
||||||
|
$this->assertFalse(empty($result));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -697,8 +699,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
function testAttachDetach() {
|
function testAttachDetach() {
|
||||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||||
|
|
||||||
$TestModel =& new TranslatedItem();
|
$TestModel = new TranslatedItem();
|
||||||
$Behavior =& $this->Model->Behaviors->Translate;
|
|
||||||
|
|
||||||
$TestModel->unbindTranslation();
|
$TestModel->unbindTranslation();
|
||||||
$translations = array('title' => 'Title', 'content' => 'Content');
|
$translations = array('title' => 'Title', 'content' => 'Content');
|
||||||
|
@ -748,7 +749,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
function testAnotherTranslateTable() {
|
function testAnotherTranslateTable() {
|
||||||
$this->loadFixtures('Translate', 'TranslatedItem', 'TranslateTable');
|
$this->loadFixtures('Translate', 'TranslatedItem', 'TranslateTable');
|
||||||
|
|
||||||
$TestModel =& new TranslatedItemWithTable();
|
$TestModel = new TranslatedItemWithTable();
|
||||||
$TestModel->locale = 'eng';
|
$TestModel->locale = 'eng';
|
||||||
$result = $TestModel->read(null, 1);
|
$result = $TestModel->read(null, 1);
|
||||||
$expected = array(
|
$expected = array(
|
||||||
|
@ -772,7 +773,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
function testTranslateWithAssociations() {
|
function testTranslateWithAssociations() {
|
||||||
$this->loadFixtures('TranslateArticle', 'TranslatedArticle', 'User', 'Comment', 'ArticlesTag', 'Tag');
|
$this->loadFixtures('TranslateArticle', 'TranslatedArticle', 'User', 'Comment', 'ArticlesTag', 'Tag');
|
||||||
|
|
||||||
$TestModel =& new TranslatedArticle();
|
$TestModel = new TranslatedArticle();
|
||||||
$TestModel->locale = 'eng';
|
$TestModel->locale = 'eng';
|
||||||
$recursive = $TestModel->recursive;
|
$recursive = $TestModel->recursive;
|
||||||
|
|
||||||
|
@ -865,7 +866,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testTranslateTableWithPrefix() {
|
function testTranslateTableWithPrefix() {
|
||||||
$this->loadFixtures('TranslateWithPrefix', 'TranslatedItem');
|
$this->loadFixtures('TranslateWithPrefix', 'TranslatedItem');
|
||||||
$TestModel =& new TranslatedItem2;
|
$TestModel = new TranslatedItem2;
|
||||||
$TestModel->locale = 'eng';
|
$TestModel->locale = 'eng';
|
||||||
$result = $TestModel->read(null, 1);
|
$result = $TestModel->read(null, 1);
|
||||||
$expected = array('TranslatedItem' => array(
|
$expected = array('TranslatedItem' => array(
|
||||||
|
@ -886,7 +887,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
function testUnbindTranslationInfinteLoop() {
|
function testUnbindTranslationInfinteLoop() {
|
||||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||||
|
|
||||||
$TestModel =& new TranslatedItem();
|
$TestModel = new TranslatedItem();
|
||||||
$TestModel->Behaviors->detach('Translate');
|
$TestModel->Behaviors->detach('Translate');
|
||||||
$TestModel->actsAs = array();
|
$TestModel->actsAs = array();
|
||||||
$TestModel->Behaviors->attach('Translate');
|
$TestModel->Behaviors->attach('Translate');
|
||||||
|
|
|
@ -30,13 +30,21 @@ require_once(dirname(dirname(__FILE__)) . DS . 'models.php');
|
||||||
*/
|
*/
|
||||||
class NumberTreeTest extends CakeTestCase {
|
class NumberTreeTest extends CakeTestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether backup global state for each test method or not
|
||||||
|
*
|
||||||
|
* @var bool false
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
public $backupGlobals = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* settings property
|
* settings property
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
* @access public
|
* @access protected
|
||||||
*/
|
*/
|
||||||
public $settings = array(
|
protected $settings = array(
|
||||||
'modelClass' => 'NumberTree',
|
'modelClass' => 'NumberTree',
|
||||||
'leftField' => 'lft',
|
'leftField' => 'lft',
|
||||||
'rightField' => 'rght',
|
'rightField' => 'rght',
|
||||||
|
@ -59,7 +67,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testInitialize() {
|
function testInitialize() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$result = $this->Tree->find('count');
|
$result = $this->Tree->find('count');
|
||||||
|
@ -77,7 +85,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testDetectInvalidLeft() {
|
function testDetectInvalidLeft() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$result = $this->Tree->findByName('1.1');
|
$result = $this->Tree->findByName('1.1');
|
||||||
|
@ -104,7 +112,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testDetectInvalidRight() {
|
function testDetectInvalidRight() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$result = $this->Tree->findByName('1.1');
|
$result = $this->Tree->findByName('1.1');
|
||||||
|
@ -131,7 +139,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testDetectInvalidParent() {
|
function testDetectInvalidParent() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$result = $this->Tree->findByName('1.1');
|
$result = $this->Tree->findByName('1.1');
|
||||||
|
@ -157,7 +165,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testDetectNoneExistantParent() {
|
function testDetectNoneExistantParent() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$result = $this->Tree->findByName('1.1');
|
$result = $this->Tree->findByName('1.1');
|
||||||
|
@ -181,7 +189,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testRecoverFromMissingParent() {
|
function testRecoverFromMissingParent() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$result = $this->Tree->findByName('1.1');
|
$result = $this->Tree->findByName('1.1');
|
||||||
|
@ -205,7 +213,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testDetectInvalidParents() {
|
function testDetectInvalidParents() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$this->Tree->updateAll(array($parentField => null));
|
$this->Tree->updateAll(array($parentField => null));
|
||||||
|
@ -228,7 +236,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testDetectInvalidLftsRghts() {
|
function testDetectInvalidLftsRghts() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$this->Tree->updateAll(array($leftField => 0, $rightField => 0));
|
$this->Tree->updateAll(array($leftField => 0, $rightField => 0));
|
||||||
|
@ -250,7 +258,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testDetectEqualLftsRghts() {
|
function testDetectEqualLftsRghts() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(1, 3);
|
$this->Tree->initialize(1, 3);
|
||||||
|
|
||||||
$result = $this->Tree->findByName('1.1');
|
$result = $this->Tree->findByName('1.1');
|
||||||
|
@ -278,7 +286,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testAddOrphan() {
|
function testAddOrphan() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$this->Tree->save(array($modelClass => array('name' => 'testAddOrphan', $parentField => null)));
|
$this->Tree->save(array($modelClass => array('name' => 'testAddOrphan', $parentField => null)));
|
||||||
|
@ -298,7 +306,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testAddMiddle() {
|
function testAddMiddle() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$data= $this->Tree->find(array($modelClass . '.name' => '1.1'), array('id'));
|
$data= $this->Tree->find(array($modelClass . '.name' => '1.1'), array('id'));
|
||||||
|
@ -332,7 +340,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testAddInvalid() {
|
function testAddInvalid() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
$this->Tree->id = null;
|
$this->Tree->id = null;
|
||||||
|
|
||||||
|
@ -357,7 +365,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testAddNotIndexedByModel() {
|
function testAddNotIndexedByModel() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$this->Tree->save(array('name' => 'testAddNotIndexed', $parentField => null));
|
$this->Tree->save(array('name' => 'testAddNotIndexed', $parentField => null));
|
||||||
|
@ -377,7 +385,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testMovePromote() {
|
function testMovePromote() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
$this->Tree->id = null;
|
$this->Tree->id = null;
|
||||||
|
|
||||||
|
@ -404,7 +412,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testMoveWithWhitelist() {
|
function testMoveWithWhitelist() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
$this->Tree->id = null;
|
$this->Tree->id = null;
|
||||||
|
|
||||||
|
@ -432,7 +440,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testInsertWithWhitelist() {
|
function testInsertWithWhitelist() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$this->Tree->whitelist = array('name', $parentField);
|
$this->Tree->whitelist = array('name', $parentField);
|
||||||
|
@ -451,7 +459,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testMoveBefore() {
|
function testMoveBefore() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
$this->Tree->id = null;
|
$this->Tree->id = null;
|
||||||
|
|
||||||
|
@ -480,7 +488,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testMoveAfter() {
|
function testMoveAfter() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
$this->Tree->id = null;
|
$this->Tree->id = null;
|
||||||
|
|
||||||
|
@ -509,7 +517,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testMoveDemoteInvalid() {
|
function testMoveDemoteInvalid() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
$this->Tree->id = null;
|
$this->Tree->id = null;
|
||||||
|
|
||||||
|
@ -543,7 +551,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testMoveInvalid() {
|
function testMoveInvalid() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
$this->Tree->id = null;
|
$this->Tree->id = null;
|
||||||
|
|
||||||
|
@ -570,7 +578,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testMoveSelfInvalid() {
|
function testMoveSelfInvalid() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
$this->Tree->id = null;
|
$this->Tree->id = null;
|
||||||
|
|
||||||
|
@ -597,7 +605,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testMoveUpSuccess() {
|
function testMoveUpSuccess() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$data = $this->Tree->find(array($modelClass . '.name' => '1.2'), array('id'));
|
$data = $this->Tree->find(array($modelClass . '.name' => '1.2'), array('id'));
|
||||||
|
@ -619,7 +627,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testMoveUpFail() {
|
function testMoveUpFail() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$data = $this->Tree->find(array($modelClass . '.name' => '1.1'));
|
$data = $this->Tree->find(array($modelClass . '.name' => '1.1'));
|
||||||
|
@ -642,7 +650,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testMoveUp2() {
|
function testMoveUp2() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(1, 10);
|
$this->Tree->initialize(1, 10);
|
||||||
|
|
||||||
$data = $this->Tree->find(array($modelClass . '.name' => '1.5'), array('id'));
|
$data = $this->Tree->find(array($modelClass . '.name' => '1.5'), array('id'));
|
||||||
|
@ -673,7 +681,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testMoveUpFirst() {
|
function testMoveUpFirst() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(1, 10);
|
$this->Tree->initialize(1, 10);
|
||||||
|
|
||||||
$data = $this->Tree->find(array($modelClass . '.name' => '1.5'), array('id'));
|
$data = $this->Tree->find(array($modelClass . '.name' => '1.5'), array('id'));
|
||||||
|
@ -704,7 +712,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testMoveDownSuccess() {
|
function testMoveDownSuccess() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$data = $this->Tree->find(array($modelClass . '.name' => '1.1'), array('id'));
|
$data = $this->Tree->find(array($modelClass . '.name' => '1.1'), array('id'));
|
||||||
|
@ -726,7 +734,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testMoveDownFail() {
|
function testMoveDownFail() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$data = $this->Tree->find(array($modelClass . '.name' => '1.2'));
|
$data = $this->Tree->find(array($modelClass . '.name' => '1.2'));
|
||||||
|
@ -748,7 +756,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testMoveDownLast() {
|
function testMoveDownLast() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(1, 10);
|
$this->Tree->initialize(1, 10);
|
||||||
|
|
||||||
$data = $this->Tree->find(array($modelClass . '.name' => '1.5'), array('id'));
|
$data = $this->Tree->find(array($modelClass . '.name' => '1.5'), array('id'));
|
||||||
|
@ -779,7 +787,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testMoveDown2() {
|
function testMoveDown2() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(1, 10);
|
$this->Tree->initialize(1, 10);
|
||||||
|
|
||||||
$data = $this->Tree->find(array($modelClass . '.name' => '1.5'), array('id'));
|
$data = $this->Tree->find(array($modelClass . '.name' => '1.5'), array('id'));
|
||||||
|
@ -810,7 +818,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testSaveNoMove() {
|
function testSaveNoMove() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(1, 10);
|
$this->Tree->initialize(1, 10);
|
||||||
|
|
||||||
$data = $this->Tree->find(array($modelClass . '.name' => '1.5'), array('id'));
|
$data = $this->Tree->find(array($modelClass . '.name' => '1.5'), array('id'));
|
||||||
|
@ -841,7 +849,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testMoveToRootAndMoveUp() {
|
function testMoveToRootAndMoveUp() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(1, 1);
|
$this->Tree->initialize(1, 1);
|
||||||
$data = $this->Tree->find(array($modelClass . '.name' => '1.1'), array('id'));
|
$data = $this->Tree->find(array($modelClass . '.name' => '1.1'), array('id'));
|
||||||
$this->Tree->id = $data[$modelClass]['id'];
|
$this->Tree->id = $data[$modelClass]['id'];
|
||||||
|
@ -866,7 +874,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testDelete() {
|
function testDelete() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$initialCount = $this->Tree->find('count');
|
$initialCount = $this->Tree->find('count');
|
||||||
|
@ -902,7 +910,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testRemove() {
|
function testRemove() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
$initialCount = $this->Tree->find('count');
|
$initialCount = $this->Tree->find('count');
|
||||||
$result = $this->Tree->findByName('1.1');
|
$result = $this->Tree->findByName('1.1');
|
||||||
|
@ -935,7 +943,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testRemoveLastTopParent() {
|
function testRemoveLastTopParent() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$initialCount = $this->Tree->find('count');
|
$initialCount = $this->Tree->find('count');
|
||||||
|
@ -968,7 +976,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testRemoveNoChildren() {
|
public function testRemoveNoChildren() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
$initialCount = $this->Tree->find('count');
|
$initialCount = $this->Tree->find('count');
|
||||||
|
|
||||||
|
@ -1003,7 +1011,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testRemoveAndDelete() {
|
function testRemoveAndDelete() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$initialCount = $this->Tree->find('count');
|
$initialCount = $this->Tree->find('count');
|
||||||
|
@ -1035,7 +1043,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testRemoveAndDeleteNoChildren() {
|
public function testRemoveAndDeleteNoChildren() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
$initialCount = $this->Tree->find('count');
|
$initialCount = $this->Tree->find('count');
|
||||||
|
|
||||||
|
@ -1068,7 +1076,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testChildren() {
|
function testChildren() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
|
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
|
||||||
|
@ -1097,7 +1105,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testCountChildren() {
|
function testCountChildren() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
|
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
|
||||||
|
@ -1118,7 +1126,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testGetParentNode() {
|
function testGetParentNode() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$data = $this->Tree->find(array($modelClass . '.name' => '1.2.2'));
|
$data = $this->Tree->find(array($modelClass . '.name' => '1.2.2'));
|
||||||
|
@ -1137,7 +1145,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testGetPath() {
|
function testGetPath() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$data = $this->Tree->find(array($modelClass . '.name' => '1.2.2'));
|
$data = $this->Tree->find(array($modelClass . '.name' => '1.2.2'));
|
||||||
|
@ -1158,7 +1166,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testNoAmbiguousColumn() {
|
function testNoAmbiguousColumn() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
|
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
|
||||||
array('className' => $modelClass, 'foreignKey' => $parentField, 'conditions' => array('Dummy.id' => null)))), false);
|
array('className' => $modelClass, 'foreignKey' => $parentField, 'conditions' => array('Dummy.id' => null)))), false);
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
@ -1191,7 +1199,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testReorderTree() {
|
function testReorderTree() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(3, 3);
|
$this->Tree->initialize(3, 3);
|
||||||
$nodes = $this->Tree->find('list', array('order' => $leftField));
|
$nodes = $this->Tree->find('list', array('order' => $leftField));
|
||||||
|
|
||||||
|
@ -1205,7 +1213,8 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
$this->Tree->moveDown($data[$modelClass]['id']);
|
$this->Tree->moveDown($data[$modelClass]['id']);
|
||||||
|
|
||||||
$unsortedNodes = $this->Tree->find('list', array('order' => $leftField));
|
$unsortedNodes = $this->Tree->find('list', array('order' => $leftField));
|
||||||
$this->assertNotIdentical($nodes, $unsortedNodes);
|
$this->assertEquals($nodes, $unsortedNodes);
|
||||||
|
$this->assertNotEquals(array_keys($nodes), array_keys($unsortedNodes));
|
||||||
|
|
||||||
$this->Tree->reorder();
|
$this->Tree->reorder();
|
||||||
$sortedNodes = $this->Tree->find('list', array('order' => $leftField));
|
$sortedNodes = $this->Tree->find('list', array('order' => $leftField));
|
||||||
|
@ -1222,7 +1231,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testReorderBigTreeWithQueryCaching() {
|
function testReorderBigTreeWithQueryCaching() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 10);
|
$this->Tree->initialize(2, 10);
|
||||||
|
|
||||||
$original = $this->Tree->cacheQueries;
|
$original = $this->Tree->cacheQueries;
|
||||||
|
@ -1239,7 +1248,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testGenerateTreeListWithSelfJoin() {
|
function testGenerateTreeListWithSelfJoin() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
|
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
|
||||||
array('className' => $modelClass, 'foreignKey' => $parentField, 'conditions' => array('Dummy.id' => null)))), false);
|
array('className' => $modelClass, 'foreignKey' => $parentField, 'conditions' => array('Dummy.id' => null)))), false);
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
@ -1257,7 +1266,7 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testArraySyntax() {
|
function testArraySyntax() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(3, 3);
|
$this->Tree->initialize(3, 3);
|
||||||
$this->assertIdentical($this->Tree->childCount(2), $this->Tree->childCount(array('id' => 2)));
|
$this->assertIdentical($this->Tree->childCount(2), $this->Tree->childCount(array('id' => 2)));
|
||||||
$this->assertIdentical($this->Tree->getParentNode(2), $this->Tree->getParentNode(array('id' => 2)));
|
$this->assertIdentical($this->Tree->getParentNode(2), $this->Tree->getParentNode(array('id' => 2)));
|
||||||
|
@ -1271,7 +1280,15 @@ class NumberTreeTest extends CakeTestCase {
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.tests.cases.libs.model.behaviors
|
* @subpackage cake.tests.cases.libs.model.behaviors
|
||||||
*/
|
*/
|
||||||
class ScopedTreeTest extends NumberTreeTest {
|
class ScopedTreeTest extends CakeTestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether backup global state for each test method or not
|
||||||
|
*
|
||||||
|
* @var bool false
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
public $backupGlobals = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* settings property
|
* settings property
|
||||||
|
@ -1301,7 +1318,7 @@ class ScopedTreeTest extends NumberTreeTest {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testStringScope() {
|
function testStringScope() {
|
||||||
$this->Tree =& new FlagTree();
|
$this->Tree = new FlagTree();
|
||||||
$this->Tree->initialize(2, 3);
|
$this->Tree->initialize(2, 3);
|
||||||
|
|
||||||
$this->Tree->id = 1;
|
$this->Tree->id = 1;
|
||||||
|
@ -1338,7 +1355,7 @@ class ScopedTreeTest extends NumberTreeTest {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testArrayScope() {
|
function testArrayScope() {
|
||||||
$this->Tree =& new FlagTree();
|
$this->Tree = new FlagTree();
|
||||||
$this->Tree->initialize(2, 3);
|
$this->Tree->initialize(2, 3);
|
||||||
|
|
||||||
$this->Tree->id = 1;
|
$this->Tree->id = 1;
|
||||||
|
@ -1375,7 +1392,7 @@ class ScopedTreeTest extends NumberTreeTest {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testMoveUpWithScope() {
|
function testMoveUpWithScope() {
|
||||||
$this->Ad =& new Ad();
|
$this->Ad = new Ad();
|
||||||
$this->Ad->Behaviors->attach('Tree', array('scope'=>'Campaign'));
|
$this->Ad->Behaviors->attach('Tree', array('scope'=>'Campaign'));
|
||||||
$this->Ad->moveUp(6);
|
$this->Ad->moveUp(6);
|
||||||
|
|
||||||
|
@ -1392,7 +1409,7 @@ class ScopedTreeTest extends NumberTreeTest {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testMoveDownWithScope() {
|
function testMoveDownWithScope() {
|
||||||
$this->Ad =& new Ad();
|
$this->Ad = new Ad();
|
||||||
$this->Ad->Behaviors->attach('Tree', array('scope' => 'Campaign'));
|
$this->Ad->Behaviors->attach('Tree', array('scope' => 'Campaign'));
|
||||||
$this->Ad->moveDown(6);
|
$this->Ad->moveDown(6);
|
||||||
|
|
||||||
|
@ -1410,7 +1427,7 @@ class ScopedTreeTest extends NumberTreeTest {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testTranslatingTree() {
|
function testTranslatingTree() {
|
||||||
$this->Tree =& new FlagTree();
|
$this->Tree = new FlagTree();
|
||||||
$this->Tree->cacheQueries = false;
|
$this->Tree->cacheQueries = false;
|
||||||
$this->Tree->translateModel = 'TranslateTreeTestModel';
|
$this->Tree->translateModel = 'TranslateTreeTestModel';
|
||||||
$this->Tree->Behaviors->attach('Translate', array('name'));
|
$this->Tree->Behaviors->attach('Translate', array('name'));
|
||||||
|
@ -1509,10 +1526,10 @@ class ScopedTreeTest extends NumberTreeTest {
|
||||||
*/
|
*/
|
||||||
public function testAliasesWithScopeInTwoTreeAssociations() {
|
public function testAliasesWithScopeInTwoTreeAssociations() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$this->TreeTwo =& new NumberTreeTwo();
|
$this->TreeTwo = new NumberTreeTwo();
|
||||||
|
|
||||||
$record = $this->Tree->find('first');
|
$record = $this->Tree->find('first');
|
||||||
|
|
||||||
|
@ -1543,7 +1560,8 @@ class ScopedTreeTest extends NumberTreeTest {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->TreeTwo->create();
|
$this->TreeTwo->create();
|
||||||
$this->assertTrue($this->TreeTwo->save($data));
|
$result = $this->TreeTwo->save($data);
|
||||||
|
$this->assertFalse(empty($result));
|
||||||
|
|
||||||
$result = $this->TreeTwo->find('first');
|
$result = $this->TreeTwo->find('first');
|
||||||
$expected = array('NumberTreeTwo' => array(
|
$expected = array('NumberTreeTwo' => array(
|
||||||
|
@ -1564,7 +1582,15 @@ class ScopedTreeTest extends NumberTreeTest {
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.tests.cases.libs.model.behaviors
|
* @subpackage cake.tests.cases.libs.model.behaviors
|
||||||
*/
|
*/
|
||||||
class AfterTreeTest extends NumberTreeTest {
|
class AfterTreeTest extends CakeTestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether backup global state for each test method or not
|
||||||
|
*
|
||||||
|
* @var bool false
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
public $backupGlobals = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* settings property
|
* settings property
|
||||||
|
@ -1594,7 +1620,7 @@ class AfterTreeTest extends NumberTreeTest {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testAftersaveCallback() {
|
function testAftersaveCallback() {
|
||||||
$this->Tree =& new AfterTree();
|
$this->Tree = new AfterTree();
|
||||||
|
|
||||||
$expected = array('AfterTree' => array('name' => 'Six and One Half Changed in AfterTree::afterSave() but not in database', 'parent_id' => 6, 'lft' => 11, 'rght' => 12));
|
$expected = array('AfterTree' => array('name' => 'Six and One Half Changed in AfterTree::afterSave() but not in database', 'parent_id' => 6, 'lft' => 11, 'rght' => 12));
|
||||||
$result = $this->Tree->save(array('AfterTree' => array('name' => 'Six and One Half', 'parent_id' => 6)));
|
$result = $this->Tree->save(array('AfterTree' => array('name' => 'Six and One Half', 'parent_id' => 6)));
|
||||||
|
@ -1606,43 +1632,21 @@ class AfterTreeTest extends NumberTreeTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* UnconventionalTreeTest class
|
|
||||||
*
|
|
||||||
* @package cake
|
|
||||||
* @subpackage cake.tests.cases.libs.model.behaviors
|
|
||||||
*/
|
|
||||||
class UnconventionalTreeTest extends NumberTreeTest {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* settings property
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
public $settings = array(
|
|
||||||
'modelClass' => 'UnconventionalTree',
|
|
||||||
'leftField' => 'left',
|
|
||||||
'rightField' => 'right',
|
|
||||||
'parentField' => 'join'
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* fixtures property
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
public $fixtures = array('core.unconventional_tree');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UuidTreeTest class
|
* UuidTreeTest class
|
||||||
*
|
*
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.tests.cases.libs.model.behaviors
|
* @subpackage cake.tests.cases.libs.model.behaviors
|
||||||
*/
|
*/
|
||||||
class UuidTreeTest extends NumberTreeTest {
|
class UuidTreeTest extends CakeTestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether backup global state for each test method or not
|
||||||
|
*
|
||||||
|
* @var bool false
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
public $backupGlobals = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* settings property
|
* settings property
|
||||||
|
@ -1672,7 +1676,7 @@ class UuidTreeTest extends NumberTreeTest {
|
||||||
*/
|
*/
|
||||||
public function testMovePromote() {
|
public function testMovePromote() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
$this->Tree->id = null;
|
$this->Tree->id = null;
|
||||||
|
|
||||||
|
@ -1698,7 +1702,7 @@ class UuidTreeTest extends NumberTreeTest {
|
||||||
*/
|
*/
|
||||||
public function testMoveWithWhitelist() {
|
public function testMoveWithWhitelist() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
$this->Tree->id = null;
|
$this->Tree->id = null;
|
||||||
|
|
||||||
|
@ -1725,7 +1729,7 @@ class UuidTreeTest extends NumberTreeTest {
|
||||||
*/
|
*/
|
||||||
public function testRemoveNoChildren() {
|
public function testRemoveNoChildren() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
$initialCount = $this->Tree->find('count');
|
$initialCount = $this->Tree->find('count');
|
||||||
|
|
||||||
|
@ -1759,7 +1763,7 @@ class UuidTreeTest extends NumberTreeTest {
|
||||||
*/
|
*/
|
||||||
public function testRemoveAndDeleteNoChildren() {
|
public function testRemoveAndDeleteNoChildren() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
$initialCount = $this->Tree->find('count');
|
$initialCount = $this->Tree->find('count');
|
||||||
|
|
||||||
|
@ -1791,7 +1795,7 @@ class UuidTreeTest extends NumberTreeTest {
|
||||||
*/
|
*/
|
||||||
public function testChildren() {
|
public function testChildren() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
|
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
|
||||||
|
@ -1819,7 +1823,7 @@ class UuidTreeTest extends NumberTreeTest {
|
||||||
*/
|
*/
|
||||||
public function testNoAmbiguousColumn() {
|
public function testNoAmbiguousColumn() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
|
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
|
||||||
|
@ -1852,7 +1856,7 @@ class UuidTreeTest extends NumberTreeTest {
|
||||||
*/
|
*/
|
||||||
public function testGenerateTreeListWithSelfJoin() {
|
public function testGenerateTreeListWithSelfJoin() {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree = new $modelClass();
|
||||||
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
|
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
|
||||||
array('className' => $modelClass, 'foreignKey' => $parentField, 'conditions' => array('Dummy.id' => null)))), false);
|
array('className' => $modelClass, 'foreignKey' => $parentField, 'conditions' => array('Dummy.id' => null)))), false);
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
|
@ -737,7 +737,7 @@ class CakeSchemaTest extends CakeTestCase {
|
||||||
),
|
),
|
||||||
'posts' => array(
|
'posts' => array(
|
||||||
'add' => array(
|
'add' => array(
|
||||||
'summary' => array('type' => 'text', 'null' => 1),
|
'summary' => array('type' => 'text', 'null' => true),
|
||||||
),
|
),
|
||||||
'drop' => array(
|
'drop' => array(
|
||||||
'tableParameters' => array(),
|
'tableParameters' => array(),
|
||||||
|
@ -745,7 +745,7 @@ class CakeSchemaTest extends CakeTestCase {
|
||||||
'change' => array(
|
'change' => array(
|
||||||
'author_id' => array('type' => 'integer', 'null' => true, 'default' => ''),
|
'author_id' => array('type' => 'integer', 'null' => true, 'default' => ''),
|
||||||
'title' => array('type' => 'string', 'null' => false, 'default' => 'Title'),
|
'title' => array('type' => 'string', 'null' => false, 'default' => 'Title'),
|
||||||
'published' => array('type' => 'string', 'null' => true, 'default' => 'Y', 'length' => '1')
|
'published' => array('type' => 'string', 'null' => true, 'default' => 'Y', 'length' => 1)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -34,7 +34,7 @@ class ConnectionManagerTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function setUp() {
|
function setUp() {
|
||||||
$this->ConnectionManager =& ConnectionManager::getInstance();
|
$this->ConnectionManager = ConnectionManager::getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,12 +79,12 @@ class ConnectionManagerTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testGetDataSource() {
|
function testGetDataSource() {
|
||||||
$connections = ConnectionManager::enumConnectionObjects();
|
$connections = ConnectionManager::enumConnectionObjects();
|
||||||
$this->assertTrue(count(array_keys($connections) >= 1));
|
$this->assertTrue((bool)(count(array_keys($connections) >= 1)));
|
||||||
|
|
||||||
$source = ConnectionManager::getDataSource(key($connections));
|
$source = ConnectionManager::getDataSource(key($connections));
|
||||||
$this->assertTrue(is_object($source));
|
$this->assertTrue(is_object($source));
|
||||||
|
|
||||||
$this->expectError(new PatternExpectation('/Non-existent data source/i'));
|
$this->expectError();
|
||||||
|
|
||||||
$source = ConnectionManager::getDataSource('non_existent_source');
|
$source = ConnectionManager::getDataSource('non_existent_source');
|
||||||
$this->assertEqual($source, null);
|
$this->assertEqual($source, null);
|
||||||
|
@ -212,7 +212,7 @@ class ConnectionManagerTest extends CakeTestCase {
|
||||||
|
|
||||||
$this->assertEqual($result, $name);
|
$this->assertEqual($result, $name);
|
||||||
|
|
||||||
$source =& new StdClass();
|
$source = new StdClass();
|
||||||
$result = ConnectionManager::getSourceName($source);
|
$result = ConnectionManager::getSourceName($source);
|
||||||
$this->assertEqual($result, null);
|
$this->assertEqual($result, null);
|
||||||
}
|
}
|
||||||
|
@ -238,7 +238,7 @@ class ConnectionManagerTest extends CakeTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
$connection = array('classname' => 'NonExistentDataSource', 'filename' => 'non_existent');
|
$connection = array('classname' => 'NonExistentDataSource', 'filename' => 'non_existent');
|
||||||
$this->expectError(new PatternExpectation('/Unable to import DataSource class/i'));
|
$this->expectError();
|
||||||
|
|
||||||
$loaded = ConnectionManager::loadDataSource($connection);
|
$loaded = ConnectionManager::loadDataSource($connection);
|
||||||
$this->assertEqual($loaded, null);
|
$this->assertEqual($loaded, null);
|
||||||
|
@ -254,7 +254,7 @@ class ConnectionManagerTest extends CakeTestCase {
|
||||||
$name = 'test_created_connection';
|
$name = 'test_created_connection';
|
||||||
|
|
||||||
$connections = ConnectionManager::enumConnectionObjects();
|
$connections = ConnectionManager::enumConnectionObjects();
|
||||||
$this->assertTrue(count(array_keys($connections) >= 1));
|
$this->assertTrue((bool)(count(array_keys($connections) >= 1)));
|
||||||
|
|
||||||
$source = ConnectionManager::getDataSource(key($connections));
|
$source = ConnectionManager::getDataSource(key($connections));
|
||||||
$this->assertTrue(is_object($source));
|
$this->assertTrue(is_object($source));
|
||||||
|
|
|
@ -19,8 +19,6 @@
|
||||||
*/
|
*/
|
||||||
App::import('Core', array('Model', 'DataSource', 'DboSource', 'DboMysql'));
|
App::import('Core', array('Model', 'DataSource', 'DboSource', 'DboMysql'));
|
||||||
|
|
||||||
Mock::generatePartial('DboMysql', 'QueryMockDboMysql', array('query'));
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DboMysqlTestDb class
|
* DboMysqlTestDb class
|
||||||
*
|
*
|
||||||
|
@ -167,23 +165,19 @@ class DboMysqlTest extends CakeTestCase {
|
||||||
* @var DboSource
|
* @var DboSource
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public $Db = null;
|
public $Dbo = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* Skip if cannot connect to mysql
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function skip() {
|
|
||||||
$this->_initDb();
|
|
||||||
$this->skipUnless($this->db->config['driver'] == 'mysql', '%s MySQL connection not available');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up a Dbo class instance for testing
|
* Sets up a Dbo class instance for testing
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function startTest() {
|
public function setUp() {
|
||||||
$db = ConnectionManager::getDataSource('test_suite');
|
$this->Dbo = ConnectionManager::getDataSource('test_suite');
|
||||||
|
if ($this->Dbo->config['driver'] !== 'mysql') {
|
||||||
|
$this->markTestSkipped('The MySQL extension is not available.');
|
||||||
|
}
|
||||||
|
$this->_debug = Configure::read('debug');
|
||||||
|
Configure::write('debug', 1);
|
||||||
$this->model = new MysqlTestModel();
|
$this->model = new MysqlTestModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,24 +188,6 @@ class DboMysqlTest extends CakeTestCase {
|
||||||
public function tearDown() {
|
public function tearDown() {
|
||||||
unset($this->model);
|
unset($this->model);
|
||||||
ClassRegistry::flush();
|
ClassRegistry::flush();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* startCase
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function startCase() {
|
|
||||||
$this->_debug = Configure::read('debug');
|
|
||||||
Configure::write('debug', 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* endCase
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function endCase() {
|
|
||||||
Configure::write('debug', $this->_debug);
|
Configure::write('debug', $this->_debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,7 +196,7 @@ class DboMysqlTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function testQuoting() {
|
public function testQuoting() {
|
||||||
$result = $this->db->fields($this->model);
|
$result = $this->Dbo->fields($this->model);
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'`MysqlTestModel`.`id`',
|
'`MysqlTestModel`.`id`',
|
||||||
'`MysqlTestModel`.`client_id`',
|
'`MysqlTestModel`.`client_id`',
|
||||||
|
@ -244,32 +220,32 @@ class DboMysqlTest extends CakeTestCase {
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$expected = 1.2;
|
$expected = 1.2;
|
||||||
$result = $this->db->value(1.2, 'float');
|
$result = $this->Dbo->value(1.2, 'float');
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
|
|
||||||
$expected = "'1,2'";
|
$expected = "'1,2'";
|
||||||
$result = $this->db->value('1,2', 'float');
|
$result = $this->Dbo->value('1,2', 'float');
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
|
|
||||||
$expected = "'4713e29446'";
|
$expected = "'4713e29446'";
|
||||||
$result = $this->db->value('4713e29446');
|
$result = $this->Dbo->value('4713e29446');
|
||||||
|
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
|
|
||||||
$expected = 'NULL';
|
$expected = 'NULL';
|
||||||
$result = $this->db->value('', 'integer');
|
$result = $this->Dbo->value('', 'integer');
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
|
|
||||||
$expected = 'NULL';
|
$expected = 0;
|
||||||
$result = $this->db->value('', 'boolean');
|
$result = $this->Dbo->value('', 'boolean');
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
|
|
||||||
$expected = 10010001;
|
$expected = 10010001;
|
||||||
$result = $this->db->value(10010001);
|
$result = $this->Dbo->value(10010001);
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
|
|
||||||
$expected = "'00010010001'";
|
$expected = "'00010010001'";
|
||||||
$result = $this->db->value('00010010001');
|
$result = $this->Dbo->value('00010010001');
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,36 +256,37 @@ class DboMysqlTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testTinyintCasting() {
|
function testTinyintCasting() {
|
||||||
$this->db->cacheSources = false;
|
$this->Dbo->cacheSources = false;
|
||||||
$this->db->query('CREATE TABLE ' . $this->db->fullTableName('tinyint') . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));');
|
$tableName = 'tinyint_' . uniqid();
|
||||||
|
$this->Dbo->query('CREATE TABLE ' . $this->Dbo->fullTableName($tableName) . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));');
|
||||||
|
|
||||||
$this->model = new CakeTestModel(array(
|
$this->model = new CakeTestModel(array(
|
||||||
'name' => 'Tinyint', 'table' => 'tinyint', 'ds' => 'test_suite'
|
'name' => 'Tinyint', 'table' => $tableName, 'ds' => 'test_suite'
|
||||||
));
|
));
|
||||||
|
|
||||||
$result = $this->model->schema();
|
$result = $this->model->schema();
|
||||||
$this->assertEqual($result['bool']['type'], 'boolean');
|
$this->assertEqual($result['bool']['type'], 'boolean');
|
||||||
$this->assertEqual($result['small_int']['type'], 'integer');
|
$this->assertEqual($result['small_int']['type'], 'integer');
|
||||||
|
|
||||||
$this->assertTrue($this->model->save(array('bool' => 5, 'small_int' => 5)));
|
$this->assertTrue((bool)$this->model->save(array('bool' => 5, 'small_int' => 5)));
|
||||||
$result = $this->model->find('first');
|
$result = $this->model->find('first');
|
||||||
$this->assertIdentical($result['Tinyint']['bool'], '1');
|
$this->assertIdentical($result['Tinyint']['bool'], '1');
|
||||||
$this->assertIdentical($result['Tinyint']['small_int'], '5');
|
$this->assertIdentical($result['Tinyint']['small_int'], '5');
|
||||||
$this->model->deleteAll(true);
|
$this->model->deleteAll(true);
|
||||||
|
|
||||||
$this->assertTrue($this->model->save(array('bool' => 0, 'small_int' => 100)));
|
$this->assertTrue((bool)$this->model->save(array('bool' => 0, 'small_int' => 100)));
|
||||||
$result = $this->model->find('first');
|
$result = $this->model->find('first');
|
||||||
$this->assertIdentical($result['Tinyint']['bool'], '0');
|
$this->assertIdentical($result['Tinyint']['bool'], '0');
|
||||||
$this->assertIdentical($result['Tinyint']['small_int'], '100');
|
$this->assertIdentical($result['Tinyint']['small_int'], '100');
|
||||||
$this->model->deleteAll(true);
|
$this->model->deleteAll(true);
|
||||||
|
|
||||||
$this->assertTrue($this->model->save(array('bool' => true, 'small_int' => 0)));
|
$this->assertTrue((bool)$this->model->save(array('bool' => true, 'small_int' => 0)));
|
||||||
$result = $this->model->find('first');
|
$result = $this->model->find('first');
|
||||||
$this->assertIdentical($result['Tinyint']['bool'], '1');
|
$this->assertIdentical($result['Tinyint']['bool'], '1');
|
||||||
$this->assertIdentical($result['Tinyint']['small_int'], '0');
|
$this->assertIdentical($result['Tinyint']['small_int'], '0');
|
||||||
$this->model->deleteAll(true);
|
$this->model->deleteAll(true);
|
||||||
|
|
||||||
$this->db->query('DROP TABLE ' . $this->db->fullTableName('tinyint'));
|
$this->Dbo->query('DROP TABLE ' . $this->Dbo->fullTableName($tableName));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -318,50 +295,50 @@ class DboMysqlTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testIndexDetection() {
|
public function testIndexDetection() {
|
||||||
$this->db->cacheSources = false;
|
$this->Dbo->cacheSources = false;
|
||||||
|
|
||||||
$name = $this->db->fullTableName('simple');
|
$name = $this->Dbo->fullTableName('simple');
|
||||||
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));');
|
$this->Dbo->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));');
|
||||||
$expected = array('PRIMARY' => array('column' => 'id', 'unique' => 1));
|
$expected = array('PRIMARY' => array('column' => 'id', 'unique' => 1));
|
||||||
$result = $this->db->index('simple', false);
|
$result = $this->Dbo->index('simple', false);
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
$this->db->query('DROP TABLE ' . $name);
|
$this->Dbo->query('DROP TABLE ' . $name);
|
||||||
|
|
||||||
$name = $this->db->fullTableName('with_a_key');
|
$name = $this->Dbo->fullTableName('with_a_key');
|
||||||
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ));');
|
$this->Dbo->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ));');
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'PRIMARY' => array('column' => 'id', 'unique' => 1),
|
'PRIMARY' => array('column' => 'id', 'unique' => 1),
|
||||||
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
|
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
|
||||||
);
|
);
|
||||||
$result = $this->db->index('with_a_key', false);
|
$result = $this->Dbo->index('with_a_key', false);
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
$this->db->query('DROP TABLE ' . $name);
|
$this->Dbo->query('DROP TABLE ' . $name);
|
||||||
|
|
||||||
$name = $this->db->fullTableName('with_two_keys');
|
$name = $this->Dbo->fullTableName('with_two_keys');
|
||||||
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ), KEY `pointless_small_int` ( `small_int` ));');
|
$this->Dbo->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ), KEY `pointless_small_int` ( `small_int` ));');
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'PRIMARY' => array('column' => 'id', 'unique' => 1),
|
'PRIMARY' => array('column' => 'id', 'unique' => 1),
|
||||||
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
|
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
|
||||||
'pointless_small_int' => array('column' => 'small_int', 'unique' => 0),
|
'pointless_small_int' => array('column' => 'small_int', 'unique' => 0),
|
||||||
);
|
);
|
||||||
$result = $this->db->index('with_two_keys', false);
|
$result = $this->Dbo->index('with_two_keys', false);
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
$this->db->query('DROP TABLE ' . $name);
|
$this->Dbo->query('DROP TABLE ' . $name);
|
||||||
|
|
||||||
$name = $this->db->fullTableName('with_compound_keys');
|
$name = $this->Dbo->fullTableName('with_compound_keys');
|
||||||
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ), KEY `pointless_small_int` ( `small_int` ), KEY `one_way` ( `bool`, `small_int` ));');
|
$this->Dbo->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ), KEY `pointless_small_int` ( `small_int` ), KEY `one_way` ( `bool`, `small_int` ));');
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'PRIMARY' => array('column' => 'id', 'unique' => 1),
|
'PRIMARY' => array('column' => 'id', 'unique' => 1),
|
||||||
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
|
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
|
||||||
'pointless_small_int' => array('column' => 'small_int', 'unique' => 0),
|
'pointless_small_int' => array('column' => 'small_int', 'unique' => 0),
|
||||||
'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0),
|
'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0),
|
||||||
);
|
);
|
||||||
$result = $this->db->index('with_compound_keys', false);
|
$result = $this->Dbo->index('with_compound_keys', false);
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
$this->db->query('DROP TABLE ' . $name);
|
$this->Dbo->query('DROP TABLE ' . $name);
|
||||||
|
|
||||||
$name = $this->db->fullTableName('with_multiple_compound_keys');
|
$name = $this->Dbo->fullTableName('with_multiple_compound_keys');
|
||||||
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ), KEY `pointless_small_int` ( `small_int` ), KEY `one_way` ( `bool`, `small_int` ), KEY `other_way` ( `small_int`, `bool` ));');
|
$this->Dbo->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ), KEY `pointless_small_int` ( `small_int` ), KEY `one_way` ( `bool`, `small_int` ), KEY `other_way` ( `small_int`, `bool` ));');
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'PRIMARY' => array('column' => 'id', 'unique' => 1),
|
'PRIMARY' => array('column' => 'id', 'unique' => 1),
|
||||||
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
|
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
|
||||||
|
@ -369,9 +346,9 @@ class DboMysqlTest extends CakeTestCase {
|
||||||
'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0),
|
'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0),
|
||||||
'other_way' => array('column' => array('small_int', 'bool'), 'unique' => 0),
|
'other_way' => array('column' => array('small_int', 'bool'), 'unique' => 0),
|
||||||
);
|
);
|
||||||
$result = $this->db->index('with_multiple_compound_keys', false);
|
$result = $this->Dbo->index('with_multiple_compound_keys', false);
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
$this->db->query('DROP TABLE ' . $name);
|
$this->Dbo->query('DROP TABLE ' . $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -381,8 +358,8 @@ class DboMysqlTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testBuildColumn() {
|
function testBuildColumn() {
|
||||||
$restore = $this->db->columns;
|
$restore = $this->Dbo->columns;
|
||||||
$this->db->columns = array('varchar(255)' => 1);
|
$this->Dbo->columns = array('varchar(255)' => 1);
|
||||||
$data = array(
|
$data = array(
|
||||||
'name' => 'testName',
|
'name' => 'testName',
|
||||||
'type' => 'varchar(255)',
|
'type' => 'varchar(255)',
|
||||||
|
@ -391,7 +368,7 @@ class DboMysqlTest extends CakeTestCase {
|
||||||
'key',
|
'key',
|
||||||
'comment' => 'test'
|
'comment' => 'test'
|
||||||
);
|
);
|
||||||
$result = $this->db->buildColumn($data);
|
$result = $this->Dbo->buildColumn($data);
|
||||||
$expected = '`testName` DEFAULT NULL COMMENT \'test\'';
|
$expected = '`testName` DEFAULT NULL COMMENT \'test\'';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
@ -404,10 +381,10 @@ class DboMysqlTest extends CakeTestCase {
|
||||||
'charset' => 'utf8',
|
'charset' => 'utf8',
|
||||||
'collate' => 'utf8_unicode_ci'
|
'collate' => 'utf8_unicode_ci'
|
||||||
);
|
);
|
||||||
$result = $this->db->buildColumn($data);
|
$result = $this->Dbo->buildColumn($data);
|
||||||
$expected = '`testName` CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL';
|
$expected = '`testName` CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
$this->db->columns = $restore;
|
$this->Dbo->columns = $restore;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -417,9 +394,9 @@ class DboMysqlTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testIndexOnMySQL4Output() {
|
function testIndexOnMySQL4Output() {
|
||||||
$name = $this->db->fullTableName('simple');
|
$name = $this->Dbo->fullTableName('simple');
|
||||||
|
|
||||||
$mockDbo =& new QueryMockDboMysql($this);
|
$mockDbo = $this->getMock('DboMysql', array('query'));
|
||||||
$columnData = array(
|
$columnData = array(
|
||||||
array('0' => array(
|
array('0' => array(
|
||||||
'Table' => 'with_compound_keys',
|
'Table' => 'with_compound_keys',
|
||||||
|
@ -492,7 +469,10 @@ class DboMysqlTest extends CakeTestCase {
|
||||||
'Comment' => ''
|
'Comment' => ''
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
$mockDbo->setReturnValue('query', $columnData, array('SHOW INDEX FROM ' . $name));
|
$mockDbo->expects($this->once())
|
||||||
|
->method('query')
|
||||||
|
->with('SHOW INDEX FROM ' . $name)
|
||||||
|
->will($this->returnValue($columnData));
|
||||||
|
|
||||||
$result = $mockDbo->index($name, false);
|
$result = $mockDbo->index($name, false);
|
||||||
$expected = array(
|
$expected = array(
|
||||||
|
@ -510,43 +490,43 @@ class DboMysqlTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testColumn() {
|
public function testColumn() {
|
||||||
$result = $this->db->column('varchar(50)');
|
$result = $this->Dbo->column('varchar(50)');
|
||||||
$expected = 'string';
|
$expected = 'string';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->db->column('text');
|
$result = $this->Dbo->column('text');
|
||||||
$expected = 'text';
|
$expected = 'text';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->db->column('int(11)');
|
$result = $this->Dbo->column('int(11)');
|
||||||
$expected = 'integer';
|
$expected = 'integer';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->db->column('int(11) unsigned');
|
$result = $this->Dbo->column('int(11) unsigned');
|
||||||
$expected = 'integer';
|
$expected = 'integer';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->db->column('tinyint(1)');
|
$result = $this->Dbo->column('tinyint(1)');
|
||||||
$expected = 'boolean';
|
$expected = 'boolean';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->db->column('boolean');
|
$result = $this->Dbo->column('boolean');
|
||||||
$expected = 'boolean';
|
$expected = 'boolean';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->db->column('float');
|
$result = $this->Dbo->column('float');
|
||||||
$expected = 'float';
|
$expected = 'float';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->db->column('float unsigned');
|
$result = $this->Dbo->column('float unsigned');
|
||||||
$expected = 'float';
|
$expected = 'float';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->db->column('double unsigned');
|
$result = $this->Dbo->column('double unsigned');
|
||||||
$expected = 'float';
|
$expected = 'float';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->db->column('decimal(14,7) unsigned');
|
$result = $this->Dbo->column('decimal(14,7) unsigned');
|
||||||
$expected = 'float';
|
$expected = 'float';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
}
|
}
|
||||||
|
@ -559,9 +539,9 @@ class DboMysqlTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testAlterSchemaIndexes() {
|
function testAlterSchemaIndexes() {
|
||||||
App::import('Model', 'CakeSchema');
|
App::import('Model', 'CakeSchema');
|
||||||
$this->db->cacheSources = $this->db->testing = false;
|
$this->Dbo->cacheSources = $this->Dbo->testing = false;
|
||||||
|
|
||||||
$schema1 =& new CakeSchema(array(
|
$schema1 = new CakeSchema(array(
|
||||||
'name' => 'AlterTest1',
|
'name' => 'AlterTest1',
|
||||||
'connection' => 'test_suite',
|
'connection' => 'test_suite',
|
||||||
'altertest' => array(
|
'altertest' => array(
|
||||||
|
@ -570,9 +550,9 @@ class DboMysqlTest extends CakeTestCase {
|
||||||
'group1' => array('type' => 'integer', 'null' => true),
|
'group1' => array('type' => 'integer', 'null' => true),
|
||||||
'group2' => array('type' => 'integer', 'null' => true)
|
'group2' => array('type' => 'integer', 'null' => true)
|
||||||
)));
|
)));
|
||||||
$this->db->query($this->db->createSchema($schema1));
|
$this->Dbo->query($this->Dbo->createSchema($schema1));
|
||||||
|
|
||||||
$schema2 =& new CakeSchema(array(
|
$schema2 = new CakeSchema(array(
|
||||||
'name' => 'AlterTest2',
|
'name' => 'AlterTest2',
|
||||||
'connection' => 'test_suite',
|
'connection' => 'test_suite',
|
||||||
'altertest' => array(
|
'altertest' => array(
|
||||||
|
@ -586,13 +566,13 @@ class DboMysqlTest extends CakeTestCase {
|
||||||
'compound_idx' => array('column' => array('group1', 'group2'), 'unique' => 0),
|
'compound_idx' => array('column' => array('group1', 'group2'), 'unique' => 0),
|
||||||
'PRIMARY' => array('column' => 'id', 'unique' => 1))
|
'PRIMARY' => array('column' => 'id', 'unique' => 1))
|
||||||
)));
|
)));
|
||||||
$this->db->query($this->db->alterSchema($schema2->compare($schema1)));
|
$this->Dbo->query($this->Dbo->alterSchema($schema2->compare($schema1)));
|
||||||
|
|
||||||
$indexes = $this->db->index('altertest');
|
$indexes = $this->Dbo->index('altertest');
|
||||||
$this->assertEqual($schema2->tables['altertest']['indexes'], $indexes);
|
$this->assertEqual($schema2->tables['altertest']['indexes'], $indexes);
|
||||||
|
|
||||||
// Change three indexes, delete one and add another one
|
// Change three indexes, delete one and add another one
|
||||||
$schema3 =& new CakeSchema(array(
|
$schema3 = new CakeSchema(array(
|
||||||
'name' => 'AlterTest3',
|
'name' => 'AlterTest3',
|
||||||
'connection' => 'test_suite',
|
'connection' => 'test_suite',
|
||||||
'altertest' => array(
|
'altertest' => array(
|
||||||
|
@ -607,21 +587,21 @@ class DboMysqlTest extends CakeTestCase {
|
||||||
'id_name_idx' => array('column' => array('id', 'name'), 'unique' => 0))
|
'id_name_idx' => array('column' => array('id', 'name'), 'unique' => 0))
|
||||||
)));
|
)));
|
||||||
|
|
||||||
$this->db->query($this->db->alterSchema($schema3->compare($schema2)));
|
$this->Dbo->query($this->Dbo->alterSchema($schema3->compare($schema2)));
|
||||||
|
|
||||||
$indexes = $this->db->index('altertest');
|
$indexes = $this->Dbo->index('altertest');
|
||||||
$this->assertEqual($schema3->tables['altertest']['indexes'], $indexes);
|
$this->assertEqual($schema3->tables['altertest']['indexes'], $indexes);
|
||||||
|
|
||||||
// Compare us to ourself.
|
// Compare us to ourself.
|
||||||
$this->assertEqual($schema3->compare($schema3), array());
|
$this->assertEqual($schema3->compare($schema3), array());
|
||||||
|
|
||||||
// Drop the indexes
|
// Drop the indexes
|
||||||
$this->db->query($this->db->alterSchema($schema1->compare($schema3)));
|
$this->Dbo->query($this->Dbo->alterSchema($schema1->compare($schema3)));
|
||||||
|
|
||||||
$indexes = $this->db->index('altertest');
|
$indexes = $this->Dbo->index('altertest');
|
||||||
$this->assertEqual(array(), $indexes);
|
$this->assertEqual(array(), $indexes);
|
||||||
|
|
||||||
$this->db->query($this->db->dropSchema($schema1));
|
$this->Dbo->query($this->Dbo->dropSchema($schema1));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* test saving and retrieval of blobs
|
* test saving and retrieval of blobs
|
||||||
|
@ -629,13 +609,13 @@ class DboMysqlTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testBlobSaving() {
|
function testBlobSaving() {
|
||||||
$this->db->cacheSources = false;
|
$this->Dbo->cacheSources = false;
|
||||||
$data = "GIF87ab |