diff --git a/app/config/acl.ini.php b/app/config/acl.ini.php index c3e055341..3245634aa 100644 --- a/app/config/acl.ini.php +++ b/app/config/acl.ini.php @@ -14,8 +14,7 @@ ; * ; * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) ; * @link http://cakephp.org CakePHP(tm) Project -; * @package cake -; * @subpackage cake.app.config +; * @package app.config ; * @since CakePHP(tm) v 0.10.0.1076 ; * @license MIT License (http://www.opensource.org/licenses/mit-license.php) ; */ diff --git a/app/config/bootstrap.php b/app/config/bootstrap.php index b0c33554b..ceeb85670 100644 --- a/app/config/bootstrap.php +++ b/app/config/bootstrap.php @@ -15,8 +15,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app.config + * @package app.config * @since CakePHP(tm) v 0.10.8.2117 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/app/config/core.php b/app/config/core.php index c9560d15a..9744da06c 100644 --- a/app/config/core.php +++ b/app/config/core.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app.config + * @package app.config * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/app/config/database.php.default b/app/config/database.php.default index f85b56922..2078240ea 100644 --- a/app/config/database.php.default +++ b/app/config/database.php.default @@ -14,16 +14,14 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app.config + * @package app.config * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ /** * In this file you set up your database connection details. * - * @package cake - * @subpackage cake.config + * @package cake.config */ /** * Database configuration class. diff --git a/app/config/routes.php b/app/config/routes.php index 4e470c363..cbb816e18 100644 --- a/app/config/routes.php +++ b/app/config/routes.php @@ -16,8 +16,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app.config + * @package app.config * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/app/config/schema/db_acl.php b/app/config/schema/db_acl.php index d13a20609..25b6ee6df 100644 --- a/app/config/schema/db_acl.php +++ b/app/config/schema/db_acl.php @@ -15,8 +15,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app.config.sql + * @package app.config.sql * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/app/config/schema/i18n.php b/app/config/schema/i18n.php index 13db98f12..f57bbce7f 100644 --- a/app/config/schema/i18n.php +++ b/app/config/schema/i18n.php @@ -15,8 +15,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app.config.sql + * @package app.config.sql * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/app/config/schema/sessions.php b/app/config/schema/sessions.php index 584d0002b..e5ae37dc1 100644 --- a/app/config/schema/sessions.php +++ b/app/config/schema/sessions.php @@ -15,8 +15,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app.config.sql + * @package app.config.sql * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/app/console/cake b/app/console/cake index d4d067d59..bd1b6da06 100755 --- a/app/console/cake +++ b/app/console/cake @@ -12,8 +12,7 @@ # # @copyright Copyright 2005-2010, Cake Software Foundation, Inc. # @link http://cakephp.org CakePHP(tm) Project -# @package cake -# @subpackage cake.app.console +# @package app.console # @since CakePHP(tm) v 2.0 # @license MIT License (http://www.opensource.org/licenses/mit-license.php) # diff --git a/app/console/cake.bat b/app/console/cake.bat index 6499c2f22..ed04546c9 100644 --- a/app/console/cake.bat +++ b/app/console/cake.bat @@ -10,9 +10,8 @@ :: Redistributions of files must retain the above copyright notice. :: :: @copyright Copyright 2005-2010, Cake Software Foundation, Inc. -:: @link http://cakephp.org CakePHP(tm) Project -:: @package cake -:: @subpackage cake.app.console +:: @link http://cakephp.org CakePHP(tm) Project +:: @package app.console :: @since CakePHP(tm) v 2.0 :: @license MIT License (http://www.opensource.org/licenses/mit-license.php) :: diff --git a/app/console/cake.php b/app/console/cake.php index af02ae4ff..9200fd36b 100755 --- a/app/console/cake.php +++ b/app/console/cake.php @@ -15,8 +15,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console + * @package app.console * @since CakePHP(tm) v 1.2.0.5012 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/app/index.php b/app/index.php index a9e0270cb..ac4fde167 100644 --- a/app/index.php +++ b/app/index.php @@ -10,8 +10,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app + * @package app * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/app/webroot/css.php b/app/webroot/css.php index bab3b5405..19ba84dc2 100644 --- a/app/webroot/css.php +++ b/app/webroot/css.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app.webroot + * @package app.webroot * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,9 +24,7 @@ if (!defined('CAKE_CORE_INCLUDE_PATH')) { /** * Ensure required classes are available. */ -if (!class_exists('File')) { - uses('file'); -} +App::import('Core', 'File'); /** * Make clean CSS diff --git a/app/webroot/css/cake.generic.css b/app/webroot/css/cake.generic.css index 4f6f5a2cd..3559401dc 100644 --- a/app/webroot/css/cake.generic.css +++ b/app/webroot/css/cake.generic.css @@ -10,8 +10,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app.webroot.css + * @package app.webroot.css * @since CakePHP(tm) * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/app/webroot/index.php b/app/webroot/index.php index 719f172c4..5955688f6 100644 --- a/app/webroot/index.php +++ b/app/webroot/index.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app.webroot + * @package app.webroot * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/app/webroot/test.php b/app/webroot/test.php index 7a27e8e29..eddcc437f 100644 --- a/app/webroot/test.php +++ b/app/webroot/test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://book.cakephp.org/view/1196/Testing - * @package cake - * @subpackage cake.app.webroot + * @package app.webroot * @since CakePHP(tm) v 1.2.0.4433 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/VERSION.txt b/cake/VERSION.txt index e5c64475c..3157f1e00 100644 --- a/cake/VERSION.txt +++ b/cake/VERSION.txt @@ -12,13 +12,13 @@ // // @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) // @link http://cakephp.org -// @package cake -// @subpackage cake.cake.libs +// @package cake.libs // @since CakePHP(tm) v 0.2.9 // @license MIT License (http://www.opensource.org/licenses/mit-license.php) // +--------------------------------------------------------------------------------------------+ // //////////////////////////////////////////////////////////////////////////////////////////////////// -1.3.6 +2.0.0-dev + diff --git a/cake/basics.php b/cake/basics.php index cba8c4eae..5a968cdeb 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -15,7 +15,6 @@ * @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 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -61,36 +60,18 @@ return true; } -/** - * Loads component/components from LIBS. Takes optional number of parameters. - * - * Example: - * - * `uses('flay', 'time');` - * - * @param string $name Filename without the .php part - * @deprecated Will be removed in 2.0 - * @link http://book.cakephp.org/view/1140/uses - */ - function uses() { - $args = func_get_args(); - foreach ($args as $file) { - require_once(LIBS . strtolower($file) . '.php'); - } - } - /** * Prints out debug information about given variable. * * Only runs if debug level is greater than zero. * * @param boolean $var Variable to show debug information for. - * @param boolean $showHtml If set to true, the method prints the debug data in a screen-friendly way. + * @param boolean $showHtml If set to true, the method prints the debug data in a browser-friendly way. * @param boolean $showFrom If set to true, the method prints from where the function was called. * @link http://book.cakephp.org/view/1190/Basic-Debugging * @link http://book.cakephp.org/view/1128/debug */ - function debug($var = false, $showHtml = false, $showFrom = true) { + function debug($var = false, $showHtml = null, $showFrom = true) { if (Configure::read('debug') > 0) { $file = ''; $line = ''; @@ -117,9 +98,12 @@ TEXT; if (php_sapi_name() == 'cli') { $template = $text; } + if ($showHtml === null) { + $showHtml = true; + } $var = print_r($var, true); if ($showHtml) { - $var = str_replace('<', '<', str_replace('>', '>', $var)); + $var = str_replace(array('<', '>'), array('<', '>'), $var); } printf($template, $file, $line, $var); } diff --git a/cake/bootstrap.php b/cake/bootstrap.php index acfc7bb2f..65931eb39 100644 --- a/cake/bootstrap.php +++ b/cake/bootstrap.php @@ -15,7 +15,6 @@ * @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 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/config/config.php b/cake/config/config.php index 071441c21..906fa844a 100644 --- a/cake/config/config.php +++ b/cake/config/config.php @@ -12,9 +12,8 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app.config + * @package cake.config * @since CakePHP(tm) v 1.1.11.4062 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -return $config['Cake.version'] = '1.3.6'; +return $config['Cake.version'] = '2.0.0-dev'; diff --git a/cake/config/paths.php b/cake/config/paths.php index e8ac21c49..365cdb4c1 100644 --- a/cake/config/paths.php +++ b/cake/config/paths.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.app.config + * @package cake.config * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/config/unicode/casefolding/0080_00ff.php b/cake/config/unicode/casefolding/0080_00ff.php index 0d2fa16be..ef01fe904 100644 --- a/cake/config/unicode/casefolding/0080_00ff.php +++ b/cake/config/unicode/casefolding/0080_00ff.php @@ -18,8 +18,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.config.unicode.casefolding + * @package cake.config.unicode.casefolding * @since CakePHP(tm) v 1.2.0.5691 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/config/unicode/casefolding/0100_017f.php b/cake/config/unicode/casefolding/0100_017f.php index 64ab7d393..1f7f1449c 100644 --- a/cake/config/unicode/casefolding/0100_017f.php +++ b/cake/config/unicode/casefolding/0100_017f.php @@ -18,8 +18,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.config.unicode.casefolding + * @package cake.config.unicode.casefolding * @since CakePHP(tm) v 1.2.0.5691 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/config/unicode/casefolding/0180_024F.php b/cake/config/unicode/casefolding/0180_024F.php index 23c692632..f2a5a849b 100644 --- a/cake/config/unicode/casefolding/0180_024F.php +++ b/cake/config/unicode/casefolding/0180_024F.php @@ -18,8 +18,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.config.unicode.casefolding + * @package cake.config.unicode.casefolding * @since CakePHP(tm) v 1.2.0.5691 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/config/unicode/casefolding/0250_02af.php b/cake/config/unicode/casefolding/0250_02af.php index 1ef96c6af..3140c1312 100644 --- a/cake/config/unicode/casefolding/0250_02af.php +++ b/cake/config/unicode/casefolding/0250_02af.php @@ -18,8 +18,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.config.unicode.casefolding + * @package cake.config.unicode.casefolding * @since CakePHP(tm) v 1.2.0.6833 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/config/unicode/casefolding/0370_03ff.php b/cake/config/unicode/casefolding/0370_03ff.php index 50618afb8..7609089da 100644 --- a/cake/config/unicode/casefolding/0370_03ff.php +++ b/cake/config/unicode/casefolding/0370_03ff.php @@ -18,8 +18,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.config.unicode.casefolding + * @package cake.config.unicode.casefolding * @since CakePHP(tm) v 1.2.0.5691 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/config/unicode/casefolding/0400_04ff.php b/cake/config/unicode/casefolding/0400_04ff.php index a04d3df66..3b12b059e 100644 --- a/cake/config/unicode/casefolding/0400_04ff.php +++ b/cake/config/unicode/casefolding/0400_04ff.php @@ -18,8 +18,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.config.unicode.casefolding + * @package cake.config.unicode.casefolding * @since CakePHP(tm) v 1.2.0.5691 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/config/unicode/casefolding/0500_052f.php b/cake/config/unicode/casefolding/0500_052f.php index 661f66d63..453b9b7df 100644 --- a/cake/config/unicode/casefolding/0500_052f.php +++ b/cake/config/unicode/casefolding/0500_052f.php @@ -18,8 +18,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.config.unicode.casefolding + * @package cake.config.unicode.casefolding * @since CakePHP(tm) v 1.2.0.5691 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/config/unicode/casefolding/0530_058f.php b/cake/config/unicode/casefolding/0530_058f.php index 232649ec4..3181438ec 100644 --- a/cake/config/unicode/casefolding/0530_058f.php +++ b/cake/config/unicode/casefolding/0530_058f.php @@ -18,8 +18,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.config.unicode.casefolding + * @package cake.config.unicode.casefolding * @since CakePHP(tm) v 1.2.0.5691 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/config/unicode/casefolding/1e00_1eff.php b/cake/config/unicode/casefolding/1e00_1eff.php index 3a8378691..ed49211a9 100644 --- a/cake/config/unicode/casefolding/1e00_1eff.php +++ b/cake/config/unicode/casefolding/1e00_1eff.php @@ -18,8 +18,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.config.unicode.casefolding + * @package cake.config.unicode.casefolding * @since CakePHP(tm) v 1.2.0.5691 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/config/unicode/casefolding/1f00_1fff.php b/cake/config/unicode/casefolding/1f00_1fff.php index a4040b852..2b0d24bf2 100644 --- a/cake/config/unicode/casefolding/1f00_1fff.php +++ b/cake/config/unicode/casefolding/1f00_1fff.php @@ -18,8 +18,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.config.unicode.casefolding + * @package cake.config.unicode.casefolding * @since CakePHP(tm) v 1.2.0.5691 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/config/unicode/casefolding/2100_214f.php b/cake/config/unicode/casefolding/2100_214f.php index 1685ebb71..a10d613f4 100644 --- a/cake/config/unicode/casefolding/2100_214f.php +++ b/cake/config/unicode/casefolding/2100_214f.php @@ -18,8 +18,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.config.unicode.casefolding + * @package cake.config.unicode.casefolding * @since CakePHP(tm) v 1.2.0.5691 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/config/unicode/casefolding/2150_218f.php b/cake/config/unicode/casefolding/2150_218f.php index 44bf3ff89..6ccd3de8c 100644 --- a/cake/config/unicode/casefolding/2150_218f.php +++ b/cake/config/unicode/casefolding/2150_218f.php @@ -18,8 +18,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.config.unicode.casefolding + * @package cake.config.unicode.casefolding * @since CakePHP(tm) v 1.2.0.5691 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/config/unicode/casefolding/2460_24ff.php b/cake/config/unicode/casefolding/2460_24ff.php index 4376e2b71..2e7a85321 100644 --- a/cake/config/unicode/casefolding/2460_24ff.php +++ b/cake/config/unicode/casefolding/2460_24ff.php @@ -18,8 +18,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.config.unicode.casefolding + * @package cake.config.unicode.casefolding * @since CakePHP(tm) v 1.2.0.5691 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/config/unicode/casefolding/2c00_2c5f.php b/cake/config/unicode/casefolding/2c00_2c5f.php index e8a70bc32..797cf964d 100644 --- a/cake/config/unicode/casefolding/2c00_2c5f.php +++ b/cake/config/unicode/casefolding/2c00_2c5f.php @@ -18,8 +18,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.config.unicode.casefolding + * @package cake.config.unicode.casefolding * @since CakePHP(tm) v 1.2.0.5691 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/config/unicode/casefolding/2c60_2c7f.php b/cake/config/unicode/casefolding/2c60_2c7f.php index dabdb88a2..058193ca6 100644 --- a/cake/config/unicode/casefolding/2c60_2c7f.php +++ b/cake/config/unicode/casefolding/2c60_2c7f.php @@ -18,8 +18,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.config.unicode.casefolding + * @package cake.config.unicode.casefolding * @since CakePHP(tm) v 1.2.0.5691 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/config/unicode/casefolding/2c80_2cff.php b/cake/config/unicode/casefolding/2c80_2cff.php index c0245fa16..d439bc2e7 100644 --- a/cake/config/unicode/casefolding/2c80_2cff.php +++ b/cake/config/unicode/casefolding/2c80_2cff.php @@ -18,8 +18,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.config.unicode.casefolding + * @package cake.config.unicode.casefolding * @since CakePHP(tm) v 1.2.0.5691 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/config/unicode/casefolding/ff00_ffef.php b/cake/config/unicode/casefolding/ff00_ffef.php index 74a2b5c4a..0b8106532 100644 --- a/cake/config/unicode/casefolding/ff00_ffef.php +++ b/cake/config/unicode/casefolding/ff00_ffef.php @@ -18,8 +18,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.config.unicode.casefolding + * @package cake.config.unicode.casefolding * @since CakePHP(tm) v 1.2.0.5691 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/cake b/cake/console/cake index d0bdb5cc0..81df781da 100755 --- a/cake/console/cake +++ b/cake/console/cake @@ -12,9 +12,8 @@ # # @copyright Copyright 2005-2010, Cake Software Foundation, Inc. # @link http://cakephp.org CakePHP(tm) Project -# @package cake -# @subpackage cake.cake.console -# @since CakePHP(tm) v 1.2.0.5012 +# @package cake.console +# @since CakePHP(tm) v 1.2.0.5012 # @license MIT License (http://www.opensource.org/licenses/mit-license.php) # ################################################################################ diff --git a/cake/console/cake.bat b/cake/console/cake.bat index cb1831d94..40a271425 100644 --- a/cake/console/cake.bat +++ b/cake/console/cake.bat @@ -10,9 +10,8 @@ :: Redistributions of files must retain the above copyright notice. :: :: @copyright Copyright 2005-2010, Cake Software Foundation, Inc. -:: @link http://cakephp.org CakePHP(tm) Project -:: @package cake -:: @subpackage cake.cake.console +:: @link http://cakephp.org CakePHP(tm) Project +:: @package cake.console :: @since CakePHP(tm) v 1.2.0.5012 :: @license MIT License (http://www.opensource.org/licenses/mit-license.php) :: diff --git a/cake/console/cake.php b/cake/console/cake.php index 02468c38f..c9bce3193 100644 --- a/cake/console/cake.php +++ b/cake/console/cake.php @@ -15,8 +15,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console + * @package cake.console * @since CakePHP(tm) v 1.2.0.5012 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/libs/console_error_handler.php b/cake/console/libs/console_error_handler.php index 0e7c28af1..80136bbcf 100644 --- a/cake/console/libs/console_error_handler.php +++ b/cake/console/libs/console_error_handler.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console + * @package cake.console.libs * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,8 +23,7 @@ require_once 'console_output.php'; * Error Handler for Cake console. Does simple printing of the * exception that occurred and the stack trace of the error. * - * @package cake - * @subpackage cake.cake.console + * @package cake.console.libs */ class ConsoleErrorHandler extends ErrorHandler { @@ -51,11 +49,12 @@ class ConsoleErrorHandler extends ErrorHandler { } /** - * Handle a exception in the console environment. + * Handle a exception in the console environment. Prints a message to stderr. * + * @param Exception $exception The exception to handle * @return void */ - public static function handleException($exception) { + public static function handleException(Exception $exception) { $stderr = self::getStderr(); $stderr->write(sprintf( __("Error: %s\n%s"), @@ -67,6 +66,11 @@ class ConsoleErrorHandler extends ErrorHandler { /** * Handle errors in the console environment. * + * @param int $code Error code + * @param string $description Description of the error. + * @param string $file The file the error occurred in. + * @param int $line The line the error ocurrred on. + * @param array $context The backtrace of the error. * @return void */ public static function handleError($code, $description, $file = null, $line = null, $context = null) { @@ -84,17 +88,4 @@ class ConsoleErrorHandler extends ErrorHandler { } } -/** - * undocumented function - * - * @return void - */ - public function render() { - $this->stderr->write(sprintf( - __("Error: %s\n%s"), - $this->error->getMessage(), - $this->error->getTraceAsString() - )); - } - } diff --git a/cake/console/libs/console_input.php b/cake/console/libs/console_input.php index 33127ae9b..8378b2e85 100644 --- a/cake/console/libs/console_input.php +++ b/cake/console/libs/console_input.php @@ -12,15 +12,14 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.console + * @package cake.console.libs * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ /** * Object wrapper for interacting with stdin * - * @package cake.console + * @package cake.console.libs */ class ConsoleInput { /** @@ -33,7 +32,7 @@ class ConsoleInput { /** * Constructor * - * @return void + * @param string $handle The location of the stream to use as input. */ public function __construct($handle = 'php://stdin') { $this->_input = fopen($handle, 'r'); diff --git a/cake/console/libs/console_input_argument.php b/cake/console/libs/console_input_argument.php index c0ed84fc0..263475e9d 100644 --- a/cake/console/libs/console_input_argument.php +++ b/cake/console/libs/console_input_argument.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console + * @package cake.console.libs * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,11 +21,36 @@ * ConsoleOptionParser creates these when you use addArgument() * * @see ConsoleOptionParser::addArgument() - * @package cake.console + * @package cake.console.libs */ class ConsoleInputArgument { +/** + * Name of the argument. + * + * @var string + */ + protected $_name; - protected $_name, $_help, $_required, $_choices; +/** + * Help string + * + * @var string + */ + protected $_help; + +/** + * Is this option required? + * + * @var boolean + */ + protected $_required; + +/** + * An array of valid choices for this argument. + * + * @var array + */ + protected $_choices; /** * Make a new Input Argument @@ -34,8 +58,7 @@ class ConsoleInputArgument { * @param mixed $name The long name of the option, or an array with all the properites. * @param string $help The help text for this option * @param boolean $required Whether this argument is required. Missing required args will trigger exceptions - * @param arraty $choices Valid choices for this option. - * @return void + * @param array $choices Valid choices for this option. */ public function __construct($name, $help = '', $required = false, $choices = array()) { if (is_array($name) && isset($name['name'])) { @@ -60,7 +83,7 @@ class ConsoleInputArgument { } /** - * Generate the help for this this argument. + * Generate the help for this argument. * * @param int $width The width to make the name of the option. * @return string @@ -116,7 +139,7 @@ class ConsoleInputArgument { return true; } if (!in_array($value, $this->_choices)) { - throw new InvalidArgumentException(sprintf( + throw new ConsoleException(sprintf( __('"%s" is not a valid value for %s. Please use one of "%s"'), $value, $this->_name, implode(', ', $this->_choices) )); @@ -125,7 +148,7 @@ class ConsoleInputArgument { } /** - * Append this argument to the passed in SimpleXml object. + * Append this arguments XML representation to the passed in SimpleXml object. * * @param SimpleXmlElement The parent element. * @return SimpleXmlElement The parent with this argument appended. diff --git a/cake/console/libs/console_input_option.php b/cake/console/libs/console_input_option.php index d4d831aa1..3c9049248 100644 --- a/cake/console/libs/console_input_option.php +++ b/cake/console/libs/console_input_option.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console + * @package cake.console.libs * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,11 +22,50 @@ * ConsoleOptionParser creates these when you use addOption() * * @see ConsoleOptionParser::addOption() - * @package cake.console + * @package cake.console.libs */ class ConsoleInputOption { +/** + * Name of the option + * + * @var string + */ + protected $_name; - protected $_name, $_short, $_help, $_boolean, $_default, $_choices; +/** + * Short (1 character) alias for the option. + * + * @var string + */ + protected $_short; + +/** + * Help text for the option. + * + * @var string + */ + protected $_help; + +/** + * Is the option a boolean option. Boolean options do not consume a parameter. + * + * @var boolean + */ + protected $_boolean; + +/** + * Default value for the option + * + * @var mixed + */ + protected $_default; + +/** + * An array of choices for the option. + * + * @var array + */ + protected $_choices; /** * Make a new Input Option @@ -37,8 +75,7 @@ class ConsoleInputOption { * @param string $help The help text for this option * @param boolean $boolean Whether this option is a boolean option. Boolean options don't consume extra tokens * @param string $default The default value for this option. - * @param arraty $choices Valid choices for this option. - * @return void + * @param array $choices Valid choices for this option. */ public function __construct($name, $short = null, $help = '', $boolean = false, $default = '', $choices = array()) { if (is_array($name) && isset($name['name'])) { @@ -117,7 +154,7 @@ class ConsoleInputOption { /** * Get the default value for this option * - * @return void + * @return mixed */ public function defaultValue() { return $this->_default; @@ -142,7 +179,7 @@ class ConsoleInputOption { return true; } if (!in_array($value, $this->_choices)) { - throw new InvalidArgumentException(sprintf( + throw new ConsoleException(sprintf( __('"%s" is not a valid value for --%s. Please use one of "%s"'), $value, $this->_name, implode(', ', $this->_choices) )); diff --git a/cake/console/libs/console_input_subcommand.php b/cake/console/libs/console_input_subcommand.php index 76bd19d2f..b2903aec2 100644 --- a/cake/console/libs/console_input_subcommand.php +++ b/cake/console/libs/console_input_subcommand.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console + * @package cake.console.libs * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,19 +22,38 @@ * ConsoleOptionParser creates these when you use addSubcommand() * * @see ConsoleOptionParser::addSubcommand() - * @package cake.console + * @package cake.console.libs */ class ConsoleInputSubcommand { - protected $_name, $_help, $_parser; +/** + * Name of the subcommand + * + * @var string + */ + protected $_name; + +/** + * Help string for the subcommand + * + * @var string + */ + protected $_help; + +/** + * The ConsoleOptionParser for this subcommand. + * + * @var ConsoleOptionParser + */ + protected $_parser; /** * Make a new Subcommand * * @param mixed $name The long name of the subcommand, or an array with all the properites. * @param string $help The help text for this option - * @param ConsoleOptionParser $parser A parser for this subcommand. - * @return void + * @param mixed $parser A parser for this subcommand. Either a ConsoleOptionParser, or an array that can be + * used with ConsoleOptionParser::buildFromArray() */ public function __construct($name, $help = '', $parser = null) { if (is_array($name) && isset($name['name'])) { diff --git a/cake/console/libs/console_option_parser.php b/cake/console/libs/console_option_parser.php index 8a9f8af65..a96a0759a 100644 --- a/cake/console/libs/console_option_parser.php +++ b/cake/console/libs/console_option_parser.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console + * @package cake.console.libs * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -27,8 +26,7 @@ require_once CONSOLE_LIBS . 'help_formatter.php'; * for GetOpt compatible option definition. Provides a builder pattern implementation * for creating shell option parsers. * - * @package cake - * @subpackage cake.cake.console + * @package cake.console.libs */ class ConsoleOptionParser { @@ -88,7 +86,7 @@ class ConsoleOptionParser { * preceeded by one - and are only one character long. They usually match with a long option, * and provide a more terse alternative. * - * #### Using Options + * ### Using Options * * Options can be defined with both long and short forms. By using `$parser->addOption()` * you can define new options. The name of the option is used as its long form, and you @@ -195,7 +193,7 @@ class ConsoleOptionParser { } /** - * Get or set the command name for shell/task + * Get or set the command name for shell/task. * * @param string $text The text to set, or null if you want to read * @return mixed If reading, the value of the command. If setting $this will be returned @@ -209,7 +207,7 @@ class ConsoleOptionParser { } /** - * Get or set the description text for shell/task + * Get or set the description text for shell/task. * * @param mixed $text The text to set, or null if you want to read. . If an array the text will be imploded with "\n" * @return mixed If reading, the value of the description. If setting $this will be returned @@ -247,7 +245,7 @@ class ConsoleOptionParser { * Add an option to the option parser. Options allow you to define optional or required * parameters for your console application. Options are defined by the parameters they use. * - * ### Params + * ### Options * * - `short` - The single letter variant for this option, leave undefined for none. * - `help` - Help text for this option. Used when generating help for the option. @@ -260,11 +258,12 @@ class ConsoleOptionParser { * - `choices` A list of valid choices for this option. If left empty all values are valid.. * An exception will be raised when parse() encounters an invalid value. * - * @param string $name The long name you want to the value to be parsed out as when options are parsed. + * @param mixed $name The long name you want to the value to be parsed out as when options are parsed. + * Will also accept an instance of ConsoleInputOption * @param array $params An array of parameters that define the behavior of the option * @return returns $this. */ - public function addOption($name, $params = array()) { + public function addOption($name, $options = array()) { if (is_object($name) && $name instanceof ConsoleInputOption) { $option = $name; $name = $option->name(); @@ -277,7 +276,7 @@ class ConsoleOptionParser { 'boolean' => false, 'choices' => array() ); - $options = array_merge($defaults, $params); + $options = array_merge($defaults, $options); $option = new ConsoleInputOption($options); } $this->_options[$name] = $option; @@ -300,7 +299,7 @@ class ConsoleOptionParser { * - `choices` A list of valid choices for this argument. If left empty all values are valid.. * An exception will be raised when parse() encounters an invalid value. * - * @param string $name The name of the argument. + * @param mixed $name The name of the argument. Will also accept an instance of ConsoleInputArgument * @param array $params Parameters for the argument, see above. * @return $this. */ @@ -357,21 +356,20 @@ class ConsoleOptionParser { /** * Append a subcommand to the subcommand list. - * Subcommands are usually methods on your Shell, but can also be used to document - * Tasks + * Subcommands are usually methods on your Shell, but can also be used to document Tasks. * - * ### Params + * ### Options * * - `help` - Help text for the subcommand. * - `parser` - A ConsoleOptionParser for the subcommand. This allows you to create method * specific option parsers. When help is generated for a subcommand, if a parser is present * it will be used. * - * @param string $name Name of the subcommand + * @param mixed $name Name of the subcommand. Will also accept an instance of ConsoleInputSubcommand * @param array $params Array of params, see above. * @return $this. */ - public function addSubcommand($name, $params = array()) { + public function addSubcommand($name, $options = array()) { if (is_object($name) && $name instanceof ConsoleInputSubcommand) { $command = $name; $name = $command->name(); @@ -381,7 +379,7 @@ class ConsoleOptionParser { 'help' => '', 'parser' => null ); - $options = array_merge($defaults, $params); + $options = array_merge($defaults, $options); $command = new ConsoleInputSubcommand($options); } $this->_subcommands[$name] = $command; @@ -457,7 +455,7 @@ class ConsoleOptionParser { } foreach ($this->_args as $i => $arg) { if ($arg->isRequired() && !isset($args[$i]) && empty($params['help'])) { - throw new RuntimeException( + throw new ConsoleException( __('Missing required arguments. %s is required.', $arg->name()) ); } @@ -552,7 +550,7 @@ class ConsoleOptionParser { */ protected function _parseOption($name, $params) { if (!isset($this->_options[$name])) { - throw new InvalidArgumentException(__('Unknown option `%s`', $name)); + throw new ConsoleException(__('Unknown option `%s`', $name)); } $option = $this->_options[$name]; $isBoolean = $option->isBoolean(); @@ -586,7 +584,7 @@ class ConsoleOptionParser { } $next = count($args); if (!isset($this->_args[$next])) { - throw new InvalidArgumentException(__('Too many arguments.')); + throw new ConsoleException(__('Too many arguments.')); } if ($this->_args[$next]->validChoice($argument)) { diff --git a/cake/console/libs/console_output.php b/cake/console/libs/console_output.php index ef47266f0..7d41da4d7 100644 --- a/cake/console/libs/console_output.php +++ b/cake/console/libs/console_output.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console + * @package cake.console.libs * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,7 +20,7 @@ * Object wrapper for outputing information from a shell application. * Can be connected to any stream resource that can be used with fopen() * - * Can generate colourzied output on consoles that support it. There are a few + * Can generate colourized output on consoles that support it. There are a few * built in styles * * - `error` Error messages. @@ -42,7 +41,7 @@ * See ConsoleOutput::styles() to learn more about defining your own styles. Nested styles are not supported * at this time. * - * @package cake.console + * @package cake.console.libs */ class ConsoleOutput { /** @@ -143,8 +142,8 @@ class ConsoleOutput { * * Checks for a pretty console enviornment. Ansicon allows pretty consoles * on windows, and is supported. - * - * @return void + * + * @param string $stream The identifier of the stream to write output to. */ public function __construct($stream = 'php://stdout') { $this->_output = fopen($stream, 'w'); @@ -156,7 +155,7 @@ class ConsoleOutput { /** * Outputs a single or multiple messages to stdout. If no parameters - * are passed outputs just a newline. + * are passed, outputs just a newline. * * @param mixed $message A string or a an array of strings to output * @param integer $newlines Number of newlines to append @@ -216,7 +215,7 @@ class ConsoleOutput { } /** - * Writes a message to the output stream + * Writes a message to the output stream. * * @param string $message Message to write. * @return boolean success diff --git a/cake/console/libs/help_formatter.php b/cake/console/libs/help_formatter.php index 002689899..f454fa8b2 100644 --- a/cake/console/libs/help_formatter.php +++ b/cake/console/libs/help_formatter.php @@ -12,9 +12,6 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console - * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ App::import('Core', 'String', false); @@ -28,12 +25,14 @@ App::import('Core', 'String', false); * * Xml output is useful for intergration with other tools like IDE's or other build tools. * + * @package cake.console.libs + * @since CakePHP(tm) v 2.0 */ class HelpFormatter { /** * Build the help formatter for a an OptionParser * - * @return void + * @param ConsoleOptionParser $parser The option parser help is being generated for. */ public function __construct(ConsoleOptionParser $parser) { $this->_parser = $parser; diff --git a/cake/console/libs/task_collection.php b/cake/console/libs/task_collection.php index d28b13b6d..32f0b31a4 100644 --- a/cake/console/libs/task_collection.php +++ b/cake/console/libs/task_collection.php @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.libs * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/shell_dispatcher.php b/cake/console/shell_dispatcher.php index a80407613..1b520500b 100644 --- a/cake/console/shell_dispatcher.php +++ b/cake/console/shell_dispatcher.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console + * @package cake.console * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Shell dispatcher handles dispatching cli commands. * - * @package cake - * @subpackage cake.cake.console + * @package cake.console */ class ShellDispatcher { @@ -102,7 +100,7 @@ class ShellDispatcher { protected function _initEnvironment() { if (!$this->__bootstrap()) { $message = "Unable to load CakePHP core.\nMake sure " . DS . 'cake' . DS . 'libs exists in ' . CAKE_CORE_INCLUDE_PATH; - throw new RuntimeException($message); + throw new CakeException($message); } if (!isset($this->args[0]) || !isset($this->params['working'])) { @@ -110,7 +108,7 @@ class ShellDispatcher { "Please make sure that " . DIRECTORY_SEPARATOR . "cake" . DIRECTORY_SEPARATOR . "console is in your system path,\n" . "and check the cookbook for the correct usage of this command.\n" . "(http://book.cakephp.org/)"; - throw new RuntimeException($message); + throw new CakeException($message); } $this->shiftArgs(); diff --git a/cake/console/shells/acl.php b/cake/console/shells/acl.php index e29e4f4ef..b4d458ba7 100644 --- a/cake/console/shells/acl.php +++ b/cake/console/shells/acl.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.shells * @since CakePHP(tm) v 1.2.0.5012 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,8 +23,7 @@ App::import('Model', 'DbAcl'); * Shell for ACL management. This console is known to have issues with zend.ze1_compatibility_mode * being enabled. Be sure to turn it off when using this shell. * - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.libs */ class AclShell extends Shell { diff --git a/cake/console/shells/api.php b/cake/console/shells/api.php index 0c036d09d..05cf326b8 100644 --- a/cake/console/shells/api.php +++ b/cake/console/shells/api.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.shells * @since CakePHP(tm) v 1.2.0.5012 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,8 +23,7 @@ App::import('Core', 'File'); /** * API shell to show method signatures of CakePHP core classes. * - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.libs */ class ApiShell extends Shell { diff --git a/cake/console/shells/app_shell.php b/cake/console/shells/app_shell.php index 59fcc2a09..a624a31ad 100644 --- a/cake/console/shells/app_shell.php +++ b/cake/console/shells/app_shell.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.console.shells + * @package cake.console.shells * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,8 +24,7 @@ * Add your application-wide methods in the class below, your shells * will inherit them. * - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.libs */ class AppShell extends Shell { diff --git a/cake/console/shells/bake.php b/cake/console/shells/bake.php index 77dd36201..ec741ed3a 100644 --- a/cake/console/shells/bake.php +++ b/cake/console/shells/bake.php @@ -16,8 +16,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.shells * @since CakePHP(tm) v 1.2.0.5012 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,8 +24,7 @@ /** * Bake is a command-line code generation utility for automating programmer chores. * - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.libs * @link http://book.cakephp.org/view/1522/Code-Generation-with-Bake */ class BakeShell extends Shell { @@ -186,7 +184,7 @@ class BakeShell extends Shell { } else { $this->error(__('Bake All could not continue without a valid model')); } - $this->_stop(); + return $this->_stop(); } /** diff --git a/cake/console/shells/command_list.php b/cake/console/shells/command_list.php index cd05af4ba..e9323c6f7 100644 --- a/cake/console/shells/command_list.php +++ b/cake/console/shells/command_list.php @@ -12,8 +12,6 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.tests.cases.console.libs * @since CakePHP v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,7 +19,7 @@ /** * Shows a list of commands available from the console. * - * @package cake.console.libs + * @package cake.console.shells */ class CommandListShell extends Shell { diff --git a/cake/console/shells/console.php b/cake/console/shells/console.php index 20ab1615d..44cc13d45 100644 --- a/cake/console/shells/console.php +++ b/cake/console/shells/console.php @@ -12,15 +12,13 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.shells * @since CakePHP(tm) v 1.2.0.5012 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ /** - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.shells */ class ConsoleShell extends Shell { diff --git a/cake/console/shells/i18n.php b/cake/console/shells/i18n.php index c40160e54..0a2bdeef6 100644 --- a/cake/console/shells/i18n.php +++ b/cake/console/shells/i18n.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.shells * @since CakePHP(tm) v 1.2.0.5669 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Shell for I18N management. * - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.shells */ class I18nShell extends Shell { diff --git a/cake/console/shells/schema.php b/cake/console/shells/schema.php index b09b4c74d..c0fe44751 100644 --- a/cake/console/shells/schema.php +++ b/cake/console/shells/schema.php @@ -15,8 +15,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.shells * @since CakePHP(tm) v 1.2.0.5550 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -26,8 +25,7 @@ App::import('Model', 'CakeSchema', false); /** * Schema is a command-line database management utility for automating programmer chores. * - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.shells * @link http://book.cakephp.org/view/1523/Schema-management-and-migrations */ class SchemaShell extends Shell { @@ -299,7 +297,7 @@ class SchemaShell extends Shell { * * @access private */ - function __create(&$Schema, $table = null) { + function __create($Schema, $table = null) { $db = ConnectionManager::getDataSource($this->Schema->connection); $drop = $create = array(); diff --git a/cake/console/shells/shell.php b/cake/console/shells/shell.php index 55c81f94d..dd59dbb2c 100644 --- a/cake/console/shells/shell.php +++ b/cake/console/shells/shell.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.shells * @since CakePHP(tm) v 1.2.0.5012 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,8 +24,7 @@ require_once CONSOLE_LIBS . 'console_option_parser.php'; /** * Base class for command-line utilities for automating programmer chores. * - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.shells */ class Shell extends Object { @@ -220,6 +218,7 @@ class Shell extends Object { if ($this->uses === null || $this->uses === false) { return; } + App::import('Core', 'ClassRegistry'); if ($this->uses !== true && !empty($this->uses)) { $uses = is_array($this->uses) ? $this->uses : array($this->uses); diff --git a/cake/console/shells/tasks/bake.php b/cake/console/shells/tasks/bake.php index 6a89e187c..bd7f59e69 100644 --- a/cake/console/shells/tasks/bake.php +++ b/cake/console/shells/tasks/bake.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs.tasks + * @package cake.console.shells.tasks * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/shells/tasks/controller.php b/cake/console/shells/tasks/controller.php index 6ec3c4371..f1cac43eb 100644 --- a/cake/console/shells/tasks/controller.php +++ b/cake/console/shells/tasks/controller.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs.tasks + * @package cake.console.shells.tasks * @since CakePHP(tm) v 1.2 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ include_once dirname(__FILE__) . DS . 'bake.php'; /** * Task class for creating and updating controller files. * - * @package cake - * @subpackage cake.cake.console.libs.tasks + * @package cake.console.shells.tasks */ class ControllerTask extends BakeTask { diff --git a/cake/console/shells/tasks/db_config.php b/cake/console/shells/tasks/db_config.php index d7e5a20c0..c3c2b36e1 100644 --- a/cake/console/shells/tasks/db_config.php +++ b/cake/console/shells/tasks/db_config.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs.tasks + * @package cake.console.shells.tasks * @since CakePHP(tm) v 1.2 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Task class for creating and updating the database configuration file. * - * @package cake - * @subpackage cake.cake.console.libs.tasks + * @package cake.console.shells.tasks */ class DbConfigTask extends Shell { @@ -106,7 +104,7 @@ class DbConfigTask extends Shell { } } - $driver = $this->in('Driver:', array('db2', 'firebird', 'mssql', 'mysql', 'mysqli', 'odbc', 'oracle', 'postgres', 'sqlite', 'sybase'), 'mysql'); + $driver = $this->in('Driver:', array('db2', 'firebird', 'mssql', 'mysql', 'odbc', 'oracle', 'postgres', 'sqlite', 'sybase'), 'mysql'); $persistent = $this->in('Persistent Connection?', array('y', 'n'), 'n'); if (strtolower($persistent) == 'n') { diff --git a/cake/console/shells/tasks/extract.php b/cake/console/shells/tasks/extract.php index 34c24314e..9965876e2 100644 --- a/cake/console/shells/tasks/extract.php +++ b/cake/console/shells/tasks/extract.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.shells.tasks * @since CakePHP(tm) v 1.2.0.5012 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ App::import('Core', 'File'); /** * Language string extractor * - * @package cake - * @subpackage cake.cake.console.libs.tasks + * @package cake.console.shells.tasks */ class ExtractTask extends Shell { diff --git a/cake/console/shells/tasks/fixture.php b/cake/console/shells/tasks/fixture.php index 88eb5241a..8fd60782b 100644 --- a/cake/console/shells/tasks/fixture.php +++ b/cake/console/shells/tasks/fixture.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs.tasks + * @package cake.console.shells.tasks * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ include_once dirname(__FILE__) . DS . 'bake.php'; /** * Task class for creating and updating fixtures files. * - * @package cake - * @subpackage cake.cake.console.libs.tasks + * @package cake.console.shells.tasks */ class FixtureTask extends BakeTask { @@ -211,7 +209,6 @@ class FixtureTask extends BakeTask { $this->_Schema = new CakeSchema(); $data = $this->_Schema->read(array('models' => false, 'connection' => $this->connection)); - if (!isset($data['tables'][$useTable])) { $this->err('Could not find your selected table ' . $useTable); return false; diff --git a/cake/console/shells/tasks/model.php b/cake/console/shells/tasks/model.php index 7616ef14c..5ac132dd1 100644 --- a/cake/console/shells/tasks/model.php +++ b/cake/console/shells/tasks/model.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs.tasks + * @package cake.console.shells.tasks * @since CakePHP(tm) v 1.2 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ include_once dirname(__FILE__) . DS . 'bake.php'; /** * Task class for creating and updating model files. * - * @package cake - * @subpackage cake.cake.console.libs.tasks + * @package cake.console.shells.tasks */ class ModelTask extends BakeTask { @@ -701,7 +699,7 @@ class ModelTask extends BakeTask { protected function _generatePossibleKeys() { $possible = array(); foreach ($this->_tables as $otherTable) { - $tempOtherModel = & new Model(array('table' => $otherTable, 'ds' => $this->connection)); + $tempOtherModel = new Model(array('table' => $otherTable, 'ds' => $this->connection)); $modelFieldsTemp = $tempOtherModel->schema(true); foreach ($modelFieldsTemp as $fieldName => $field) { if ($field['type'] == 'integer' || $field['type'] == 'string') { diff --git a/cake/console/shells/tasks/plugin.php b/cake/console/shells/tasks/plugin.php index 6ae7bd5cb..118273d45 100644 --- a/cake/console/shells/tasks/plugin.php +++ b/cake/console/shells/tasks/plugin.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs.tasks + * @package cake.console.shells.tasks * @since CakePHP(tm) v 1.2 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Core', 'File'); /** * Task class for creating a plugin * - * @package cake - * @subpackage cake.cake.console.libs.tasks + * @package cake.console.shells.tasks */ class PluginTask extends Shell { diff --git a/cake/console/shells/tasks/project.php b/cake/console/shells/tasks/project.php index bb2a8f34b..433ce9616 100644 --- a/cake/console/shells/tasks/project.php +++ b/cake/console/shells/tasks/project.php @@ -13,8 +13,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.bake + * @package cake.console.shells.tasks * @since CakePHP(tm) v 1.2 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ App::import('Core', 'File'); /** * Task class for creating new project apps and plugins * - * @package cake - * @subpackage cake.cake.console.libs.tasks + * @package cake.console.shells.tasks */ class ProjectTask extends Shell { diff --git a/cake/console/shells/tasks/template.php b/cake/console/shells/tasks/template.php index 85eed96c6..108ffa8a4 100644 --- a/cake/console/shells/tasks/template.php +++ b/cake/console/shells/tasks/template.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.console.libs.tasks + * @package cake.console.shells.tasks * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/shells/tasks/test.php b/cake/console/shells/tasks/test.php index 093457421..0fe453040 100644 --- a/cake/console/shells/tasks/test.php +++ b/cake/console/shells/tasks/test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs.tasks + * @package cake.console.shells.tasks * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,8 +23,7 @@ App::import('Model', 'ClassRegistry'); /** * Task class for creating and updating test files. * - * @package cake - * @subpackage cake.cake.console.libs.tasks + * @package cake.console.shells.tasks */ class TestTask extends BakeTask { diff --git a/cake/console/shells/tasks/view.php b/cake/console/shells/tasks/view.php index bf8777238..51c84f2f3 100644 --- a/cake/console/shells/tasks/view.php +++ b/cake/console/shells/tasks/view.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs.tasks + * @package cake.console.libs.tasks * @since CakePHP(tm) v 1.2 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ include_once dirname(__FILE__) . DS . 'bake.php'; /** * Task class for creating and updating view files. * - * @package cake - * @subpackage cake.cake.console.libs.tasks + * @package cake.console.shells.tasks */ class ViewTask extends BakeTask { diff --git a/cake/console/shells/testsuite.php b/cake/console/shells/testsuite.php index 8814242a2..b8eb079b8 100644 --- a/cake/console/shells/testsuite.php +++ b/cake/console/shells/testsuite.php @@ -14,8 +14,7 @@ * * @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.cake.console.libs + * @package cake.console.shells * @since CakePHP(tm) v 1.2.0.4433 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/default/actions/controller_actions.ctp b/cake/console/templates/default/actions/controller_actions.ctp index 370879e66..e6f0f8e83 100644 --- a/cake/console/templates/default/actions/controller_actions.ctp +++ b/cake/console/templates/default/actions/controller_actions.ctp @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.console.libs.template.objects + * @package cake.console.libs.template.objects * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,13 +24,9 @@ } public function view($id = null) { - if (!$id) { - - $this->Session->setFlash(__('Invalid ')); - $this->redirect(array('action' => 'index')); - - $this->flash(__('Invalid '), array('action' => 'index')); - + $this->->id = $id; + if (!$this->->exists()) { + throw new NotFoundException(__('Invalid ')); } $this->set('', $this->->read(null, $id)); } @@ -72,15 +67,11 @@ public function edit($id = null) { - if (!$id && empty($this->request->data)) { - - $this->Session->setFlash(__('Invalid ')); - $this->redirect(array('action' => 'index')); - - $this->flash(__('Invalid '), array('action' => 'index')); - + $this->->id = $id; + if (!$this->->exists()) { + throw new NotFoundException(__('Invalid ')); } - if ($this->request->is('post')) { + if ($this->request->is('post') || $this->request->is('put')) { if ($this->->save($this->request->data)) { $this->Session->setFlash(__('The has been saved')); @@ -93,9 +84,8 @@ $this->Session->setFlash(__('The could not be saved. Please, try again.')); } - } - if (!$this->request->is('post')) { - $this->data = $this->->read(null, $id); + } else { + $this->request->data = $this->->read(null, $id); } request->is('post')) { throw new MethodNotAllowedException(); } - if (!$id) { - - $this->Session->setFlash(__('Invalid id for ')); - $this->redirect(array('action'=>'index')); - - $this->flash(__('Invalid '), array('action' => 'index')); - + $this->->id = $id; + if (!$this->->exists()) { + throw new NotFoundException(__('Invalid ')); } - if ($this->->delete($id)) { + if ($this->->delete()) { $this->Session->setFlash(__(' deleted')); $this->redirect(array('action'=>'index')); diff --git a/cake/console/templates/default/classes/controller.ctp b/cake/console/templates/default/classes/controller.ctp index a66e0faa5..52f968824 100644 --- a/cake/console/templates/default/classes/controller.ctp +++ b/cake/console/templates/default/classes/controller.ctp @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake. + * @package cake. * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/default/classes/fixture.ctp b/cake/console/templates/default/classes/fixture.ctp index a8d1bbfb2..dd1b5b478 100644 --- a/cake/console/templates/default/classes/fixture.ctp +++ b/cake/console/templates/default/classes/fixture.ctp @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake. + * @package cake. * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/default/classes/model.ctp b/cake/console/templates/default/classes/model.ctp index 222dd0da8..ece196dba 100644 --- a/cake/console/templates/default/classes/model.ctp +++ b/cake/console/templates/default/classes/model.ctp @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.console.libs.templates.objects + * @package cake.console.libs.templates.objects * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/default/classes/test.ctp b/cake/console/templates/default/classes/test.ctp index 5811e8446..f9dd98b0b 100644 --- a/cake/console/templates/default/classes/test.ctp +++ b/cake/console/templates/default/classes/test.ctp @@ -13,8 +13,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.console.libs.templates.objects + * @package cake.console.libs.templates.objects * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/default/views/form.ctp b/cake/console/templates/default/views/form.ctp index 455648ed7..ce2b525f9 100644 --- a/cake/console/templates/default/views/form.ctp +++ b/cake/console/templates/default/views/form.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs.templates.views + * @package cake.console.libs.templates.views * @since CakePHP(tm) v 1.2.0.5234 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -20,7 +19,7 @@
Form->create('{$modelClass}');?>\n";?>
- ", Inflector::humanize($action), $singularHumanName); ?> + ", Inflector::humanize($action), $singularHumanName); ?> Sweet, \"" . Inflector::humanize($app) . "\" got Baked by CakePHP!\n"; $output .=" 0): Debugger::checkSecurityKeys(); endif; diff --git a/cake/console/templates/default/views/index.ctp b/cake/console/templates/default/views/index.ctp index 0732fe058..01c834d64 100644 --- a/cake/console/templates/default/views/index.ctp +++ b/cake/console/templates/default/views/index.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs.templates.views + * @package cake.console.libs.templates.views * @since CakePHP(tm) v 1.2.0.5234 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/default/views/view.ctp b/cake/console/templates/default/views/view.ctp index 9e791196f..8ed607d83 100644 --- a/cake/console/templates/default/views/view.ctp +++ b/cake/console/templates/default/views/view.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs.templates.views + * @package cake.console.libs.templates.views * @since CakePHP(tm) v 1.2.0.5234 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/skel/app_controller.php b/cake/console/templates/skel/app_controller.php index 2139202a3..8573bb7c4 100644 --- a/cake/console/templates/skel/app_controller.php +++ b/cake/console/templates/skel/app_controller.php @@ -15,8 +15,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app + * @package app * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -27,8 +26,7 @@ * Add your application-wide methods in the class below, your controllers * will inherit them. * - * @package cake - * @subpackage cake.app + * @package app */ class AppController extends Controller { } diff --git a/cake/console/templates/skel/app_helper.php b/cake/console/templates/skel/app_helper.php index 2dd482b90..02955a34e 100644 --- a/cake/console/templates/skel/app_helper.php +++ b/cake/console/templates/skel/app_helper.php @@ -16,7 +16,6 @@ * @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 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -30,7 +29,6 @@ App::import('Helper', 'Helper', false); * will inherit them. * * @package cake - * @subpackage cake.cake */ class AppHelper extends Helper { } diff --git a/cake/console/templates/skel/app_model.php b/cake/console/templates/skel/app_model.php index bb4236c45..87a130a8a 100644 --- a/cake/console/templates/skel/app_model.php +++ b/cake/console/templates/skel/app_model.php @@ -15,8 +15,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app + * @package app * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -27,8 +26,7 @@ * Add your application-wide methods in the class below, your models * will inherit them. * - * @package cake - * @subpackage cake.app + * @package app */ class AppModel extends Model { } diff --git a/cake/console/templates/skel/config/acl.ini.php b/cake/console/templates/skel/config/acl.ini.php index 7a90814db..3da8e407f 100644 --- a/cake/console/templates/skel/config/acl.ini.php +++ b/cake/console/templates/skel/config/acl.ini.php @@ -14,8 +14,7 @@ ; * ; * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) ; * @link http://cakephp.org CakePHP(tm) Project -; * @package cake -; * @subpackage cake.app.config +; * @package app.config ; * @since CakePHP(tm) v 0.10.0.1076 ; * @license MIT License (http://www.opensource.org/licenses/mit-license.php) ; */ diff --git a/cake/console/templates/skel/config/bootstrap.php b/cake/console/templates/skel/config/bootstrap.php index f4a85e10f..697274852 100644 --- a/cake/console/templates/skel/config/bootstrap.php +++ b/cake/console/templates/skel/config/bootstrap.php @@ -15,8 +15,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app.config + * @package app.config * @since CakePHP(tm) v 0.10.8.2117 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/skel/config/core.php b/cake/console/templates/skel/config/core.php index c9560d15a..9744da06c 100644 --- a/cake/console/templates/skel/config/core.php +++ b/cake/console/templates/skel/config/core.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app.config + * @package app.config * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/skel/config/database.php.default b/cake/console/templates/skel/config/database.php.default index f85b56922..0952dac47 100644 --- a/cake/console/templates/skel/config/database.php.default +++ b/cake/console/templates/skel/config/database.php.default @@ -14,16 +14,14 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app.config + * @package app.config * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ /** * In this file you set up your database connection details. * - * @package cake - * @subpackage cake.config + * @package cake.config */ /** * Database configuration class. @@ -31,7 +29,6 @@ * * driver => The name of a supported driver; valid options are as follows: * mysql - MySQL 4 & 5, - * mysqli - MySQL 4 & 5 Improved Interface (PHP5 only), * sqlite - SQLite (PHP5 only), * postgres - PostgreSQL 7 and higher, * mssql - Microsoft SQL Server 2000 and higher, @@ -56,7 +53,7 @@ * 'public', DB2 defaults to empty. * * encoding => - * For MySQL, MySQLi, Postgres specifies the character encoding to use when connecting to the + * For MySQL, Postgres and Sqlite, specifies the character encoding to use when connecting to the * database. Uses database default. * */ diff --git a/cake/console/templates/skel/config/routes.php b/cake/console/templates/skel/config/routes.php index 8aa7561ba..b6089eb2d 100644 --- a/cake/console/templates/skel/config/routes.php +++ b/cake/console/templates/skel/config/routes.php @@ -16,8 +16,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app.config + * @package app.config * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/skel/config/schema/db_acl.php b/cake/console/templates/skel/config/schema/db_acl.php index 511250f62..8400e85ed 100644 --- a/cake/console/templates/skel/config/schema/db_acl.php +++ b/cake/console/templates/skel/config/schema/db_acl.php @@ -16,8 +16,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app.config.sql + * @package app.config.sql * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/skel/config/schema/i18n.php b/cake/console/templates/skel/config/schema/i18n.php index a2f02ea72..504f00812 100644 --- a/cake/console/templates/skel/config/schema/i18n.php +++ b/cake/console/templates/skel/config/schema/i18n.php @@ -16,8 +16,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app.config.sql + * @package app.config.sql * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/skel/config/schema/sessions.php b/cake/console/templates/skel/config/schema/sessions.php index 8a37814f4..29a40a566 100644 --- a/cake/console/templates/skel/config/schema/sessions.php +++ b/cake/console/templates/skel/config/schema/sessions.php @@ -16,8 +16,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app.config.sql + * @package app.config.sql * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/skel/console/cake b/cake/console/templates/skel/console/cake index d4d067d59..bd1b6da06 100644 --- a/cake/console/templates/skel/console/cake +++ b/cake/console/templates/skel/console/cake @@ -12,8 +12,7 @@ # # @copyright Copyright 2005-2010, Cake Software Foundation, Inc. # @link http://cakephp.org CakePHP(tm) Project -# @package cake -# @subpackage cake.app.console +# @package app.console # @since CakePHP(tm) v 2.0 # @license MIT License (http://www.opensource.org/licenses/mit-license.php) # diff --git a/cake/console/templates/skel/console/cake.bat b/cake/console/templates/skel/console/cake.bat index 84ed04a4f..ed04546c9 100644 --- a/cake/console/templates/skel/console/cake.bat +++ b/cake/console/templates/skel/console/cake.bat @@ -11,8 +11,7 @@ :: :: @copyright Copyright 2005-2010, Cake Software Foundation, Inc. :: @link http://cakephp.org CakePHP(tm) Project -:: @package cake -:: @subpackage cake.app.console +:: @package app.console :: @since CakePHP(tm) v 2.0 :: @license MIT License (http://www.opensource.org/licenses/mit-license.php) :: diff --git a/cake/console/templates/skel/console/cake.php b/cake/console/templates/skel/console/cake.php index 8ccac0bfb..d4f4ef1c0 100644 --- a/cake/console/templates/skel/console/cake.php +++ b/cake/console/templates/skel/console/cake.php @@ -15,8 +15,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console + * @package app.console * @since CakePHP(tm) v 1.2.0.5012 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/skel/controllers/pages_controller.php b/cake/console/templates/skel/controllers/pages_controller.php index 650adda94..f0cf2ce27 100644 --- a/cake/console/templates/skel/controllers/pages_controller.php +++ b/cake/console/templates/skel/controllers/pages_controller.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.controller + * @package cake.libs.controller * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,8 +24,7 @@ * * Override this controller by placing a copy in controllers directory of an application * - * @package cake - * @subpackage cake.cake.libs.controller + * @package cake.libs.controller */ class PagesController extends AppController { diff --git a/cake/console/templates/skel/index.php b/cake/console/templates/skel/index.php index a9e0270cb..ac4fde167 100644 --- a/cake/console/templates/skel/index.php +++ b/cake/console/templates/skel/index.php @@ -10,8 +10,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app + * @package app * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/skel/views/elements/email/html/default.ctp b/cake/console/templates/skel/views/elements/email/html/default.ctp index 45a84c9e0..3ab3f4cc6 100644 --- a/cake/console/templates/skel/views/elements/email/html/default.ctp +++ b/cake/console/templates/skel/views/elements/email/html/default.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.elements.email.html + * @package cake.libs.view.templates.elements.email.html * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/skel/views/elements/email/text/default.ctp b/cake/console/templates/skel/views/elements/email/text/default.ctp index 9d384e3f8..7655f1430 100644 --- a/cake/console/templates/skel/views/elements/email/text/default.ctp +++ b/cake/console/templates/skel/views/elements/email/text/default.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.elements.email.text + * @package cake.libs.view.templates.elements.email.text * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/skel/views/layouts/ajax.ctp b/cake/console/templates/skel/views/layouts/ajax.ctp index dadf156ed..93371552b 100644 --- a/cake/console/templates/skel/views/layouts/ajax.ctp +++ b/cake/console/templates/skel/views/layouts/ajax.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.layouts + * @package cake.libs.view.templates.layouts * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/skel/views/layouts/default.ctp b/cake/console/templates/skel/views/layouts/default.ctp index a07b907b3..e8b6b3c50 100644 --- a/cake/console/templates/skel/views/layouts/default.ctp +++ b/cake/console/templates/skel/views/layouts/default.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs.templates.skel.views.layouts + * @package cake.console.libs.templates.skel.views.layouts * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/skel/views/layouts/email/html/default.ctp b/cake/console/templates/skel/views/layouts/email/html/default.ctp index 8b5a339f8..cc4364bb1 100644 --- a/cake/console/templates/skel/views/layouts/email/html/default.ctp +++ b/cake/console/templates/skel/views/layouts/email/html/default.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.layouts.email.html + * @package cake.libs.view.templates.layouts.email.html * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/skel/views/layouts/email/text/default.ctp b/cake/console/templates/skel/views/layouts/email/text/default.ctp index e509b1b32..f85bd7ea2 100644 --- a/cake/console/templates/skel/views/layouts/email/text/default.ctp +++ b/cake/console/templates/skel/views/layouts/email/text/default.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.layouts.email.text + * @package cake.libs.view.templates.layouts.email.text * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/skel/views/layouts/flash.ctp b/cake/console/templates/skel/views/layouts/flash.ctp index bfd9a4621..554fb377c 100644 --- a/cake/console/templates/skel/views/layouts/flash.ctp +++ b/cake/console/templates/skel/views/layouts/flash.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.layouts + * @package cake.libs.view.templates.layouts * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/skel/webroot/css.php b/cake/console/templates/skel/webroot/css.php index 9a1313877..59505c4e9 100644 --- a/cake/console/templates/skel/webroot/css.php +++ b/cake/console/templates/skel/webroot/css.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app.webroot + * @package app.webroot * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/skel/webroot/css/cake.generic.css b/cake/console/templates/skel/webroot/css/cake.generic.css index 7f978afc0..66deb64a8 100644 --- a/cake/console/templates/skel/webroot/css/cake.generic.css +++ b/cake/console/templates/skel/webroot/css/cake.generic.css @@ -10,8 +10,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app.webroot.css + * @package app.webroot.css * @since CakePHP(tm) * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/skel/webroot/index.php b/cake/console/templates/skel/webroot/index.php index 719f172c4..5955688f6 100644 --- a/cake/console/templates/skel/webroot/index.php +++ b/cake/console/templates/skel/webroot/index.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app.webroot + * @package app.webroot * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/console/templates/skel/webroot/test.php b/cake/console/templates/skel/webroot/test.php index 7a27e8e29..eddcc437f 100644 --- a/cake/console/templates/skel/webroot/test.php +++ b/cake/console/templates/skel/webroot/test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://book.cakephp.org/view/1196/Testing - * @package cake - * @subpackage cake.app.webroot + * @package app.webroot * @since CakePHP(tm) v 1.2.0.4433 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/app.php b/cake/libs/app.php index f18bb0719..7d8868814 100644 --- a/cake/libs/app.php +++ b/cake/libs/app.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 1.2.0.6001 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -43,8 +42,7 @@ * which application controllers App knows about. * * @link http://book.cakephp.org/view/933/The-App-Class - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs */ class App { diff --git a/cake/libs/cache.php b/cake/libs/cache.php index e211d20f9..66f255b34 100644 --- a/cake/libs/cache.php +++ b/cake/libs/cache.php @@ -13,17 +13,33 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 1.2.0.4933 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ /** - * Caching for CakePHP. + * Cache provides a consistent interface to Caching in your application. It allows you + * to use several different Cache engines, without coupling your application to a specific + * implementation. It also allows you to change out cache storage or configuration without effecting + * the rest of your application. * - * @package cake - * @subpackage cake.cake.libs + * You can configure Cache engines in your application's `bootstrap.php` file. A sample configuration would + * be + * + * {{{ + * Cache::config('shared', array( + * 'engine' => 'Apc', + * 'prefix' => 'my_app_' + * )); + * }}} + * + * This would configure an APC cache engine to the 'shared' alias. You could then read and write + * to that cache alias by using it for the `$config` parameter in the various Cache methods. In + * general all Cache operations are supported by all cache engines. However, Cache::increment() and + * Cache::decrement() are not supported by File caching. + * + * @package cake.libs */ class Cache { @@ -67,7 +83,7 @@ class Cache { * @param string $name Name of the configuration * @param array $settings Optional associative array of settings passed to the engine * @return array(engine, settings) on success, false on failure - * @throws Exception + * @throws CacheException */ public static function config($name = null, $settings = array()) { if (is_array($name)) { @@ -113,10 +129,10 @@ class Cache { return false; } $cacheClass = $class . 'Engine'; - self::$_engines[$name] = new $cacheClass(); - if (!self::$_engines[$name] instanceof CacheEngine) { - throw new Exception(__('Cache engines must use CacheEngine as a base class.')); + if (!is_subclass_of($cacheClass, 'CacheEngine')) { + throw new CacheException(__('Cache engines must use CacheEngine as a base class.')); } + self::$_engines[$name] = new $cacheClass(); if (self::$_engines[$name]->init($config)) { if (time() % self::$_engines[$name]->settings['probability'] === 0) { self::$_engines[$name]->gc(); @@ -456,8 +472,7 @@ class Cache { /** * Storage engine for CakePHP caching * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs */ abstract class CacheEngine { diff --git a/cake/libs/cache/apc.php b/cake/libs/cache/apc.php index dbc4df8cc..544a0c908 100644 --- a/cake/libs/cache/apc.php +++ b/cake/libs/cache/apc.php @@ -13,8 +13,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.cache + * @package cake.libs.cache * @since CakePHP(tm) v 1.2.0.4933 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ /** * APC storage engine for cache * - * @package cake - * @subpackage cake.cake.libs.cache + * @package cake.libs.cache */ class ApcEngine extends CacheEngine { diff --git a/cake/libs/cache/file.php b/cake/libs/cache/file.php index 687a74f72..46ff892a3 100644 --- a/cake/libs/cache/file.php +++ b/cake/libs/cache/file.php @@ -13,8 +13,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.cache + * @package cake.libs.cache * @since CakePHP(tm) v 1.2.0.4933 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * File Storage engine for cache * * @todo use the File and Folder classes (if it's not a too big performance hit) - * @package cake - * @subpackage cake.cake.libs.cache + * @package cake.libs.cache */ class FileEngine extends CacheEngine { @@ -249,20 +247,20 @@ class FileEngine extends CacheEngine { * Not implemented * * @return void - * @throws BadMethodCallException + * @throws CacheException */ public function decrement($key, $offset = 1) { - throw new BadMethodCallException(__('Files cannot be atomically decremented.')); + throw new CacheException(__('Files cannot be atomically decremented.')); } /** * Not implemented * * @return void - * @throws BadMethodCallException + * @throws CacheException */ public function increment($key, $offset = 1) { - throw new BadMethodCallException(__('Files cannot be atomically incremented.')); + throw new CacheException(__('Files cannot be atomically incremented.')); } /** diff --git a/cake/libs/cache/memcache.php b/cake/libs/cache/memcache.php index 9b121e89f..79d98376e 100644 --- a/cake/libs/cache/memcache.php +++ b/cake/libs/cache/memcache.php @@ -13,8 +13,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.cache + * @package cake.libs.cache * @since CakePHP(tm) v 1.2.0.4933 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,8 +23,7 @@ * control you have over expire times far in the future. See MemcacheEngine::write() for * more information. * - * @package cake - * @subpackage cake.cake.libs.cache + * @package cake.libs.cache */ class MemcacheEngine extends CacheEngine { @@ -148,11 +146,11 @@ class MemcacheEngine extends CacheEngine { * @param integer $offset How much to increment * @param integer $duration How long to cache the data, in seconds * @return New incremented value, false otherwise - * @throws RuntimeException when you try to increment with compress = true + * @throws CacheException when you try to increment with compress = true */ public function increment($key, $offset = 1) { if ($this->settings['compress']) { - throw new RuntimeException( + throw new CacheException( __('Method increment() not implemented for compressed cache in %s', __CLASS__) ); } @@ -166,11 +164,11 @@ class MemcacheEngine extends CacheEngine { * @param integer $offset How much to substract * @param integer $duration How long to cache the data, in seconds * @return New decremented value, false otherwise - * @throws RuntimeException when you try to decrement with compress = true + * @throws CacheException when you try to decrement with compress = true */ public function decrement($key, $offset = 1) { if ($this->settings['compress']) { - throw new RuntimeException( + throw new CacheException( __('Method decrement() not implemented for compressed cache in %s', __CLASS__) ); } diff --git a/cake/libs/cache/xcache.php b/cake/libs/cache/xcache.php index be8f53c22..53b0d08b9 100644 --- a/cake/libs/cache/xcache.php +++ b/cake/libs/cache/xcache.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.cache + * @package cake.libs.cache * @since CakePHP(tm) v 1.2.0.4947 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ * Xcache storage engine for cache * * @link http://trac.lighttpd.net/xcache/ Xcache - * @package cake - * @subpackage cake.cake.libs.cache + * @package cake.libs.cache */ class XcacheEngine extends CacheEngine { diff --git a/cake/libs/cake_log.php b/cake/libs/cake_log.php index 5e8887c65..e632c2898 100644 --- a/cake/libs/cake_log.php +++ b/cake/libs/cake_log.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -50,7 +49,6 @@ interface CakeLogInterface { * @param string $type * @param string $message * @return void - * @author Mark Story */ public function write($type, $message); } @@ -60,8 +58,7 @@ interface CakeLogInterface { * using CakeLogs's methods. If you don't configure any adapters, and write to the logs * a default FileLog will be autoconfigured for you. * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs */ class CakeLog { @@ -97,18 +94,18 @@ class CakeLog { * @param string $key The keyname for this logger, used to remove the logger later. * @param array $config Array of configuration information for the logger * @return boolean success of configuration. - * @throws Exception + * @throws CakeLogException */ public static function config($key, $config) { if (empty($config['engine'])) { - throw new Exception(__('Missing logger classname')); + throw new CakeLogException(__('Missing logger classname')); } $loggerName = $config['engine']; unset($config['engine']); $className = self::_getLogger($loggerName); $logger = new $className($config); if (!$logger instanceof CakeLogInterface) { - throw new Exception(sprintf( + throw new CakeLogException(sprintf( __('logger class %s does not implement a write method.'), $loggerName )); } @@ -134,7 +131,7 @@ class CakeLog { } } if (!class_exists($loggerName)) { - throw new Exception(__('Could not load class %s', $loggerName)); + throw new CakeLogException(__('Could not load class %s', $loggerName)); } return $loggerName; } diff --git a/cake/libs/cake_request.php b/cake/libs/cake_request.php index ec05c55d2..b7a10058e 100644 --- a/cake/libs/cake_request.php +++ b/cake/libs/cake_request.php @@ -12,7 +12,6 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -426,7 +425,7 @@ class CakeRequest implements ArrayAccess { $type = strtolower(substr($name, 2)); return $this->is($type); } - throw new BadMethodCallException(sprintf('Method %s does not exist', $name)); + throw new CakeException(__('Method %s does not exist', $name)); } /** @@ -519,7 +518,8 @@ class CakeRequest implements ArrayAccess { } /** - * Add parameters to the request's parsed parameter set. This will overwrite any existing parameters + * Add parameters to the request's parsed parameter set. This will overwrite any existing parameters. + * This modifies the parameters available through `$request->params`. * * @param array $params Array of parameters to merge in * @return The current object, you can chain this method. @@ -531,6 +531,7 @@ class CakeRequest implements ArrayAccess { /** * Add paths to the requests' paths vars. This will overwrite any existing paths. + * Provides an easy way to modify, here, webroot and base. * * @param array $paths Array of paths to merge in * @return the current object, you can chain this method. @@ -605,11 +606,11 @@ class CakeRequest implements ArrayAccess { * * #### Get all types: * - * `$request->accepts();` + * `$this->request->accepts();` * * #### Check for a single type: * - * `$request->accepts('json');` + * `$this->request->accepts('json');` * * @param string $type The content type to check for. Leave null to get all types a client accepts. * @return mixed Either an array of all the types the client accepts or a boolean if they accept the @@ -632,6 +633,14 @@ class CakeRequest implements ArrayAccess { /** * Get the lanaguages accepted by the client, or check if a specific language is accepted. * + * Get the list of accepted languages: + * + * {{{ CakeRequest::acceptLanguage(); }}} + * + * Check if a specific language is accepted: + * + * {{{ CakeRequest::acceptLanguage('es-es'); }}} + * * @param string $language The language to test. * @return If a $language is provided, a boolean. Otherwise the array of accepted languages. */ diff --git a/cake/libs/cake_response.php b/cake/libs/cake_response.php index d2217efbd..9c200cbcb 100644 --- a/cake/libs/cake_response.php +++ b/cake/libs/cake_response.php @@ -1,9 +1,6 @@ _status; } if (!isset($this->_statusCodes[$code])) { - throw new OutOfRangeException(__('Unknown status code')); + throw new CakeException(__('Unknown status code')); } return $this->_status = $code; } @@ -500,15 +505,19 @@ class CakeResponse { * if $contentType is an associative array, it will be stored as a content type definition * * ### Setting the content type + * * e.g `type('jpg');` * * ### Returning the current content type + * * e.g `type();` * * ### Storing a content type definition + * * e.g `type(array('keynote' => 'application/keynote'));` * * ### Replacing a content type definition + * * e.g `type(array('jpg' => 'text/plain'));` * * @param string $contentType @@ -623,7 +632,8 @@ class CakeResponse { } /** - * Sets the correct output buffering handler to send a compressed response + * Sets the correct output buffering handler to send a compressed response. Responses will + * be compressed with zlib, if the extension is available. * * @return boolean false if client does not accept compressed responses or no handler is available, true otherwise */ @@ -635,7 +645,7 @@ class CakeResponse { } /** - * Sets the correct headers to instruct the browser to dowload the response as a file + * Sets the correct headers to instruct the browser to dowload the response as a file. * * @param string $filename the name of the file as the browser will download the response * @return void diff --git a/cake/libs/cake_session.php b/cake/libs/cake_session.php index dcc662144..a08fd49c3 100644 --- a/cake/libs/cake_session.php +++ b/cake/libs/cake_session.php @@ -17,11 +17,13 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v .0.10.0.1222 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +if (!class_exists('Security')) { + App::import('Core', 'Security'); +} /** * Session class for Cake. @@ -29,8 +31,7 @@ * Cake abstracts the handling of sessions. There are several convenient methods to access session information. * This class is the implementation of those methods. They are mostly used by the Session Component. * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs */ class CakeSession { @@ -97,13 +98,6 @@ class CakeSession { */ public static $sessionTime = false; -/** - * Keeps track of keys to watch for writes on - * - * @var array - */ - public static $watchKeys = array(); - /** * Current Session id * @@ -148,14 +142,8 @@ class CakeSession { if (($checkAgent === true || $checkAgent === null) && env('HTTP_USER_AGENT') != null) { self::$_userAgent = md5(env('HTTP_USER_AGENT') . Configure::read('Security.salt')); } - - if ($start === true) { - self::_setPath($base); - self::_setHost(env('HTTP_HOST')); - } - if (isset($_SESSION) || $start === true) { - self::start(); - } + self::_setPath($base); + self::_setHost(env('HTTP_HOST')); } /** @@ -229,6 +217,9 @@ class CakeSession { * @return boolean True if variable is there */ public static function check($name = null) { + if (!self::started() && !self::start()) { + return false; + } if (empty($name)) { return false; } @@ -261,9 +252,6 @@ class CakeSession { */ public static function delete($name) { if (self::check($name)) { - if (in_array($name, self::$watchKeys)) { - trigger_error(__('Deleting session key {%s}', $name), E_USER_NOTICE); - } self::__overwrite($_SESSION, Set::remove($_SESSION, $name)); return (self::check($name) == false); } @@ -371,6 +359,9 @@ class CakeSession { * @return mixed The value of the session variable */ public static function read($name = null) { + if (!self::started() && !self::start()) { + return false; + } if (is_null($name)) { return self::__returnSessionVars(); } @@ -390,9 +381,8 @@ class CakeSession { * Returns all session variables. * * @return mixed Full $_SESSION array, or false on error. - * @access private */ - function __returnSessionVars() { + private static function __returnSessionVars() { if (!empty($_SESSION)) { return $_SESSION; } @@ -400,41 +390,6 @@ class CakeSession { return false; } -/** - * Tells Session to write a notification when a certain session path or subpath is written to - * - * @param mixed $var The variable path to watch - * @return void - */ - public static function watch($var) { - if (empty($var)) { - return false; - } - if (!in_array($var, self::$watchKeys, true)) { - self::$watchKeys[] = $var; - } - } - -/** - * Tells Session to stop watching a given key path - * - * @param mixed $var The variable path to watch - * @return void - */ - public static function ignore($var) { - if (!in_array($var, self::$watchKeys)) { - debug("NOT"); - return; - } - foreach (self::$watchKeys as $i => $key) { - if ($key == $var) { - unset(self::$watchKeys[$i]); - self::$watchKeys = array_values(self::$watchKeys); - return; - } - } - } - /** * Writes value to given session variable name. * @@ -443,6 +398,9 @@ class CakeSession { * @return boolean True if the write was successful, false if the write failed */ public static function write($name, $value = null) { + if (!self::started() && !self::start()) { + return false; + } if (empty($name)) { return false; } @@ -451,9 +409,6 @@ class CakeSession { $write = array($name => $value); } foreach ($write as $key => $val) { - if (in_array($key, self::$watchKeys)) { - trigger_error(__('Writing session key {%s}: %s', $key, Debugger::exportVar($val)), E_USER_NOTICE); - } self::__overwrite($_SESSION, Set::insert($_SESSION, $key, $val)); if (Set::classicExtract($_SESSION, $key) !== $val) { return false; @@ -492,7 +447,7 @@ class CakeSession { * Sessions can be configured with a few shortcut names as well as have any number of ini settings declared. * * @return void - * @throws Exception Throws exceptions when ini_set() fails. + * @throws CakeSessionException Throws exceptions when ini_set() fails. */ protected static function _configureSession() { $sessionConfig = Configure::read('Session'); @@ -524,7 +479,7 @@ class CakeSession { if (!empty($sessionConfig['ini']) && is_array($sessionConfig['ini'])) { foreach ($sessionConfig['ini'] as $setting => $value) { if (ini_set($setting, $value) === false) { - throw new Exception(sprintf( + throw new CakeSessionException(sprintf( __('Unable to configure the session, setting %s failed.'), $setting )); @@ -562,13 +517,13 @@ class CakeSession { App::import('Core', 'session/' . $class); } if (!class_exists($class)) { - throw new Exception(__('Could not load %s to handle the session.', $class)); + throw new CakeSessionException(__('Could not load %s to handle the session.', $class)); } $handler = new $class(); if ($handler instanceof CakeSessionHandlerInterface) { return $handler; } - throw new Exception(__('Chosen SessionHandler does not implement CakeSessionHandlerInterface it cannot be used with an engine key.')); + throw new CakeSessionException(__('Chosen SessionHandler does not implement CakeSessionHandlerInterface it cannot be used with an engine key.')); } /** @@ -671,6 +626,10 @@ class CakeSession { * @return void */ protected static function _checkValid() { + if (!self::started() && !self::start()) { + self::$valid = false; + return false; + } if (self::read('Config')) { $sessionConfig = Configure::read('Session'); diff --git a/cake/libs/cake_socket.php b/cake/libs/cake_socket.php index 3bcb7ca0a..82610ff92 100644 --- a/cake/libs/cake_socket.php +++ b/cake/libs/cake_socket.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 1.2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,8 +23,7 @@ App::import('Core', 'Validation'); * * Core base class for network communication. * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs */ class CakeSocket { @@ -100,6 +98,7 @@ class CakeSocket { * Connect the socket to the given host and port. * * @return boolean Success + * @throws SocketException */ public function connect() { if ($this->connection != null) { @@ -112,7 +111,6 @@ class CakeSocket { } if ($this->config['persistent'] == true) { - $tmp = null; $this->connection = @pfsockopen($scheme.$this->config['host'], $this->config['port'], $errNum, $errStr, $this->config['timeout']); } else { $this->connection = @fsockopen($scheme.$this->config['host'], $this->config['port'], $errNum, $errStr, $this->config['timeout']); @@ -120,6 +118,7 @@ class CakeSocket { if (!empty($errNum) || !empty($errStr)) { $this->setLastError($errStr, $errNum); + throw new SocketException($errStr, $errNum); } $this->connected = is_resource($this->connection); @@ -137,9 +136,8 @@ class CakeSocket { public function host() { if (Validation::ip($this->config['host'])) { return gethostbyaddr($this->config['host']); - } else { - return gethostbyaddr($this->address()); } + return gethostbyaddr($this->address()); } /** @@ -150,9 +148,8 @@ class CakeSocket { public function address() { if (Validation::ip($this->config['host'])) { return $this->config['host']; - } else { - return gethostbyname($this->config['host']); } + return gethostbyname($this->config['host']); } /** @@ -163,9 +160,8 @@ class CakeSocket { public function addresses() { if (Validation::ip($this->config['host'])) { return array($this->config['host']); - } else { - return gethostbynamel($this->config['host']); } + return gethostbynamel($this->config['host']); } /** @@ -176,9 +172,8 @@ class CakeSocket { public function lastError() { if (!empty($this->lastError)) { return $this->lastError['num'] . ': ' . $this->lastError['str']; - } else { - return null; } + return null; } /** @@ -186,6 +181,7 @@ class CakeSocket { * * @param integer $errNum Error code * @param string $errStr Error string + * @return void */ public function setLastError($errNum, $errStr) { $this->lastError = array('num' => $errNum, 'str' => $errStr); @@ -229,17 +225,8 @@ class CakeSocket { return false; } return $buffer; - } else { - return false; } - } - -/** - * Abort socket operation. - * - * @return boolean Success - */ - public function abort() { + return false; } /** @@ -272,6 +259,7 @@ class CakeSocket { /** * Resets the state of this Socket instance to it's initial state (before Object::__construct got executed) * + * @param array $state Array with key and values to reset * @return boolean True on success */ public function reset($state = null) { diff --git a/cake/libs/class_registry.php b/cake/libs/class_registry.php index 4e7b22c38..25659089f 100644 --- a/cake/libs/class_registry.php +++ b/cake/libs/class_registry.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 0.9.2 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -27,8 +26,7 @@ * If you try to add an object with the same key twice, nothing will come of it. * If you need a second instance of an object, give it another key. * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs */ class ClassRegistry { diff --git a/cake/libs/config/ini_file.php b/cake/libs/config/ini_file.php deleted file mode 100644 index 722dbcb08..000000000 --- a/cake/libs/config/ini_file.php +++ /dev/null @@ -1,101 +0,0 @@ -_values = $contents[$section]; - } else { - $this->_values = $contents; - } - } - -/** - * Get the contents of the ini file as a plain array. - * - * @return array - */ - public function asArray() { - return $this->_values; - } - -/** - * Part of ArrayAccess implementation. - * - * @param string $name - */ - public function offsetExists($name) { - return isset($this->_values[$name]); - } - -/** - * Part of ArrayAccess implementation. - * - * @param string $name - */ - public function offsetGet($name) { - if (!isset($this->_values[$name])) { - return null; - } - return $this->_values[$name]; - } - -/** - * Part of ArrayAccess implementation. - * - * @param string $name - */ - public function offsetSet($name, $value) { - throw new LogicException('You cannot modify an IniFile parse result.'); - } - -/** - * Part of ArrayAccess implementation. - * - * @param string $name - */ - public function offsetUnset($name) { - unset($this->_values[$name]); - } -} \ No newline at end of file diff --git a/cake/libs/config/ini_reader.php b/cake/libs/config/ini_reader.php new file mode 100644 index 000000000..915bf9498 --- /dev/null +++ b/cake/libs/config/ini_reader.php @@ -0,0 +1,108 @@ + array('password' => 'secret'))` + * + * You can nest properties as deeply as needed using .'s. IniReader also manipulates + * how the special ini values of 'yes', 'no', 'on', 'off', 'null' are handled. + * These values will be converted to their boolean equivalents. + * + * @package cake.config + * @see http://php.net/parse_ini_file + */ +class IniReader implements ConfigReaderInterface { + +/** + * The path to read ini files from. + * + * @var array + */ + protected $_path; + +/** + * The section to read, if null all sections will be read. + * + * @var string + */ + protected $_section; + +/** + * Build and construct a new ini file parser. The parser can be used to read + * ini files that are on the filesystem. + * + * @param string $path Path to load ini config files from. + * @param string $section Only get one section. + */ + public function __construct($path, $section = null) { + $this->_path = $path; + $this->_section = $section; + } + +/** + * Read an ini file and return the results as an array. + * + * @param string $file Name of the file to read. + * @return array + */ + public function read($file) { + $filename = $this->_path . $file; + $contents = parse_ini_file($filename, true); + if (!empty($this->_section) && isset($contents[$this->_section])) { + $values = $this->_parseNestedValues($contents[$this->_section]); + } else { + $values = array(); + foreach ($contents as $section => $attribs) { + $values[$section] = $this->_parseNestedValues($attribs); + } + } + return $values; + } + +/** + * parses nested values out of keys. + * + * @param array $values Values to be exploded. + * @return array Array of values exploded + */ + protected function _parseNestedValues($values) { + foreach ($values as $key => $value) { + if ($value === '1') { + $value = true; + } + if ($value === '') { + $value = false; + } + if (strpos($key, '.') !== false) { + $values = Set::insert($values, $key, $value); + } else { + $values[$key] = $value; + } + } + return $values; + } +} \ No newline at end of file diff --git a/cake/libs/config/php_reader.php b/cake/libs/config/php_reader.php new file mode 100644 index 000000000..c122f0808 --- /dev/null +++ b/cake/libs/config/php_reader.php @@ -0,0 +1,78 @@ + + * 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://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests + * @package cake.libs.config + * @since CakePHP(tm) v 2.0 + * @license MIT License (http://www.opensource.org/licenses/mit-license.php) + */ + +/** + * PHP Reader allows Configure to load configuration values from + * files containing simple PHP arrays. + * + * @package cake.libs.config + */ +class PhpReader implements ConfigReaderInterface { +/** + * The path this reader finds files on. + * + * @var string + */ + protected $_path = null; + +/** + * Constructor for PHP Config file reading. + * + * @param string $path The path to read config files from. Defaults to CONFIGS + */ + public function __construct($path = CONFIGS) { + $this->_path = $path; + } + +/** + * Read a config file and return its contents. + * + * Keys with `.` will be treated as values in plugins. Instead of reading from + * the initialized path, plugin keys will be located using App::pluginPath(). + * + * + * @param string $key The identifier to read from. If the key has a . it will be treated + * as a plugin prefix. + * @return array Parsed configuration values. + * @throws ConfigureException when files don't exist or they don't contain `$config`. + * Or when files contain '..' as this could lead to abusive reads. + */ + public function read($key) { + if (strpos($key, '..') !== false) { + throw new ConfigureException(__('Cannot load configuration files with ../ in them.')); + } + list($plugin, $key) = pluginSplit($key); + + if ($plugin) { + $file = App::pluginPath($plugin) . 'config' . DS . $key . '.php'; + } else { + $file = $this->_path . $key . '.php'; + } + if (!file_exists($file)) { + throw new ConfigureException(__('Could not load configuration file: ') . $file); + } + include $file; + if (!isset($config)) { + throw new ConfigureException( + sprintf(__('No variable $config found in %s.php'), $file) + ); + } + return $config; + } +} \ No newline at end of file diff --git a/cake/libs/configure.php b/cake/libs/configure.php index 76cffb12d..1546ae087 100644 --- a/cake/libs/configure.php +++ b/cake/libs/configure.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 1.0.0.2363 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,8 +24,7 @@ * as methods for loading additional configuration files or storing runtime configuration * for future use. * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @link http://book.cakephp.org/view/924/The-Configuration-Class */ class Configure { @@ -40,6 +38,14 @@ class Configure { 'debug' => 0 ); +/** + * Configured reader classes, used to load config files from resources + * + * @var array + * @see Configure::load() + */ + protected static $_readers = array(); + /** * Initializes configure and runs the bootstrap process. * Bootstrapping includes the following steps: @@ -55,13 +61,19 @@ class Configure { */ public static function bootstrap($boot = true) { if ($boot) { - self::write('App', array('base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => WEBROOT_DIR, 'www_root' => WWW_ROOT)); + self::write('App', array( + 'base' => false, + 'baseUrl' => false, + 'dir' => APP_DIR, + 'webroot' => WEBROOT_DIR, + 'www_root' => WWW_ROOT + )); if (!include(CONFIGS . 'core.php')) { trigger_error(__("Can't find application core file. Please create %score.php, and make sure it is readable by PHP.", CONFIGS), E_USER_ERROR); } - if (Configure::read('Cache.disable') !== true) { + if (empty(self::$_values['Cache']['disable'])) { $cache = Cache::config('default'); if (empty($cache['settings'])) { @@ -76,7 +88,7 @@ class Configure { $prefix = $cache['settings']['prefix']; } - if (Configure::read('debug') >= 1) { + if (self::$_values['debug'] >= 1) { $duration = '+10 seconds'; } else { $duration = '+999 days'; @@ -167,13 +179,11 @@ class Configure { } } - if (isset($config['debug']) || isset($config['log'])) { - if (function_exists('ini_set')) { - if (self::$_values['debug']) { - ini_set('display_errors', 1); - } else { - ini_set('display_errors', 0); - } + if (isset($config['debug']) && function_exists('ini_set')) { + if (self::$_values['debug']) { + ini_set('display_errors', 1); + } else { + ini_set('display_errors', 0); } } return true; @@ -250,59 +260,77 @@ class Configure { } /** - * Loads a file from app/config/configure_file.php. + * Add a new reader to Configure. Readers allow you to read configuration + * files in various formats/storage locations. CakePHP comes with two built-in readers + * PhpReader and IniReader. You can also implement your own reader classes in your application. * - * Config file variables should be formated like: - * `$config['name'] = 'value';` - * These will be used to create dynamic Configure vars. load() is also used to - * load stored config files created with Configure::store() + * To add a new reader to Configure: * - * - To load config files from app/config use `Configure::load('configure_file');`. - * - To load config files from a plugin `Configure::load('plugin.configure_file');`. + * `Configure::config('ini', new IniReader());` + * + * @param string $name The name of the reader being configured. This alias is used later to + * read values from a specific reader. + * @param ConfigReaderInterface $reader The reader to append. + * @return void + */ + public static function config($name, ConfigReaderInterface $reader) { + self::$_readers[$name] = $reader; + } + +/** + * Gets the names of the configured reader objects. + * + * @return array Array of the configured reader objects. + */ + public static function configured($name = null) { + if ($name) { + return isset(self::$_readers[$name]); + } + return array_keys(self::$_readers); + } + +/** + * Remove a configured reader. This will unset the reader + * and make any future attempts to use it cause an Exception. + * + * @param string $name Name of the reader to drop. + * @return boolean Success + */ + public static function drop($name) { + if (!isset(self::$_readers[$name])) { + return false; + } + unset(self::$_readers[$name]); + return true; + } + +/** + * Loads stored configuration information from a resource. You can add + * config file resource readers with `Configure::config()`. + * + * Loaded configuration infomration will be merged with the current + * runtime configuration. You can load configuration files from plugins + * by preceeding the filename with the plugin name. + * + * `Configure::load('Users.user', 'default')` + * + * Would load the 'user' config file using the default config reader. You can load + * app config files by giving the name of the resource you want loaded. + * + * `Configure::load('setup', 'default');` * * @link http://book.cakephp.org/view/929/load - * @param string $fileName name of file to load, extension must be .php and only the name - * should be used, not the extenstion - * @return mixed false if file not found, void if load successful + * @param string $key name of configuration resource to load. + * @param string $config Name of the configured reader to use to read the resource identfied by $key. + * @return mixed false if file not found, void if load successful. + * @throws ConfigureException Will throw any exceptions the reader raises. */ - public static function load($fileName) { - $found = $plugin = $pluginPath = false; - list($plugin, $fileName) = pluginSplit($fileName); - if ($plugin) { - $pluginPath = App::pluginPath($plugin); - } - $pos = strpos($fileName, '..'); - - if ($pos === false) { - if ($pluginPath && file_exists($pluginPath . 'config' . DS . $fileName . '.php')) { - include($pluginPath . 'config' . DS . $fileName . '.php'); - $found = true; - } elseif (file_exists(CONFIGS . $fileName . '.php')) { - include(CONFIGS . $fileName . '.php'); - $found = true; - } elseif (file_exists(CACHE . 'persistent' . DS . $fileName . '.php')) { - include(CACHE . 'persistent' . DS . $fileName . '.php'); - $found = true; - } else { - foreach (App::core('cake') as $key => $path) { - if (file_exists($path . DS . 'config' . DS . $fileName . '.php')) { - include($path . DS . 'config' . DS . $fileName . '.php'); - $found = true; - break; - } - } - } - } - - if (!$found) { + public static function load($key, $config = 'default') { + if (!isset(self::$_readers[$config])) { return false; } - - if (!isset($config)) { - trigger_error(__('Configure::load() - no variable $config found in %s.php', $fileName), E_USER_WARNING); - return false; - } - return self::write($config); + $values = self::$_readers[$config]->read($key); + return self::write($values); } /** @@ -322,62 +350,52 @@ class Configure { } /** - * Used to write a config file to disk. + * Used to write runtime configuration into Cache. Stored runtime configuration can be + * restored using `Configure::restore()`. These methods can be used to enable configuration managers + * frontends, or other GUI type interfaces for configuration. * - * {{{ - * Configure::store('Model', 'class_paths', array('Users' => array( - * 'path' => 'users', 'plugin' => true - * ))); - * }}} - * - * @param string $type Type of config file to write, ex: Models, Controllers, Helpers, Components - * @param string $name file name. - * @param array $data array of values to store. - * @return void + * @param string $name The storage name for the saved configuration. + * @param string $cacheConfig The cache configuration to save into. Defaults to 'default' + * @param array $data Either an array of data to store, or leave empty to store all values. + * @return boolean Success */ - public static function store($type, $name, $data = array()) { - $write = true; - $content = ''; - - foreach ($data as $key => $value) { - $content .= "\$config['$type']['$key'] = " . var_export($value, true) . ";\n"; + public static function store($name, $cacheConfig = 'default', $data = null) { + if ($data === null) { + $data = self::$_values; } - if (is_null($type)) { - $write = false; - } - self::__writeConfig($content, $name, $write); + return Cache::write($name, $data, $cacheConfig); } /** - * Creates a cached version of a configuration file. - * Appends values passed from Configure::store() to the cached file + * Restores configuration data stored in the Cache into configure. Restored + * values will overwrite existing ones. * - * @param string $content Content to write on file - * @param string $name Name to use for cache file - * @param boolean $write true if content should be written, false otherwise - * @return void - * @access private + * @param string $name Name of the stored config file to load. + * @param string $cacheConfig Name of the Cache configuration to read from. + * @return boolean Success. */ - private static function __writeConfig($content, $name, $write = true) { - $file = CACHE . 'persistent' . DS . $name . '.php'; - - if (self::read('debug') > 0) { - $expires = "+10 seconds"; - } else { - $expires = "+999 days"; - } - $cache = cache('persistent' . DS . $name . '.php', null, $expires); - - if ($cache === null) { - cache('persistent' . DS . $name . '.php', "isWritable()) { - $fileClass->fwrite($content); - } + public static function restore($name, $cacheConfig = 'default') { + $values = Cache::read($name, $cacheConfig); + if ($values) { + return self::write($values); } + return false; } +} +/** + * An interface for creating objects compatible with Configure::load() + * + * @package cake.libs + */ +interface ConfigReaderInterface { +/** + * Read method is used for reading configuration information from sources. + * These sources can either be static resources like files, or dynamic ones like + * a database, or other datasource. + * + * @param string $key + * @return array An array of data to merge into the runtime configuration + */ + function read($key); } \ No newline at end of file diff --git a/cake/libs/controller/app_controller.php b/cake/libs/controller/app_controller.php index c8423a41b..07c117dff 100644 --- a/cake/libs/controller/app_controller.php +++ b/cake/libs/controller/app_controller.php @@ -15,8 +15,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.controller + * @package cake.libs.controller * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -28,8 +27,7 @@ * Add your application-wide methods in the class below, your controllers * will inherit them. * - * @package cake - * @subpackage cake.cake.libs.controller + * @package cake.libs.controller * @link http://book.cakephp.org/view/957/The-App-Controller */ class AppController extends Controller { diff --git a/cake/libs/controller/cake_error_controller.php b/cake/libs/controller/cake_error_controller.php index 443024840..f55649672 100644 --- a/cake/libs/controller/cake_error_controller.php +++ b/cake/libs/controller/cake_error_controller.php @@ -4,8 +4,7 @@ * * Controller used by ErrorHandler to render error views. * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs */ class CakeErrorController extends AppController { public $name = 'CakeError'; diff --git a/cake/libs/controller/component.php b/cake/libs/controller/component.php index c0d4b57a6..f55840d1f 100644 --- a/cake/libs/controller/component.php +++ b/cake/libs/controller/component.php @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.controller + * @package cake.libs.controller * @since CakePHP(tm) v 1.2 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -35,8 +34,7 @@ App::import('Controller', 'ComponentCollection', false); * but before Controller::afterFilter(). * - `beforeRedirect()` - Fired before a redirect() is done. * - * @package cake - * @subpackage cake.cake.libs.controller + * @package cake.libs.controller * @link http://book.cakephp.org/view/993/Components * @see Controller::$components */ @@ -108,7 +106,7 @@ class Component extends Object { * @return void * @link http://book.cakephp.org/view/998/MVC-Class-Access-Within-Components */ - public function initialize(&$controller) { } + public function initialize($controller) { } /** * Called after the Controller::beforeFilter() and before the controller action @@ -117,7 +115,7 @@ class Component extends Object { * @return void * @link http://book.cakephp.org/view/998/MVC-Class-Access-Within-Components */ - public function startup(&$controller) { } + public function startup($controller) { } /** * Called after the Controller::beforeRender(), after the view class is loaded, and before the @@ -126,7 +124,7 @@ class Component extends Object { * @param object $controller Controller with components to beforeRender * @return void */ - public function beforeRender(&$controller) { } + public function beforeRender($controller) { } /** * Called after Controller::render() and before the output is printed to the browser. @@ -134,7 +132,7 @@ class Component extends Object { * @param object $controller Controller with components to shutdown * @return void */ - function shutdown(&$controller) { } + function shutdown($controller) { } /** * Called before Controller::redirect(). Allows you to replace the url that will @@ -154,6 +152,6 @@ class Component extends Object { * @param bool $exit Will the script exit. * @return mixed Either an array or null. */ - public function beforeRedirect(&$controller, $url, $status = null, $exit = true) {} + public function beforeRedirect($controller, $url, $status = null, $exit = true) {} } diff --git a/cake/libs/controller/component_collection.php b/cake/libs/controller/component_collection.php index 90ec17f17..3d9e23c47 100644 --- a/cake/libs/controller/component_collection.php +++ b/cake/libs/controller/component_collection.php @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.libs.controller + * @package cake.libs.controller * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -78,7 +77,7 @@ class ComponentCollection extends ObjectCollection { )); } if (!class_exists($componentClass)) { - throw new MissingComponentFileException(array( + throw new MissingComponentClassException(array( 'file' => Inflector::underscore($component) . '.php', 'class' => $componentClass )); diff --git a/cake/libs/controller/components/acl.php b/cake/libs/controller/components/acl.php index a8d811d3d..6795ab335 100644 --- a/cake/libs/controller/components/acl.php +++ b/cake/libs/controller/components/acl.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.controller.components + * @package cake.libs.controller.components * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -27,8 +26,7 @@ * You can define by changing `Configure::write('Acl.classname', 'DbAcl');` in your core.php. Concrete ACL * implementations should extend `AclBase` and implement the methods it defines. * - * @package cake - * @subpackage cake.cake.libs.controller.components + * @package cake.libs.controller.components * @link http://book.cakephp.org/view/1242/Access-Control-Lists */ class AclComponent extends Component { @@ -58,7 +56,7 @@ class AclComponent extends Component { /** * Constructor. Will return an instance of the correct ACL class as defined in `Configure::read('Acl.classname')` * - * @throws Exception when Acl.classname could not be loaded. + * @throws CakeException when Acl.classname could not be loaded. */ public function __construct(ComponentCollection $collection, $settings = array()) { parent::__construct($collection, $settings); @@ -68,7 +66,7 @@ class AclComponent extends Component { list($plugin, $name) = pluginSplit($name); $name .= 'Component'; } else { - throw new Exception(__('Could not find %s.', $name)); + throw new CakeException(__('Could not find %s.', $name)); } } $this->adapter($name); @@ -84,7 +82,7 @@ class AclComponent extends Component { * * @param mixed $adapter Instance of AclBase or a string name of the class to use. (optional) * @return mixed either null, or instance of AclBase - * @throws Exception when the given class is not an AclBase + * @throws CakeException when the given class is not an AclBase */ public function adapter($adapter = null) { if ($adapter) { @@ -92,7 +90,7 @@ class AclComponent extends Component { $adapter = new $adapter(); } if (!$adapter instanceof AclInterface) { - throw new Exception(__('AclComponent adapters must implement AclInterface')); + throw new CakeException(__('AclComponent adapters must implement AclInterface')); } $this->_Instance = $adapter; $this->_Instance->initialize($this); @@ -186,8 +184,7 @@ class AclComponent extends Component { * Access Control List interface. * Implementing classes are used by AclComponent to perform ACL checks in Cake. * - * @package cake - * @subpackage cake.cake.libs.controller.components + * @package cake.libs.controller.components */ interface AclInterface { @@ -255,8 +252,7 @@ interface AclInterface { * edit * }}} * - * @package cake - * @subpackage cake.cake.libs.model + * @package cake.libs.model */ class DbAcl extends Object implements AclInterface { @@ -525,8 +521,7 @@ class DbAcl extends Object implements AclInterface { * IniAcl implements an access control system using an INI file. An example * of the ini file used can be found in /config/acl.ini.php. * - * @package cake - * @subpackage cake.cake.libs.model.iniacl + * @package cake.libs.model.iniacl */ class IniAcl extends Object implements AclInterface { @@ -662,9 +657,9 @@ class IniAcl extends Object implements AclInterface { * @return array INI section structure */ public function readConfigFile($filename) { - App::import('Core', 'config/IniFile'); - $iniFile = new IniFile($filename); - return $iniFile->asArray(); + App::import('Core', 'config/IniReader'); + $iniFile = new IniReader(dirname($filename) . DS); + return $iniFile->read(basename($filename)); } /** diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index a075f4fcf..063960f91 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.controller.components + * @package cake.libs.controller.components * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -28,8 +27,7 @@ App::import('Core', 'Security', false); * * Binds access control with user authentication and session management. * - * @package cake - * @subpackage cake.cake.libs.controller.components + * @package cake.libs.controller.components * @link http://book.cakephp.org/view/1250/Authentication */ class AuthComponent extends Component { @@ -262,7 +260,7 @@ class AuthComponent extends Component { * @param object $controller A reference to the instantiating controller object * @return void */ - public function initialize(Controller $controller, $settings = array()) { + public function initialize($controller) { $this->request = $controller->request; $this->params = $this->request; @@ -299,7 +297,7 @@ class AuthComponent extends Component { * @param object $controller A reference to the instantiating controller object * @return boolean */ - public function startup(&$controller) { + public function startup($controller) { $isErrorOrTests = ( strtolower($controller->name) == 'cakeerror' || (strtolower($controller->name) == 'tests' && Configure::read('debug') > 0) @@ -926,7 +924,7 @@ class AuthComponent extends Component { * * @param object $controller Instantiating controller */ - public function shutdown(&$controller) { + public function shutdown($controller) { if ($this->_loggedIn) { $this->Session->delete('Auth.redirect'); } diff --git a/cake/libs/controller/components/cookie.php b/cake/libs/controller/components/cookie.php index bff3b7137..87fb4a802 100644 --- a/cake/libs/controller/components/cookie.php +++ b/cake/libs/controller/components/cookie.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.controller.components + * @package cake.libs.controller.components * @since CakePHP(tm) v 1.2.0.4213 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -28,8 +27,7 @@ App::import('Core', 'Security'); * * Cookie handling for the controller. * - * @package cake - * @subpackage cake.cake.libs.controller.components + * @package cake.libs.controller.components * @link http://book.cakephp.org/view/1280/Cookies * */ @@ -182,7 +180,7 @@ class CookieComponent extends Component { * Start CookieComponent for use in the controller * */ - public function startup() { + public function startup($controller) { $this->_expire($this->time); if (isset($_COOKIE[$this->name])) { @@ -193,7 +191,7 @@ class CookieComponent extends Component { /** * Write a value to the $_COOKIE[$key]; * - * Optional [Name.], reguired key, optional $value, optional $encrypt, optional $expires + * Optional [Name.], required key, optional $value, optional $encrypt, optional $expires * $this->Cookie->write('[Name.]key, $value); * * By default all values are encrypted. @@ -222,7 +220,6 @@ class CookieComponent extends Component { if (strpos($name, '.') === false) { $this->_values[$name] = $value; $this->_write("[$name]", $value); - } else { $names = explode('.', $name, 2); if (!isset($this->_values[$names[0]])) { @@ -238,7 +235,7 @@ class CookieComponent extends Component { /** * Read the value of the $_COOKIE[$key]; * - * Optional [Name.], reguired key + * Optional [Name.], required key * $this->Cookie->read(Name.key); * * @param mixed $key Key of the value to be obtained. If none specified, obtain map key => values @@ -252,7 +249,7 @@ class CookieComponent extends Component { if (is_null($key)) { return $this->_values; } - + if (strpos($key, '.') !== false) { $names = explode('.', $key, 2); $key = $names[0]; @@ -270,7 +267,7 @@ class CookieComponent extends Component { /** * Delete a cookie value * - * Optional [Name.], reguired key + * Optional [Name.], required key * $this->Cookie->read('Name.key); * * You must use this method before any output is sent to the browser. @@ -348,11 +345,11 @@ class CookieComponent extends Component { return $this->_expires; } $this->_reset = $this->_expires; - + if ($expires == 0) { return $this->_expires = 0; } - + if (is_integer($expires) || is_numeric($expires)) { return $this->_expires = $now + intval($expires); } @@ -433,7 +430,7 @@ class CookieComponent extends Component { $decrypted = array(); $type = $this->_type; - foreach ($values as $name => $value) { + foreach ((array)$values as $name => $value) { if (is_array($value)) { foreach ($value as $key => $val) { $pos = strpos($val, 'Q2FrZQ==.'); diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index a4cb6dd02..031ef8543 100755 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.controller.components + * @package cake.libs.controller.components * @since CakePHP(tm) v 1.2.0.3467 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,8 +24,7 @@ App::import('Core', 'Multibyte'); * This component is used for handling Internet Message Format based * based on the standard outlined in http://www.rfc-editor.org/rfc/rfc2822.txt * - * @package cake - * @subpackage cake.cake.libs.controller.components + * @package cake.libs.controller.components * @link http://book.cakephp.org/view/1283/Email * */ @@ -97,6 +95,15 @@ class EmailComponent extends Component { */ public $bcc = array(); +/** + * The date to put in the Date: header. This should be a date + * conformant with the RFC2822 standard. Leave null, to have + * today's date generated. + * + * @var string + */ + var $date = null; + /** * The subject of the email * @@ -148,6 +155,18 @@ class EmailComponent extends Component { */ public $lineLength = 70; +/** + * Line feed character(s) to be used when sending using mail() function + * If null PHP_EOL is used. + * RFC2822 requires it to be CRLF but some Unix + * mail transfer agents replace LF by CRLF automatically + * (which leads to doubling CR if CRLF is used). + * + * @var string + * @access public + */ + var $lineFeed = null; + /** * @deprecated see lineLength */ @@ -261,6 +280,9 @@ class EmailComponent extends Component { * it be handled by sendmail (or similar) or a string * to completely override the Message-ID. * + * If you are sending Email from a shell, be sure to set this value. As you + * could encounter delivery issues if you do not. + * * @var mixed * @access public */ @@ -314,7 +336,7 @@ class EmailComponent extends Component { * * @param object $controller Instantiating controller */ - public function initialize(&$controller) { + public function initialize($controller) { if (Configure::read('App.encoding') !== null) { $this->charset = Configure::read('App.encoding'); } @@ -325,7 +347,7 @@ class EmailComponent extends Component { * * @param object $controller Instantiating controller */ - public function startup(&$controller) {} + public function startup($controller) {} /** * Send an email using the specified content, template and layout @@ -412,6 +434,7 @@ class EmailComponent extends Component { $this->bcc = array(); $this->subject = null; $this->additionalParams = null; + $this->date = null; $this->smtpError = null; $this->attachments = array(); $this->htmlMessage = null; @@ -576,6 +599,12 @@ class EmailComponent extends Component { } } + $date = $this->date; + if ($date == false) { + $date = date(DATE_RFC2822); + } + $headers['Date'] = $date; + $headers['X-Mailer'] = $this->xMailer; if (!empty($this->headers)) { @@ -790,8 +819,13 @@ class EmailComponent extends Component { * @access private */ function _mail() { - $header = implode("\r\n", $this->_header); - $message = implode("\r\n", $this->_message); + if ($this->lineFeed === null) { + $lineFeed = PHP_EOL; + } else { + $lineFeed = $this->lineFeed; + } + $header = implode($lineFeed, $this->_header); + $message = implode($lineFeed, $this->_message); if (is_array($this->to)) { $to = implode(', ', array_map(array($this, '_formatAddress'), $this->to)); } else { @@ -861,7 +895,7 @@ class EmailComponent extends Component { } if (!is_array($this->to)) { - $tos = array($this->to); + $tos = array_map('trim', explode(',', $this->to)); } else { $tos = $this->to; } diff --git a/cake/libs/controller/components/paginator.php b/cake/libs/controller/components/paginator.php new file mode 100644 index 000000000..5c0c4b940 --- /dev/null +++ b/cake/libs/controller/components/paginator.php @@ -0,0 +1,379 @@ +Paginator->settings = array( + * 'limit' => 20, + * 'maxLimit' => 100 + * ); + * }}} + * + * The above settings will be used to paginate any model. You can configure model specific settings by + * keying the settings with the model name. + * + * {{{ + * $this->Paginator->settings = array( + * 'Post' => array( + * 'limit' => 20, + * 'maxLimit' => 100 + * ), + * 'Comment' => array( ... ) + * ); + * }}} + * + * This would allow you to have different pagination settings for `Comment` and `Post` models. + * + * @package cake.libs.controller.components + */ +class PaginatorComponent extends Component { + +/** + * Pagination settings. These settings control pagination at a general level. + * You can also define sub arrays for pagination settings for specific models. + * + * - `maxLimit` The maximum limit users can choose to view. Defaults to 100 + * - `limit` The initial number of items per page. Defaults to 20. + * - `page` The starting page, defaults to 1. + * - `paramType` What type of parameters you want pagination to use? + * - `named` Use named parameters / routed parameters. + * - `querystring` Use query string parameters. + * + * @var array + */ + public $settings = array( + 'page' => 1, + 'limit' => 20, + 'maxLimit' => 100, + 'paramType' => 'named' + ); + +/** + * A list of parameters users are allowed to set using request parameters. Modifying + * this list will allow users to have more influence over pagination, + * be careful with what you permit. + * + * @var array + */ + public $whitelist = array( + 'limit', 'sort', 'page', 'direction' + ); + +/** + * Constructor + * + * @param ComponentCollection $collection A ComponentCollection this component can use to lazy load its components + * @param array $settings Array of configuration settings. + */ + public function __construct(ComponentCollection $collection, $settings = array()) { + $settings = array_merge($this->settings, (array)$settings); + $this->Controller = $collection->getController(); + parent::__construct($collection, $settings); + } + +/** + * Handles automatic pagination of model records. + * + * @param mixed $object Model to paginate (e.g: model instance, or 'Model', or 'Model.InnerModel') + * @param mixed $scope Additional find conditions to use while paginating + * @param array $whitelist List of allowed fields for ordering. This allows you to prevent ordering + * on non-indexed, or undesirable columns. + * @return array Model query results + */ + public function paginate($object = null, $scope = array(), $whitelist = array()) { + if (is_array($object)) { + $whitelist = $scope; + $scope = $object; + $object = null; + } + + $object = $this->_getObject($object); + + if (!is_object($object)) { + throw new MissingModelException($object); + } + + $options = $this->mergeOptions($object->alias); + $options = $this->validateSort($object, $options, $whitelist); + $options = $this->checkLimit($options); + + $conditions = $fields = $order = $limit = $page = $recursive = null; + + if (!isset($options['conditions'])) { + $options['conditions'] = array(); + } + + $type = 'all'; + + if (isset($options[0])) { + $type = $options[0]; + unset($options[0]); + } + + extract($options); + + if (is_array($scope) && !empty($scope)) { + $conditions = array_merge($conditions, $scope); + } elseif (is_string($scope)) { + $conditions = array($conditions, $scope); + } + if ($recursive === null) { + $recursive = $object->recursive; + } + + $extra = array_diff_key($options, compact( + 'conditions', 'fields', 'order', 'limit', 'page', 'recursive' + )); + if ($type !== 'all') { + $extra['type'] = $type; + } + + if ($object->hasMethod('paginateCount')) { + $count = $object->paginateCount($conditions, $recursive, $extra); + } else { + $parameters = compact('conditions'); + if ($recursive != $object->recursive) { + $parameters['recursive'] = $recursive; + } + $count = $object->find('count', array_merge($parameters, $extra)); + } + $pageCount = intval(ceil($count / $limit)); + + if ($page === 'last' || $page >= $pageCount) { + $options['page'] = $page = $pageCount; + } elseif (intval($page) < 1) { + $options['page'] = $page = 1; + } + $page = $options['page'] = (int)$page; + + if ($object->hasMethod('paginate')) { + $results = $object->paginate( + $conditions, $fields, $order, $limit, $page, $recursive, $extra + ); + } else { + $parameters = compact('conditions', 'fields', 'order', 'limit', 'page'); + if ($recursive != $object->recursive) { + $parameters['recursive'] = $recursive; + } + $results = $object->find($type, array_merge($parameters, $extra)); + } + $defaults = $this->getDefaults($object->alias); + unset($defaults[0]); + + $paging = array( + 'page' => $page, + 'current' => count($results), + 'count' => $count, + 'prevPage' => ($page > 1), + 'nextPage' => ($count > ($page * $limit)), + 'pageCount' => $pageCount, + 'order' => $order, + 'limit' => $limit, + 'options' => Set::diff($options, $defaults), + 'paramType' => $options['paramType'] + ); + if (!isset($this->Controller->request['paging'])) { + $this->Controller->request['paging'] = array(); + } + $this->Controller->request['paging'] = array_merge( + (array)$this->Controller->request['paging'], + array($object->alias => $paging) + ); + + if ( + !in_array('Paginator', $this->Controller->helpers) && + !array_key_exists('Paginator', $this->Controller->helpers) + ) { + $this->Controller->helpers[] = 'Paginator'; + } + return $results; + } + +/** + * Get the object pagination will occur on. + * + * @param mixed $object The object you are looking for. + * @return mixed The model object to paginate on. + */ + protected function _getObject($object) { + if (is_string($object)) { + $assoc = null; + if (strpos($object, '.') !== false) { + list($object, $assoc) = pluginSplit($object); + } + + if ($assoc && isset($this->Controller->{$object}->{$assoc})) { + $object = $this->Controller->{$object}->{$assoc}; + } elseif ( + $assoc && isset($this->Controller->{$this->Controller->modelClass}) && + isset($this->Controller->{$this->Controller->modelClass}->{$assoc} + )) { + $object = $this->Controller->{$this->Controller->modelClass}->{$assoc}; + } elseif (isset($this->Controller->{$object})) { + $object = $this->Controller->{$object}; + } elseif ( + isset($this->Controller->{$this->Controller->modelClass}) && isset($this->Controller->{$this->Controller->modelClass}->{$object} + )) { + $object = $this->Controller->{$this->Controller->modelClass}->{$object}; + } + } elseif (empty($object) || $object === null) { + if (isset($this->Controller->{$this->Controller->modelClass})) { + $object = $this->Controller->{$this->Controller->modelClass}; + } else { + $className = null; + $name = $this->Controller->uses[0]; + if (strpos($this->Controller->uses[0], '.') !== false) { + list($name, $className) = explode('.', $this->Controller->uses[0]); + } + if ($className) { + $object = $this->Controller->{$className}; + } else { + $object = $this->Controller->{$name}; + } + } + } + return $object; + } + +/** + * Merges the various options that Pagination uses. + * Pulls settings together from the following places: + * + * - General pagination settings + * - Model specific settings. + * - Request parameters + * + * The result of this method is the aggregate of all the option sets combined together. You can change + * PaginatorComponent::$whitelist to modify which options/values can be set using request parameters. + * + * @param string $alias Model alias being paginated, if the general settings has a key with this value + * that key's settings will be used for pagination instead of the general ones. + * @return array Array of merged options. + */ + public function mergeOptions($alias) { + $defaults = $this->getDefaults($alias); + switch ($defaults['paramType']) { + case 'named': + $request = $this->Controller->request->params['named']; + break; + case 'querystring': + $request = $this->Controller->request->query; + break; + } + $request = array_intersect_key($request, array_flip($this->whitelist)); + return array_merge($defaults, $request); + } + +/** + * Get the default settings for a $model. If there are no settings for a specific model, the general settings + * will be used. + * + * @param string $alias Model name to get default settings for. + * @return array An array of pagination defaults for a model, or the general settings. + */ + public function getDefaults($alias) { + if (isset($this->settings[$alias])) { + $defaults = $this->settings[$alias]; + } else { + $defaults = $this->settings; + } + return array_merge( + array('page' => 1, 'limit' => 20, 'maxLimit' => 100, 'paramType' => 'named'), + $defaults + ); + } + +/** + * Validate that the desired sorting can be performed on the $object. Only fields or + * virtualFields can be sorted on. The direction param will also be sanitized. Lastly + * sort + direction keys will be converted into the model friendly order key. + * + * You can use the whitelist parameter to control which columns/fields are available for sorting. + * This helps prevent users from ordering large result sets on un-indexed values. + * + * @param Model $object The model being paginated. + * @param array $options The pagination options being used for this request. + * @param array $whitelist The list of columns that can be used for sorting. If empty all keys are allowed. + * @return array An array of options with sort + direction removed and replaced with order if possible. + */ + public function validateSort($object, $options, $whitelist = array()) { + if (isset($options['sort'])) { + $direction = null; + if (isset($options['direction'])) { + $direction = strtolower($options['direction']); + } + if ($direction != 'asc' && $direction != 'desc') { + $direction = 'asc'; + } + $options['order'] = array($options['sort'] => $direction); + } + + if (!empty($whitelist)) { + $field = key($options['order']); + if (!in_array($field, $whitelist)) { + $options['order'] = null; + } + } + + if (!empty($options['order']) && is_array($options['order'])) { + $alias = $object->alias ; + $key = $field = key($options['order']); + + if (strpos($key, '.') !== false) { + list($alias, $field) = explode('.', $key); + } + $value = $options['order'][$key]; + unset($options['order'][$key]); + + if ($object->hasField($field)) { + $options['order'][$alias . '.' . $field] = $value; + } elseif ($object->hasField($field, true)) { + $options['order'][$field] = $value; + } elseif (isset($object->{$alias}) && $object->{$alias}->hasField($field)) { + $options['order'][$alias . '.' . $field] = $value; + } + } + + return $options; + } + +/** + * Check the limit parameter and ensure its within the maxLimit bounds. + * + * @param array $options An array of options with a limit key to be checked. + * @return array An array of options for pagination + */ + public function checkLimit($options) { + $options['limit'] = (int) $options['limit']; + if (empty($options['limit']) || $options['limit'] < 1) { + $options['limit'] = 1; + } + $options['limit'] = min((int)$options['limit'], $options['maxLimit']); + return $options; + } +} \ No newline at end of file diff --git a/cake/libs/controller/components/request_handler.php b/cake/libs/controller/components/request_handler.php index b68e5e33e..3889f716c 100644 --- a/cake/libs/controller/components/request_handler.php +++ b/cake/libs/controller/components/request_handler.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.controller.components + * @package cake.libs.controller.components * @since CakePHP(tm) v 0.10.4.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ /** * Request object for handling HTTP requests * - * @package cake - * @subpackage cake.cake.libs.controller.components + * @package cake.libs.controller.components * @link http://book.cakephp.org/view/1291/Request-Handling * */ @@ -118,7 +116,7 @@ class RequestHandlerComponent extends Component { * @return void * @see Router::parseExtensions() */ - public function initialize(&$controller, $settings = array()) { + public function initialize($controller, $settings = array()) { $this->request = $controller->request; $this->response = $controller->response; if (isset($this->request->params['url']['ext'])) { @@ -156,7 +154,7 @@ class RequestHandlerComponent extends Component { * @param object $controller A reference to the controller * @return void */ - public function startup(&$controller) { + public function startup($controller) { $controller->request->params['isAjax'] = $this->request->is('ajax'); $isRecognized = ( !in_array($this->ext, array('html', 'htm')) && @@ -194,7 +192,7 @@ class RequestHandlerComponent extends Component { * @param mixed $url A string or array containing the redirect location * @param mixed HTTP Status for redirect */ - public function beforeRedirect(&$controller, $url, $status = null) { + public function beforeRedirect($controller, $url, $status = null, $exit = true) { if (!$this->request->is('ajax')) { return; } @@ -509,7 +507,7 @@ class RequestHandlerComponent extends Component { * @see RequestHandlerComponent::setContent() * @see RequestHandlerComponent::respondAs() */ - public function renderAs(&$controller, $type, $options = array()) { + public function renderAs($controller, $type, $options = array()) { $defaults = array('charset' => 'UTF-8'); if (Configure::read('App.encoding') !== null) { diff --git a/cake/libs/controller/components/security.php b/cake/libs/controller/components/security.php index 49632a1c6..daf0bc8bb 100644 --- a/cake/libs/controller/components/security.php +++ b/cake/libs/controller/components/security.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.controller.components + * @package cake.libs.controller.components * @since CakePHP(tm) v 0.10.8.2156 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ App::import('Core', 'Security', false); /** * SecurityComponent * - * @package cake - * @subpackage cake.cake.libs.controller.components + * @package cake.libs.controller.components * @link http://book.cakephp.org/view/1296/Security-Component */ class SecurityComponent extends Component { @@ -211,7 +209,7 @@ class SecurityComponent extends Component { * @param object $controller Instantiating controller * @return void */ - public function startup(&$controller) { + public function startup($controller) { $this->request = $controller->request; $this->_action = strtolower($this->request->params['action']); $this->_methodsRequired($controller); @@ -319,7 +317,6 @@ class SecurityComponent extends Component { } $this->loginOptions = array_merge($base, $this->loginOptions); $this->_requireMethod('Login', $args); - if (isset($this->loginOptions['users'])) { $this->loginUsers =& $this->loginOptions['users']; } @@ -441,7 +438,7 @@ class SecurityComponent extends Component { * @see SecurityComponent::$blackHoleCallback * @link http://book.cakephp.org/view/1307/blackHole-object-controller-string-error */ - function blackHole(&$controller, $error = '') { + function blackHole($controller, $error = '') { if ($this->blackHoleCallback == null) { $code = 404; if ($error == 'login') { @@ -474,7 +471,7 @@ class SecurityComponent extends Component { * @param object $controller Instantiating controller * @return bool true if $method is required */ - protected function _methodsRequired(&$controller) { + protected function _methodsRequired($controller) { foreach (array('Post', 'Get', 'Put', 'Delete') as $method) { $property = 'require' . $method; if (is_array($this->$property) && !empty($this->$property)) { @@ -497,7 +494,7 @@ class SecurityComponent extends Component { * @param object $controller Instantiating controller * @return bool true if secure connection required */ - protected function _secureRequired(&$controller) { + protected function _secureRequired($controller) { if (is_array($this->requireSecure) && !empty($this->requireSecure)) { $requireSecure = array_map('strtolower', $this->requireSecure); @@ -518,7 +515,7 @@ class SecurityComponent extends Component { * @param object $controller Instantiating controller * @return bool true if authentication required */ - protected function _authRequired(&$controller) { + protected function _authRequired($controller) { if (is_array($this->requireAuth) && !empty($this->requireAuth) && !empty($this->request->data)) { $requireAuth = array_map('strtolower', $this->requireAuth); @@ -553,11 +550,11 @@ class SecurityComponent extends Component { * @param object $controller Instantiating controller * @return bool true if login is required */ - protected function _loginRequired(&$controller) { + protected function _loginRequired($controller) { if (is_array($this->requireLogin) && !empty($this->requireLogin)) { - $requireLogin = array_map('strtolower', $this->requireLogin); + $requireLogin = $this->requireLogin; - if (in_array($this->_action, $requireLogin) || $this->requireLogin == array('*')) { + if (in_array($this->_action, $this->requireLogin) || $this->requireLogin == array('*')) { $login = $this->loginCredentials($this->loginOptions['type']); if ($login == null) { @@ -600,7 +597,7 @@ class SecurityComponent extends Component { * @param object $controller Instantiating controller * @return bool true if submitted form is valid */ - protected function _validatePost(&$controller) { + protected function _validatePost($controller) { if (empty($controller->request->data)) { return true; } @@ -619,15 +616,11 @@ class SecurityComponent extends Component { } unset($check['_Token']); - $locked = str_rot13($locked); - if (preg_match('/(\A|;|{|})O\:[0-9]+/', $locked)) { - return false; - } + $locked = explode('|', $locked); $lockedFields = array(); $fields = Set::flatten($check); $fieldList = array_keys($fields); - $locked = unserialize($locked); $multi = array(); foreach ($fieldList as $i => $key) { @@ -676,7 +669,7 @@ class SecurityComponent extends Component { * @param object $controller Instantiating controller * @return bool Success */ - protected function _generateToken(&$controller) { + protected function _generateToken($controller) { if (isset($controller->request->params['requested']) && $controller->request->params['requested'] === 1) { if ($this->Session->check('_Token')) { $tokenData = $this->Session->read('_Token'); @@ -769,7 +762,7 @@ class SecurityComponent extends Component { * @param array $params Parameters to send to method * @return mixed Controller callback method's response */ - protected function _callback(&$controller, $method, $params = array()) { + protected function _callback($controller, $method, $params = array()) { if (is_callable(array($controller, $method))) { return call_user_func_array(array(&$controller, $method), empty($params) ? null : $params); } else { diff --git a/cake/libs/controller/components/session.php b/cake/libs/controller/components/session.php index 77ab43a4d..09a9f6da6 100644 --- a/cake/libs/controller/components/session.php +++ b/cake/libs/controller/components/session.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.controller.components + * @package cake.libs.controller.components * @since CakePHP(tm) v 0.10.0.1232 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -26,24 +25,12 @@ if (!class_exists('cakesession')) { * * Session handling from the controller. * - * @package cake - * @subpackage cake.cake.libs.controller.components + * @package cake.libs.controller.components * @link http://book.cakephp.org/view/1310/Sessions * */ class SessionComponent extends Component { -/** - * Constructor automatically starts the session. - * - * @param ComponentCollection $collection A ComponentCollection this component can use to lazy load its components - * @param array $settings Array of configuration settings. - */ - public function __construct(ComponentCollection $collection, $settings = array()) { - parent::__construct($collection, $settings); - CakeSession::start(); - } - /** * Get / Set the userAgent * diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 2ac674109..758d41225 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.controller + * @package cake.libs.controller * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -27,15 +26,28 @@ App::import('Controller', 'Component', false); App::import('View', 'View', false); /** - * Controller - * * Application controller class for organization of business logic. * Provides basic functionality, such as rendering views inside layouts, * automatic model availability, redirection, callbacks, and more. * - * @package cake - * @subpackage cake.cake.libs.controller - * @link http://book.cakephp.org/view/956/Introduction + * Controllers should provide a number of 'action' methods. These are public methods on the controller + * that are not prefixed with a '_' and not part of Controller. Each action serves as an endpoint for + * performing a specific action on a resource or collection of resources. For example adding or editing a new + * object, or listing a set of objects. + * + * You can access request parameters, using `$this->request`. The request object contains all the POST, GET and FILES + * that were part of the request. + * + * After performing the required actions, controllers are responsible for creating a response. This usually + * takes the form of a generated View, or possibly a redirection to another controller action. In either case + * `$this->response` allows you to manipulate all aspects of the response. + * + * Controllers are created by Dispatcher based on request parameters and routing. By default controllers and actions + * use conventional names. For example `/posts/index` maps to `PostsController::index()`. You can re-map urls + * using Router::connect(). + * + * @package cake.libs.controller + * @link http://book.cakephp.org/view/956/Introduction */ class Controller extends Object { @@ -94,26 +106,6 @@ class Controller extends Object { */ protected $_responseClass = 'CakeResponse'; -/** - * Holds pagination defaults for controller actions. The keys that can be included - * in this array are: 'conditions', 'fields', 'order', 'limit', 'page', and 'recursive', - * similar to the keys in the second parameter of Model::find(). - * - * Pagination defaults can also be supplied in a model-by-model basis by using - * the name of the model as a key for a pagination array: - * - * {{{ - * public $paginate = array( - * 'Post' => array(...), - * 'Comment' => array(...) - * ); - * }}} - * - * @var array - * @link http://book.cakephp.org/view/1231/Pagination - */ - public $paginate = array('limit' => 20, 'page' => 1); - /** * The name of the views subfolder containing views for this controller. * @@ -168,7 +160,7 @@ class Controller extends Object { public $autoLayout = true; /** - * Instance of Component used to handle callbacks. + * Instance of ComponentCollection used to handle callbacks. * * @var string */ @@ -260,7 +252,8 @@ class Controller extends Object { public $scaffold = false; /** - * Holds current methods of the controller + * Holds current methods of the controller. This is a list of all the methods reachable + * via url. Modifying this array, will allow you to change which methods can be reached. * * @var array */ @@ -292,6 +285,15 @@ class Controller extends Object { */ public $validationErrors = null; +/** + * The class name of the parent class you wish to merge with. + * Typically this is AppController, but you may wish to merge vars with a different + * parent class. + * + * @var string + */ + protected $_mergeParent = 'AppController'; + /** * Constructor. * @@ -321,7 +323,7 @@ class Controller extends Object { $this->methods = array_diff($childMethods, $parentMethods); if ($request instanceof CakeRequest) { - $this->_setRequest($request); + $this->setRequest($request); } $this->getResponse(); parent::__construct(); @@ -362,6 +364,8 @@ class Controller extends Object { return isset($this->request->params['action']) ? $this->request->params['action'] : ''; case 'params': return $this->request; + case 'paginate': + return $this->Components->load('Paginator')->settings; } return null; } @@ -382,6 +386,8 @@ class Controller extends Object { return $this->request->params['action'] = $value; case 'params': return $this->request->params = $value; + case 'paginate': + return $this->Components->load('Paginator')->settings = $value; } return $this->{$name} = $value; } @@ -393,7 +399,7 @@ class Controller extends Object { * @param CakeRequest $request * @return void */ - protected function _setRequest(CakeRequest $request) { + public function setRequest(CakeRequest $request) { $this->request = $request; $this->plugin = isset($request->params['plugin']) ? $request->params['plugin'] : null; @@ -410,7 +416,7 @@ class Controller extends Object { } /** - * Merge components, helpers, and uses vars from AppController and PluginAppController. + * Merge components, helpers, and uses vars from Controller::$_mergeParent and PluginAppController. * * @return void */ @@ -426,8 +432,8 @@ class Controller extends Object { $plugin = $pluginName . '.'; } - if (is_subclass_of($this, 'AppController') || !empty($pluginController)) { - $appVars = get_class_vars('AppController'); + if (is_subclass_of($this, $this->_mergeParent) || !empty($pluginController)) { + $appVars = get_class_vars($this->_mergeParent); $uses = $appVars['uses']; $merge = array('components', 'helpers'); @@ -440,17 +446,23 @@ class Controller extends Object { $this->uses = array_flip($this->uses); array_unshift($this->uses, $plugin . $this->modelClass); } - } elseif ($this->uses !== null || $this->uses !== false) { - $this->_mergeVars(array('uses'), 'AppController', false); + } elseif ( + ($this->uses !== null || $this->uses !== false) && + is_array($this->uses) && !empty($appVars['uses']) + ) { + $this->uses = array_merge($this->uses, array_diff($appVars['uses'], $this->uses)); } - $this->_mergeVars($merge, 'AppController', true); + $this->_mergeVars($merge, $this->_mergeParent, true); } if ($pluginController && $pluginName != null) { $merge = array('components', 'helpers'); - - if ($this->uses !== null || $this->uses !== false) { - $this->_mergeVars(array('uses'), $pluginController, false); + $appVars = get_class_vars($pluginController); + if ( + ($this->uses !== null || $this->uses !== false) && + is_array($this->uses) && !empty($appVars['uses']) + ) { + $this->uses = array_merge($this->uses, array_diff($appVars['uses'], $this->uses)); } $this->_mergeVars($merge, $pluginController); } @@ -476,9 +488,10 @@ class Controller extends Object { } else { $id = $this->passedArgs['0']; } + $plugin = $this->plugin ? $this->plugin . '.' : null; if ($this->uses === false) { - $this->loadModel($this->modelClass, $id); + $this->loadModel($plugin . $this->modelClass, $id); } elseif ($this->uses) { $uses = is_array($this->uses) ? $this->uses : array($this->uses); list($plugin, $modelClassName) = pluginSplit($uses[0]); @@ -550,7 +563,7 @@ class Controller extends Object { * * @return mixed Associative array of the HTTP codes as keys, and the message * strings as values, or null of the given $code does not exist. - * @deprecated + * @deprecated Use CakeResponse::httpCodes(); */ public function httpCodes($code = null) { return $this->response->httpCodes($code); @@ -671,7 +684,7 @@ class Controller extends Object { * * @param string $status The header message that is being set. * @return void - * @deprecated + * @deprecated Use CakeResponse::header() */ public function header($status) { $this->response->header($status); @@ -859,7 +872,7 @@ class Controller extends Object { * * @return void * @link http://book.cakephp.org/view/988/disableCache - * @deprecated + * @deprecated Use CakeResponse::disableCache() */ public function disableCache() { $this->response->disableCache(); @@ -953,205 +966,15 @@ class Controller extends Object { * @param array $whitelist List of allowed options for paging * @return array Model query results * @link http://book.cakephp.org/view/1232/Controller-Setup + * @deprecated Use PaginatorComponent instead */ public function paginate($object = null, $scope = array(), $whitelist = array()) { - if (is_array($object)) { - $whitelist = $scope; - $scope = $object; - $object = null; - } - $assoc = null; - - if (is_string($object)) { - $assoc = null; - if (strpos($object, '.') !== false) { - list($object, $assoc) = pluginSplit($object); - } - - if ($assoc && isset($this->{$object}->{$assoc})) { - $object = $this->{$object}->{$assoc}; - } elseif ( - $assoc && isset($this->{$this->modelClass}) && - isset($this->{$this->modelClass}->{$assoc} - )) { - $object = $this->{$this->modelClass}->{$assoc}; - } elseif (isset($this->{$object})) { - $object = $this->{$object}; - } elseif ( - isset($this->{$this->modelClass}) && isset($this->{$this->modelClass}->{$object} - )) { - $object = $this->{$this->modelClass}->{$object}; - } - } elseif (empty($object) || $object === null) { - if (isset($this->{$this->modelClass})) { - $object = $this->{$this->modelClass}; - } else { - $className = null; - $name = $this->uses[0]; - if (strpos($this->uses[0], '.') !== false) { - list($name, $className) = explode('.', $this->uses[0]); - } - if ($className) { - $object = $this->{$className}; - } else { - $object = $this->{$name}; - } - } - } - - if (!is_object($object)) { - trigger_error(sprintf( - __('Controller::paginate() - can\'t find model %1$s in controller %2$sController'), $object, $this->name - ), E_USER_WARNING); - return array(); - } - $options = array_merge($this->request->params, $this->request->query, $this->passedArgs); - - if (isset($this->paginate[$object->alias])) { - $defaults = $this->paginate[$object->alias]; - } else { - $defaults = $this->paginate; - } - - if (isset($options['show'])) { - $options['limit'] = $options['show']; - } - - if (isset($options['sort'])) { - $direction = null; - if (isset($options['direction'])) { - $direction = strtolower($options['direction']); - } - if ($direction != 'asc' && $direction != 'desc') { - $direction = 'asc'; - } - $options['order'] = array($options['sort'] => $direction); - } - - if (!empty($options['order']) && is_array($options['order'])) { - $alias = $object->alias ; - $key = $field = key($options['order']); - - if (strpos($key, '.') !== false) { - list($alias, $field) = explode('.', $key); - } - $value = $options['order'][$key]; - unset($options['order'][$key]); - - if ($object->hasField($field)) { - $options['order'][$alias . '.' . $field] = $value; - } elseif ($object->hasField($field, true)) { - $options['order'][$field] = $value; - } elseif (isset($object->{$alias}) && $object->{$alias}->hasField($field)) { - $options['order'][$alias . '.' . $field] = $value; - } - } - $vars = array('fields', 'order', 'limit', 'page', 'recursive'); - $keys = array_keys($options); - $count = count($keys); - - for ($i = 0; $i < $count; $i++) { - if (!in_array($keys[$i], $vars, true)) { - unset($options[$keys[$i]]); - } - if (empty($whitelist) && ($keys[$i] === 'fields' || $keys[$i] === 'recursive')) { - unset($options[$keys[$i]]); - } elseif (!empty($whitelist) && !in_array($keys[$i], $whitelist)) { - unset($options[$keys[$i]]); - } - } - $conditions = $fields = $order = $limit = $page = $recursive = null; - - if (!isset($defaults['conditions'])) { - $defaults['conditions'] = array(); - } - - $type = 'all'; - - if (isset($defaults[0])) { - $type = $defaults[0]; - unset($defaults[0]); - } - - $options = array_merge(array('page' => 1, 'limit' => 20), $defaults, $options); - $options['limit'] = (int) $options['limit']; - if (empty($options['limit']) || $options['limit'] < 1) { - $options['limit'] = 1; - } - - extract($options); - - if (is_array($scope) && !empty($scope)) { - $conditions = array_merge($conditions, $scope); - } elseif (is_string($scope)) { - $conditions = array($conditions, $scope); - } - if ($recursive === null) { - $recursive = $object->recursive; - } - - $extra = array_diff_key($defaults, compact( - 'conditions', 'fields', 'order', 'limit', 'page', 'recursive' - )); - if ($type !== 'all') { - $extra['type'] = $type; - } - - if (method_exists($object, 'paginateCount')) { - $count = $object->paginateCount($conditions, $recursive, $extra); - } else { - $parameters = compact('conditions'); - if ($recursive != $object->recursive) { - $parameters['recursive'] = $recursive; - } - $count = $object->find('count', array_merge($parameters, $extra)); - } - $pageCount = intval(ceil($count / $limit)); - - if ($page === 'last' || $page >= $pageCount) { - $options['page'] = $page = $pageCount; - } elseif (intval($page) < 1) { - $options['page'] = $page = 1; - } - $page = $options['page'] = (integer)$page; - - if (method_exists($object, 'paginate')) { - $results = $object->paginate( - $conditions, $fields, $order, $limit, $page, $recursive, $extra - ); - } else { - $parameters = compact('conditions', 'fields', 'order', 'limit', 'page'); - if ($recursive != $object->recursive) { - $parameters['recursive'] = $recursive; - } - $results = $object->find($type, array_merge($parameters, $extra)); - } - $paging = array( - 'page' => $page, - 'current' => count($results), - 'count' => $count, - 'prevPage' => ($page > 1), - 'nextPage' => ($count > ($page * $limit)), - 'pageCount' => $pageCount, - 'defaults' => array_merge(array('limit' => 20, 'step' => 1), $defaults), - 'options' => $options - ); - if (!isset($this->request->params['paging'])) { - $this->request->params['paging'] = array(); - } - $this->request->params['paging'] = array_merge( - (array)$this->request->params['paging'], - array($object->alias => $paging) - ); - - if (!in_array('Paginator', $this->helpers) && !array_key_exists('Paginator', $this->helpers)) { - $this->helpers[] = 'Paginator'; - } - return $results; + return $this->Components->load('Paginator', $this->paginate)->paginate($object, $scope, $whitelist); } /** - * Called before the controller action. + * Called before the controller action. You can use this method to configure and customize components + * or perform logic that needs to happen before each controller action. * * @link http://book.cakephp.org/view/984/Callbacks */ @@ -1159,7 +982,8 @@ class Controller extends Object { } /** - * Called after the controller action is run, but before the view is rendered. + * Called after the controller action is run, but before the view is rendered. You can use this method + * to perform logic or set view variables that are required on every request. * * @link http://book.cakephp.org/view/984/Callbacks */ diff --git a/cake/libs/controller/pages_controller.php b/cake/libs/controller/pages_controller.php index bc7a380e7..65e8b0465 100644 --- a/cake/libs/controller/pages_controller.php +++ b/cake/libs/controller/pages_controller.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.controller + * @package cake.libs.controller * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,8 +24,7 @@ * * Override this controller by placing a copy in controllers directory of an application * - * @package cake - * @subpackage cake.cake.libs.controller + * @package cake.libs.controller * @link http://book.cakephp.org/view/958/The-Pages-Controller */ class PagesController extends AppController { diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index 581d788c0..97a2533d7 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.controller + * @package cake.libs.controller * @since Cake v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -29,8 +28,7 @@ App::import('View', 'Scaffold'); * and afford the web developer an early look at the data, and the possibility to over-ride * scaffolded actions with custom-made ones. * - * @package cake - * @subpackage cake.cake.libs.controller + * @package cake.libs.controller */ class Scaffold { @@ -172,15 +170,14 @@ class Scaffold { */ protected function _scaffoldView(CakeRequest $request) { if ($this->controller->_beforeScaffold('view')) { - - $message = __(sprintf("No id set for %s::view()", Inflector::humanize($this->modelKey))); if (isset($request->params['pass'][0])) { $this->ScaffoldModel->id = $request->params['pass'][0]; - } else { - return $this->_sendMessage($message); + } + if (!$this->ScaffoldModel->exists()) { + throw new NotFoundException(__('Invalid %s', Inflector::humanize($this->modelKey))); } $this->ScaffoldModel->recursive = 1; - $this->controller->request->data = $this->controller->data = $this->ScaffoldModel->read(); + $this->controller->request->data = $this->ScaffoldModel->read(); $this->controller->set( Inflector::variable($this->controller->modelClass), $this->request->data ); @@ -245,10 +242,8 @@ class Scaffold { if (isset($request->params['pass'][0])) { $this->ScaffoldModel->id = $request['pass'][0]; } - if (!$this->ScaffoldModel->exists()) { - $message = __(sprintf("Invalid id for %s::edit()", Inflector::humanize($this->modelKey))); - return $this->_sendMessage($message); + throw new NotFoundException(__('Invalid %s', Inflector::humanize($this->modelKey))); } } @@ -260,7 +255,9 @@ class Scaffold { if ($this->ScaffoldModel->save($request->data)) { if ($this->controller->_afterScaffoldSave($action)) { $message = __( - sprintf('The %1$s has been %2$s', Inflector::humanize($this->modelKey), $success) + 'The %1$s has been %2$s', + Inflector::humanize($this->modelKey), + $success ); return $this->_sendMessage($message); } else { @@ -306,25 +303,26 @@ class Scaffold { */ protected function _scaffoldDelete(CakeRequest $request) { if ($this->controller->_beforeScaffold('delete')) { - $message = __( - sprintf("No id set for %s::delete()", Inflector::humanize($this->modelKey)) - ); + if (!$request->is('post')) { + throw new MethodNotAllowedException(); + } + $id = false; if (isset($request->params['pass'][0])) { $id = $request->params['pass'][0]; - } else { - return $this->_sendMessage($message); } - - if ($this->ScaffoldModel->delete($id)) { - $message = __( - sprintf('The %1$s with id: %2$d has been deleted.', Inflector::humanize($this->modelClass), $id) - ); + $this->ScaffoldModel->id = $id; + if (!$this->ScaffoldModel->exists()) { + throw new NotFoundException(__('Invalid %s', Inflector::humanize($this->modelClass))); + } + if ($this->ScaffoldModel->delete()) { + $message = __('The %1$s with id: %2$d has been deleted.', Inflector::humanize($this->modelClass), $id); return $this->_sendMessage($message); } else { - $message = __(sprintf( - 'There was an error deleting the %1$s with id: %2$d', - Inflector::humanize($this->modelClass), $id - )); + $message = __( + 'There was an error deleting the %1$s with id: %2$d', + Inflector::humanize($this->modelClass), + $id + ); return $this->_sendMessage($message); } } elseif ($this->controller->_scaffoldError('delete') === false) { diff --git a/cake/libs/debugger.php b/cake/libs/debugger.php index f07ab78c6..942aa1c63 100644 --- a/cake/libs/debugger.php +++ b/cake/libs/debugger.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 1.2.4560 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -36,8 +35,7 @@ if (!class_exists('String')) { * * Debugger overrides PHP's default error handling to provide stack traces and enhanced logging * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @link http://book.cakephp.org/view/1191/Using-the-Debugger-Class */ class Debugger { @@ -236,7 +234,7 @@ class Debugger { * @param array $context Context * @return boolean true if error was handled */ - public function showError($code, $description, $file = null, $line = null, $context = null) { + public static function showError($code, $description, $file = null, $line = null, $context = null) { $_this = Debugger::getInstance(); if (empty($file)) { diff --git a/cake/libs/dispatcher.php b/cake/libs/dispatcher.php index cb14d18ba..f8c833bc9 100644 --- a/cake/libs/dispatcher.php +++ b/cake/libs/dispatcher.php @@ -15,8 +15,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake + * @package cake.libs * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -35,7 +34,6 @@ App::import('Controller', 'Controller', false); * the controller. * * @package cake - * @subpackage cake.cake */ class Dispatcher { @@ -99,8 +97,8 @@ class Dispatcher { return; } - $request = $this->parseParams($request, $additionalParams); - $controller = $this->_getController($request); + $this->request = $this->parseParams($request, $additionalParams); + $controller = $this->_getController($this->request); if (!is_object($controller)) { Router::setRequestInfo($request); @@ -195,10 +193,10 @@ class Dispatcher { * @return CakeRequest The request object with routing params set. */ public function parseParams(CakeRequest $request, $additionalParams = array()) { - if (count(Router::$routes) > 0) { + if (count(Router::$routes) == 0) { $namedExpressions = Router::getNamedExpressions(); extract($namedExpressions); - include CONFIGS . 'routes.php'; + $this->_loadRoutes(); } $params = Router::parse($request->url); @@ -250,6 +248,15 @@ class Dispatcher { return false; } +/** + * Loads route configuration + * + * @return void + */ + protected function _loadRoutes() { + include CONFIGS . 'routes.php'; + } + /** * Outputs cached dispatch view cache * @@ -315,7 +322,8 @@ class Dispatcher { $this->_stop(); } $controller = null; - $ext = array_pop(explode('.', $url)); + $pathSegments = explode('.', $url); + $ext = array_pop($pathSegments); $parts = explode('/', $url); $assetFile = null; diff --git a/cake/libs/error/error_handler.php b/cake/libs/error/error_handler.php index 85cea7ec4..775bd8d43 100644 --- a/cake/libs/error/error_handler.php +++ b/cake/libs/error/error_handler.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs.error * @since CakePHP(tm) v 0.10.5.1732 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -88,8 +87,7 @@ * * Would enable handling for all non Notice errors. * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs.error * @see ExceptionRenderer for more information on how to customize exception rendering. */ class ErrorHandler { @@ -110,7 +108,12 @@ class ErrorHandler { if (!class_exists('CakeLog')) { require LIBS . 'cake_log.php'; } - CakeLog::write(LOG_ERR, '[' . get_class($exception) . '] ' . $exception->getMessage()); + $message = sprintf("[%s] %s\n%s", + get_class($exception), + $exception->getMessage(), + $exception->getTraceAsString() + ); + CakeLog::write(LOG_ERR, $message); } if ($config['renderer'] !== 'ExceptionRenderer') { App::import('Lib', $config['renderer']); diff --git a/cake/libs/error/exception_renderer.php b/cake/libs/error/exception_renderer.php index 0d6c71b83..5745564df 100644 --- a/cake/libs/error/exception_renderer.php +++ b/cake/libs/error/exception_renderer.php @@ -15,8 +15,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs.error * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -45,8 +44,7 @@ * can configure your class in your core.php, with `Configure::write('Exception.renderer', 'MyClass');` * You should place any custom exception renderers in `app/libs`. * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs.error */ class ExceptionRenderer { @@ -107,7 +105,7 @@ class ExceptionRenderer { } } elseif (!$methodExists) { $method = 'error500'; - if ($code >= 400) { + if ($code >= 400 && $code < 500) { $method = 'error400'; } } diff --git a/cake/libs/error/exceptions.php b/cake/libs/error/exceptions.php index 473b2dbee..75224c557 100644 --- a/cake/libs/error/exceptions.php +++ b/cake/libs/error/exceptions.php @@ -13,18 +13,26 @@ * * @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.libs + * @package cake.libs.error * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +/** + * Parent class for all of the HTTP related exceptions in CakePHP. + * All HTTP status/error related exceptions should extend this class so + * catch blocks can be specifically typed. + * + * @package cake.libs + */ +class HttpException extends RuntimeException { } + /** * Represents an HTTP 400 error. * * @package cake.libs */ -class BadRequestException extends RuntimeException { +class BadRequestException extends HttpException { /** * Constructor * @@ -44,7 +52,7 @@ class BadRequestException extends RuntimeException { * * @package cake.libs */ -class UnauthorizedException extends RuntimeException { +class UnauthorizedException extends HttpException { /** * Constructor * @@ -64,7 +72,7 @@ class UnauthorizedException extends RuntimeException { * * @package cake.libs */ -class ForbiddenException extends RuntimeException { +class ForbiddenException extends HttpException { /** * Constructor * @@ -84,7 +92,7 @@ class ForbiddenException extends RuntimeException { * * @package cake.libs */ -class NotFoundException extends RuntimeException { +class NotFoundException extends HttpException { /** * Constructor * @@ -104,7 +112,7 @@ class NotFoundException extends RuntimeException { * * @package cake.libs */ -class MethodNotAllowedException extends RuntimeException { +class MethodNotAllowedException extends HttpException { /** * Constructor * @@ -124,7 +132,7 @@ class MethodNotAllowedException extends RuntimeException { * * @package cake.libs */ -class InternalErrorException extends CakeException { +class InternalErrorException extends HttpException { /** * Constructor * @@ -378,4 +386,70 @@ class MissingTableException extends CakeException { */ class MissingModelException extends CakeException { protected $_messageTemplate = 'Model %s could not be found.'; -} \ No newline at end of file +} + + +/** + * Exception class for Cache. This exception will be thrown from Cache when it + * encounters an error. + * + * @package cake.libs + */ +class CacheException extends CakeException { } + +/** + * Exception class for Router. This exception will be thrown from Router when it + * encounters an error. + * + * @package cake.libs + */ +class RouterException extends CakeException { } + +/** + * Exception class for CakeLog. This exception will be thrown from CakeLog when it + * encounters an error. + * + * @package cake.libs + */ +class CakeLogException extends CakeException { } + +/** + * Exception class for CakeSession. This exception will be thrown from CakeSession when it + * encounters an error. + * + * @package cake.libs + */ +class CakeSessionException extends CakeException { } + +/** + * Exception class for Configure. This exception will be thrown from Configure when it + * encounters an error. + * + * @package cake.libs + */ +class ConfigureException extends CakeException { } + +/** + * Exception class for Socket. This exception will be thrown from CakeSocket, HttpSocket and HttpResponse when it + * encounters an error. + * + * @package cake.libs + */ +class SocketException extends CakeException { } + +/** + * Exception class for Xml. This exception will be thrown from Xml when it + * encounters an error. + * + * @package cake.libs + */ +class XmlException extends CakeException { } + +/** + * Exception class for Console libraries. This exception will be thrown from Console library + * classes when they encounter an error. + * + * @package cake.libs + */ +class ConsoleException extends CakeException { } + diff --git a/cake/libs/file.php b/cake/libs/file.php index 663004840..49d030e4d 100644 --- a/cake/libs/file.php +++ b/cake/libs/file.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -29,8 +28,7 @@ if (!class_exists('Folder')) { /** * Convenience class for reading, writing and appending to files. * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs */ class File { @@ -90,7 +88,6 @@ class File { * @param string $path Path to file * @param boolean $create Create file if it does not exist (if true) * @param integer $mode Mode to apply to the folder holding the file - * @access private */ function __construct($path, $create = false, $mode = 0755) { $this->Folder = new Folder(dirname($path), $create, $mode); @@ -104,7 +101,6 @@ class File { /** * Closes the current file if it is opened * - * @access private */ function __destruct() { $this->close(); @@ -214,7 +210,7 @@ class File { * @param string $data Data to prepare for writing. * @return string The with converted line endings. */ - public function prepare($data, $forceWindows = false) { + public static function prepare($data, $forceWindows = false) { $lineBreak = "\n"; if (DIRECTORY_SEPARATOR == '\\' || $forceWindows === true) { $lineBreak = "\r\n"; diff --git a/cake/libs/folder.php b/cake/libs/folder.php index 551e05876..02b097227 100644 --- a/cake/libs/folder.php +++ b/cake/libs/folder.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ * Folder structure browser, lists folders and files. * Provides an Object interface for Common directory related tasks. * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs */ class Folder { @@ -240,10 +238,8 @@ class Folder { * * @param string $path Path to check * @return boolean true if windows path, false otherwise - * @access public - * @static */ - function isWindowsPath($path) { + public static function isWindowsPath($path) { return (preg_match('/^[A-Z]:\\\\/i', $path) || substr($path, 0, 2) == '\\\\'); } @@ -252,10 +248,8 @@ class Folder { * * @param string $path Path to check * @return bool true if path is absolute. - * @access public - * @static */ - function isAbsolute($path) { + public static function isAbsolute($path) { return !empty($path) && ($path[0] === '/' || preg_match('/^[A-Z]:\\\\/i', $path) || substr($path, 0, 2) == '\\\\'); } @@ -264,10 +258,8 @@ class Folder { * * @param string $path Path to check * @return string Set of slashes ("\\" or "/") - * @access public - * @static */ - function normalizePath($path) { + public static function normalizePath($path) { return Folder::correctSlashFor($path); } @@ -276,10 +268,8 @@ class Folder { * * @param string $path Path to check * @return string Set of slashes ("\\" or "/") - * @access public - * @static */ - function correctSlashFor($path) { + public static function correctSlashFor($path) { return (Folder::isWindowsPath($path)) ? '\\' : '/'; } @@ -288,10 +278,8 @@ class Folder { * * @param string $path Path to check * @return string Path with ending slash - * @access public - * @static */ - function slashTerm($path) { + public static function slashTerm($path) { if (Folder::isSlashTerm($path)) { return $path; } @@ -304,10 +292,8 @@ class Folder { * @param string $path Path * @param string $element Element to and at end of path * @return string Combined path - * @access public - * @static */ - function addPathElement($path, $element) { + public static function addPathElement($path, $element) { return rtrim($path, DS) . DS . $element; } @@ -755,10 +741,8 @@ class Folder { * * @param string $path Path to check * @return boolean true if path ends with slash, false otherwise - * @access public - * @static */ - function isSlashTerm($path) { + public static function isSlashTerm($path) { $lastChar = $path[strlen($path) - 1]; return $lastChar === '/' || $lastChar === '\\'; } diff --git a/cake/libs/http/basic_authentication.php b/cake/libs/http/basic_authentication.php new file mode 100644 index 000000000..49b12fc5f --- /dev/null +++ b/cake/libs/http/basic_authentication.php @@ -0,0 +1,66 @@ +request['header']['Authorization'] = self::_generateHeader($authInfo['user'], $authInfo['pass']); + } + } + +/** + * Proxy Authentication + * + * @param HttpSocket $http + * @param array $proxyInfo + * @return void + * @see http://www.ietf.org/rfc/rfc2617.txt + */ + public static function proxyAuthentication(HttpSocket $http, &$proxyInfo) { + if (isset($proxyInfo['user'], $proxyInfo['pass'])) { + $http->request['header']['Proxy-Authorization'] = self::_generateHeader($proxyInfo['user'], $proxyInfo['pass']); + } + } + +/** + * Generate basic [proxy] authentication header + * + * @param string $user + * @param string $pass + * @return string + */ + protected static function _generateHeader($user, $pass) { + return 'Basic ' . base64_encode($user . ':' . $pass); + } + +} diff --git a/cake/libs/http/digest_authentication.php b/cake/libs/http/digest_authentication.php new file mode 100644 index 000000000..14275f4e5 --- /dev/null +++ b/cake/libs/http/digest_authentication.php @@ -0,0 +1,104 @@ +request['header']['Authorization'] = self::_generateHeader($http, $authInfo); + } + } + +/** + * Retrive information about the authetication + * + * @param HttpSocket $http + * @parma array $authInfo + * @return boolean + */ + protected static function _getServerInformation(HttpSocket $http, &$authInfo) { + $originalRequest = $http->request; + $http->configAuth(false); + $http->request($http->request); + $http->request = $originalRequest; + $http->configAuth('Digest', $authInfo); + + if (empty($http->response['header']['WWW-Authenticate'])) { + return false; + } + preg_match_all('@(\w+)=(?:(?:")([^"]+)"|([^\s,$]+))@', $http->response['header']['WWW-Authenticate'], $matches, PREG_SET_ORDER); + foreach ($matches as $match) { + $authInfo[$match[1]] = $match[2]; + } + if (!empty($authInfo['qop']) && empty($authInfo['nc'])) { + $authInfo['nc'] = 1; + } + return true; + } + +/** + * Generate the header Authorization + * + * @param HttpSocket $http + * @param array $authInfo + * @return string + */ + protected static function _generateHeader(HttpSocket $http, &$authInfo) { + $a1 = md5($authInfo['user'] . ':' . $authInfo['realm'] . ':' . $authInfo['pass']); + $a2 = md5($http->request['method'] . ':' . $http->request['uri']['path']); + + if (empty($authInfo['qop'])) { + $response = md5($a1 . ':' . $authInfo['nonce'] . ':' . $a2); + } else { + $authInfo['cnonce'] = uniqid(); + $nc = sprintf('%08x', $authInfo['nc']++); + $response = md5($a1 . ':' . $authInfo['nonce'] . ':' . $nc . ':' . $authInfo['cnonce'] . ':auth:' . $a2); + } + + $authHeader = 'Digest '; + $authHeader .= 'username="' . str_replace(array('\\', '"'), array('\\\\', '\\"'), $authInfo['user']) . '", '; + $authHeader .= 'realm="' . $authInfo['realm'] . '", '; + $authHeader .= 'nonce="' . $authInfo['nonce'] . '", '; + $authHeader .= 'uri="' . $http->request['uri']['path'] . '", '; + $authHeader .= 'response="' . $response . '"'; + if (!empty($authInfo['opaque'])) { + $authHeader .= ', opaque="' . $authInfo['opaque'] . '"'; + } + if (!empty($authInfo['qop'])) { + $authHeader .= ', qop="auth", nc=' . $nc . ', cnonce="' . $authInfo['cnonce'] . '"'; + } + return $authHeader; + } +} diff --git a/cake/libs/http_response.php b/cake/libs/http_response.php new file mode 100644 index 000000000..51aff7a78 --- /dev/null +++ b/cake/libs/http_response.php @@ -0,0 +1,437 @@ +parseResponse($message); + } + } + +/** + * Body content + * + * @return string + */ + public function body() { + return (string)$this->body; + } + +/** + * Get header in case insensitive + * + * @param string $name Header name + * @return mixed String if header exists or null + */ + public function getHeader($name, $headers = null) { + if (!is_array($headers)) { + $headers =& $this->headers; + } + if (isset($headers[$name])) { + return $headers[$name]; + } + foreach ($headers as $key => $value) { + if (strcasecmp($key, $name) == 0) { + return $value; + } + } + return null; + } + +/** + * If return is 200 (OK) + * + * @return boolean + */ + public function isOk() { + return $this->code == 200; + } + +/** + * Parses the given message and breaks it down in parts. + * + * @param string $message Message to parse + * @return void + * @throw SocketException + */ + public function parseResponse($message) { + if (!is_string($message)) { + throw new SocketException(__('Invalid response.')); + } + + if (!preg_match("/^(.+\r\n)(.*)(?<=\r\n)\r\n/Us", $message, $match)) { + throw new SocketException(__('Invalid HTTP response.')); + } + + list(, $statusLine, $header) = $match; + $this->raw = $message; + $this->body = (string)substr($message, strlen($match[0])); + + if (preg_match("/(.+) ([0-9]{3}) (.+)\r\n/DU", $statusLine, $match)) { + $this->httpVersion = $match[1]; + $this->code = $match[2]; + $this->reasonPhrase = $match[3]; + } + + $this->headers = $this->_parseHeader($header); + $transferEncoding = $this->getHeader('Transfer-Encoding'); + $decoded = $this->_decodeBody($this->body, $transferEncoding); + $this->body = $decoded['body']; + + if (!empty($decoded['header'])) { + $this->headers = $this->_parseHeader($this->_buildHeader($this->headers) . $this->_buildHeader($decoded['header'])); + } + + if (!empty($this->headers)) { + $this->cookies = $this->parseCookies($this->headers); + } + } + +/** + * Generic function to decode a $body with a given $encoding. Returns either an array with the keys + * 'body' and 'header' or false on failure. + * + * @param string $body A string continaing the body to decode. + * @param mixed $encoding Can be false in case no encoding is being used, or a string representing the encoding. + * @return mixed Array of response headers and body or false. + */ + protected function _decodeBody($body, $encoding = 'chunked') { + if (!is_string($body)) { + return false; + } + if (empty($encoding)) { + return array('body' => $body, 'header' => false); + } + $decodeMethod = '_decode' . Inflector::camelize(str_replace('-', '_', $encoding)) . 'Body'; + + if (!is_callable(array(&$this, $decodeMethod))) { + return array('body' => $body, 'header' => false); + } + return $this->{$decodeMethod}($body); + } + +/** + * Decodes a chunked message $body and returns either an array with the keys 'body' and 'header' or false as + * a result. + * + * @param string $body A string continaing the chunked body to decode. + * @return mixed Array of response headers and body or false. + * @throws SocketException + */ + protected function _decodeChunkedBody($body) { + if (!is_string($body)) { + return false; + } + + $decodedBody = null; + $chunkLength = null; + + while ($chunkLength !== 0) { + if (!preg_match("/^([0-9a-f]+) *(?:;(.+)=(.+))?\r\n/iU", $body, $match)) { + throw new SocketException(__('HttpSocket::_decodeChunkedBody - Could not parse malformed chunk.')); + } + + $chunkSize = 0; + $hexLength = 0; + $chunkExtensionName = ''; + $chunkExtensionValue = ''; + if (isset($match[0])) { + $chunkSize = $match[0]; + } + if (isset($match[1])) { + $hexLength = $match[1]; + } + if (isset($match[2])) { + $chunkExtensionName = $match[2]; + } + if (isset($match[3])) { + $chunkExtensionValue = $match[3]; + } + + $body = substr($body, strlen($chunkSize)); + $chunkLength = hexdec($hexLength); + $chunk = substr($body, 0, $chunkLength); + if (!empty($chunkExtensionName)) { + /** + * @todo See if there are popular chunk extensions we should implement + */ + } + $decodedBody .= $chunk; + if ($chunkLength !== 0) { + $body = substr($body, $chunkLength + strlen("\r\n")); + } + } + + $entityHeader = false; + if (!empty($body)) { + $entityHeader = $this->_parseHeader($body); + } + return array('body' => $decodedBody, 'header' => $entityHeader); + } + +/** + * Parses an array based header. + * + * @param array $header Header as an indexed array (field => value) + * @return array Parsed header + */ + protected function _parseHeader($header) { + if (is_array($header)) { + return $header; + } elseif (!is_string($header)) { + return false; + } + + preg_match_all("/(.+):(.+)(?:(?_unescapeToken($field); + + if (!isset($header[$field])) { + $header[$field] = $value; + } else { + $header[$field] = array_merge((array)$header[$field], (array)$value); + } + } + return $header; + } + +/** + * Parses cookies in response headers. + * + * @param array $header Header array containing one ore more 'Set-Cookie' headers. + * @return mixed Either false on no cookies, or an array of cookies recieved. + * @todo Make this 100% RFC 2965 confirm + */ + public function parseCookies($header) { + $cookieHeader = $this->getHeader('Set-Cookie', $header); + if (!$cookieHeader) { + return false; + } + + $cookies = array(); + foreach ((array)$cookieHeader as $cookie) { + if (strpos($cookie, '";"') !== false) { + $cookie = str_replace('";"', "{__cookie_replace__}", $cookie); + $parts = str_replace("{__cookie_replace__}", '";"', explode(';', $cookie)); + } else { + $parts = preg_split('/\;[ \t]*/', $cookie); + } + + list($name, $value) = explode('=', array_shift($parts), 2); + $cookies[$name] = compact('value'); + + foreach ($parts as $part) { + if (strpos($part, '=') !== false) { + list($key, $value) = explode('=', $part); + } else { + $key = $part; + $value = true; + } + + $key = strtolower($key); + if (!isset($cookies[$name][$key])) { + $cookies[$name][$key] = $value; + } + } + } + return $cookies; + } + +/** + * Unescapes a given $token according to RFC 2616 (HTTP 1.1 specs) + * + * @param string $token Token to unescape + * @param array $chars + * @return string Unescaped token + * @todo Test $chars parameter + */ + protected function _unescapeToken($token, $chars = null) { + $regex = '/"([' . implode('', $this->_tokenEscapeChars(true, $chars)) . '])"/'; + $token = preg_replace($regex, '\\1', $token); + return $token; + } + +/** + * Gets escape chars according to RFC 2616 (HTTP 1.1 specs). + * + * @param boolean $hex true to get them as HEX values, false otherwise + * @param array $chars + * @return array Escape chars + * @todo Test $chars parameter + */ + protected function _tokenEscapeChars($hex = true, $chars = null) { + if (!empty($chars)) { + $escape = $chars; + } else { + $escape = array('"', "(", ")", "<", ">", "@", ",", ";", ":", "\\", "/", "[", "]", "?", "=", "{", "}", " "); + for ($i = 0; $i <= 31; $i++) { + $escape[] = chr($i); + } + $escape[] = chr(127); + } + + if ($hex == false) { + return $escape; + } + $regexChars = ''; + foreach ($escape as $key => $char) { + $escape[$key] = '\\x' . str_pad(dechex(ord($char)), 2, '0', STR_PAD_LEFT); + } + return $escape; + } + +/** + * ArrayAccess - Offset Exists + * + * @param mixed $offset + * @return boolean + */ + public function offsetExists($offset) { + return in_array($offset, array('raw', 'status', 'header', 'body', 'cookies')); + } + +/** + * ArrayAccess - Offset Get + * + * @param mixed $offset + * @return mixed + */ + public function offsetGet($offset) { + switch ($offset) { + case 'raw': + $firstLineLength = strpos($this->raw, "\r\n") + 2; + if ($this->raw[$firstLineLength] === "\r") { + $header = null; + } else { + $header = substr($this->raw, $firstLineLength, strpos($this->raw, "\r\n\r\n") - $firstLineLength) . "\r\n"; + } + return array( + 'status-line' => $this->httpVersion . ' ' . $this->code . ' ' . $this->reasonPhrase . "\r\n", + 'header' => $header, + 'body' => $this->body, + 'response' => $this->raw + ); + case 'status': + return array( + 'http-version' => $this->httpVersion, + 'code' => $this->code, + 'reason-phrase' => $this->reasonPhrase + ); + case 'header': + return $this->headers; + case 'body': + return $this->body; + case 'cookies': + return $this->cookies; + } + return null; + } + +/** + * ArrayAccess - 0ffset Set + * + * @param mixed $offset + * @param mixed $value + * @return void + */ + public function offsetSet($offset, $value) { + return; + } + +/** + * ArrayAccess - Offset Unset + * + * @param mixed @offset + * @return void + */ + public function offsetUnset($offset) { + return; + } + +/** + * Instance as string + * + * @return string + */ + public function __toString() { + return $this->body(); + } + +} diff --git a/cake/libs/http_socket.php b/cake/libs/http_socket.php index 7433b2bf8..9e820f921 100644 --- a/cake/libs/http_socket.php +++ b/cake/libs/http_socket.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 1.2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -26,34 +25,23 @@ App::import('Core', 'Router'); * Core base class for HTTP network communication. HttpSocket can be used as an * Object Oriented replacement for cURL in many places. * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs */ class HttpSocket extends CakeSocket { -/** - * Object description - * - * @var string - * @access public - */ - public $description = 'HTTP-based DataSource Interface'; - /** * When one activates the $quirksMode by setting it to true, all checks meant to * enforce RFC 2616 (HTTP/1.1 specs). * will be disabled and additional measures to deal with non-standard responses will be enabled. * * @var boolean - * @access public */ public $quirksMode = false; /** - * The default values to use for a request + * Contain information about the last request (read only) * * @var array - * @access public */ public $request = array( 'method' => 'GET', @@ -67,11 +55,6 @@ class HttpSocket extends CakeSocket { 'query' => null, 'fragment' => null ), - 'auth' => array( - 'method' => 'Basic', - 'user' => null, - 'pass' => null - ), 'version' => '1.1', 'body' => '', 'line' => null, @@ -84,33 +67,23 @@ class HttpSocket extends CakeSocket { ); /** -* The default structure for storing the response -* -* @var array -* @access public -*/ - public $response = array( - 'raw' => array( - 'status-line' => null, - 'header' => null, - 'body' => null, - 'response' => null - ), - 'status' => array( - 'http-version' => null, - 'code' => null, - 'reason-phrase' => null - ), - 'header' => array(), - 'body' => '', - 'cookies' => array() - ); - -/** - * Default configuration settings for the HttpSocket + * Contain information about the last response (read only) + * + * @var array + */ + public $response = null; + +/** + * Response classname + * + * @var string + */ + public $responseClass = 'HttpResponse'; + +/** + * Configuration settings for the HttpSocket and the requests * * @var array - * @access public */ public $config = array( 'persistent' => false, @@ -124,22 +97,30 @@ class HttpSocket extends CakeSocket { 'host' => 'localhost', 'port' => 80 ), - 'auth' => array( - 'method' => 'Basic', - 'user' => null, - 'pass' => null - ), 'cookies' => array() ) ); /** - * String that represents a line break. + * Authentication settings * - * @var string - * @access public + * @var array */ - public $lineBreak = "\r\n"; + protected $_auth = array(); + +/** + * Proxy settings + * + * @var array + */ + protected $_proxy = array(); + +/** + * Resource to receive the content of request + * + * @var mixed + */ + protected $_contentResource = null; /** * Build an HTTP Socket using the specified configuration. @@ -175,12 +156,72 @@ class HttpSocket extends CakeSocket { parent::__construct($this->config); } +/** + * Set authentication settings + * + * @param string $method Authentication method (ie. Basic, Digest). If empty, disable authentication + * @param mixed $user Username for authentication. Can be an array with settings to authentication class + * @param string $pass Password for authentication + * @return void + */ + public function configAuth($method, $user = null, $pass = null) { + if (empty($method)) { + $this->_auth = array(); + return; + } + if (is_array($user)) { + $this->_auth = array($method => $user); + return; + } + $this->_auth = array($method => compact('user', 'pass')); + } + +/** + * Set proxy settings + * + * @param mixed $host Proxy host. Can be an array with settings to authentication class + * @param integer $port Port. Default 3128. + * @param string $method Proxy method (ie, Basic, Digest). If empty, disable proxy authentication + * @param string $user Username if your proxy need authentication + * @param string $pass Password to proxy authentication + * @return void + */ + public function configProxy($host, $port = 3128, $method = null, $user = null, $pass = null) { + if (empty($host)) { + $this->_proxy = array(); + return; + } + if (is_array($host)) { + $this->_proxy = $host + array('host' => null); + return; + } + $this->_proxy = compact('host', 'port', 'method', 'user', 'pass'); + } + +/** + * Set the resource to receive the request content. This resource must support fwrite. + * + * @param mixed $resource Resource or false to disable the resource use + * @return void + * @throw SocketException + */ + public function setContentResource($resource) { + if ($resource === false) { + $this->_contentResource = null; + return; + } + if (!is_resource($resource)) { + throw new SocketException(__('Invalid resource.')); + } + $this->_contentResource = $resource; + } + /** * Issue the specified request. HttpSocket::get() and HttpSocket::post() wrap this * method and provide a more granular interface. * * @param mixed $request Either an URI string, or an array defining host/uri - * @return mixed false on error, request body on success + * @return mixed false on error, HttpResponse on success */ public function request($request = array()) { $this->reset(false); @@ -195,10 +236,6 @@ class HttpSocket extends CakeSocket { $request['uri'] = null; } $uri = $this->_parseUri($request['uri']); - $hadAuth = false; - if (is_array($uri) && array_key_exists('user', $uri)) { - $hadAuth = true; - } if (!isset($uri['host'])) { $host = $this->config['host']; } @@ -208,25 +245,33 @@ class HttpSocket extends CakeSocket { } $request['uri'] = $this->url($request['uri']); $request['uri'] = $this->_parseUri($request['uri'], true); - $this->request = Set::merge($this->request, $this->config['request'], $request); + $this->request = Set::merge($this->request, array_diff_key($this->config['request'], array('cookies' => true)), $request); - if (!$hadAuth && !empty($this->config['request']['auth']['user'])) { - $this->request['uri']['user'] = $this->config['request']['auth']['user']; - $this->request['uri']['pass'] = $this->config['request']['auth']['pass']; - } $this->_configUri($this->request['uri']); + $Host = $this->request['uri']['host']; + if (!empty($this->config['request']['cookies'][$Host])) { + if (!isset($this->request['cookies'])) { + $this->request['cookies'] = array(); + } + if (!isset($request['cookies'])) { + $request['cookies'] = array(); + } + $this->request['cookies'] = array_merge($this->request['cookies'], $this->config['request']['cookies'][$Host], $request['cookies']); + } + if (isset($host)) { $this->config['host'] = $host; } + $this->_setProxy(); + $this->request['proxy'] = $this->_proxy; + $cookies = null; if (is_array($this->request['header'])) { - $this->request['header'] = $this->_parseHeader($this->request['header']); if (!empty($this->request['cookies'])) { $cookies = $this->buildCookies($this->request['cookies']); } - $Host = $this->request['uri']['host']; $schema = ''; $port = 0; if (isset($this->request['uri']['schema'])) { @@ -245,12 +290,11 @@ class HttpSocket extends CakeSocket { $this->request['header'] = array_merge(compact('Host'), $this->request['header']); } - if (isset($this->request['auth']['user']) && isset($this->request['auth']['pass'])) { - $this->request['header']['Authorization'] = $this->request['auth']['method'] . " " . base64_encode($this->request['auth']['user'] . ":" . $this->request['auth']['pass']); - } - if (isset($this->request['uri']['user']) && isset($this->request['uri']['pass'])) { - $this->request['header']['Authorization'] = $this->request['auth']['method'] . " " . base64_encode($this->request['uri']['user'] . ":" . $this->request['uri']['pass']); + if (isset($this->request['uri']['user'], $this->request['uri']['pass'])) { + $this->configAuth('Basic', $this->request['uri']['user'], $this->request['uri']['pass']); } + $this->_setAuth(); + $this->request['auth'] = $this->_auth; if (is_array($this->request['body'])) { $this->request['body'] = $this->_httpSerialize($this->request['body']); @@ -275,9 +319,10 @@ class HttpSocket extends CakeSocket { } if ($this->quirksMode === false && $this->request['line'] === false) { - return $this->response = false; + return false; } + $this->request['raw'] = ''; if ($this->request['line'] !== false) { $this->request['raw'] = $this->request['line']; } @@ -291,20 +336,46 @@ class HttpSocket extends CakeSocket { $this->write($this->request['raw']); $response = null; + $inHeader = true; while ($data = $this->read()) { - $response .= $data; + if ($this->_contentResource) { + if ($inHeader) { + $response .= $data; + $pos = strpos($response, "\r\n\r\n"); + if ($pos !== false) { + $pos += 4; + $data = substr($response, $pos); + fwrite($this->_contentResource, $data); + + $response = substr($response, 0, $pos); + $inHeader = false; + } + } else { + fwrite($this->_contentResource, $data); + fflush($this->_contentResource); + } + } else { + $response .= $data; + } } - if ($connectionType == 'close') { + if ($connectionType === 'close') { $this->disconnect(); } - $this->response = $this->_parseResponse($response); - if (!empty($this->response['cookies'])) { - $this->config['request']['cookies'] = array_merge($this->config['request']['cookies'], $this->response['cookies']); + if (!App::import('Lib', $this->responseClass)) { + throw new SocketException(__('Class %s not found.', $this->responseClass)); + } + $responseClass = $this->responseClass; + $this->response = new $responseClass($response); + if (!empty($this->response->cookies)) { + if (!isset($this->config['request']['cookies'][$Host])) { + $this->config['request']['cookies'][$Host] = array(); + } + $this->config['request']['cookies'][$Host] = array_merge($this->config['request']['cookies'][$Host], $this->response->cookies); } - return $this->response['body']; + return $this->response; } /** @@ -394,7 +465,7 @@ class HttpSocket extends CakeSocket { } /** - * Normalizes urls into a $uriTemplate. If no template is provided + * Normalizes urls into a $uriTemplate. If no template is provided * a default one will be used. Will generate the url using the * current config information. * @@ -426,10 +497,10 @@ class HttpSocket extends CakeSocket { } if (is_string($url)) { if ($url{0} == '/') { - $url = $this->config['request']['uri']['host'].':'.$this->config['request']['uri']['port'] . $url; + $url = $this->config['request']['uri']['host'] . ':' . $this->config['request']['uri']['port'] . $url; } if (!preg_match('/^.+:\/\/|\*|^\//', $url)) { - $url = $this->config['request']['uri']['scheme'].'://'.$url; + $url = $this->config['request']['uri']['scheme'] . '://' . $url; } } elseif (!is_array($url) && !empty($url)) { return false; @@ -449,159 +520,57 @@ class HttpSocket extends CakeSocket { } /** - * Parses the given message and breaks it down in parts. + * Set authentication in request * - * @param string $message Message to parse - * @return array Parsed message (with indexed elements such as raw, status, header, body) + * @return void + * @throws SocketException */ - protected function _parseResponse($message) { - if (is_array($message)) { - return $message; - } elseif (!is_string($message)) { - return false; + protected function _setAuth() { + if (empty($this->_auth)) { + return; } - - static $responseTemplate; - - if (empty($responseTemplate)) { - $classVars = get_class_vars(__CLASS__); - $responseTemplate = $classVars['response']; + $method = key($this->_auth); + $authClass = Inflector::camelize($method) . 'Authentication'; + if (!App::import('Lib', 'http/' . $authClass)) { + throw new SocketException(__('Unknown authentication method.')); } - - $response = $responseTemplate; - - if (!preg_match("/^(.+\r\n)(.*)(?<=\r\n)\r\n/Us", $message, $match)) { - return false; + if (!method_exists($authClass, 'authentication')) { + throw new SocketException(sprintf(__('The %s do not support authentication.'), $authClass)); } - - list($null, $response['raw']['status-line'], $response['raw']['header']) = $match; - $response['raw']['response'] = $message; - $response['raw']['body'] = substr($message, strlen($match[0])); - - if (preg_match("/(.+) ([0-9]{3}) (.+)\r\n/DU", $response['raw']['status-line'], $match)) { - $response['status']['http-version'] = $match[1]; - $response['status']['code'] = (int)$match[2]; - $response['status']['reason-phrase'] = $match[3]; - } - - $response['header'] = $this->_parseHeader($response['raw']['header']); - $transferEncoding = null; - if (isset($response['header']['Transfer-Encoding'])) { - $transferEncoding = $response['header']['Transfer-Encoding']; - } - $decoded = $this->_decodeBody($response['raw']['body'], $transferEncoding); - $response['body'] = $decoded['body']; - - if (!empty($decoded['header'])) { - $response['header'] = $this->_parseHeader($this->_buildHeader($response['header']).$this->_buildHeader($decoded['header'])); - } - - if (!empty($response['header'])) { - $response['cookies'] = $this->parseCookies($response['header']); - } - - foreach ($response['raw'] as $field => $val) { - if ($val === '') { - $response['raw'][$field] = null; - } - } - - return $response; + call_user_func_array("$authClass::authentication", array($this, &$this->_auth[$method])); } /** - * Generic function to decode a $body with a given $encoding. Returns either an array with the keys - * 'body' and 'header' or false on failure. + * Set the proxy configuration and authentication * - * @param string $body A string continaing the body to decode. - * @param mixed $encoding Can be false in case no encoding is being used, or a string representing the encoding. - * @return mixed Array of response headers and body or false. + * @return void + * @throws SocketException */ - protected function _decodeBody($body, $encoding = 'chunked') { - if (!is_string($body)) { - return false; + protected function _setProxy() { + if (empty($this->_proxy) || !isset($this->_proxy['host'], $this->_proxy['port'])) { + return; } - if (empty($encoding)) { - return array('body' => $body, 'header' => false); + $this->config['host'] = $this->_proxy['host']; + $this->config['port'] = $this->_proxy['port']; + + if (empty($this->_proxy['method']) || !isset($this->_proxy['user'], $this->_proxy['pass'])) { + return; } - $decodeMethod = '_decode'.Inflector::camelize(str_replace('-', '_', $encoding)).'Body'; - - if (!is_callable(array(&$this, $decodeMethod))) { - if (!$this->quirksMode) { - trigger_error(__('HttpSocket::_decodeBody - Unknown encoding: %s. Activate quirks mode to surpress error.', h($encoding)), E_USER_WARNING); - } - return array('body' => $body, 'header' => false); + $authClass = Inflector::camelize($this->_proxy['method']) . 'Authentication'; + if (!App::import('Lib', 'http/' . $authClass)) { + throw new SocketException(__('Unknown authentication method for proxy.')); } - return $this->{$decodeMethod}($body); - } - -/** - * Decodes a chunked message $body and returns either an array with the keys 'body' and 'header' or false as - * a result. - * - * @param string $body A string continaing the chunked body to decode. - * @return mixed Array of response headers and body or false. - */ - protected function _decodeChunkedBody($body) { - if (!is_string($body)) { - return false; + if (!method_exists($authClass, 'proxyAuthentication')) { + throw new SocketException(sprintf(__('The %s do not support proxy authentication.'), $authClass)); } - - $decodedBody = null; - $chunkLength = null; - - while ($chunkLength !== 0) { - if (!preg_match("/^([0-9a-f]+) *(?:;(.+)=(.+))?\r\n/iU", $body, $match)) { - if (!$this->quirksMode) { - trigger_error(__('HttpSocket::_decodeChunkedBody - Could not parse malformed chunk. Activate quirks mode to do this.'), E_USER_WARNING); - return false; - } - break; - } - - $chunkSize = 0; - $hexLength = 0; - $chunkExtensionName = ''; - $chunkExtensionValue = ''; - if (isset($match[0])) { - $chunkSize = $match[0]; - } - if (isset($match[1])) { - $hexLength = $match[1]; - } - if (isset($match[2])) { - $chunkExtensionName = $match[2]; - } - if (isset($match[3])) { - $chunkExtensionValue = $match[3]; - } - - $body = substr($body, strlen($chunkSize)); - $chunkLength = hexdec($hexLength); - $chunk = substr($body, 0, $chunkLength); - if (!empty($chunkExtensionName)) { - /** - * @todo See if there are popular chunk extensions we should implement - */ - } - $decodedBody .= $chunk; - if ($chunkLength !== 0) { - $body = substr($body, $chunkLength+strlen("\r\n")); - } - } - - $entityHeader = false; - if (!empty($body)) { - $entityHeader = $this->_parseHeader($body); - } - return array('body' => $decodedBody, 'header' => $entityHeader); + call_user_func_array("$authClass::proxyAuthentication", array($this, &$this->_proxy)); } /** * Parses and sets the specified URI into current request configuration. * * @param mixed $uri URI, See HttpSocket::_parseUri() - * @return array Current configuration settings + * @return boolean If uri has merged in config */ protected function _configUri($uri = null) { if (empty($uri)) { @@ -619,19 +588,18 @@ class HttpSocket extends CakeSocket { } $config = array( 'request' => array( - 'uri' => array_intersect_key($uri, $this->config['request']['uri']), - 'auth' => array_intersect_key($uri, $this->config['request']['auth']) + 'uri' => array_intersect_key($uri, $this->config['request']['uri']) ) ); $this->config = Set::merge($this->config, $config); $this->config = Set::merge($this->config, array_intersect_key($this->config['request']['uri'], $this->config)); - return $this->config; + return true; } /** * Takes a $uri array and turns it into a fully qualified URL string * - * @param mixed $uri Either A $uri array, or a request string. Will use $this->config if left empty. + * @param mixed $uri Either A $uri array, or a request string. Will use $this->config if left empty. * @param string $uriTemplate The Uri template/format to use. * @return mixed A fully qualified URL formated according to $uriTemplate, or false on failure */ @@ -665,7 +633,7 @@ class HttpSocket extends CakeSocket { $uriTemplate = str_replace(':%port', null, $uriTemplate); } foreach ($uri as $property => $value) { - $uriTemplate = str_replace('%'.$property, $value, $uriTemplate); + $uriTemplate = str_replace('%' . $property, $value, $uriTemplate); } if ($uriTemplate === '/*') { @@ -740,7 +708,7 @@ class HttpSocket extends CakeSocket { * - ?key[subKey]=value * - ?key[]=value1&key[]=value2 * - * A leading '?' mark in $query is optional and does not effect the outcome of this function. + * A leading '?' mark in $query is optional and does not effect the outcome of this function. * For the complete capabilities of this implementation take a look at HttpSocketTest::testparseQuery() * * @param mixed $query A query string to parse into an array or an array to return directly "as is" @@ -803,6 +771,7 @@ class HttpSocket extends CakeSocket { * @param array $request Needs to contain a 'uri' key. Should also contain a 'method' key, otherwise defaults to GET. * @param string $versionToken The version token to use, defaults to HTTP/1.1 * @return string Request line + * @throws SocketException */ protected function _buildRequestLine($request = array(), $versionToken = 'HTTP/1.1') { $asteriskMethods = array('OPTIONS'); @@ -810,8 +779,7 @@ class HttpSocket extends CakeSocket { if (is_string($request)) { $isValid = preg_match("/(.+) (.+) (.+)\r\n/U", $request, $match); if (!$this->quirksMode && (!$isValid || ($match[2] == '*' && !in_array($match[3], $asteriskMethods)))) { - trigger_error(__('HttpSocket::_buildRequestLine - Passed an invalid request line string. Activate quirks mode to do this.'), E_USER_WARNING); - return false; + throw new SocketException(__('HttpSocket::_buildRequestLine - Passed an invalid request line string. Activate quirks mode to do this.')); } return $request; } elseif (!is_array($request)) { @@ -822,13 +790,16 @@ class HttpSocket extends CakeSocket { $request['uri'] = $this->_parseUri($request['uri']); $request = array_merge(array('method' => 'GET'), $request); - $request['uri'] = $this->_buildUri($request['uri'], '/%path?%query'); + if (!empty($this->_proxy['host'])) { + $request['uri'] = $this->_buildUri($request['uri'], '%scheme://%host:%port/%path?%query'); + } else { + $request['uri'] = $this->_buildUri($request['uri'], '/%path?%query'); + } if (!$this->quirksMode && $request['uri'] === '*' && !in_array($request['method'], $asteriskMethods)) { - trigger_error(__('HttpSocket::_buildRequestLine - The "*" asterisk character is only allowed for the following methods: %s. Activate quirks mode to work outside of HTTP/1.1 specs.', implode(',', $asteriskMethods)), E_USER_WARNING); - return false; + throw new SocketException(__('HttpSocket::_buildRequestLine - The "*" asterisk character is only allowed for the following methods: %s. Activate quirks mode to work outside of HTTP/1.1 specs.', implode(',', $asteriskMethods))); } - return $request['method'].' '.$request['uri'].' '.$versionToken.$this->lineBreak; + return $request['method'] . ' ' . $request['uri'] . ' ' . $versionToken . "\r\n"; } /** @@ -851,6 +822,7 @@ class HttpSocket extends CakeSocket { * Builds the header. * * @param array $header Header to build + * @param string $mode * @return string Header built from array */ protected function _buildHeader($header, $mode = 'standard') { @@ -860,6 +832,17 @@ class HttpSocket extends CakeSocket { return false; } + $fieldsInHeader = array(); + foreach ($header as $key => $value) { + $lowKey = strtolower($key); + if (array_key_exists($lowKey, $fieldsInHeader)) { + $header[$fieldsInHeader[$lowKey]] = $value; + unset($header[$key]); + } else { + $fieldsInHeader[$lowKey] = $key; + } + } + $returnHeader = ''; foreach ($header as $field => $contents) { if (is_array($contents) && $mode == 'standard') { @@ -869,144 +852,37 @@ class HttpSocket extends CakeSocket { $contents = preg_replace("/\r\n(?![\t ])/", "\r\n ", $content); $field = $this->_escapeToken($field); - $returnHeader .= $field.': '.$contents.$this->lineBreak; + $returnHeader .= $field . ': ' . $contents . "\r\n"; } } return $returnHeader; } -/** - * Parses an array based header. - * - * @param array $header Header as an indexed array (field => value) - * @return array Parsed header - */ - protected function _parseHeader($header) { - if (is_array($header)) { - foreach ($header as $field => $value) { - unset($header[$field]); - $field = strtolower($field); - preg_match_all('/(?:^|(?<=-))[a-z]/U', $field, $offsets, PREG_OFFSET_CAPTURE); - - foreach ($offsets[0] as $offset) { - $field = substr_replace($field, strtoupper($offset[0]), $offset[1], 1); - } - $header[$field] = $value; - } - return $header; - } elseif (!is_string($header)) { - return false; - } - - preg_match_all("/(.+):(.+)(?:(?lineBreak . "|\$)/Uis", $header, $matches, PREG_SET_ORDER); - - $header = array(); - foreach ($matches as $match) { - list(, $field, $value) = $match; - - $value = trim($value); - $value = preg_replace("/[\t ]\r\n/", "\r\n", $value); - - $field = $this->_unescapeToken($field); - - $field = strtolower($field); - preg_match_all('/(?:^|(?<=-))[a-z]/U', $field, $offsets, PREG_OFFSET_CAPTURE); - foreach ($offsets[0] as $offset) { - $field = substr_replace($field, strtoupper($offset[0]), $offset[1], 1); - } - - if (!isset($header[$field])) { - $header[$field] = $value; - } else { - $header[$field] = array_merge((array)$header[$field], (array)$value); - } - } - return $header; - } - -/** - * Parses cookies in response headers. - * - * @param array $header Header array containing one ore more 'Set-Cookie' headers. - * @return mixed Either false on no cookies, or an array of cookies recieved. - * @access public - * @todo Make this 100% RFC 2965 confirm - */ - function parseCookies($header) { - if (!isset($header['Set-Cookie'])) { - return false; - } - - $cookies = array(); - foreach ((array)$header['Set-Cookie'] as $cookie) { - if (strpos($cookie, '";"') !== false) { - $cookie = str_replace('";"', "{__cookie_replace__}", $cookie); - $parts = str_replace("{__cookie_replace__}", '";"', explode(';', $cookie)); - } else { - $parts = preg_split('/\;[ \t]*/', $cookie); - } - - list($name, $value) = explode('=', array_shift($parts), 2); - $cookies[$name] = compact('value'); - - foreach ($parts as $part) { - if (strpos($part, '=') !== false) { - list($key, $value) = explode('=', $part); - } else { - $key = $part; - $value = true; - } - - $key = strtolower($key); - if (!isset($cookies[$name][$key])) { - $cookies[$name][$key] = $value; - } - } - } - return $cookies; - } - /** * Builds cookie headers for a request. * * @param array $cookies Array of cookies to send with the request. * @return string Cookie header string to be sent with the request. - * @access public * @todo Refactor token escape mechanism to be configurable */ - function buildCookies($cookies) { + public function buildCookies($cookies) { $header = array(); foreach ($cookies as $name => $cookie) { - $header[] = $name.'='.$this->_escapeToken($cookie['value'], array(';')); + $header[] = $name . '=' . $this->_escapeToken($cookie['value'], array(';')); } - $header = $this->_buildHeader(array('Cookie' => implode('; ', $header)), 'pragmatic'); - return $header; - } - -/** - * Unescapes a given $token according to RFC 2616 (HTTP 1.1 specs) - * - * @param string $token Token to unescape - * @return string Unescaped token - * @access protected - * @todo Test $chars parameter - */ - function _unescapeToken($token, $chars = null) { - $regex = '/"(['.join('', $this->_tokenEscapeChars(true, $chars)).'])"/'; - $token = preg_replace($regex, '\\1', $token); - return $token; + return $this->_buildHeader(array('Cookie' => implode('; ', $header)), 'pragmatic'); } /** * Escapes a given $token according to RFC 2616 (HTTP 1.1 specs) * * @param string $token Token to escape + * @param array $chars * @return string Escaped token - * @access protected * @todo Test $chars parameter */ - function _escapeToken($token, $chars = null) { - $regex = '/(['.join('', $this->_tokenEscapeChars(true, $chars)).'])/'; + protected function _escapeToken($token, $chars = null) { + $regex = '/([' . implode('', $this->_tokenEscapeChars(true, $chars)) . '])/'; $token = preg_replace($regex, '"\\1"', $token); return $token; } @@ -1015,11 +891,11 @@ class HttpSocket extends CakeSocket { * Gets escape chars according to RFC 2616 (HTTP 1.1 specs). * * @param boolean $hex true to get them as HEX values, false otherwise + * @param array $chars * @return array Escape chars - * @access protected * @todo Test $chars parameter */ - function _tokenEscapeChars($hex = true, $chars = null) { + protected function _tokenEscapeChars($hex = true, $chars = null) { if (!empty($chars)) { $escape = $chars; } else { @@ -1035,7 +911,7 @@ class HttpSocket extends CakeSocket { } $regexChars = ''; foreach ($escape as $key => $char) { - $escape[$key] = '\\x'.str_pad(dechex(ord($char)), 2, '0', STR_PAD_LEFT); + $escape[$key] = '\\x' . str_pad(dechex(ord($char)), 2, '0', STR_PAD_LEFT); } return $escape; } @@ -1052,7 +928,7 @@ class HttpSocket extends CakeSocket { if (empty($initalState)) { $initalState = get_class_vars(__CLASS__); } - if ($full == false) { + if (!$full) { $this->request = $initalState['request']; $this->response = $initalState['response']; return true; diff --git a/cake/libs/i18n.php b/cake/libs/i18n.php index 05ec9c9e8..63cc47b19 100644 --- a/cake/libs/i18n.php +++ b/cake/libs/i18n.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 1.2.0.4116 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -27,8 +26,7 @@ App::import('Core', 'Multibyte'); /** * I18n handles translation of Text and time format strings. * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs */ class I18n { diff --git a/cake/libs/inflector.php b/cake/libs/inflector.php index d1bf78cfa..0e3eb0278 100644 --- a/cake/libs/inflector.php +++ b/cake/libs/inflector.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -26,8 +25,7 @@ * Inflector pluralizes and singularizes English nouns. * Used by Cake's naming conventions throughout the framework. * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @link http://book.cakephp.org/view/1478/Inflector */ class Inflector { diff --git a/cake/libs/l10n.php b/cake/libs/l10n.php index 4f5868412..2da41af34 100644 --- a/cake/libs/l10n.php +++ b/cake/libs/l10n.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 1.2.0.4116 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Core', 'CakeRequest'); /** * Localization * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs */ class L10n { diff --git a/cake/libs/log/file_log.php b/cake/libs/log/file_log.php index fbd4cff3e..c7adb306d 100644 --- a/cake/libs/log/file_log.php +++ b/cake/libs/log/file_log.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.log + * @package cake.libs.log * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ * File Storage stream for Logging. Writes logs to different files * based on the type of log it is. * - * @package cake - * @subpackage cake.cake.libs.log + * @package cake.libs.log */ class FileLog implements CakeLogInterface { diff --git a/cake/libs/magic_db.php b/cake/libs/magic_db.php index 1a3143b4e..86a91d82d 100644 --- a/cake/libs/magic_db.php +++ b/cake/libs/magic_db.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 1.2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -27,8 +26,7 @@ if (!class_exists('File')) { /** * A class to parse and use the MagicDb for file type analysis * - * @package cake.tests - * @subpackage cake.tests.cases.libs + * @package cake.libs */ class MagicDb extends Object { @@ -172,8 +170,7 @@ class MagicDb extends Object { /** * undocumented class * - * @package cake.tests - * @subpackage cake.tests.cases.libs + * @package cake.libs */ class MagicFileResource extends Object{ diff --git a/cake/libs/model/app_model.php b/cake/libs/model/app_model.php index e18dca1c1..4af1eb2e5 100644 --- a/cake/libs/model/app_model.php +++ b/cake/libs/model/app_model.php @@ -15,8 +15,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.model + * @package cake.libs.model * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -28,8 +27,7 @@ * Create the same file in app/app_model.php * Add your application-wide methods to the class, your models will inherit them. * - * @package cake - * @subpackage cake.cake.libs.model + * @package cake.libs.model */ class AppModel extends Model { } diff --git a/cake/libs/model/behavior_collection.php b/cake/libs/model/behavior_collection.php index b5fbfe0f0..965c315f4 100644 --- a/cake/libs/model/behavior_collection.php +++ b/cake/libs/model/behavior_collection.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.model + * @package cake.libs.model * @since CakePHP(tm) v 1.2.0.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -26,8 +25,7 @@ App::import('Core', 'ObjectCollection'); * * Defines the Behavior interface, and contains common model interaction functionality. * - * @package cake - * @subpackage cake.cake.libs.model + * @package cake.libs.model */ class BehaviorCollection extends ObjectCollection { @@ -44,14 +42,14 @@ class BehaviorCollection extends ObjectCollection { * * @var array */ - private $__methods = array(); + protected $_methods = array(); /** * Keeps a list of all methods which have been mapped with regular expressions * * @var array */ - private $__mappedMethods = array(); + protected $_mappedMethods = array(); /** * Attaches a model object and loads a list of behaviors @@ -130,7 +128,7 @@ class BehaviorCollection extends ObjectCollection { $this->_loaded[$name]->setup(ClassRegistry::getObject($this->modelName), $config); foreach ($this->_loaded[$name]->mapMethods as $method => $alias) { - $this->__mappedMethods[$method] = array($alias, $name); + $this->_mappedMethods[$method] = array($name, $alias); } $methods = get_class_methods($this->_loaded[$name]); $parentMethods = array_flip(get_class_methods('ModelBehavior')); @@ -142,11 +140,11 @@ class BehaviorCollection extends ObjectCollection { foreach ($methods as $m) { if (!isset($parentMethods[$m])) { $methodAllowed = ( - $m[0] != '_' && !array_key_exists($m, $this->__methods) && + $m[0] != '_' && !array_key_exists($m, $this->_methods) && !in_array($m, $callbacks) ); if ($methodAllowed) { - $this->__methods[$m] = array($m, $name); + $this->_methods[$m] = array($name, $m); } } } @@ -172,9 +170,9 @@ class BehaviorCollection extends ObjectCollection { $this->_loaded[$name]->cleanup(ClassRegistry::getObject($this->modelName)); unset($this->_loaded[$name]); } - foreach ($this->__methods as $m => $callback) { - if (is_array($callback) && $callback[1] == $name) { - unset($this->__methods[$m]); + foreach ($this->_methods as $m => $callback) { + if (is_array($callback) && $callback[0] == $name) { + unset($this->_methods[$m]); } } $this->_enabled = array_values(array_diff($this->_enabled, (array)$name)); @@ -192,88 +190,70 @@ class BehaviorCollection extends ObjectCollection { } /** - * Dispatches a behavior method + * Dispatches a behavior method. Will call either normal methods or mapped methods. * + * If a method is not handeled by the BehaviorCollection, and $strict is false, a + * special return of `array('unhandled')` will be returned to signal the method was not found. + * + * @param Model $model The model the method was originally called on. + * @param string $method The method called. + * @param array $params Parameters for the called method. + * @param boolean $strict If methods are not found, trigger an error. * @return array All methods for all behaviors attached to this object */ - public function dispatchMethod(&$model, $method, $params = array(), $strict = false) { - $methods = array_keys($this->__methods); - $check = array_flip($methods); - $found = isset($check[$method]); - $call = null; - - if ($strict && !$found) { + public function dispatchMethod($model, $method, $params = array(), $strict = false) { + $method = $this->hasMethod($method, true); + + if ($strict && empty($method)) { trigger_error(__("BehaviorCollection::dispatchMethod() - Method %s not found in any attached behavior", $method), E_USER_WARNING); return null; - } elseif ($found) { - $methods = array_combine($methods, array_values($this->__methods)); - $call = $methods[$method]; - } else { - $count = count($this->__mappedMethods); - $mapped = array_keys($this->__mappedMethods); - - for ($i = 0; $i < $count; $i++) { - if (preg_match($mapped[$i] . 'i', $method)) { - $call = $this->__mappedMethods[$mapped[$i]]; - array_unshift($params, $method); - break; - } - } } - - if (!empty($call)) { - return call_user_func_array( - array(&$this->_loaded[$call[1]], $call[0]), - array_merge(array(&$model), $params) - ); + if (empty($method)) { + return array('unhandled'); } - return array('unhandled'); - } - -/** - * Dispatches a behavior callback on all attached behavior objects - * - * @param model $model - * @param string $callback - * @param array $params - * @param array $options - * @return mixed - */ - public function trigger(&$model, $callback, $params = array(), $options = array()) { - if (empty($this->_enabled)) { - return true; + if (count($method) === 3) { + array_unshift($params, $method[2]); + unset($method[2]); } - $options = array_merge( - array('break' => false, 'breakOn' => array(null, false), 'modParams' => false), - $options + return call_user_func_array( + array($this->_loaded[$method[0]], $method[1]), + array_merge(array(&$model), $params) ); - foreach ($this->_enabled as $name) { - $result = call_user_func_array( - array(&$this->_loaded[$name], $callback), - array_merge(array(&$model), $params) - ); - if ( - $options['break'] && ($result === $options['breakOn'] || - (is_array($options['breakOn']) && in_array($result, $options['breakOn'], true))) - ) { - return $result; - } elseif ($options['modParams'] && is_array($result)) { - $params[0] = $result; - } - } - if ($options['modParams'] && isset($params[0])) { - return $params[0]; - } - return true; } /** - * Gets the method list for attached behaviors, i.e. all public, non-callback methods + * Gets the method list for attached behaviors, i.e. all public, non-callback methods. + * This does not include mappedMethods. * * @return array All public methods for all behaviors attached to this collection */ public function methods() { - return $this->__methods; + return $this->_methods; } -} \ No newline at end of file +/** + * Check to see if a behavior in this collection implements the provided method. Will + * also check mappedMethods. + * + * @param string $method The method to find. + * @param boolean $callback Return the callback for the method. + * @return mixed If $callback is false, a boolean will be returnned, if its true, an array + * containing callback information will be returnned. For mapped methods the array will have 3 elements. + */ + public function hasMethod($method, $callback = false) { + if (isset($this->_methods[$method])) { + return $callback ? $this->_methods[$method] : true; + } + foreach ($this->_mappedMethods as $pattern => $target) { + if (preg_match($pattern . 'i', $method)) { + if ($callback) { + $target[] = $method; + return $target; + } + return true; + } + } + return false; + } + +} diff --git a/cake/libs/model/behaviors/acl.php b/cake/libs/model/behaviors/acl.php index dd8647557..b03586657 100644 --- a/cake/libs/model/behaviors/acl.php +++ b/cake/libs/model/behaviors/acl.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.cake.libs.model.behaviors + * @package cake.libs.model.behaviors * @since CakePHP v 1.2.0.4487 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ /** * ACL behavior * - * @package cake - * @subpackage cake.cake.libs.model.behaviors + * @package cake.libs.model.behaviors * @link http://book.cakephp.org/view/1320/ACL */ class AclBehavior extends ModelBehavior { @@ -43,7 +41,7 @@ class AclBehavior extends ModelBehavior { * @param mixed $config * @return void */ - public function setup(&$model, $config = array()) { + public function setup($model, $config = array()) { if (is_string($config)) { $config = array('type' => $config); } @@ -67,7 +65,7 @@ class AclBehavior extends ModelBehavior { * @return array * @link http://book.cakephp.org/view/1322/node */ - public function node(&$model, $ref = null) { + public function node($model, $ref = null) { $type = $this->__typeMaps[$this->settings[$model->name]['type']]; if (empty($ref)) { $ref = array('model' => $model->name, 'foreign_key' => $model->id); @@ -81,7 +79,7 @@ class AclBehavior extends ModelBehavior { * @param boolean $created True if this is a new record * @return void */ - public function afterSave(&$model, $created) { + public function afterSave($model, $created) { $type = $this->__typeMaps[$this->settings[$model->name]['type']]; $parent = $model->parentNode(); if (!empty($parent)) { @@ -105,7 +103,7 @@ class AclBehavior extends ModelBehavior { * * @return void */ - public function afterDelete(&$model) { + public function afterDelete($model) { $type = $this->__typeMaps[$this->settings[$model->name]['type']]; $node = Set::extract($this->node($model), "0.{$type}.id"); if (!empty($node)) { diff --git a/cake/libs/model/behaviors/containable.php b/cake/libs/model/behaviors/containable.php index 624c467f0..03963a723 100644 --- a/cake/libs/model/behaviors/containable.php +++ b/cake/libs/model/behaviors/containable.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.libs * @since CakePHP(tm) v 1.2.0.5669 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,8 +23,7 @@ * Behavior to allow for dynamic and atomic manipulation of a Model's associations used for a find call. Most useful for limiting * the amount of associations and data returned. * - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.libs * @link http://book.cakephp.org/view/1323/Containable */ class ContainableBehavior extends ModelBehavior { @@ -63,7 +61,7 @@ class ContainableBehavior extends ModelBehavior { * @param object $Model Model using the behavior * @param array $settings Settings to override for model. */ - public function setup(&$Model, $settings = array()) { + public function setup($Model, $settings = array()) { if (!isset($this->settings[$Model->alias])) { $this->settings[$Model->alias] = array('recursive' => true, 'notices' => true, 'autoFields' => true); } @@ -94,9 +92,12 @@ class ContainableBehavior extends ModelBehavior { * @param array $query Query parameters as set by cake * @return array */ - public function beforeFind(&$Model, $query) { + public function beforeFind($Model, $query) { $reset = (isset($query['reset']) ? $query['reset'] : true); - $noContain = ((isset($this->runtime[$Model->alias]['contain']) && empty($this->runtime[$Model->alias]['contain'])) || (isset($query['contain']) && empty($query['contain']))); + $noContain = ( + (isset($this->runtime[$Model->alias]['contain']) && empty($this->runtime[$Model->alias]['contain'])) || + (isset($query['contain']) && empty($query['contain'])) + ); $contain = array(); if (isset($this->runtime[$Model->alias]['contain'])) { $contain = $this->runtime[$Model->alias]['contain']; @@ -105,7 +106,10 @@ class ContainableBehavior extends ModelBehavior { if (isset($query['contain'])) { $contain = array_merge($contain, (array)$query['contain']); } - if ($noContain || !$contain || in_array($contain, array(null, false), true) || (isset($contain[0]) && $contain[0] === null)) { + if ( + $noContain || !$contain || in_array($contain, array(null, false), true) || + (isset($contain[0]) && $contain[0] === null) + ) { if ($noContain) { $query['recursive'] = -1; } @@ -177,6 +181,7 @@ class ContainableBehavior extends ModelBehavior { $autoFields = ($this->settings[$Model->alias]['autoFields'] && !in_array($Model->findQueryType, array('list', 'count')) && !empty($query['fields'])); + if (!$autoFields) { return $query; } @@ -225,7 +230,7 @@ class ContainableBehavior extends ModelBehavior { * @param array $results Results of the find operation * @param bool $primary true if this is the primary model that issued the find operation, false otherwise */ - public function afterFind(&$Model, $results, $primary) { + public function afterFind($Model, $results, $primary) { if (!empty($Model->__backContainableAssociation)) { foreach ($Model->__backContainableAssociation as $relation => $bindings) { $Model->{$relation} = $bindings; @@ -242,7 +247,7 @@ class ContainableBehavior extends ModelBehavior { * @return void * @link http://book.cakephp.org/view/1323/Containable#Using-Containable-1324 */ - public function contain(&$Model) { + public function contain($Model) { $args = func_get_args(); $contain = call_user_func_array('am', array_slice($args, 1)); $this->runtime[$Model->alias]['contain'] = $contain; @@ -256,7 +261,7 @@ class ContainableBehavior extends ModelBehavior { * @param object $Model Model on which to reset bindings * @return void */ - public function resetBindings(&$Model) { + public function resetBindings($Model) { if (!empty($Model->__backOriginalAssociation)) { $Model->__backAssociation = $Model->__backOriginalAssociation; unset($Model->__backOriginalAssociation); @@ -264,7 +269,7 @@ class ContainableBehavior extends ModelBehavior { $Model->resetAssociations(); if (!empty($Model->__backInnerAssociation)) { $assocs = $Model->__backInnerAssociation; - unset($Model->__backInnerAssociation); + $Model->__backInnerAssociation = array(); foreach ($assocs as $currentModel) { $this->resetBindings($Model->$currentModel); } @@ -280,7 +285,7 @@ class ContainableBehavior extends ModelBehavior { * @param bool $throwErrors Wether unexisting bindings show throw errors * @return array Containments */ - public function containments(&$Model, $contain, $containments = array(), $throwErrors = null) { + public function containments($Model, $contain, $containments = array(), $throwErrors = null) { $options = array('className', 'joinTable', 'with', 'foreignKey', 'associationForeignKey', 'conditions', 'fields', 'order', 'limit', 'offset', 'unique', 'finderQuery', 'deleteQuery', 'insertQuery'); $keep = array(); $depth = array(); @@ -383,7 +388,7 @@ class ContainableBehavior extends ModelBehavior { * @param mixed $fields If array, fields to initially load, if false use $Model as primary model * @return array Fields */ - public function fieldDependencies(&$Model, $map, $fields = array()) { + public function fieldDependencies($Model, $map, $fields = array()) { if ($fields === false) { foreach ($map as $parent => $children) { foreach ($children as $type => $bindings) { diff --git a/cake/libs/model/behaviors/translate.php b/cake/libs/model/behaviors/translate.php index 7397767d0..3f0c462d5 100644 --- a/cake/libs/model/behaviors/translate.php +++ b/cake/libs/model/behaviors/translate.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.model.behaviors + * @package cake.libs.model.behaviors * @since CakePHP(tm) v 1.2.0.4525 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Translate behavior * - * @package cake - * @subpackage cake.cake.libs.model.behaviors + * @package cake.libs.model.behaviors * @link http://book.cakephp.org/view/1328/Translate */ class TranslateBehavior extends ModelBehavior { @@ -51,7 +49,7 @@ class TranslateBehavior extends ModelBehavior { * @param array $config Array of configuration information. * @return mixed */ - public function setup(&$model, $config = array()) { + public function setup($model, $config = array()) { $db = ConnectionManager::getDataSource($model->useDbConfig); if (!$db->connected) { trigger_error( @@ -73,7 +71,7 @@ class TranslateBehavior extends ModelBehavior { * @param Model $model Model being detached. * @return void */ - public function cleanup(&$model) { + public function cleanup($model) { $this->unbindTranslation($model); unset($this->settings[$model->alias]); unset($this->runtime[$model->alias]); @@ -86,7 +84,8 @@ class TranslateBehavior extends ModelBehavior { * @param array $query Array of Query parameters. * @return array Modified query */ - public function beforeFind(&$model, $query) { + public function beforeFind($model, $query) { + $this->runtime[$model->alias]['virtualFields'] = $model->virtualFields; $locale = $this->_getLocale($model); if (empty($locale)) { return $query; @@ -113,48 +112,28 @@ class TranslateBehavior extends ModelBehavior { ); return $query; } - $autoFields = false; - if (empty($query['fields'])) { - $query['fields'] = array($model->alias.'.*'); - - $recursive = $model->recursive; - if (isset($query['recursive'])) { - $recursive = $query['recursive']; - } - - if ($recursive >= 0) { - foreach (array('hasOne', 'belongsTo') as $type) { - foreach ($model->{$type} as $key => $value) { - - if (empty($value['fields'])) { - $query['fields'][] = $key.'.*'; - } else { - foreach ($value['fields'] as $field) { - $query['fields'][] = $key.'.'.$field; - } - } - } - } - } - $autoFields = true; - } $fields = array_merge($this->settings[$model->alias], $this->runtime[$model->alias]['fields']); $addFields = array(); - if (is_array($query['fields'])) { + if (empty($query['fields'])) { + $addFields = $fields; + } else if (is_array($query['fields'])) { foreach ($fields as $key => $value) { $field = (is_numeric($key)) ? $value : $key; - if (in_array($model->alias.'.*', $query['fields']) || $autoFields || in_array($model->alias.'.'.$field, $query['fields']) || in_array($field, $query['fields'])) { + if (in_array($model->alias.'.*', $query['fields']) || in_array($model->alias.'.'.$field, $query['fields']) || in_array($field, $query['fields'])) { $addFields[] = $field; } } } + $this->runtime[$model->alias]['virtualFields'] = $model->virtualFields; if ($addFields) { - foreach ($addFields as $field) { - foreach (array($field, $model->alias.'.'.$field) as $_field) { - $key = array_search($_field, $query['fields']); + foreach ($addFields as $_f => $field) { + $aliasField = is_numeric($_f) ? $field : $_f; + + foreach (array($aliasField, $model->alias.'.'.$aliasField) as $_field) { + $key = array_search($_field, (array)$query['fields']); if ($key !== false) { unset($query['fields'][$key]); @@ -163,7 +142,10 @@ class TranslateBehavior extends ModelBehavior { if (is_array($locale)) { foreach ($locale as $_locale) { - $query['fields'][] = 'I18n__'.$field.'__'.$_locale.'.content'; + $model->virtualFields['i18n_'.$field.'_'.$_locale] = 'I18n__'.$field.'__'.$_locale.'.content'; + if (!empty($query['fields'])) { + $query['fields'][] = 'i18n_'.$field.'_'.$_locale; + } $query['joins'][] = array( 'type' => 'LEFT', 'alias' => 'I18n__'.$field.'__'.$_locale, @@ -171,13 +153,16 @@ class TranslateBehavior extends ModelBehavior { 'conditions' => array( $model->alias . '.' . $model->primaryKey => $db->identifier("I18n__{$field}__{$_locale}.foreign_key"), 'I18n__'.$field.'__'.$_locale.'.model' => $model->name, - 'I18n__'.$field.'__'.$_locale.'.'.$RuntimeModel->displayField => $field, + 'I18n__'.$field.'__'.$_locale.'.'.$RuntimeModel->displayField => $aliasField, 'I18n__'.$field.'__'.$_locale.'.locale' => $_locale ) ); } } else { - $query['fields'][] = 'I18n__'.$field.'.content'; + $model->virtualFields['i18n_'.$field] = 'I18n__'.$field.'.content'; + if (!empty($query['fields'])) { + $query['fields'][] = 'i18n_'.$field; + } $query['joins'][] = array( 'type' => 'LEFT', 'alias' => 'I18n__'.$field, @@ -185,7 +170,7 @@ class TranslateBehavior extends ModelBehavior { 'conditions' => array( $model->alias . '.' . $model->primaryKey => $db->identifier("I18n__{$field}.foreign_key"), 'I18n__'.$field.'.model' => $model->name, - 'I18n__'.$field.'.'.$RuntimeModel->displayField => $field + 'I18n__'.$field.'.'.$RuntimeModel->displayField => $aliasField ) ); @@ -197,9 +182,6 @@ class TranslateBehavior extends ModelBehavior { } } } - if (is_array($query['fields'])) { - $query['fields'] = array_merge($query['fields']); - } $this->runtime[$model->alias]['beforeFind'] = $addFields; return $query; } @@ -212,8 +194,9 @@ class TranslateBehavior extends ModelBehavior { * @param boolean $primary Did the find originate on $model. * @return array Modified results */ - public function afterFind(&$model, $results, $primary) { - $this->runtime[$model->alias]['fields'] = array(); + public function afterFind($model, $results, $primary) { + $model->virtualFields = $this->runtime[$model->alias]['virtualFields']; + $this->runtime[$model->alias]['virtualFields'] = $this->runtime[$model->alias]['fields'] = array(); $locale = $this->_getLocale($model); if (empty($locale) || empty($results) || empty($this->runtime[$model->alias]['beforeFind'])) { @@ -221,28 +204,30 @@ class TranslateBehavior extends ModelBehavior { } $beforeFind = $this->runtime[$model->alias]['beforeFind']; - foreach ($results as $key => $row) { - $results[$key][$model->alias]['locale'] = (is_array($locale)) ? @$locale[0] : $locale; + foreach ($results as $key => &$row) { + $results[$key][$model->alias]['locale'] = (is_array($locale)) ? current($locale) : $locale; + foreach ($beforeFind as $_f => $field) { + $aliasField = is_numeric($_f) ? $field : $_f; - foreach ($beforeFind as $field) { if (is_array($locale)) { foreach ($locale as $_locale) { - if (!isset($results[$key][$model->alias][$field]) && !empty($results[$key]['I18n__'.$field.'__'.$_locale]['content'])) { - $results[$key][$model->alias][$field] = $results[$key]['I18n__'.$field.'__'.$_locale]['content']; + if (!isset($row[$model->alias][$aliasField]) && !empty($row[$model->alias]['i18n_'.$field.'_'.$_locale])) { + $row[$model->alias][$aliasField] = $row[$model->alias]['i18n_'.$field.'_'.$_locale]; + $row[$model->alias]['locale'] = $_locale; } - unset($results[$key]['I18n__'.$field.'__'.$_locale]); + unset($row[$model->alias]['i18n_'.$field.'_'.$_locale]); } - if (!isset($results[$key][$model->alias][$field])) { - $results[$key][$model->alias][$field] = ''; + if (!isset($row[$model->alias][$aliasField])) { + $row[$model->alias][$aliasField] = ''; } } else { $value = ''; - if (!empty($results[$key]['I18n__'.$field]['content'])) { - $value = $results[$key]['I18n__'.$field]['content']; + if (!empty($row[$model->alias]['i18n_' . $field])) { + $value = $row[$model->alias]['i18n_' . $field]; } - $results[$key][$model->alias][$field] = $value; - unset($results[$key]['I18n__'.$field]); + $row[$model->alias][$aliasField] = $value; + unset($row[$model->alias]['i18n_' . $field]); } } } @@ -255,7 +240,7 @@ class TranslateBehavior extends ModelBehavior { * @param Model $model Model invalidFields was called on. * @return boolean */ - public function beforeValidate(&$model) { + public function beforeValidate($model) { $locale = $this->_getLocale($model); if (empty($locale)) { return true; @@ -289,7 +274,7 @@ class TranslateBehavior extends ModelBehavior { * @param boolean $created Whether or not the save created a record. * @return void */ - public function afterSave(&$model, $created) { + public function afterSave($model, $created) { if (!isset($this->runtime[$model->alias]['beforeSave'])) { return true; } @@ -297,7 +282,7 @@ class TranslateBehavior extends ModelBehavior { $tempData = $this->runtime[$model->alias]['beforeSave']; unset($this->runtime[$model->alias]['beforeSave']); $conditions = array('model' => $model->alias, 'foreign_key' => $model->id); - $RuntimeModel =& $this->translateModel($model); + $RuntimeModel = $this->translateModel($model); foreach ($tempData as $field => $value) { unset($conditions['content']); @@ -332,8 +317,8 @@ class TranslateBehavior extends ModelBehavior { * @param Model $model Model the callback was run on. * @return void */ - public function afterDelete(&$model) { - $RuntimeModel =& $this->translateModel($model); + public function afterDelete($model) { + $RuntimeModel = $this->translateModel($model); $conditions = array('model' => $model->alias, 'foreign_key' => $model->id); $RuntimeModel->deleteAll($conditions); } @@ -344,12 +329,12 @@ class TranslateBehavior extends ModelBehavior { * @param Model $model Model the locale needs to be set/get on. * @return mixed string or false */ - protected function _getLocale(&$model) { + protected function _getLocale($model) { if (!isset($model->locale) || is_null($model->locale)) { if (!class_exists('I18n')) { App::import('Core', 'i18n'); } - $I18n =& I18n::getInstance(); + $I18n = I18n::getInstance(); $I18n->l10n->get(Configure::read('Config.language')); $model->locale = $I18n->l10n->locale; } @@ -366,7 +351,7 @@ class TranslateBehavior extends ModelBehavior { * @param Model $model Model to get a translatemodel for. * @return object */ - public function &translateModel(&$model) { + public function translateModel($model) { if (!isset($this->runtime[$model->alias]['model'])) { if (!isset($model->translateModel) || empty($model->translateModel)) { $className = 'I18nModel'; @@ -381,8 +366,7 @@ class TranslateBehavior extends ModelBehavior { } elseif (empty($model->translateTable) && empty($model->translateModel)) { $this->runtime[$model->alias]['model']->setSource('i18n'); } - $model =& $this->runtime[$model->alias]['model']; - return $model; + return $this->runtime[$model->alias]['model']; } /** @@ -394,12 +378,12 @@ class TranslateBehavior extends ModelBehavior { * @param boolean $reset * @return bool */ - function bindTranslation(&$model, $fields, $reset = true) { + function bindTranslation($model, $fields, $reset = true) { if (is_string($fields)) { $fields = array($fields); } $associations = array(); - $RuntimeModel =& $this->translateModel($model); + $RuntimeModel = $this->translateModel($model); $default = array('className' => $RuntimeModel->alias, 'foreignKey' => 'foreign_key'); foreach ($fields as $key => $value) { @@ -467,7 +451,7 @@ class TranslateBehavior extends ModelBehavior { * unbind all original translations * @return bool */ - function unbindTranslation(&$model, $fields = null) { + function unbindTranslation($model, $fields = null) { if (empty($fields) && empty($this->settings[$model->alias])) { return false; } @@ -478,7 +462,7 @@ class TranslateBehavior extends ModelBehavior { if (is_string($fields)) { $fields = array($fields); } - $RuntimeModel =& $this->translateModel($model); + $RuntimeModel = $this->translateModel($model); $associations = array(); foreach ($fields as $key => $value) { @@ -513,15 +497,12 @@ class TranslateBehavior extends ModelBehavior { return true; } } -if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) { /** - * @package cake - * @subpackage cake.cake.libs.model.behaviors + * @package cake.libs.model.behaviors */ - class I18nModel extends AppModel { - public $name = 'I18nModel'; - public $useTable = 'i18n'; - public $displayField = 'field'; - } +class I18nModel extends AppModel { + public $name = 'I18nModel'; + public $useTable = 'i18n'; + public $displayField = 'field'; } diff --git a/cake/libs/model/behaviors/tree.php b/cake/libs/model/behaviors/tree.php index 51510538d..032d9e1a9 100644 --- a/cake/libs/model/behaviors/tree.php +++ b/cake/libs/model/behaviors/tree.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.cake.libs.model.behaviors + * @package cake.libs.model.behaviors * @since CakePHP v 1.2.0.4487 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -26,8 +25,7 @@ * Enables a model object to act as a node-based tree. Using Modified Preorder Tree Traversal * * @see http://en.wikipedia.org/wiki/Tree_traversal - * @package cake - * @subpackage cake.cake.libs.model.behaviors + * @package cake.libs.model.behaviors * @link http://book.cakephp.org/view/1339/Tree */ class TreeBehavior extends ModelBehavior { @@ -57,7 +55,7 @@ class TreeBehavior extends ModelBehavior { * @param array $config array of configuration settings. * @return void */ - public function setup(&$Model, $config = array()) { + public function setup($Model, $config = array()) { if (!is_array($config)) { $config = array('type' => $config); } @@ -65,7 +63,7 @@ class TreeBehavior extends ModelBehavior { if (in_array($settings['scope'], $Model->getAssociated('belongsTo'))) { $data = $Model->getAssociated($settings['scope']); - $parent =& $Model->{$settings['scope']}; + $parent = $Model->{$settings['scope']}; $settings['scope'] = $Model->alias . '.' . $data['foreignKey'] . ' = ' . $parent->alias . '.' . $parent->primaryKey; $settings['recursive'] = 0; } @@ -82,7 +80,7 @@ class TreeBehavior extends ModelBehavior { * @param boolean $created indicates whether the node just saved was created or updated * @return boolean true on success, false on failure */ - public function afterSave(&$Model, $created) { + public function afterSave($Model, $created) { extract($this->settings[$Model->alias]); if ($created) { if ((isset($Model->data[$Model->alias][$parent])) && $Model->data[$Model->alias][$parent]) { @@ -102,7 +100,7 @@ class TreeBehavior extends ModelBehavior { * @param AppModel $Model Model instance * @return boolean true to continue, false to abort the delete */ - public function beforeDelete(&$Model) { + public function beforeDelete($Model, $cascade = true) { extract($this->settings[$Model->alias]); list($name, $data) = array($Model->alias, $Model->read()); $data = $data[$name]; @@ -134,7 +132,7 @@ class TreeBehavior extends ModelBehavior { * @param AppModel $Model Model instance * @return boolean true to continue, false to abort the save */ - public function beforeSave(&$Model) { + public function beforeSave($Model) { extract($this->settings[$Model->alias]); $this->_addToWhitelist($Model, array($left, $right)); @@ -204,7 +202,7 @@ class TreeBehavior extends ModelBehavior { * @return integer number of child nodes * @link http://book.cakephp.org/view/1347/Counting-children */ - public function childCount(&$Model, $id = null, $direct = false) { + public function childCount($Model, $id = null, $direct = false) { if (is_array($id)) { extract (array_merge(array('id' => null), $id)); } @@ -250,7 +248,7 @@ class TreeBehavior extends ModelBehavior { * @return array Array of child nodes * @link http://book.cakephp.org/view/1346/Children */ - public function children(&$Model, $id = null, $direct = false, $fields = null, $order = null, $limit = null, $page = 1, $recursive = null) { + public function children($Model, $id = null, $direct = false, $fields = null, $order = null, $limit = null, $page = 1, $recursive = null) { if (is_array($id)) { extract (array_merge(array('id' => null), $id)); } @@ -307,7 +305,7 @@ class TreeBehavior extends ModelBehavior { * @return array An associative array of records, where the id is the key, and the display field is the value * @link http://book.cakephp.org/view/1348/generatetreelist */ - public function generateTreeList(&$Model, $conditions = null, $keyPath = null, $valuePath = null, $spacer = '_', $recursive = null) { + public function generateTreeList($Model, $conditions = null, $keyPath = null, $valuePath = null, $spacer = '_', $recursive = null) { $overrideRecursive = $recursive; extract($this->settings[$Model->alias]); if (!is_null($overrideRecursive)) { @@ -362,7 +360,7 @@ class TreeBehavior extends ModelBehavior { * @return array Array of data for the parent node * @link http://book.cakephp.org/view/1349/getparentnode */ - public function getParentNode(&$Model, $id = null, $fields = null, $recursive = null) { + public function getParentNode($Model, $id = null, $fields = null, $recursive = null) { if (is_array($id)) { extract (array_merge(array('id' => null), $id)); } @@ -395,7 +393,7 @@ class TreeBehavior extends ModelBehavior { * @return array Array of nodes from top most parent to current node * @link http://book.cakephp.org/view/1350/getpath */ - public function getPath(&$Model, $id = null, $fields = null, $recursive = null) { + public function getPath($Model, $id = null, $fields = null, $recursive = null) { if (is_array($id)) { extract (array_merge(array('id' => null), $id)); } @@ -432,7 +430,7 @@ class TreeBehavior extends ModelBehavior { * @return boolean true on success, false on failure * @link http://book.cakephp.org/view/1352/moveDown */ - public function moveDown(&$Model, $id = null, $number = 1) { + public function moveDown($Model, $id = null, $number = 1) { if (is_array($id)) { extract (array_merge(array('id' => null), $id)); } @@ -490,7 +488,7 @@ class TreeBehavior extends ModelBehavior { * @return boolean true on success, false on failure * @link http://book.cakephp.org/view/1353/moveUp */ - public function moveUp(&$Model, $id = null, $number = 1) { + public function moveUp($Model, $id = null, $number = 1) { if (is_array($id)) { extract (array_merge(array('id' => null), $id)); } @@ -554,7 +552,7 @@ class TreeBehavior extends ModelBehavior { * @return boolean true on success, false on failure * @link http://book.cakephp.org/view/1628/Recover */ - public function recover(&$Model, $mode = 'parent', $missingParentAction = null) { + public function recover($Model, $mode = 'parent', $missingParentAction = null) { if (is_array($mode)) { extract (array_merge(array('mode' => 'parent'), $mode)); } @@ -599,7 +597,7 @@ class TreeBehavior extends ModelBehavior { $this->_setParent($Model, $array[$Model->alias][$parent]); } } else { - $db =& ConnectionManager::getDataSource($Model->useDbConfig); + $db = ConnectionManager::getDataSource($Model->useDbConfig); foreach ($Model->find('all', array('conditions' => $scope, 'fields' => array($Model->primaryKey, $parent), 'order' => $left)) as $array) { $path = $this->getPath($Model, $array[$Model->alias][$Model->primaryKey]); if ($path == null || count($path) < 2) { @@ -634,7 +632,7 @@ class TreeBehavior extends ModelBehavior { * @link http://book.cakephp.org/view/1355/reorder * @link http://book.cakephp.org/view/1629/Reorder */ - function reorder(&$Model, $options = array()) { + function reorder($Model, $options = array()) { $options = array_merge(array('id' => null, 'field' => $Model->displayField, 'order' => 'ASC', 'verify' => true), $options); extract($options); if ($verify && !$this->verify($Model)) { @@ -673,7 +671,7 @@ class TreeBehavior extends ModelBehavior { * @return boolean true on success, false on failure * @link http://book.cakephp.org/view/1354/removeFromTree */ - public function removeFromTree(&$Model, $id = null, $delete = false) { + public function removeFromTree($Model, $id = null, $delete = false) { if (is_array($id)) { extract (array_merge(array('id' => null), $id)); } @@ -702,7 +700,7 @@ class TreeBehavior extends ModelBehavior { $parentNode[$right] = $node[$right] + 1; } - $db =& ConnectionManager::getDataSource($Model->useDbConfig); + $db = ConnectionManager::getDataSource($Model->useDbConfig); $Model->updateAll( array($parent => $db->value($node[$parent], $parent)), array($Model->escapeField($parent) => $node[$Model->primaryKey]) @@ -744,7 +742,7 @@ class TreeBehavior extends ModelBehavior { * [incorrect left/right index,node id], message) * @link http://book.cakephp.org/view/1630/Verify */ - public function verify(&$Model) { + public function verify($Model) { extract($this->settings[$Model->alias]); if (!$Model->find('count', array('conditions' => $scope))) { return true; @@ -815,7 +813,7 @@ class TreeBehavior extends ModelBehavior { * @param mixed $parentId * @return boolean true on success, false on failure */ - protected function _setParent(&$Model, $parentId = null, $created = false) { + protected function _setParent($Model, $parentId = null, $created = false) { extract($this->settings[$Model->alias]); list($node) = array_values($Model->find('first', array( 'conditions' => array($scope, $Model->escapeField() => $Model->id), @@ -888,7 +886,7 @@ class TreeBehavior extends ModelBehavior { * @access private */ function __getMax($Model, $scope, $right, $recursive = -1, $created = false) { - $db =& ConnectionManager::getDataSource($Model->useDbConfig); + $db = ConnectionManager::getDataSource($Model->useDbConfig); if ($created) { if (is_string($scope)) { $scope .= " AND {$Model->alias}.{$Model->primaryKey} <> "; @@ -916,7 +914,7 @@ class TreeBehavior extends ModelBehavior { * @access private */ function __getMin($Model, $scope, $left, $recursive = -1) { - $db =& ConnectionManager::getDataSource($Model->useDbConfig); + $db = ConnectionManager::getDataSource($Model->useDbConfig); $name = $Model->alias . '.' . $left; list($edge) = array_values($Model->find('first', array( 'conditions' => $scope, @@ -938,7 +936,7 @@ class TreeBehavior extends ModelBehavior { * @param string $field * @access private */ - function __sync(&$Model, $shift, $dir = '+', $conditions = array(), $created = false, $field = 'both') { + function __sync($Model, $shift, $dir = '+', $conditions = array(), $created = false, $field = 'both') { $ModelRecursive = $Model->recursive; extract($this->settings[$Model->alias]); $Model->recursive = $recursive; diff --git a/cake/libs/model/cake_schema.php b/cake/libs/model/cake_schema.php index c3dfbf17d..a38e0ed7b 100644 --- a/cake/libs/model/cake_schema.php +++ b/cake/libs/model/cake_schema.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.model + * @package cake.libs.model * @since CakePHP(tm) v 1.2.0.5550 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ App::import('Core', 'ConnectionManager'); /** * Base Class for Schema management * - * @package cake - * @subpackage cake.cake.libs.model + * @package cake.libs.model */ class CakeSchema extends Object { @@ -95,11 +93,7 @@ class CakeSchema extends Object { } if (empty($options['path'])) { - if (is_dir(CONFIGS . 'schema')) { - $this->path = CONFIGS . 'schema'; - } else { - $this->path = CONFIGS . 'sql'; - } + $this->path = CONFIGS . 'schema'; } $options = array_merge(get_object_vars($this), $options); @@ -161,7 +155,7 @@ class CakeSchema extends Object { * @param array $options schema object properties * @return array Set of name and tables */ - public function &load($options = array()) { + public function load($options = array()) { if (is_string($options)) { $options = array('path' => $options); } @@ -183,8 +177,8 @@ class CakeSchema extends Object { $Schema = new $class($options); return $Schema; } - $false = false; - return $false; + + return false; } /** @@ -299,7 +293,6 @@ class CakeSchema extends Object { $systemTables = array( 'aros', 'acos', 'aros_acos', Configure::read('Session.table'), 'i18n' ); - if (in_array($table, $systemTables)) { $tables[$Object->table] = $this->__columns($Object); $tables[$Object->table]['indexes'] = $db->index($Object); diff --git a/cake/libs/model/connection_manager.php b/cake/libs/model/connection_manager.php index 42b2c5003..f8916877e 100644 --- a/cake/libs/model/connection_manager.php +++ b/cake/libs/model/connection_manager.php @@ -14,19 +14,17 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.model + * @package cake.libs.model * @since CakePHP(tm) v 0.10.x.1402 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ require LIBS . 'model' . DS . 'datasources' . DS . 'datasource.php'; -include_once CONFIGS . 'database.php'; +config('database'); /** * Manages loaded instances of DataSource objects * - * @package cake - * @subpackage cake.cake.libs.model + * @package cake.libs.model */ class ConnectionManager { diff --git a/cake/libs/model/datasources/datasource.php b/cake/libs/model/datasources/datasource.php index 85c0b1f59..d38e8bf10 100644 --- a/cake/libs/model/datasources/datasource.php +++ b/cake/libs/model/datasources/datasource.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.model.datasources + * @package cake.libs.model.datasources * @since CakePHP(tm) v 0.10.5.1790 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * DataSource base class * - * @package cake - * @subpackage cake.cake.libs.model.datasources + * @package cake.libs.model.datasources */ class DataSource extends Object { @@ -263,7 +261,7 @@ class DataSource extends Object { * @param Model $model * @return array Array of Metadata for the $model */ - public function describe(&$model) { + public function describe($model) { if ($this->cacheSources === false) { return null; } @@ -286,7 +284,7 @@ class DataSource extends Object { * * @return boolean Returns true if a transaction is not in progress */ - public function begin(&$model) { + public function begin() { return !$this->_transactionStarted; } @@ -295,7 +293,7 @@ class DataSource extends Object { * * @return boolean Returns true if a transaction is in progress */ - public function commit(&$model) { + public function commit() { return $this->_transactionStarted; } @@ -304,7 +302,7 @@ class DataSource extends Object { * * @return boolean Returns true if a transaction is in progress */ - public function rollback(&$model) { + public function rollback() { return $this->_transactionStarted; } @@ -328,7 +326,7 @@ class DataSource extends Object { * @param array $values An Array of values to save. * @return boolean success */ - public function create(&$model, $fields = null, $values = null) { + public function create($model, $fields = null, $values = null) { return false; } @@ -341,7 +339,7 @@ class DataSource extends Object { * @param array $queryData An array of query data used to find the data you want * @return mixed */ - public function read(&$model, $queryData = array()) { + public function read($model, $queryData = array()) { return false; } @@ -355,7 +353,7 @@ class DataSource extends Object { * @param array $values Array of values to be update $fields to. * @return boolean Success */ - public function update(&$model, $fields = null, $values = null) { + public function update($model, $fields = null, $values = null) { return false; } @@ -367,7 +365,7 @@ class DataSource extends Object { * @param Model $model The model class having record(s) deleted * @param mixed $id Primary key of the model */ - public function delete(&$model, $id = null) { + public function delete($model, $id = null) { if ($id == null) { $id = $model->id; } @@ -384,7 +382,7 @@ class DataSource extends Object { } /** - * Returns the ID generated from the previous INSERT operation. + * Returns the number of rows returned by last operation. * * @param unknown_type $source * @return integer Number of rows returned by last operation @@ -394,7 +392,7 @@ class DataSource extends Object { } /** - * Returns the ID generated from the previous INSERT operation. + * Returns the number of rows affected by last query. * * @param unknown_type $source * @return integer Number of rows affected by last query. @@ -413,6 +411,7 @@ class DataSource extends Object { public function enabled() { return true; } + /** * Returns true if the DataSource supports the given interface (method) * @@ -556,7 +555,7 @@ class DataSource extends Object { * @param string $key Key name to make * @return string Key name for model. */ - public function resolveKey(&$model, $key) { + public function resolveKey($model, $key) { return $model->alias . $key; } diff --git a/cake/libs/model/datasources/dbo/dbo_mssql.php b/cake/libs/model/datasources/dbo/dbo_mssql.php index a07829eb3..91db76c5f 100644 --- a/cake/libs/model/datasources/dbo/dbo_mssql.php +++ b/cake/libs/model/datasources/dbo/dbo_mssql.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.model.datasources.dbo + * @package cake.libs.model.datasources.dbo * @since CakePHP(tm) v 0.10.5.1790 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * Long description for class * - * @package cake - * @subpackage cake.cake.libs.model.datasources.dbo + * @package cake.libs.model.datasources.dbo */ class DboMssql extends DboSource { @@ -227,7 +225,7 @@ class DboMssql extends DboSource { * @param Model $model Model object to describe * @return array Fields in table. Keys are name and type */ - function describe(&$model) { + function describe($model) { $cache = parent::describe($model); if ($cache != null) { @@ -317,7 +315,7 @@ class DboMssql extends DboSource { * @param mixed $fields * @return array */ - function fields(&$model, $alias = null, $fields = array(), $quote = true) { + function fields($model, $alias = null, $fields = array(), $quote = true) { if (empty($alias)) { $alias = $model->alias; } @@ -383,7 +381,7 @@ class DboMssql extends DboSource { * @param mixed $conditions * @return array */ - function create(&$model, $fields = null, $values = null) { + function create($model, $fields = null, $values = null) { if (!empty($values)) { $fields = array_combine($fields, $values); } @@ -413,7 +411,7 @@ class DboMssql extends DboSource { * @param mixed $conditions * @return array */ - function update(&$model, $fields = array(), $values = null, $conditions = null) { + function update($model, $fields = array(), $values = null, $conditions = null) { if (!empty($values)) { $fields = array_combine($fields, $values); } @@ -667,7 +665,7 @@ class DboMssql extends DboSource { * @param boolean $cache Enables returning/storing cached query results * @return array Array of resultset rows, or false if no rows matched */ - function read(&$model, $queryData = array(), $recursive = null) { + function read($model, $queryData = array(), $recursive = null) { $results = parent::read($model, $queryData, $recursive); $this->__fieldMappings = array(); return $results; diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php index cff28d572..1d6052f6a 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysql.php +++ b/cake/libs/model/datasources/dbo/dbo_mysql.php @@ -12,26 +12,47 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.model.datasources.dbo + * @package cake.libs.model.datasources.dbo * @since CakePHP(tm) v 0.10.5.1790 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ /** - * Provides common base for MySQL & MySQLi connections + * MySQL DBO driver object * - * @package cake - * @subpackage cake.cake.libs.model.datasources.dbo + * Provides connection and SQL generation for MySQL RDMS + * + * @package cake.libs.model.datasources.dbo */ -class DboMysqlBase extends DboSource { +class DboMysql extends DboSource { /** - * Description property. + * Datasource description * * @var string */ - public $description = "MySQL DBO Base Driver"; + public $description = "MySQL DBO Driver"; + +/** + * Base configuration settings for MySQL driver + * + * @var array + */ + protected $_baseConfig = array( + 'persistent' => true, + 'host' => 'localhost', + 'login' => 'root', + 'password' => '', + 'database' => 'cake', + 'port' => '3306' + ); + +/** + * Reference to the PDO object connection + * + * @var PDO $_connection + */ + protected $_connection = null; /** * Start quote @@ -110,49 +131,190 @@ class DboMysqlBase extends DboSource { 'boolean' => array('name' => 'tinyint', 'limit' => '1') ); +/** + * Connects to the database using options in the given configuration array. + * + * @return boolean True if the database could be connected, else false + */ + function connect() { + $config = $this->config; + $this->connected = false; + try { + $flags = array( + PDO::ATTR_PERSISTENT => $config['persistent'], + PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true + ); + if (!empty($config['encoding'])) { + $flags[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES ' . $config['encoding']; + } + $this->_connection = new PDO( + "mysql:{$config['host']};port={$config['port']};dbname={$config['database']}", + $config['login'], + $config['password'], + $flags + ); + $this->connected = true; + } catch (PDOException $e) { + $this->errors[] = $e->getMessage(); + } + + $this->_useAlias = (bool)version_compare($this->getVersion(), "4.1", ">="); + + return $this->connected; + } + +/** + * Check whether the MySQL extension is installed/loaded + * + * @return boolean + */ + function enabled() { + return in_array('mysql', PDO::getAvailableDrivers()); + } + +/** + * Returns an array of sources (tables) in the database. + * + * @return array Array of tablenames in the database + */ + function listSources($data = null) { + $cache = parent::listSources(); + if ($cache != null) { + return $cache; + } + $result = $this->_execute('SHOW TABLES FROM ' . $this->config['database']); + + if (!$result) { + $result->closeCursor(); + return array(); + } else { + $tables = array(); + + while ($line = $result->fetch()) { + $tables[] = $line[0]; + } + + $result->closeCursor(); + parent::listSources($tables); + return $tables; + } + } + +/** + * Builds a map of the columns contained in a result + * + * @param PDOStatement $results + */ + function resultSet($results) { + $this->map = array(); + $numFields = $results->columnCount(); + $index = 0; + $j = 0; + + while ($j < $numFields) { + $column = $results->getColumnMeta($j); + if (!empty($column['table']) && strpos($column['name'], $this->virtualFieldSeparator) === false) { + $this->map[$index++] = array($column['table'], $column['name']); + } else { + $this->map[$index++] = array(0, $column['name']); + } + $j++; + } + } + +/** + * Fetches the next row from the current result set + * + * @return mixed array with results fetched and mapped to column names or false if there is no results left to fetch + */ + function fetchResult() { + if ($row = $this->_result->fetch()) { + $resultRow = array(); + foreach ($this->map as $col => $meta) { + list($table, $column) = $meta; + $resultRow[$table][$column] = $row[$col]; + } + return $resultRow; + } else { + $this->_result->closeCursor(); + return false; + } + } + +/** + * Gets the database encoding + * + * @return string The database encoding + */ + public function getEncoding() { + return $this->_execute('SHOW VARIABLES LIKE ?', array('character_set_client'))->fetchObject()->Value; + } + +/** + * Gets the version string of the database server + * + * @return string The database encoding + */ + public function getVersion() { + return $this->_connection->getAttribute(PDO::ATTR_SERVER_VERSION); + } + +/** + * Query charset by collation + * + * @param string $name Collation name + * @return string Character set name + */ + public function getCharsetName($name) { + if ((bool)version_compare($this->getVersion(), "5", ">=")) { + $r = $this->_execute('SELECT CHARACTER_SET_NAME FROM INFORMATION_SCHEMA.COLLATIONS WHERE COLLATION_NAME = ?', array($name)); + $cols = $r->fetch(); + + if (isset($cols['CHARACTER_SET_NAME'])) { + return $cols['CHARACTER_SET_NAME']; + } + } + return false; + } + /** * Returns an array of the fields in given table name. * - * @param string $tableName Name of database table to inspect + * @param mixed $tableName Name of database table to inspect or model instance * @return array Fields in table. Keys are name and type */ - function describe(&$model) { + function describe($model) { $cache = parent::describe($model); if ($cache != null) { return $cache; } $fields = false; - $cols = $this->query('SHOW FULL COLUMNS FROM ' . $this->fullTableName($model)); + $cols = $this->_execute('SHOW FULL COLUMNS FROM ' . $this->fullTableName($model)); foreach ($cols as $column) { - $colKey = array_keys($column); - if (isset($column[$colKey[0]]) && !isset($column[0])) { - $column[0] = $column[$colKey[0]]; + $fields[$column->Field] = array( + 'type' => $this->column($column->Type), + 'null' => ($column->Null == 'YES' ? true : false), + 'default' => $column->Default, + 'length' => $this->length($column->Type), + ); + if (!empty($column->Key) && isset($this->index[$column->Key])) { + $fields[$column->Field]['key'] = $this->index[$column->Key]; } - if (isset($column[0])) { - $fields[$column[0]['Field']] = array( - 'type' => $this->column($column[0]['Type']), - 'null' => ($column[0]['Null'] == 'YES' ? true : false), - 'default' => $column[0]['Default'], - 'length' => $this->length($column[0]['Type']), - ); - if (!empty($column[0]['Key']) && isset($this->index[$column[0]['Key']])) { - $fields[$column[0]['Field']]['key'] = $this->index[$column[0]['Key']]; + foreach ($this->fieldParameters as $name => $value) { + if (!empty($column->{$value['column']})) { + $fields[$column->Field][$name] = $column->{$value['column']}; } - foreach ($this->fieldParameters as $name => $value) { - if (!empty($column[0][$value['column']])) { - $fields[$column[0]['Field']][$name] = $column[0][$value['column']]; - } - } - if (isset($fields[$column[0]['Field']]['collate'])) { - $charset = $this->getCharsetName($fields[$column[0]['Field']]['collate']); - if ($charset) { - $fields[$column[0]['Field']]['charset'] = $charset; - } + } + if (isset($fields[$column->Field]['collate'])) { + $charset = $this->getCharsetName($fields[$column->Field]['collate']); + if ($charset) { + $fields[$column->Field]['charset'] = $charset; } } } $this->__cacheDescription($this->fullTableName($model, false), $fields); + $cols->closeCursor(); return $fields; } @@ -165,7 +327,7 @@ class DboMysqlBase extends DboSource { * @param mixed $conditions * @return array */ - function update(&$model, $fields = array(), $values = null, $conditions = null) { + function update($model, $fields = array(), $values = null, $conditions = null) { if (!$this->_useAlias) { return parent::update($model, $fields, $values, $conditions); } @@ -207,7 +369,7 @@ class DboMysqlBase extends DboSource { * @param mixed $conditions * @return boolean Success */ - function delete(&$model, $conditions = null) { + function delete($model, $conditions = null) { if (!$this->_useAlias) { return parent::delete($model, $conditions); } @@ -249,26 +411,26 @@ class DboMysqlBase extends DboSource { function index($model) { $index = array(); $table = $this->fullTableName($model); + $old = version_compare($this->getVersion(), '4.1', '<='); if ($table) { - $indexes = $this->query('SHOW INDEX FROM ' . $table); - if (isset($indexes[0]['STATISTICS'])) { - $keys = Set::extract($indexes, '{n}.STATISTICS'); - } else { - $keys = Set::extract($indexes, '{n}.0'); - } - foreach ($keys as $i => $key) { - if (!isset($index[$key['Key_name']])) { + $indices = $this->_execute('SHOW INDEX FROM ' . $table); + while ($idx = $indices->fetch()) { + if ($old) { + $idx = (object) current((array)$idx); + } + if (!isset($index[$idx->Key_name]['column'])) { $col = array(); - $index[$key['Key_name']]['column'] = $key['Column_name']; - $index[$key['Key_name']]['unique'] = intval($key['Non_unique'] == 0); + $index[$idx->Key_name]['column'] = $idx->Column_name; + $index[$idx->Key_name]['unique'] = intval($idx->Non_unique == 0); } else { - if (!is_array($index[$key['Key_name']]['column'])) { - $col[] = $index[$key['Key_name']]['column']; + if (!empty($index[$idx->Key_name]['column']) && !is_array($index[$idx->Key_name]['column'])) { + $col[] = $index[$idx->Key_name]['column']; } - $col[] = $key['Column_name']; - $index[$key['Key_name']]['column'] = $col; + $col[] = $idx->Column_name; + $index[$idx->Key_name]['column'] = $col; } } + $indices->closeCursor(); } return $index; } @@ -336,16 +498,12 @@ class DboMysqlBase extends DboSource { /** * Generate a MySQL "drop table" statement for the given Schema object * - * @param object $schema An instance of a subclass of CakeSchema + * @param CakeSchema $schema An instance of a subclass of CakeSchema * @param string $table Optional. If specified only the table name given will be generated. * Otherwise, all tables defined in the schema are generated. * @return string */ - function dropSchema($schema, $table = null) { - if (!is_a($schema, 'CakeSchema')) { - trigger_error(__('Invalid schema object'), E_USER_WARNING); - return null; - } + function dropSchema(CakeSchema $schema, $table = null) { $out = ''; foreach ($schema->tables as $curTable => $columns) { if (!$table || $table == $curTable) { @@ -412,21 +570,6 @@ class DboMysqlBase extends DboSource { return $alter; } -/** - * Inserts multiple values into a table - * - * @param string $table - * @param string $fields - * @param array $values - */ - function insertMulti($table, $fields, $values) { - $table = $this->fullTableName($table); - if (is_array($fields)) { - $fields = implode(', ', array_map(array(&$this, 'name'), $fields)); - } - $values = implode(', ', $values); - $this->query("INSERT INTO {$table} ({$fields}) VALUES {$values}"); - } /** * Returns an detailed array of sources (tables) in the database. * @@ -435,23 +578,29 @@ class DboMysqlBase extends DboSource { */ function listDetailedSources($name = null) { $condition = ''; + $params = array(); if (is_string($name)) { - $condition = ' LIKE ' . $this->value($name); + $condition = ' WHERE name = ?' ; + $params = array($name); } - $result = $this->query('SHOW TABLE STATUS FROM ' . $this->name($this->config['database']) . $condition . ';'); + $result = $this->_execute('SHOW TABLE STATUS ' . $condition, $params); + if (!$result) { + $result->closeCursor(); return array(); } else { $tables = array(); - foreach ($result as $row) { - $tables[$row['TABLES']['Name']] = $row['TABLES']; - if (!empty($row['TABLES']['Collation'])) { - $charset = $this->getCharsetName($row['TABLES']['Collation']); + while ($row = $result->fetch()) { + $tables[$row->Name] = (array) $row; + unset($tables[$row->Name]['queryString']); + if (!empty($row->Collation)) { + $charset = $this->getCharsetName($row->Collation); if ($charset) { - $tables[$row['TABLES']['Name']]['charset'] = $charset; + $tables[$row->Name]['charset'] = $charset; } } } + $result->closeCursor(); if (is_string($name)) { return $tables[$name]; } @@ -507,292 +656,3 @@ class DboMysqlBase extends DboSource { return 'text'; } } - -/** - * MySQL DBO driver object - * - * Provides connection and SQL generation for MySQL RDMS - * - * @package cake - * @subpackage cake.cake.libs.model.datasources.dbo - */ -class DboMysql extends DboMysqlBase { - -/** - * Datasource description - * - * @var string - */ - public $description = "MySQL DBO Driver"; - -/** - * Base configuration settings for MySQL driver - * - * @var array - */ - protected $_baseConfig = array( - 'persistent' => true, - 'host' => 'localhost', - 'login' => 'root', - 'password' => '', - 'database' => 'cake', - 'port' => '3306' - ); - -/** - * Connects to the database using options in the given configuration array. - * - * @return boolean True if the database could be connected, else false - */ - function connect() { - $config = $this->config; - $this->connected = false; - - if (!$config['persistent']) { - $this->connection = mysql_connect($config['host'] . ':' . $config['port'], $config['login'], $config['password'], true); - $config['connect'] = 'mysql_connect'; - } else { - $this->connection = mysql_pconnect($config['host'] . ':' . $config['port'], $config['login'], $config['password']); - } - - if (mysql_select_db($config['database'], $this->connection)) { - $this->connected = true; - } - - if (!empty($config['encoding'])) { - $this->setEncoding($config['encoding']); - } - - $this->_useAlias = (bool)version_compare(mysql_get_server_info($this->connection), "4.1", ">="); - - return $this->connected; - } - -/** - * Check whether the MySQL extension is installed/loaded - * - * @return boolean - */ - function enabled() { - return extension_loaded('mysql'); - } -/** - * Disconnects from database. - * - * @return boolean True if the database could be disconnected, else false - */ - function disconnect() { - if (isset($this->results) && is_resource($this->results)) { - mysql_free_result($this->results); - } - $this->connected = !@mysql_close($this->connection); - return !$this->connected; - } - -/** - * Executes given SQL statement. - * - * @param string $sql SQL statement - * @return resource Result resource identifier - */ - protected function _execute($sql) { - return mysql_query($sql, $this->connection); - } - -/** - * Returns an array of sources (tables) in the database. - * - * @return array Array of tablenames in the database - */ - function listSources() { - $cache = parent::listSources(); - if ($cache != null) { - return $cache; - } - $result = $this->_execute('SHOW TABLES FROM ' . $this->name($this->config['database']) . ';'); - - if (!$result) { - return array(); - } else { - $tables = array(); - - while ($line = mysql_fetch_row($result)) { - $tables[] = $line[0]; - } - parent::listSources($tables); - return $tables; - } - } - -/** - * Returns a quoted and escaped string of $data for use in an SQL statement. - * - * @param string $data String to be prepared for use in an SQL statement - * @param string $column The column into which this data will be inserted - * @param boolean $safe Whether or not numeric data should be handled automagically if no column data is provided - * @return string Quoted and escaped data - */ - function value($data, $column = null, $safe = false) { - $parent = parent::value($data, $column, $safe); - - if ($parent != null) { - return $parent; - } - if ($data === null || (is_array($data) && empty($data))) { - return 'NULL'; - } - if ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') { - return "''"; - } - if (empty($column)) { - $column = $this->introspectType($data); - } - - switch ($column) { - case 'boolean': - return $this->boolean((bool)$data); - break; - case 'integer': - case 'float': - if ($data === '') { - return 'NULL'; - } - if (is_float($data)) { - return sprintf('%F', $data); - } - if ((is_int($data) || $data === '0') || ( - is_numeric($data) && strpos($data, ',') === false && - $data[0] != '0' && strpos($data, 'e') === false) - ) { - return $data; - } - default: - return "'" . mysql_real_escape_string($data, $this->connection) . "'"; - break; - } - } - -/** - * Returns a formatted error message from previous database operation. - * - * @return string Error message with error number - */ - function lastError() { - if (mysql_errno($this->connection)) { - return mysql_errno($this->connection).': '.mysql_error($this->connection); - } - return null; - } - -/** - * Returns number of affected rows in previous database operation. If no previous operation exists, - * this returns false. - * - * @return integer Number of affected rows - */ - function lastAffected() { - if ($this->_result) { - return mysql_affected_rows($this->connection); - } - return null; - } - -/** - * Returns number of rows in previous resultset. If no previous resultset exists, - * this returns false. - * - * @return integer Number of rows in resultset - */ - function lastNumRows() { - if ($this->hasResult()) { - return mysql_num_rows($this->_result); - } - return null; - } - -/** - * Returns the ID generated from the previous INSERT operation. - * - * @param unknown_type $source - * @return in - */ - function lastInsertId($source = null) { - $id = $this->fetchRow('SELECT LAST_INSERT_ID() AS insertID', false); - if ($id !== false && !empty($id) && !empty($id[0]) && isset($id[0]['insertID'])) { - return $id[0]['insertID']; - } - - return null; - } - -/** - * Enter description here... - * - * @param unknown_type $results - */ - function resultSet(&$results) { - if (isset($this->results) && is_resource($this->results) && $this->results != $results) { - mysql_free_result($this->results); - } - $this->results =& $results; - $this->map = array(); - $numFields = mysql_num_fields($results); - $index = 0; - $j = 0; - - while ($j < $numFields) { - $column = mysql_fetch_field($results, $j); - if (!empty($column->table) && strpos($column->name, $this->virtualFieldSeparator) === false) { - $this->map[$index++] = array($column->table, $column->name); - } else { - $this->map[$index++] = array(0, $column->name); - } - $j++; - } - } - -/** - * Fetches the next row from the current result set - * - * @return unknown - */ - function fetchResult() { - if ($row = mysql_fetch_row($this->results)) { - $resultRow = array(); - $i = 0; - foreach ($row as $index => $field) { - list($table, $column) = $this->map[$index]; - $resultRow[$table][$column] = $row[$index]; - $i++; - } - return $resultRow; - } else { - return false; - } - } - -/** - * Gets the database encoding - * - * @return string The database encoding - */ - function getEncoding() { - return mysql_client_encoding($this->connection); - } - -/** - * Query charset by collation - * - * @param string $name Collation name - * @return string Character set name - */ - function getCharsetName($name) { - if ((bool)version_compare(mysql_get_server_info($this->connection), "5", ">=")) { - $cols = $this->query('SELECT CHARACTER_SET_NAME FROM INFORMATION_SCHEMA.COLLATIONS WHERE COLLATION_NAME= ' . $this->value($name) . ';'); - if (isset($cols[0]['COLLATIONS']['CHARACTER_SET_NAME'])) { - return $cols[0]['COLLATIONS']['CHARACTER_SET_NAME']; - } - } - return false; - } -} diff --git a/cake/libs/model/datasources/dbo/dbo_mysqli.php b/cake/libs/model/datasources/dbo/dbo_mysqli.php deleted file mode 100644 index 7c6cdfd5d..000000000 --- a/cake/libs/model/datasources/dbo/dbo_mysqli.php +++ /dev/null @@ -1,336 +0,0 @@ - true, - 'host' => 'localhost', - 'login' => 'root', - 'password' => '', - 'database' => 'cake', - 'port' => '3306' - ); - -/** - * Connects to the database using options in the given configuration array. - * - * @return boolean True if the database could be connected, else false - */ - function connect() { - $config = $this->config; - $this->connected = false; - - if (is_numeric($config['port'])) { - $config['socket'] = null; - } else { - $config['socket'] = $config['port']; - $config['port'] = null; - } - - $this->connection = mysqli_connect($config['host'], $config['login'], $config['password'], $config['database'], $config['port'], $config['socket']); - - if ($this->connection !== false) { - $this->connected = true; - } - - $this->_useAlias = (bool)version_compare(mysqli_get_server_info($this->connection), "4.1", ">="); - - if (!empty($config['encoding'])) { - $this->setEncoding($config['encoding']); - } - return $this->connected; - } - -/** - * Check that MySQLi is installed/enabled - * - * @return boolean - */ - function enabled() { - return extension_loaded('mysqli'); - } -/** - * Disconnects from database. - * - * @return boolean True if the database could be disconnected, else false - */ - function disconnect() { - if (isset($this->results) && is_resource($this->results)) { - mysqli_free_result($this->results); - } - $this->connected = !@mysqli_close($this->connection); - return !$this->connected; - } - -/** - * Executes given SQL statement. - * - * @param string $sql SQL statement - * @return resource Result resource identifier - */ - protected function _execute($sql) { - if (preg_match('/^\s*call/i', $sql)) { - return $this->_executeProcedure($sql); - } - return mysqli_query($this->connection, $sql); - } - -/** - * Executes given SQL statement (procedure call). - * - * @param string $sql SQL statement (procedure call) - * @return resource Result resource identifier for first recordset - */ - protected function _executeProcedure($sql) { - $answer = mysqli_multi_query($this->connection, $sql); - - $firstResult = mysqli_store_result($this->connection); - - if (mysqli_more_results($this->connection)) { - while ($lastResult = mysqli_next_result($this->connection)); - } - return $firstResult; - } - -/** - * Returns an array of sources (tables) in the database. - * - * @return array Array of tablenames in the database - */ - function listSources() { - $cache = parent::listSources(); - if ($cache !== null) { - return $cache; - } - $result = $this->_execute('SHOW TABLES FROM ' . $this->name($this->config['database']) . ';'); - - if (!$result) { - return array(); - } - - $tables = array(); - - while ($line = mysqli_fetch_row($result)) { - $tables[] = $line[0]; - } - parent::listSources($tables); - return $tables; - } - -/** - * Returns a quoted and escaped string of $data for use in an SQL statement. - * - * @param string $data String to be prepared for use in an SQL statement - * @param string $column The column into which this data will be inserted - * @param boolean $safe Whether or not numeric data should be handled automagically if no column data is provided - * @return string Quoted and escaped data - */ - function value($data, $column = null, $safe = false) { - $parent = parent::value($data, $column, $safe); - - if ($parent != null) { - return $parent; - } - if ($data === null || (is_array($data) && empty($data))) { - return 'NULL'; - } - if ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') { - return "''"; - } - if (empty($column)) { - $column = $this->introspectType($data); - } - - switch ($column) { - case 'boolean': - return $this->boolean((bool)$data); - break; - case 'integer' : - case 'float' : - case null : - if ($data === '') { - return 'NULL'; - } - if ((is_int($data) || is_float($data) || $data === '0') || ( - is_numeric($data) && strpos($data, ',') === false && - $data[0] != '0' && strpos($data, 'e') === false)) { - return $data; - } - default: - $data = "'" . mysqli_real_escape_string($this->connection, $data) . "'"; - break; - } - - return $data; - } - -/** - * Returns a formatted error message from previous database operation. - * - * @return string Error message with error number - */ - function lastError() { - if (mysqli_errno($this->connection)) { - return mysqli_errno($this->connection).': '.mysqli_error($this->connection); - } - return null; - } - -/** - * Returns number of affected rows in previous database operation. If no previous operation exists, - * this returns false. - * - * @return integer Number of affected rows - */ - function lastAffected() { - if ($this->_result) { - return mysqli_affected_rows($this->connection); - } - return null; - } - -/** - * Returns number of rows in previous resultset. If no previous resultset exists, - * this returns false. - * - * @return integer Number of rows in resultset - */ - function lastNumRows() { - if ($this->hasResult()) { - return mysqli_num_rows($this->_result); - } - return null; - } - -/** - * Returns the ID generated from the previous INSERT operation. - * - * @param unknown_type $source - * @return in - */ - function lastInsertId($source = null) { - $id = $this->fetchRow('SELECT LAST_INSERT_ID() AS insertID', false); - if ($id !== false && !empty($id) && !empty($id[0]) && isset($id[0]['insertID'])) { - return $id[0]['insertID']; - } - return null; - } - -/** - * Enter description here... - * - * @param unknown_type $results - */ - function resultSet(&$results) { - if (isset($this->results) && is_resource($this->results) && $this->results != $results) { - mysqli_free_result($this->results); - } - $this->results =& $results; - $this->map = array(); - $numFields = mysqli_num_fields($results); - $index = 0; - $j = 0; - while ($j < $numFields) { - $column = mysqli_fetch_field_direct($results, $j); - if (!empty($column->table)) { - $this->map[$index++] = array($column->table, $column->name); - } else { - $this->map[$index++] = array(0, $column->name); - } - $j++; - } - } - -/** - * Fetches the next row from the current result set - * - * @return unknown - */ - function fetchResult() { - if ($row = mysqli_fetch_row($this->results)) { - $resultRow = array(); - foreach ($row as $index => $field) { - $table = $column = null; - if (count($this->map[$index]) === 2) { - list($table, $column) = $this->map[$index]; - } - $resultRow[$table][$column] = $row[$index]; - } - return $resultRow; - } - return false; - } - -/** - * Gets the database encoding - * - * @return string The database encoding - */ - function getEncoding() { - return mysqli_client_encoding($this->connection); - } - -/** - * Query charset by collation - * - * @param string $name Collation name - * @return string Character set name - */ - function getCharsetName($name) { - if ((bool)version_compare(mysqli_get_server_info($this->connection), "5", ">=")) { - $cols = $this->query('SELECT CHARACTER_SET_NAME FROM INFORMATION_SCHEMA.COLLATIONS WHERE COLLATION_NAME= ' . $this->value($name) . ';'); - if (isset($cols[0]['COLLATIONS']['CHARACTER_SET_NAME'])) { - return $cols[0]['COLLATIONS']['CHARACTER_SET_NAME']; - } - } - return false; - } - -/** - * Checks if the result is valid - * - * @return boolean True if the result is valid, else false - */ - function hasResult() { - return is_object($this->_result); - } -} diff --git a/cake/libs/model/datasources/dbo/dbo_oracle.php b/cake/libs/model/datasources/dbo/dbo_oracle.php index 6ade6a59f..4b4444211 100644 --- a/cake/libs/model/datasources/dbo/dbo_oracle.php +++ b/cake/libs/model/datasources/dbo/dbo_oracle.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.model.datasources.dbo + * @package cake.libs.model.datasources.dbo * @since CakePHP v 1.2.0.4041 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * Long description for class * - * @package cake - * @subpackage cake.cake.libs.model.datasources.dbo + * @package cake.libs.model.datasources.dbo */ class DboOracle extends DboSource { @@ -478,7 +476,7 @@ class DboOracle extends DboSource { * @param object instance of a model to inspect * @return array Fields in table. Keys are name and type */ - public function describe(&$model) { + public function describe($model) { $table = $this->fullTableName($model, false); if (!empty($model->sequence)) { @@ -974,7 +972,7 @@ class DboOracle extends DboSource { * @param integer $recursive Number of levels of association * @param array $stack */ - function queryAssociation(&$model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet, $recursive, $stack) { + function queryAssociation($model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet, $recursive, $stack) { if ($query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet)) { if (!isset($resultSet) || !is_array($resultSet)) { if (Configure::read('debug') > 0) { @@ -1121,16 +1119,12 @@ class DboOracle extends DboSource { /** * Generate a "drop table" statement for the given Schema object * - * @param object $schema An instance of a subclass of CakeSchema + * @param CakeSchema $schema An instance of a subclass of CakeSchema * @param string $table Optional. If specified only the table name given will be generated. * Otherwise, all tables defined in the schema are generated. * @return string */ - function dropSchema($schema, $table = null) { - if (!is_a($schema, 'CakeSchema')) { - trigger_error(__('Invalid schema object'), E_USER_WARNING); - return null; - } + function dropSchema(CakeSchema $schema, $table = null) { $out = ''; foreach ($schema->tables as $curTable => $columns) { diff --git a/cake/libs/model/datasources/dbo/dbo_postgres.php b/cake/libs/model/datasources/dbo/dbo_postgres.php index 7b37f5412..e5e12d2bc 100644 --- a/cake/libs/model/datasources/dbo/dbo_postgres.php +++ b/cake/libs/model/datasources/dbo/dbo_postgres.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.model.datasources.dbo + * @package cake.libs.model.datasources.dbo * @since CakePHP(tm) v 0.9.1.114 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * Long description for class * - * @package cake - * @subpackage cake.cake.libs.model.datasources.dbo + * @package cake.libs.model.datasources.dbo */ class DboPostgres extends DboSource { @@ -112,23 +110,29 @@ class DboPostgres extends DboSource { */ function connect() { $config = $this->config; - $conn = "host='{$config['host']}' port='{$config['port']}' dbname='{$config['database']}' "; - $conn .= "user='{$config['login']}' password='{$config['password']}'"; - - if (!$config['persistent']) { - $this->connection = pg_connect($conn, PGSQL_CONNECT_FORCE_NEW); - } else { - $this->connection = pg_pconnect($conn); - } $this->connected = false; + try { + $flags = array( + PDO::ATTR_PERSISTENT => $config['persistent'] + ); + $this->_connection = new PDO( + "pgsql:host={$config['host']};port={$config['port']};dbname={$config['database']}", + $config['login'], + $config['password'], + $flags + ); - if ($this->connection) { $this->connected = true; - $this->_execute("SET search_path TO " . $config['schema']); - } - if (!empty($config['encoding'])) { - $this->setEncoding($config['encoding']); + if (!empty($config['encoding'])) { + $this->setEncoding($config['encoding']); + } + if (!empty($config['schema'])) { + $this->_execute('SET search_path TO ' . $config['schema']); + } + } catch (PDOException $e) { + $this->errors[] = $e->getMessage(); } + return $this->connected; } @@ -138,33 +142,7 @@ class DboPostgres extends DboSource { * @return boolean */ function enabled() { - return extension_loaded('pgsql'); - } -/** - * Disconnects from database. - * - * @return boolean True if the database could be disconnected, else false - */ - function disconnect() { - if ($this->hasResult()) { - pg_free_result($this->_result); - } - if (is_resource($this->connection)) { - $this->connected = !pg_close($this->connection); - } else { - $this->connected = false; - } - return !$this->connected; - } - -/** - * Executes given SQL statement. - * - * @param string $sql SQL statement - * @return resource Result resource identifier - */ - function _execute($sql) { - return pg_query($this->connection, $sql); + return in_array('pgsql', PDO::getAvailableDrivers()); } /** @@ -172,7 +150,7 @@ class DboPostgres extends DboSource { * * @return array Array of tablenames in the database */ - function listSources() { + function listSources($data = null) { $cache = parent::listSources(); if ($cache != null) { @@ -180,18 +158,20 @@ class DboPostgres extends DboSource { } $schema = $this->config['schema']; - $sql = "SELECT table_name as name FROM INFORMATION_SCHEMA.tables WHERE table_schema = '{$schema}';"; - $result = $this->fetchAll($sql, false); + $sql = "SELECT table_name as name FROM INFORMATION_SCHEMA.tables WHERE table_schema = ?"; + $result = $this->_execute($sql, array($schema)); if (!$result) { + $result->closeCursor(); return array(); } else { $tables = array(); foreach ($result as $item) { - $tables[] = $item[0]['name']; + $tables[] = $item->name; } + $result->closeCursor(); parent::listSources($tables); return $tables; } @@ -203,67 +183,62 @@ class DboPostgres extends DboSource { * @param string $tableName Name of database table to inspect * @return array Fields in table. Keys are name and type */ - function &describe(&$model) { + function describe($model) { $fields = parent::describe($model); $table = $this->fullTableName($model, false); $this->_sequenceMap[$table] = array(); if ($fields === null) { - $cols = $this->fetchAll( + $cols = $this->_execute( "SELECT DISTINCT column_name AS name, data_type AS type, is_nullable AS null, column_default AS default, ordinal_position AS position, character_maximum_length AS char_length, character_octet_length AS oct_length FROM information_schema.columns - WHERE table_name = " . $this->value($table) . " AND table_schema = " . - $this->value($this->config['schema'])." ORDER BY position", - false + WHERE table_name = ? AND table_schema = ? ORDER BY position", + array($table, $this->config['schema']) ); - foreach ($cols as $column) { - $colKey = array_keys($column); - - if (isset($column[$colKey[0]]) && !isset($column[0])) { - $column[0] = $column[$colKey[0]]; - } - - if (isset($column[0])) { - $c = $column[0]; - - if (!empty($c['char_length'])) { - $length = intval($c['char_length']); - } elseif (!empty($c['oct_length'])) { - if ($c['type'] == 'character varying') { - $length = null; - $c['type'] = 'text'; - } else { - $length = intval($c['oct_length']); - } + foreach ($cols as $c) { + $type = $c->type; + if (!empty($c->oct_length) && $c->char_length === null) { + if ($c->type == 'character varying') { + $length = null; + $type = 'text'; } else { - $length = $this->length($c['type']); + $length = intval($c->oct_length); } - $fields[$c['name']] = array( - 'type' => $this->column($c['type']), - 'null' => ($c['null'] == 'NO' ? false : true), - 'default' => preg_replace( - "/^'(.*)'$/", - "$1", - preg_replace('/::.*/', '', $c['default']) - ), - 'length' => $length - ); - if ($c['name'] == $model->primaryKey) { - $fields[$c['name']]['key'] = 'primary'; - if ($fields[$c['name']]['type'] !== 'string') { - $fields[$c['name']]['length'] = 11; + } elseif (!empty($c->char_length)) { + $length = intval($c->char_length); + } else { + $length = $this->length($c->type); + } + if (empty($length)) { + $length = null; + } + $fields[$c->name] = array( + 'type' => $this->column($type), + 'null' => ($c->null == 'NO' ? false : true), + 'default' => preg_replace( + "/^'(.*)'$/", + "$1", + preg_replace('/::.*/', '', $c->default) + ), + 'length' => $length + ); + if ($model instanceof Model) { + if ($c->name == $model->primaryKey) { + $fields[$c->name]['key'] = 'primary'; + if ($fields[$c->name]['type'] !== 'string') { + $fields[$c->name]['length'] = 11; } } - if ( - $fields[$c['name']]['default'] == 'NULL' || - preg_match('/nextval\([\'"]?([\w.]+)/', $c['default'], $seq) - ) { - $fields[$c['name']]['default'] = null; - if (!empty($seq) && isset($seq[1])) { - $this->_sequenceMap[$table][$c['name']] = $seq[1]; - } + } + if ( + $fields[$c->name]['default'] == 'NULL' || + preg_match('/nextval\([\'"]?([\w.]+)/', $c->default, $seq) + ) { + $fields[$c->name]['default'] = null; + if (!empty($seq) && isset($seq[1])) { + $this->_sequenceMap[$table][$c->default] = $seq[1]; } } } @@ -272,93 +247,11 @@ class DboPostgres extends DboSource { if (isset($model->sequence)) { $this->_sequenceMap[$table][$model->primaryKey] = $model->sequence; } + + $cols->closeCursor(); return $fields; } -/** - * Returns a quoted and escaped string of $data for use in an SQL statement. - * - * @param string $data String to be prepared for use in an SQL statement - * @param string $column The column into which this data will be inserted - * @param boolean $read Value to be used in READ or WRITE context - * @return string Quoted and escaped - * @todo Add logic that formats/escapes data based on column type - */ - function value($data, $column = null, $read = true) { - - $parent = parent::value($data, $column); - if ($parent != null) { - return $parent; - } - - if ($data === null || (is_array($data) && empty($data))) { - return 'NULL'; - } - if (empty($column)) { - $column = $this->introspectType($data); - } - - switch($column) { - case 'binary': - $data = pg_escape_bytea($data); - break; - case 'boolean': - if ($data === true || $data === 't' || $data === 'true') { - return 'TRUE'; - } elseif ($data === false || $data === 'f' || $data === 'false') { - return 'FALSE'; - } - return (!empty($data) ? 'TRUE' : 'FALSE'); - break; - case 'float': - if (is_float($data)) { - $data = sprintf('%F', $data); - } - case 'inet': - case 'integer': - case 'date': - case 'datetime': - case 'timestamp': - case 'time': - if ($data === '') { - return $read ? 'NULL' : 'DEFAULT'; - } - default: - $data = pg_escape_string($data); - break; - } - return "'" . $data . "'"; - } - -/** - * Returns a formatted error message from previous database operation. - * - * @return string Error message - */ - function lastError() { - $error = pg_last_error($this->connection); - return ($error) ? $error : null; - } - -/** - * Returns number of affected rows in previous database operation. If no previous operation exists, this returns false. - * - * @return integer Number of affected rows - */ - function lastAffected() { - return ($this->_result) ? pg_affected_rows($this->_result) : false; - } - -/** - * Returns number of rows in previous resultset. If no previous resultset exists, - * this returns false. - * - * @return integer Number of rows in resultset - */ - function lastNumRows() { - return ($this->_result) ? pg_num_rows($this->_result) : false; - } - /** * Returns the ID generated from the previous INSERT operation. * @@ -368,8 +261,7 @@ class DboPostgres extends DboSource { */ function lastInsertId($source, $field = 'id') { $seq = $this->getSequence($source, $field); - $data = $this->fetchRow("SELECT currval('{$seq}') as max"); - return $data[0]['max']; + return $this->_connection->lastInsertId($seq); } /** @@ -394,20 +286,22 @@ class DboPostgres extends DboSource { * Deletes all the records in a table and drops all associated auto-increment sequences * * @param mixed $table A string or model class representing the table to be truncated - * @param integer $reset If -1, sequences are dropped, if 0 (default), sequences are reset, + * @param boolean $reset true for resseting the sequence, false to leave it as is. * and if 1, sequences are not modified * @return boolean SQL TRUNCATE TABLE statement, false if not applicable. */ - public function truncate($table, $reset = 0) { + public function truncate($table, $reset = true) { + $table = $this->fullTableName($table, false); + if (!isset($this->_sequenceMap[$table])) { + $cache = $this->cacheSources; + $this->cacheSources = false; + $this->describe($table); + $this->cacheSources = $cache; + } if (parent::truncate($table)) { - $table = $this->fullTableName($table, false); - if (isset($this->_sequenceMap[$table]) && $reset !== 1) { + if (isset($this->_sequenceMap[$table]) && $reset) { foreach ($this->_sequenceMap[$table] as $field => $sequence) { - if ($reset === 0) { - $this->execute("ALTER SEQUENCE \"{$sequence}\" RESTART WITH 1"); - } elseif ($reset === -1) { - $this->execute("DROP SEQUENCE IF EXISTS \"{$sequence}\""); - } + $this->_execute("ALTER SEQUENCE \"{$sequence}\" RESTART WITH 1"); } } return true; @@ -436,7 +330,7 @@ class DboPostgres extends DboSource { * @param mixed $fields * @return array */ - function fields(&$model, $alias = null, $fields = array(), $quote = true) { + function fields($model, $alias = null, $fields = array(), $quote = true) { if (empty($alias)) { $alias = $model->alias; } @@ -447,7 +341,7 @@ class DboPostgres extends DboSource { } $count = count($fields); - if ($count >= 1 && strpos($fields[0], 'COUNT(*)') === false) { + if ($count >= 1 && !preg_match('/^\s*COUNT\(\*/', $fields[0])) { $result = array(); for ($i = 0; $i < $count; $i++) { if (!preg_match('/^.+\\(.*\\)/', $fields[$i]) && !preg_match('/\s+AS\s+/', $fields[$i])) { @@ -781,20 +675,18 @@ class DboPostgres extends DboSource { * @param unknown_type $results */ function resultSet(&$results) { - $this->results =& $results; $this->map = array(); - $num_fields = pg_num_fields($results); + $numFields = $results->columnCount(); $index = 0; $j = 0; - while ($j < $num_fields) { - $columnName = pg_field_name($results, $j); - - if (strpos($columnName, '__')) { - $parts = explode('__', $columnName); - $this->map[$index++] = array($parts[0], $parts[1]); + while ($j < $numFields) { + $column = $results->getColumnMeta($j); + if (strpos($column['name'], '__')) { + list($table, $name) = explode('__', $column['name']); + $this->map[$index++] = array($table, $name, $column['native_type']); } else { - $this->map[$index++] = array(0, $columnName); + $this->map[$index++] = array(0, $column['name'], $column['native_type']); } $j++; } @@ -806,12 +698,11 @@ class DboPostgres extends DboSource { * @return unknown */ function fetchResult() { - if ($row = pg_fetch_row($this->results)) { + if ($row = $this->_result->fetch()) { $resultRow = array(); - foreach ($row as $index => $field) { - list($table, $column) = $this->map[$index]; - $type = pg_field_type($this->results, $index); + foreach ($this->map as $index => $meta) { + list($table, $column, $type) = $meta; switch ($type) { case 'bool': @@ -819,7 +710,7 @@ class DboPostgres extends DboSource { break; case 'binary': case 'bytea': - $resultRow[$table][$column] = pg_unescape_bytea($row[$index]); + $resultRow[$table][$column] = stream_get_contents($row[$index]); break; default: $resultRow[$table][$column] = $row[$index]; @@ -828,6 +719,7 @@ class DboPostgres extends DboSource { } return $resultRow; } else { + $this->_result->closeCursor(); return false; } } @@ -835,24 +727,33 @@ class DboPostgres extends DboSource { /** * Translates between PHP boolean values and PostgreSQL boolean values * - * @param mixed $data Value to be translated - * @param boolean $quote True to quote value, false otherwise - * @return mixed Converted boolean value + * @param mixed $data Value to be translated + * @param boolean $quote true to quote a boolean to be used in a query, flase to return the boolean value + * @return boolean Converted boolean value */ function boolean($data, $quote = true) { switch (true) { case ($data === true || $data === false): - return $data; + $result = $data; + break; case ($data === 't' || $data === 'f'): - return ($data === 't'); + $result = ($data === 't'); + break; case ($data === 'true' || $data === 'false'): - return ($data === 'true'); + $result = ($data === 'true'); + break; case ($data === 'TRUE' || $data === 'FALSE'): - return ($data === 'TRUE'); + $result = ($data === 'TRUE'); + break; default: - return (bool)$data; + $result = (bool) $data; break; } + + if ($quote) { + return ($result) ? 'TRUE' : 'FALSE'; + } + return (int) $result; } /** @@ -862,7 +763,10 @@ class DboPostgres extends DboSource { * @return boolean True on success, false on failure */ function setEncoding($enc) { - return pg_set_client_encoding($this->connection, $enc) == 0; + if ($this->_execute('SET NAMES ?', array($enc))) { + return true; + } + return false; } /** @@ -871,7 +775,7 @@ class DboPostgres extends DboSource { * @return string The database encoding */ function getEncoding() { - return pg_client_encoding($this->connection); + $cosa = $this->_execute('SHOW client_encoding')->fetch(); } /** diff --git a/cake/libs/model/datasources/dbo/dbo_sqlite.php b/cake/libs/model/datasources/dbo/dbo_sqlite.php index 67ca2111e..66859261e 100644 --- a/cake/libs/model/datasources/dbo/dbo_sqlite.php +++ b/cake/libs/model/datasources/dbo/dbo_sqlite.php @@ -12,19 +12,17 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.model.datasources.dbo + * @package cake.libs.model.datasources.dbo * @since CakePHP(tm) v 0.9.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ /** - * DBO implementation for the SQLite DBMS. + * DBO implementation for the SQLite3 DBMS. * - * Long description for class + * A DboSource adapter for SQLite 3 using PDO * - * @package cake - * @subpackage cake.cake.libs.model.datasources.dbo + * @package cake.libs.model.datasources.dbo */ class DboSqlite extends DboSource { @@ -32,63 +30,48 @@ class DboSqlite extends DboSource { * Datasource Description * * @var string + * @access public */ - public $description = "SQLite DBO Driver"; + var $description = "SQLite DBO Driver"; /** - * Opening quote for quoted identifiers + * Quote Start * * @var string + * @access public */ - public $startQuote = '"'; + var $startQuote = '"'; /** - * Closing quote for quoted identifiers + * Quote End * * @var string + * @access public */ - public $endQuote = '"'; + var $endQuote = '"'; /** - * Keeps the transaction statistics of CREATE/UPDATE/DELETE queries + * Base configuration settings for SQLite3 driver * * @var array - * @access protected + * @access public */ - protected $_queryStats = array(); - -/** - * Base configuration settings for SQLite driver - * - * @var array - */ - protected $_baseConfig = array( - 'persistent' => true, + var $_baseConfig = array( + 'persistent' => false, 'database' => null ); /** - * Index of basic SQL commands + * SQLite3 column definition * * @var array - * @access protected + * @access public */ - protected $_commands = array( - 'begin' => 'BEGIN TRANSACTION', - 'commit' => 'COMMIT TRANSACTION', - 'rollback' => 'ROLLBACK TRANSACTION' - ); - -/** - * SQLite column definition - * - * @var array - */ - public $columns = array( - 'primary_key' => array('name' => 'integer primary key'), + var $columns = array( + 'primary_key' => array('name' => 'integer primary key autoincrement'), 'string' => array('name' => 'varchar', 'limit' => '255'), 'text' => array('name' => 'text'), - 'integer' => array('name' => 'integer', 'limit' => 11, 'formatter' => 'intval'), + 'integer' => array('name' => 'integer', 'limit' => null, 'formatter' => 'intval'), 'float' => array('name' => 'float', 'formatter' => 'floatval'), 'datetime' => array('name' => 'datetime', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'), 'timestamp' => array('name' => 'timestamp', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'), @@ -104,12 +87,12 @@ class DboSqlite extends DboSource { * @var array * @access public */ - public $fieldParameters = array( + var $fieldParameters = array( 'collate' => array( 'value' => 'COLLATE', 'quote' => false, - 'join' => ' ', - 'column' => 'Collate', + 'join' => ' ', + 'column' => 'Collate', 'position' => 'afterDefault', 'options' => array( 'BINARY', 'NOCASE', 'RTRIM' @@ -122,83 +105,46 @@ class DboSqlite extends DboSource { * * @param array $config Configuration array for connecting * @return mixed + * @access public */ function connect() { $config = $this->config; - if (!$config['persistent']) { - $this->connection = sqlite_open($config['database']); - } else { - $this->connection = sqlite_popen($config['database']); + $flags = array(PDO::ATTR_PERSISTENT => $config['persistent']); + try { + $this->_connection = new PDO('sqlite:' . $config['database'], null, null, $flags); + $this->_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $this->connected = true; } - $this->connected = is_resource($this->connection); - - if ($this->connected) { - $this->_execute('PRAGMA count_changes = 1;'); + catch(PDOException $e) { + $this->errors[] = $e->getMessage(); } return $this->connected; } /** - * Check that SQLite is enabled/installed + * Check whether the MySQL extension is installed/loaded * * @return boolean */ function enabled() { - return extension_loaded('sqlite'); - } -/** - * Disconnects from database. - * - * @return boolean True if the database could be disconnected, else false - */ - function disconnect() { - @sqlite_close($this->connection); - $this->connected = false; - return $this->connected; - } - -/** - * Executes given SQL statement. - * - * @param string $sql SQL statement - * @return resource Result resource identifier - */ - function _execute($sql) { - $result = sqlite_query($this->connection, $sql); - - if (preg_match('/^(INSERT|UPDATE|DELETE)/', $sql)) { - $this->resultSet($result); - list($this->_queryStats) = $this->fetchResult(); - } - return $result; - } - -/** - * Overrides DboSource::execute() to correctly handle query statistics - * - * @param string $sql - * @return unknown - */ - function execute($sql) { - $result = parent::execute($sql); - $this->_queryStats = array(); - return $result; + return in_array('sqlite', PDO::getAvailableDrivers()); } /** * Returns an array of tables in the database. If there are no tables, an error is raised and the application exits. * * @return array Array of tablenames in the database + * @access public */ - function listSources() { + function listSources($data = null) { $cache = parent::listSources(); - if ($cache != null) { return $cache; } + $result = $this->fetchAll("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;", false); - if (empty($result)) { + if (!$result || empty($result)) { return array(); } else { $tables = array(); @@ -216,72 +162,40 @@ class DboSqlite extends DboSource { * * @param string $tableName Name of database table to inspect * @return array Fields in table. Keys are name and type + * @access public */ - function describe(&$model) { + function describe($model) { $cache = parent::describe($model); if ($cache != null) { return $cache; } $fields = array(); - $result = $this->fetchAll('PRAGMA table_info(' . $this->fullTableName($model) . ')'); + $result = $this->_execute('PRAGMA table_info(' . $model->tablePrefix . $model->table . ')'); foreach ($result as $column) { - $fields[$column[0]['name']] = array( - 'type' => $this->column($column[0]['type']), - 'null' => !$column[0]['notnull'], - 'default' => $column[0]['dflt_value'], - 'length' => $this->length($column[0]['type']) + $column = (array) $column; + $default = ($column['dflt_value'] === 'NULL') ? null : trim($column['dflt_value'], "'"); + + $fields[$column['name']] = array( + 'type' => $this->column($column['type']), + 'null' => !$column['notnull'], + 'default' => $default, + 'length' => $this->length($column['type']) ); - if ($column[0]['pk'] == 1) { - $colLength = $this->length($column[0]['type']); - $fields[$column[0]['name']] = array( - 'type' => $fields[$column[0]['name']]['type'], - 'null' => false, - 'default' => $column[0]['dflt_value'], - 'key' => $this->index['PRI'], - 'length'=> ($colLength != null) ? $colLength : 11 - ); + if ($column['pk'] == 1) { + $fields[$column['name']]['key'] = $this->index['PRI']; + $fields[$column['name']]['null'] = false; + if (empty($fields[$column['name']]['length'])) { + $fields[$column['name']]['length'] = 11; + } } } + $result->closeCursor(); $this->__cacheDescription($model->tablePrefix . $model->table, $fields); return $fields; } -/** - * Returns a quoted and escaped string of $data for use in an SQL statement. - * - * @param string $data String to be prepared for use in an SQL statement - * @return string Quoted and escaped - */ - function value($data, $column = null, $safe = false) { - $parent = parent::value($data, $column, $safe); - - if ($parent != null) { - return $parent; - } - if ($data === null) { - return 'NULL'; - } - if ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') { - return "''"; - } - switch ($column) { - case 'boolean': - $data = $this->boolean((bool)$data); - break; - case 'integer': - case 'float': - if ($data === '') { - return 'NULL'; - } - default: - $data = sqlite_escape_string($data); - break; - } - return "'" . $data . "'"; - } - /** * Generates and executes an SQL UPDATE statement for given model, fields, and values. * @@ -290,8 +204,9 @@ class DboSqlite extends DboSource { * @param array $values * @param mixed $conditions * @return array + * @access public */ - function update(&$model, $fields = array(), $values = null, $conditions = null) { + function update($model, $fields = array(), $values = null, $conditions = null) { if (empty($values) && !empty($fields)) { foreach ($fields as $field => $value) { if (strpos($field, $model->alias . '.') !== false) { @@ -302,8 +217,7 @@ class DboSqlite extends DboSource { } } } - $result = parent::update($model, $fields, $values, $conditions); - return $result; + return parent::update($model, $fields, $values, $conditions); } /** @@ -312,60 +226,11 @@ class DboSqlite extends DboSource { * * @param mixed $table A string or model class representing the table to be truncated * @return boolean SQL TRUNCATE TABLE statement, false if not applicable. + * @access public */ - public function truncate($table) { - return $this->execute('DELETE From ' . $this->fullTableName($table)); - } - -/** - * Returns a formatted error message from previous database operation. - * - * @return string Error message - */ - function lastError() { - $error = sqlite_last_error($this->connection); - if ($error) { - return $error.': '.sqlite_error_string($error); - } - return null; - } - -/** - * Returns number of affected rows in previous database operation. If no previous operation exists, this returns false. - * - * @return integer Number of affected rows - */ - function lastAffected() { - if (!empty($this->_queryStats)) { - foreach (array('rows inserted', 'rows updated', 'rows deleted') as $key) { - if (array_key_exists($key, $this->_queryStats)) { - return $this->_queryStats[$key]; - } - } - } - return false; - } - -/** - * Returns number of rows in previous resultset. If no previous resultset exists, - * this returns false. - * - * @return integer Number of rows in resultset - */ - function lastNumRows() { - if ($this->hasResult()) { - sqlite_num_rows($this->_result); - } - return false; - } - -/** - * Returns the ID generated from the previous INSERT operation. - * - * @return int - */ - function lastInsertId() { - return sqlite_last_insert_rowid($this->connection); + function truncate($table) { + $this->_execute('DELETE FROM sqlite_sequence where name=' . $this->fullTableName($table)); + return $this->execute('DELETE FROM ' . $this->fullTableName($table)); } /** @@ -373,6 +238,7 @@ class DboSqlite extends DboSource { * * @param string $real Real database-layer column type (i.e. "varchar(255)") * @return string Abstract column type (i.e. "string") + * @access public */ function column($real) { if (is_array($real)) { @@ -385,9 +251,7 @@ class DboSqlite extends DboSource { $col = strtolower(str_replace(')', '', $real)); $limit = null; - if (strpos($col, '(') !== false) { - list($col, $limit) = explode('(', $col); - } + @list($col, $limit) = explode('(', $col); if (in_array($col, array('text', 'integer', 'float', 'boolean', 'timestamp', 'date', 'datetime', 'time'))) { return $col; @@ -398,29 +262,55 @@ class DboSqlite extends DboSource { if (in_array($col, array('blob', 'clob'))) { return 'binary'; } - if (strpos($col, 'numeric') !== false) { + if (strpos($col, 'numeric') !== false || strpos($col, 'decimal') !== false) { return 'float'; } return 'text'; } /** - * Enter description here... + * Generate ResultSet * - * @param unknown_type $results + * @param mixed $results + * @access public */ - function resultSet(&$results) { - $this->results =& $results; + function resultSet($results) { + $this->results = $results; $this->map = array(); - $fieldCount = sqlite_num_fields($results); - $index = $j = 0; + $num_fields = $results->columnCount(); + $index = 0; + $j = 0; - while ($j < $fieldCount) { - $columnName = str_replace('"', '', sqlite_field_name($results, $j)); + //PDO::getColumnMeta is experimental and does not work with sqlite3, + // so try to figure it out based on the querystring + $querystring = $results->queryString; + if (stripos($querystring, 'SELECT') === 0) { + $last = stripos($querystring, 'FROM'); + if ($last !== false) { + $selectpart = substr($querystring, 7, $last - 8); + $selects = explode(',', $selectpart); + } + } elseif (strpos($querystring, 'PRAGMA table_info') === 0) { + $selects = array('cid', 'name', 'type', 'notnull', 'dflt_value', 'pk'); + } elseif(strpos($querystring, 'PRAGMA index_list') === 0) { + $selects = array('seq', 'name', 'unique'); + } elseif(strpos($querystring, 'PRAGMA index_info') === 0) { + $selects = array('seqno', 'cid', 'name'); + } + while ($j < $num_fields) { + if (preg_match('/\bAS\s+(.*)/i', $selects[$j], $matches)) { + $columnName = trim($matches[1],'"'); + } else { + $columnName = trim(str_replace('"', '', $selects[$j])); + } + + if (strpos($selects[$j], 'DISTINCT') === 0) { + $columnName = str_ireplace('DISTINCT', '', $columnName); + } if (strpos($columnName, '.')) { $parts = explode('.', $columnName); - $this->map[$index++] = array($parts[0], $parts[1]); + $this->map[$index++] = array(trim($parts[0]), trim($parts[1])); } else { $this->map[$index++] = array(0, $columnName); } @@ -431,34 +321,30 @@ class DboSqlite extends DboSource { /** * Fetches the next row from the current result set * - * @return unknown + * @return mixed array with results fetched and mapped to column names or false if there is no results left to fetch */ function fetchResult() { - if ($row = sqlite_fetch_array($this->results, SQLITE_ASSOC)) { + if ($row = $this->_result->fetch()) { $resultRow = array(); - $i = 0; - - foreach ($row as $index => $field) { - if (strpos($index, '.')) { - list($table, $column) = explode('.', str_replace('"', '', $index)); - $resultRow[$table][$column] = $row[$index]; - } else { - $resultRow[0][str_replace('"', '', $index)] = $row[$index]; - } - $i++; + foreach ($this->map as $col => $meta) { + list($table, $column) = $meta; + $resultRow[$table][$column] = $row[$col]; } return $resultRow; } else { + $this->_result->closeCursor(); return false; } } + /** * Returns a limit statement in the correct format for the particular database. * * @param integer $limit Limit of results returned * @param integer $offset Offset from which to start results * @return string SQL limit/offset statement + * @access public */ function limit($limit, $offset = null) { if ($limit) { @@ -479,8 +365,9 @@ class DboSqlite extends DboSource { * Generate a database-native column schema string * * @param array $column An array structured like the following: array('name'=>'value', 'type'=>'value'[, options]), - * where options can be 'default', 'length', or 'key'. + * where options can be 'default', 'length', or 'key'. * @return string + * @access public */ function buildColumn($column) { $name = $type = null; @@ -488,7 +375,7 @@ class DboSqlite extends DboSource { extract($column); if (empty($name) || empty($type)) { - trigger_error(__('Column name or type not defined in schema'), E_USER_WARNING); + trigger_error('Column name or type not defined in schema', E_USER_WARNING); return null; } @@ -509,6 +396,7 @@ class DboSqlite extends DboSource { * Sets the database encoding * * @param string $enc Database encoding + * @access public */ function setEncoding($enc) { if (!in_array($enc, array("UTF-8", "UTF-16", "UTF-16le", "UTF-16be"))) { @@ -521,6 +409,7 @@ class DboSqlite extends DboSource { * Gets the database encoding * * @return string The database encoding + * @access public */ function getEncoding() { return $this->fetchRow('PRAGMA encoding'); @@ -532,6 +421,7 @@ class DboSqlite extends DboSource { * @param array $indexes * @param string $table * @return string + * @access public */ function buildIndex($indexes, $table = null) { $join = array(); @@ -547,11 +437,12 @@ class DboSqlite extends DboSource { $out .= 'UNIQUE '; } if (is_array($value['column'])) { - $value['column'] = implode(', ', array_map(array(&$this, 'name'), $value['column'])); + $value['column'] = join(', ', array_map(array(&$this, 'name'), $value['column'])); } else { $value['column'] = $this->name($value['column']); } - $out .= "INDEX {$name} ON {$table}({$value['column']});"; + $t = trim($table, '"'); + $out .= "INDEX {$t}_{$name} ON {$table}({$value['column']});"; $join[] = $out; } return $join; @@ -563,13 +454,17 @@ class DboSqlite extends DboSource { * * @param string $model Name of model to inspect * @return array Fields in table. Keys are column and unique + * @access public */ - function index(&$model) { + function index($model) { $index = array(); $table = $this->fullTableName($model); if ($table) { $indexes = $this->query('PRAGMA index_list(' . $table . ')'); - $tableInfo = $this->query('PRAGMA table_info(' . $table . ')'); + + if (is_bool($indexes)) { + return array(); + } foreach ($indexes as $i => $info) { $key = array_pop($info); $keyInfo = $this->query('PRAGMA index_info("' . $key['name'] . '")'); @@ -600,16 +495,17 @@ class DboSqlite extends DboSource { * @param string $type * @param array $data * @return string + * @access public */ function renderStatement($type, $data) { switch (strtolower($type)) { case 'schema': extract($data); - - foreach (array('columns', 'indexes') as $var) { - if (is_array(${$var})) { - ${$var} = "\t" . implode(",\n\t", array_filter(${$var})); - } + if (is_array($columns)) { + $columns = "\t" . join(",\n\t", array_filter($columns)); + } + if (is_array($indexes)) { + $indexes = "\t" . join("\n\t", array_filter($indexes)); } return "CREATE TABLE {$table} (\n{$columns});\n{$indexes}"; break; @@ -618,4 +514,32 @@ class DboSqlite extends DboSource { break; } } + +/** + * PDO deals in objects, not resources, so overload accordingly. + * + * @return boolean + * @access public + */ + function hasResult() { + return is_object($this->_result); + } + +/** + * Generate a "drop table" statement for the given Schema object + * + * @param object $schema An instance of a subclass of CakeSchema + * @param string $table Optional. If specified only the table name given will be generated. + * Otherwise, all tables defined in the schema are generated. + * @return string + */ + public function dropSchema(CakeSchema $schema, $table = null) { + $out = ''; + foreach ($schema->tables as $curTable => $columns) { + if (!$table || $table == $curTable) { + $out .= 'DROP TABLE IF EXISTS ' . $this->fullTableName($curTable) . ";\n"; + } + } + return $out; + } } diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 566463610..717e5ca92 100755 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.model.datasources + * @package cake.libs.model.datasources * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,8 +23,7 @@ App::import('Core', 'String'); * * Creates DBO-descendant objects from a given db connection configuration * - * @package cake - * @subpackage cake.cake.libs.model.datasources + * @package cake.libs.model.datasources */ class DboSource extends DataSource { @@ -88,6 +86,14 @@ class DboSource extends DataSource { */ private $__sqlOps = array('like', 'ilike', 'or', 'not', 'in', 'between', 'regexp', 'similar to'); +/** + * Indicates the level of nested transactions + * + * @var integer + * @access protected + */ + protected $_transactionNesting = 0; + /** * Index of basic SQL commands * @@ -160,18 +166,42 @@ class DboSource extends DataSource { } /** - * Prepares a value, or an array of values for database queries by quoting and escaping them. + * Disconnects from database. * - * @param mixed $data A value or an array of values to prepare. - * @param string $column The column into which this data will be inserted - * @param boolean $read Value to be used in READ or WRITE context - * @return mixed Prepared value or array of values. + * @return boolean True if the database could be disconnected, else false */ - public function value($data, $column = null, $read = true) { + function disconnect() { + if ($this->_result instanceof PDOStatement) { + $this->_result->closeCursor(); + } + unset($this->_connection); + $this->connected = false; + return !$this->connected; + } + +/** + * Get the underlying connection object. + * + * @return PDOConnection + */ + public function getConnection() { + return $this->_connection; + } + + +/** + * Returns a quoted and escaped string of $data for use in an SQL statement. + * + * @param string $data String to be prepared for use in an SQL statement + * @param string $column The column into which this data will be inserted + * @param boolean $safe Whether or not numeric data should be handled automagically if no column data is provided + * @return string Quoted and escaped data + */ + function value($data, $column = null, $safe = false) { if (is_array($data) && !empty($data)) { return array_map( array(&$this, 'value'), - $data, array_fill(0, count($data), $column), array_fill(0, count($data), $read) + $data, array_fill(0, count($data), $column), array_fill(0, count($data), $safe) ); } elseif (is_object($data) && isset($data->type)) { if ($data->type == 'identifier') { @@ -181,15 +211,50 @@ class DboSource extends DataSource { } } elseif (in_array($data, array('{$__cakeID__$}', '{$__cakeForeignKey__$}'), true)) { return $data; - } else { - return null; + } + + if ($data === null || (is_array($data) && empty($data))) { + return 'NULL'; + } + + if (empty($column)) { + $column = $this->introspectType($data); + } + + switch ($column) { + case 'binary': + return $this->_connection->quote($data, PDO::PARAM_LOB); + break; + case 'boolean': + return $this->_connection->quote($this->boolean($data), PDO::PARAM_BOOL); + break; + case 'string': + case 'text': + return $this->_connection->quote($data, PDO::PARAM_STR); + default: + if ($data === '') { + return 'NULL'; + } + if (is_float($data)) { + return sprintf('%F', $data); + } + if ((is_int($data) || $data === '0') || ( + is_numeric($data) && strpos($data, ',') === false && + $data[0] != '0' && strpos($data, 'e') === false) + ) { + return $data; + } + return $this->_connection->quote($data); + break; } } + /** - * Returns an object to represent a database identifier in a query + * Returns an object to represent a database identifier in a query. Expression objects + * are not sanitized or esacped. * - * @param string $identifier + * @param string $identifier A SQL expression to be used as an identifier * @return object An object representing a database identifier to be used in a query */ public function identifier($identifier) { @@ -200,9 +265,10 @@ class DboSource extends DataSource { } /** - * Returns an object to represent a database expression in a query + * Returns an object to represent a database expression in a query. Expression objects + * are not sanitized or esacped. * - * @param string $expression + * @param string $expression An arbitrary SQL expression to be inserted into a query. * @return object An object representing a database expression to be used in a query */ public function expression($expression) { @@ -216,11 +282,12 @@ class DboSource extends DataSource { * Executes given SQL statement. * * @param string $sql SQL statement + * @param array $params Additional options for the query. * @return boolean */ - public function rawQuery($sql) { + public function rawQuery($sql, $params = array()) { $this->took = $this->error = $this->numRows = false; - return $this->execute($sql); + return $this->execute($sql, $params); } /** @@ -230,28 +297,23 @@ class DboSource extends DataSource { * * ### Options * - * - stats - Collect meta data stats for this query. Stats include time take, rows affected, - * any errors, and number of rows returned. Defaults to `true`. * - log - Whether or not the query should be logged to the memory log. * * @param string $sql * @param array $options + * @param array $params values to be bided to the query * @return mixed Resource or object representing the result set, or false on failure */ - public function execute($sql, $options = array()) { - $defaults = array('stats' => true, 'log' => $this->fullDebug); - $options = array_merge($defaults, $options); + public function execute($sql, $options = array(), $params = array()) { + $options = $options + array('log' => $this->fullDebug); + $this->error = null; $t = microtime(true); - $this->_result = $this->_execute($sql); - if ($options['stats']) { - $this->took = round((microtime(true) - $t) * 1000, 0); - $this->affected = $this->lastAffected(); - $this->error = $this->lastError(); - $this->numRows = $this->lastNumRows(); - } + $this->_result = $this->_execute($sql, $params); if ($options['log']) { + $this->took = round((microtime(true) - $t) * 1000, 0); + $this->numRows = $this->affected = $this->lastAffected(); $this->logQuery($sql); } @@ -262,6 +324,85 @@ class DboSource extends DataSource { return $this->_result; } +/** + * Executes given SQL statement. + * + * @param string $sql SQL statement + * @param array $params list of params to be bound to query + * @return PDOStatement if query executes with no problem, true as the result of a succesfull + * query returning no rows, suchs as a CREATE statement, false otherwise + */ + protected function _execute($sql, $params = array()) { + $sql = trim($sql); + if (preg_match('/^(?:CREATE|ALTER|DROP)/i', $sql)) { + $statements = array_filter(explode(';', $sql)); + if (count($statements) > 1) { + $result = array_map(array($this, '_execute'), $statements); + return array_search(false, $result) === false; + } + } + + try { + $query = $this->_connection->prepare($sql); + $query->setFetchMode(PDO::FETCH_LAZY); + if (!$query->execute($params)) { + $this->_results = $query; + $this->error = $this->lastError($query); + $query->closeCursor(); + return false; + } + if (!$query->columnCount()) { + $query->closeCursor(); + return true; + } + return $query; + } catch (PDOException $e) { + $this->_results = null; + $this->error = $e->getMessage(); + return false; + } + + } + +/** + * Returns a formatted error message from previous database operation. + * + * @param PDOStatement $query the query to extract the error from if any + * @return string Error message with error number + */ + function lastError(PDOStatement $query = null) { + $error = $query->errorInfo(); + if (empty($error[2])) { + return null; + } + return $error[1] . ': ' . $error[2]; + } + +/** + * Returns number of affected rows in previous database operation. If no previous operation exists, + * this returns false. + * + * @param string $source + * @return integer Number of affected rows + */ + function lastAffected($source = null) { + if ($this->hasResult()) { + return $this->_result->rowCount(); + } + return null; + } + +/** + * Returns number of rows in previous resultset. If no previous resultset exists, + * this returns false. + * + * @param string $source + * @return integer Number of rows in resultset + */ + function lastNumRows($source = null) { + return $this->lastAffected($source); + } + /** * DataSource Query abstraction * @@ -278,14 +419,14 @@ class DboSource extends DataSource { if (count($args) == 1) { return $this->fetchAll($args[0]); - } elseif (count($args) > 1 && (strpos(strtolower($args[0]), 'findby') === 0 || strpos(strtolower($args[0]), 'findallby') === 0)) { + } elseif (count($args) > 1 && (strpos($args[0], 'findBy') === 0 || strpos($args[0], 'findAllBy') === 0)) { $params = $args[1]; - if (strpos(strtolower($args[0]), 'findby') === 0) { - $all = false; + if (strpos($args[0], 'findBy') === 0) { + $all = false; $field = Inflector::underscore(preg_replace('/^findBy/i', '', $args[0])); } else { - $all = true; + $all = true; $field = Inflector::underscore(preg_replace('/^findAllBy/i', '', $args[0])); } @@ -352,8 +493,7 @@ class DboSource extends DataSource { } else { $cache = true; } - $args[1] = array_map(array(&$this, 'value'), $args[1]); - return $this->fetchAll(String::insert($args[0], $args[1]), $cache); + return $this->fetchAll($args[0], $args[1], array('cache' => $cache)); } } } @@ -361,6 +501,7 @@ class DboSource extends DataSource { /** * Returns a row from current resultset as an array * + * @param string $sql Some SQL to be executed. * @return array The fetched row as an array */ public function fetchRow($sql = null) { @@ -386,16 +527,31 @@ class DboSource extends DataSource { * Returns an array of all result rows for a given SQL query. * Returns false if no rows matched. * + * + * ### Options + * + * - cache - Returns the cached version of the query, if exists and stores the result in cache + * * @param string $sql SQL statement - * @param boolean $cache Enables returning/storing cached query results + * @param array $params parameters to be bound as values for the SQL statement + * @param array $options additional options for the query. * @return array Array of resultset rows, or false if no rows matched */ - public function fetchAll($sql, $cache = true, $modelName = null) { - if ($cache && ($cached = $this->getQueryCache($sql)) !== false) { + public function fetchAll($sql, $params = array(), $options = array()) { + if (is_string($options)) { + $options = array('modelName' => $options); + } + if (is_bool($params)) { + $options['cache'] = $params; + $params = array(); + } + $defaults = array('cache' => true); + $options = $options + $defaults; + $cache = $options['cache']; + if ($cache && ($cached = $this->getQueryCache($sql, $params)) !== false) { return $cached; } - - if ($this->execute($sql)) { + if ($result = $this->execute($sql, array(), $params)) { $out = array(); $first = $this->fetchRow(); @@ -407,9 +563,10 @@ class DboSource extends DataSource { $out[] = $item; } - if ($cache) { - $this->_writeQueryCache($sql, $out); + if (!is_bool($result) && $cache) { + $this->_writeQueryCache($sql, $out, $params); } + if (empty($out) && is_bool($this->_result)) { return $this->_result; } @@ -422,7 +579,7 @@ class DboSource extends DataSource { /** * Modifies $result array to place virtual fields in model entry where they belongs to * - * @param array $resut REference to the fetched row + * @param array $resut Reference to the fetched row * @return void */ public function fetchVirtualField(&$result) { @@ -526,7 +683,7 @@ class DboSource extends DataSource { return $return; } $data = trim($data); - if (preg_match('/^[\w-]+(\.[\w-]+)*$/', $data)) { // string, string.string + if (preg_match('/^[\w-]+(?:\.[^ \*]*)*$/', $data)) { // string, string.string if (strpos($data, '.') === false) { // string return $this->cacheMethod(__FUNCTION__, $cacheKey, $this->startQuote . $data . $this->endQuote); } @@ -576,13 +733,14 @@ class DboSource extends DataSource { * @return boolean True if the result is valid else false */ public function hasResult() { - return is_resource($this->_result); + return is_a($this->_result, 'PDOStatement'); } /** * Get the query log as an array. * * @param boolean $sorted Get the queries sorted by time taken, defaults to false. + * @param boolean $clear If True the existing log will cleared. * @return array Array of queries run as an array */ public function getLog($sorted = false, $clear = true) { @@ -701,7 +859,7 @@ class DboSource extends DataSource { * be used to generate values. * @return boolean Success */ - public function create(&$model, $fields = null, $values = null) { + public function create($model, $fields = null, $values = null) { $id = null; if ($fields == null) { @@ -749,7 +907,7 @@ class DboSource extends DataSource { * @param integer $recursive Number of levels of association * @return mixed boolean false on error/failure. An array of results on success. */ - public function read(&$model, $queryData = array(), $recursive = null) { + public function read($model, $queryData = array(), $recursive = null) { $queryData = $this->__scrubQueryData($queryData); $null = null; @@ -784,7 +942,7 @@ class DboSource extends DataSource { foreach ($_associations as $type) { foreach ($model->{$type} as $assoc => $assocData) { - $linkModel =& $model->{$assoc}; + $linkModel = $model->{$assoc}; $external = isset($assocData['external']); if ($model->useDbConfig == $linkModel->useDbConfig) { @@ -795,9 +953,9 @@ class DboSource extends DataSource { } } - $query = $this->generateAssociationQuery($model, $null, null, null, null, $queryData, false, $null); + $query = trim($this->generateAssociationQuery($model, $null, null, null, null, $queryData, false, $null)); - $resultSet = $this->fetchAll($query, $model->cacheQueries, $model->alias); + $resultSet = $this->fetchAll($query, $model->cacheQueries); if ($resultSet === false) { $model->onError(); @@ -809,16 +967,16 @@ class DboSource extends DataSource { if ($model->recursive > -1) { foreach ($_associations as $type) { foreach ($model->{$type} as $assoc => $assocData) { - $linkModel =& $model->{$assoc}; + $linkModel = $model->{$assoc}; if (empty($linkedModels[$type . '/' . $assoc])) { if ($model->useDbConfig == $linkModel->useDbConfig) { - $db =& $this; + $db = $this; } else { - $db =& ConnectionManager::getDataSource($linkModel->useDbConfig); + $db = ConnectionManager::getDataSource($linkModel->useDbConfig); } } elseif ($model->recursive > 1 && ($type == 'belongsTo' || $type == 'hasOne')) { - $db =& $this; + $db = $this; } if (isset($db) && method_exists($db, 'queryAssociation')) { @@ -893,7 +1051,7 @@ class DboSource extends DataSource { * @param integer $recursive Number of levels of association * @param array $stack */ - public function queryAssociation(&$model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet, $recursive, $stack) { + public function queryAssociation($model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet, $recursive, $stack) { if ($query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet)) { if (!isset($resultSet) || !is_array($resultSet)) { if (Configure::read('debug') > 0) { @@ -924,14 +1082,14 @@ class DboSource extends DataSource { if ($recursive > 0) { foreach ($linkModel->associations() as $type1) { foreach ($linkModel->{$type1} as $assoc1 => $assocData1) { - $deepModel =& $linkModel->{$assoc1}; + $deepModel = $linkModel->{$assoc1}; $tmpStack = $stack; $tmpStack[] = $assoc1; if ($linkModel->useDbConfig === $deepModel->useDbConfig) { - $db =& $this; + $db = $this; } else { - $db =& ConnectionManager::getDataSource($deepModel->useDbConfig); + $db = ConnectionManager::getDataSource($deepModel->useDbConfig); } $db->queryAssociation($linkModel, $deepModel, $type1, $assoc1, $assocData1, $queryData, true, $fetch, $recursive - 1, $tmpStack); } @@ -966,7 +1124,7 @@ class DboSource extends DataSource { $q = $this->insertQueryData($query, null, $association, $assocData, $model, $linkModel, $stack); if ($q != false) { - $fetch = $this->fetchAll($q, $model->cacheQueries, $model->alias); + $fetch = $this->fetchAll($q, $model->cacheQueries); } else { $fetch = null; } @@ -978,7 +1136,7 @@ class DboSource extends DataSource { if ($type !== 'hasAndBelongsToMany') { $q = $this->insertQueryData($query, $resultSet[$i], $association, $assocData, $model, $linkModel, $stack); if ($q != false) { - $fetch = $this->fetchAll($q, $model->cacheQueries, $model->alias); + $fetch = $this->fetchAll($q, $model->cacheQueries); } else { $fetch = null; } @@ -993,15 +1151,15 @@ class DboSource extends DataSource { if ($recursive > 0) { foreach ($linkModel->associations() as $type1) { foreach ($linkModel->{$type1} as $assoc1 => $assocData1) { - $deepModel =& $linkModel->{$assoc1}; + $deepModel = $linkModel->{$assoc1}; if (($type1 === 'belongsTo') || ($deepModel->alias === $model->alias && $type === 'belongsTo') || ($deepModel->alias != $model->alias)) { $tmpStack = $stack; $tmpStack[] = $assoc1; if ($linkModel->useDbConfig == $deepModel->useDbConfig) { - $db =& $this; + $db = $this; } else { - $db =& ConnectionManager::getDataSource($deepModel->useDbConfig); + $db = ConnectionManager::getDataSource($deepModel->useDbConfig); } $db->queryAssociation($linkModel, $deepModel, $type1, $assoc1, $assocData1, $queryData, true, $fetch, $recursive - 1, $tmpStack); } @@ -1053,7 +1211,7 @@ class DboSource extends DataSource { if (count($ids) > 1) { $query = str_replace('= (', 'IN (', $query); } - return $this->fetchAll($query, $model->cacheQueries, $model->alias); + return $this->fetchAll($query, $model->cacheQueries); } /** @@ -1189,7 +1347,7 @@ class DboSource extends DataSource { * @param array $resultSet * @return mixed */ - public function generateAssociationQuery(&$model, &$linkModel, $type, $association = null, $assocData = array(), &$queryData, $external = false, &$resultSet) { + public function generateAssociationQuery($model, &$linkModel, $type, $association = null, $assocData = array(), &$queryData, $external = false, &$resultSet) { $queryData = $this->__scrubQueryData($queryData); $assocData = $this->__scrubQueryData($assocData); @@ -1422,7 +1580,7 @@ class DboSource extends DataSource { * @access public * @see DboSource::renderStatement() */ - public function buildStatement($query, &$model) { + public function buildStatement($query, $model) { $query = array_merge(array('offset' => null, 'joins' => array()), $query); if (!empty($query['joins'])) { $count = count($query['joins']); @@ -1541,7 +1699,7 @@ class DboSource extends DataSource { * @param mixed $conditions * @return boolean Success */ - public function update(&$model, $fields = array(), $values = null, $conditions = null) { + public function update($model, $fields = array(), $values = null, $conditions = null) { if ($values == null) { $combined = $fields; } else { @@ -1575,7 +1733,7 @@ class DboSource extends DataSource { * @param boolean $alias Include the model alias in the field name * @return array Fields and values, quoted and preparted */ - protected function _prepareUpdateFields(&$model, $fields, $quoteValues = true, $alias = false) { + protected function _prepareUpdateFields($model, $fields, $quoteValues = true, $alias = false) { $quotedAlias = $this->startQuote . $model->alias . $this->endQuote; $updates = array(); @@ -1618,7 +1776,7 @@ class DboSource extends DataSource { * @param mixed $conditions * @return boolean Success */ - public function delete(&$model, $conditions = null) { + public function delete($model, $conditions = null) { $alias = $joins = null; $table = $this->fullTableName($model); $conditions = $this->_matchRecords($model, $conditions); @@ -1642,7 +1800,7 @@ class DboSource extends DataSource { * @param mixed $conditions * @return array List of record IDs */ - protected function _matchRecords(&$model, $conditions = null) { + protected function _matchRecords($model, $conditions = null) { if ($conditions === true) { $conditions = $this->conditions(true); } elseif ($conditions === null) { @@ -1718,7 +1876,7 @@ class DboSource extends DataSource { * @param array $params Function parameters (any values must be quoted manually) * @return string An SQL calculation function */ - public function calculate(&$model, $func, $params = array()) { + public function calculate($model, $func, $params = array()) { $params = (array)$params; switch (strtolower($func)) { @@ -1764,14 +1922,14 @@ class DboSource extends DataSource { /** * Begin a transaction * - * @param model $model * @return boolean True on success, false on fail * (i.e. if the database/model does not support transactions, * or a transaction has not started). */ - public function begin(&$model) { - if (parent::begin($model) && $this->execute($this->_commands['begin'])) { + public function begin() { + if ($this->_transactionStarted || $this->_connection->beginTransaction()) { $this->_transactionStarted = true; + $this->_transactionNesting++; return true; } return false; @@ -1780,14 +1938,18 @@ class DboSource extends DataSource { /** * Commit a transaction * - * @param model $model * @return boolean True on success, false on fail * (i.e. if the database/model does not support transactions, * or a transaction has not started). */ - public function commit(&$model) { - if (parent::commit($model) && $this->execute($this->_commands['commit'])) { - $this->_transactionStarted = false; + public function commit() { + if ($this->_transactionStarted) { + $this->_transactionNesting--; + if ($this->_transactionNesting <= 0) { + $this->_transactionStarted = false; + $this->_transactionNesting = 0; + return $this->_connection->commit(); + } return true; } return false; @@ -1796,19 +1958,29 @@ class DboSource extends DataSource { /** * Rollback a transaction * - * @param model $model * @return boolean True on success, false on fail * (i.e. if the database/model does not support transactions, * or a transaction has not started). */ - public function rollback(&$model) { - if (parent::rollback($model) && $this->execute($this->_commands['rollback'])) { + public function rollback() { + if ($this->_transactionStarted && $this->_connection->rollBack()) { $this->_transactionStarted = false; + $this->_transactionNesting = 0; return true; } return false; } +/** + * Returns the ID generated from the previous INSERT operation. + * + * @param unknown_type $source + * @return in + */ + function lastInsertId($source = null) { + return $this->_connection->lastInsertId(); + } + /** * Creates a default set of conditions from the model if $conditions is null/empty. * If conditions are supplied then they will be returned. If a model doesn't exist and no conditions @@ -1823,7 +1995,7 @@ class DboSource extends DataSource { * @see DboSource::update() * @see DboSource::conditions() */ - public function defaultConditions(&$model, $conditions, $useAlias = true) { + public function defaultConditions($model, $conditions, $useAlias = true) { if (!empty($conditions)) { return $conditions; } @@ -1882,7 +2054,7 @@ class DboSource extends DataSource { * @param mixed $fields virtual fields to be used on query * @return array */ - protected function _constructVirtualFields(&$model, $alias, $fields) { + protected function _constructVirtualFields($model, $alias, $fields) { $virtual = array(); foreach ($fields as $field) { $virtualField = $this->name($alias . $this->virtualFieldSeparator . $field); @@ -1901,7 +2073,7 @@ class DboSource extends DataSource { * @param boolean $quote If false, returns fields array unquoted * @return array */ - public function fields(&$model, $alias = null, $fields = array(), $quote = true) { + public function fields($model, $alias = null, $fields = array(), $quote = true) { if (empty($alias)) { $alias = $model->alias; } @@ -2194,7 +2366,7 @@ class DboSource extends DataSource { * @return string * @access private */ - function __parseKey(&$model, $key, $value) { + function __parseKey($model, $key, $value) { $operatorMatch = '/^((' . implode(')|(', $this->__sqlOps); $operatorMatch .= '\\x20)|<[>=]?(?![^>]+>)\\x20?|[>=!]{1,3}(?!<)\\x20?)/is'; $bound = (strpos($key, '?') !== false || (is_array($value) && strpos($key, ':') !== false)); @@ -2445,7 +2617,7 @@ class DboSource extends DataSource { * @param string $sql SQL WHERE clause (condition only, not the "WHERE" part) * @return boolean True if the table has a matching record, else false */ - public function hasAny(&$Model, $sql) { + public function hasAny($Model, $sql) { $sql = $this->conditions($sql); $table = $this->fullTableName($Model); $alias = $this->alias . $this->name($Model->alias); @@ -2524,7 +2696,7 @@ class DboSource extends DataSource { * Translates between PHP boolean values and Database (faked) boolean values * * @param mixed $data Value to be translated - * @return mixed Converted boolean value + * @return int Converted boolean value */ public function boolean($data) { if ($data === true || $data === false) { @@ -2533,7 +2705,7 @@ class DboSource extends DataSource { } return 0; } else { - return !empty($data); + return (int) !empty($data); } } @@ -2546,13 +2718,18 @@ class DboSource extends DataSource { */ public function insertMulti($table, $fields, $values) { $table = $this->fullTableName($table); - if (is_array($fields)) { - $fields = implode(', ', array_map(array(&$this, 'name'), $fields)); - } + $holder = implode(',', array_fill(0, count($fields), '?')); + $fields = implode(', ', array_map(array(&$this, 'name'), $fields)); + $count = count($values); + $sql = "INSERT INTO {$table} ({$fields}) VALUES ({$holder})"; + $statement = $this->_connection->prepare($sql); + $this->begin(); for ($x = 0; $x < $count; $x++) { - $this->query("INSERT INTO {$table} ({$fields}) VALUES {$values[$x]}"); + $statement->execute($values[$x]); + $statement->closeCursor(); } + return $this->commit(); } /** @@ -2629,16 +2806,12 @@ class DboSource extends DataSource { /** * Generate a "drop table" statement for the given Schema object * - * @param object $schema An instance of a subclass of CakeSchema + * @param CakeSchema $schema An instance of a subclass of CakeSchema * @param string $table Optional. If specified only the table name given will be generated. * Otherwise, all tables defined in the schema are generated. * @return string */ - public function dropSchema($schema, $table = null) { - if (!is_a($schema, 'CakeSchema')) { - trigger_error(__('Invalid schema object'), E_USER_WARNING); - return null; - } + public function dropSchema(CakeSchema $schema, $table = null) { $out = ''; foreach ($schema->tables as $curTable => $columns) { @@ -2867,11 +3040,12 @@ class DboSource extends DataSource { * * @param string $sql SQL query * @param mixed $data result of $sql query + * @param array $params query params bound as values * @return void */ - protected function _writeQueryCache($sql, $data) { - if (strpos(trim(strtolower($sql)), 'select') !== false) { - $this->_queryCache[$sql] = $data; + protected function _writeQueryCache($sql, $data, $params = array()) { + if (preg_match('/^\s*select/i', $sql)) { + $this->_queryCache[$sql][serialize($params)] = $data; } } @@ -2879,11 +3053,15 @@ class DboSource extends DataSource { * Returns the result for a sql query if it is already cached * * @param string $sql SQL query + * @param array $params query params bound as values * @return mixed results for query if it is cached, false otherwise */ - public function getQueryCache($sql = null) { + public function getQueryCache($sql, $params = array()) { if (isset($this->_queryCache[$sql]) && preg_match('/^\s*select/i', $sql)) { - return $this->_queryCache[$sql]; + $serialized = serialize($params); + if (isset($this->_queryCache[$sql][$serialized])) { + return $this->_queryCache[$sql][$serialized]; + } } return false; } diff --git a/cake/libs/model/db_acl.php b/cake/libs/model/db_acl.php index 70826bdb7..e8a31cef7 100644 --- a/cake/libs/model/db_acl.php +++ b/cake/libs/model/db_acl.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.model + * @package cake.libs.model * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -29,8 +28,7 @@ App::import('Model', 'App'); * ACL Node * * - * @package cake - * @subpackage cake.cake.libs.model + * @package cake.libs.model */ class AclNode extends AppModel { @@ -193,8 +191,7 @@ class AclNode extends AppModel { /** * Access Control Object * - * @package cake - * @subpackage cake.cake.libs.model + * @package cake.libs.model */ class Aco extends AclNode { @@ -218,8 +215,7 @@ class Aco extends AclNode { /** * Action for Access Control Object * - * @package cake - * @subpackage cake.cake.libs.model + * @package cake.libs.model */ class AcoAction extends AppModel { @@ -243,8 +239,7 @@ class AcoAction extends AppModel { /** * Access Request Object * - * @package cake - * @subpackage cake.cake.libs.model + * @package cake.libs.model */ class Aro extends AclNode { @@ -268,8 +263,7 @@ class Aro extends AclNode { /** * Permissions linking AROs with ACOs * - * @package cake - * @subpackage cake.cake.libs.model + * @package cake.libs.model */ class Permission extends AppModel { diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 085e1af94..396da7d4e 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.model + * @package cake.libs.model * @since CakePHP(tm) v 0.10.0.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -38,8 +37,7 @@ App::import('Model', 'ConnectionManager', false); * (i.e. class 'User' => table 'users'; class 'Man' => table 'men') * The table is required to have at least 'id auto_increment' primary key. * - * @package cake - * @subpackage cake.cake.libs.model + * @package cake.libs.model * @link http://book.cakephp.org/view/1000/Models */ class Model extends Object { @@ -330,7 +328,13 @@ class Model extends Object { * @var array * @access private */ - private $__backAssociation = array(); + public $__backAssociation = array(); + + public $__backInnerAssociation = array(); + + public $__backOriginalAssociation = array(); + + public $__backContainableAssociation = array(); /** * The ID of the model record that was last inserted. @@ -904,9 +908,6 @@ class Model extends Object { $dateFields = array('Y' => 'year', 'm' => 'month', 'd' => 'day', 'H' => 'hour', 'i' => 'min', 's' => 'sec'); $timeFields = array('H' => 'hour', 'i' => 'min', 's' => 'sec'); - - $db = $this->getDataSource(); - $format = $db->columns[$type]['format']; $date = array(); if (isset($data['hour']) && isset($data['meridian']) && $data['hour'] != 12 && 'pm' == $data['meridian']) { @@ -949,9 +950,13 @@ class Model extends Object { } } } - $date = str_replace(array_keys($date), array_values($date), $format); + + $format = $this->getDataSource()->columns[$type]['format']; + $day = empty($date['Y']) ? null : $date['Y'] . '-' . $date['m'] . '-' . $date['d'] . ' '; + $hour = empty($date['H']) ? null : $date['H'] . ':' . $date['i'] . ':' . $date['s']; + $date = new DateTime($day . $hour); if ($useNewDate && !empty($date)) { - return $date; + return $date->format($format); } } return $data; @@ -1061,6 +1066,23 @@ class Model extends Object { return false; } +/** + * Check that a method is callable on a model. This will check both the model's own methods, its + * inherited methods and methods that could be callable through behaviors. + * + * @param string $method The method to be called. + * @return boolean True on method being callable. + */ + public function hasMethod($method) { + if (method_exists($this, $method)) { + return true; + } + if ($this->Behaviors->hasMethod($method)) { + return true; + } + return false; + } + /** * Returns true if the supplied field is a model Virtual Field * @@ -1314,8 +1336,8 @@ class Model extends Object { } if ($options['callbacks'] === true || $options['callbacks'] === 'before') { - $result = $this->Behaviors->trigger($this, 'beforeSave', array($options), array( - 'break' => true, 'breakOn' => false + $result = $this->Behaviors->trigger('beforeSave', array(&$this, $options), array( + 'break' => true, 'breakOn' => array(false, null) )); if (!$result || !$this->beforeSave($options)) { $this->whitelist = $_whitelist; @@ -1398,7 +1420,7 @@ class Model extends Object { $success = $this->data; } if ($options['callbacks'] === true || $options['callbacks'] === 'after') { - $this->Behaviors->trigger($this, 'afterSave', array($created, $options)); + $this->Behaviors->trigger('afterSave', array(&$this, $created, $options)); $this->afterSave($created); } if (!empty($this->data)) { @@ -1449,15 +1471,11 @@ class Model extends Object { foreach ((array)$data as $row) { if ((is_string($row) && (strlen($row) == 36 || strlen($row) == 16)) || is_numeric($row)) { - $values = array( - $db->value($id, $this->getColumnType($this->primaryKey)), - $db->value($row) - ); + $values = array($id, $row); if ($isUUID && $primaryAdded) { - $values[] = $db->value(String::uuid()); + $values[] = String::uuid(); } - $values = implode(',', $values); - $newValues[] = "({$values})"; + $newValues[] = $values; unset($values); } elseif (isset($row[$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) { $newData[] = $row; @@ -1496,7 +1514,6 @@ class Model extends Object { } if (!empty($newValues)) { - $fields = implode(',', $fields); $db->insertMulti($this->{$join}, $fields, $newValues); } } @@ -1849,13 +1866,15 @@ class Model extends Object { $id = $this->id; if ($this->beforeDelete($cascade)) { - $filters = $this->Behaviors->trigger($this, 'beforeDelete', array($cascade), array( - 'break' => true, 'breakOn' => false - )); + $filters = $this->Behaviors->trigger( + 'beforeDelete', + array(&$this, $cascade), + array('break' => true, 'breakOn' => array(false, null)) + ); if (!$filters || !$this->exists()) { return false; } - $db =& ConnectionManager::getDataSource($this->useDbConfig); + $db = ConnectionManager::getDataSource($this->useDbConfig); $this->_deleteDependent($id, $cascade); $this->_deleteLinks($id); @@ -1872,7 +1891,7 @@ class Model extends Object { if (!empty($this->belongsTo)) { $this->updateCounterCache($keys[$this->alias]); } - $this->Behaviors->trigger($this, 'afterDelete'); + $this->Behaviors->trigger('afterDelete', array(&$this)); $this->afterDelete(); $this->_clearCache(); $this->id = false; @@ -2136,9 +2155,12 @@ class Model extends Object { $query['order'] = array($query['order']); if ($query['callbacks'] === true || $query['callbacks'] === 'before') { - $return = $this->Behaviors->trigger($this, 'beforeFind', array($query), array( - 'break' => true, 'breakOn' => false, 'modParams' => true - )); + $return = $this->Behaviors->trigger( + 'beforeFind', + array(&$this, $query), + array('break' => true, 'breakOn' => array(false, null), 'modParams' => 1) + ); + $query = (is_array($return)) ? $return : $query; if ($return === false) { @@ -2401,7 +2423,11 @@ class Model extends Object { * @access private */ function __filterResults($results, $primary = true) { - $return = $this->Behaviors->trigger($this, 'afterFind', array($results, $primary), array('modParams' => true)); + $return = $this->Behaviors->trigger( + 'afterFind', + array(&$this, $results, $primary), + array('modParams' => 1) + ); if ($return !== true) { $results = $return; } @@ -2526,9 +2552,8 @@ class Model extends Object { function invalidFields($options = array()) { if ( !$this->Behaviors->trigger( - $this, 'beforeValidate', - array($options), + array(&$this, $options), array('break' => true, 'breakOn' => false) ) || $this->beforeValidate($options) === false diff --git a/cake/libs/model/model_behavior.php b/cake/libs/model/model_behavior.php index ae38705cd..7ff613b71 100644 --- a/cake/libs/model/model_behavior.php +++ b/cake/libs/model/model_behavior.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.model + * @package cake.libs.model * @since CakePHP(tm) v 1.2.0.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,10 +22,45 @@ /** * Model behavior base class. * - * Defines the Behavior interface, and contains common model interaction functionality. + * Defines the Behavior interface, and contains common model interaction functionality. Behaviors + * allow you to simulate mixins, and create resuable blocks of application logic, that can be reused across + * several models. Behaviors also provide a way to hook into model callbacks and augment their behavior. * - * @package cake - * @subpackage cake.cake.libs.model + * ### Mixin methods + * + * Behaviors can provide mixin like features by declaring public methods. These methods should expect + * the model instance to be shifted onto the parameter list. + * + * {{{ + * function doSomething($model, $arg1, $arg2) { + * //do something + * } + * }}} + * + * Would be called like `$this->Model->doSomething($arg1, $arg2);`. + * + * ### Mapped methods + * + * Behaviors can also define mapped methods. Mapped methods use pattern matching for method invocation. This + * allows you to create methods similar to Model::findAllByXXX methods on your behaviors. Mapped methods need to + * be declared in your behaviors `$mapMethods` array. The method signature for a mapped method is slightly different + * than a normal behavior mixin method. + * + * {{{ + * var $mapMethods = array('/do(\w+)/' => 'doSomething'); + * + * function doSomething($model, $method, $arg1, $arg2) { + * //do something + * } + * }}} + * + * The above will map every doXXX() method call to the behavior. As you can see, the model is + * still the first parameter, but the called method name will be the 2nd parameter. This allows + * you to munge the method name for additional information, much like Model::findAllByXX. + * + * @package cake.libs.model + * @see Model::$actsAs + * @see BehaviorCollection::load() */ class ModelBehavior extends Object { @@ -37,7 +71,6 @@ class ModelBehavior extends Object { * associative array, keyed off of the model name. * * @var array - * @access public * @see Model::$alias */ public $settings = array(); @@ -49,7 +82,6 @@ class ModelBehavior extends Object { * the findBy* / findAllBy* magic methods. * * @var array - * @access public */ public $mapMethods = array(); @@ -59,85 +91,98 @@ class ModelBehavior extends Object { * @param object $model Model using this behavior * @param array $config Configuration settings for $model */ - public function setup(&$model, $config = array()) { } + public function setup($model, $config = array()) { } /** * Clean up any initialization this behavior has done on a model. Called when a behavior is dynamically * detached from a model using Model::detach(). * * @param object $model Model using this behavior - * @access public * @see BehaviorCollection::detach() */ - function cleanup(&$model) { + function cleanup($model) { if (isset($this->settings[$model->alias])) { unset($this->settings[$model->alias]); } } /** - * Before find callback + * beforeFind can be used to cancel find operations, or modify the query that will be executed. + * By returning null/false you can abort a find. By returning an array you can modify/replace the query + * that is going to be run. * * @param object $model Model using this behavior * @param array $queryData Data used to execute this query, i.e. conditions, order, etc. - * @return mixed False if the operation should abort. An array will replace the value of $query. - * @access public + * @return mixed False or null will abort the operation. You can return an array to replace the + * $query that will be eventually run. */ - public function beforeFind(&$model, $query) { } + public function beforeFind($model, $query) { + return true; + } /** - * After find callback. Can be used to modify any results returned by find and findAll. + * After find callback. Can be used to modify any results returned by find. * * @param object $model Model using this behavior * @param mixed $results The results of the find operation * @param boolean $primary Whether this model is being queried directly (vs. being queried as an association) * @return mixed An array value will replace the value of $results - any other value will be ignored. - * @access public */ - public function afterFind(&$model, $results, $primary) { } + public function afterFind($model, $results, $primary) { } /** - * Before validate callback + * beforeValidate is called before a model is validated, you can use this callback to + * add behavior validation rules into a models validate array. Returning false + * will allow you to make the validation fail. + * + * @param object $model Model using this behavior + * @return mixed False or null will abort the operation. Any other result will continue. + * @access public + */ + public function beforeValidate($model) { + return true; + } + +/** + * beforeSave is called before a model is saved. Returning false from a beforeSave callback + * will abort the save operation. * * @param object $model Model using this behavior * @return mixed False if the operation should abort. Any other result will continue. - * @access public */ - public function beforeValidate(&$model) { } + public function beforeSave($model) { + return true; + } /** - * Before save callback - * - * @param object $model Model using this behavior - * @return mixed False if the operation should abort. Any other result will continue. - * @access public - */ - public function beforeSave(&$model) { } - -/** - * After save callback + * afterSave is called after a model is saved. * * @param object $model Model using this behavior * @param boolean $created True if this save created a new record */ - public function afterSave(&$model, $created) { } + public function afterSave($model, $created) { + return true; + } /** - * Before delete callback + * Before delete is called before any delete occurs on the attached model, but after the model's + * beforeDelete is called. Returning false from a beforeDelete will abort the delete. * * @param object $model Model using this behavior * @param boolean $cascade If true records that depend on this record will also be deleted * @return mixed False if the operation should abort. Any other result will continue. * @access public */ - public function beforeDelete(&$model, $cascade = true) { } + public function beforeDelete($model, $cascade = true) { + return true; + } /** - * After delete callback + * After delete is called after any delete occurs on the attached model. * * @param object $model Model using this behavior */ - public function afterDelete(&$model) { } + public function afterDelete($model) { } /** * DataSource error callback @@ -145,7 +190,7 @@ class ModelBehavior extends Object { * @param object $model Model using this behavior * @param string $error Error generated in DataSource */ - public function onError(&$model, $error) { } + public function onError($model, $error) { } /** * If $model's whitelist property is non-empty, $field will be added to it. @@ -155,10 +200,9 @@ class ModelBehavior extends Object { * * @param object $model Model using this behavior * @param string $field Field to be added to $model's whitelist - * @access protected * @return void */ - function _addToWhitelist(&$model, $field) { + function _addToWhitelist($model, $field) { if (is_array($field)) { foreach ($field as $f) { $this->_addToWhitelist($model, $f); diff --git a/cake/libs/multibyte.php b/cake/libs/multibyte.php index a988fa109..123d3d11b 100644 --- a/cake/libs/multibyte.php +++ b/cake/libs/multibyte.php @@ -13,8 +13,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 1.2.0.6833 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -256,8 +255,7 @@ if (!function_exists('mb_encode_mimeheader')) { * Multibyte handling methods. * * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs */ class Multibyte { @@ -1077,7 +1075,11 @@ class Multibyte { if ($range === false) { return null; } - Configure::load('unicode' . DS . 'casefolding' . DS . $range); + if (!Configure::configured('_cake_core_')) { + App::import('Core', 'config/PhpReader'); + Configure::config('_cake_core_', new PhpReader(CAKE . 'config' . DS)); + } + Configure::load('unicode' . DS . 'casefolding' . DS . $range, '_cake_core_'); self::$__caseFold[$range] = Configure::read($range); Configure::delete($range); } diff --git a/cake/libs/object.php b/cake/libs/object.php index 0f1d49030..9096ae121 100644 --- a/cake/libs/object.php +++ b/cake/libs/object.php @@ -15,8 +15,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -27,8 +26,7 @@ * Also includes methods for logging and the special method RequestAction, * to call other Controllers' Actions from anywhere. * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs */ class Object { diff --git a/cake/libs/object_collection.php b/cake/libs/object_collection.php index b2a6eb443..a9750f3e8 100644 --- a/cake/libs/object_collection.php +++ b/cake/libs/object_collection.php @@ -1,10 +1,5 @@ _loaded`. Enabled objects are stored in `$this->_enabled`. In addition + * the all support an `enabled` option that controls the enabled/disabled state of the object + * when loaded. + * + * @package cake.libs + * @since CakePHP(tm) v 2.0 + */ abstract class ObjectCollection { /** @@ -55,25 +60,43 @@ abstract class ObjectCollection { * ### Options * * - `breakOn` Set to the value or values you want the callback propagation to stop on. - * Defaults to `false` - * - `break` Set to true to enabled breaking. Defaults to `false`. + * Can either be a scalar value, or an array of values to break on. Defaults to `false`. + * + * - `break` Set to true to enabled breaking. When a trigger is broken, the last returned value + * will be returned. If used in combination with `collectReturn` the collected results will be returned. + * Defaults to `false`. + * * - `collectReturn` Set to true to collect the return of each object into an array. * This array of return values will be returned from the trigger() call. Defaults to `false`. + * * - `triggerDisabled` Will trigger the callback on all objects in the collection even the non-enabled - * objects. Defaults to false. + * objects. Defaults to false. + * + * - `modParams` Allows each object the callback gets called on to modify the parameters to the next object. + * Setting modParams to an integer value will allow you to modify the parameter with that index. + * Any non-null value will modify the parameter index indicated. + * Defaults to false. + * * * @param string $callback Method to fire on all the objects. Its assumed all the objects implement * the method you are calling. * @param array $params Array of parameters for the triggered callback. * @param array $options Array of options. - * @return mixed true. + * @return mixed Either the last result or all results if collectReturn is on. + * @throws CakeException when modParams is used with an index that does not exist. */ public function trigger($callback, $params = array(), $options = array()) { if (empty($this->_enabled)) { return true; } $options = array_merge( - array('break' => false, 'breakOn' => false, 'collectReturn' => false, 'triggerDisabled' => false), + array( + 'break' => false, + 'breakOn' => false, + 'collectReturn' => false, + 'triggerDisabled' => false, + 'modParams' => false + ), $options ); $collected = array(); @@ -81,19 +104,27 @@ abstract class ObjectCollection { if ($options['triggerDisabled'] === true) { $list = array_keys($this->_loaded); } + if ($options['modParams'] !== false && !isset($params[$options['modParams']])) { + throw new CakeException(__('Cannot use modParams with indexes that do not exist.')); + } foreach ($list as $name) { - $result = call_user_func_array(array(&$this->_loaded[$name], $callback), $params); + $result = call_user_func_array(array($this->_loaded[$name], $callback), $params); if ($options['collectReturn'] === true) { $collected[] = $result; } if ( - $options['break'] && ($result === $options['breakOn'] || + $options['break'] && ($result === $options['breakOn'] || (is_array($options['breakOn']) && in_array($result, $options['breakOn'], true))) ) { - return ($options['collectReturn'] === true) ? $collected : $result; + return $result; + } elseif ($options['modParams'] !== false && is_array($result)) { + $params[$options['modParams']] = $result; } } - return $options['collectReturn'] ? $collected : true; + if ($options['modParams'] !== false) { + return $params[$options['modParams']]; + } + return $options['collectReturn'] ? $collected : $result; } /** @@ -190,6 +221,20 @@ abstract class ObjectCollection { $this->_enabled = array_values(array_diff($this->_enabled, (array)$name)); } +/** + * Adds or overwrites an instatiated object to the collection + * + * @param string $name Name of the object + * @param Object $object The object to use + */ + public function set($name = null, $object = null) { + if (!empty($name) && !empty($object)) { + list($plugin, $name) = pluginSplit($name); + $this->_loaded[$name] = $object; + } + return $this->_loaded; + } + /** * Normalizes an object array, creates an array that makes lazy loading * easier diff --git a/cake/libs/route/cake_route.php b/cake/libs/route/cake_route.php index 706323f3a..be944951f 100644 --- a/cake/libs/route/cake_route.php +++ b/cake/libs/route/cake_route.php @@ -16,8 +16,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs.route * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -165,6 +164,11 @@ class CakeRoute { $parsed = str_replace(array_keys($routeParams), array_values($routeParams), $parsed); $this->_compiledRoute = '#^' . $parsed . '[/]*$#'; $this->keys = $names; + + //remove defaults that are also keys. They can cause match failures + foreach ($this->keys as $key) { + unset($this->defaults[$key]); + } } /** @@ -260,53 +264,62 @@ class CakeRoute { //check that all the key names are in the url $keyNames = array_flip($this->keys); - if (array_intersect_key($keyNames, $url) != $keyNames) { + if (array_intersect_key($keyNames, $url) !== $keyNames) { return false; } - $diffUnfiltered = Set::diff($url, $defaults); - $diff = array(); + // Missing defaults is a fail. + if (array_diff_key($defaults, $url) !== array()) { + return false; + } - foreach ($diffUnfiltered as $key => $var) { - if ($var === 0 || $var === '0' || !empty($var)) { - $diff[$key] = $var; + $greedyNamed = Router::$named['greedy']; + $allowedNamedParams = Router::$named['rules']; + + $named = $pass = $_query = array(); + + foreach ($url as $key => $value) { + + // keys that exist in the defaults and have different values is a match failure. + $defaultExists = array_key_exists($key, $defaults); + if ($defaultExists && $defaults[$key] != $value) { + return false; + } elseif ($defaultExists) { + continue; + } + + // If the key is a routed key, its not different yet. + if (array_key_exists($key, $keyNames)) { + continue; + } + + // pull out passed args + $numeric = is_numeric($key); + if ($numeric && isset($defaults[$key]) && $defaults[$key] == $value) { + continue; + } elseif ($numeric) { + $pass[] = $value; + unset($url[$key]); + continue; + } + + // pull out named params if named params are greedy or a rule exists. + if ( + ($greedyNamed || isset($allowedNamedParams[$key])) && + ($value !== false && $value !== null) + ) { + $named[$key] = $value; + continue; + } + + // keys that don't exist are different. + if (!$defaultExists && !empty($value)) { + return false; } } //if a not a greedy route, no extra params are allowed. - if (!$this->_greedy && array_diff_key($diff, $keyNames) != array()) { - return false; - } - - //remove defaults that are also keys. They can cause match failures - foreach ($this->keys as $key) { - unset($defaults[$key]); - } - $filteredDefaults = array_filter($defaults); - - //if the difference between the url diff and defaults contains keys from defaults its not a match - if (array_intersect_key($filteredDefaults, $diffUnfiltered) !== array()) { - return false; - } - - $passedArgsAndParams = array_diff_key($diff, $filteredDefaults, $keyNames); - list($named, $params) = Router::getNamedElements($passedArgsAndParams, $url['controller'], $url['action']); - - //remove any pass params, they have numeric indexes, skip any params that are in the defaults - $pass = array(); - $i = 0; - while (isset($url[$i])) { - if (!isset($diff[$i])) { - $i++; - continue; - } - $pass[] = $url[$i]; - unset($url[$i], $params[$i]); - $i++; - } - - //still some left over parameters that weren't named or passed args, bail. - if (!empty($params)) { + if (!$this->_greedy && (!empty($pass) || !empty($named))) { return false; } @@ -318,7 +331,7 @@ class CakeRoute { } } } - return $this->_writeUrl(array_merge($url, compact('pass', 'named'))); + return $this->_writeUrl(array_merge($url, compact('pass', 'named', '_query'))); } /** @@ -343,7 +356,13 @@ class CakeRoute { if (!empty($params['named']) && is_array($params['named'])) { $named = array(); foreach ($params['named'] as $key => $value) { - $named[] = $key . $separator . $value; + if (is_array($value)) { + foreach ($value as $namedKey => $namedValue) { + $named[] = $key . "[$namedKey]" . $separator . $namedValue; + } + } else { + $named[] = $key . $separator . $value; + } } $params['pass'] = $params['pass'] . '/' . implode('/', $named); } @@ -368,4 +387,21 @@ class CakeRoute { $out = str_replace('//', '/', $out); return $out; } + +/** + * Generates a well-formed querystring from $q + * + * Will compose an array or nested array into a proper querystring. + * + * @param mixed $q An array of parameters to compose into a query string. + * @param bool $escape Whether or not to use escaped & + * @return string + */ + public function queryString($q, $escape = false) { + $join = '&'; + if ($escape === true) { + $join = '&'; + } + return '?' . http_build_query($q, null, $join); + } } \ No newline at end of file diff --git a/cake/libs/route/plugin_short_route.php b/cake/libs/route/plugin_short_route.php index 1c1c4330b..9509c5d32 100644 --- a/cake/libs/route/plugin_short_route.php +++ b/cake/libs/route/plugin_short_route.php @@ -14,8 +14,7 @@ App::import('Core', 'route/CakeRoute'); * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs.route * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/route/redirect_route.php b/cake/libs/route/redirect_route.php index 148ce358f..8b9a63fe2 100644 --- a/cake/libs/route/redirect_route.php +++ b/cake/libs/route/redirect_route.php @@ -2,7 +2,9 @@ App::import('Core', 'CakeResponse'); App::import('Core', 'route/CakeRoute'); /** - * Redirect route will perform an immediate redirect + * Redirect route will perform an immediate redirect. Redirect routes + * are useful when you want to have Routing layer redirects occur in your + * application, for when URLs move. * * PHP5 * @@ -14,8 +16,7 @@ App::import('Core', 'route/CakeRoute'); * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.route + * @package cake.libs.route * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -28,6 +29,25 @@ class RedirectRoute extends CakeRoute { */ public $response = null; +/** + * The location to redirect to. Either a string or a cake array url. + * + * @var mixed + */ + public $redirect; + +/** + * Constructor + * + * @param string $template Template string with parameter placeholders + * @param array $defaults Array of defaults for the route. + * @param string $params Array of parameters and additional options for the Route + */ + public function __construct($template, $defaults = array(), $options = array()) { + parent::__construct($template, $defaults, $options); + $this->redirect = (array)$defaults; + } + /** * Parses a string url into an array. Parsed urls will result in an automatic * redirection @@ -43,22 +63,21 @@ class RedirectRoute extends CakeRoute { if (!$this->response) { $this->response = new CakeResponse(); } - $redirect = $this->defaults; - if (count($this->defaults) == 1 && !isset($this->defaults['controller'])) { - $redirect = $this->defaults[0]; + $redirect = $this->redirect; + if (count($this->redirect) == 1 && !isset($this->redirect['controller'])) { + $redirect = $this->redirect[0]; } if (isset($this->options['persist']) && is_array($redirect)) { $argOptions['context'] = array('action' => $redirect['action'], 'controller' => $redirect['controller']); - $args = Router::getArgs($params['_args_'], $argOptions); - $redirect += $args['pass']; - $redirect += $args['named']; - } + $redirect += Router::getArgs($params['_args_'], $argOptions) + array('url' => array()); + $redirect = Router::reverse($redirect); + } $status = 301; if (isset($this->options['status']) && ($this->options['status'] >= 300 && $this->options['status'] < 400)) { $status = $this->options['status']; } $this->response->header(array('Location' => Router::url($redirect, true))); - $this->response->statusCode($status); + $this->response->statusCode($status); $this->response->send(); } diff --git a/cake/libs/router.php b/cake/libs/router.php index b51f02134..c0737ae25 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,10 +21,23 @@ App::import('Core', 'CakeRequest'); App::import('Core', 'route/CakeRoute'); /** - * Parses the request URL into controller, action, and parameters. + * Parses the request URL into controller, action, and parameters. Uses the connected routes + * to match the incoming url string to parameters that will allow the request to be dispatched. Also + * handles converting parameter lists into url strings, using the connected routes. Routing allows you to decouple + * the way the world interacts with your application (urls) and the implementation (controllers and actions). * - * @package cake - * @subpackage cake.cake.libs + * ### Connecting routes + * + * Connecting routes is done using Router::connect(). When parsing incoming requests or reverse matching + * parameters, routes are enumerated in the order they were connected. You can modify the order of connected + * routes using Router::promote(). For more information on routes and how to connect them see Router::connect(). + * + * ### Named parameters + * + * Named parameters allow you to embed key:value pairs into path segments. This allows you create hash + * structures using urls. You can define how named parameters work in your application using Router::connectNamed() + * + * @package cake.libs */ class Router { @@ -226,7 +238,7 @@ class Router { * shifted into the passed arguments. As well as supplying patterns for routing parameters. * @see routes * @return array Array of routes - * @throws Exception + * @throws RouterException */ public static function connect($route, $defaults = array(), $options = array()) { foreach (self::$_prefixes as $prefix) { @@ -246,13 +258,15 @@ class Router { $routeClass = 'CakeRoute'; if (isset($options['routeClass'])) { $routeClass = $options['routeClass']; + if (!is_subclass_of($routeClass, 'CakeRoute')) { + throw new RouterException(__('Route classes must extend CakeRoute')); + } unset($options['routeClass']); + if ($routeClass == 'RedirectRoute' && isset($defaults['redirect'])) { + $defaults = $defaults['redirect']; + } } - $Route = new $routeClass($route, $defaults, $options); - if (!$Route instanceof CakeRoute) { - throw new Exception(__('Route classes must extend CakeRoute')); - } - self::$routes[] =& $Route; + self::$routes[] = new $routeClass($route, $defaults, $options); return self::$routes; } @@ -267,15 +281,18 @@ class Router { * * `Router::redirect('/home/*', array('controller' => 'posts', 'action' => 'view', array('persist' => true));` * - * Redirects /home/* to /posts/view and passes the parameters to /posts/view + * Redirects /home/* to /posts/view and passes the parameters to /posts/view. Using an array as the + * redirect destination allows you to use other routes to define where a url string should be redirected ot. * * `Router::redirect('/posts/*', 'http://google.com', array('status' => 302));` * * Redirects /posts/* to http://google.com with a HTTP status of 302 * * ### Options: + * * - `status` Sets the HTTP status (default 301) - * - `persist` Passes the params to the redirected route, if it can + * - `persist` Passes the params to the redirected route, if it can. This is useful with greedy routes, + * routes that end in `*` are greedy. As you can remap urls and not loose any passed/named args. * * @param string $route A string describing the template of the route * @param array $url A url to redirect to. Can be a string or a Cake array-based url @@ -285,14 +302,19 @@ class Router { * @see routes * @return array Array of routes */ - public static function redirect($route, $url, $options) { + public static function redirect($route, $url, $options = array()) { App::import('Core', 'route/RedirectRoute'); $options['routeClass'] = 'RedirectRoute'; + if (is_string($url)) { + $url = array('redirect' => $url); + } return self::connect($route, $url, $options); } /** - * Specifies what named parameters CakePHP should be parsing. The most common setups are: + * Specifies what named parameters CakePHP should be parsing out of incoming urls. By default + * CakePHP will parse every named parameter out of incoming URLs. However, if you want to take more + * control over how named parameters are parsed you can use one of the following setups: * * Do not parse any named parameters: * @@ -306,7 +328,7 @@ class Router { * * {{{ Router::connectNamed(array('page' => '[\d]+'), array('default' => false, 'greedy' => false)); }}} * - * Parse only the page parameter no mater what. + * Parse only the page parameter no matter what. * * {{{ Router::connectNamed(array('page'), array('default' => false, 'greedy' => false)); }}} * @@ -328,17 +350,23 @@ class Router { * ); * }}} * + * ### Options + * + * - `greedy` Setting this to true will make Router parse all named params. Setting it to false will + * parse only the connected named params. + * - `default` Set this to true to merge in the default set of named parameters. + * - `reset` Set to true to clear existing rules and start fresh. + * - `separator` Change the string used to separate the key & value in a named parameter. Defaults to `:` + * * @param array $named A list of named parameters. Key value pairs are accepted where values are * either regex strings to match, or arrays as seen above. * @param array $options Allows to control all settings: separator, greedy, reset, default * @return array */ public static function connectNamed($named, $options = array()) { - - - if (isset($options['argSeparator'])) { - self::$named['separator'] = $options['argSeparator']; - unset($options['argSeparator']); + if (isset($options['separator'])) { + self::$named['separator'] = $options['separator']; + unset($options['separator']); } if ($named === true || $named === false) { @@ -377,7 +405,6 @@ class Router { * @return void */ public static function defaults($connect = true) { - self::$_connectDefaults = $connect; } @@ -395,7 +422,6 @@ class Router { * @return array Array of mapped resources */ public static function mapResources($controller, $options = array()) { - $options = array_merge(array('prefix' => '/', 'id' => self::$__named['ID'] . '|' . self::$__named['UUID']), $options); $prefix = $options['prefix']; @@ -422,7 +448,6 @@ class Router { * @return array A list of prefixes used in connected routes */ public static function prefixes() { - return self::$_prefixes; } @@ -433,8 +458,6 @@ class Router { * @return array Parsed elements from URL */ public static function parse($url) { - - if (!self::$_defaultsMapped && self::$_connectDefaults) { self::__connectDefaultRoutes(); } @@ -692,6 +715,7 @@ class Router { public static function reload() { if (empty(self::$_initialState)) { self::$_initialState = get_class_vars('Router'); + self::_setPrefixes(); return; } foreach (self::$_initialState as $key => $val) { @@ -889,7 +913,7 @@ class Router { * @see Router::url() */ protected static function _handleNoRoute($url) { - $named = $args = array(); + $named = $args = $query = array(); $skip = array_merge( array('bare', 'action', 'controller', 'plugin', 'prefix'), self::$_prefixes @@ -900,10 +924,11 @@ class Router { // Remove this once parsed URL parameters can be inserted into 'pass' for ($i = 0; $i < $count; $i++) { + $key = $keys[$i]; if (is_numeric($keys[$i])) { - $args[] = $url[$keys[$i]]; + $args[] = $url[$key]; } else { - $named[$keys[$i]] = $url[$keys[$i]]; + $named[$key] = $url[$key]; } } @@ -915,7 +940,7 @@ class Router { } } - if (empty($named) && empty($args) && (!isset($url['action']) || $url['action'] === 'index')) { + if (empty($named) && empty($args) && empty($query) && (!isset($url['action']) || $url['action'] === 'index')) { $url['action'] = null; } @@ -939,9 +964,19 @@ class Router { if (!empty($named)) { foreach ($named as $name => $value) { - $output .= '/' . $name . self::$named['separator'] . $value; + if (is_array($value)) { + $flattend = Set::flatten($value, ']['); + foreach ($flattend as $namedKey => $namedValue) { + $output .= '/' . $name . "[$namedKey]" . self::$named['separator'] . $namedValue; + } + } else { + $output .= '/' . $name . self::$named['separator'] . $value; + } } } + if (!empty($query)) { + $output .= Router::queryString($query); + } return $output; } @@ -960,7 +995,7 @@ class Router { if (isset(self::$named['rules'][$param])) { $rule = self::$named['rules'][$param]; if (Router::matchNamed($param, $val, $rule, compact('controller', 'action'))) { - $named[$param] = $val; + $named[substr($param, 1)] = $val; unset($params[$param]); } } @@ -1203,7 +1238,23 @@ class Router { if ($passIt) { $pass[] = $param; } else { - $named[$key] = $val; + if (preg_match_all('/\[([A-Za-z0-9_-]+)?\]/', $key, $matches, PREG_SET_ORDER)) { + $matches = array_reverse($matches); + $parts = explode('[', $key); + $key = array_shift($parts); + $arr = $val; + foreach ($matches as $match) { + if (empty($match[1])) { + $arr = array($arr); + } else { + $arr = array( + $match[1] => $arr + ); + } + } + $val = $arr; + } + $named = array_merge_recursive($named, array($key => $val)); } } else { $pass[] = $param; diff --git a/cake/libs/sanitize.php b/cake/libs/sanitize.php index 34ed32e79..d538b46bd 100644 --- a/cake/libs/sanitize.php +++ b/cake/libs/sanitize.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -26,8 +25,7 @@ * Removal of alpahnumeric characters, SQL-safe slash-added strings, HTML-friendly strings, * and all of the above on arrays. * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs */ class Sanitize { diff --git a/cake/libs/security.php b/cake/libs/security.php index 348402de2..e8b01e2b8 100644 --- a/cake/libs/security.php +++ b/cake/libs/security.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v .0.10.0.1233 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Security Library contains utility methods related to security * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs */ class Security { diff --git a/cake/libs/session/cache_session.php b/cake/libs/session/cache_session.php index 5c8f2eae5..9b1b4ded0 100644 --- a/cake/libs/session/cache_session.php +++ b/cake/libs/session/cache_session.php @@ -12,15 +12,15 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ /** * CacheSession provides method for saving sessions into a Cache engine. Used with CakeSession * - * @package cake.libs + * @package cake.libs.session + * @see CakeSession for configuration information. */ class CacheSession implements CakeSessionHandlerInterface { /** diff --git a/cake/libs/session/database_session.php b/cake/libs/session/database_session.php index e10fe5a93..574d1f5c0 100644 --- a/cake/libs/session/database_session.php +++ b/cake/libs/session/database_session.php @@ -12,15 +12,14 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ /** * DatabaseSession provides methods to be used with CakeSession. * - * @package cake.libs + * @package cake.libs.session */ class DatabaseSession implements CakeSessionHandlerInterface { diff --git a/cake/libs/set.php b/cake/libs/set.php index 4938308cd..14282682d 100644 --- a/cake/libs/set.php +++ b/cake/libs/set.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 1.2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Class used for manipulation of arrays. * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs */ class Set { @@ -1017,7 +1015,7 @@ class Set { * @param string $key * @return array */ - private function __flatten($results, $key = null) { + private static function __flatten($results, $key = null) { $stack = array(); foreach ($results as $k => $r) { $id = $k; @@ -1042,6 +1040,10 @@ class Set { * @return array Sorted array of data */ public static function sort($data, $path, $dir) { + $originalKeys = array_keys($data); + if (is_numeric(implode('', $originalKeys))) { + $data = array_values($data); + } $result = Set::__flatten(Set::extract($data, $path)); list($keys, $values) = array(Set::extract($result, '{n}.id'), Set::extract($result, '{n}.value')); @@ -1053,7 +1055,6 @@ class Set { } array_multisort($values, $dir, $keys, $dir); $sorted = array(); - $keys = array_unique($keys); foreach ($keys as $k) { diff --git a/cake/libs/string.php b/cake/libs/string.php index affcc263b..8fc0a2ddf 100644 --- a/cake/libs/string.php +++ b/cake/libs/string.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 1.2.0.5551 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ * String handling methods. * * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs */ class String { diff --git a/cake/libs/validation.php b/cake/libs/validation.php index 5a65ae2d6..aefa47756 100644 --- a/cake/libs/validation.php +++ b/cake/libs/validation.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 1.2.0.3830 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,8 +23,7 @@ if (!class_exists('Multibyte')) { /** * Offers different validation methods. * - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP v 1.2.0.3830 */ class Validation { @@ -415,7 +413,8 @@ class Validation { if (is_array($check)) { return self::extension(array_shift($check), $extensions); } - $extension = strtolower(array_pop(explode('.', $check))); + $pathSegments = explode('.', $check); + $extension = strtolower(array_pop($pathSegments)); foreach ($extensions as $value) { if ($extension == strtolower($value)) { return true; @@ -431,7 +430,7 @@ class Validation { * @param string $ipVersion The IP Protocol version to validate against * @return boolean Success */ - public function ip($check, $type = 'both') { + public static function ip($check, $type = 'both') { $type = strtolower($type); $flags = array(); if ($type === 'ipv4' || $type === 'both') { @@ -668,12 +667,12 @@ class Validation { */ public static function url($check, $strict = false) { self::__populateIp(); - $validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=~') . '\/0-9a-z]|(%[0-9a-f]{2}))'; + $validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=~') . '\/0-9a-z\p{L}\p{N}]|(%[0-9a-f]{2}))'; $regex = '/^(?:(?:https?|ftps?|file|news|gopher):\/\/)' . (!empty($strict) ? '' : '?') . - '(?:' . self::$__pattern['IPv4'] . '|' . self::$__pattern['hostname'] . ')(?::[1-9][0-9]{0,3})?' . + '(?:' . self::$__pattern['IPv4'] . '|\[' . self::$__pattern['IPv6'] . '\]|' . self::$__pattern['hostname'] . ')(?::[1-9][0-9]{0,4})?' . '(?:\/?|\/' . $validChars . '*)?' . '(?:\?' . $validChars . '*)?' . - '(?:#' . $validChars . '*)?$/i'; + '(?:#' . $validChars . '*)?$/iu'; return self::_check($check, $regex); } @@ -701,6 +700,18 @@ class Validation { return call_user_func_array(array($object, $method), array($check, $args)); } +/** + * Checks that a value is a valid uuid - http://tools.ietf.org/html/rfc4122 + * + * @param string $check Value to check + * @return boolean Success + * @access public + */ + public static function uuid($check) { + $regex = '/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i'; + return self::_check($check, $regex); + } + /** * Attempts to pass unhandled Validation locales to a class starting with $classPrefix * and ending with Validation. For example $classPrefix = 'nl', the class would be diff --git a/cake/libs/view/elements/email/html/default.ctp b/cake/libs/view/elements/email/html/default.ctp index 45a84c9e0..3ab3f4cc6 100644 --- a/cake/libs/view/elements/email/html/default.ctp +++ b/cake/libs/view/elements/email/html/default.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.elements.email.html + * @package cake.libs.view.templates.elements.email.html * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/elements/email/text/default.ctp b/cake/libs/view/elements/email/text/default.ctp index 9d384e3f8..7655f1430 100644 --- a/cake/libs/view/elements/email/text/default.ctp +++ b/cake/libs/view/elements/email/text/default.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.elements.email.text + * @package cake.libs.view.templates.elements.email.text * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/elements/exception_stack_trace.ctp b/cake/libs/view/elements/exception_stack_trace.ctp index 9219e21ae..247c45169 100644 --- a/cake/libs/view/elements/exception_stack_trace.ctp +++ b/cake/libs/view/elements/exception_stack_trace.ctp @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.elements + * @package cake.libs.view.templates.elements * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/elements/sql_dump.ctp b/cake/libs/view/elements/sql_dump.ctp index 025d5ae93..b770dfbaa 100644 --- a/cake/libs/view/elements/sql_dump.ctp +++ b/cake/libs/view/elements/sql_dump.ctp @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.elements + * @package cake.libs.view.templates.elements * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/errors/error400.ctp b/cake/libs/view/errors/error400.ctp index 4d1660517..b6487ee91 100644 --- a/cake/libs/view/errors/error400.ctp +++ b/cake/libs/view/errors/error400.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.errors + * @package cake.libs.view.templates.errors * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/errors/error500.ctp b/cake/libs/view/errors/error500.ctp index b5bdcfde0..e032b9eed 100644 --- a/cake/libs/view/errors/error500.ctp +++ b/cake/libs/view/errors/error500.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.errors + * @package cake.libs.view.templates.errors * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/errors/missing_action.ctp b/cake/libs/view/errors/missing_action.ctp index 19cfe6222..5b6fdb970 100644 --- a/cake/libs/view/errors/missing_action.ctp +++ b/cake/libs/view/errors/missing_action.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.errors + * @package cake.libs.view.templates.errors * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/errors/missing_behavior_class.ctp b/cake/libs/view/errors/missing_behavior_class.ctp index eb19034b8..e7c454069 100644 --- a/cake/libs/view/errors/missing_behavior_class.ctp +++ b/cake/libs/view/errors/missing_behavior_class.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.errors + * @package cake.libs.view.templates.errors * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/errors/missing_behavior_file.ctp b/cake/libs/view/errors/missing_behavior_file.ctp index 6f90206c1..09e90b350 100644 --- a/cake/libs/view/errors/missing_behavior_file.ctp +++ b/cake/libs/view/errors/missing_behavior_file.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.errors + * @package cake.libs.view.templates.errors * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/errors/missing_component_class.ctp b/cake/libs/view/errors/missing_component_class.ctp index ccb0497ef..cf06671dc 100644 --- a/cake/libs/view/errors/missing_component_class.ctp +++ b/cake/libs/view/errors/missing_component_class.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.errors + * @package cake.libs.view.templates.errors * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/errors/missing_component_file.ctp b/cake/libs/view/errors/missing_component_file.ctp index 592238fb4..527afc9c3 100644 --- a/cake/libs/view/errors/missing_component_file.ctp +++ b/cake/libs/view/errors/missing_component_file.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.errors + * @package cake.libs.view.templates.errors * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/errors/missing_connection.ctp b/cake/libs/view/errors/missing_connection.ctp index 2f11f4f5f..dfda66e3a 100644 --- a/cake/libs/view/errors/missing_connection.ctp +++ b/cake/libs/view/errors/missing_connection.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.errors + * @package cake.libs.view.templates.errors * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/errors/missing_controller.ctp b/cake/libs/view/errors/missing_controller.ctp index d45d8d31c..7f9e7d27f 100644 --- a/cake/libs/view/errors/missing_controller.ctp +++ b/cake/libs/view/errors/missing_controller.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.errors + * @package cake.libs.view.templates.errors * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/errors/missing_database.ctp b/cake/libs/view/errors/missing_database.ctp index d3e4944f6..7aa2d5e80 100644 --- a/cake/libs/view/errors/missing_database.ctp +++ b/cake/libs/view/errors/missing_database.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.errors + * @package cake.libs.view.templates.errors * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/errors/missing_helper_class.ctp b/cake/libs/view/errors/missing_helper_class.ctp index 9742a1563..842ded905 100644 --- a/cake/libs/view/errors/missing_helper_class.ctp +++ b/cake/libs/view/errors/missing_helper_class.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.errors + * @package cake.libs.view.templates.errors * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/errors/missing_helper_file.ctp b/cake/libs/view/errors/missing_helper_file.ctp index 69bf38e30..6ba0e9b6f 100644 --- a/cake/libs/view/errors/missing_helper_file.ctp +++ b/cake/libs/view/errors/missing_helper_file.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.errors + * @package cake.libs.view.templates.errors * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/errors/missing_layout.ctp b/cake/libs/view/errors/missing_layout.ctp index 28445cc77..011e59a64 100644 --- a/cake/libs/view/errors/missing_layout.ctp +++ b/cake/libs/view/errors/missing_layout.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.errors + * @package cake.libs.view.templates.errors * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/errors/missing_table.ctp b/cake/libs/view/errors/missing_table.ctp index b639856fe..1288dd06a 100644 --- a/cake/libs/view/errors/missing_table.ctp +++ b/cake/libs/view/errors/missing_table.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.errors + * @package cake.libs.view.templates.errors * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/errors/missing_view.ctp b/cake/libs/view/errors/missing_view.ctp index 658f4d1ce..9d8c7cb91 100644 --- a/cake/libs/view/errors/missing_view.ctp +++ b/cake/libs/view/errors/missing_view.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.errors + * @package cake.libs.view.templates.errors * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/errors/private_action.ctp b/cake/libs/view/errors/private_action.ctp index c91062ba2..833f42112 100644 --- a/cake/libs/view/errors/private_action.ctp +++ b/cake/libs/view/errors/private_action.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.errors + * @package cake.libs.view.templates.errors * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/errors/scaffold_error.ctp b/cake/libs/view/errors/scaffold_error.ctp index 931cbdca5..40f09c90a 100644 --- a/cake/libs/view/errors/scaffold_error.ctp +++ b/cake/libs/view/errors/scaffold_error.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.errors + * @package cake.libs.view.templates.errors * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/helper.php b/cake/libs/view/helper.php index 59470ea9f..16ea94798 100644 --- a/cake/libs/view/helper.php +++ b/cake/libs/view/helper.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view + * @package cake.libs.view * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -28,8 +27,7 @@ if (!class_exists('Router')) { * Abstract base class for all other Helpers in CakePHP. * Provides common methods and features. * - * @package cake - * @subpackage cake.cake.libs.view + * @package cake.libs.view */ class Helper extends Object { @@ -107,6 +105,30 @@ class Helper extends Object { */ protected $_View; +/** + * Minimized attributes + * + * @var array + */ + protected $_minimizedAttributes = array( + 'compact', 'checked', 'declare', 'readonly', 'disabled', 'selected', + 'defer', 'ismap', 'nohref', 'noshade', 'nowrap', 'multiple', 'noresize' + ); + +/** + * Format to attribute + * + * @var string + */ + protected $_attributeFormat = '%s="%s"'; + +/** + * Format to attribute + * + * @var string + */ + protected $_minimizedAttributeFormat = '%s="%s"'; + /** * Default Constructor * @@ -115,7 +137,6 @@ class Helper extends Object { */ public function __construct(View $View, $settings = array()) { $this->_View = $View; - $this->params = $View->params; $this->request = $View->request; if (!empty($this->helpers)) { $this->_helperMap = ObjectCollection::normalizeObjectArray($this->helpers); @@ -361,7 +382,7 @@ class Helper extends Object { foreach ($filtered as $key => $value) { if ($value !== false && $value !== null) { - $attributes[] = $this->__formatAttribute($key, $value, $escape); + $attributes[] = $this->_formatAttribute($key, $value, $escape); } } $out = implode(' ', $attributes); @@ -378,23 +399,21 @@ class Helper extends Object { * @param string $key The name of the attribute to create * @param string $value The value of the attribute to create. * @return string The composed attribute. - * @access private */ - function __formatAttribute($key, $value, $escape = true) { + protected function _formatAttribute($key, $value, $escape = true) { $attribute = ''; - $attributeFormat = '%s="%s"'; - $minimizedAttributes = array('compact', 'checked', 'declare', 'readonly', 'disabled', - 'selected', 'defer', 'ismap', 'nohref', 'noshade', 'nowrap', 'multiple', 'noresize'); if (is_array($value)) { $value = ''; } - if (in_array($key, $minimizedAttributes)) { + if (is_numeric($key)) { + $attribute = sprintf($this->_minimizedAttributeFormat, $value, $value); + } elseif (in_array($key, $this->_minimizedAttributes)) { if ($value === 1 || $value === true || $value === 'true' || $value === '1' || $value == $key) { - $attribute = sprintf($attributeFormat, $key, $key); + $attribute = sprintf($this->_minimizedAttributeFormat, $key, $key); } } else { - $attribute = sprintf($attributeFormat, $key, ($escape ? h($value) : $value)); + $attribute = sprintf($this->_attributeFormat, $key, ($escape ? h($value) : $value)); } return $attribute; } diff --git a/cake/libs/view/helper_collection.php b/cake/libs/view/helper_collection.php index 18b700812..9d5fcbf17 100644 --- a/cake/libs/view/helper_collection.php +++ b/cake/libs/view/helper_collection.php @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view + * @package cake.libs.view * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/helpers/app_helper.php b/cake/libs/view/helpers/app_helper.php index d09503bb0..9ded31b9c 100644 --- a/cake/libs/view/helpers/app_helper.php +++ b/cake/libs/view/helpers/app_helper.php @@ -15,8 +15,6 @@ * * @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 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -29,8 +27,7 @@ App::import('View', 'Helper', false); * Add your application-wide methods in the class below, your helpers * will inherit them. * - * @package cake - * @subpackage cake.cake + * @package cake.libs.view.helpers */ class AppHelper extends Helper { } diff --git a/cake/libs/view/helpers/cache.php b/cake/libs/view/helpers/cache.php index 6a1c430ea..34f1c9ef3 100644 --- a/cake/libs/view/helpers/cache.php +++ b/cake/libs/view/helpers/cache.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.helpers + * @package cake.libs.view.helpers * @since CakePHP(tm) v 1.0.0.2277 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,8 +23,7 @@ * When using CacheHelper you don't call any of its methods, they are all automatically * called by View, and use the $cacheAction settings set in the controller. * - * @package cake - * @subpackage cake.cake.libs.view.helpers + * @package cake.libs.view.helpers * @link http://book.cakephp.org/view/1376/Cache */ class CacheHelper extends AppHelper { diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 9445d9695..dd1c7d85f 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -12,12 +12,11 @@ * 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.libs.view.helpers - * @since CakePHP(tm) v 0.10.0.1076 - * @license MIT License (http://www.opensource.org/licenses/mit-license.php) + * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) + * @link http://cakephp.org CakePHP(tm) Project + * @package cake.libs.view.helpers + * @since CakePHP(tm) v 0.10.0.1076 + * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ /** @@ -25,8 +24,7 @@ * * Automatic generation of HTML FORMs from given data. * - * @package cake - * @subpackage cake.cake.libs.view.helpers + * @package cake.libs.view.helpers * @link http://book.cakephp.org/view/1383/Form */ class FormHelper extends AppHelper { @@ -210,11 +208,13 @@ class FormHelper extends AppHelper { } } - $object = $this->_introspectModel($model); - $this->setEntity($model . '.', true); + if ($model !== false) { + $object = $this->_introspectModel($model); + $this->setEntity($model . '.', true); + } $modelEntity = $this->model(); - if (isset($this->fieldset[$modelEntity]['key'])) { + if ($model !== false && isset($this->fieldset[$modelEntity]['key'])) { $data = $this->fieldset[$modelEntity]; $recordExists = ( isset($this->request->data[$model]) && @@ -401,7 +401,7 @@ class FormHelper extends AppHelper { $fields += $locked; $fields = Security::hash(serialize($fields) . Configure::read('Security.salt')); - $locked = str_rot13(serialize(array_keys($locked))); + $locked = implode(array_keys($locked), '|'); $out = $this->hidden('_Token.fields', array( 'value' => urlencode($fields . ':' . $locked), @@ -540,7 +540,8 @@ class FormHelper extends AppHelper { if ($text === null) { if (strpos($fieldName, '.') !== false) { - $text = array_pop(explode('.', $fieldName)); + $fieldElements = explode('.', $fieldName); + $text = array_pop($fieldElements); } else { $text = $fieldName; } @@ -1133,14 +1134,15 @@ class FormHelper extends AppHelper { * The first argument to an input type should always be the fieldname, in `Model.field` format. * The second argument should always be an array of attributes for the input. * - * @param string $method Method name / input type to make. + * @param string $method Method name / input type to make. * @param array $params Parameters for the method call * @return string Formatted input method. + * @throws CakeException When there are no params for the method call. */ public function __call($method, $params) { $options = array(); if (empty($params)) { - throw new Exception(__('Missing field name for FormHelper::%s', $method)); + throw new CakeException(__('Missing field name for FormHelper::%s', $method)); } if (isset($params[1])) { $options = $params[1]; @@ -1320,6 +1322,7 @@ class FormHelper extends AppHelper { unset($options['confirm']); } + $url = $this->url($url); $formName = uniqid('post_'); $out = $this->create(false, array('url' => $url, 'name' => $formName, 'id' => $formName, 'style' => 'display:none;')); if (isset($options['data']) && is_array($options['data'])) { diff --git a/cake/libs/view/helpers/html.php b/cake/libs/view/helpers/html.php index 2509e8d56..c5165515f 100644 --- a/cake/libs/view/helpers/html.php +++ b/cake/libs/view/helpers/html.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.helpers + * @package cake.libs.view.helpers * @since CakePHP(tm) v 0.9.1 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ * * HtmlHelper encloses all methods needed while working with HTML pages. * - * @package cake - * @subpackage cake.cake.libs.view.helpers + * @package cake.libs.view.helpers * @link http://book.cakephp.org/view/1434/HTML */ class HtmlHelper extends AppHelper { @@ -835,7 +833,7 @@ class HtmlHelper extends AppHelper { /** * Internal function to build a nested list (UL/OL) out of an associative array. * - * @param array $list Set of elements to list + * @param array $items Set of elements to list * @param array $options Additional HTML attributes of the list (ol/ul) tag * @param array $itemOptions Additional HTML attributes of the list item (LI) tag * @param string $tag Type of list tag to use (ol/ul) diff --git a/cake/libs/view/helpers/jquery_engine.php b/cake/libs/view/helpers/jquery_engine.php index f09c70c33..b0864fba1 100644 --- a/cake/libs/view/helpers/jquery_engine.php +++ b/cake/libs/view/helpers/jquery_engine.php @@ -18,8 +18,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.view.helpers + * @package cake.libs.view.helpers * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ App::import('Helper', 'Js'); diff --git a/cake/libs/view/helpers/js.php b/cake/libs/view/helpers/js.php index 9fcecaab9..e285481ad 100644 --- a/cake/libs/view/helpers/js.php +++ b/cake/libs/view/helpers/js.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.cake.libs.view.helpers + * @package cake.libs.view.helpers * @since CakePHP v 1.2 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,8 +23,7 @@ * JsHelper provides an abstract interface for authoring JavaScript with a * given client-side library. * - * @package cake - * @subpackage cake.cake.libs.view.helpers + * @package cake.libs.view.helpers */ class JsHelper extends AppHelper { /** @@ -155,20 +153,6 @@ class JsHelper extends AppHelper { trigger_error(__('JsHelper:: Missing Method %s is undefined', $method), E_USER_WARNING); } -/** - * Workaround for Object::Object() existing. Since Object::object exists, it does not - * fall into call__ and is not passed onto the engine helper. See JsBaseEngineHelper::object() for - * more information on this method. - * - * @param mixed $data Data to convert into JSON - * @param array $options Options to use for encoding JSON. See JsBaseEngineHelper::object() for more details. - * @return string encoded JSON - * @deprecated Remove when support for PHP4 and Object::object are removed. - */ - public function object($data = array(), $options = array()) { - return $this->{$this->__engineName}->object($data, $options); - } - /** * Overwrite inherited Helper::value() * See JsBaseEngineHelper::value() for more information on this method. @@ -203,7 +187,6 @@ class JsHelper extends AppHelper { */ public function writeBuffer($options = array()) { $domReady = $this->request->is('ajax'); - // $domReady = isset($this->params['isAjax']) ? !$this->params['isAjax'] : true; $defaults = array( 'onDomReady' => $domReady, 'inline' => true, 'cache' => false, 'clear' => true, 'safe' => true diff --git a/cake/libs/view/helpers/mootools_engine.php b/cake/libs/view/helpers/mootools_engine.php index bd0b676dd..5064db644 100644 --- a/cake/libs/view/helpers/mootools_engine.php +++ b/cake/libs/view/helpers/mootools_engine.php @@ -20,8 +20,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.libs.view.helpers + * @package cake.libs.view.helpers * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/helpers/number.php b/cake/libs/view/helpers/number.php index 03e01eea2..c88cd8ff2 100644 --- a/cake/libs/view/helpers/number.php +++ b/cake/libs/view/helpers/number.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.helpers + * @package cake.libs.view.helpers * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,8 +24,7 @@ * * Methods to make numbers more readable. * - * @package cake - * @subpackage cake.cake.libs.view.helpers + * @package cake.libs.view.helpers * @link http://book.cakephp.org/view/1452/Number */ class NumberHelper extends AppHelper { diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index 5816c6b6a..8fe9e40ec 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.helpers + * @package cake.libs.view.helpers * @since CakePHP(tm) v 1.2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * PaginationHelper encloses all methods needed when working with pagination. * - * @package cake - * @subpackage cake.cake.libs.view.helpers + * @package cake.libs.view.helpers * @link http://book.cakephp.org/view/1458/Paginator */ class PaginatorHelper extends AppHelper { @@ -44,7 +42,8 @@ class PaginatorHelper extends AppHelper { private $__defaultModel = null; /** - * The class used for 'Ajax' pagination links. + * The class used for 'Ajax' pagination links. Defaults to JsHelper. You should make sure + * that JsHelper is defined as a helper before PaginatorHelper, if you want to customize the JsHelper. * * @var string */ @@ -55,26 +54,30 @@ class PaginatorHelper extends AppHelper { * * The values that may be specified are: * - * - `$options['format']` Format of the counter. Supported formats are 'range' and 'pages' + * - `format` Format of the counter. Supported formats are 'range' and 'pages' * and custom (default). In the default mode the supplied string is parsed and constants are replaced * by their actual values. - * Constants: %page%, %pages%, %current%, %count%, %start%, %end% . - * - `$options['separator']` The separator of the actual page and number of pages (default: ' of '). - * - `$options['url']` Url of the action. See Router::url() - * - `$options['url']['sort']` the key that the recordset is sorted. - * - `$options['url']['direction']` Direction of the sorting (default: 'asc'). - * - `$options['url']['page']` Page # to display. - * - `$options['model']` The name of the model. - * - `$options['escape']` Defines if the title field for the link should be escaped (default: true). - * - `$options['update']` DOM id of the element updated with the results of the AJAX call. + * placeholders: %page%, %pages%, %current%, %count%, %start%, %end% . + * - `separator` The separator of the actual page and number of pages (default: ' of '). + * - `url` Url of the action. See Router::url() + * - `url['sort']` the key that the recordset is sorted. + * - `url['direction']` Direction of the sorting (default: 'asc'). + * - `url['page']` Page number to use in links. + * - `model` The name of the model. + * - `escape` Defines if the title field for the link should be escaped (default: true). + * - `update` DOM id of the element updated with the results of the AJAX call. * If this key isn't specified Paginator will use plain HTML links. - * - `$options['indicator']` DOM id of the element that will be shown when doing AJAX requests. **Only supported by - * AjaxHelper** + * - `paging['paramType']` The type of parameters to use when creating links. Valid options are + * 'querystring', 'named', and 'route'. See PaginatorComponent::$settings for more information. + * - `convertKeys` - A list of keys in url arrays that should be converted to querysting params + * if paramType == 'querystring'. * * @var array * @access public */ - public $options = array(); + public $options = array( + 'convertKeys' => array('page', 'limit', 'sort', 'direction') + ); /** * Constructor for the helper. Sets up the helper that is used for creating 'AJAX' links. @@ -87,7 +90,7 @@ class PaginatorHelper extends AppHelper { * * @param View $View the view object the helper is attached to. * @param array $settings Array of settings. - * @return void + * @throws CakeException When the AjaxProvider helper does not implement a link method. */ function __construct(View $View, $settings = array()) { parent::__construct($View, $settings); @@ -99,7 +102,7 @@ class PaginatorHelper extends AppHelper { } $classname = $ajaxProvider . 'Helper'; if (!method_exists($classname, 'link')) { - throw new Exception(sprintf( + throw new CakeException(sprintf( __('%s does not implement a link() method, it is incompatible with PaginatorHelper'), $classname )); } @@ -112,7 +115,6 @@ class PaginatorHelper extends AppHelper { */ public function beforeRender($viewFile) { $this->options['url'] = array_merge($this->request->params['pass'], $this->request->params['named']); - parent::beforeRender($viewFile); } @@ -162,6 +164,9 @@ class PaginatorHelper extends AppHelper { ); unset($options[$model]); } + if (!empty($options['convertKeys'])) { + $options['convertKeys'] = array_merge($this->options['convertKeys'], $options['convertKeys']); + } $this->options = array_filter(array_merge($this->options, $options)); } @@ -191,7 +196,7 @@ class PaginatorHelper extends AppHelper { public function sortKey($model = null, $options = array()) { if (empty($options)) { $params = $this->params($model); - $options = array_merge($params['defaults'], $params['options']); + $options = $params['options']; } if (isset($options['sort']) && !empty($options['sort'])) { @@ -217,7 +222,7 @@ class PaginatorHelper extends AppHelper { if (empty($options)) { $params = $this->params($model); - $options = array_merge($params['defaults'], $params['options']); + $options = $params['options']; } if (isset($options['direction'])) { @@ -248,6 +253,10 @@ class PaginatorHelper extends AppHelper { * @return string A "previous" link or $disabledTitle text if the link is disabled. */ public function prev($title = '<< Previous', $options = array(), $disabledTitle = null, $disabledOptions = array()) { + $defaults = array( + 'rel' => 'prev' + ); + $options = array_merge($defaults, (array)$options); return $this->__pagingLink('Prev', $title, $options, $disabledTitle, $disabledOptions); } @@ -267,6 +276,10 @@ class PaginatorHelper extends AppHelper { * @return string A "next" link or or $disabledTitle text if the link is disabled. */ public function next($title = 'Next >>', $options = array(), $disabledTitle = null, $disabledOptions = array()) { + $defaults = array( + 'rel' => 'next' + ); + $options = array_merge($defaults, (array)$options); return $this->__pagingLink('Next', $title, $options, $disabledTitle, $disabledOptions); } @@ -350,11 +363,11 @@ class PaginatorHelper extends AppHelper { $url = array_merge((array)$options['url'], (array)$url); unset($options['url']); } + unset($options['convertKeys']); + $url = $this->url($url, true, $model); $obj = isset($options['update']) ? $this->_ajaxHelperClass : 'Html'; - $url = array_merge(array('page' => $this->current($model)), $url); - $url = array_merge(Set::filter($url, true), array_intersect_key($url, array('plugin' => true))); return $this->{$obj}->link($title, $url, $options); } @@ -368,9 +381,7 @@ class PaginatorHelper extends AppHelper { */ public function url($options = array(), $asArray = false, $model = null) { $paging = $this->params($model); - $url = array_merge(array_filter(Set::diff(array_merge( - $paging['defaults'], $paging['options']), $paging['defaults'])), $options - ); + $url = array_merge(array_filter($paging['options']), $options); if (isset($url['order'])) { $sort = $direction = null; @@ -380,6 +391,7 @@ class PaginatorHelper extends AppHelper { unset($url['order']); $url = array_merge($url, compact('sort', 'direction')); } + $url = $this->_convertUrlKeys($url, $paging['paramType']); if ($asArray) { return $url; @@ -387,6 +399,28 @@ class PaginatorHelper extends AppHelper { return parent::url($url); } +/** + * Converts the keys being used into the format set by options.paramType + * + * @param array $url Array of url params to convert + * @return converted url params. + */ + protected function _convertUrlKeys($url, $type) { + if ($type == 'named') { + return $url; + } + if (!isset($url['?'])) { + $url['?'] = array(); + } + foreach ($this->options['convertKeys'] as $key) { + if (isset($url[$key])) { + $url['?'][$key] = $url[$key]; + unset($url[$key]); + } + } + return $url; + } + /** * Protected method for generating prev/next links * @@ -421,6 +455,7 @@ class PaginatorHelper extends AppHelper { if ($this->{$check}($model)) { return $this->Html->tag($tag, $this->link($title, $url, array_merge($options, compact('escape', 'class')))); } else { + unset($options['rel']); return $this->Html->tag($tag, $title, array_merge($options, compact('escape', 'class'))); } } @@ -528,9 +563,9 @@ class PaginatorHelper extends AppHelper { } $start = 0; if ($paging['count'] >= 1) { - $start = (($paging['page'] - 1) * $paging['options']['limit']) + 1; + $start = (($paging['page'] - 1) * $paging['limit']) + 1; } - $end = $start + $paging['options']['limit'] - 1; + $end = $start + $paging['limit'] - 1; if ($paging['count'] < $end) { $end = $paging['count']; } @@ -568,7 +603,12 @@ class PaginatorHelper extends AppHelper { /** * Returns a set of numbers for the paged result set - * uses a modulus to decide how many numbers to show on each side of the current page (default: 8) + * uses a modulus to decide how many numbers to show on each side of the current page (default: 8). + * + * `$this->Paginator->numbers(array('first' => 2, 'last' => 2));` + * + * Using the first and last options you can create links to the beginning and end of the page set. + * * * ### Options * @@ -579,9 +619,9 @@ class PaginatorHelper extends AppHelper { * - `separator` Separator content defaults to ' | ' * - `tag` The tag to wrap links in, defaults to 'span' * - `first` Whether you want first links generated, set to an integer to define the number of 'first' - * links to generate + * links to generate. * - `last` Whether you want last links generated, set to an integer to define the number of 'last' - * links to generate + * links to generate. * - `ellipsis` Ellipsis content, defaults to '...' * * @param mixed $options Options for the numbers, (before, after, model, modulus, separator) @@ -691,32 +731,42 @@ class PaginatorHelper extends AppHelper { } /** - * Returns a first or set of numbers for the first pages + * Returns a first or set of numbers for the first pages. + * + * `echo $this->Paginator->first('< first');` + * + * Creates a single link for the first page. Will output nothing if you are on the first page. + * + * `echo $this->Paginator->first(3);` + * + * Will create links for the first 3 pages, once you get to the third or greater page. Prior to that + * nothing will be output. * * ### Options: * * - `tag` The tag wrapping tag you want to use, defaults to 'span' - * - `before` Content to insert before the link/tag + * - `after` Content to insert after the link/tag * - `model` The model to use defaults to PaginatorHelper::defaultModel() * - `separator` Content between the generated links, defaults to ' | ' * - `ellipsis` Content for ellipsis, defaults to '...' * - * @param mixed $first if string use as label for the link, if numeric print page numbers - * @param mixed $options + * @param mixed $first if string use as label for the link. If numeric, the number of page links + * you want at the beginning of the range. + * @param mixed $options An array of options. * @return string numbers string. */ public function first($first = '<< first', $options = array()) { $options = array_merge( array( 'tag' => 'span', - 'after'=> null, + 'after' => null, 'model' => $this->defaultModel(), 'separator' => ' | ', - 'ellipsis' => '...', + 'ellipsis' => '...' ), (array)$options); - $params = array_merge(array('page'=> 1), (array)$this->params($options['model'])); + $params = array_merge(array('page' => 1), (array)$this->params($options['model'])); unset($options['model']); if ($params['pageCount'] <= 1) { @@ -727,7 +777,7 @@ class PaginatorHelper extends AppHelper { $out = ''; - if (is_int($first) && $params['page'] > $first) { + if (is_int($first) && $params['page'] >= $first) { if ($after === null) { $after = $ellipsis; } @@ -738,7 +788,8 @@ class PaginatorHelper extends AppHelper { } } $out .= $after; - } elseif ($params['page'] > 1) { + } elseif ($params['page'] > 1 && is_string($first)) { + $options += array('rel' => 'first'); $out = $this->Html->tag($tag, $this->link($first, array('page' => 1), $options)) . $after; } @@ -746,7 +797,15 @@ class PaginatorHelper extends AppHelper { } /** - * Returns a last or set of numbers for the last pages + * Returns a last or set of numbers for the last pages. + * + * `echo $this->Paginator->last('last >');` + * + * Creates a single link for the last page. Will output nothing if you are on the last page. + * + * `echo $this->Paginator->last(3);` + * + * Will create links for the last 3 pages. Once you enter the page range, no output will be created. * * ### Options: * @@ -784,7 +843,7 @@ class PaginatorHelper extends AppHelper { $out = ''; $lower = $params['pageCount'] - $last + 1; - if (is_int($last) && $params['page'] < $lower) { + if (is_int($last) && $params['page'] <= $lower) { if ($before === null) { $before = $ellipsis; } @@ -795,7 +854,8 @@ class PaginatorHelper extends AppHelper { } } $out = $before . $out; - } elseif ($params['page'] < $params['pageCount']) { + } elseif ($params['page'] < $params['pageCount'] && is_string($last)) { + $options += array('rel' => 'last'); $out = $before . $this->Html->tag( $tag, $this->link($last, array('page' => $params['pageCount']), $options )); diff --git a/cake/libs/view/helpers/prototype_engine.php b/cake/libs/view/helpers/prototype_engine.php index 7f3e230b4..69a088f79 100644 --- a/cake/libs/view/helpers/prototype_engine.php +++ b/cake/libs/view/helpers/prototype_engine.php @@ -15,8 +15,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.libs.view.helpers + * @package cake.libs.view.helpers * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/helpers/rss.php b/cake/libs/view/helpers/rss.php index ae1ab6239..c1b7d219d 100644 --- a/cake/libs/view/helpers/rss.php +++ b/cake/libs/view/helpers/rss.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.helpers + * @package cake.libs.view.helpers * @since CakePHP(tm) v 1.2 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Core', 'Xml'); /** * RSS Helper class for easy output RSS structures. * - * @package cake - * @subpackage cake.cake.libs.view.helpers + * @package cake.libs.view.helpers * @link http://book.cakephp.org/view/1460/RSS */ class RssHelper extends AppHelper { diff --git a/cake/libs/view/helpers/session.php b/cake/libs/view/helpers/session.php index 0f6aa002d..fb26c91c7 100644 --- a/cake/libs/view/helpers/session.php +++ b/cake/libs/view/helpers/session.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.helpers + * @package cake.libs.view.helpers * @since CakePHP(tm) v 1.1.7.3328 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,25 +24,11 @@ if (!class_exists('CakeSession')) { * * Session reading from the view. * - * @package cake - * @subpackage cake.cake.libs.view.helpers + * @package cake.libs.view.helpers * @link http://book.cakephp.org/view/1465/Session */ class SessionHelper extends AppHelper { -/** - * Constructor. Starts the session if it has not already been started - * - * @param View $view View instance for this helper - * @param array $settings Settings for the helper. - * @return void - */ - public function __construct(View $view, $settings = array()) { - parent::__construct($view, $settings); - if (!CakeSession::started()) { - CakeSession::start(); - } - } /** * Used to read a session values set in a controller for a key or return values for all keys. * diff --git a/cake/libs/view/helpers/text.php b/cake/libs/view/helpers/text.php index 3f6933bbd..12eff3893 100644 --- a/cake/libs/view/helpers/text.php +++ b/cake/libs/view/helpers/text.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.helpers + * @package cake.libs.view.helpers * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -36,8 +35,7 @@ if (!class_exists('Multibyte')) { * * Text manipulations: Highlight, excerpt, truncate, strip of links, convert email addresses to mailto: links... * - * @package cake - * @subpackage cake.cake.libs.view.helpers + * @package cake.libs.view.helpers * @link http://book.cakephp.org/view/1469/Text */ class TextHelper extends AppHelper { diff --git a/cake/libs/view/helpers/time.php b/cake/libs/view/helpers/time.php index 31093a556..32e9e3050 100644 --- a/cake/libs/view/helpers/time.php +++ b/cake/libs/view/helpers/time.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.helpers + * @package cake.libs.view.helpers * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * Manipulation of time data. * - * @package cake - * @subpackage cake.cake.libs.view.helpers + * @package cake.libs.view.helpers * @link http://book.cakephp.org/view/1470/Time */ class TimeHelper extends AppHelper { @@ -284,7 +282,8 @@ class TimeHelper extends AppHelper { } /** - * Returns true if given datetime string is within this week + * Returns true if given datetime string is within this week. + * * @param string $dateString * @param int $userOffset User's offset from GMT (in hours) * @return boolean True if datetime string is within current week @@ -293,7 +292,7 @@ class TimeHelper extends AppHelper { */ public function isThisWeek($dateString, $userOffset = null) { $date = $this->fromString($dateString, $userOffset); - return date('W Y', $date) == date('W Y', time()); + return date('W o', $date) == date('W o', time()); } /** diff --git a/cake/libs/view/layouts/ajax.ctp b/cake/libs/view/layouts/ajax.ctp index dadf156ed..93371552b 100644 --- a/cake/libs/view/layouts/ajax.ctp +++ b/cake/libs/view/layouts/ajax.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.layouts + * @package cake.libs.view.templates.layouts * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/layouts/default.ctp b/cake/libs/view/layouts/default.ctp index 30ec1a7dc..f247f3c35 100644 --- a/cake/libs/view/layouts/default.ctp +++ b/cake/libs/view/layouts/default.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.layouts + * @package cake.libs.view.templates.layouts * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/layouts/email/html/default.ctp b/cake/libs/view/layouts/email/html/default.ctp index 41ce9a42d..7a8a1e7df 100644 --- a/cake/libs/view/layouts/email/html/default.ctp +++ b/cake/libs/view/layouts/email/html/default.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.layouts.email.html + * @package cake.libs.view.templates.layouts.email.html * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/layouts/email/text/default.ctp b/cake/libs/view/layouts/email/text/default.ctp index 979535832..236b8ebb3 100644 --- a/cake/libs/view/layouts/email/text/default.ctp +++ b/cake/libs/view/layouts/email/text/default.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.layouts.email.text + * @package cake.libs.view.templates.layouts.email.text * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/layouts/flash.ctp b/cake/libs/view/layouts/flash.ctp index 970589df0..cbe4c5abc 100644 --- a/cake/libs/view/layouts/flash.ctp +++ b/cake/libs/view/layouts/flash.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.layouts + * @package cake.libs.view.templates.layouts * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/media.php b/cake/libs/view/media.php index 5bc0d179e..880383b30 100644 --- a/cake/libs/view/media.php +++ b/cake/libs/view/media.php @@ -12,13 +12,47 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view + * @package cake.libs.view * @since CakePHP(tm) v 1.2.0.5714 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ App::import('View', 'View', false); +/** + * Media View provides a custom view implementation for sending files to visitors. Its great + * for making the response of a controller action be a file that is saved somewhere on the filesystem. + * + * An example use comes from the CakePHP internals. MediaView is used to serve plugin and theme assets, + * as they are not normally accessible from an application's webroot. Unlike other views, MediaView + * uses several viewVars that have special meaning: + * + * - `id` The filename on the server's filesystem, including extension. + * - `name` The filename that will be sent to the user, specified without the extension. + * - `download` Set to true to set a `Content-Disposition` header. This is ideal for file downloads. + * - `extension` The extension of the file being served. This is used to set the mimetype + * - `path` The absolute path, including the trailing / on the server's filesystem to `id`. + * - `mimeType` The mime type of the file if CakeResponse doesn't know about it. + * + * ### Usage + * + * {{{ + * class ExampleController extends AppController { + * function download () { + * $this->view = 'Media'; + * $params = array( + * 'id' => 'example.zip', + * 'name' => 'example', + * 'download' => true, + * 'extension' => 'zip', + * 'path' => APP . 'files' . DS + * ); + * $this->set($params); + * } + * } + * }}} + * + * @package cake.libs.view + */ class MediaView extends View { /** * Indicates whether response gzip compression was enabled for this class @@ -34,11 +68,10 @@ class MediaView extends View { */ public $response = null; - /** * Constructor * - * @param object $controller + * @param object $controller The controller with viewVars */ function __construct($controller = null) { parent::__construct($controller); @@ -53,7 +86,7 @@ class MediaView extends View { /** * Display or download the given file * - * @return unknown + * @return mixed */ function render() { $name = $download = $extension = $id = $modified = $path = $size = $cache = $mimeType = $compress = null; @@ -160,6 +193,12 @@ class MediaView extends View { return false; } +/** + * Reads out a file handle, and echos the content to the client. + * + * @param resource $handle A file handle or stream + * @return void + */ protected function _sendFile($handle) { $chunkSize = 8192; $buffer = ''; @@ -180,6 +219,7 @@ class MediaView extends View { /** * Returns true if connection is still active + * * @return boolean */ protected function _isActive() { @@ -188,6 +228,7 @@ class MediaView extends View { /** * Clears the contents of the topmost output buffer and discards them + * * @return boolean */ protected function _clearBuffer() { @@ -196,6 +237,8 @@ class MediaView extends View { /** * Flushes the contents of the output buffer + * + * @return void */ protected function _flushBuffer() { @flush(); diff --git a/cake/libs/view/pages/home.ctp b/cake/libs/view/pages/home.ctp index 67b121a93..9951a08c0 100644 --- a/cake/libs/view/pages/home.ctp +++ b/cake/libs/view/pages/home.ctp @@ -11,14 +11,14 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.pages + * @package cake.libs.view.templates.pages * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ if (Configure::read() == 0): - $this->cakeError('error404'); + throw new NotFoundException(); endif; +App::import('Core', 'Debugger'); ?>

diff --git a/cake/libs/view/scaffold.php b/cake/libs/view/scaffold.php index 032676985..6f051a211 100644 --- a/cake/libs/view/scaffold.php +++ b/cake/libs/view/scaffold.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view + * @package cake.libs.view * @since Cake v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -50,8 +49,8 @@ class ScaffoldView extends ThemeView { } } - if ($name === 'add') { - $name = 'edit'; + if ($name === 'add' || $name == 'edit') { + $name = 'form'; } $scaffoldAction = 'scaffold.' . $name; diff --git a/cake/libs/view/scaffolds/edit.ctp b/cake/libs/view/scaffolds/form.ctp similarity index 76% rename from cake/libs/view/scaffolds/edit.ctp rename to cake/libs/view/scaffolds/form.ctp index 3e59682b5..1a3992e38 100644 --- a/cake/libs/view/scaffolds/edit.ctp +++ b/cake/libs/view/scaffolds/form.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.scaffolds + * @package cake.libs.view.templates.scaffolds * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -27,10 +26,15 @@

    -action != 'add'):?> -
  • Html->link(__('Delete'), array('action' => 'delete', $this->Form->value($modelClass.'.'.$primaryKey)), null, __('Are you sure you want to delete').' #' . $this->Form->value($modelClass.'.'.$primaryKey)); ?>
  • +request->action != 'add'): ?> +
  • Form->postLink( + __('Delete'), + array('action' => 'delete', $this->Form->value($modelClass . '.' . $primaryKey)), + null, + __('Are you sure you want to delete # %s?', $this->Form->value($modelClass . '.' . $primaryKey))); + ?>
  • -
  • Html->link(__('List').' '.$pluralHumanName, array('action' => 'index'));?>
  • +
  • Html->link(__('List') . ' ' . $pluralHumanName, array('action' => 'index'));?>
  • $_data) { diff --git a/cake/libs/view/scaffolds/index.ctp b/cake/libs/view/scaffolds/index.ctp index 7a4f49aef..c3da1d4d8 100644 --- a/cake/libs/view/scaffolds/index.ctp +++ b/cake/libs/view/scaffolds/index.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.console.libs.templates.views + * @package cake.console.libs.templates.views * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -33,33 +32,37 @@ foreach (${$pluralVar} as ${$singularVar}): if ($i++ % 2 == 0) { $class = ' class="altrow"'; } -echo "\n"; - echo "\t\n"; + echo ""; foreach ($scaffoldFields as $_field) { $isKey = false; if (!empty($associations['belongsTo'])) { foreach ($associations['belongsTo'] as $_alias => $_details) { if ($_field === $_details['foreignKey']) { $isKey = true; - echo "\t\t\n\t\t\t" . $this->Html->link(${$singularVar}[$_alias][$_details['displayField']], array('controller' => $_details['controller'], 'action' => 'view', ${$singularVar}[$_alias][$_details['primaryKey']])) . "\n\t\t\n"; + echo "" . $this->Html->link(${$singularVar}[$_alias][$_details['displayField']], array('controller' => $_details['controller'], 'action' => 'view', ${$singularVar}[$_alias][$_details['primaryKey']])) . ""; break; } } } if ($isKey !== true) { - echo "\t\t" . h(${$singularVar}[$modelClass][$_field]) . "\n"; + echo "" . h(${$singularVar}[$modelClass][$_field]) . ""; } } - echo "\t\t\n"; - echo "\t\t\t" . $this->Html->link(__('View'), array('action' => 'view', ${$singularVar}[$modelClass][$primaryKey])) . "\n"; - echo "\t\t\t" . $this->Html->link(__('Edit'), array('action' => 'edit', ${$singularVar}[$modelClass][$primaryKey])) . "\n"; - echo "\t\t\t" . $this->Html->link(__('Delete'), array('action' => 'delete', ${$singularVar}[$modelClass][$primaryKey]), null, __('Are you sure you want to delete').' #' . ${$singularVar}[$modelClass][$primaryKey]) . "\n"; - echo "\t\t\n"; - echo "\t\n"; + echo ''; + echo $this->Html->link(__('View'), array('action' => 'view', ${$singularVar}[$modelClass][$primaryKey])); + echo $this->Html->link(__('Edit'), array('action' => 'edit', ${$singularVar}[$modelClass][$primaryKey])); + echo $this->Form->postLink( + __('Delete'), + array('action' => 'delete', ${$singularVar}[$modelClass][$primaryKey]), + null, + __('Are you sure you want to delete').' #' . ${$singularVar}[$modelClass][$primaryKey] + ); + echo ''; + echo ''; endforeach; -echo "\n"; + ?>

    - Paginator->prev('<< ' . __('previous'), array(), null, array('class' => 'disabled')) . "\n";?> - | Paginator->numbers() . "\n"?> - Paginator->next(__('next') .' >>', array(), null, array('class' => 'disabled')) . "\n";?> + Paginator->prev('<< ' . __('previous'), array(), null, array('class' => 'disabled')); ?> + | Paginator->numbers(); ?> + Paginator->next(__('next') .' >>', array(), null, array('class' => 'disabled')); ?>
@@ -82,8 +85,8 @@ echo "\n"; foreach ($associations as $_type => $_data) { foreach ($_data as $_alias => $_details) { if ($_details['controller'] != $this->name && !in_array($_details['controller'], $done)) { - echo "\t\t
  • " . $this->Html->link(__('List %s', Inflector::humanize($_details['controller'])), array('controller' => $_details['controller'], 'action' => 'index')) . "
  • \n"; - echo "\t\t
  • " . $this->Html->link(__('New %s', Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' => 'add')) . "
  • \n"; + echo "
  • " . $this->Html->link(__('List %s', Inflector::humanize($_details['controller'])), array('controller' => $_details['controller'], 'action' => 'index')) . "
  • "; + echo "
  • " . $this->Html->link(__('New %s', Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' => 'add')) . "
  • "; $done[] = $_details['controller']; } } diff --git a/cake/libs/view/scaffolds/view.ctp b/cake/libs/view/scaffolds/view.ctp index 963c59acc..c31b7397f 100644 --- a/cake/libs/view/scaffolds/view.ctp +++ b/cake/libs/view/scaffolds/view.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.scaffolds + * @package cake.libs.view.templates.scaffolds * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/libs/view/theme.php b/cake/libs/view/theme.php index 80e56ae42..24e06e29b 100644 --- a/cake/libs/view/theme.php +++ b/cake/libs/view/theme.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view + * @package cake.libs.view * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -29,8 +28,7 @@ App::import('View', 'View'); * * Example of theme path with `$this->theme = 'super_hot';` Would be `app/views/themed/super_hot/posts` * - * @package cake - * @subpackage cake.cake.libs.view + * @package cake.libs.view */ class ThemeView extends View { /** diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index a3221c761..ef1d46b9f 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view + * @package cake.libs.view * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,12 +24,16 @@ App::import('View', 'HelperCollection', false); App::import('View', 'Helper', false); /** - * View, the V in the MVC triad. + * View, the V in the MVC triad. View interacts with Helpers and view variables passed + * in from the controller to render the results of the controller action. Often this is HTML, + * but can also take the form of JSON, XML, PDF's or streaming files. * - * Class holding methods for displaying presentation data. + * CakePHP uses a two-step-view pattern. This means that the view content is rendered first, + * and then inserted into the selected layout. A special `$content_for_layout` variable is available + * in the layout, and it contains the rendered view. This also means you can pass data from the view to the + * layout using `$this->set()` * - * @package cake - * @subpackage cake.cake.libs.view + * @package cake.libs.view */ class View extends Object { @@ -53,7 +56,6 @@ class View extends Object { * Name of the controller. * * @var string Name of controller - * @access public */ public $name = null; @@ -68,7 +70,6 @@ class View extends Object { * An array of names of built-in helpers to include. * * @var mixed A single name as a string or a list of names as an array. - * @access public */ public $helpers = array('Html'); @@ -83,7 +84,6 @@ class View extends Object { * Variables for the view * * @var array - * @access public */ public $viewVars = array(); @@ -91,7 +91,6 @@ class View extends Object { * Name of layout to use with this View. * * @var string - * @access public */ public $layout = 'default'; @@ -103,18 +102,10 @@ class View extends Object { public $layoutPath = null; /** - * Turns on or off Cake's conventional mode of rendering views. On by default. + * Turns on or off Cake's conventional mode of applying layout files. On by default. + * Setting to off means that layouts will not be automatically applied to rendered views. * * @var boolean - * @access public - */ - public $autoRender = true; - -/** - * Turns on or off Cake's conventional mode of finding layout files. On by default. - * - * @var boolean - * @access public */ public $autoLayout = true; @@ -122,23 +113,21 @@ class View extends Object { * File extension. Defaults to Cake's template ".ctp". * * @var string - * @access public */ public $ext = '.ctp'; /** - * Sub-directory for this view file. + * Sub-directory for this view file. This is often used for extension based routing. + * for example with an `xml` extension, $subDir would be `xml/` * * @var string - * @access public */ public $subDir = null; /** - * Theme name. + * Theme name. If you are using themes, you should remember to use ThemeView as well. * * @var string - * @access public */ public $theme = null; @@ -147,7 +136,6 @@ class View extends Object { * * @see Controller::$cacheAction * @var mixed - * @access public */ public $cacheAction = false; @@ -155,7 +143,6 @@ class View extends Object { * holds current errors for the model validation * * @var array - * @access public */ public $validationErrors = array(); @@ -163,7 +150,6 @@ class View extends Object { * True when the view has been rendered. * * @var boolean - * @access public */ public $hasRendered = false; @@ -171,7 +157,6 @@ class View extends Object { * True if in scope of model-specific region * * @var boolean - * @access public */ public $modelScope = false; @@ -179,7 +164,6 @@ class View extends Object { * Name of current model this view context is attached to * * @var string - * @access public */ public $model = null; @@ -187,7 +171,6 @@ class View extends Object { * Name of association model this view context is attached to * * @var string - * @access public */ public $association = null; @@ -195,7 +178,6 @@ class View extends Object { * Name of current model field this view context is attached to * * @var string - * @access public */ public $field = null; @@ -203,7 +185,6 @@ class View extends Object { * Suffix of current field this view context is attached to * * @var string - * @access public */ public $fieldSuffix = null; @@ -211,7 +192,6 @@ class View extends Object { * The current model ID this view context is attached to * * @var mixed - * @access public */ public $modelId = null; @@ -219,7 +199,6 @@ class View extends Object { * List of generated DOM UUIDs * * @var array - * @access public */ public $uuids = array(); @@ -227,7 +206,6 @@ class View extends Object { * Holds View output. * * @var string - * @access public */ public $output = false; @@ -254,10 +232,9 @@ class View extends Object { * List of variables to collect from the associated controller * * @var array - * @access protected */ private $__passedVars = array( - 'viewVars', 'autoLayout', 'autoRender', 'ext', 'helpers', 'layout', 'name', + 'viewVars', 'autoLayout', 'ext', 'helpers', 'layout', 'name', 'layoutPath', 'viewPath', 'request', 'plugin', 'passedArgs', 'cacheAction' ); @@ -265,7 +242,6 @@ class View extends Object { * Scripts (and/or other tags) for the layout * * @var array - * @access protected */ protected $_scripts = array(); @@ -273,7 +249,6 @@ class View extends Object { * Holds an array of paths. * * @var array - * @access private */ private $__paths = array(); @@ -304,9 +279,8 @@ class View extends Object { /** * Renders a piece of PHP with provided parameters and returns HTML, XML, or any other string. * - * This realizes the concept of Elements, (or "partial layouts") - * and the $params array is used to send data to be used in the - * Element. Elements can be cached through use of the cache key. + * This realizes the concept of Elements, (or "partial layouts") and the $params array is used to send + * data to be used in the element. Elements can be cached improving performance by using the `cache` option. * * ### Special params * @@ -381,10 +355,22 @@ class View extends Object { * Renders view for given action and layout. If $file is given, that is used * for a view filename (e.g. customFunkyView.ctp). * - * @param string $action Name of action to render for - * @param string $layout Layout to use - * @param string $file Custom filename for view + * Render triggers helper callbacks, which are fired before and after the view are rendered, + * as well as before and after the layout. The helper callbacks are called + * + * - `beforeRender` + * - `afterRender` + * - `beforeLayout` + * - `afterLayout` + * + * If View::$autoRender is false and no `$layout` is provided, the view will be returned bare. + * + * @param string $action Name of action to render for, this will be used as the filename to render, unless + * $file is give as well. + * @param string $layout Layout to use. + * @param string $file Custom filename for view. Providing this will render a specific file for the given action. * @return string Rendered Element + * @throws CakeException if there is an error in the view. */ public function render($action = null, $layout = null, $file = null) { if ($this->hasRendered) { @@ -409,7 +395,7 @@ class View extends Object { $layout = $this->layout; } if ($this->output === false) { - throw new RuntimeException(__("Error in view %s, got no content.", $viewFileName)); + throw new CakeException(__("Error in view %s, got no content.", $viewFileName)); } if ($layout && $this->autoLayout) { $this->output = $this->renderLayout($this->output, $layout); @@ -428,6 +414,7 @@ class View extends Object { * * @param string $content_for_layout Content to render in a view, wrapped by the surrounding layout. * @return mixed Rendered output, or false on error + * @throws CakeException if there is an error in the view. */ public function renderLayout($content_for_layout, $layout = null) { $layoutFileName = $this->_getLayoutFileName($layout); @@ -451,7 +438,7 @@ class View extends Object { $this->output = $this->_render($layoutFileName); if ($this->output === false) { - throw new RuntimeException(__("Error in layout %s, got no content.", $layoutFileName)); + throw new CakeException(__("Error in layout %s, got no content.", $layoutFileName)); } $this->Helpers->trigger('afterLayout', array($layoutFileName)); @@ -580,7 +567,7 @@ class View extends Object { /** * Allows a template or element to set a variable that will be available in - * a layout or other element. Analagous to Controller::set. + * a layout or other element. Analagous to Controller::set(). * * @param mixed $one A string or an array of data. * @param mixed $two Value in case $one is a string (which then works as the key). @@ -646,12 +633,10 @@ class View extends Object { * array of data. * * @param string $___viewFn Filename of the view - * @param array $___dataForView Data to include in rendered view - * @param boolean $loadHelpers Boolean to indicate that helpers should be loaded. - * @param boolean $cached Whether or not to trigger the creation of a cache file. + * @param array $___dataForView Data to include in rendered view. If empty the current View::$viewVars will be used. * @return string Rendered output */ - protected function _render($___viewFn, $___dataForView = array(), $loadHelpers = true, $cached = false) { + protected function _render($___viewFn, $___dataForView = array()) { if (empty($___dataForView)) { $___dataForView = $this->viewVars; } diff --git a/cake/libs/xml.php b/cake/libs/xml.php index 42097597a..1a90ddf94 100644 --- a/cake/libs/xml.php +++ b/cake/libs/xml.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP v .0.10.3.1400 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -73,7 +72,7 @@ class Xml { * @param mixed $input XML string, a path to a file, an URL or an array * @param array $options The options to use * @return object SimpleXMLElement or DOMDocument - * @throws Exception + * @throws XmlException */ public static function build($input, $options = array()) { if (!is_array($options)) { @@ -101,9 +100,9 @@ class Xml { $dom->load($input); return $dom; } elseif (!is_string($input)) { - throw new Exception(__('Invalid input.')); + throw new XmlException(__('Invalid input.')); } - throw new Exception(__('XML cannot be read.')); + throw new XmlException(__('XML cannot be read.')); } /** @@ -141,14 +140,15 @@ class Xml { * @param array $input Array with data * @param array $options The options to use * @return object SimpleXMLElement or DOMDocument + * @throws XmlException */ public static function fromArray($input, $options = array()) { if (!is_array($input) || count($input) !== 1) { - throw new Exception(__('Invalid input.')); + throw new XmlException(__('Invalid input.')); } $key = key($input); if (is_integer($key)) { - throw new Exception(__('The key of input must be alphanumeric')); + throw new XmlException(__('The key of input must be alphanumeric')); } if (!is_array($options)) { @@ -181,7 +181,7 @@ class Xml { * @param string $format Either 'attribute' or 'tags'. This determines where nested keys go. * @return void */ - protected function _fromArray(&$dom, &$node, &$data, $format) { + protected static function _fromArray(&$dom, &$node, &$data, $format) { if (empty($data) || !is_array($data)) { return; } @@ -212,7 +212,7 @@ class Xml { } } else { if ($key[0] === '@') { - throw new Exception(__('Invalid array')); + throw new XmlException(__('Invalid array')); } if (array_keys($value) === range(0, count($value) - 1)) { // List foreach ($value as $item) { @@ -225,7 +225,7 @@ class Xml { } } } else { - throw new Exception(__('Invalid array')); + throw new XmlException(__('Invalid array')); } } } @@ -236,7 +236,7 @@ class Xml { * @param array $data Array with informations to create childs * @return void */ - private function __createChild($data) { + private static function __createChild($data) { extract($data); $childNS = $childValue = null; if (is_array($value)) { @@ -270,13 +270,14 @@ class Xml { * * @param object $obj SimpleXMLElement, DOMDocument or DOMNode instance * @return array Array representation of the XML structure. + * @throws XmlException */ public static function toArray($obj) { if ($obj instanceof DOMNode) { $obj = simplexml_import_dom($obj); } if (!($obj instanceof SimpleXMLElement)) { - throw new Exception(__('The input is not instance of SimpleXMLElement, DOMDocument or DOMNode.')); + throw new XmlException(__('The input is not instance of SimpleXMLElement, DOMDocument or DOMNode.')); } $result = array(); $namespaces = array_merge(array('' => ''), $obj->getNamespaces(true)); diff --git a/cake/tests/cases/basics.test.php b/cake/tests/cases/basics.test.php index f6051717b..c5f4c3ca3 100644 --- a/cake/tests/cases/basics.test.php +++ b/cake/tests/cases/basics.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ App::import('Core', 'Folder'); /** * BasicsTest class * - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases */ class BasicsTest extends CakeTestCase { @@ -167,25 +165,6 @@ class BasicsTest extends CakeTestCase { $_ENV = $__ENV; } -/** - * test uses() - * - * @return void - * @access public - * @deprecated - */ - function testUses() { - $this->skipIf(class_exists('Security') || class_exists('Sanitize'), '%s Security and/or Sanitize class already loaded'); - - $this->assertFalse(class_exists('Security')); - $this->assertFalse(class_exists('Sanitize')); - - uses('Security', 'Sanitize'); - - $this->assertTrue(class_exists('Security')); - $this->assertTrue(class_exists('Sanitize')); - } - /** * Test h() * @@ -686,12 +665,20 @@ class BasicsTest extends CakeTestCase { $this->assertPattern($pattern, $result); ob_start(); - debug('
    this-is-a-test
    ', true); + debug('
    this-is-a-test
    '); $result = ob_get_clean(); $pattern = '/(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|'; $pattern .= preg_quote(substr(__FILE__, 1), '/') . ')'; $pattern .= '.*line.*' . (__LINE__ - 4) . '.*<div>this-is-a-test<\/div>.*/s'; $this->assertPattern($pattern, $result); + + ob_start(); + debug('
    this-is-a-test
    ', false); + $result = ob_get_clean(); + $pattern = '/(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|'; + $pattern .= preg_quote(substr(__FILE__, 1), '/') . ')'; + $pattern .= '.*line.*' . (__LINE__ - 4) . '.*\this-is-a-test\<\/div\>.*/s'; + $this->assertPattern($pattern, $result); } /** diff --git a/cake/tests/cases/console/all_console.test.php b/cake/tests/cases/console/all_console.test.php index 101a8faba..305ebbfc3 100644 --- a/cake/tests/cases/console/all_console.test.php +++ b/cake/tests/cases/console/all_console.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * This test group will run all console classes. * - * @package cake - * @subpackage cake.tests.cases.console + * @package cake.tests.cases.console */ class AllConsoleTest extends PHPUnit_Framework_TestSuite { diff --git a/cake/tests/cases/console/all_console_libs.test.php b/cake/tests/cases/console/all_console_libs.test.php index 70fb8746d..ad1f60fbd 100644 --- a/cake/tests/cases/console/all_console_libs.test.php +++ b/cake/tests/cases/console/all_console_libs.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * This test group will run all console lib classes. * - * @package cake - * @subpackage cake.tests.cases.console + * @package cake.tests.cases.console */ class AllConsoleLibsTest extends PHPUnit_Framework_TestSuite { diff --git a/cake/tests/cases/console/all_shells.test.php b/cake/tests/cases/console/all_shells.test.php index 7f657af82..e8ca96ac5 100644 --- a/cake/tests/cases/console/all_shells.test.php +++ b/cake/tests/cases/console/all_shells.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * This test group will run all top level shell classes. * - * @package cake - * @subpackage cake.tests.cases.console + * @package cake.tests.cases.console */ class AllShellsTest extends PHPUnit_Framework_TestSuite { diff --git a/cake/tests/cases/console/all_tasks.test.php b/cake/tests/cases/console/all_tasks.test.php index 51decf3d1..91ca6abdc 100644 --- a/cake/tests/cases/console/all_tasks.test.php +++ b/cake/tests/cases/console/all_tasks.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * This test group will run all the task tests. * - * @package cake - * @subpackage cake.tests.groups + * @package cake.tests.groups */ class AllTasksTest extends PHPUnit_Framework_TestSuite { diff --git a/cake/tests/cases/console/libs/console_error_handler.test.php b/cake/tests/cases/console/libs/console_error_handler.test.php index 0b0719a14..51d16ab0f 100644 --- a/cake/tests/cases/console/libs/console_error_handler.test.php +++ b/cake/tests/cases/console/libs/console_error_handler.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.tests.cases.console + * @package cake.tests.cases.console * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -43,7 +42,6 @@ class ConsoleErrorHandlerTest extends CakeTestCase { */ function tearDown() { parent::tearDown(); - ConsoleErrorHandler::$stderr = null; } /** @@ -52,7 +50,7 @@ class ConsoleErrorHandlerTest extends CakeTestCase { * @return void */ function testHandleError() { - $content = 'Notice Error: This is a notice error in [/some/file, line 275]'; + $content = "Notice Error: This is a notice error in [/some/file, line 275]\n"; ConsoleErrorHandler::$stderr->expects($this->once())->method('write') ->with($content); diff --git a/cake/tests/cases/console/libs/console_option_parser.test.php b/cake/tests/cases/console/libs/console_option_parser.test.php index 656f3317a..fac420ecd 100644 --- a/cake/tests/cases/console/libs/console_option_parser.test.php +++ b/cake/tests/cases/console/libs/console_option_parser.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests - * @package cake - * @subpackage cake.tests.cases.console + * @package cake.tests.cases.console * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -230,7 +229,7 @@ class ConsoleOptionParserTest extends CakeTestCase { /** * test parsing options that do not exist. * - * @expectedException InvalidArgumentException + * @expectedException ConsoleException */ function testOptionThatDoesNotExist() { $parser = new ConsoleOptionParser('test', false); @@ -242,7 +241,7 @@ class ConsoleOptionParserTest extends CakeTestCase { /** * test that options with choices enforce them. * - * @expectedException InvalidArgumentException + * @expectedException ConsoleException * @return void */ function testOptionWithChoices() { @@ -297,7 +296,7 @@ class ConsoleOptionParserTest extends CakeTestCase { /** * test parsing arguments. * - * @expectedException InvalidArgumentException + * @expectedException ConsoleException * @return void */ function testParseArgumentTooMany() { @@ -315,7 +314,7 @@ class ConsoleOptionParserTest extends CakeTestCase { /** * test that when there are not enough arguments an exception is raised * - * @expectedException RuntimeException + * @expectedException ConsoleException * @return void */ function testPositionalArgNotEnough() { @@ -329,7 +328,7 @@ class ConsoleOptionParserTest extends CakeTestCase { /** * test that arguments with choices enforce them. * - * @expectedException InvalidArgumentException + * @expectedException ConsoleException * @return void */ function testPositionalArgWithChoices() { diff --git a/cake/tests/cases/console/libs/console_output.test.php b/cake/tests/cases/console/libs/console_output.test.php index 9e9c8710d..d2af99d04 100644 --- a/cake/tests/cases/console/libs/console_output.test.php +++ b/cake/tests/cases/console/libs/console_output.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests - * @package cake - * @subpackage cake.tests.cases.console + * @package cake.tests.cases.console * @since CakePHP(tm) v 1.2.0.5432 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/cases/console/libs/help_formatter.test.php b/cake/tests/cases/console/libs/help_formatter.test.php index a957843b1..5caae1490 100644 --- a/cake/tests/cases/console/libs/help_formatter.test.php +++ b/cake/tests/cases/console/libs/help_formatter.test.php @@ -435,6 +435,6 @@ TEXT; $formatter = new HelpFormatter($parser); $result = $formatter->xml(false); - $this->assertType('SimpleXmlElement', $result); + $this->assertInstanceOf('SimpleXmlElement', $result); } } diff --git a/cake/tests/cases/console/libs/task_collection.test.php b/cake/tests/cases/console/libs/task_collection.test.php index da7d6eaef..27a43e619 100644 --- a/cake/tests/cases/console/libs/task_collection.test.php +++ b/cake/tests/cases/console/libs/task_collection.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -49,8 +48,8 @@ class TaskCollectionTest extends CakeTestCase { */ function testLoad() { $result = $this->Tasks->load('DbConfig'); - $this->assertType('DbConfigTask', $result); - $this->assertType('DbConfigTask', $this->Tasks->DbConfig); + $this->assertInstanceOf('DbConfigTask', $result); + $this->assertInstanceOf('DbConfigTask', $this->Tasks->DbConfig); $result = $this->Tasks->attached(); $this->assertEquals(array('DbConfig'), $result, 'attached() results are wrong.'); @@ -65,8 +64,8 @@ class TaskCollectionTest extends CakeTestCase { */ function testLoadWithEnableFalse() { $result = $this->Tasks->load('DbConfig', array(), false); - $this->assertType('DbConfigTask', $result); - $this->assertType('DbConfigTask', $this->Tasks->DbConfig); + $this->assertInstanceOf('DbConfigTask', $result); + $this->assertInstanceOf('DbConfigTask', $this->Tasks->DbConfig); $this->assertFalse($this->Tasks->enabled('DbConfig'), 'DbConfigTask should be disabled'); } @@ -94,8 +93,8 @@ class TaskCollectionTest extends CakeTestCase { $this->Tasks = new TaskCollection($shell, $dispatcher); $result = $this->Tasks->load('TestPlugin.OtherTask'); - $this->assertType('OtherTaskTask', $result, 'Task class is wrong.'); - $this->assertType('OtherTaskTask', $this->Tasks->OtherTask, 'Class is wrong'); + $this->assertInstanceOf('OtherTaskTask', $result, 'Task class is wrong.'); + $this->assertInstanceOf('OtherTaskTask', $this->Tasks->OtherTask, 'Class is wrong'); } /** @@ -118,25 +117,4 @@ class TaskCollectionTest extends CakeTestCase { $this->assertEquals(array('Extract'), $result, 'loaded tasks is wrong'); } -/** - * test normalizeObjectArray - * - * @return void - */ - function testnormalizeObjectArray() { - $tasks = array( - 'Html', - 'Foo.Bar' => array('one', 'two'), - 'Something', - 'Banana.Apple' => array('foo' => 'bar') - ); - $result = TaskCollection::normalizeObjectArray($tasks); - $expected = array( - 'Html' => array('class' => 'Html', 'settings' => array()), - 'Bar' => array('class' => 'Foo.Bar', 'settings' => array('one', 'two')), - 'Something' => array('class' => 'Something', 'settings' => array()), - 'Apple' => array('class' => 'Banana.Apple', 'settings' => array('foo' => 'bar')), - ); - $this->assertEquals($expected, $result); - } } \ No newline at end of file diff --git a/cake/tests/cases/console/shell_dispatcher.test.php b/cake/tests/cases/console/shell_dispatcher.test.php index 2da5bbe81..eb6fd2bd6 100644 --- a/cake/tests/cases/console/shell_dispatcher.test.php +++ b/cake/tests/cases/console/shell_dispatcher.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests - * @package cake - * @subpackage cake.tests.cases.console + * @package cake.tests.cases.console * @since CakePHP(tm) v 1.2.0.5432 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ require_once CAKE . 'console' . DS . 'shell_dispatcher.php'; /** * TestShellDispatcher class * - * @package cake - * @subpackage cake.tests.cases.console + * @package cake.tests.cases.console */ class TestShellDispatcher extends ShellDispatcher { @@ -105,8 +103,7 @@ class TestShellDispatcher extends ShellDispatcher { /** * ShellDispatcherTest * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class ShellDispatcherTest extends CakeTestCase { diff --git a/cake/tests/cases/console/shells/acl.test.php b/cake/tests/cases/console/shells/acl.test.php index 305ee1ebc..b13d593b4 100644 --- a/cake/tests/cases/console/shells/acl.test.php +++ b/cake/tests/cases/console/shells/acl.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks * @since CakePHP v 1.2.0.7726 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,8 +24,7 @@ require_once CAKE . 'console' . DS . 'shell_dispatcher.php'; /** * AclShellTest class * - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks */ class AclShellTest extends CakeTestCase { @@ -44,8 +42,6 @@ class AclShellTest extends CakeTestCase { * @return void */ public function setUp() { - parent::setUp(); - Configure::write('Acl.database', 'test'); Configure::write('Acl.classname', 'DbAcl'); @@ -59,7 +55,6 @@ class AclShellTest extends CakeTestCase { ); $collection = new ComponentCollection(); $this->Task->Acl = new AclComponent($collection); - $this->Task->params['datasource'] = 'test'; } @@ -206,8 +201,9 @@ class AclShellTest extends CakeTestCase { $this->Task->expects($this->at(0))->method('out') ->with($this->matchesRegularExpression('/granted/'), true); $this->Task->grant(); + $node = $this->Task->Acl->Aro->node(array('model' => 'AuthUser', 'foreign_key' => 2)); + $node = $this->Task->Acl->Aro->read(null, $node[0]['Aro']['id']); - $node = $this->Task->Acl->Aro->read(null, 4); $this->assertFalse(empty($node['Aco'][0])); $this->assertEqual($node['Aco'][0]['Permission']['_create'], 1); } @@ -224,7 +220,8 @@ class AclShellTest extends CakeTestCase { $this->Task->deny(); - $node = $this->Task->Acl->Aro->read(null, 4); + $node = $this->Task->Acl->Aro->node(array('model' => 'AuthUser', 'foreign_key' => 2)); + $node = $this->Task->Acl->Aro->read(null, $node[0]['Aro']['id']); $this->assertFalse(empty($node['Aco'][0])); $this->assertEqual($node['Aco'][0]['Permission']['_create'], -1); } @@ -274,7 +271,8 @@ class AclShellTest extends CakeTestCase { $this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'all'); $this->Task->inherit(); - $node = $this->Task->Acl->Aro->read(null, 4); + $node = $this->Task->Acl->Aro->node(array('model' => 'AuthUser', 'foreign_key' => 2)); + $node = $this->Task->Acl->Aro->read(null, $node[0]['Aro']['id']); $this->assertFalse(empty($node['Aco'][0])); $this->assertEqual($node['Aco'][0]['Permission']['_create'], 0); } @@ -286,9 +284,13 @@ class AclShellTest extends CakeTestCase { */ public function testGetPath() { $this->Task->args = array('aro', 'AuthUser.2'); - $this->Task->expects($this->at(2))->method('out')->with('[1] ROOT'); - $this->Task->expects($this->at(3))->method('out')->with(' [2] admins'); - $this->Task->expects($this->at(4))->method('out')->with(' [4] Elrond'); + $node = $this->Task->Acl->Aro->node(array('model' => 'AuthUser', 'foreign_key' => 2)); + $first = $node[0]['Aro']['id']; + $second = $node[1]['Aro']['id']; + $last = $node[2]['Aro']['id']; + $this->Task->expects($this->at(2))->method('out')->with('['.$last.'] ROOT'); + $this->Task->expects($this->at(3))->method('out')->with(' ['.$second.'] admins'); + $this->Task->expects($this->at(4))->method('out')->with(' ['.$first.'] Elrond'); $this->Task->getPath(); } diff --git a/cake/tests/cases/console/shells/api.test.php b/cake/tests/cases/console/shells/api.test.php index 109cf57f7..e43c55d33 100644 --- a/cake/tests/cases/console/shells/api.test.php +++ b/cake/tests/cases/console/shells/api.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks * @since CakePHP v 1.2.0.7726 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -26,8 +25,7 @@ require_once CAKE . 'console' . DS . 'shell_dispatcher.php'; /** * ApiShellTest class * - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks */ class ApiShellTest extends CakeTestCase { @@ -76,15 +74,16 @@ class ApiShellTest extends CakeTestCase { '16. render($action = NULL, $layout = NULL, $file = NULL)', '17. set($one, $two = NULL)', '18. setAction($action)', - '19. shutdownProcess()', - '20. startupProcess()', - '21. validate()', - '22. validateErrors()' + '19. setRequest($request)', + '20. shutdownProcess()', + '21. startupProcess()', + '22. validate()', + '23. validateErrors()' ); $this->Shell->expects($this->at(2))->method('out')->with($expected); $this->Shell->args = array('controller'); - $this->Shell->paths['controller'] = CAKE_CORE_INCLUDE_PATH . DS . LIBS . 'controller' . DS; + $this->Shell->paths['controller'] = LIBS . 'controller' . DS; $this->Shell->main(); } } diff --git a/cake/tests/cases/console/shells/bake.test.php b/cake/tests/cases/console/shells/bake.test.php index fc5e79163..7b2767389 100644 --- a/cake/tests/cases/console/shells/bake.test.php +++ b/cake/tests/cases/console/shells/bake.test.php @@ -13,16 +13,15 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ App::import('Shell', 'Shell', false); App::import('Shell', 'Bake', false); -App::import('Shell', 'tasks/model', false); -App::import('Shell', 'tasks/controller', false); -App::import('Shell', 'tasks/db_config', false); +App::import('Shell', 'tasks/model'); +App::import('Shell', 'tasks/controller'); +App::import('Shell', 'tasks/db_config'); App::import('Core', 'Controller'); require_once CAKE . 'console' . DS . 'shell_dispatcher.php'; @@ -94,12 +93,11 @@ class BakeShellTest extends CakeTestCase { $this->Shell->Controller->expects($this->once())->method('bake')->will($this->returnValue(true)); $this->Shell->View->expects($this->once())->method('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->expects($this->at(5))->method('out')->with('User Controller was baked.'); - $this->Shell->expects($this->at(7))->method('out')->with('User Views were baked.'); - $this->Shell->expects($this->at(8))->method('out')->with('Bake All complete'); + $this->Shell->expects($this->once())->method('_stop'); + $this->Shell->expects($this->at(0))->method('out')->with('Bake All'); + $this->Shell->expects($this->at(5))->method('out')->with('Bake All complete'); + $this->Shell->connection = ''; $this->Shell->params = array(); $this->Shell->args = array('User'); $this->Shell->all(); diff --git a/cake/tests/cases/console/shells/command_list.test.php b/cake/tests/cases/console/shells/command_list.test.php index bdabc2230..7b518730a 100644 --- a/cake/tests/cases/console/shells/command_list.test.php +++ b/cake/tests/cases/console/shells/command_list.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.tests.cases.console.libs + * @package cake.tests.cases.console.libs * @since CakePHP v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/cases/console/shells/schema.test.php b/cake/tests/cases/console/shells/schema.test.php index 611928e53..d18b7a478 100644 --- a/cake/tests/cases/console/shells/schema.test.php +++ b/cake/tests/cases/console/shells/schema.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.tests.cases.console.libs.Shells + * @package cake.tests.cases.console.libs.Shells * @since CakePHP v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -28,8 +27,7 @@ require_once CAKE . 'console' . DS . 'shell_dispatcher.php'; /** * Test for Schema database management * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class SchemaShellTestSchema extends CakeSchema { @@ -89,8 +87,7 @@ class SchemaShellTestSchema extends CakeSchema { /** * SchemaShellTest class * - * @package cake - * @subpackage cake.tests.cases.console.libs.Shells + * @package cake.tests.cases.console.libs.Shells */ class SchemaShellTest extends CakeTestCase { @@ -223,7 +220,7 @@ class SchemaShellTest extends CakeTestCase { $this->file = new File(TMP . 'tests' . DS . 'i18n.sql'); $contents = $this->file->read(); $this->assertPattern('/DROP TABLE/', $contents); - $this->assertPattern('/CREATE TABLE `i18n`/', $contents); + $this->assertPattern('/CREATE TABLE.*?i18n/', $contents); $this->assertPattern('/id/', $contents); $this->assertPattern('/model/', $contents); $this->assertPattern('/field/', $contents); @@ -253,7 +250,7 @@ class SchemaShellTest extends CakeTestCase { $this->file = new File(TMP . 'tests' . DS . 'dump_test.sql'); $contents = $this->file->read(); - $this->assertPattern('/CREATE TABLE `test_plugin_acos`/', $contents); + $this->assertPattern('/CREATE TABLE.*?test_plugin_acos/', $contents); $this->assertPattern('/id/', $contents); $this->assertPattern('/model/', $contents); @@ -339,6 +336,7 @@ class SchemaShellTest extends CakeTestCase { ), true); App::objects('plugin', null, false); + $this->db->cacheSources = false; $this->Shell->params = array( 'plugin' => 'TestPlugin', 'connection' => 'test' @@ -366,8 +364,7 @@ class SchemaShellTest extends CakeTestCase { */ public function testCreateNoArgs() { $this->Shell->params = array( - 'connection' => 'test', - 'path' => APP . 'config' . DS . 'sql' + 'connection' => 'test' ); $this->Shell->args = array('i18n'); $this->Shell->startup(); @@ -375,6 +372,8 @@ class SchemaShellTest extends CakeTestCase { $this->Shell->create(); $db = ConnectionManager::getDataSource('test'); + + $db->cacheSources = false; $sources = $db->listSources(); $this->assertTrue(in_array($db->config['prefix'] . 'i18n', $sources)); @@ -396,7 +395,7 @@ class SchemaShellTest extends CakeTestCase { $this->Shell->params = array( 'connection' => 'test', 'name' => 'DbAcl', - 'path' => APP . 'config' . DS . 'schema' + 'path' => CONFIGS . 'schema' ); $this->Shell->args = array('DbAcl', 'acos'); $this->Shell->startup(); @@ -404,6 +403,7 @@ class SchemaShellTest extends CakeTestCase { $this->Shell->create(); $db = ConnectionManager::getDataSource('test'); + $db->cacheSources = false; $sources = $db->listSources(); $this->assertTrue(in_array($db->config['prefix'] . 'acos', $sources), 'acos should be present.'); $this->assertFalse(in_array($db->config['prefix'] . 'aros', $sources), 'aros should not be found.'); diff --git a/cake/tests/cases/console/shells/shell.test.php b/cake/tests/cases/console/shells/shell.test.php index ff341468b..ac5d77faf 100644 --- a/cake/tests/cases/console/shells/shell.test.php +++ b/cake/tests/cases/console/shells/shell.test.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.tests.cases.console.libs + * @package cake.tests.cases.console.libs * @since CakePHP v 1.2.0.7726 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,12 +24,11 @@ App::import('Shell', 'Shell', false); require_once CAKE . 'console' . DS . 'shell_dispatcher.php'; /** - * TestShell class + * ShellTestShell class * - * @package cake - * @subpackage cake.tests.cases.console.libs + * @package cake.tests.cases.console.libs */ -class TestShell extends Shell { +class ShellTestShell extends Shell { /** * name property @@ -38,7 +36,7 @@ class TestShell extends Shell { * @var name * @access public */ - public $name = 'TestShell'; + public $name = 'ShellTestShell'; /** * stopped property @@ -88,8 +86,7 @@ class TestMergeShell extends Shell { /** * TestAppleTask class * - * @package cake - * @subpackage cake.tests.cases.console.libs + * @package cake.tests.cases.console.libs */ class TestAppleTask extends Shell { } @@ -97,8 +94,7 @@ class TestAppleTask extends Shell { /** * TestBananaTask class * - * @package cake - * @subpackage cake.tests.cases.console.libs + * @package cake.tests.cases.console.libs */ class TestBananaTask extends Shell { } @@ -106,8 +102,7 @@ class TestBananaTask extends Shell { /** * ShellTest class * - * @package cake - * @subpackage cake.tests.cases.console.libs + * @package cake.tests.cases.console.libs */ class ShellTest extends CakeTestCase { @@ -133,7 +128,7 @@ class ShellTest extends CakeTestCase { $output = $this->getMock('ConsoleOutput', array(), array(), '', false); $error = $this->getMock('ConsoleOutput', array(), array(), '', false); $in = $this->getMock('ConsoleInput', array(), array(), '', false); - $this->Shell = new TestShell($output, $error, $in); + $this->Shell = new ShellTestShell($output, $error, $in); } /** @@ -142,10 +137,10 @@ class ShellTest extends CakeTestCase { * @return void */ public function testConstruct() { - $this->assertEqual($this->Shell->name, 'TestShell'); - $this->assertType('ConsoleInput', $this->Shell->stdin); - $this->assertType('ConsoleOutput', $this->Shell->stdout); - $this->assertType('ConsoleOutput', $this->Shell->stderr); + $this->assertEqual($this->Shell->name, 'ShellTestShell'); + $this->assertInstanceOf('ConsoleInput', $this->Shell->stdin); + $this->assertInstanceOf('ConsoleOutput', $this->Shell->stdout); + $this->assertInstanceOf('ConsoleOutput', $this->Shell->stderr); } /** diff --git a/cake/tests/cases/console/shells/tasks/controller.test.php b/cake/tests/cases/console/shells/tasks/controller.test.php index f3601376e..5abda16c9 100644 --- a/cake/tests/cases/console/shells/tasks/controller.test.php +++ b/cake/tests/cases/console/shells/tasks/controller.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -49,8 +48,7 @@ if (!$imported) { /** * ControllerTaskTest class * - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks */ class ControllerTaskTest extends CakeTestCase { @@ -340,7 +338,7 @@ class ControllerTaskTest extends CakeTestCase { $this->assertContains("\$this->set('bakeArticles', \$this->paginate());", $result); $this->assertContains('function view($id = null)', $result); - $this->assertContains("\$this->Session->setFlash(__('Invalid bake article'));", $result); + $this->assertContains("throw new NotFoundException(__('Invalid bake article'));", $result); $this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result); $this->assertContains('function add()', $result); @@ -352,7 +350,7 @@ class ControllerTaskTest extends CakeTestCase { $this->assertContains("\$this->Session->setFlash(__('The bake article could not be saved. Please, try again.'));", $result); $this->assertContains('function delete($id = null)', $result); - $this->assertContains('if ($this->BakeArticle->delete($id))', $result); + $this->assertContains('if ($this->BakeArticle->delete())', $result); $this->assertContains("\$this->Session->setFlash(__('Bake article deleted'));", $result); $result = $this->Task->bakeActions('BakeArticles', 'admin_', true); @@ -382,7 +380,7 @@ class ControllerTaskTest extends CakeTestCase { $this->assertContains("\$this->set('bakeArticles', \$this->paginate());", $result); $this->assertContains('function view($id = null)', $result); - $this->assertContains("\$this->flash(__('Invalid bake article'), array('action' => 'index'))", $result); + $this->assertContains("throw new NotFoundException(__('Invalid bake article'));", $result); $this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result); $this->assertContains('function add()', $result); @@ -396,7 +394,7 @@ class ControllerTaskTest extends CakeTestCase { $this->assertContains("\$this->set(compact('bakeTags'))", $result); $this->assertContains('function delete($id = null)', $result); - $this->assertContains('if ($this->BakeArticle->delete($id))', $result); + $this->assertContains('if ($this->BakeArticle->delete())', $result); $this->assertContains("\$this->flash(__('Bake article deleted'), array('action' => 'index'))", $result); } diff --git a/cake/tests/cases/console/shells/tasks/db_config.test.php b/cake/tests/cases/console/shells/tasks/db_config.test.php index aca87ac94..6d37ffbb8 100644 --- a/cake/tests/cases/console/shells/tasks/db_config.test.php +++ b/cake/tests/cases/console/shells/tasks/db_config.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -48,8 +47,7 @@ class TEST_DATABASE_CONFIG { /** * DbConfigTest class * - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks */ class DbConfigTaskTest extends CakeTestCase { diff --git a/cake/tests/cases/console/shells/tasks/extract.test.php b/cake/tests/cases/console/shells/tasks/extract.test.php index 21993e0d4..0b2fbf4bc 100644 --- a/cake/tests/cases/console/shells/tasks/extract.test.php +++ b/cake/tests/cases/console/shells/tasks/extract.test.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks * @since CakePHP v 1.2.0.7726 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -28,8 +27,7 @@ require_once CAKE . 'console' . DS . 'shell_dispatcher.php'; /** * ExtractTaskTest class * - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks */ class ExtractTaskTest extends CakeTestCase { diff --git a/cake/tests/cases/console/shells/tasks/fixture.test.php b/cake/tests/cases/console/shells/tasks/fixture.test.php index 7121f7fd1..9265fdfb6 100644 --- a/cake/tests/cases/console/shells/tasks/fixture.test.php +++ b/cake/tests/cases/console/shells/tasks/fixture.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -29,8 +28,7 @@ require_once CAKE . 'console' . DS . 'shell_dispatcher.php'; /** * FixtureTaskTest class * - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks */ class FixtureTaskTest extends CakeTestCase { diff --git a/cake/tests/cases/console/shells/tasks/model.test.php b/cake/tests/cases/console/shells/tasks/model.test.php index ac2a2c7fc..98ad033cd 100644 --- a/cake/tests/cases/console/shells/tasks/model.test.php +++ b/cake/tests/cases/console/shells/tasks/model.test.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks * @since CakePHP v 1.2.6 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -31,8 +30,7 @@ require_once CAKE . 'console' . DS . 'shell_dispatcher.php'; /** * ModelTaskTest class * - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks */ class ModelTaskTest extends CakeTestCase { diff --git a/cake/tests/cases/console/shells/tasks/plugin.test.php b/cake/tests/cases/console/shells/tasks/plugin.test.php index 327b258c2..22131744e 100644 --- a/cake/tests/cases/console/shells/tasks/plugin.test.php +++ b/cake/tests/cases/console/shells/tasks/plugin.test.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2006-2009, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks * @since CakePHP v 1.3.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -32,8 +31,7 @@ require_once CAKE . 'console' . DS . 'shell_dispatcher.php'; /** * PluginTaskPlugin class * - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks */ class PluginTaskTest extends CakeTestCase { diff --git a/cake/tests/cases/console/shells/tasks/project.test.php b/cake/tests/cases/console/shells/tasks/project.test.php index e9044d992..65a5b4a52 100644 --- a/cake/tests/cases/console/shells/tasks/project.test.php +++ b/cake/tests/cases/console/shells/tasks/project.test.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks * @since CakePHP v 1.3.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -29,8 +28,7 @@ require_once CAKE . 'console' . DS . 'shell_dispatcher.php'; /** * ProjectTask Test class * - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks */ class ProjectTaskTest extends CakeTestCase { @@ -70,7 +68,7 @@ class ProjectTaskTest extends CakeTestCase { * @return void */ protected function _setupTestProject() { - $skel = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS . 'templates' . DS . 'skel'; + $skel = CAKE . 'console' . DS . 'templates' . DS . 'skel'; $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y')); $this->Task->bake($this->Task->path . 'bake_test_app', $skel); } @@ -256,7 +254,7 @@ class ProjectTaskTest extends CakeTestCase { * @return void */ public function testExecute() { - $this->Task->params['skel'] = CAKE_CORE_INCLUDE_PATH . DS . CAKE . DS . 'console' . DS. 'templates' . DS . 'skel'; + $this->Task->params['skel'] = CAKE . DS . 'console' . DS. 'templates' . DS . 'skel'; $this->Task->params['working'] = TMP . 'tests' . DS; $path = $this->Task->path . 'bake_test_app'; @@ -264,7 +262,7 @@ class ProjectTaskTest extends CakeTestCase { $this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y')); $this->Task->execute(); - $this->assertTrue(is_dir($path), 'No project dir %s'); + $this->assertTrue(is_dir($path), 'No project dir'); $this->assertTrue(is_dir($path . DS . 'controllers'), 'No controllers dir '); $this->assertTrue(is_dir($path . DS . 'controllers' . DS .'components'), 'No components dir '); $this->assertTrue(is_dir($path . DS . 'models'), 'No models dir'); diff --git a/cake/tests/cases/console/shells/tasks/template.test.php b/cake/tests/cases/console/shells/tasks/template.test.php index 9d970a092..0085d4f75 100644 --- a/cake/tests/cases/console/shells/tasks/template.test.php +++ b/cake/tests/cases/console/shells/tasks/template.test.php @@ -15,8 +15,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -28,8 +27,7 @@ require_once CAKE . 'console' . DS . 'shell_dispatcher.php'; /** * TemplateTaskTest class * - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks */ class TemplateTaskTest extends CakeTestCase { @@ -88,7 +86,7 @@ class TemplateTaskTest extends CakeTestCase { * @return void */ public function testFindingInstalledThemesForBake() { - $consoleLibs = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS; + $consoleLibs = CAKE . 'console' . DS; $this->Task->initialize(); $this->assertEqual($this->Task->templatePaths, array('default' => $consoleLibs . 'templates' . DS . 'default' . DS)); } diff --git a/cake/tests/cases/console/shells/tasks/test.test.php b/cake/tests/cases/console/shells/tasks/test.test.php index 14b603e54..394098a38 100644 --- a/cake/tests/cases/console/shells/tasks/test.test.php +++ b/cake/tests/cases/console/shells/tasks/test.test.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks * @since CakePHP v 1.2.0.7726 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -34,7 +33,7 @@ require_once CAKE . 'console' . DS . 'shell_dispatcher.php'; * Test Article model * * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks */ class TestTaskArticle extends Model { @@ -111,7 +110,7 @@ class TestTaskArticle extends Model { * Tag Testing Model * * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks */ class TestTaskTag extends Model { @@ -151,7 +150,7 @@ class TestTaskTag extends Model { * Simulated plugin * * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks */ class TestTaskAppModel extends Model { } @@ -160,7 +159,7 @@ class TestTaskAppModel extends Model { * Testing AppMode (TaskComment) * * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks */ class TestTaskComment extends TestTaskAppModel { @@ -198,7 +197,7 @@ class TestTaskComment extends TestTaskAppModel { * Test Task Comments Controller * * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks */ class TestTaskCommentsController extends Controller { @@ -222,8 +221,7 @@ class TestTaskCommentsController extends Controller { /** * TestTaskTest class * - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks */ class TestTaskTest extends CakeTestCase { diff --git a/cake/tests/cases/console/shells/tasks/view.test.php b/cake/tests/cases/console/shells/tasks/view.test.php index 5a2dfcce5..99f1afdf9 100644 --- a/cake/tests/cases/console/shells/tasks/view.test.php +++ b/cake/tests/cases/console/shells/tasks/view.test.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks * @since CakePHP v 1.2.0.7726 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -34,7 +33,7 @@ require_once CAKE . 'console' . DS . 'shell_dispatcher.php'; * Test View Task Comment Model * * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks */ class ViewTaskComment extends Model { @@ -72,7 +71,7 @@ class ViewTaskComment extends Model { * Test View Task Article Model * * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks */ class ViewTaskArticle extends Model { @@ -97,7 +96,7 @@ class ViewTaskArticle extends Model { * Test View Task Comments Controller * * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks */ class ViewTaskCommentsController extends Controller { @@ -130,7 +129,7 @@ class ViewTaskCommentsController extends Controller { * Test View Task Articles Controller * * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks */ class ViewTaskArticlesController extends Controller { @@ -202,8 +201,7 @@ class ViewTaskArticlesController extends Controller { /** * ViewTaskTest class * - * @package cake - * @subpackage cake.tests.cases.console.libs.tasks + * @package cake.tests.cases.console.libs.tasks */ class ViewTaskTest extends CakeTestCase { diff --git a/cake/tests/cases/console/shells/testsuite.test.php b/cake/tests/cases/console/shells/testsuite.test.php index bfe463dbf..c57d1573b 100644 --- a/cake/tests/cases/console/shells/testsuite.test.php +++ b/cake/tests/cases/console/shells/testsuite.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.tests.libs + * @package cake.tests.libs * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/cases/libs/all_behaviors.test.php b/cake/tests/cases/libs/all_behaviors.test.php index 625e4065a..88720d386 100644 --- a/cake/tests/cases/libs/all_behaviors.test.php +++ b/cake/tests/cases/libs/all_behaviors.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ * * This test group will run all test in the cases/libs/models/behaviors directory * - * @package cake - * @subpackage cake.tests.groups + * @package cake.tests.groups */ class AllBehaviorsTest extends PHPUnit_Framework_TestSuite { @@ -39,7 +37,7 @@ class AllBehaviorsTest extends PHPUnit_Framework_TestSuite { $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'model' . DS . 'behavior_collection.test.php'); $suite->addTestFile($path . 'acl.test.php'); - // $suite->addTestFile($path . 'containable.test.php'); + $suite->addTestFile($path . 'containable.test.php'); $suite->addTestFile($path . 'translate.test.php'); $suite->addTestFile($path . 'tree.test.php'); return $suite; diff --git a/cake/tests/cases/libs/all_cache_engines.test.php b/cake/tests/cases/libs/all_cache_engines.test.php index 64d2da93c..5c03437cd 100644 --- a/cake/tests/cases/libs/all_cache_engines.test.php +++ b/cake/tests/cases/libs/all_cache_engines.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * This test group will run cache engine tests. * - * @package cake - * @subpackage cake.tests.groups + * @package cake.tests.groups */ class AllCacheEnginesTest extends PHPUnit_Framework_TestSuite { diff --git a/cake/tests/cases/libs/all_components.test.php b/cake/tests/cases/libs/all_components.test.php index 6724303ca..28e59aadf 100644 --- a/cake/tests/cases/libs/all_components.test.php +++ b/cake/tests/cases/libs/all_components.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * This test group will run component class tests * - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases */ class AllComponentsTest extends PHPUnit_Framework_TestSuite { diff --git a/cake/tests/cases/libs/all_configure.test.php b/cake/tests/cases/libs/all_configure.test.php index 859178051..6e35aef74 100644 --- a/cake/tests/cases/libs/all_configure.test.php +++ b/cake/tests/cases/libs/all_configure.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * This test group will run cache engine tests. * - * @package cake - * @subpackage cake.tests.groups + * @package cake.tests.groups */ class AllConfigureTest extends PHPUnit_Framework_TestSuite { @@ -34,9 +32,10 @@ class AllConfigureTest extends PHPUnit_Framework_TestSuite { * @return void */ public static function suite() { - $suite = new PHPUnit_Framework_TestSuite('All Configure, App and ClassRegistry related tests'); + $suite = new CakeTestSuite('All Configure, App and ClassRegistry related tests'); $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'configure.test.php'); + $suite->addTestDirectory(CORE_TEST_CASES . DS . 'libs' . DS . 'config'); $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'app.test.php'); $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'class_registry.test.php'); return $suite; diff --git a/cake/tests/cases/libs/all_controllers.test.php b/cake/tests/cases/libs/all_controllers.test.php index ab3cf5581..8164896d9 100644 --- a/cake/tests/cases/libs/all_controllers.test.php +++ b/cake/tests/cases/libs/all_controllers.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * This test group will run cache engine tests. * - * @package cake - * @subpackage cake.tests.groups + * @package cake.tests.groups */ class AllControllersTest extends PHPUnit_Framework_TestSuite { diff --git a/cake/tests/cases/libs/all_database.test.php b/cake/tests/cases/libs/all_database.test.php index 797541d05..21cef27b6 100644 --- a/cake/tests/cases/libs/all_database.test.php +++ b/cake/tests/cases/libs/all_database.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * This test group will run database tests not in model or behavior group. * - * @package cake - * @subpackage cake.tests.groups + * @package cake.tests.groups */ class AllDatabaseTest extends PHPUnit_Framework_TestSuite { @@ -37,8 +35,15 @@ class AllDatabaseTest extends PHPUnit_Framework_TestSuite { $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'); + $tasks = array( + 'db_acl', + 'cake_schema', + 'connection_manager', + 'datasources' . DS . 'dbo_source', + 'datasources' . DS . 'dbo' . DS . 'dbo_mysql', + 'datasources' . DS . 'dbo' . DS . 'dbo_postgres', + 'datasources' . DS . 'dbo' . DS . 'dbo_sqlite' + ); foreach ($tasks as $task) { $suite->addTestFile($path . $task . '.test.php'); } diff --git a/cake/tests/cases/libs/all_error.test.php b/cake/tests/cases/libs/all_error.test.php index e37176908..b64c87542 100644 --- a/cake/tests/cases/libs/all_error.test.php +++ b/cake/tests/cases/libs/all_error.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * This test group will run error handling related tests. * - * @package cake - * @subpackage cake.tests.groups + * @package cake.tests.groups */ class AllErrorTest extends PHPUnit_Framework_TestSuite { diff --git a/cake/tests/cases/libs/all_helpers.test.php b/cake/tests/cases/libs/all_helpers.test.php index 389290d27..247a10deb 100644 --- a/cake/tests/cases/libs/all_helpers.test.php +++ b/cake/tests/cases/libs/all_helpers.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * This test group will run all test in the cases/libs/view/helpers directory. * - * @package cake - * @subpackage cake.tests.groups + * @package cake.tests.groups */ class AllHelpersTest extends PHPUnit_Framework_TestSuite { diff --git a/cake/tests/cases/libs/all_js_helpers.test.php b/cake/tests/cases/libs/all_js_helpers.test.php index b17e6b4fc..9dd0ab750 100644 --- a/cake/tests/cases/libs/all_js_helpers.test.php +++ b/cake/tests/cases/libs/all_js_helpers.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * 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 + * @package cake.tests.groups */ class AllJavascriptHelpersTest extends PHPUnit_Framework_TestSuite { diff --git a/cake/tests/cases/libs/all_libs.test.php b/cake/tests/cases/libs/all_libs.test.php index 0bab4f0e9..ba0388850 100644 --- a/cake/tests/cases/libs/all_libs.test.php +++ b/cake/tests/cases/libs/all_libs.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * This test group will run all non mvc related lib class tests * - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases */ class AllLibsTest extends PHPUnit_Framework_TestSuite { @@ -49,6 +47,7 @@ class AllLibsTest extends PHPUnit_Framework_TestSuite { $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'); + $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'object_collection.test.php'); return $suite; } } \ No newline at end of file diff --git a/cake/tests/cases/libs/all_localization.test.php b/cake/tests/cases/libs/all_localization.test.php index ce7d0cc95..d30ab86b0 100644 --- a/cake/tests/cases/libs/all_localization.test.php +++ b/cake/tests/cases/libs/all_localization.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * This test group will run i18n/l10n tests * - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases */ class AllLocalizationTest extends PHPUnit_Framework_TestSuite { diff --git a/cake/tests/cases/libs/all_model.test.php b/cake/tests/cases/libs/all_model.test.php index fb99184c0..bf968b0c3 100644 --- a/cake/tests/cases/libs/all_model.test.php +++ b/cake/tests/cases/libs/all_model.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * This test group will run model class tests * - * @package cake - * @subpackage cake.tests.groups + * @package cake.tests.groups */ class AllModelTest extends PHPUnit_Framework_TestSuite { diff --git a/cake/tests/cases/libs/all_routing.test.php b/cake/tests/cases/libs/all_routing.test.php index cf1ff215e..68f0520f9 100644 --- a/cake/tests/cases/libs/all_routing.test.php +++ b/cake/tests/cases/libs/all_routing.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * This test group will run view class tests (view, theme) * - * @package cake - * @subpackage cake.tests.groups + * @package cake.tests.groups */ class AllRoutingTest extends PHPUnit_Framework_TestSuite { diff --git a/cake/tests/cases/libs/all_socket.test.php b/cake/tests/cases/libs/all_socket.test.php index 60802436e..811822f9e 100644 --- a/cake/tests/cases/libs/all_socket.test.php +++ b/cake/tests/cases/libs/all_socket.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * This test group will run socket class tests * - * @package cake - * @subpackage cake.tests.groups + * @package cake.tests.groups */ class AllSocketTest extends PHPUnit_Framework_TestSuite { @@ -34,10 +32,12 @@ class AllSocketTest extends PHPUnit_Framework_TestSuite { * @return void */ public static function suite() { - $suite = new PHPUnit_Framework_TestSuite('All Socket related class tests'); + $suite = new CakeTestSuite('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'); + $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'http_response.test.php'); + $suite->addTestDirectory(CORE_TEST_CASES . DS . 'libs' . DS . 'http'); return $suite; } } \ No newline at end of file diff --git a/cake/tests/cases/libs/all_test_suite.test.php b/cake/tests/cases/libs/all_test_suite.test.php index 9c6a46e6a..b85ea0a19 100644 --- a/cake/tests/cases/libs/all_test_suite.test.php +++ b/cake/tests/cases/libs/all_test_suite.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * This test group will run socket class tests * - * @package cake - * @subpackage cake.tests.groups + * @package cake.tests.groups */ class AllTestSuiteTest extends PHPUnit_Framework_TestSuite { @@ -40,6 +38,7 @@ class AllTestSuiteTest extends PHPUnit_Framework_TestSuite { $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'); + $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'controller_test_case.test.php'); return $suite; } } \ No newline at end of file diff --git a/cake/tests/cases/libs/all_tests.test.php b/cake/tests/cases/libs/all_tests.test.php index b3c94cb82..f7bdc72d3 100644 --- a/cake/tests/cases/libs/all_tests.test.php +++ b/cake/tests/cases/libs/all_tests.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ * * This test group will run all test in the cases/libs/models/behaviors directory * - * @package cake - * @subpackage cake.tests.groups + * @package cake.tests.groups */ class AllTests extends PHPUnit_Framework_TestSuite { diff --git a/cake/tests/cases/libs/all_views.test.php b/cake/tests/cases/libs/all_views.test.php index a84cd0c6d..0201426e4 100644 --- a/cake/tests/cases/libs/all_views.test.php +++ b/cake/tests/cases/libs/all_views.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * This test group will run view class tests (view, theme) * - * @package cake - * @subpackage cake.tests.groups + * @package cake.tests.groups */ class AllViewsTest extends PHPUnit_Framework_TestSuite { diff --git a/cake/tests/cases/libs/all_xml.test.php b/cake/tests/cases/libs/all_xml.test.php index aed5b21d1..e56714ab0 100644 --- a/cake/tests/cases/libs/all_xml.test.php +++ b/cake/tests/cases/libs/all_xml.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ * * This test group will run xml class tests * - * @package cake - * @subpackage cake.tests.groups + * @package cake.tests.groups */ class AllXmlTest extends PHPUnit_Framework_TestSuite { diff --git a/cake/tests/cases/libs/app.test.php b/cake/tests/cases/libs/app.test.php index 079794030..6e7793072 100644 --- a/cake/tests/cases/libs/app.test.php +++ b/cake/tests/cases/libs/app.test.php @@ -3,8 +3,7 @@ /** * AppImportTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class AppImportTest extends CakeTestCase { @@ -211,9 +210,9 @@ class AppImportTest extends CakeTestCase { $this->assertTrue($file); $this->assertTrue(class_exists('Shell')); - $file = App::import('Lib', 'cache/Apc'); + $file = App::import('Lib', 'config/PhpReader'); $this->assertTrue($file); - $this->assertTrue(class_exists('ApcEngine')); + $this->assertTrue(class_exists('PhpReader')); $file = App::import('Model', 'SomeRandomModelThatDoesNotExist', false); $this->assertFalse($file); diff --git a/cake/tests/cases/libs/cache.test.php b/cake/tests/cases/libs/cache.test.php index ad24b70d3..0a35c9794 100644 --- a/cake/tests/cases/libs/cache.test.php +++ b/cake/tests/cases/libs/cache.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.5432 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,8 +23,7 @@ if (!class_exists('Cache')) { /** * CacheTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class CacheTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/cache/apc.test.php b/cake/tests/cases/libs/cache/apc.test.php index bfdcea470..0abd07778 100644 --- a/cake/tests/cases/libs/cache/apc.test.php +++ b/cake/tests/cases/libs/cache/apc.test.php @@ -12,8 +12,7 @@ * * @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.cache + * @package cake.tests.cases.libs.cache * @since CakePHP(tm) v 1.2.0.5434 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,8 +23,7 @@ if (!class_exists('Cache')) { /** * ApcEngineTest class * - * @package cake - * @subpackage cake.tests.cases.libs.cache + * @package cake.tests.cases.libs.cache */ class ApcEngineTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/cache/file.test.php b/cake/tests/cases/libs/cache/file.test.php index 33361f040..fb6741a7a 100644 --- a/cake/tests/cases/libs/cache/file.test.php +++ b/cake/tests/cases/libs/cache/file.test.php @@ -12,8 +12,7 @@ * * @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.cache + * @package cake.tests.cases.libs.cache * @since CakePHP(tm) v 1.2.0.5434 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,8 +23,7 @@ if (!class_exists('Cache')) { /** * FileEngineTest class * - * @package cake - * @subpackage cake.tests.cases.libs.cache + * @package cake.tests.cases.libs.cache */ class FileEngineTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/cache/memcache.test.php b/cake/tests/cases/libs/cache/memcache.test.php index 0eb11e71a..42324a8bc 100644 --- a/cake/tests/cases/libs/cache/memcache.test.php +++ b/cake/tests/cases/libs/cache/memcache.test.php @@ -12,16 +12,14 @@ * * @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.cache + * @package cake.tests.cases.libs.cache * @since CakePHP(tm) v 1.2.0.5434 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ if (!class_exists('Cache')) { require LIBS . 'cache.php'; } -App::import('Core', 'cache/Memcache'); - +require_once LIBS . 'cache' . DS . 'memcache.php'; class TestMemcacheEngine extends MemcacheEngine { /** @@ -38,8 +36,7 @@ class TestMemcacheEngine extends MemcacheEngine { /** * MemcacheEngineTest class * - * @package cake - * @subpackage cake.tests.cases.libs.cache + * @package cake.tests.cases.libs.cache */ class MemcacheEngineTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/cache/xcache.test.php b/cake/tests/cases/libs/cache/xcache.test.php index d889d713c..eea1c4b2c 100644 --- a/cake/tests/cases/libs/cache/xcache.test.php +++ b/cake/tests/cases/libs/cache/xcache.test.php @@ -12,8 +12,7 @@ * * @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.cache + * @package cake.tests.cases.libs.cache * @since CakePHP(tm) v 1.2.0.5434 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,8 +23,7 @@ if (!class_exists('Cache')) { /** * XcacheEngineTest class * - * @package cake - * @subpackage cake.tests.cases.libs.cache + * @package cake.tests.cases.libs.cache */ class XcacheEngineTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/cake_log.test.php b/cake/tests/cases/libs/cake_log.test.php index 52c5c5abc..0d21cb5b2 100644 --- a/cake/tests/cases/libs/cake_log.test.php +++ b/cake/tests/cases/libs/cake_log.test.php @@ -12,19 +12,17 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.5432 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::import('Core', 'Log'); +App::import('Core', 'CakeLog'); App::import('Core', 'log/FileLog'); /** * CakeLogTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class CakeLogTest extends CakeTestCase { @@ -70,7 +68,7 @@ class CakeLogTest extends CakeTestCase { /** * test all the errors from failed logger imports * - * @expectedException Exception + * @expectedException CakeLogException * @return void */ function testImportingLoggerFailure() { @@ -80,7 +78,7 @@ class CakeLogTest extends CakeTestCase { /** * test that loggers have to implement the correct interface. * - * @expectedException Exception + * @expectedException CakeLogException * @return void */ function testNotImplementingInterface() { diff --git a/cake/tests/cases/libs/cake_request.test.php b/cake/tests/cases/libs/cake_request.test.php index af4ad93cb..58cc50631 100644 --- a/cake/tests/cases/libs/cake_request.test.php +++ b/cake/tests/cases/libs/cake_request.test.php @@ -12,14 +12,11 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -if (!class_exists('dispatcher')) { - require CAKE . 'dispatcher.php'; -} +App::import('Core', 'Dispatcher'); App::import('Core', 'CakeRequest'); class CakeRequestTestCase extends CakeTestCase { @@ -614,7 +611,7 @@ class CakeRequestTestCase extends CakeTestCase { /** * test __call expcetions * - * @expectedException Exception + * @expectedException CakeException * @return void */ function test__callExceptionOnUnknownMethod() { diff --git a/cake/tests/cases/libs/cake_response.test.php b/cake/tests/cases/libs/cake_response.test.php index eee0cfc69..d0d2a9e58 100644 --- a/cake/tests/cases/libs/cake_response.test.php +++ b/cake/tests/cases/libs/cake_response.test.php @@ -55,7 +55,7 @@ class CakeResponseTestCase extends CakeTestCase { /** * Tests the statusCode method * -* @expectedException OutOfRangeException +* @expectedException CakeException */ public function testStatusCode() { $response = new CakeResponse(); diff --git a/cake/tests/cases/libs/cake_session.test.php b/cake/tests/cases/libs/cake_session.test.php index 51d37dc14..3673121fd 100644 --- a/cake/tests/cases/libs/cake_session.test.php +++ b/cake/tests/cases/libs/cake_session.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -34,8 +33,7 @@ class TestCakeSession extends CakeSession { /** * CakeSessionTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class CakeSessionTest extends CakeTestCase { @@ -88,7 +86,6 @@ class CakeSessionTest extends CakeTestCase { 'ini' => array(), )); TestCakeSession::init(); - TestCakeSession::$watchKeys = array(); } /** @@ -136,10 +133,10 @@ class CakeSessionTest extends CakeTestCase { */ function testSessionPath() { TestCakeSession::init('/index.php'); - $this->assertEqual('/', TestCakeSession::$path); + $this->assertEquals(TestCakeSession::$path, '/'); TestCakeSession::init('/sub_dir/index.php'); - $this->assertEqual('/sub_dir/', TestCakeSession::$path); + $this->assertEquals(TestCakeSession::$path, '/sub_dir/'); } /** @@ -150,7 +147,7 @@ class CakeSessionTest extends CakeTestCase { */ function testCakeSessionPathEmpty() { TestCakeSession::init(''); - $this->assertEqual('/', TestCakeSession::$path, 'Session path is empty, with "" as $base needs to be / %s'); + $this->assertEquals(TestCakeSession::$path, '/', 'Session path is empty, with "" as $base needs to be /'); } /** @@ -161,7 +158,7 @@ class CakeSessionTest extends CakeTestCase { */ function testCakeSessionPathContainsQuestion() { TestCakeSession::init('/index.php?'); - $this->assertEqual('/', TestCakeSession::$path); + $this->assertEquals(TestCakeSession::$path, '/'); } /** @@ -173,7 +170,7 @@ class CakeSessionTest extends CakeTestCase { function testSetHost() { TestCakeSession::init(); TestCakeSession::setHost('cakephp.org'); - $this->assertEqual('cakephp.org', TestCakeSession::$host); + $this->assertEquals(TestCakeSession::$host, 'cakephp.org'); } /** @@ -185,7 +182,7 @@ class CakeSessionTest extends CakeTestCase { function testSetHostWithPort() { TestCakeSession::init(); TestCakeSession::setHost('cakephp.org:443'); - $this->assertEqual('cakephp.org', TestCakeSession::$host); + $this->assertEquals(TestCakeSession::$host, 'cakephp.org'); } /** @@ -238,14 +235,14 @@ class CakeSessionTest extends CakeTestCase { function testSimpleRead() { TestCakeSession::write('testing', '1,2,3'); $result = TestCakeSession::read('testing'); - $this->assertEqual($result, '1,2,3'); + $this->assertEquals('1,2,3', $result); TestCakeSession::write('testing', array('1' => 'one', '2' => 'two','3' => 'three')); $result = TestCakeSession::read('testing.1'); - $this->assertEqual($result, 'one'); + $this->assertEquals('one', $result); $result = TestCakeSession::read('testing'); - $this->assertEqual($result, array('1' => 'one', '2' => 'two', '3' => 'three')); + $this->assertEquals(array('1' => 'one', '2' => 'two', '3' => 'three'), $result); $result = TestCakeSession::read(); $this->assertTrue(isset($result['testing'])); @@ -254,7 +251,7 @@ class CakeSessionTest extends CakeTestCase { TestCakeSession::write('This.is.a.deep.array.my.friend', 'value'); $result = TestCakeSession::read('This.is.a.deep.array.my.friend'); - $this->assertEqual('value', $result); + $this->assertEquals($result, 'value'); } /** @@ -305,13 +302,15 @@ class CakeSessionTest extends CakeTestCase { * @return void */ function testId() { - $expected = session_id(); + TestCakeSession::destroy(); + $result = TestCakeSession::id(); - $this->assertEqual($result, $expected); + $expected = session_id(); + $this->assertEquals($expected, $result); TestCakeSession::id('MySessionId'); $result = TestCakeSession::id(); - $this->assertEqual($result, 'MySessionId'); + $this->assertEquals('MySessionId', $result); } /** @@ -321,10 +320,9 @@ class CakeSessionTest extends CakeTestCase { * @return void */ function testStarted() { - $this->assertTrue(TestCakeSession::started()); - unset($_SESSION); $_SESSION = null; + $this->assertFalse(TestCakeSession::started()); $this->assertTrue(TestCakeSession::start()); $this->assertTrue(TestCakeSession::started()); @@ -339,11 +337,11 @@ class CakeSessionTest extends CakeTestCase { function testError() { TestCakeSession::read('Does.not.exist'); $result = TestCakeSession::error(); - $this->assertEqual($result, "Does.not.exist doesn't exist"); + $this->assertEquals("Does.not.exist doesn't exist", $result); TestCakeSession::delete('Failing.delete'); $result = TestCakeSession::error(); - $this->assertEqual($result, "Failing.delete doesn't exist"); + $this->assertEquals("Failing.delete doesn't exist", $result); } /** @@ -364,47 +362,6 @@ class CakeSessionTest extends CakeTestCase { $this->assertFalse(TestCakeSession::check('Clearing')); } -/** - * testWatchVar method - * - * @expectedException Exception - * @access public - * @return void - */ - function testWatchVarWrite() { - $this->assertFalse(TestCakeSession::watch(null)); - - TestCakeSession::write('Watching', "I'm watching you"); - TestCakeSession::watch('Watching'); - TestCakeSession::write('Watching', 'They found us!'); - } - -/** - * undocumented function - * - * @expectedException Exception - * @return void - */ - function testWatchVarDelete() { - TestCakeSession::watch('Watching'); - TestCakeSession::delete('Watching'); - - $this->assertFalse(TestCakeSession::watch('Invalid.key')); - } - -/** - * testIgnore method - * - * @access public - * @return void - */ - function testIgnore() { - TestCakeSession::write('Watching', "I'm watching you"); - TestCakeSession::watch('Watching'); - TestCakeSession::ignore('Watching'); - $this->assertTrue(TestCakeSession::write('Watching', 'They found us!')); - } - /** * testDestroy method * @@ -448,7 +405,7 @@ class CakeSessionTest extends CakeTestCase { */ function testCheckKeyWithSpaces() { $this->assertTrue(TestCakeSession::write('Session Test', "test")); - $this->assertEqual(TestCakeSession::check('Session Test'), 'test'); + $this->assertEquals('test', TestCakeSession::check('Session Test')); TestCakeSession::delete('Session Test'); $this->assertTrue(TestCakeSession::write('Session Test.Test Case', "test")); @@ -476,7 +433,7 @@ class CakeSessionTest extends CakeTestCase { $this->assertTrue($result); $result = TestCakeSession::read($key); - $this->assertEqual($result, 'haxored'); + $this->assertEquals('haxored', $result); } /** @@ -487,17 +444,17 @@ class CakeSessionTest extends CakeTestCase { */ function testReadingSavedEmpty() { TestCakeSession::write('SessionTestCase', 0); - $this->assertEqual(TestCakeSession::read('SessionTestCase'), 0); + $this->assertEquals(0, TestCakeSession::read('SessionTestCase')); TestCakeSession::write('SessionTestCase', '0'); - $this->assertEqual(TestCakeSession::read('SessionTestCase'), '0'); + $this->assertEquals('0', TestCakeSession::read('SessionTestCase')); $this->assertFalse(TestCakeSession::read('SessionTestCase') === 0); TestCakeSession::write('SessionTestCase', false); $this->assertFalse(TestCakeSession::read('SessionTestCase')); TestCakeSession::write('SessionTestCase', null); - $this->assertEqual(TestCakeSession::read('SessionTestCase'), null); + $this->assertEquals(null, TestCakeSession::read('SessionTestCase')); } /** @@ -541,24 +498,24 @@ class CakeSessionTest extends CakeTestCase { TestCakeSession::start(); TestCakeSession::write('SessionTestCase', 0); - $this->assertEqual(TestCakeSession::read('SessionTestCase'), 0); + $this->assertEquals(0, TestCakeSession::read('SessionTestCase')); TestCakeSession::write('SessionTestCase', '0'); - $this->assertEqual(TestCakeSession::read('SessionTestCase'), '0'); + $this->assertEquals('0', TestCakeSession::read('SessionTestCase')); $this->assertFalse(TestCakeSession::read('SessionTestCase') === 0); TestCakeSession::write('SessionTestCase', false); $this->assertFalse(TestCakeSession::read('SessionTestCase')); TestCakeSession::write('SessionTestCase', null); - $this->assertEqual(TestCakeSession::read('SessionTestCase'), null); + $this->assertEquals(null, TestCakeSession::read('SessionTestCase')); TestCakeSession::write('SessionTestCase', 'This is a Test'); - $this->assertEqual(TestCakeSession::read('SessionTestCase'), 'This is a Test'); + $this->assertEquals('This is a Test', TestCakeSession::read('SessionTestCase')); TestCakeSession::write('SessionTestCase', 'This is a Test'); TestCakeSession::write('SessionTestCase', 'This was updated'); - $this->assertEqual(TestCakeSession::read('SessionTestCase'), 'This was updated'); + $this->assertEquals('This was updated', TestCakeSession::read('SessionTestCase')); TestCakeSession::destroy(); $this->assertNull(TestCakeSession::read('SessionTestCase')); @@ -623,24 +580,24 @@ class CakeSessionTest extends CakeTestCase { TestCakeSession::destroy(); TestCakeSession::write('SessionTestCase', 0); - $this->assertEqual(TestCakeSession::read('SessionTestCase'), 0); + $this->assertEquals(0, TestCakeSession::read('SessionTestCase')); TestCakeSession::write('SessionTestCase', '0'); - $this->assertEqual(TestCakeSession::read('SessionTestCase'), '0'); + $this->assertEquals('0', TestCakeSession::read('SessionTestCase')); $this->assertFalse(TestCakeSession::read('SessionTestCase') === 0); TestCakeSession::write('SessionTestCase', false); $this->assertFalse(TestCakeSession::read('SessionTestCase')); TestCakeSession::write('SessionTestCase', null); - $this->assertEqual(TestCakeSession::read('SessionTestCase'), null); + $this->assertEquals(null, TestCakeSession::read('SessionTestCase')); TestCakeSession::write('SessionTestCase', 'This is a Test'); - $this->assertEqual(TestCakeSession::read('SessionTestCase'), 'This is a Test'); + $this->assertEquals('This is a Test', TestCakeSession::read('SessionTestCase')); TestCakeSession::write('SessionTestCase', 'This is a Test'); TestCakeSession::write('SessionTestCase', 'This was updated'); - $this->assertEqual(TestCakeSession::read('SessionTestCase'), 'This was updated'); + $this->assertEquals('This was updated', TestCakeSession::read('SessionTestCase')); TestCakeSession::destroy(); $this->assertNull(TestCakeSession::read('SessionTestCase')); @@ -686,23 +643,23 @@ class CakeSessionTest extends CakeTestCase { TestCakeSession::start(); TestCakeSession::write('SessionTestCase', 0); - $this->assertEqual(TestCakeSession::read('SessionTestCase'), 0); + $this->assertEquals(0, TestCakeSession::read('SessionTestCase')); TestCakeSession::write('SessionTestCase', '0'); - $this->assertEqual(TestCakeSession::read('SessionTestCase'), '0'); + $this->assertEquals('0', TestCakeSession::read('SessionTestCase')); $this->assertFalse(TestCakeSession::read('SessionTestCase') === 0); TestCakeSession::write('SessionTestCase', false); $this->assertFalse(TestCakeSession::read('SessionTestCase')); TestCakeSession::write('SessionTestCase', null); - $this->assertEqual(TestCakeSession::read('SessionTestCase'), null); + $this->assertEquals(null, TestCakeSession::read('SessionTestCase')); TestCakeSession::write('SessionTestCase', 'This is a Test'); - $this->assertEqual(TestCakeSession::read('SessionTestCase'), 'This is a Test'); + $this->assertEquals('This is a Test', TestCakeSession::read('SessionTestCase')); TestCakeSession::write('SessionTestCase', 'Some additional data'); - $this->assertEqual(TestCakeSession::read('SessionTestCase'), 'Some additional data'); + $this->assertEquals('Some additional data', TestCakeSession::read('SessionTestCase')); TestCakeSession::destroy(); $this->assertNull(TestCakeSession::read('SessionTestCase')); @@ -728,21 +685,21 @@ class CakeSessionTest extends CakeTestCase { TestCakeSession::destroy(); TestCakeSession::write('Test', 'some value'); - $this->assertEqual(CakeSession::$sessionTime, time() + $timeoutSeconds); - $this->assertEqual($_SESSION['Config']['countdown'], 10); - $this->assertEqual($_SESSION['Config']['time'], CakeSession::$sessionTime); - $this->assertEqual(CakeSession::$time, time()); - $this->assertEqual($_SESSION['Config']['time'], time() + $timeoutSeconds); + $this->assertEquals(time() + $timeoutSeconds, CakeSession::$sessionTime); + $this->assertEquals(10, $_SESSION['Config']['countdown']); + $this->assertEquals(CakeSession::$sessionTime, $_SESSION['Config']['time']); + $this->assertEquals(time(), CakeSession::$time); + $this->assertEquals(time() + $timeoutSeconds, $_SESSION['Config']['time']); Configure::write('Session.harden', true); TestCakeSession::destroy(); TestCakeSession::write('Test', 'some value'); - $this->assertEqual(CakeSession::$sessionTime, time() + $timeoutSeconds); - $this->assertEqual($_SESSION['Config']['countdown'], 10); - $this->assertEqual($_SESSION['Config']['time'], CakeSession::$sessionTime); - $this->assertEqual(CakeSession::$time, time()); - $this->assertEqual($_SESSION['Config']['time'], CakeSession::$time + $timeoutSeconds); + $this->assertEquals(time() + $timeoutSeconds, CakeSession::$sessionTime); + $this->assertEquals(10, $_SESSION['Config']['countdown']); + $this->assertEquals(CakeSession::$sessionTime, $_SESSION['Config']['time']); + $this->assertEquals(time(), CakeSession::$time); + $this->assertEquals(CakeSession::$time + $timeoutSeconds, $_SESSION['Config']['time']); } } diff --git a/cake/tests/cases/libs/cake_socket.test.php b/cake/tests/cases/libs/cake_socket.test.php index 48b304060..ac12b4553 100644 --- a/cake/tests/cases/libs/cake_socket.test.php +++ b/cake/tests/cases/libs/cake_socket.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Core', 'CakeSocket'); /** * SocketTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class CakeSocketTest extends CakeTestCase { @@ -34,7 +32,8 @@ class CakeSocketTest extends CakeTestCase { * @return void */ function setUp() { - $this->Socket = new CakeSocket(); + parent::setUp(); + $this->Socket = new CakeSocket(array('timeout' => 1)); } /** @@ -44,6 +43,7 @@ class CakeSocketTest extends CakeTestCase { * @return void */ function tearDown() { + parent::tearDown(); unset($this->Socket); } @@ -54,7 +54,7 @@ class CakeSocketTest extends CakeTestCase { * @return void */ function testConstruct() { - $this->Socket->__construct(); + $this->Socket = new CakeSocket(); $config = $this->Socket->config; $this->assertIdentical($config, array( 'persistent' => false, @@ -101,6 +101,30 @@ class CakeSocketTest extends CakeTestCase { $this->assertTrue($this->Socket->connected); } +/** + * data provider function for testInvalidConnection + * + * @return array + */ + public static function invalidConnections() { + return array( + array(array('host' => 'invalid.host', 'timeout' => 1)), + array(array('host' => '127.0.0.1', 'port' => '70000', 'timeout' => 1)) + ); + } + +/** + * testInvalidConnection method + * + * @dataProvider invalidConnections + * @expectedException SocketException + * return void + */ + public function testInvalidConnection($data) { + $this->Socket->config = array_merge($this->Socket->config, $data); + $this->Socket->connect(); + } + /** * testSocketHost method * diff --git a/cake/tests/cases/libs/cake_test_case.test.php b/cake/tests/cases/libs/cake_test_case.test.php index f9e5e8410..505dd8a08 100644 --- a/cake/tests/cases/libs/cake_test_case.test.php +++ b/cake/tests/cases/libs/cake_test_case.test.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.cake.libs. + * @package cake.libs. * @since CakePHP v 1.2.0.4487 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -31,8 +30,7 @@ if (!class_exists('AppController')) { /** * CakeTestCaseTest * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class CakeTestCaseTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/cake_test_fixture.test.php b/cake/tests/cases/libs/cake_test_fixture.test.php index 2042eb922..82c08be98 100644 --- a/cake/tests/cases/libs/cake_test_fixture.test.php +++ b/cake/tests/cases/libs/cake_test_fixture.test.php @@ -12,8 +12,7 @@ * * @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.cake.tests.libs + * @package cake.tests.libs * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Datasource', 'DboSource', false); /** * CakeTestFixtureTestFixture class * - * @package cake - * @subpackage cake.cake.tests.cases.libs + * @package cake.tests.cases.libs */ class CakeTestFixtureTestFixture extends CakeTestFixture { @@ -67,8 +65,7 @@ class CakeTestFixtureTestFixture extends CakeTestFixture { /** * CakeTestFixtureImportFixture class * - * @package cake - * @subpackage cake.cake.tests.cases.libs + * @package cake.tests.cases.libs */ class CakeTestFixtureImportFixture extends CakeTestFixture { @@ -90,8 +87,7 @@ class CakeTestFixtureImportFixture extends CakeTestFixture { /** * CakeTestFixtureDefaultImportFixture class * - * @package cake - * @subpackage cake.cake.tests.cases.libs + * @package cake.tests.cases.libs */ class CakeTestFixtureDefaultImportFixture extends CakeTestFixture { @@ -107,7 +103,7 @@ class CakeTestFixtureDefaultImportFixture extends CakeTestFixture { * FixtureImportTestModel class * * @package default - * @subpackage cake.cake.tests.cases.libs. + * @package cake.tests.cases.libs. */ class FixtureImportTestModel extends Model { public $name = 'FixtureImport'; @@ -125,8 +121,7 @@ class FixturePrefixTest extends Model { /** * Test case for CakeTestFixture * - * @package cake - * @subpackage cake.cake.tests.cases.libs + * @package cake.tests.cases.libs */ class CakeTestFixtureTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/class_registry.test.php b/cake/tests/cases/libs/class_registry.test.php index 7c0c14b23..21aa081b1 100644 --- a/cake/tests/cases/libs/class_registry.test.php +++ b/cake/tests/cases/libs/class_registry.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.5432 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Core', 'ClassRegistry'); /** * ClassRegisterModel class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class ClassRegisterModel extends CakeTestModel { @@ -39,8 +37,7 @@ class ClassRegisterModel extends CakeTestModel { /** * RegisterArticle class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class RegisterArticle extends ClassRegisterModel { @@ -56,8 +53,7 @@ class RegisterArticle extends ClassRegisterModel { /** * RegisterArticleFeatured class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class RegisterArticleFeatured extends ClassRegisterModel { @@ -73,8 +69,7 @@ class RegisterArticleFeatured extends ClassRegisterModel { /** * RegisterArticleTag class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class RegisterArticleTag extends ClassRegisterModel { @@ -90,8 +85,7 @@ class RegisterArticleTag extends ClassRegisterModel { /** * RegistryPluginAppModel class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class RegistryPluginAppModel extends ClassRegisterModel { @@ -107,8 +101,7 @@ class RegistryPluginAppModel extends ClassRegisterModel { /** * TestRegistryPluginModel class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class TestRegistryPluginModel extends RegistryPluginAppModel { @@ -124,8 +117,7 @@ class TestRegistryPluginModel extends RegistryPluginAppModel { /** * RegisterCategory class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class RegisterCategory extends ClassRegisterModel { @@ -141,8 +133,7 @@ class RegisterCategory extends ClassRegisterModel { /** * ClassRegistryTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class ClassRegistryTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/config/ini_file.test.php b/cake/tests/cases/libs/config/ini_file.test.php deleted file mode 100644 index 566c1113b..000000000 --- a/cake/tests/cases/libs/config/ini_file.test.php +++ /dev/null @@ -1,88 +0,0 @@ - - * 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://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests - * @package cake - * @subpackage cake.tests.cases - * @since CakePHP(tm) v 2.0 - * @license MIT License (http://www.opensource.org/licenses/mit-license.php) - */ -App::import('Core', 'config/IniFile'); - -class IniFileTest extends CakeTestCase { - -/** - * The test file that will be read. - * - * @var string - */ - var $file; - -/** - * setup - * - * @return void - */ - function setup() { - parent::setup(); - $this->file = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS . 'acl.ini.php'; - } - -/** - * test constrction - * - * @return void - */ - function testConstruct() { - $config = new IniFile($this->file); - - $this->assertTrue(isset($config['admin'])); - $this->assertTrue(isset($config['paul']['groups'])); - $this->assertEquals('ads', $config['admin']['deny']); - } - -/** - * no other sections should exist. - * - * @return void - */ - function testReadingOnlyOneSection() { - $config = new IniFile($this->file, 'admin'); - - $this->assertTrue(isset($config['groups'])); - $this->assertEquals('administrators', $config['groups']); - } - -/** - * test getting all the values as an array - * - * @return void - */ - function testAsArray() { - $config = new IniFile($this->file); - $content = $config->asArray(); - - $this->assertTrue(isset($content['admin']['groups'])); - $this->assertTrue(isset($content['paul']['groups'])); - } - -/** - * test that values cannot be modified - * - * @expectedException LogicException - */ - function testNoModification() { - $config = new IniFile($this->file); - $config['admin'] = 'something'; - } -} \ No newline at end of file diff --git a/cake/tests/cases/libs/config/ini_reader.test.php b/cake/tests/cases/libs/config/ini_reader.test.php new file mode 100644 index 000000000..2fb8eb2dd --- /dev/null +++ b/cake/tests/cases/libs/config/ini_reader.test.php @@ -0,0 +1,101 @@ + + * 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://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests + * @package cake.tests.cases + * @since CakePHP(tm) v 2.0 + * @license MIT License (http://www.opensource.org/licenses/mit-license.php) + */ +App::import('Core', 'config/IniReader'); + +class IniReaderTest extends CakeTestCase { + +/** + * The test file that will be read. + * + * @var string + */ + var $file; + +/** + * setup + * + * @return void + */ + function setup() { + parent::setup(); + $this->path = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS; + } + +/** + * test constrction + * + * @return void + */ + function testConstruct() { + $reader = new IniReader($this->path); + $config = $reader->read('acl.ini.php'); + + $this->assertTrue(isset($config['admin'])); + $this->assertTrue(isset($config['paul']['groups'])); + $this->assertEquals('ads', $config['admin']['deny']); + } + +/** + * no other sections should exist. + * + * @return void + */ + function testReadingOnlyOneSection() { + $reader = new IniReader($this->path, 'admin'); + $config = $reader->read('acl.ini.php'); + + $this->assertTrue(isset($config['groups'])); + $this->assertEquals('administrators', $config['groups']); + } + +/** + * test that names with .'s get exploded into arrays. + * + * @return void + */ + function testReadingValuesWithDots() { + $reader = new IniReader($this->path); + $config = $reader->read('nested.ini'); + + $this->assertTrue(isset($config['database']['db']['username'])); + $this->assertEquals('mark', $config['database']['db']['username']); + $this->assertEquals(3, $config['nesting']['one']['two']['three']); + } + +/** + * test boolean reading + * + * @return void + */ + function testBooleanReading() { + $reader = new IniReader($this->path); + $config = $reader->read('nested.ini'); + + $this->assertTrue($config['bools']['test_on']); + $this->assertFalse($config['bools']['test_off']); + + $this->assertTrue($config['bools']['test_yes']); + $this->assertFalse($config['bools']['test_no']); + + $this->assertTrue($config['bools']['test_true']); + $this->assertFalse($config['bools']['test_false']); + + $this->assertFalse($config['bools']['test_null']); + } +} \ No newline at end of file diff --git a/cake/tests/cases/libs/config/php_reader.test.php b/cake/tests/cases/libs/config/php_reader.test.php new file mode 100644 index 000000000..63957ea62 --- /dev/null +++ b/cake/tests/cases/libs/config/php_reader.test.php @@ -0,0 +1,90 @@ + + * 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://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests + * @package cake.tests.cases + * @since CakePHP(tm) v 2.0 + * @license MIT License (http://www.opensource.org/licenses/mit-license.php) + */ +App::import('Core', 'config/PhpReader'); + +class PhpReaderTest extends CakeTestCase { +/** + * setup + * + * @return void + */ + function setUp() { + parent::setUp(); + $this->path = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS; + } +/** + * test reading files + * + * @return void + */ + function testRead() { + $reader = new PhpReader($this->path); + $values = $reader->read('var_test'); + $this->assertEquals('value', $values['Read']); + $this->assertEquals('buried', $values['Deep']['Deeper']['Deepest']); + } + +/** + * Test an exception is thrown by reading files that don't exist. + * + * @expectedException ConfigureException + * @return void + */ + function testReadWithNonExistantFile() { + $reader = new PhpReader($this->path); + $reader->read('fake_values'); + } + +/** + * test reading an empty file. + * + * @expectedException RuntimeException + * @return void + */ + function testReadEmptyFile() { + $reader = new PhpReader($this->path); + $reader->read('empty'); + } + +/** + * test reading keys with ../ doesn't work + * + * @expectedException ConfigureException + * @return void + */ + function testReadWithDots() { + $reader = new PhpReader($this->path); + $reader->read('../empty'); + } + +/** + * test reading from plugins + * + * @return void + */ + function testReadPluginValue() { + App::build(array( + 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS) + ), true); + $reader = new PhpReader($this->path); + $result = $reader->read('TestPlugin.load'); + + $this->assertTrue(isset($result['plugin_load'])); + } +} diff --git a/cake/tests/cases/libs/configure.test.php b/cake/tests/cases/libs/configure.test.php index a99790291..e58874e21 100644 --- a/cake/tests/cases/libs/configure.test.php +++ b/cake/tests/cases/libs/configure.test.php @@ -14,17 +14,16 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.5432 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +App::import('Core', 'config/PhpReader'); /** * ConfigureTest * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class ConfigureTest extends CakeTestCase { @@ -70,6 +69,7 @@ class ConfigureTest extends CakeTestCase { } Configure::write('debug', $this->_debug); Configure::write('Cache.disable', $this->_cacheDisable); + Configure::drop('test'); } /** @@ -184,18 +184,26 @@ class ConfigureTest extends CakeTestCase { /** * testLoad method * - * @access public + * @expectedException RuntimeException + * @return void + */ + function testLoadExceptionOnNonExistantFile() { + Configure::config('test', new PhpReader()); + $result = Configure::load('non_existing_configuration_file', 'test'); + } + +/** + * test load + * * @return void */ function testLoad() { - $result = Configure::load('non_existing_configuration_file'); - $this->assertFalse($result); + Configure::config('test', new PhpReader(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config' . DS)); - $result = Configure::load('config'); + $result = Configure::load('var_test', 'test'); $this->assertTrue($result); - - $result = Configure::load('../../index'); - $this->assertFalse($result); + + $this->assertEquals('value', Configure::read('Read')); } /** @@ -206,13 +214,15 @@ class ConfigureTest extends CakeTestCase { */ function testLoadPlugin() { App::build(array('plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)), true); - $result = Configure::load('test_plugin.load'); + Configure::config('test', new PhpReader()); + + $result = Configure::load('test_plugin.load', 'test'); $this->assertTrue($result); $expected = '/test_app/plugins/test_plugin/config/load.php'; $config = Configure::read('plugin_load'); $this->assertEqual($config, $expected); - $result = Configure::load('test_plugin.more.load'); + $result = Configure::load('test_plugin.more.load', 'test'); $this->assertTrue($result); $expected = '/test_app/plugins/test_plugin/config/more.load.php'; $config = Configure::read('plugin_more_load'); @@ -225,25 +235,39 @@ class ConfigureTest extends CakeTestCase { * @access public * @return void */ - function testStoreAndLoad() { + function testStoreAndRestore() { Configure::write('Cache.disable', false); - $expected = array('data' => 'value with backslash \, \'singlequote\' and "doublequotes"'); - Configure::store('SomeExample', 'test', $expected); + Configure::write('Testing', 'yummy'); + $this->assertTrue(Configure::store('store_test', 'default')); - Configure::load('test'); - $config = Configure::read('SomeExample'); - $this->assertEqual($config, $expected); + Configure::delete('Testing'); + $this->assertNull(Configure::read('Testing')); - $expected = array( - 'data' => array('first' => 'value with backslash \, \'singlequote\' and "doublequotes"', 'second' => 'value2'), - 'data2' => 'value' - ); - Configure::store('AnotherExample', 'test_config', $expected); + Configure::restore('store_test', 'default'); + $this->assertEquals('yummy', Configure::read('Testing')); - Configure::load('test_config'); - $config = Configure::read('AnotherExample'); - $this->assertEqual($config, $expected); + Cache::delete('store_test', 'default'); + } + +/** + * test that store and restore only store/restore the provided data. + * + * @return void + */ + function testStoreAndRestoreWithData() { + Configure::write('Cache.disable', false); + + Configure::write('testing', 'value'); + Configure::store('store_test', 'default', array('store_test' => 'one')); + Configure::delete('testing'); + $this->assertNull(Configure::read('store_test'), 'Calling store with data shouldnt modify runtime.'); + + Configure::restore('store_test', 'default'); + $this->assertEquals('one', Configure::read('store_test')); + $this->assertNull(Configure::read('testing'), 'Values that were not stored are not restored.'); + + Cache::delete('store_test', 'default'); } /** @@ -256,5 +280,35 @@ class ConfigureTest extends CakeTestCase { $result = Configure::version(); $this->assertTrue(version_compare($result, '1.2', '>=')); } + +/** + * test adding new readers. + * + * @return void + */ + function testReaderSetup() { + $reader = new PhpReader(); + Configure::config('test', $reader); + $configured = Configure::configured(); + + $this->assertTrue(in_array('test', $configured)); + + $this->assertTrue(Configure::configured('test')); + $this->assertFalse(Configure::configured('fake_garbage')); + + $this->assertTrue(Configure::drop('test')); + $this->assertFalse(Configure::drop('test'), 'dropping things that do not exist should return false.'); + } + +/** + * test reader() throwing exceptions on missing interface. + * + * @expectedException Exception + * @return void + */ + function testReaderExceptionOnIncorrectClass() { + $reader = new StdClass(); + Configure::config('test', $reader); + } } diff --git a/cake/tests/cases/libs/controller/component.test.php b/cake/tests/cases/libs/controller/component.test.php index 923e86868..eb01dae61 100644 --- a/cake/tests/cases/libs/controller/component.test.php +++ b/cake/tests/cases/libs/controller/component.test.php @@ -12,65 +12,17 @@ * * @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.controller + * @package cake.tests.cases.libs.controller * @since CakePHP(tm) v 1.2.0.5436 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ App::import('Controller', 'Controller', false); App::import('Controller', 'Component', false); -if (!class_exists('AppController')) { - -/** - * AppController class - * - * @package cake - * @subpackage cake.tests.cases.libs.controller - */ - class AppController extends Controller { - -/** - * name property - * - * @var string 'App' - * @access public - */ - public $name = 'App'; - -/** - * uses property - * - * @var array - * @access public - */ - public $uses = array(); - -/** - * helpers property - * - * @var array - * @access public - */ - public $helpers = array(); - -/** - * components property - * - * @var array - * @access public - */ - public $components = array('Orange' => array('colour' => 'blood orange')); - } -} elseif (!defined('APP_CONTROLLER_EXISTS')){ - define('APP_CONTROLLER_EXISTS', true); -} - /** * ParamTestComponent * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class ParamTestComponent extends Component { @@ -98,7 +50,7 @@ class ParamTestComponent extends Component { * @access public * @return void */ - function initialize(&$controller, $settings) { + function initialize($controllerz) { foreach ($settings as $key => $value) { if (is_numeric($key)) { $this->{$value} = true; @@ -112,10 +64,9 @@ class ParamTestComponent extends Component { /** * ComponentTestController class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ -class ComponentTestController extends AppController { +class ComponentTestController extends Controller { /** * name property @@ -132,13 +83,13 @@ class ComponentTestController extends AppController { * @access public */ public $uses = array(); + } /** * AppleComponent class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class AppleComponent extends Component { @@ -165,7 +116,7 @@ class AppleComponent extends Component { * @access public * @return void */ - function startup(&$controller) { + function startup($controller) { $this->testName = $controller->name; } } @@ -173,8 +124,7 @@ class AppleComponent extends Component { /** * OrangeComponent class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class OrangeComponent extends Component { @@ -193,7 +143,7 @@ class OrangeComponent extends Component { * @access public * @return void */ - function initialize(&$controller) { + function initialize($controller) { $this->Controller = $controller; $this->Banana->testField = 'OrangeField'; } @@ -204,7 +154,7 @@ class OrangeComponent extends Component { * @param Controller $controller * @return string */ - public function startup(&$controller) { + public function startup($controller) { $controller->foo = 'pass'; } } @@ -212,8 +162,7 @@ class OrangeComponent extends Component { /** * BananaComponent class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class BananaComponent extends Component { @@ -231,7 +180,7 @@ class BananaComponent extends Component { * @param Controller $controller * @return string */ - public function startup(&$controller) { + public function startup($controller) { $controller->bar = 'fail'; } } @@ -239,8 +188,7 @@ class BananaComponent extends Component { /** * MutuallyReferencingOneComponent class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class MutuallyReferencingOneComponent extends Component { @@ -256,8 +204,7 @@ class MutuallyReferencingOneComponent extends Component { /** * MutuallyReferencingTwoComponent class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class MutuallyReferencingTwoComponent extends Component { @@ -273,8 +220,7 @@ class MutuallyReferencingTwoComponent extends Component { /** * SomethingWithEmailComponent class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class SomethingWithEmailComponent extends Component { @@ -291,8 +237,7 @@ class SomethingWithEmailComponent extends Component { /** * ComponentTest class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class ComponentTest extends CakeTestCase { @@ -329,7 +274,7 @@ class ComponentTest extends CakeTestCase { $Collection = new ComponentCollection(); $Component = new AppleComponent($Collection); - $this->assertType('OrangeComponent', $Component->Orange, 'class is wrong'); + $this->assertInstanceOf('OrangeComponent', $Component->Orange, 'class is wrong'); } /** @@ -341,8 +286,8 @@ class ComponentTest extends CakeTestCase { $Collection = new ComponentCollection(); $Apple = new AppleComponent($Collection); - $this->assertType('OrangeComponent', $Apple->Orange, 'class is wrong'); - $this->assertType('BananaComponent', $Apple->Orange->Banana, 'class is wrong'); + $this->assertInstanceOf('OrangeComponent', $Apple->Orange, 'class is wrong'); + $this->assertInstanceOf('BananaComponent', $Apple->Orange->Banana, 'class is wrong'); $this->assertTrue(empty($Apple->Session)); $this->assertTrue(empty($Apple->Orange->Session)); } @@ -356,7 +301,7 @@ class ComponentTest extends CakeTestCase { $Collection = new ComponentCollection(); $Apple = $Collection->load('Apple'); - $this->assertType('OrangeComponent', $Apple->Orange, 'class is wrong'); + $this->assertInstanceOf('OrangeComponent', $Apple->Orange, 'class is wrong'); $result = $Collection->enabled(); $this->assertEquals(array('Apple'), $result, 'Too many components enabled.'); } @@ -391,27 +336,9 @@ class ComponentTest extends CakeTestCase { $Controller->beforeFilter(); $Controller->Components->trigger('startup', array(&$Controller)); - $this->assertType('SomethingWithEmailComponent', $Controller->SomethingWithEmail); - $this->assertType('EmailComponent', $Controller->SomethingWithEmail->Email); - $this->assertType('ComponentTestController', $Controller->SomethingWithEmail->Email->Controller); - } - -/** - * Test that SessionComponent doesn't get added if its already in the components array. - * - * @return void - */ - public function testDoubleLoadingOfSessionComponent() { - if ($this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController')) { - return; - } - - $Controller = new ComponentTestController(); - $Controller->uses = false; - $Controller->components = array('Session'); - $Controller->constructClasses(); - - $this->assertEqual($Controller->components, array('Session' => '', 'Orange' => array('colour' => 'blood orange'))); + $this->assertInstanceOf('SomethingWithEmailComponent', $Controller->SomethingWithEmail); + $this->assertInstanceOf('EmailComponent', $Controller->SomethingWithEmail->Email); + $this->assertInstanceOf('ComponentTestController', $Controller->SomethingWithEmail->Email->Controller); } } diff --git a/cake/tests/cases/libs/controller/component_collection.test.php b/cake/tests/cases/libs/controller/component_collection.test.php index d41f74095..3d84142d2 100644 --- a/cake/tests/cases/libs/controller/component_collection.test.php +++ b/cake/tests/cases/libs/controller/component_collection.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -47,8 +46,8 @@ class ComponentCollectionTest extends CakeTestCase { */ function testLoad() { $result = $this->Components->load('Cookie'); - $this->assertType('CookieComponent', $result); - $this->assertType('CookieComponent', $this->Components->Cookie); + $this->assertInstanceOf('CookieComponent', $result); + $this->assertInstanceOf('CookieComponent', $this->Components->Cookie); $result = $this->Components->attached(); $this->assertEquals(array('Cookie'), $result, 'attached() results are wrong.'); @@ -66,8 +65,8 @@ class ComponentCollectionTest extends CakeTestCase { */ function testLoadWithEnableFalse() { $result = $this->Components->load('Cookie', array('enabled' => false)); - $this->assertType('CookieComponent', $result); - $this->assertType('CookieComponent', $this->Components->Cookie); + $this->assertInstanceOf('CookieComponent', $result); + $this->assertInstanceOf('CookieComponent', $this->Components->Cookie); $this->assertFalse($this->Components->enabled('Cookie'), 'Cookie should be disabled'); } @@ -91,8 +90,8 @@ class ComponentCollectionTest extends CakeTestCase { 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS), )); $result = $this->Components->load('TestPlugin.OtherComponent'); - $this->assertType('OtherComponentComponent', $result, 'Component class is wrong.'); - $this->assertType('OtherComponentComponent', $this->Components->OtherComponent, 'Class is wrong'); + $this->assertInstanceOf('OtherComponentComponent', $result, 'Component class is wrong.'); + $this->assertInstanceOf('OtherComponentComponent', $this->Components->OtherComponent, 'Class is wrong'); App::build(); } @@ -119,162 +118,6 @@ class ComponentCollectionTest extends CakeTestCase { $this->assertEquals(array('Security'), $result, 'enabled components is wrong'); } -/** - * creates mock classes for testing - * - * @return void - */ - protected function _makeMockClasses() { - if (!class_exists('TriggerMockCookieComponent')) { - $this->getMock('CookieComponent', array(), array(), 'TriggerMockCookieComponent', false); - $this->getMock('SecurityComponent', array(), array(), 'TriggerMockSecurityComponent', false); - } - } - -/** - * test triggering callbacks. - * - * @return void - */ - function testTrigger() { - $controller = null; - $this->_makeMockClasses(); - $this->Components->load('TriggerMockCookie'); - $this->Components->load('TriggerMockSecurity'); - - $this->Components->TriggerMockCookie->expects($this->once())->method('startup') - ->with(null); - $this->Components->TriggerMockSecurity->expects($this->once())->method('startup') - ->with(null); - - $this->mockObjects[] = $this->Components->TriggerMockCookie; - $this->mockObjects[] = $this->Components->TriggerMockSecurity; - - $this->assertTrue($this->Components->trigger('startup', array(&$controller))); - } - -/** - * test that the initalize callback is triggered on all components even those that are disabled. - * - * @return void - */ - function testTriggerWithTriggerDisabledObjects() { - $controller = 'Not a controller'; - - $this->_makeMockClasses(); - $this->Components->load('TriggerMockCookie', array(), false); - $this->Components->load('TriggerMockSecurity'); - - $this->Components->TriggerMockCookie->expects($this->once())->method('initialize') - ->with($controller); - $this->Components->TriggerMockSecurity->expects($this->once())->method('initialize') - ->with($controller); - - $this->mockObjects[] = $this->Components->TriggerMockCookie; - $this->mockObjects[] = $this->Components->TriggerMockSecurity; - - $result = $this->Components->trigger('initialize', array(&$controller), array('triggerDisabled' => true)); - $this->assertTrue($result); - } - -/** - * test trigger and disabled helpers. - * - * @return void - */ - function testTriggerWithDisabledComponents() { - $controller = null; - $this->_makeMockClasses(); - $this->Components->load('TriggerMockCookie'); - $this->Components->load('TriggerMockSecurity'); - - $this->Components->TriggerMockCookie->expects($this->once())->method('startup') - ->with($controller); - $this->Components->TriggerMockSecurity->expects($this->never())->method('startup'); - - $this->mockObjects[] = $this->Components->TriggerMockCookie; - $this->mockObjects[] = $this->Components->TriggerMockSecurity; - - $this->Components->disable('TriggerMockSecurity'); - - $this->assertTrue($this->Components->trigger('startup', array(&$controller))); - } - -/** - * test that the collectReturn option works. - * - * @return void - */ - function testTriggerWithCollectReturn() { - $controller = null; - $this->_makeMockClasses(); - $this->Components->load('TriggerMockCookie'); - $this->Components->load('TriggerMockSecurity'); - - $this->Components->TriggerMockCookie->expects($this->once())->method('startup') - ->will($this->returnValue(array('one', 'two'))); - $this->Components->TriggerMockSecurity->expects($this->once())->method('startup') - ->will($this->returnValue(array('three', 'four'))); - - $this->mockObjects[] = $this->Components->TriggerMockCookie; - $this->mockObjects[] = $this->Components->TriggerMockSecurity; - - $result = $this->Components->trigger('startup', array(&$controller), array('collectReturn' => true)); - $expected = array( - array('one', 'two'), - array('three', 'four') - ); - $this->assertEquals($expected, $result); - } - -/** - * test that trigger with break & breakOn works. - * - * @return void - */ - function testTriggerWithBreak() { - $controller = null; - $this->_makeMockClasses(); - $this->Components->load('TriggerMockCookie'); - $this->Components->load('TriggerMockSecurity'); - - $this->Components->TriggerMockCookie->expects($this->once())->method('startup') - ->will($this->returnValue(false)); - $this->Components->TriggerMockSecurity->expects($this->never())->method('startup'); - - $this->mockObjects[] = $this->Components->TriggerMockCookie; - $this->mockObjects[] = $this->Components->TriggerMockSecurity; - - $result = $this->Components->trigger( - 'startup', - array(&$controller), - array('break' => true, 'breakOn' => false) - ); - $this->assertFalse($result); - } - -/** - * test normalizeObjectArray - * - * @return void - */ - function testnormalizeObjectArray() { - $components = array( - 'Html', - 'Foo.Bar' => array('one', 'two'), - 'Something', - 'Banana.Apple' => array('foo' => 'bar') - ); - $result = ComponentCollection::normalizeObjectArray($components); - $expected = array( - 'Html' => array('class' => 'Html', 'settings' => array()), - 'Bar' => array('class' => 'Foo.Bar', 'settings' => array('one', 'two')), - 'Something' => array('class' => 'Something', 'settings' => array()), - 'Apple' => array('class' => 'Banana.Apple', 'settings' => array('foo' => 'bar')), - ); - $this->assertEquals($expected, $result); - } - /** * test getting the controller out of the collection * diff --git a/cake/tests/cases/libs/controller/components/acl.test.php b/cake/tests/cases/libs/controller/components/acl.test.php index 600b69069..4e10cce48 100644 --- a/cake/tests/cases/libs/controller/components/acl.test.php +++ b/cake/tests/cases/libs/controller/components/acl.test.php @@ -12,8 +12,7 @@ * * @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.controller.components + * @package cake.tests.cases.libs.controller.components * @since CakePHP(tm) v 1.2.0.5435 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ App::import('model' . DS . 'db_acl'); /** * AclNodeTwoTestBase class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class AclNodeTwoTestBase extends AclNode { @@ -48,8 +46,7 @@ class AclNodeTwoTestBase extends AclNode { /** * AroTwoTest class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class AroTwoTest extends AclNodeTwoTestBase { @@ -81,8 +78,7 @@ class AroTwoTest extends AclNodeTwoTestBase { /** * AcoTwoTest class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class AcoTwoTest extends AclNodeTwoTestBase { @@ -114,8 +110,7 @@ class AcoTwoTest extends AclNodeTwoTestBase { /** * PermissionTwoTest class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class PermissionTwoTest extends CakeTestModel { @@ -163,8 +158,7 @@ class PermissionTwoTest extends CakeTestModel { /** * DbAclTwoTest class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class DbAclTwoTest extends DbAcl { @@ -185,8 +179,7 @@ class DbAclTwoTest extends DbAcl { /** * Short description for class. * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class AclComponentTest extends CakeTestCase { /** @@ -218,7 +211,7 @@ class AclComponentTest extends CakeTestCase { * test that construtor throws an exception when Acl.classname is a * non-existant class * - * @expectedException Exception + * @expectedException CakeException * @return void */ function testConstrutorException() { @@ -243,7 +236,7 @@ class AclComponentTest extends CakeTestCase { /** * test that adapter() whines when the class is not an AclBase * - * @expectedException Exception + * @expectedException CakeException * @return void */ function testAdapterException() { diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index 98f389efd..371edd2ed 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -12,8 +12,7 @@ * * @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.cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components * @since CakePHP(tm) v 1.2.0.5347 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -26,7 +25,7 @@ App::import('Core', 'Xml'); * TestAuthComponent class * * @package cake -* @subpackage cake.tests.cases.libs.controller.components +* @package cake.tests.cases.libs.controller.components */ class TestAuthComponent extends AuthComponent { @@ -52,7 +51,7 @@ class TestAuthComponent extends AuthComponent { * @access public * @return void */ - function _stop() { + function _stop($status = 0) { $this->testStop = true; } } @@ -61,7 +60,7 @@ class TestAuthComponent extends AuthComponent { * AuthUser class * * @package cake -* @subpackage cake.tests.cases.libs.controller.components +* @package cake.tests.cases.libs.controller.components */ class AuthUser extends CakeTestModel { @@ -122,8 +121,7 @@ class AuthUser extends CakeTestModel { /** * AuthUserCustomField class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class AuthUserCustomField extends AuthUser { @@ -140,7 +138,7 @@ class AuthUserCustomField extends AuthUser { * UuidUser class * * @package cake -* @subpackage cake.tests.cases.libs.controller.components +* @package cake.tests.cases.libs.controller.components */ class UuidUser extends CakeTestModel { @@ -210,7 +208,7 @@ class UuidUser extends CakeTestModel { * AuthTestController class * * @package cake -* @subpackage cake.tests.cases.libs.controller.components +* @package cake.tests.cases.libs.controller.components */ class AuthTestController extends Controller { @@ -364,8 +362,7 @@ class AuthTestController extends Controller { /** * AjaxAuthController class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class AjaxAuthController extends Controller { @@ -444,7 +441,7 @@ class AjaxAuthController extends Controller { * AuthTest class * * @package cake -* @subpackage cake.tests.cases.libs.controller.components +* @package cake.tests.cases.libs.controller.components */ class AuthTest extends CakeTestCase { @@ -498,7 +495,8 @@ class AuthTest extends CakeTestCase { ); $this->Controller->beforeFilter(); - ClassRegistry::addObject('view', new View($this->Controller)); + $view = new View($this->Controller); + ClassRegistry::addObject('view', $view); $this->Controller->Session->delete('Auth'); $this->Controller->Session->delete('Message.auth'); diff --git a/cake/tests/cases/libs/controller/components/cookie.test.php b/cake/tests/cases/libs/controller/components/cookie.test.php index cd16ca19e..0dc3ccd38 100644 --- a/cake/tests/cases/libs/controller/components/cookie.test.php +++ b/cake/tests/cases/libs/controller/components/cookie.test.php @@ -12,8 +12,7 @@ * * @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.controller.components + * @package cake.tests.cases.libs.controller.components * @since CakePHP(tm) v 1.2.0.5435 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ App::import('Component', 'Cookie'); /** * CookieComponentTestController class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class CookieComponentTestController extends Controller { @@ -55,8 +53,7 @@ class CookieComponentTestController extends Controller { /** * CookieComponentTest class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class CookieComponentTest extends CakeTestCase { @@ -383,7 +380,7 @@ class CookieComponentTest extends CakeTestCase { 'name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' => 'CakePHP Rocks!')); - $this->Cookie->startup(); + $this->Cookie->startup(null); $data = $this->Cookie->read('Encrytped_array'); $expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!'); @@ -458,6 +455,19 @@ class CookieComponentTest extends CakeTestCase { unset($_COOKIE['CakeTestCookie']); } + +/** + * test that no error is issued for non array data. + * + * @return void + */ + function testNoErrorOnNonArrayData() { + $this->Cookie->destroy(); + $_COOKIE['CakeTestCookie'] = 'kaboom'; + + $this->assertNull($this->Cookie->read('value')); + } + /** * encrypt method * diff --git a/cake/tests/cases/libs/controller/components/email.test.php b/cake/tests/cases/libs/controller/components/email.test.php index f8fd2e4a5..411a93c09 100755 --- a/cake/tests/cases/libs/controller/components/email.test.php +++ b/cake/tests/cases/libs/controller/components/email.test.php @@ -14,8 +14,7 @@ * * @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.cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components * @since CakePHP(tm) v 1.2.0.5347 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -26,8 +25,7 @@ App::import('Core', 'CakeSocket'); /** * EmailTestComponent class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class EmailTestComponent extends EmailComponent { @@ -153,8 +151,7 @@ class EmailTestComponent extends EmailComponent { /** * EmailTestController class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class EmailTestController extends Controller { @@ -194,8 +191,7 @@ class EmailTestController extends Controller { /** * EmailTest class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class EmailComponentTest extends CakeTestCase { @@ -230,7 +226,8 @@ class EmailComponentTest extends CakeTestCase { $this->Controller->Components->init($this->Controller); $this->Controller->EmailTest->initialize($this->Controller, array()); - ClassRegistry::addObject('view', new View($this->Controller)); + $view = new View($this->Controller); + ClassRegistry::addObject('view', $view); App::build(array( 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) @@ -268,7 +265,7 @@ class EmailComponentTest extends CakeTestCase { * @return void */ function testSmtpConfig() { - if ($this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost')) { + if ($this->skipIf(!@fsockopen('localhost', 25, $err, $errstr, .01), '%s No SMTP server running on localhost')) { return; } $this->Controller->EmailTest->delivery = 'smtp'; @@ -295,7 +292,7 @@ class EmailComponentTest extends CakeTestCase { * @return void */ function testBadSmtpSend() { - if ($this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost')) { + if ($this->skipIf(!@fsockopen('localhost', 25, $err, $errstr, .01), '%s No SMTP server running on localhost')) { return; } $this->Controller->EmailTest->smtpOptions['host'] = 'blah'; @@ -310,7 +307,7 @@ class EmailComponentTest extends CakeTestCase { * @return void */ function testSmtpSend() { - if ($this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost')) { + if ($this->skipIf(!@fsockopen('localhost', 25, $err, $errstr, .01), '%s No SMTP server running on localhost')) { return; } @@ -359,7 +356,7 @@ TEMPDOC; * @return void */ function testSmtpEhlo() { - if ($this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost')) { + if ($this->skipIf(!@fsockopen('localhost', 25, $err, $errstr, .01), '%s No SMTP server running on localhost')) { return; } @@ -416,7 +413,7 @@ TEMPDOC; * @return void */ function testSmtpSendMultipleTo() { - if ($this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost')) { + if ($this->skipIf(!@fsockopen('localhost', 25, $err, $errstr, .01), '%s No SMTP server running on localhost')) { return; } $this->Controller->EmailTest->reset(); @@ -465,7 +462,7 @@ TEMPDOC; * @return void */ function testAuthenticatedSmtpSend() { - if ($this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost')) { + if ($this->skipIf(!@fsockopen('localhost', 25, $err, $errstr, .01), '%s No SMTP server running on localhost')) { return; } @@ -501,6 +498,7 @@ TEMPDOC; $this->Controller->EmailTest->delivery = 'debug'; $this->Controller->EmailTest->messageId = false; + $date = date(DATE_RFC2822); $message = <<To: postmaster@localhost From: noreply@example.com @@ -509,6 +507,7 @@ Header: From: noreply@example.com Reply-To: noreply@example.com +Date: $date X-Mailer: CakePHP Email Component Content-Type: {CONTENTTYPE} Content-Transfer-Encoding: 7bitParameters: @@ -552,6 +551,7 @@ MSGBLOC; $this->Controller->EmailTest->delivery = 'debug'; $this->Controller->EmailTest->messageId = false; + $date = date(DATE_RFC2822); $header = <<'; $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message', 'default', 'thin')); $this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect)); + } - return; +/** + * test that elements used in email templates get helpers. + * + * @return void + */ + function testTemplateNestedElements() { + $this->Controller->EmailTest->to = 'postmaster@localhost'; + $this->Controller->EmailTest->from = 'noreply@example.com'; + $this->Controller->EmailTest->subject = 'Cake SMTP test'; + $this->Controller->EmailTest->replyTo = 'noreply@example.com'; - $text = <<Controller->EmailTest->delivery = 'debug'; + $this->Controller->EmailTest->messageId = false; + $this->Controller->EmailTest->layout = 'default'; + $this->Controller->EmailTest->template = 'nested_element'; + $this->Controller->EmailTest->sendAs = 'html'; + $this->Controller->helpers = array('Html'); -This element has some text that is just too wide to comply with email -standards. -This is the body of the message - -This email was sent using the CakePHP Framework, http://cakephp.org. -TEXTBLOC; - - $this->Controller->EmailTest->sendAs = 'text'; - $expect = '
    ' . str_replace('{CONTENTTYPE}', 'text/plain; charset=UTF-8', $header) . $text . "\n" . '
    '; - $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message', 'wide', 'default')); - $this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect)); + $this->Controller->EmailTest->send(); + $result = $this->Controller->Session->read('Message.email.message'); + $this->assertPattern('/Test/', $result); + $this->assertPattern('/http\:\/\/example\.com/', $result); } /** @@ -658,7 +667,7 @@ TEXTBLOC; * @return void */ function testSmtpSendSocket() { - if ($this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost')) { + if ($this->skipIf(!@fsockopen('localhost', 25, $err, $errstr, .01), '%s No SMTP server running on localhost')) { return; } @@ -697,6 +706,7 @@ TEXTBLOC; $this->assertPattern('/Subject: Cake Debug Test\n/', $result); $this->assertPattern('/Reply-To: noreply@example.com\n/', $result); $this->assertPattern('/From: noreply@example.com\n/', $result); + $this->assertPattern('/Date: ' . preg_quote(date(DATE_RFC2822)) . '\n/', $result); $this->assertPattern('/X-Mailer: CakePHP Email Component\n/', $result); $this->assertPattern('/Content-Type: text\/plain; charset=UTF-8\n/', $result); $this->assertPattern('/Content-Transfer-Encoding: 7bitParameters:\n/', $result); @@ -724,6 +734,7 @@ TEXTBLOC; $this->assertPattern('/Subject: Cake Debug Test\n/', $result); $this->assertPattern('/Reply-To: noreply@example.com\n/', $result); $this->assertPattern('/From: noreply@example.com\n/', $result); + $this->assertPattern('/Date: ' . preg_quote(date(DATE_RFC2822)) . '\n/', $result); $this->assertPattern('/X-Mailer: CakePHP Email Component\n/', $result); $this->assertPattern('/Content-Type: text\/plain; charset=UTF-8\n/', $result); $this->assertPattern('/Content-Transfer-Encoding: 7bitParameters:\n/', $result); @@ -857,7 +868,24 @@ HTMLBLOC; $this->assertPattern('/First line\n/', $result); $this->assertPattern('/Second line\n/', $result); $this->assertPattern('/Third line\n/', $result); + } +/** + * test setting a custom date. + * + * @return void + */ + function testDateProperty() { + $this->Controller->EmailTest->to = 'postmaster@localhost'; + $this->Controller->EmailTest->from = 'noreply@example.com'; + $this->Controller->EmailTest->subject = 'Cake Debug Test'; + $this->Controller->EmailTest->date = 'Today!'; + $this->Controller->EmailTest->template = null; + $this->Controller->EmailTest->delivery = 'debug'; + + $this->assertTrue($this->Controller->EmailTest->send('test message')); + $result = $this->Controller->Session->read('Message.email.message'); + $this->assertPattern('/Date: Today!\n/', $result); } /** @@ -1051,17 +1079,23 @@ HTMLBLOC; $this->Controller->EmailTest->return = 'test.return@example.com'; $this->Controller->EmailTest->cc = array('cc1@example.com', 'cc2@example.com'); $this->Controller->EmailTest->bcc = array('bcc1@example.com', 'bcc2@example.com'); + $this->Controller->EmailTest->date = 'Today!'; $this->Controller->EmailTest->subject = 'Test subject'; $this->Controller->EmailTest->additionalParams = 'X-additional-header'; $this->Controller->EmailTest->delivery = 'smtp'; $this->Controller->EmailTest->smtpOptions['host'] = 'blah'; - $this->Controller->EmailTest->smtpOptions['timeout'] = 0.5; + $this->Controller->EmailTest->smtpOptions['timeout'] = 0.2; $this->Controller->EmailTest->attachments = array('attachment1', 'attachment2'); $this->Controller->EmailTest->textMessage = 'This is the body of the message'; $this->Controller->EmailTest->htmlMessage = 'This is the body of the message'; $this->Controller->EmailTest->messageId = false; - $this->assertFalse($this->Controller->EmailTest->send('Should not work')); + try { + $this->Controller->EmailTest->send('Should not work'); + $this->fail('No exception'); + } catch (SocketException $e) { + $this->assertTrue(true, 'SocketException raised'); + } $this->Controller->EmailTest->reset(); @@ -1072,6 +1106,7 @@ HTMLBLOC; $this->assertNull($this->Controller->EmailTest->return); $this->assertIdentical($this->Controller->EmailTest->cc, array()); $this->assertIdentical($this->Controller->EmailTest->bcc, array()); + $this->assertNull($this->Controller->EmailTest->date); $this->assertNull($this->Controller->EmailTest->subject); $this->assertNull($this->Controller->EmailTest->additionalParams); $this->assertIdentical($this->Controller->EmailTest->getHeaders(), array()); @@ -1200,10 +1235,10 @@ HTMLBLOC; $result = $this->Controller->EmailTest->formatAddress('email@example.com', true); $this->assertEqual($result, ''); - + $result = $this->Controller->EmailTest->formatAddress('', true); $this->assertEqual($result, ''); - + $result = $this->Controller->EmailTest->formatAddress('alias name ', true); $this->assertEqual($result, ''); } diff --git a/cake/tests/cases/libs/controller/components/paginator.test.php b/cake/tests/cases/libs/controller/components/paginator.test.php new file mode 100644 index 000000000..cbaecb2b9 --- /dev/null +++ b/cake/tests/cases/libs/controller/components/paginator.test.php @@ -0,0 +1,764 @@ + + * 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://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests + * @package cake.tests.cases.libs.controller.components + * @since CakePHP(tm) v 2.0 + * @license MIT License (http://www.opensource.org/licenses/mit-license.php) + */ +App::import('Controller', 'Controller', false); +App::import('Component', 'Paginator'); +App::import('Core', array('CakeRequest', 'CakeResponse')); + +/** + * PaginatorTestController class + * + * @package cake.tests.cases.libs.controller.components + */ +class PaginatorTestController extends Controller { +/** + * name property + * + * @var string 'PaginatorTest' + * @access public + */ + public $name = 'PaginatorTest'; + +/** + * uses property + * + * @var array + * @access public + */ + //public $uses = null; + +/** + * components property + * + * @var array + * @access public + */ + public $components = array('Paginator'); +} + +/** + * PaginatorControllerPost class + * + * @package cake.tests.cases.libs.controller.components + */ +class PaginatorControllerPost extends CakeTestModel { + +/** + * name property + * + * @var string 'PaginatorControllerPost' + * @access public + */ + public $name = 'PaginatorControllerPost'; + +/** + * useTable property + * + * @var string 'posts' + * @access public + */ + public $useTable = 'posts'; + +/** + * invalidFields property + * + * @var array + * @access public + */ + public $invalidFields = array('name' => 'error_msg'); + +/** + * lastQuery property + * + * @var mixed null + * @access public + */ + public $lastQuery = null; + +/** + * beforeFind method + * + * @param mixed $query + * @access public + * @return void + */ + function beforeFind($query) { + $this->lastQuery = $query; + } + +/** + * find method + * + * @param mixed $type + * @param array $options + * @access public + * @return void + */ + function find($conditions = null, $fields = array(), $order = null, $recursive = null) { + if ($conditions == 'popular') { + $conditions = array($this->name . '.' . $this->primaryKey .' > ' => '1'); + $options = Set::merge($fields, compact('conditions')); + return parent::find('all', $options); + } + return parent::find($conditions, $fields); + } +} + +/** + * ControllerPaginateModel class + * + * @package cake.tests.cases.libs.controller.components + */ +class ControllerPaginateModel extends CakeTestModel { + +/** + * name property + * + * @var string 'ControllerPaginateModel' + * @access public + */ + public $name = 'ControllerPaginateModel'; + +/** + * useTable property + * + * @var string 'comments' + * @access public + */ + public $useTable = 'comments'; + +/** + * paginate method + * + * @return void + */ + public function paginate($conditions, $fields, $order, $limit, $page, $recursive, $extra) { + $this->extra = $extra; + } + +/** + * paginateCount + * + * @access public + * @return void + */ + function paginateCount($conditions, $recursive, $extra) { + $this->extraCount = $extra; + } +} + +/** + * PaginatorControllerCommentclass + * + * @package cake.tests.cases.libs.controller.components + */ +class PaginatorControllerComment extends CakeTestModel { + +/** + * name property + * + * @var string 'Comment' + * @access public + */ + public $name = 'Comment'; + +/** + * useTable property + * + * @var string 'comments' + * @access public + */ + public $useTable = 'comments'; + +/** + * alias property + * + * @var string 'PaginatorControllerComment' + * @access public + */ + public $alias = 'PaginatorControllerComment'; +} + +class PaginatorTest extends CakeTestCase { + +/** + * fixtures property + * + * @var array + * @access public + */ + public $fixtures = array('core.post', 'core.comment'); + +/** + * setup + * + * @return void + */ + function setUp() { + parent::setUp(); + $this->request = new CakeRequest('controller_posts/index'); + $this->request->params['pass'] = $this->request->params['named'] = array(); + $this->Controller = new Controller($this->request); + $this->Paginator = new PaginatorComponent($this->getMock('ComponentCollection'), array()); + $this->Paginator->Controller = $this->Controller; + $this->Controller->Post = $this->getMock('Model'); + $this->Controller->Post->alias = 'Post'; + } + +/** + * testPaginate method + * + * @access public + * @return void + */ + function testPaginate() { + $Controller = new PaginatorTestController($this->request); + $Controller->uses = array('PaginatorControllerPost', 'PaginatorControllerComment'); + $Controller->request->params['pass'] = array('1'); + $Controller->request->query = array(); + $Controller->constructClasses(); + + $results = Set::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id'); + $this->assertEqual($results, array(1, 2, 3)); + + $results = Set::extract($Controller->Paginator->paginate('PaginatorControllerComment'), '{n}.PaginatorControllerComment.id'); + $this->assertEqual($results, array(1, 2, 3, 4, 5, 6)); + + $Controller->modelClass = null; + + $Controller->uses[0] = 'Plugin.PaginatorControllerPost'; + $results = Set::extract($Controller->Paginator->paginate(), '{n}.PaginatorControllerPost.id'); + $this->assertEqual($results, array(1, 2, 3)); + + $Controller->request->params['named'] = array('page' => '-1'); + $results = Set::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id'); + $this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['page'], 1); + $this->assertEqual($results, array(1, 2, 3)); + + $Controller->request->params['named'] = array('sort' => 'PaginatorControllerPost.id', 'direction' => 'asc'); + $results = Set::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id'); + $this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['page'], 1); + $this->assertEqual($results, array(1, 2, 3)); + + $Controller->request->params['named'] = array('sort' => 'PaginatorControllerPost.id', 'direction' => 'desc'); + $results = Set::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id'); + $this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['page'], 1); + $this->assertEqual($results, array(3, 2, 1)); + + $Controller->request->params['named'] = array('sort' => 'id', 'direction' => 'desc'); + $results = Set::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id'); + $this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['page'], 1); + $this->assertEqual($results, array(3, 2, 1)); + + $Controller->request->params['named'] = array('sort' => 'NotExisting.field', 'direction' => 'desc'); + $results = Set::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id'); + $this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['page'], 1, 'Invalid field in query %s'); + $this->assertEqual($results, array(1, 2, 3)); + + $Controller->request->params['named'] = array( + 'sort' => 'PaginatorControllerPost.author_id', 'direction' => 'allYourBase' + ); + $results = Set::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id'); + $this->assertEqual($Controller->PaginatorControllerPost->lastQuery['order'][0], array('PaginatorControllerPost.author_id' => 'asc')); + $this->assertEqual($results, array(1, 3, 2)); + + $Controller->request->params['named'] = array(); + $Controller->Paginator->settings = array('limit' => 0, 'maxLimit' => 10, 'paramType' => 'named'); + $Controller->Paginator->paginate('PaginatorControllerPost'); + $this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['page'], 1); + $this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['pageCount'], 3); + $this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['prevPage'], false); + $this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['nextPage'], true); + + $Controller->request->params['named'] = array(); + $Controller->Paginator->settings = array('limit' => 'garbage!', 'maxLimit' => 10, 'paramType' => 'named'); + $Controller->Paginator->paginate('PaginatorControllerPost'); + $this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['page'], 1); + $this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['pageCount'], 3); + $this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['prevPage'], false); + $this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['nextPage'], true); + + $Controller->request->params['named'] = array(); + $Controller->Paginator->settings = array('limit' => '-1', 'maxLimit' => 10, 'paramType' => 'named'); + $Controller->Paginator->paginate('PaginatorControllerPost'); + + $this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['limit'], 1); + $this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['page'], 1); + $this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['pageCount'], 3); + $this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['prevPage'], false); + $this->assertIdentical($Controller->params['paging']['PaginatorControllerPost']['nextPage'], true); + } + +/** + * Test that non-numeric values are rejected for page, and limit + * + * @return void + */ + function testPageParamCasting() { + $this->Controller->Post->expects($this->at(0)) + ->method('hasMethod') + ->with('paginateCount') + ->will($this->returnValue(false)); + + $this->Controller->Post->expects($this->at(1)) + ->method('find') + ->will($this->returnValue(2)); + + $this->Controller->Post->expects($this->at(2)) + ->method('hasMethod') + ->with('paginate') + ->will($this->returnValue(false)); + + $this->Controller->Post->expects($this->at(3)) + ->method('find') + ->will($this->returnValue(array('stuff'))); + + $this->request->params['named'] = array('page' => '1 " onclick="alert(\'xss\');">'); + $this->Paginator->settings = array('limit' => 1, 'maxLimit' => 10, 'paramType' => 'named'); + $this->Paginator->paginate('Post'); + $this->assertSame(1, $this->request->params['paging']['Post']['page'], 'XSS exploit opened'); + } + +/** + * testPaginateExtraParams method + * + * @access public + * @return void + */ + function testPaginateExtraParams() { + $Controller = new PaginatorTestController($this->request); + + $Controller->uses = array('PaginatorControllerPost', 'PaginatorControllerComment'); + $Controller->request->params['pass'] = array('1'); + $Controller->params['url'] = array(); + $Controller->constructClasses(); + + $Controller->request->params['named'] = array('page' => '-1', 'contain' => array('PaginatorControllerComment')); + $result = $Controller->Paginator->paginate('PaginatorControllerPost'); + $this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['page'], 1); + $this->assertEqual(Set::extract($result, '{n}.PaginatorControllerPost.id'), array(1, 2, 3)); + $this->assertTrue(!isset($Controller->PaginatorControllerPost->lastQuery['contain'])); + + $Controller->request->params['named'] = array('page' => '-1'); + $Controller->Paginator->settings = array( + 'PaginatorControllerPost' => array( + 'contain' => array('PaginatorControllerComment'), + 'maxLimit' => 10, + 'paramType' => 'named' + ), + ); + $result = $Controller->Paginator->paginate('PaginatorControllerPost'); + $this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['page'], 1); + $this->assertEqual(Set::extract($result, '{n}.PaginatorControllerPost.id'), array(1, 2, 3)); + $this->assertTrue(isset($Controller->PaginatorControllerPost->lastQuery['contain'])); + + $Controller->Paginator->settings = array( + 'PaginatorControllerPost' => array( + 'popular', 'fields' => array('id', 'title'), 'maxLimit' => 10, 'paramType' => 'named' + ), + ); + $result = $Controller->Paginator->paginate('PaginatorControllerPost'); + $this->assertEqual(Set::extract($result, '{n}.PaginatorControllerPost.id'), array(2, 3)); + $this->assertEqual($Controller->PaginatorControllerPost->lastQuery['conditions'], array('PaginatorControllerPost.id > ' => '1')); + + $Controller->request->params['named'] = array('limit' => 12); + $Controller->Paginator->settings = array('limit' => 30, 'maxLimit' => 100, 'paramType' => 'named'); + $result = $Controller->Paginator->paginate('PaginatorControllerPost'); + $paging = $Controller->params['paging']['PaginatorControllerPost']; + + $this->assertEqual($Controller->PaginatorControllerPost->lastQuery['limit'], 12); + $this->assertEqual($paging['options']['limit'], 12); + + $Controller = new PaginatorTestController($this->request); + $Controller->uses = array('ControllerPaginateModel'); + $Controller->request->query = array(); + $Controller->constructClasses(); + $Controller->Paginator->settings = array( + 'ControllerPaginateModel' => array( + 'contain' => array('ControllerPaginateModel'), + 'group' => 'Comment.author_id', + 'maxLimit' => 10, + 'paramType' => 'named' + ) + ); + $result = $Controller->Paginator->paginate('ControllerPaginateModel'); + $expected = array( + 'contain' => array('ControllerPaginateModel'), + 'group' => 'Comment.author_id', + 'maxLimit' => 10, + 'paramType' => 'named' + ); + $this->assertEqual($Controller->ControllerPaginateModel->extra, $expected); + $this->assertEqual($Controller->ControllerPaginateModel->extraCount, $expected); + + $Controller->Paginator->settings = array( + 'ControllerPaginateModel' => array( + 'foo', 'contain' => array('ControllerPaginateModel'), + 'group' => 'Comment.author_id', + 'maxLimit' => 10, + 'paramType' => 'named' + ) + ); + $Controller->Paginator->paginate('ControllerPaginateModel'); + $expected = array( + 'contain' => array('ControllerPaginateModel'), + 'group' => 'Comment.author_id', + 'type' => 'foo', + 'maxLimit' => 10, + 'paramType' => 'named' + ); + $this->assertEqual($Controller->ControllerPaginateModel->extra, $expected); + $this->assertEqual($Controller->ControllerPaginateModel->extraCount, $expected); + } + +/** + * Test that special paginate types are called and that the type param doesn't leak out into defaults or options. + * + * @return void + */ + function testPaginateSpecialType() { + $Controller = new PaginatorTestController($this->request); + $Controller->uses = array('PaginatorControllerPost', 'PaginatorControllerComment'); + $Controller->passedArgs[] = '1'; + $Controller->params['url'] = array(); + $Controller->constructClasses(); + + $Controller->Paginator->settings = array( + 'PaginatorControllerPost' => array( + 'popular', + 'fields' => array('id', 'title'), + 'maxLimit' => 10, + 'paramType' => 'named' + ) + ); + $result = $Controller->Paginator->paginate('PaginatorControllerPost'); + + $this->assertEqual(Set::extract($result, '{n}.PaginatorControllerPost.id'), array(2, 3)); + $this->assertEqual( + $Controller->PaginatorControllerPost->lastQuery['conditions'], + array('PaginatorControllerPost.id > ' => '1') + ); + $this->assertFalse(isset($Controller->params['paging']['PaginatorControllerPost']['options'][0])); + } + +/** + * testDefaultPaginateParams method + * + * @access public + * @return void + */ + function testDefaultPaginateParams() { + $Controller = new PaginatorTestController($this->request); + $Controller->modelClass = 'PaginatorControllerPost'; + $Controller->params['url'] = array(); + $Controller->constructClasses(); + $Controller->Paginator->settings = array( + 'order' => 'PaginatorControllerPost.id DESC', + 'maxLimit' => 10, + 'paramType' => 'named' + ); + $results = Set::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id'); + $this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['order'], 'PaginatorControllerPost.id DESC'); + $this->assertEqual($results, array(3, 2, 1)); + } + +/** + * test paginate() and virtualField interactions + * + * @return void + */ + function testPaginateOrderVirtualField() { + $Controller = new PaginatorTestController($this->request); + $Controller->uses = array('PaginatorControllerPost', 'PaginatorControllerComment'); + $Controller->params['url'] = array(); + $Controller->constructClasses(); + $Controller->PaginatorControllerPost->virtualFields = array( + 'offset_test' => 'PaginatorControllerPost.id + 1' + ); + + $Controller->Paginator->settings = array( + 'fields' => array('id', 'title', 'offset_test'), + 'order' => array('offset_test' => 'DESC'), + 'maxLimit' => 10, + 'paramType' => 'named' + ); + $result = $Controller->Paginator->paginate('PaginatorControllerPost'); + $this->assertEqual(Set::extract($result, '{n}.PaginatorControllerPost.offset_test'), array(4, 3, 2)); + + $Controller->request->params['named'] = array('sort' => 'offset_test', 'direction' => 'asc'); + $result = $Controller->Paginator->paginate('PaginatorControllerPost'); + $this->assertEqual(Set::extract($result, '{n}.PaginatorControllerPost.offset_test'), array(2, 3, 4)); + } + +/** + * Tests for missing models + * + * @expectedException MissingModelException + */ + function testPaginateMissingModel() { + $Controller = new PaginatorTestController($this->request); + $Controller->constructClasses(); + $Controller->Paginator->paginate('MissingModel'); + } + +/** + * test that option merging prefers specific models + * + * @return void + */ + function testMergeOptionsModelSpecific() { + $this->Paginator->settings = array( + 'page' => 1, + 'limit' => 20, + 'maxLimit' => 100, + 'paramType' => 'named', + 'Post' => array( + 'page' => 1, + 'limit' => 10, + 'maxLimit' => 50, + 'paramType' => 'named', + ) + ); + $result = $this->Paginator->mergeOptions('Silly'); + $this->assertEquals($this->Paginator->settings, $result); + + $result = $this->Paginator->mergeOptions('Post'); + $expected = array('page' => 1, 'limit' => 10, 'paramType' => 'named', 'maxLimit' => 50); + $this->assertEquals($expected, $result); + } + +/** + * test mergeOptions with named params. + * + * @return void + */ + function testMergeOptionsNamedParams() { + $this->request->params['named'] = array( + 'page' => 10, + 'limit' => 10 + ); + $this->Paginator->settings = array( + 'page' => 1, + 'limit' => 20, + 'maxLimit' => 100, + 'paramType' => 'named', + ); + $result = $this->Paginator->mergeOptions('Post'); + $expected = array('page' => 10, 'limit' => 10, 'maxLimit' => 100, 'paramType' => 'named'); + $this->assertEquals($expected, $result); + } + +/** + * test merging options from the querystring. + * + * @return void + */ + function testMergeOptionsQueryString() { + $this->request->params['named'] = array( + 'page' => 10, + 'limit' => 10 + ); + $this->request->query = array( + 'page' => 99, + 'limit' => 75 + ); + $this->Paginator->settings = array( + 'page' => 1, + 'limit' => 20, + 'maxLimit' => 100, + 'paramType' => 'querystring', + ); + $result = $this->Paginator->mergeOptions('Post'); + $expected = array('page' => 99, 'limit' => 75, 'maxLimit' => 100, 'paramType' => 'querystring'); + $this->assertEquals($expected, $result); + } + +/** + * test that the default whitelist doesn't let people screw with things they should not be allowed to. + * + * @return void + */ + function testMergeOptionsDefaultWhiteList() { + $this->request->params['named'] = array( + 'page' => 10, + 'limit' => 10, + 'fields' => array('bad.stuff'), + 'recursive' => 1000, + 'conditions' => array('bad.stuff'), + 'contain' => array('bad') + ); + $this->Paginator->settings = array( + 'page' => 1, + 'limit' => 20, + 'maxLimit' => 100, + 'paramType' => 'named', + ); + $result = $this->Paginator->mergeOptions('Post'); + $expected = array('page' => 10, 'limit' => 10, 'maxLimit' => 100, 'paramType' => 'named'); + $this->assertEquals($expected, $result); + } + +/** + * test that modifying the whitelist works. + * + * @return void + */ + function testMergeOptionsExtraWhitelist() { + $this->request->params['named'] = array( + 'page' => 10, + 'limit' => 10, + 'fields' => array('bad.stuff'), + 'recursive' => 1000, + 'conditions' => array('bad.stuff'), + 'contain' => array('bad') + ); + $this->Paginator->settings = array( + 'page' => 1, + 'limit' => 20, + 'maxLimit' => 100, + 'paramType' => 'named', + ); + $this->Paginator->whitelist[] = 'fields'; + $result = $this->Paginator->mergeOptions('Post'); + $expected = array( + 'page' => 10, 'limit' => 10, 'maxLimit' => 100, 'paramType' => 'named', 'fields' => array('bad.stuff') + ); + $this->assertEquals($expected, $result); + } + +/** + * test that invalid directions are ignored. + * + * @return void + */ + function testValidateSortInvalidDirection() { + $model = $this->getMock('Model'); + $model->alias = 'model'; + $model->expects($this->any())->method('hasField')->will($this->returnValue(true)); + + $options = array('sort' => 'something', 'direction' => 'boogers'); + $result = $this->Paginator->validateSort($model, $options); + + $this->assertEquals('asc', $result['order']['model.something']); + } + +/** + * test that fields not in whitelist won't be part of order conditions. + * + * @return void + */ + function testValidateSortWhitelistFailure() { + $model = $this->getMock('Model'); + $model->alias = 'model'; + $model->expects($this->any())->method('hasField')->will($this->returnValue(true)); + + $options = array('sort' => 'body', 'direction' => 'asc'); + $result = $this->Paginator->validateSort($model, $options, array('title', 'id')); + + $this->assertNull($result['order']); + } + +/** + * test that virtual fields work. + * + * @return void + */ + function testValidateSortVirtualField() { + $model = $this->getMock('Model'); + $model->alias = 'model'; + + $model->expects($this->at(0)) + ->method('hasField') + ->with('something') + ->will($this->returnValue(false)); + + $model->expects($this->at(1)) + ->method('hasField') + ->with('something', true) + ->will($this->returnValue(true)); + + $options = array('sort' => 'something', 'direction' => 'desc'); + $result = $this->Paginator->validateSort($model, $options); + + $this->assertEquals('desc', $result['order']['something']); + } + +/** + * test that maxLimit is respected + * + * @return void + */ + function testCheckLimit() { + $result = $this->Paginator->checkLimit(array('limit' => 1000000, 'maxLimit' => 100)); + $this->assertEquals(100, $result['limit']); + + $result = $this->Paginator->checkLimit(array('limit' => 'sheep!', 'maxLimit' => 100)); + $this->assertEquals(1, $result['limit']); + + $result = $this->Paginator->checkLimit(array('limit' => '-1', 'maxLimit' => 100)); + $this->assertEquals(1, $result['limit']); + + $result = $this->Paginator->checkLimit(array('limit' => null, 'maxLimit' => 100)); + $this->assertEquals(1, $result['limit']); + + $result = $this->Paginator->checkLimit(array('limit' => 0, 'maxLimit' => 100)); + $this->assertEquals(1, $result['limit']); + } + +/** + * testPaginateMaxLimit + * + * @return void + * @access public + */ + function testPaginateMaxLimit() { + $Controller = new Controller($this->request); + + $Controller->uses = array('PaginatorControllerPost', 'ControllerComment'); + $Controller->passedArgs[] = '1'; + $Controller->params['url'] = array(); + $Controller->constructClasses(); + + $Controller->request->params['named'] = array( + 'contain' => array('ControllerComment'), 'limit' => '1000' + ); + $result = $Controller->paginate('PaginatorControllerPost'); + $this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 100); + + $Controller->request->params['named'] = array( + 'contain' => array('ControllerComment'), 'limit' => '1000', 'maxLimit' => 1000 + ); + $result = $Controller->paginate('PaginatorControllerPost'); + $this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 100); + + $Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '10'); + $result = $Controller->paginate('PaginatorControllerPost'); + $this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 10); + + $Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '1000'); + $Controller->paginate = array('maxLimit' => 2000, 'paramType' => 'named'); + $result = $Controller->paginate('PaginatorControllerPost'); + $this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 1000); + + $Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '5000'); + $result = $Controller->paginate('PaginatorControllerPost'); + $this->assertEqual($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 2000); + } +} \ No newline at end of file diff --git a/cake/tests/cases/libs/controller/components/request_handler.test.php b/cake/tests/cases/libs/controller/components/request_handler.test.php index a9fe81d81..3ce9ccc4e 100644 --- a/cake/tests/cases/libs/controller/components/request_handler.test.php +++ b/cake/tests/cases/libs/controller/components/request_handler.test.php @@ -12,8 +12,7 @@ * * @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.controller.components + * @package cake.tests.cases.libs.controller.components * @since CakePHP(tm) v 1.2.0.5435 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,8 +23,7 @@ App::import('Core', array('CakeRequest', 'CakeResponse')); /** * RequestHandlerTestController class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class RequestHandlerTestController extends Controller { @@ -80,8 +78,7 @@ class RequestHandlerTestController extends Controller { /** * RequestHandlerTestDisabledController class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class RequestHandlerTestDisabledController extends Controller { @@ -106,8 +103,7 @@ class RequestHandlerTestDisabledController extends Controller { /** * RequestHandlerComponentTest class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class RequestHandlerComponentTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/controller/components/security.test.php b/cake/tests/cases/libs/controller/components/security.test.php index 22274277a..cb7197392 100644 --- a/cake/tests/cases/libs/controller/components/security.test.php +++ b/cake/tests/cases/libs/controller/components/security.test.php @@ -12,8 +12,7 @@ * * @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.controller.components + * @package cake.tests.cases.libs.controller.components * @since CakePHP(tm) v 1.2.0.5435 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,7 +23,7 @@ App::import('Component', 'Security'); * TestSecurityComponent * * @package cake -* @subpackage cake.tests.cases.libs.controller.components +* @package cake.tests.cases.libs.controller.components */ class TestSecurityComponent extends SecurityComponent { @@ -34,7 +33,7 @@ class TestSecurityComponent extends SecurityComponent { * @param Controller $controller * @return unknown */ - function validatePost(&$controller) { + function validatePost($controller) { return $this->_validatePost($controller); } } @@ -43,7 +42,7 @@ class TestSecurityComponent extends SecurityComponent { * SecurityTestController * * @package cake -* @subpackage cake.tests.cases.libs.controller.components +* @package cake.tests.cases.libs.controller.components */ class SecurityTestController extends Controller { @@ -98,8 +97,8 @@ class SecurityTestController extends Controller { * @access public * @return void */ - function redirect($option, $code, $exit) { - return $code; + function redirect($url, $status = null, $exit = true) { + return $status; } /** @@ -116,8 +115,7 @@ class SecurityTestController extends Controller { /** * SecurityComponentTest class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class SecurityComponentTest extends CakeTestCase { @@ -578,9 +576,9 @@ DIGEST; */ function testValidatePost() { $this->Controller->Security->startup($this->Controller); + $key = $this->Controller->request->params['_Token']['key']; - $fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877%3An%3A1%3A%7Bv%3A0%3B'; - $fields .= 'f%3A11%3A%22Zbqry.inyvq%22%3B%7D'; + $fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877%3AModel.valid'; $this->Controller->request->data = array( 'Model' => array('username' => 'nate', 'password' => 'foo', 'valid' => '0'), @@ -597,8 +595,7 @@ DIGEST; function testValidatePostFormHacking() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->params['_Token']['key']; - $fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877%3An%3A1%3A%7Bv%3A0%3B'; - $fields .= 'f%3A11%3A%22Zbqry.inyvq%22%3B%7D'; + $fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877%3AModel.valid'; $this->Controller->request->data = array( 'Model' => array('username' => 'nate', 'password' => 'foo', 'valid' => '0'), @@ -639,8 +636,9 @@ DIGEST; */ function testValidatePostArray() { $this->Controller->Security->startup($this->Controller); + $key = $this->Controller->request->params['_Token']['key']; - $fields = 'f7d573650a295b94e0938d32b323fde775e5f32b%3An%3A0%3A%7B%7D'; + $fields = 'f7d573650a295b94e0938d32b323fde775e5f32b%3A'; $this->Controller->request->data = array( 'Model' => array('multi_field' => array('1', '3')), @@ -657,8 +655,9 @@ DIGEST; */ function testValidatePostNoModel() { $this->Controller->Security->startup($this->Controller); + $key = $this->Controller->request->params['_Token']['key']; - $fields = '540ac9c60d323c22bafe997b72c0790f39a8bdef%3An%3A0%3A%7B%7D'; + $fields = '540ac9c60d323c22bafe997b72c0790f39a8bdef%3A'; $this->Controller->request->data = array( 'anything' => 'some_data', @@ -677,8 +676,9 @@ DIGEST; */ function testValidatePostSimple() { $this->Controller->Security->startup($this->Controller); + $key = $this->Controller->request->params['_Token']['key']; - $fields = '69f493434187b867ea14b901fdf58b55d27c935d%3An%3A0%3A%7B%7D'; + $fields = '69f493434187b867ea14b901fdf58b55d27c935d%3A'; $this->Controller->request->data = $data = array( 'Model' => array('username' => '', 'password' => ''), @@ -697,9 +697,9 @@ DIGEST; */ function testValidatePostComplex() { $this->Controller->Security->startup($this->Controller); + $key = $this->Controller->request->params['_Token']['key']; - $fields = 'c9118120e680a7201b543f562e5301006ccfcbe2%3An%3A2%3A%7Bv%3A0%3Bf%3A14%3A%'; - $fields .= '22Nqqerffrf.0.vq%22%3Bv%3A1%3Bf%3A14%3A%22Nqqerffrf.1.vq%22%3B%7D'; + $fields = 'c9118120e680a7201b543f562e5301006ccfcbe2%3AAddresses.0.id%7CAddresses.1.id'; $this->Controller->request->data = array( 'Addresses' => array( @@ -725,8 +725,9 @@ DIGEST; */ function testValidatePostMultipleSelect() { $this->Controller->Security->startup($this->Controller); + $key = $this->Controller->request->params['_Token']['key']; - $fields = '422cde416475abc171568be690a98cad20e66079%3An%3A0%3A%7B%7D'; + $fields = '422cde416475abc171568be690a98cad20e66079%3A'; $this->Controller->request->data = array( 'Tag' => array('Tag' => array(1, 2)), @@ -749,7 +750,7 @@ DIGEST; $result = $this->Controller->Security->validatePost($this->Controller); $this->assertTrue($result); - $fields = '19464422eafe977ee729c59222af07f983010c5f%3An%3A0%3A%7B%7D'; + $fields = '19464422eafe977ee729c59222af07f983010c5f%3A'; $this->Controller->request->data = array( 'User.password' => 'bar', 'User.name' => 'foo', 'User.is_valid' => '1', 'Tag' => array('Tag' => array(1)), '_Token' => compact('key', 'fields'), @@ -770,8 +771,7 @@ DIGEST; function testValidatePostCheckbox() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->request->params['_Token']['key']; - $fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877%3An%3A1%3A%7Bv%3A0%'; - $fields .= '3Bf%3A11%3A%22Zbqry.inyvq%22%3B%7D'; + $fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877%3AModel.valid'; $this->Controller->request->data = array( 'Model' => array('username' => '', 'password' => '', 'valid' => '0'), @@ -781,7 +781,7 @@ DIGEST; $result = $this->Controller->Security->validatePost($this->Controller); $this->assertTrue($result); - $fields = '874439ca69f89b4c4a5f50fb9c36ff56a28f5d42%3An%3A0%3A%7B%7D'; + $fields = '874439ca69f89b4c4a5f50fb9c36ff56a28f5d42%3A'; $this->Controller->request->data = array( 'Model' => array('username' => '', 'password' => '', 'valid' => '0'), @@ -814,8 +814,8 @@ DIGEST; function testValidatePostHidden() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->request->params['_Token']['key']; - $fields = '51ccd8cb0997c7b3d4523ecde5a109318405ef8c%3An%3A2%3A%7Bv%3A0%3Bf%3A12%3A'; - $fields .= '%22Zbqry.uvqqra%22%3Bv%3A1%3Bf%3A18%3A%22Zbqry.bgure_uvqqra%22%3B%7D'; + $fields = '51ccd8cb0997c7b3d4523ecde5a109318405ef8c%3AModel.hidden%7CModel.other_hidden'; + $fields .= ''; $this->Controller->request->data = array( 'Model' => array( @@ -838,8 +838,7 @@ DIGEST; $this->Controller->Security->disabledFields = array('Model.username', 'Model.password'); $this->Controller->Security->startup($this->Controller); $key = $this->Controller->request->params['_Token']['key']; - $fields = 'ef1082968c449397bcd849f963636864383278b1%3An%3A1%3A%7Bv%'; - $fields .= '3A0%3Bf%3A12%3A%22Zbqry.uvqqra%22%3B%7D'; + $fields = 'ef1082968c449397bcd849f963636864383278b1%3AModel.hidden'; $this->Controller->request->data = array( 'Model' => array( @@ -861,9 +860,7 @@ DIGEST; function testValidateHiddenMultipleModel() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->request->params['_Token']['key']; - $fields = 'a2d01072dc4660eea9d15007025f35a7a5b58e18%3An%3A3%3A%7Bv%3A0%3Bf%3A11'; - $fields .= '%3A%22Zbqry.inyvq%22%3Bv%3A1%3Bf%3A12%3A%22Zbqry2.inyvq%22%3Bv%3A2%'; - $fields .= '3Bf%3A12%3A%22Zbqry3.inyvq%22%3B%7D'; + $fields = 'a2d01072dc4660eea9d15007025f35a7a5b58e18%3AModel.valid%7CModel2.valid%7CModel3.valid'; $this->Controller->request->data = array( 'Model' => array('username' => '', 'password' => '', 'valid' => '0'), @@ -884,9 +881,8 @@ DIGEST; function testValidateHasManyModel() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->request->params['_Token']['key']; - $fields = '51e3b55a6edd82020b3f29c9ae200e14bbeb7ee5%3An%3A4%3A%7Bv%3A0%3Bf%3A14%3A%2'; - $fields .= '2Zbqry.0.uvqqra%22%3Bv%3A1%3Bf%3A13%3A%22Zbqry.0.inyvq%22%3Bv%3A2%3Bf%3'; - $fields .= 'A14%3A%22Zbqry.1.uvqqra%22%3Bv%3A3%3Bf%3A13%3A%22Zbqry.1.inyvq%22%3B%7D'; + $fields = '51e3b55a6edd82020b3f29c9ae200e14bbeb7ee5%3AModel.0.hidden%7CModel.0.valid'; + $fields .= '%7CModel.1.hidden%7CModel.1.valid'; $this->Controller->request->data = array( 'Model' => array( @@ -915,9 +911,8 @@ DIGEST; function testValidateHasManyRecordsPass() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->request->params['_Token']['key']; - $fields = '7a203edb3d345bbf38fe0dccae960da8842e11d7%3An%3A4%3A%7Bv%3A0%3Bf%3A12%3A%2'; - $fields .= '2Nqqerff.0.vq%22%3Bv%3A1%3Bf%3A17%3A%22Nqqerff.0.cevznel%22%3Bv%3A2%3Bf%'; - $fields .= '3A12%3A%22Nqqerff.1.vq%22%3Bv%3A3%3Bf%3A17%3A%22Nqqerff.1.cevznel%22%3B%7D'; + $fields = '7a203edb3d345bbf38fe0dccae960da8842e11d7%3AAddress.0.id%7CAddress.0.primary%7C'; + $fields .= 'Address.1.id%7CAddress.1.primary'; $this->Controller->request->data = array( 'Address' => array( @@ -960,9 +955,8 @@ DIGEST; function testValidateHasManyRecordsFail() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->request->params['_Token']['key']; - $fields = '7a203edb3d345bbf38fe0dccae960da8842e11d7%3An%3A4%3A%7Bv%3A0%3Bf%3A12%3A%2'; - $fields .= '2Nqqerff.0.vq%22%3Bv%3A1%3Bf%3A17%3A%22Nqqerff.0.cevznel%22%3Bv%3A2%3Bf%'; - $fields .= '3A12%3A%22Nqqerff.1.vq%22%3Bv%3A3%3Bf%3A17%3A%22Nqqerff.1.cevznel%22%3B%7D'; + $fields = '7a203edb3d345bbf38fe0dccae960da8842e11d7%3AAddress.0.id%7CAddress.0.primary%7C'; + $fields .= 'Address.1.id%7CAddress.1.primary'; $this->Controller->request->data = array( 'Address' => array( diff --git a/cake/tests/cases/libs/controller/components/session.test.php b/cake/tests/cases/libs/controller/components/session.test.php index bf605f1df..938d8dd00 100644 --- a/cake/tests/cases/libs/controller/components/session.test.php +++ b/cake/tests/cases/libs/controller/components/session.test.php @@ -12,8 +12,7 @@ * * @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.controller.components + * @package cake.tests.cases.libs.controller.components * @since CakePHP(tm) v 1.2.0.5436 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ App::import('Component', 'Session'); /** * SessionTestController class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class SessionTestController extends Controller { @@ -49,8 +47,7 @@ class SessionTestController extends Controller { /** * OrangeSessionTestController class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class OrangeSessionTestController extends Controller { @@ -75,8 +72,7 @@ class OrangeSessionTestController extends Controller { /** * SessionComponentTest class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class SessionComponentTest extends CakeTestCase { @@ -143,6 +139,7 @@ class SessionComponentTest extends CakeTestCase { */ function testSessionIdConsistentAcrossRequestAction() { $Session = new SessionComponent($this->ComponentCollection); + $Session->check('Test'); $this->assertTrue(isset($_SESSION)); $Object = new Object(); @@ -287,6 +284,7 @@ class SessionComponentTest extends CakeTestCase { function testSessionId() { unset($_SESSION); $Session = new SessionComponent($this->ComponentCollection); + $Session->check('test'); $this->assertEquals(session_id(), $Session->id()); } diff --git a/cake/tests/cases/libs/controller/controller.test.php b/cake/tests/cases/libs/controller/controller.test.php index 02260dcb5..675fcb100 100644 --- a/cake/tests/cases/libs/controller/controller.test.php +++ b/cake/tests/cases/libs/controller/controller.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller * @since CakePHP(tm) v 1.2.0.5436 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,51 +21,41 @@ App::import('Core', array('CakeRequest', 'CakeResponse')); App::import('Component', 'Security'); App::import('Component', 'Cookie'); + /** * AppController class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ -if (!class_exists('AppController')) { - /** - * AppController class - * - * @package cake - * @subpackage cake.tests.cases.libs.controller - */ - class AppController extends Controller { - /** - * helpers property - * - * @var array - * @access public - */ - public $helpers = array('Html'); - /** - * uses property - * - * @var array - * @access public - */ - public $uses = array('ControllerPost'); - /** - * components property - * - * @var array - * @access public - */ - public $components = array('Cookie'); - } -} elseif (!defined('APP_CONTROLLER_EXISTS')) { - define('APP_CONTROLLER_EXISTS', true); +class ControllerTestAppController extends Controller { +/** + * helpers property + * + * @var array + * @access public + */ + public $helpers = array('Html'); +/** + * uses property + * + * @var array + * @access public + */ + public $uses = array('ControllerPost'); +/** + * components property + * + * @var array + * @access public + */ + public $components = array('Cookie'); } + /** * ControllerPost class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class ControllerPost extends CakeTestModel { @@ -121,23 +110,22 @@ class ControllerPost extends CakeTestModel { * @access public * @return void */ - function find($type, $options = array()) { - if ($type == 'popular') { + function find($conditions = null, $fields = array(), $order = null, $recursive = null) { + if ($conditions == 'popular') { $conditions = array($this->name . '.' . $this->primaryKey .' > ' => '1'); - $options = Set::merge($options, compact('conditions')); - return parent::find('all', $options); + $options = Set::merge($fields, compact('conditions')); + return parent::find('all', $fields); } - return parent::find($type, $options); + return parent::find($conditions, $fields); } } /** * ControllerPostsController class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ -class ControllerCommentsController extends AppController { +class ControllerCommentsController extends ControllerTestAppController { /** * name property @@ -146,13 +134,14 @@ class ControllerCommentsController extends AppController { * @access public */ public $name = 'ControllerComments'; + + protected $_mergeParent = 'ControllerTestAppController'; } /** * ControllerComment class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class ControllerComment extends CakeTestModel { @@ -192,8 +181,7 @@ class ControllerComment extends CakeTestModel { /** * ControllerAlias class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class ControllerAlias extends CakeTestModel { @@ -222,55 +210,10 @@ class ControllerAlias extends CakeTestModel { public $useTable = 'posts'; } -/** - * ControllerPaginateModel class - * - * @package cake - * @subpackage cake.tests.cases.libs.controller - */ -class ControllerPaginateModel extends CakeTestModel { - -/** - * name property - * - * @var string - * @access public - */ - public $name = 'ControllerPaginateModel'; - -/** - * useTable property - * - * @var string' - * @access public - */ - public $useTable = 'comments'; - -/** - * paginate method - * - * @return void - */ - public function paginate($conditions, $fields, $order, $limit, $page, $recursive, $extra) { - $this->extra = $extra; - } - -/** - * paginateCount - * - * @access public - * @return void - */ - function paginateCount($conditions, $recursive, $extra) { - $this->extraCount = $extra; - } -} - /** * NameTest class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class NameTest extends CakeTestModel { @@ -300,10 +243,9 @@ class NameTest extends CakeTestModel { /** * TestController class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ -class TestController extends AppController { +class TestController extends ControllerTestAppController { /** * name property @@ -335,6 +277,8 @@ class TestController extends AppController { * @access public */ public $uses = array('ControllerComment', 'ControllerAlias'); + + protected $_mergeParent = 'ControllerTestAppController'; /** * index method @@ -355,8 +299,7 @@ class TestController extends AppController { /** * TestComponent class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class TestComponent extends Object { @@ -374,7 +317,7 @@ class TestComponent extends Object { * @access public * @return void */ - function initialize(&$controller) { + function initialize($controller) { } /** @@ -383,7 +326,7 @@ class TestComponent extends Object { * @access public * @return void */ - function startup(&$controller) { + function startup($controller) { } /** * shutdown method @@ -391,14 +334,14 @@ class TestComponent extends Object { * @access public * @return void */ - function shutdown(&$controller) { + function shutdown($controller) { } /** * beforeRender callback * * @return void */ - function beforeRender(&$controller) { + function beforeRender($controller) { if ($this->viewclass) { $controller->view = $this->viewclass; } @@ -408,10 +351,9 @@ class TestComponent extends Object { /** * AnotherTestController class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ -class AnotherTestController extends AppController { +class AnotherTestController extends ControllerTestAppController { /** * name property @@ -426,13 +368,14 @@ class AnotherTestController extends AppController { * @access public */ public $uses = null; + + protected $_mergeParent = 'ControllerTestAppController'; } /** * ControllerTest class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class ControllerTest extends CakeTestCase { @@ -508,7 +451,7 @@ class ControllerTest extends CakeTestCase { $result = $Controller->loadModel('Comment'); $this->assertTrue($result); - $this->assertType('Comment', $Controller->Comment); + $this->assertInstanceOf('Comment', $Controller->Comment); $this->assertTrue(in_array('Comment', $Controller->modelNames)); ClassRegistry::flush(); @@ -597,308 +540,6 @@ class ControllerTest extends CakeTestCase { Configure::write('Cache.disable', true); } -/** - * testPaginate method - * - * @access public - * @return void - */ - function testPaginate() { - $request = new CakeRequest('controller_posts/index'); - $request->params['pass'] = $request->params['named'] = array(); - - $Controller = new Controller($request); - $Controller->uses = array('ControllerPost', 'ControllerComment'); - $Controller->passedArgs[] = '1'; - $Controller->query = array(); - $Controller->constructClasses(); - - $results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id'); - $this->assertEqual($results, array(1, 2, 3)); - - $results = Set::extract($Controller->paginate('ControllerComment'), '{n}.ControllerComment.id'); - $this->assertEqual($results, array(1, 2, 3, 4, 5, 6)); - - $Controller->modelClass = null; - - $Controller->uses[0] = 'Plugin.ControllerPost'; - $results = Set::extract($Controller->paginate(), '{n}.ControllerPost.id'); - $this->assertEqual($results, array(1, 2, 3)); - - $Controller->passedArgs = array('page' => '-1'); - $results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id'); - $this->assertEqual($Controller->params['paging']['ControllerPost']['page'], 1); - $this->assertEqual($results, array(1, 2, 3)); - - $Controller->passedArgs = array('sort' => 'ControllerPost.id', 'direction' => 'asc'); - $results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id'); - $this->assertEqual($Controller->params['paging']['ControllerPost']['page'], 1); - $this->assertEqual($results, array(1, 2, 3)); - - $Controller->passedArgs = array('sort' => 'ControllerPost.id', 'direction' => 'desc'); - $results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id'); - $this->assertEqual($Controller->params['paging']['ControllerPost']['page'], 1); - $this->assertEqual($results, array(3, 2, 1)); - - $Controller->passedArgs = array('sort' => 'id', 'direction' => 'desc'); - $results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id'); - $this->assertEqual($Controller->params['paging']['ControllerPost']['page'], 1); - $this->assertEqual($results, array(3, 2, 1)); - - $Controller->passedArgs = array('sort' => 'NotExisting.field', 'direction' => 'desc'); - $results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id'); - $this->assertEqual($Controller->params['paging']['ControllerPost']['page'], 1, 'Invalid field in query %s'); - $this->assertEqual($results, array(1, 2, 3)); - - $Controller->passedArgs = array('sort' => 'ControllerPost.author_id', 'direction' => 'allYourBase'); - $results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id'); - $this->assertEqual($Controller->ControllerPost->lastQuery['order'][0], array('ControllerPost.author_id' => 'asc')); - $this->assertEqual($results, array(1, 3, 2)); - - $Controller->passedArgs = array('page' => '1 " onclick="alert(\'xss\');">'); - $Controller->paginate = array('limit' => 1); - $Controller->paginate('ControllerPost'); - $this->assertIdentical($Controller->params['paging']['ControllerPost']['page'], 1, 'XSS exploit opened %s'); - $this->assertIdentical($Controller->params['paging']['ControllerPost']['options']['page'], 1, 'XSS exploit opened %s'); - - $Controller->passedArgs = array(); - $Controller->paginate = array('limit' => 0); - $Controller->paginate('ControllerPost'); - $this->assertIdentical($Controller->params['paging']['ControllerPost']['page'], 1); - $this->assertIdentical($Controller->params['paging']['ControllerPost']['pageCount'], 3); - $this->assertIdentical($Controller->params['paging']['ControllerPost']['prevPage'], false); - $this->assertIdentical($Controller->params['paging']['ControllerPost']['nextPage'], true); - - $Controller->passedArgs = array(); - $Controller->paginate = array('limit' => 'garbage!'); - $Controller->paginate('ControllerPost'); - $this->assertIdentical($Controller->params['paging']['ControllerPost']['page'], 1); - $this->assertIdentical($Controller->params['paging']['ControllerPost']['pageCount'], 3); - $this->assertIdentical($Controller->params['paging']['ControllerPost']['prevPage'], false); - $this->assertIdentical($Controller->params['paging']['ControllerPost']['nextPage'], true); - - $Controller->passedArgs = array(); - $Controller->paginate = array('limit' => '-1'); - $Controller->paginate('ControllerPost'); - $this->assertIdentical($Controller->params['paging']['ControllerPost']['page'], 1); - $this->assertIdentical($Controller->params['paging']['ControllerPost']['pageCount'], 3); - $this->assertIdentical($Controller->params['paging']['ControllerPost']['prevPage'], false); - $this->assertIdentical($Controller->params['paging']['ControllerPost']['nextPage'], true); - } - -/** - * testPaginateExtraParams method - * - * @access public - * @return void - */ - function testPaginateExtraParams() { - $request = new CakeRequest('controller_posts/index'); - $request->params['pass'] = $request->params['named'] = array(); - - $Controller = new Controller($request); - - $Controller->uses = array('ControllerPost', 'ControllerComment'); - $Controller->passedArgs[] = '1'; - $Controller->query = array(); - $Controller->constructClasses(); - - $Controller->passedArgs = array('page' => '-1', 'contain' => array('ControllerComment')); - $result = $Controller->paginate('ControllerPost'); - $this->assertEqual($Controller->params['paging']['ControllerPost']['page'], 1); - $this->assertEqual(Set::extract($result, '{n}.ControllerPost.id'), array(1, 2, 3)); - $this->assertTrue(!isset($Controller->ControllerPost->lastQuery['contain'])); - - $Controller->passedArgs = array('page' => '-1'); - $Controller->paginate = array('ControllerPost' => array('contain' => array('ControllerComment'))); - $result = $Controller->paginate('ControllerPost'); - $this->assertEqual($Controller->params['paging']['ControllerPost']['page'], 1); - $this->assertEqual(Set::extract($result, '{n}.ControllerPost.id'), array(1, 2, 3)); - $this->assertTrue(isset($Controller->ControllerPost->lastQuery['contain'])); - - $Controller->paginate = array('ControllerPost' => array('popular', 'fields' => array('id', 'title'))); - $result = $Controller->paginate('ControllerPost'); - $this->assertEqual(Set::extract($result, '{n}.ControllerPost.id'), array(2, 3)); - $this->assertEqual($Controller->ControllerPost->lastQuery['conditions'], array('ControllerPost.id > ' => '1')); - - $Controller->passedArgs = array('limit' => 12); - $Controller->paginate = array('limit' => 30); - $result = $Controller->paginate('ControllerPost'); - $paging = $Controller->params['paging']['ControllerPost']; - - $this->assertEqual($Controller->ControllerPost->lastQuery['limit'], 12); - $this->assertEqual($paging['options']['limit'], 12); - - $Controller = new Controller($request); - $Controller->uses = array('ControllerPaginateModel'); - $Controller->query = array(); - $Controller->constructClasses(); - $Controller->paginate = array( - 'ControllerPaginateModel' => array('contain' => array('ControllerPaginateModel'), 'group' => 'Comment.author_id') - ); - $result = $Controller->paginate('ControllerPaginateModel'); - $expected = array('contain' => array('ControllerPaginateModel'), 'group' => 'Comment.author_id'); - $this->assertEqual($Controller->ControllerPaginateModel->extra, $expected); - $this->assertEqual($Controller->ControllerPaginateModel->extraCount, $expected); - - $Controller->paginate = array( - 'ControllerPaginateModel' => array('foo', 'contain' => array('ControllerPaginateModel'), 'group' => 'Comment.author_id') - ); - $Controller->paginate('ControllerPaginateModel'); - $expected = array('contain' => array('ControllerPaginateModel'), 'group' => 'Comment.author_id', 'type' => 'foo'); - $this->assertEqual($Controller->ControllerPaginateModel->extra, $expected); - $this->assertEqual($Controller->ControllerPaginateModel->extraCount, $expected); - } - -/** - * testPaginateFieldsDouble method - * - * @return void - * @access public - */ - function testPaginateFieldsDouble(){ - $Controller = new Controller($this->getMock('CakeRequest')); - $Controller->uses = array('ControllerPost'); - $Controller->request = $this->getMock('CakeRequest'); - $Controller->request->query = array(); - $Controller->constructClasses(); - - $Controller->paginate = array( - 'fields' => array( - 'ControllerPost.id', - 'radians(180.0) as floatvalue' - ), - 'order' => array('ControllerPost.created'=>'DESC'), - 'limit' => 1, - 'page' => 1, - 'recursive' => -1 - ); - $conditions = array(); - $result = $Controller->paginate('ControllerPost', $conditions); - $expected = array( - array( - 'ControllerPost' => array( - 'id' => 3, - ), - 0 => array( - 'floatvalue' => '3.14159265358979', - ), - ), - ); - $this->assertEqual($result, $expected); - } - - -/** - * testPaginatePassedArgs method - * - * @return void - */ - public function testPaginatePassedArgs() { - $request = new CakeRequest('controller_posts/index'); - $request->params['pass'] = $request->params['named'] = array(); - - $Controller = new Controller($request); - $Controller->uses = array('ControllerPost'); - $Controller->passedArgs[] = array('1', '2', '3'); - $Controller->query = array(); - $Controller->constructClasses(); - - $Controller->paginate = array( - 'fields' => array(), - 'order' => '', - 'limit' => 5, - 'page' => 1, - 'recursive' => -1 - ); - $conditions = array(); - $Controller->paginate('ControllerPost',$conditions); - - $expected = array( - 'fields' => array(), - 'order' => '', - 'limit' => 5, - 'page' => 1, - 'recursive' => -1, - 'conditions' => array() - ); - $this->assertEqual($Controller->params['paging']['ControllerPost']['options'],$expected); - } - -/** - * Test that special paginate types are called and that the type param doesn't leak out into defaults or options. - * - * @return void - */ - function testPaginateSpecialType() { - $request = new CakeRequest('controller_posts/index'); - $request->params['pass'] = $request->params['named'] = array(); - - $Controller = new Controller($request); - $Controller->uses = array('ControllerPost', 'ControllerComment'); - $Controller->passedArgs[] = '1'; - $Controller->query = array(); - $Controller->constructClasses(); - - $Controller->paginate = array('ControllerPost' => array('popular', 'fields' => array('id', 'title'))); - $result = $Controller->paginate('ControllerPost'); - - $this->assertEqual(Set::extract($result, '{n}.ControllerPost.id'), array(2, 3)); - $this->assertEqual($Controller->ControllerPost->lastQuery['conditions'], array('ControllerPost.id > ' => '1')); - $this->assertFalse(isset($Controller->params['paging']['ControllerPost']['defaults'][0])); - $this->assertFalse(isset($Controller->params['paging']['ControllerPost']['options'][0])); - } - -/** - * testDefaultPaginateParams method - * - * @access public - * @return void - */ - function testDefaultPaginateParams() { - $request = new CakeRequest('controller_posts/index'); - $request->params['pass'] = $request->params['named'] = array(); - - $Controller = new Controller($request); - $Controller->modelClass = 'ControllerPost'; - $Controller->query = array(); - $Controller->paginate = array('order' => 'ControllerPost.id DESC'); - $Controller->constructClasses(); - $results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id'); - $this->assertEqual($Controller->params['paging']['ControllerPost']['defaults']['order'], 'ControllerPost.id DESC'); - $this->assertEqual($Controller->params['paging']['ControllerPost']['options']['order'], 'ControllerPost.id DESC'); - $this->assertEqual($results, array(3, 2, 1)); - } - -/** - * test paginate() and virtualField interactions - * - * @return void - */ - function testPaginateOrderVirtualField() { - $request = new CakeRequest('controller_posts/index'); - $request->params['pass'] = $request->params['named'] = array(); - - $Controller = new Controller($request); - $Controller->uses = array('ControllerPost', 'ControllerComment'); - $Controller->query = array(); - $Controller->constructClasses(); - $Controller->ControllerPost->virtualFields = array( - 'offset_test' => 'ControllerPost.id + 1' - ); - - $Controller->paginate = array( - 'fields' => array('id', 'title', 'offset_test'), - 'order' => array('offset_test' => 'DESC') - ); - $result = $Controller->paginate('ControllerPost'); - $this->assertEqual(Set::extract($result, '{n}.ControllerPost.offset_test'), array(4, 3, 2)); - - $Controller->passedArgs = array('sort' => 'offset_test', 'direction' => 'asc'); - $result = $Controller->paginate('ControllerPost'); - $this->assertEqual(Set::extract($result, '{n}.ControllerPost.offset_test'), array(2, 3, 4)); - } - /** * testFlash method * @@ -1216,17 +857,13 @@ class ControllerTest extends CakeTestCase { * @return void */ function testMergeVars() { - if ($this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController')) { - return; - } $request = new CakeRequest('controller_posts/index'); - $TestController = new TestController($request); $TestController->constructClasses(); $testVars = get_class_vars('TestController'); - $appVars = get_class_vars('AppController'); + $appVars = get_class_vars('ControllerTestAppController'); $components = is_array($appVars['components']) ? array_merge($appVars['components'], $testVars['components']) @@ -1241,15 +878,17 @@ class ControllerTest extends CakeTestCase { ? array_merge($appVars['uses'], $testVars['uses']) : $testVars['uses']; - $this->assertEqual(count(array_diff_assoc(Set::normalize($TestController->helpers), Set::normalize($helpers))), 0); + $this->assertEqual(count(array_diff_key($TestController->helpers, array_flip($helpers))), 0); $this->assertEqual(count(array_diff($TestController->uses, $uses)), 0); $this->assertEqual(count(array_diff_assoc(Set::normalize($TestController->components), Set::normalize($components))), 0); + $expected = array('ControllerComment', 'ControllerAlias', 'ControllerPost'); + $this->assertEquals($expected, $TestController->uses, '$uses was merged incorrectly, ControllerTestAppController models should be last.'); $TestController = new AnotherTestController($request); $TestController->constructClasses(); - $appVars = get_class_vars('AppController'); + $appVars = get_class_vars('ControllerTestAppController'); $testVars = get_class_vars('AnotherTestController'); @@ -1262,7 +901,7 @@ class ControllerTest extends CakeTestCase { $TestController = new ControllerCommentsController($request); $TestController->constructClasses(); - $appVars = get_class_vars('AppController'); + $appVars = get_class_vars('ControllerTestAppController'); $testVars = get_class_vars('ControllerCommentsController'); @@ -1280,9 +919,6 @@ class ControllerTest extends CakeTestCase { * @return void */ function testChildComponentOptionsSupercedeParents() { - if ($this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController')) { - return; - } $request = new CakeRequest('controller_posts/index'); $TestController = new TestController($request); @@ -1295,7 +931,7 @@ class ControllerTest extends CakeTestCase { /** * Ensure that __mergeVars is not being greedy and merging with - * AppController when you make an instance of Controller + * ControllerTestAppController when you make an instance of Controller * * @return void */ @@ -1499,7 +1135,7 @@ class ControllerTest extends CakeTestCase { $Controller->components = array("RequestHandler"); $Controller->modelClass='ControllerPost'; - $Controller->request->params['url'] = array('ext' => 'rss'); + $Controller->params['url'] = array('ext' => 'rss'); $Controller->constructClasses(); $Controller->Components->trigger('initialize', array(&$Controller)); $Controller->beforeFilter(); @@ -1601,7 +1237,37 @@ class ControllerTest extends CakeTestCase { $Controller = new TestController($request); $Controller->constructClasses(); - $this->assertType('SecurityComponent', $Controller->Security); - $this->assertType('ControllerComment', $Controller->ControllerComment); + $this->assertInstanceOf('SecurityComponent', $Controller->Security); + $this->assertInstanceOf('ControllerComment', $Controller->ControllerComment); + } + +/** + * test that using Controller::paginate() falls back to PaginatorComponent + * + * @return void + */ + function testPaginateBackwardsCompatibility() { + $request = new CakeRequest('controller_posts/index'); + $request->params['pass'] = $request->params['named'] = array(); + + $Controller = new Controller($request); + $Controller->uses = array('ControllerPost', 'ControllerComment'); + $Controller->passedArgs[] = '1'; + $Controller->params['url'] = array(); + $Controller->constructClasses(); + $expected = array('page' => 1, 'limit' => 20, 'maxLimit' => 100, 'paramType' => 'named'); + $this->assertEqual($Controller->paginate, $expected); + + $results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id'); + $this->assertEqual($results, array(1, 2, 3)); + + $Controller->passedArgs = array(); + $Controller->paginate = array('limit' => '-1'); + $this->assertEqual($Controller->paginate, array('limit' => '-1')); + $Controller->paginate('ControllerPost'); + $this->assertIdentical($Controller->params['paging']['ControllerPost']['page'], 1); + $this->assertIdentical($Controller->params['paging']['ControllerPost']['pageCount'], 3); + $this->assertIdentical($Controller->params['paging']['ControllerPost']['prevPage'], false); + $this->assertIdentical($Controller->params['paging']['ControllerPost']['nextPage'], true); } } diff --git a/cake/tests/cases/libs/controller/controller_merge_vars.test.php b/cake/tests/cases/libs/controller/controller_merge_vars.test.php index a3199b3a2..80e12d88c 100644 --- a/cake/tests/cases/libs/controller/controller_merge_vars.test.php +++ b/cake/tests/cases/libs/controller/controller_merge_vars.test.php @@ -14,40 +14,35 @@ * * @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.controller + * @package cake.tests.cases.libs.controller * @since CakePHP(tm) v 1.2.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ App::import('Core', 'Controller'); -if (!class_exists('AppController')) { - /** * Test case AppController * * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ - class AppController extends Controller { +class MergeVarsAppController extends Controller { /** * components * * @var array */ - public $components = array('MergeVar' => array('flag', 'otherFlag', 'redirect' => false)); + public $components = array('MergeVar' => array('flag', 'otherFlag', 'redirect' => false)); /** * helpers * * @var array */ - public $helpers = array('MergeVar' => array('format' => 'html', 'terse')); - } -} elseif (!defined('APP_CONTROLLER_EXISTS')) { - define('APP_CONTROLLER_EXISTS', true); + public $helpers = array('MergeVar' => array('format' => 'html', 'terse')); } + /** * MergeVar Component * @@ -62,7 +57,7 @@ class MergeVarComponent extends Object { * * @package cake.tests.cases.libs.controller */ -class MergeVariablesController extends AppController { +class MergeVariablesController extends MergeVarsAppController { /** * name @@ -77,6 +72,13 @@ class MergeVariablesController extends AppController { * @var arrays */ public $uses = array(); + +/** + * parent for mergeVars + * + * @var string + */ + protected $_mergeParent = 'MergeVarsAppController'; } /** @@ -84,7 +86,7 @@ class MergeVariablesController extends AppController { * * @package cake.tests.cases.libs.controller */ -class MergeVarPluginAppController extends AppController { +class MergeVarPluginAppController extends MergeVarsAppController { /** * components @@ -99,6 +101,13 @@ class MergeVarPluginAppController extends AppController { * @var array */ public $helpers = array('Javascript'); + +/** + * parent for mergeVars + * + * @var string + */ + protected $_mergeParent = 'MergeVarsAppController'; } /** @@ -130,14 +139,6 @@ class MergePostsController extends MergeVarPluginAppController { * @package cake.tests.cases.libs.controller */ class ControllerMergeVarsTest extends CakeTestCase { -/** - * end test - * - * @return void - */ - function endTest() { - ClassRegistry::flush(); - } /** * test that component settings are not duplicated when merging component settings @@ -145,8 +146,6 @@ class ControllerMergeVarsTest extends CakeTestCase { * @return void */ function testComponentParamMergingNoDuplication() { - $this->skipIf(defined('APP_CONTROLLER_EXISTS'), "APP_CONTROLLER_EXISTS cannot run {$this->name}"); - $Controller = new MergeVariablesController(); $Controller->constructClasses(); @@ -160,8 +159,6 @@ class ControllerMergeVarsTest extends CakeTestCase { * @return void */ function testComponentMergingWithRedeclarations() { - $this->skipIf(defined('APP_CONTROLLER_EXISTS'), "APP_CONTROLLER_EXISTS cannot run {$this->name}"); - $Controller = new MergeVariablesController(); $Controller->components['MergeVar'] = array('remote', 'redirect' => true); $Controller->constructClasses(); @@ -176,8 +173,6 @@ class ControllerMergeVarsTest extends CakeTestCase { * @return void */ function testHelperSettingMergingNoDuplication() { - $this->skipIf(defined('APP_CONTROLLER_EXISTS'), "APP_CONTROLLER_EXISTS cannot run {$this->name}"); - $Controller = new MergeVariablesController(); $Controller->constructClasses(); @@ -192,9 +187,7 @@ class ControllerMergeVarsTest extends CakeTestCase { * @return void */ function testHelperOrderPrecedence() { - $this->skipIf(defined('APP_CONTROLLER_EXISTS'), "APP_CONTROLLER_EXISTS cannot run {$this->name}"); - - $Controller =& new MergeVariablesController(); + $Controller = new MergeVariablesController(); $Controller->helpers = array('Custom', 'Foo' => array('something')); $Controller->constructClasses(); @@ -212,8 +205,6 @@ class ControllerMergeVarsTest extends CakeTestCase { * @return void */ function testMergeVarsWithPlugin() { - $this->skipIf(defined('APP_CONTROLLER_EXISTS'), "APP_CONTROLLER_EXISTS cannot run {$this->name}"); - $Controller = new MergePostsController(); $Controller->components = array('Email' => array('ports' => 'open')); $Controller->plugin = 'MergeVarPlugin'; @@ -251,9 +242,7 @@ class ControllerMergeVarsTest extends CakeTestCase { * @return void */ 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->uses = array(); $Controller->constructClasses(); diff --git a/cake/tests/cases/libs/controller/pages_controller.test.php b/cake/tests/cases/libs/controller/pages_controller.test.php index 8188d3976..1d9d3febc 100644 --- a/cake/tests/cases/libs/controller/pages_controller.test.php +++ b/cake/tests/cases/libs/controller/pages_controller.test.php @@ -12,36 +12,19 @@ * * @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.controller + * @package cake.tests.cases.libs.controller * @since CakePHP(tm) v 1.2.0.5436 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -if (!class_exists('AppController')) { - require_once LIBS . 'controller' . DS . 'app_controller.php'; -} elseif (!defined('APP_CONTROLLER_EXISTS')) { - define('APP_CONTROLLER_EXISTS', true); -} App::import('Controller', 'Pages'); /** * PagesControllerTest class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class PagesControllerTest extends CakeTestCase { -/** - * endTest method - * - * @access public - * @return void - */ - function endTest() { - App::build(); - } - /** * testDisplay method * @@ -49,10 +32,6 @@ class PagesControllerTest extends CakeTestCase { * @return void */ function testDisplay() { - if ($this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController')) { - return; - } - App::build(array( 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS, TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS) )); diff --git a/cake/tests/cases/libs/controller/scaffold.test.php b/cake/tests/cases/libs/controller/scaffold.test.php index 415ac6ce2..031d8a0c5 100644 --- a/cake/tests/cases/libs/controller/scaffold.test.php +++ b/cake/tests/cases/libs/controller/scaffold.test.php @@ -12,8 +12,7 @@ * * @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.controller + * @package cake.tests.cases.libs.controller * @since CakePHP(tm) v 1.2.0.5436 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ App::import('Core', 'Controller', false); /** * ScaffoldMockController class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class ScaffoldMockController extends Controller { @@ -48,8 +46,7 @@ class ScaffoldMockController extends Controller { /** * ScaffoldMockControllerWithFields class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class ScaffoldMockControllerWithFields extends Controller { @@ -83,8 +80,7 @@ class ScaffoldMockControllerWithFields extends Controller { /** * TestScaffoldMock class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class TestScaffoldMock extends Scaffold { @@ -93,8 +89,8 @@ class TestScaffoldMock extends Scaffold { * * @param unknown_type $params */ - function _scaffold($params) { - $this->_params = $params; + function _scaffold(CakeRequest $request) { + $this->_params = $request; } /** @@ -110,8 +106,7 @@ class TestScaffoldMock extends Scaffold { /** * ScaffoldMock class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class ScaffoldMock extends CakeTestModel { @@ -166,8 +161,7 @@ class ScaffoldMock extends CakeTestModel { /** * ScaffoldUser class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class ScaffoldUser extends CakeTestModel { @@ -196,8 +190,7 @@ class ScaffoldUser extends CakeTestModel { /** * ScaffoldComment class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class ScaffoldComment extends CakeTestModel { @@ -226,8 +219,7 @@ class ScaffoldComment extends CakeTestModel { /** * ScaffoldTag class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class ScaffoldTag extends CakeTestModel { /** @@ -241,8 +233,7 @@ class ScaffoldTag extends CakeTestModel { /** * TestScaffoldView class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class TestScaffoldView extends ScaffoldView { @@ -261,8 +252,7 @@ class TestScaffoldView extends ScaffoldView { /** * ScaffoldViewTest class * - * @package cake - * @subpackage cake.tests.cases.libs.controller + * @package cake.tests.cases.libs.controller */ class ScaffoldViewTest extends CakeTestCase { @@ -319,11 +309,11 @@ class ScaffoldViewTest extends CakeTestCase { $this->assertEqual($result, $expected); $result = $ScaffoldView->testGetFilename('edit'); - $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'edit.ctp'; + $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'form.ctp'; $this->assertEqual($result, $expected); $result = $ScaffoldView->testGetFilename('add'); - $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'edit.ctp'; + $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'form.ctp'; $this->assertEqual($result, $expected); $result = $ScaffoldView->testGetFilename('view'); @@ -339,15 +329,15 @@ class ScaffoldViewTest extends CakeTestCase { $this->assertEqual($result, $expected); $result = $ScaffoldView->testGetFilename('admin_edit'); - $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'edit.ctp'; + $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'form.ctp'; $this->assertEqual($result, $expected); $result = $ScaffoldView->testGetFilename('admin_add'); - $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'edit.ctp'; + $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'form.ctp'; $this->assertEqual($result, $expected); $result = $ScaffoldView->testGetFilename('error'); - $expected = 'cake' . DS . 'libs' . DS . 'view' . DS . 'errors' . DS . 'scaffold_error.ctp'; + $expected = CAKE . 'libs' . DS . 'view' . DS . 'errors' . DS . 'scaffold_error.ctp'; $this->assertEqual($result, $expected); $Controller = new ScaffoldMockController($this->request); @@ -357,11 +347,11 @@ class ScaffoldViewTest extends CakeTestCase { $ScaffoldView = new TestScaffoldView($Controller); $result = $ScaffoldView->testGetFilename('admin_edit'); - $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' .DS . 'views' . DS . 'posts' . DS . 'scaffold.edit.ctp'; + $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' .DS . 'views' . DS . 'posts' . DS . 'scaffold.form.ctp'; $this->assertEqual($result, $expected); $result = $ScaffoldView->testGetFilename('edit'); - $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' .DS . 'views' . DS . 'posts' . DS . 'scaffold.edit.ctp'; + $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' .DS . 'views' . DS . 'posts' . DS . 'scaffold.form.ctp'; $this->assertEqual($result, $expected); $Controller = new ScaffoldMockController($this->request); @@ -377,12 +367,12 @@ class ScaffoldViewTest extends CakeTestCase { $ScaffoldView = new TestScaffoldView($Controller); $result = $ScaffoldView->testGetFilename('admin_add'); $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' - . DS .'test_plugin' . DS . 'views' . DS . 'tests' . DS . 'scaffold.edit.ctp'; + . DS .'test_plugin' . DS . 'views' . DS . 'tests' . DS . 'scaffold.form.ctp'; $this->assertEqual($result, $expected); $result = $ScaffoldView->testGetFilename('add'); $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' - . DS .'test_plugin' . DS . 'views' . DS . 'tests' . DS . 'scaffold.edit.ctp'; + . DS .'test_plugin' . DS . 'views' . DS . 'tests' . DS . 'scaffold.form.ctp'; $this->assertEqual($result, $expected); Configure::write('Routing.prefixes', $_admin); @@ -524,7 +514,7 @@ class ScaffoldViewTest extends CakeTestCase { $this->assertContains('input name="data[ScaffoldMock][title]" maxlength="255" type="text" value="First Article" id="ScaffoldMockTitle"', $result); $this->assertContains('input name="data[ScaffoldMock][published]" maxlength="1" type="text" value="Y" id="ScaffoldMockPublished"', $result); $this->assertContains('textarea name="data[ScaffoldMock][body]" cols="30" rows="6" id="ScaffoldMockBody"', $result); - $this->assertPattern('/
  • ]*>Delete<\/a>\s*<\/li>/', $result); + $this->assertPattern('/assertEqual($result, $expected); } diff --git a/cake/tests/cases/libs/dispatcher.test.php b/cake/tests/cases/libs/dispatcher.test.php index 35f161e7a..20fab006b 100644 --- a/cake/tests/cases/libs/dispatcher.test.php +++ b/cake/tests/cases/libs/dispatcher.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -40,8 +39,7 @@ class DispatcherMockCakeResponse extends CakeResponse { /** * TestDispatcher class * - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases */ class TestDispatcher extends Dispatcher { @@ -49,12 +47,11 @@ class TestDispatcher extends Dispatcher { * invoke method * * @param mixed $controller - * @param mixed $params - * @param mixed $missingAction + * @param mixed $request * @return void */ - protected function _invoke(&$controller, $params) { - if ($result = parent::_invoke($controller, $params)) { + protected function _invoke(Controller $controller, CakeRequest $request) { + if ($result = parent::_invoke($controller, $request)) { if ($result[0] === 'missingAction') { return $result; } @@ -76,8 +73,7 @@ class TestDispatcher extends Dispatcher { /** * MyPluginAppController class * - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases */ class MyPluginAppController extends AppController { } @@ -85,8 +81,7 @@ class MyPluginAppController extends AppController { /** * MyPluginController class * - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases */ class MyPluginController extends MyPluginAppController { @@ -138,8 +133,7 @@ class MyPluginController extends MyPluginAppController { /** * SomePagesController class * - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases */ class SomePagesController extends AppController { @@ -192,7 +186,7 @@ class SomePagesController extends AppController { * * @return void */ - public function redirect() { + public function redirect($url, $status = null, $exit = true) { echo 'this should not be accessible'; } } @@ -200,8 +194,7 @@ class SomePagesController extends AppController { /** * OtherPagesController class * - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases */ class OtherPagesController extends MyPluginAppController { @@ -244,8 +237,7 @@ class OtherPagesController extends MyPluginAppController { /** * TestDispatchPagesController class * - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases */ class TestDispatchPagesController extends AppController { @@ -287,8 +279,7 @@ class TestDispatchPagesController extends AppController { /** * ArticlesTestAppController class * - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases */ class ArticlesTestAppController extends AppController { } @@ -296,8 +287,7 @@ class ArticlesTestAppController extends AppController { /** * ArticlesTestController class * - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases */ class ArticlesTestController extends ArticlesTestAppController { @@ -338,8 +328,7 @@ class ArticlesTestController extends ArticlesTestAppController { /** * SomePostsController class * - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases */ class SomePostsController extends AppController { @@ -403,8 +392,7 @@ class SomePostsController extends AppController { /** * TestCachedPagesController class * - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases */ class TestCachedPagesController extends Controller { @@ -499,8 +487,7 @@ class TestCachedPagesController extends Controller { /** * TimesheetsController class * - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases */ class TimesheetsController extends Controller { @@ -533,8 +520,7 @@ class TimesheetsController extends Controller { /** * DispatcherTest class * - * @package cake - * @subpackage cake.tests.cases + * @package cake.tests.cases */ class DispatcherTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/error/error_handler.test.php b/cake/tests/cases/libs/error/error_handler.test.php index 736524251..ee5e43bca 100644 --- a/cake/tests/cases/libs/error/error_handler.test.php +++ b/cake/tests/cases/libs/error/error_handler.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.5432 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ App::import('Core', array('ErrorHandler', 'Controller', 'Router')); /** * ErrorHandlerTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class ErrorHandlerTest extends CakeTestCase { @@ -220,6 +218,7 @@ class ErrorHandlerTest extends CakeTestCase { $log = file(LOGS . 'error.log'); $this->assertPattern('/\[NotFoundException\] Kaboom!/', $log[0], 'message missing.'); + $this->assertPattern('/\#0.*ErrorHandlerTest->testHandleExceptionLog/', $log[1], 'Stack trace missing.'); } } diff --git a/cake/tests/cases/libs/error/exception_renderer.test.php b/cake/tests/cases/libs/error/exception_renderer.test.php index c99c6b118..1bc7e8bf0 100644 --- a/cake/tests/cases/libs/error/exception_renderer.test.php +++ b/cake/tests/cases/libs/error/exception_renderer.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ App::import('Core', array('ExceptionRenderer', 'Controller', 'Component')); /** * Short description for class. * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class AuthBlueberryUser extends CakeTestModel { @@ -48,8 +46,7 @@ class AuthBlueberryUser extends CakeTestModel { /** * BlueberryComponent class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class BlueberryComponent extends Component { @@ -67,7 +64,7 @@ class BlueberryComponent extends Component { * @access public * @return void */ - function initialize(&$controller) { + function initialize($controller) { $this->testName = 'BlueberryComponent'; } } @@ -75,8 +72,7 @@ class BlueberryComponent extends Component { /** * TestErrorController class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class TestErrorController extends Controller { @@ -121,8 +117,7 @@ class TestErrorController extends Controller { /** * MyCustomExceptionRenderer class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class MyCustomExceptionRenderer extends ExceptionRenderer { @@ -146,8 +141,7 @@ class MissingWidgetThingException extends NotFoundException { } /** * ExceptionRendererTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class ExceptionRendererTest extends CakeTestCase { @@ -265,7 +259,7 @@ class ExceptionRendererTest extends CakeTestCase { $exception = new NotFoundException('Page not found'); $ExceptionRenderer = new ExceptionRenderer($exception); - $this->assertType('CakeErrorController', $ExceptionRenderer->controller); + $this->assertInstanceOf('CakeErrorController', $ExceptionRenderer->controller); $this->assertEquals('error400', $ExceptionRenderer->method); $this->assertEquals($exception, $ExceptionRenderer->error); } @@ -280,7 +274,7 @@ class ExceptionRendererTest extends CakeTestCase { $exception = new MissingActionException('Page not found'); $ExceptionRenderer = new ExceptionRenderer($exception); - $this->assertType('CakeErrorController', $ExceptionRenderer->controller); + $this->assertInstanceOf('CakeErrorController', $ExceptionRenderer->controller); $this->assertEquals('error400', $ExceptionRenderer->method); $this->assertEquals($exception, $ExceptionRenderer->error); } @@ -322,6 +316,24 @@ class ExceptionRendererTest extends CakeTestCase { $this->assertEquals('error500', $ExceptionRenderer->method, 'incorrect method coercion.'); } +/** + * test that unknown exception types with valid status codes are treated correctly. + * + * @return void + */ + function testUnknownExceptionTypeWithCodeHigherThan500() { + $exception = new OutOfBoundsException('foul ball.', 501); + $ExceptionRenderer = new ExceptionRenderer($exception); + $ExceptionRenderer->controller->response = $this->getMock('CakeResponse', array('statusCode', '_sendHeader')); + $ExceptionRenderer->controller->response->expects($this->once())->method('statusCode')->with(501); + + ob_start(); + $ExceptionRenderer->render(); + $results = ob_get_clean(); + + $this->assertEquals('error500', $ExceptionRenderer->method, 'incorrect method coercion.'); + } + /** * testerror400 method * diff --git a/cake/tests/cases/libs/file.test.php b/cake/tests/cases/libs/file.test.php index 2895deb88..d120ff8f3 100644 --- a/cake/tests/cases/libs/file.test.php +++ b/cake/tests/cases/libs/file.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Core', 'File'); /** * FileTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class FileTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/folder.test.php b/cake/tests/cases/libs/folder.test.php index 428520610..b30bfc616 100644 --- a/cake/tests/cases/libs/folder.test.php +++ b/cake/tests/cases/libs/folder.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Core', 'File'); /** * FolderTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class FolderTest extends CakeTestCase { @@ -195,8 +193,8 @@ class FolderTest extends CakeTestCase { $this->assertFalse($result); $expected = $new . ' is a file'; - $result = array_pop($Folder->errors()); - $this->assertEqual($result, $expected); + $result = $Folder->errors(); + $this->assertEqual($result[0], $expected); $new = TMP . 'test_folder_new'; $result = $Folder->create($new); diff --git a/cake/tests/cases/libs/html_coverage_report.test.php b/cake/tests/cases/libs/html_coverage_report.test.php index 39f41fb60..90fe7f69a 100644 --- a/cake/tests/cases/libs/html_coverage_report.test.php +++ b/cake/tests/cases/libs/html_coverage_report.test.php @@ -13,7 +13,6 @@ * @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) */ diff --git a/cake/tests/cases/libs/http/basic_authentication.test.php b/cake/tests/cases/libs/http/basic_authentication.test.php new file mode 100644 index 000000000..990ed0750 --- /dev/null +++ b/cake/tests/cases/libs/http/basic_authentication.test.php @@ -0,0 +1,64 @@ + + * 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://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests + * @package cake.tests.cases.libs.http + * @since CakePHP(tm) v 2.0.0 + * @license MIT License (http://www.opensource.org/licenses/mit-license.php) + */ + +App::import('Core', 'HttpSocket'); +App::import('Lib', 'http/BasicAuthentication'); + +/** + * BasicMethodTest class + * + * @package cake.tests.cases.libs.http + */ +class BasicMethodTest extends CakeTestCase { + +/** + * testAuthentication method + * + * @return void + */ + public function testAuthentication() { + $http = new HttpSocket(); + $auth = array( + 'method' => 'Basic', + 'user' => 'mark', + 'pass' => 'secret' + ); + + BasicAuthentication::authentication($http, $auth); + $this->assertEqual($http->request['header']['Authorization'], 'Basic bWFyazpzZWNyZXQ='); + } + +/** + * testProxyAuthentication method + * + * @return void + */ + public function testProxyAuthentication() { + $http = new HttpSocket(); + $proxy = array( + 'method' => 'Basic', + 'user' => 'mark', + 'pass' => 'secret' + ); + + BasicAuthentication::proxyAuthentication($http, $proxy); + $this->assertEqual($http->request['header']['Proxy-Authorization'], 'Basic bWFyazpzZWNyZXQ='); + } + +} \ No newline at end of file diff --git a/cake/tests/cases/libs/http/digest_authentication.test.php b/cake/tests/cases/libs/http/digest_authentication.test.php new file mode 100644 index 000000000..17832ce45 --- /dev/null +++ b/cake/tests/cases/libs/http/digest_authentication.test.php @@ -0,0 +1,195 @@ + + * 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://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests + * @package cake.tests.cases.libs.http + * @since CakePHP(tm) v 2.0.0 + * @license MIT License (http://www.opensource.org/licenses/mit-license.php) + */ + +App::import('Core', 'HttpSocket'); +App::import('Lib', 'http/DigestAuthentication'); + +class DigestHttpSocket extends HttpSocket { + +/** + * nextHeader attribute + * + * @var string + */ + public $nextHeader = ''; + +/** + * request method + * + * @param mixed $request + * @return void + */ + public function request($request) { + if ($request === false) { + if (isset($this->response['header']['WWW-Authenticate'])) { + unset($this->response['header']['WWW-Authenticate']); + } + return; + } + $this->response['header']['WWW-Authenticate'] = $this->nextHeader; + } + +} + +/** + * DigestAuthenticationTest class + * + * @package cake.tests.cases.libs.http + */ +class DigestAuthenticationTest extends CakeTestCase { + +/** + * Socket property + * + * @var mixed null + */ + public $HttpSocket = null; + +/** + * This function sets up a HttpSocket instance we are going to use for testing + * + * @return void + */ + public function setUp() { + $this->HttpSocket = new DigestHttpSocket(); + $this->HttpSocket->request['method'] = 'GET'; + $this->HttpSocket->request['uri']['path'] = '/'; + } + +/** + * We use this function to clean up after the test case was executed + * + * @return void + */ + function tearDown() { + unset($this->HttpSocket); + } + +/** + * testBasic method + * + * @return void + */ + public function testBasic() { + $this->HttpSocket->nextHeader = 'Digest realm="The batcave",nonce="4cded326c6c51"'; + $this->assertFalse(isset($this->HttpSocket->request['header']['Authorization'])); + + $auth = array('user' => 'admin', 'pass' => '1234'); + DigestAuthentication::authentication($this->HttpSocket, $auth); + $this->assertTrue(isset($this->HttpSocket->request['header']['Authorization'])); + $this->assertEqual($auth['realm'], 'The batcave'); + $this->assertEqual($auth['nonce'], '4cded326c6c51'); + } + +/** + * testQop method + * + * @return void + */ + public function testQop() { + $this->HttpSocket->nextHeader = 'Digest realm="The batcave",nonce="4cded326c6c51"'; + $auth = array('user' => 'admin', 'pass' => '1234'); + DigestAuthentication::authentication($this->HttpSocket, $auth); + $expected = 'Digest username="admin", realm="The batcave", nonce="4cded326c6c51", uri="/", response="da7e2a46b471d77f70a9bb3698c8902b"'; + $this->assertEqual($expected, $this->HttpSocket->request['header']['Authorization']); + $this->assertFalse(isset($auth['qop'])); + $this->assertFalse(isset($auth['nc'])); + + $this->HttpSocket->nextHeader = 'Digest realm="The batcave",nonce="4cded326c6c51",qop="auth"'; + $auth = array('user' => 'admin', 'pass' => '1234'); + DigestAuthentication::authentication($this->HttpSocket, $auth); + $expected = '@Digest username="admin", realm="The batcave", nonce="4cded326c6c51", uri="/", response="[a-z0-9]{32}", qop="auth", nc=00000001, cnonce="[a-z0-9]+"@'; + $this->assertPattern($expected, $this->HttpSocket->request['header']['Authorization']); + $this->assertEqual($auth['qop'], 'auth'); + $this->assertEqual($auth['nc'], 2); + } + +/** + * testOpaque method + * + * @return void + */ + public function testOpaque() { + $this->HttpSocket->nextHeader = 'Digest realm="The batcave",nonce="4cded326c6c51"'; + $auth = array('user' => 'admin', 'pass' => '1234'); + DigestAuthentication::authentication($this->HttpSocket, $auth); + $this->assertFalse(strpos($this->HttpSocket->request['header']['Authorization'], 'opaque="d8ea7aa61a1693024c4cc3a516f49b3c"')); + + $this->HttpSocket->nextHeader = 'Digest realm="The batcave",nonce="4cded326c6c51",opaque="d8ea7aa61a1693024c4cc3a516f49b3c"'; + $auth = array('user' => 'admin', 'pass' => '1234'); + DigestAuthentication::authentication($this->HttpSocket, $auth); + $this->assertTrue(strpos($this->HttpSocket->request['header']['Authorization'], 'opaque="d8ea7aa61a1693024c4cc3a516f49b3c"') > 0); + } + +/** + * testMultipleRequest method + * + * @return void + */ + public function testMultipleRequest() { + $this->HttpSocket->nextHeader = 'Digest realm="The batcave",nonce="4cded326c6c51",qop="auth"'; + $auth = array('user' => 'admin', 'pass' => '1234'); + DigestAuthentication::authentication($this->HttpSocket, $auth); + $this->assertTrue(strpos($this->HttpSocket->request['header']['Authorization'], 'nc=00000001') > 0); + $this->assertEqual($auth['nc'], 2); + + DigestAuthentication::authentication($this->HttpSocket, $auth); + $this->assertTrue(strpos($this->HttpSocket->request['header']['Authorization'], 'nc=00000002') > 0); + $this->assertEqual($auth['nc'], 3); + $responsePos = strpos($this->HttpSocket->request['header']['Authorization'], 'response='); + $response = substr($this->HttpSocket->request['header']['Authorization'], $responsePos + 10, 32); + + $this->HttpSocket->nextHeader = ''; + DigestAuthentication::authentication($this->HttpSocket, $auth); + $this->assertTrue(strpos($this->HttpSocket->request['header']['Authorization'], 'nc=00000003') > 0); + $this->assertEqual($auth['nc'], 4); + $responsePos = strpos($this->HttpSocket->request['header']['Authorization'], 'response='); + $response2 = substr($this->HttpSocket->request['header']['Authorization'], $responsePos + 10, 32); + $this->assertNotEqual($response, $response2); + } + +/** + * testPathChanged method + * + * @return void + */ + public function testPathChanged() { + $this->HttpSocket->nextHeader = 'Digest realm="The batcave",nonce="4cded326c6c51"'; + $this->HttpSocket->request['uri']['path'] = '/admin'; + $auth = array('user' => 'admin', 'pass' => '1234'); + DigestAuthentication::authentication($this->HttpSocket, $auth); + $responsePos = strpos($this->HttpSocket->request['header']['Authorization'], 'response='); + $response = substr($this->HttpSocket->request['header']['Authorization'], $responsePos + 10, 32); + $this->assertNotEqual($response, 'da7e2a46b471d77f70a9bb3698c8902b'); + } + +/** + * testNoDigestResponse method + * + * @return void + */ + public function testNoDigestResponse() { + $this->HttpSocket->nextHeader = false; + $this->HttpSocket->request['uri']['path'] = '/admin'; + $auth = array('user' => 'admin', 'pass' => '1234'); + DigestAuthentication::authentication($this->HttpSocket, $auth); + $this->assertFalse(isset($this->HttpSocket->request['header']['Authorization'])); + } + +} \ No newline at end of file diff --git a/cake/tests/cases/libs/http_response.test.php b/cake/tests/cases/libs/http_response.test.php new file mode 100644 index 000000000..9155bb8a3 --- /dev/null +++ b/cake/tests/cases/libs/http_response.test.php @@ -0,0 +1,506 @@ + + * 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://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests + * @package cake.tests.cases.libs + * @since CakePHP(tm) v 1.2.0.4206 + * @license MIT License (http://www.opensource.org/licenses/mit-license.php) + */ +App::import('Core', 'HttpResponse'); + +/** + * TestHttpResponse class + * + * @package cake.tests.cases.libs + */ +class TestHttpResponse extends HttpResponse { + +/** + * Convenience method for testing protected method + * + * @param array $header Header as an indexed array (field => value) + * @return array Parsed header + */ + public function parseHeader($header) { + return parent::_parseHeader($header); + } + +/** + * Convenience method for testing protected method + * + * @param string $body A string continaing the body to decode + * @param mixed $encoding Can be false in case no encoding is being used, or a string representing the encoding + * @return mixed Array or false + */ + public function decodeBody($body, $encoding = 'chunked') { + return parent::_decodeBody($body, $encoding); + } + +/** + * Convenience method for testing protected method + * + * @param string $body A string continaing the chunked body to decode + * @return mixed Array or false + */ + public function decodeChunkedBody($body) { + return parent::_decodeChunkedBody($body); + } + +/** + * Convenience method for testing protected method + * + * @param string $token Token to unescape + * @return string Unescaped token + */ + public function unescapeToken($token, $chars = null) { + return parent::_unescapeToken($token, $chars); + } + +/** + * Convenience method for testing protected method + * + * @param boolean $hex true to get them as HEX values, false otherwise + * @return array Escape chars + */ + public function tokenEscapeChars($hex = true, $chars = null) { + return parent::_tokenEscapeChars($hex, $chars); + } + +} + +/** + * HttpResponseTest class + * + * @package cake.tests.cases.libs + */ +class HttpResponseTest extends CakeTestCase { +/** + * This function sets up a HttpResponse + * + * @return void + */ + public function setUp() { + $this->HttpResponse = new TestHttpResponse(); + } + +/** + * testBody + * + * @return void + */ + public function testBody() { + $this->HttpResponse->body = 'testing'; + $this->assertEqual($this->HttpResponse->body(), 'testing'); + + $this->HttpResponse->body = null; + $this->assertIdentical($this->HttpResponse->body(), ''); + } + +/** + * testToString + * + * @return void + */ + public function testToString() { + $this->HttpResponse->body = 'other test'; + $this->assertEqual($this->HttpResponse->body(), 'other test'); + $this->assertEqual((string)$this->HttpResponse, 'other test'); + $this->assertTrue(strpos($this->HttpResponse, 'test') > 0); + + $this->HttpResponse->body = null; + $this->assertEqual((string)$this->HttpResponse, ''); + } + +/** + * testGetHeadr + * + * @return void + */ + public function testGetHeader() { + $this->HttpResponse->headers = array( + 'foo' => 'Bar', + 'Some' => 'ok', + 'HeAdEr' => 'value', + 'content-Type' => 'text/plain' + ); + + $this->assertEqual($this->HttpResponse->getHeader('foo'), 'Bar'); + $this->assertEqual($this->HttpResponse->getHeader('Foo'), 'Bar'); + $this->assertEqual($this->HttpResponse->getHeader('FOO'), 'Bar'); + $this->assertEqual($this->HttpResponse->getHeader('header'), 'value'); + $this->assertEqual($this->HttpResponse->getHeader('Content-Type'), 'text/plain'); + $this->assertIdentical($this->HttpResponse->getHeader(0), null); + + $this->assertEqual($this->HttpResponse->getHeader('foo', false), 'Bar'); + $this->assertEqual($this->HttpResponse->getHeader('foo', array('foo' => 'not from class')), 'not from class'); + } + +/** + * testIsOk + * + * @return void + */ + public function testIsOk() { + $this->HttpResponse->code = 0; + $this->assertFalse($this->HttpResponse->isOk()); + $this->HttpResponse->code = -1; + $this->assertFalse($this->HttpResponse->isOk()); + $this->HttpResponse->code = 201; + $this->assertFalse($this->HttpResponse->isOk()); + $this->HttpResponse->code = 'what?'; + $this->assertFalse($this->HttpResponse->isOk()); + $this->HttpResponse->code = 200; + $this->assertTrue($this->HttpResponse->isOk()); + } + +/** + * Test that HttpSocket::parseHeader can take apart a given (and valid) $header string and turn it into an array. + * + * @return void + */ + public function testParseHeader() { + $r = $this->HttpResponse->parseHeader(array('foo' => 'Bar', 'fOO-bAr' => 'quux')); + $this->assertEquals($r, array('foo' => 'Bar', 'fOO-bAr' => 'quux')); + + $r = $this->HttpResponse->parseHeader(true); + $this->assertEquals($r, false); + + $header = "Host: cakephp.org\t\r\n"; + $r = $this->HttpResponse->parseHeader($header); + $expected = array( + 'Host' => 'cakephp.org' + ); + $this->assertEquals($r, $expected); + + $header = "Date:Sat, 07 Apr 2007 10:10:25 GMT\r\nX-Powered-By: PHP/5.1.2\r\n"; + $r = $this->HttpResponse->parseHeader($header); + $expected = array( + 'Date' => 'Sat, 07 Apr 2007 10:10:25 GMT', + 'X-Powered-By' => 'PHP/5.1.2' + ); + $this->assertEquals($r, $expected); + + $header = "people: Jim,John\r\nfoo-LAND: Bar\r\ncAKe-PHP: rocks\r\n"; + $r = $this->HttpResponse->parseHeader($header); + $expected = array( + 'people' => 'Jim,John', + 'foo-LAND' => 'Bar', + 'cAKe-PHP' => 'rocks' + ); + $this->assertEquals($r, $expected); + + $header = "People: Jim,John,Tim\r\nPeople: Lisa,Tina,Chelsea\r\n"; + $r = $this->HttpResponse->parseHeader($header); + $expected = array( + 'People' => array('Jim,John,Tim', 'Lisa,Tina,Chelsea') + ); + $this->assertEquals($r, $expected); + + $header = "Multi-Line: I am a \r\nmulti line\t\r\nfield value.\r\nSingle-Line: I am not\r\n"; + $r = $this->HttpResponse->parseHeader($header); + $expected = array( + 'Multi-Line' => "I am a\r\nmulti line\r\nfield value.", + 'Single-Line' => 'I am not' + ); + $this->assertEquals($r, $expected); + + $header = "Esc\"@\"ped: value\r\n"; + $r = $this->HttpResponse->parseHeader($header); + $expected = array( + 'Esc@ped' => 'value' + ); + $this->assertEquals($r, $expected); + } + +/** + * testParseResponse method + * + * @return void + */ + public function testParseResponse() { + $tests = array( + 'simple-request' => array( + 'response' => array( + 'status-line' => "HTTP/1.x 200 OK\r\n", + 'header' => "Date: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\n", + 'body' => "

    Hello World

    \r\n

    It's good to be html

    " + ), + 'expectations' => array( + 'httpVersion' => 'HTTP/1.x', + 'code' => 200, + 'reasonPhrase' => 'OK', + 'headers' => array('Date' => 'Mon, 16 Apr 2007 04:14:16 GMT', 'Server' => 'CakeHttp Server'), + 'body' => "

    Hello World

    \r\n

    It's good to be html

    " + ) + ), + 'no-header' => array( + 'response' => array( + 'status-line' => "HTTP/1.x 404 OK\r\n", + 'header' => null + ), + 'expectations' => array( + 'code' => 404, + 'headers' => array() + ) + ) + ); + + $testResponse = array(); + $expectations = array(); + + foreach ($tests as $name => $test) { + $testResponse = array_merge($testResponse, $test['response']); + $testResponse['response'] = $testResponse['status-line'] . $testResponse['header'] . "\r\n" . $testResponse['body']; + $this->HttpResponse->parseResponse($testResponse['response']); + $expectations = array_merge($expectations, $test['expectations']); + + foreach ($expectations as $property => $expectedVal) { + $this->assertEquals($this->HttpResponse->{$property}, $expectedVal, 'Test "' . $name . '": response.' . $property . ' - %s'); + } + + foreach (array('status-line', 'header', 'body', 'response') as $field) { + $this->assertEquals($this->HttpResponse['raw'][$field], $testResponse[$field], 'Test response.raw.' . $field . ': %s'); + } + } + } + +/** + * data provider function for testInvalidParseResponseData + * + * @return array + */ + public static function invalidParseResponseDataProvider() { + return array( + array(array('foo' => 'bar')), + array(true), + array("HTTP Foo\r\nBar: La"), + array('HTTP/1.1 TEST ERROR') + ); + } + +/** + * testInvalidParseResponseData + * + * @dataProvider invalidParseResponseDataProvider + * @expectedException SocketException + * return void + */ + public function testInvalidParseResponseData($value) { + $this->HttpResponse->parseResponse($value); + } + +/** + * testDecodeBody method + * + * @return void + */ + public function testDecodeBody() { + $r = $this->HttpResponse->decodeBody(true); + $this->assertEquals($r, false); + + $r = $this->HttpResponse->decodeBody('Foobar', false); + $this->assertEquals($r, array('body' => 'Foobar', 'header' => false)); + + $encoding = 'chunked'; + $sample = array( + 'encoded' => "19\r\nThis is a chunked message\r\n0\r\n", + 'decoded' => array('body' => "This is a chunked message", 'header' => false) + ); + + $r = $this->HttpResponse->decodeBody($sample['encoded'], $encoding); + $this->assertEquals($r, $sample['decoded']); + } + +/** + * testDecodeFooCoded + * + * @return void + */ + public function testDecodeFooCoded() { + $r = $this->HttpResponse->decodeBody(true); + $this->assertEquals($r, false); + + $r = $this->HttpResponse->decodeBody('Foobar', false); + $this->assertEquals($r, array('body' => 'Foobar', 'header' => false)); + + $encoding = 'foo-bar'; + $sample = array( + 'encoded' => '!Foobar!', + 'decoded' => array('body' => '!Foobar!', 'header' => false), + ); + + $r = $this->HttpResponse->decodeBody($sample['encoded'], $encoding); + $this->assertEquals($r, $sample['decoded']); + } + +/** + * testDecodeChunkedBody method + * + * @return void + */ + public function testDecodeChunkedBody() { + $r = $this->HttpResponse->decodeChunkedBody(true); + $this->assertEquals($r, false); + + $encoded = "19\r\nThis is a chunked message\r\n0\r\n"; + $decoded = "This is a chunked message"; + $r = $this->HttpResponse->decodeChunkedBody($encoded); + $this->assertEquals($r['body'], $decoded); + $this->assertEquals($r['header'], false); + + $encoded = "19 \r\nThis is a chunked message\r\n0\r\n"; + $r = $this->HttpResponse->decodeChunkedBody($encoded); + $this->assertEquals($r['body'], $decoded); + + $encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\n0\r\n"; + $decoded = "This is a chunked message\nThat is cool\n"; + $r = $this->HttpResponse->decodeChunkedBody($encoded); + $this->assertEquals($r['body'], $decoded); + $this->assertEquals($r['header'], false); + + $encoded = "19\r\nThis is a chunked message\r\nE;foo-chunk=5\r\n\nThat is cool\n\r\n0\r\n"; + $r = $this->HttpResponse->decodeChunkedBody($encoded); + $this->assertEquals($r['body'], $decoded); + $this->assertEquals($r['header'], false); + + $encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\n0\r\nfoo-header: bar\r\ncake: PHP\r\n\r\n"; + $r = $this->HttpResponse->decodeChunkedBody($encoded); + $this->assertEquals($r['body'], $decoded); + $this->assertEquals($r['header'], array('foo-header' => 'bar', 'cake' => 'PHP')); + + $encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\n"; + $this->expectError(); + $r = $this->HttpResponse->decodeChunkedBody($encoded); + $this->assertEquals($r, false); + } + +/** + * testParseCookies method + * + * @return void + */ + public function testParseCookies() { + $header = array( + 'Set-Cookie' => array( + 'foo=bar', + 'people=jim,jack,johnny";";Path=/accounts', + 'google=not=nice' + ), + 'Transfer-Encoding' => 'chunked', + 'Date' => 'Sun, 18 Nov 2007 18:57:42 GMT', + ); + $cookies = $this->HttpResponse->parseCookies($header); + $expected = array( + 'foo' => array( + 'value' => 'bar' + ), + 'people' => array( + 'value' => 'jim,jack,johnny";"', + 'path' => '/accounts', + ), + 'google' => array( + 'value' => 'not=nice', + ) + ); + $this->assertEqual($cookies, $expected); + + $header['Set-Cookie'][] = 'cakephp=great; Secure'; + $expected['cakephp'] = array('value' => 'great', 'secure' => true); + $cookies = $this->HttpResponse->parseCookies($header); + $this->assertEqual($cookies, $expected); + + $header['Set-Cookie'] = 'foo=bar'; + unset($expected['people'], $expected['cakephp'], $expected['google']); + $cookies = $this->HttpResponse->parseCookies($header); + $this->assertEqual($cookies, $expected); + } + +/** + * Test that escaped token strings are properly unescaped by HttpSocket::unescapeToken + * + * @return void + */ + public function testUnescapeToken() { + $this->assertEquals($this->HttpResponse->unescapeToken('Foo'), 'Foo'); + + $escape = $this->HttpResponse->tokenEscapeChars(false); + foreach ($escape as $char) { + $token = 'My-special-"' . $char . '"-Token'; + $unescapedToken = $this->HttpResponse->unescapeToken($token); + $expectedToken = 'My-special-' . $char . '-Token'; + + $this->assertEquals($unescapedToken, $expectedToken, 'Test token unescaping for ASCII '.ord($char)); + } + + $token = 'Extreme-":"Token-" "-""""@"-test'; + $escapedToken = $this->HttpResponse->unescapeToken($token); + $expectedToken = 'Extreme-:Token- -"@-test'; + $this->assertEquals($expectedToken, $escapedToken); + } + +/** + * testArrayAccess + * + * @return void + */ + public function testArrayAccess() { + $this->HttpResponse->httpVersion = 'HTTP/1.1'; + $this->HttpResponse->code = 200; + $this->HttpResponse->reasonPhrase = 'OK'; + $this->HttpResponse->headers = array( + 'Server' => 'CakePHP', + 'ContEnt-Type' => 'text/plain' + ); + $this->HttpResponse->cookies = array( + 'foo' => array('value' => 'bar'), + 'bar' => array('value' => 'foo') + ); + $this->HttpResponse->body = 'This is a test!'; + $this->HttpResponse->raw = "HTTP/1.1 200 OK\r\nServer: CakePHP\r\nContEnt-Type: text/plain\r\n\r\nThis is a test!"; + + $expected1 = "HTTP/1.1 200 OK\r\n"; + $this->assertEqual($this->HttpResponse['raw']['status-line'], $expected1); + $expected2 = "Server: CakePHP\r\nContEnt-Type: text/plain\r\n"; + $this->assertEqual($this->HttpResponse['raw']['header'], $expected2); + $expected3 = 'This is a test!'; + $this->assertEqual($this->HttpResponse['raw']['body'], $expected3); + $expected = $expected1 . $expected2 . "\r\n" . $expected3; + $this->assertEqual($this->HttpResponse['raw']['response'], $expected); + + $expected = 'HTTP/1.1'; + $this->assertEqual($this->HttpResponse['status']['http-version'], $expected); + $expected = 200; + $this->assertEqual($this->HttpResponse['status']['code'], $expected); + $expected = 'OK'; + $this->assertEqual($this->HttpResponse['status']['reason-phrase'], $expected); + + $expected = array( + 'Server' => 'CakePHP', + 'ContEnt-Type' => 'text/plain' + ); + $this->assertEqual($this->HttpResponse['header'], $expected); + + $expected = 'This is a test!'; + $this->assertEqual($this->HttpResponse['body'], $expected); + + $expected = array( + 'foo' => array('value' => 'bar'), + 'bar' => array('value' => 'foo') + ); + $this->assertEqual($this->HttpResponse['cookies'], $expected); + + $this->HttpResponse->raw = "HTTP/1.1 200 OK\r\n\r\nThis is a test!"; + $this->assertIdentical($this->HttpResponse['raw']['header'], null); + } + +} \ No newline at end of file diff --git a/cake/tests/cases/libs/http_socket.test.php b/cake/tests/cases/libs/http_socket.test.php index 5b3f79e0c..94de48389 100644 --- a/cake/tests/cases/libs/http_socket.test.php +++ b/cake/tests/cases/libs/http_socket.test.php @@ -12,13 +12,71 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ App::import('Core', 'HttpSocket'); +/** + * TestAuthentication class + * + * @package cake + * @package cake.tests.cases.libs + */ +class TestAuthentication { + +/** + * authentication method + * + * @param HttpSocket $http + * @param array $authInfo + * @return void + */ + public static function authentication(HttpSocket $http, &$authInfo) { + $http->request['header']['Authorization'] = 'Test ' . $authInfo['user'] . '.' . $authInfo['pass']; + } + +/** + * proxyAuthentication method + * + * @param HttpSocket $http + * @param array $proxyInfo + * @return void + */ + public static function proxyAuthentication(HttpSocket $http, &$proxyInfo) { + $http->request['header']['Proxy-Authorization'] = 'Test ' . $proxyInfo['user'] . '.' . $proxyInfo['pass']; + } + +} + +/** + * CustomResponse + * + */ +class CustomResponse { + +/** + * First 10 chars + * + * @var string + */ + public $first10; + +/** + * Constructor + * + */ + public function __construct($message) { + $this->first10 = substr($message, 0, 10); + } + +} + +/** + * TestHttpSocket + * + */ class TestHttpSocket extends HttpSocket { /** @@ -27,7 +85,7 @@ class TestHttpSocket extends HttpSocket { * @param mixed $uri URI (see {@link _parseUri()}) * @return array Current configuration settings */ - function configUri($uri = null) { + public function configUri($uri = null) { return parent::_configUri($uri); } @@ -38,7 +96,7 @@ class TestHttpSocket extends HttpSocket { * @param mixed $base If true use default URI config, otherwise indexed array to set 'scheme', 'host', 'port', etc. * @return array Parsed URI */ - function parseUri($uri = null, $base = array()) { + public function parseUri($uri = null, $base = array()) { return parent::_parseUri($uri, $base); } @@ -49,7 +107,7 @@ class TestHttpSocket extends HttpSocket { * @param string $uriTemplate The Uri template/format to use * @return string A fully qualified URL formated according to $uriTemplate */ - function buildUri($uri = array(), $uriTemplate = '%scheme://%user:%pass@%host:%port/%path?%query#%fragment') { + public function buildUri($uri = array(), $uriTemplate = '%scheme://%user:%pass@%host:%port/%path?%query#%fragment') { return parent::_buildUri($uri, $uriTemplate); } @@ -59,61 +117,20 @@ class TestHttpSocket extends HttpSocket { * @param array $header Header to build * @return string Header built from array */ - function buildHeader($header, $mode = 'standard') { + public function buildHeader($header, $mode = 'standard') { return parent::_buildHeader($header, $mode); } -/** - * Convenience method for testing protected method - * - * @param string $message Message to parse - * @return array Parsed message (with indexed elements such as raw, status, header, body) - */ - function parseResponse($message) { - return parent::_parseResponse($message); - } - -/** - * Convenience method for testing protected method - * - * @param array $header Header as an indexed array (field => value) - * @return array Parsed header - */ - function parseHeader($header) { - return parent::_parseHeader($header); - } - /** * Convenience method for testing protected method * * @param mixed $query A query string to parse into an array or an array to return directly "as is" * @return array The $query parsed into a possibly multi-level array. If an empty $query is given, an empty array is returned. */ - function parseQuery($query) { + public function parseQuery($query) { return parent::_parseQuery($query); } -/** - * Convenience method for testing protected method - * - * @param string $body A string continaing the body to decode - * @param mixed $encoding Can be false in case no encoding is being used, or a string representing the encoding - * @return mixed Array or false - */ - function decodeBody($body, $encoding = 'chunked') { - return parent::_decodeBody($body, $encoding); - } - -/** - * Convenience method for testing protected method - * - * @param string $body A string continaing the chunked body to decode - * @return mixed Array or false - */ - function decodeChunkedBody($body) { - return parent::_decodeChunkedBody($body); - } - /** * Convenience method for testing protected method * @@ -121,7 +138,7 @@ class TestHttpSocket extends HttpSocket { * @param string $versionToken The version token to use, defaults to HTTP/1.1 * @return string Request line */ - function buildRequestLine($request = array(), $versionToken = 'HTTP/1.1') { + public function buildRequestLine($request = array(), $versionToken = 'HTTP/1.1') { return parent::_buildRequestLine($request, $versionToken); } @@ -131,7 +148,7 @@ class TestHttpSocket extends HttpSocket { * @param boolean $hex true to get them as HEX values, false otherwise * @return array Escape chars */ - function tokenEscapeChars($hex = true, $chars = null) { + public function tokenEscapeChars($hex = true, $chars = null) { return parent::_tokenEscapeChars($hex, $chars); } @@ -141,26 +158,16 @@ class TestHttpSocket extends HttpSocket { * @param string $token Token to escape * @return string Escaped token */ - function EscapeToken($token, $chars = null) { + public function EscapeToken($token, $chars = null) { return parent::_escapeToken($token, $chars); } -/** - * Convenience method for testing protected method - * - * @param string $token Token to unescape - * @return string Unescaped token - */ - function unescapeToken($token, $chars = null) { - return parent::_unescapeToken($token, $chars); - } } /** * HttpSocketTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class HttpSocketTest extends CakeTestCase { @@ -168,7 +175,6 @@ class HttpSocketTest extends CakeTestCase { * Socket property * * @var mixed null - * @access public */ public $Socket = null; @@ -176,17 +182,15 @@ class HttpSocketTest extends CakeTestCase { * RequestSocket property * * @var mixed null - * @access public */ public $RequestSocket = null; /** * This function sets up a TestHttpSocket instance we are going to use for testing * - * @access public * @return void */ - function setUp() { + public function setUp() { if (!class_exists('MockHttpSocket')) { $this->getMock('TestHttpSocket', array('read', 'write', 'connect'), array(), 'MockHttpSocket'); $this->getMock('TestHttpSocket', array('read', 'write', 'connect', 'request'), array(), 'MockHttpSocketRequests'); @@ -199,20 +203,18 @@ class HttpSocketTest extends CakeTestCase { /** * We use this function to clean up after the test case was executed * - * @access public * @return void */ - function tearDown() { + public function tearDown() { unset($this->Socket, $this->RequestSocket); } /** * Test that HttpSocket::__construct does what one would expect it to do * - * @access public * @return void */ - function testConstruct() { + public function testConstruct() { $this->Socket->reset(); $baseConfig = $this->Socket->config; $this->Socket->expects($this->never())->method('connect'); @@ -220,13 +222,12 @@ class HttpSocketTest extends CakeTestCase { $baseConfig['host'] = 'foo-bar'; $baseConfig['protocol'] = getprotobyname($baseConfig['protocol']); $this->assertEquals($this->Socket->config, $baseConfig); + $this->Socket->reset(); $baseConfig = $this->Socket->config; $this->Socket->__construct('http://www.cakephp.org:23/'); - $baseConfig['host'] = 'www.cakephp.org'; - $baseConfig['request']['uri']['host'] = 'www.cakephp.org'; - $baseConfig['port'] = 23; - $baseConfig['request']['uri']['port'] = 23; + $baseConfig['host'] = $baseConfig['request']['uri']['host'] = 'www.cakephp.org'; + $baseConfig['port'] = $baseConfig['request']['uri']['port'] = 23; $baseConfig['protocol'] = getprotobyname($baseConfig['protocol']); $this->assertEquals($this->Socket->config, $baseConfig); @@ -238,269 +239,275 @@ class HttpSocketTest extends CakeTestCase { /** * Test that HttpSocket::configUri works properly with different types of arguments * - * @access public * @return void */ - function testConfigUri() { + public function testConfigUri() { $this->Socket->reset(); $r = $this->Socket->configUri('https://bob:secret@www.cakephp.org:23/?query=foo'); $expected = array( 'persistent' => false, - 'host' => 'www.cakephp.org', - 'protocol' => 'tcp', - 'port' => 23, - 'timeout' => 30, + 'host' => 'www.cakephp.org', + 'protocol' => 'tcp', + 'port' => 23, + 'timeout' => 30, 'request' => array( 'uri' => array( - 'scheme' => 'https' - , 'host' => 'www.cakephp.org' - , 'port' => 23 - ), - 'auth' => array( - 'method' => 'Basic' - , 'user' => 'bob' - , 'pass' => 'secret' - ), - 'cookies' => array(), - ) - ); - $this->assertEquals($this->Socket->config, $expected); - $this->assertEquals($r, $expected); - $r = $this->Socket->configUri(array('host' => 'www.foo-bar.org')); - $expected['host'] = 'www.foo-bar.org'; - $expected['request']['uri']['host'] = 'www.foo-bar.org'; - $this->assertEquals($this->Socket->config, $expected); - $this->assertEquals($r, $expected); - - $r = $this->Socket->configUri('http://www.foo.com'); - $expected = array( - 'persistent' => false, - 'host' => 'www.foo.com', - 'protocol' => 'tcp', - 'port' => 80, - 'timeout' => 30, - 'request' => array( - 'uri' => array( - 'scheme' => 'http' - , 'host' => 'www.foo.com' - , 'port' => 80 - ), - 'auth' => array( - 'method' => 'Basic' - , 'user' => null - , 'pass' => null + 'scheme' => 'https', + 'host' => 'www.cakephp.org', + 'port' => 23 ), 'cookies' => array() ) ); $this->assertEquals($this->Socket->config, $expected); - $this->assertEquals($r, $expected); + $this->assertTrue($r); + $r = $this->Socket->configUri(array('host' => 'www.foo-bar.org')); + $expected['host'] = 'www.foo-bar.org'; + $expected['request']['uri']['host'] = 'www.foo-bar.org'; + $this->assertEquals($this->Socket->config, $expected); + $this->assertTrue($r); + + $r = $this->Socket->configUri('http://www.foo.com'); + $expected = array( + 'persistent' => false, + 'host' => 'www.foo.com', + 'protocol' => 'tcp', + 'port' => 80, + 'timeout' => 30, + 'request' => array( + 'uri' => array( + 'scheme' => 'http', + 'host' => 'www.foo.com', + 'port' => 80 + ), + 'cookies' => array() + ) + ); + $this->assertEquals($this->Socket->config, $expected); + $this->assertTrue($r); $r = $this->Socket->configUri('/this-is-broken'); $this->assertEquals($this->Socket->config, $expected); - $this->assertEquals($r, false); + $this->assertFalse($r); $r = $this->Socket->configUri(false); $this->assertEquals($this->Socket->config, $expected); - $this->assertEquals($r, false); + $this->assertFalse($r); } /** * Tests that HttpSocket::request (the heart of the HttpSocket) is working properly. * - * @access public * @return void */ - function testRequest() { + public function testRequest() { $this->Socket->reset(); $response = $this->Socket->request(true); $this->assertFalse($response); $tests = array( - 0 => array( - 'request' => 'http://www.cakephp.org/?foo=bar' - , 'expectation' => array( + array( + 'request' => 'http://www.cakephp.org/?foo=bar', + 'expectation' => array( 'config' => array( - 'persistent' => false - , 'host' => 'www.cakephp.org' - , 'protocol' => 'tcp' - , 'port' => 80 - , 'timeout' => 30 - , 'request' => array( + 'persistent' => false, + 'host' => 'www.cakephp.org', + 'protocol' => 'tcp', + 'port' => 80, + 'timeout' => 30, + 'request' => array( 'uri' => array ( - 'scheme' => 'http' - , 'host' => 'www.cakephp.org' - , 'port' => 80, - ) - , 'auth' => array( - 'method' => 'Basic' - ,'user' => null - ,'pass' => null + 'scheme' => 'http', + 'host' => 'www.cakephp.org', + 'port' => 80 ), 'cookies' => array(), + ) + ), + 'request' => array( + 'method' => 'GET', + 'uri' => array( + 'scheme' => 'http', + 'host' => 'www.cakephp.org', + 'port' => 80, + 'user' => null, + 'pass' => null, + 'path' => '/', + 'query' => array('foo' => 'bar'), + 'fragment' => null ), - ) - , 'request' => array( - 'method' => 'GET' - , 'uri' => array( - 'scheme' => 'http' - , 'host' => 'www.cakephp.org' - , 'port' => 80 - , 'user' => null - , 'pass' => null - , 'path' => '/' - , 'query' => array('foo' => 'bar') - , 'fragment' => null - ) - , 'auth' => array( - 'method' => 'Basic' - , 'user' => null - , 'pass' => null - ) - , 'version' => '1.1' - , 'body' => '' - , 'line' => "GET /?foo=bar HTTP/1.1\r\n" - , 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\n" - , 'raw' => "" - , 'cookies' => array(), + 'version' => '1.1', + 'body' => '', + 'line' => "GET /?foo=bar HTTP/1.1\r\n", + 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\n", + 'raw' => "", + 'cookies' => array(), + 'proxy' => array(), + 'auth' => array() ) ) - ) - , 1 => array( + ), + array( 'request' => array( 'uri' => array( - 'host' => 'www.cakephp.org' - , 'query' => '?foo=bar' + 'host' => 'www.cakephp.org', + 'query' => '?foo=bar' ) ) - ) - , 2 => array( + ), + array( 'request' => 'www.cakephp.org/?foo=bar' - ) - , 3 => array( - 'request' => array('host' => '192.168.0.1', 'uri' => 'http://www.cakephp.org/?foo=bar') - , 'expectation' => array( + ), + array( + 'request' => array( + 'host' => '192.168.0.1', + 'uri' => 'http://www.cakephp.org/?foo=bar' + ), + 'expectation' => array( 'request' => array( 'uri' => array('host' => 'www.cakephp.org') - ) - , 'config' => array( + ), + 'config' => array( 'request' => array( 'uri' => array('host' => 'www.cakephp.org') - ) - , 'host' => '192.168.0.1' + ), + 'host' => '192.168.0.1' ) ) - ) - , 'reset4' => array( + ), + 'reset4' => array( 'request.uri.query' => array() - ) - , 4 => array( - 'request' => array('header' => array('Foo@woo' => 'bar-value')) - , 'expectation' => array( + ), + array( + 'request' => array( + 'header' => array('Foo@woo' => 'bar-value') + ), + 'expectation' => array( 'request' => array( - 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nFoo\"@\"woo: bar-value\r\n" - , 'line' => "GET / HTTP/1.1\r\n" + 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nFoo\"@\"woo: bar-value\r\n", + 'line' => "GET / HTTP/1.1\r\n" ) ) - ) - , 5 => array( - 'request' => array('header' => array('Foo@woo' => 'bar-value', 'host' => 'foo.com'), 'uri' => 'http://www.cakephp.org/') - , 'expectation' => array( + ), + array( + 'request' => array('header' => array('Foo@woo' => 'bar-value', 'host' => 'foo.com'), 'uri' => 'http://www.cakephp.org/'), + 'expectation' => array( 'request' => array( 'header' => "Host: foo.com\r\nConnection: close\r\nUser-Agent: CakePHP\r\nFoo\"@\"woo: bar-value\r\n" - ) - , 'config' => array( + ), + 'config' => array( 'host' => 'www.cakephp.org' ) ) - ) - , 6 => array( - 'request' => array('header' => "Foo: bar\r\n") - , 'expectation' => array( + ), + array( + 'request' => array('header' => "Foo: bar\r\n"), + 'expectation' => array( 'request' => array( 'header' => "Foo: bar\r\n" ) ) - ) - , 7 => array( - 'request' => array('header' => "Foo: bar\r\n", 'uri' => 'http://www.cakephp.org/search?q=http_socket#ignore-me') - , 'expectation' => array( + ), + array( + 'request' => array('header' => "Foo: bar\r\n", 'uri' => 'http://www.cakephp.org/search?q=http_socket#ignore-me'), + 'expectation' => array( 'request' => array( 'uri' => array( - 'path' => '/search' - , 'query' => array('q' => 'http_socket') - , 'fragment' => 'ignore-me' - ) - , 'line' => "GET /search?q=http_socket HTTP/1.1\r\n" + 'path' => '/search', + 'query' => array('q' => 'http_socket'), + 'fragment' => 'ignore-me' + ), + 'line' => "GET /search?q=http_socket HTTP/1.1\r\n" ) ) - ) - , 'reset8' => array( + ), + 'reset8' => array( 'request.uri.query' => array() - ) - , 8 => array( - 'request' => array('method' => 'POST', 'uri' => 'http://www.cakephp.org/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today')) - , 'expectation' => array( + ), + array( + 'request' => array( + 'method' => 'POST', + 'uri' => 'http://www.cakephp.org/posts/add', + 'body' => array( + 'name' => 'HttpSocket-is-released', + 'date' => 'today' + ) + ), + 'expectation' => array( 'request' => array( - 'method' => 'POST' - , 'uri' => array( - 'path' => '/posts/add' - , 'fragment' => null - ) - , 'body' => "name=HttpSocket-is-released&date=today" - , 'line' => "POST /posts/add HTTP/1.1\r\n" - , 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n" - , 'raw' => "name=HttpSocket-is-released&date=today" + 'method' => 'POST', + 'uri' => array( + 'path' => '/posts/add', + 'fragment' => null + ), + 'body' => "name=HttpSocket-is-released&date=today", + 'line' => "POST /posts/add HTTP/1.1\r\n", + 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n", + 'raw' => "name=HttpSocket-is-released&date=today" ) ) - ) - , 9 => array( - 'request' => array('method' => 'POST', 'uri' => 'http://www.cakephp.org:8080/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today')) - , 'expectation' => array( + ), + array( + 'request' => array( + 'method' => 'POST', + 'uri' => 'http://www.cakephp.org:8080/posts/add', + 'body' => array( + 'name' => 'HttpSocket-is-released', + 'date' => 'today' + ) + ), + 'expectation' => array( 'config' => array( - 'port' => 8080 - , 'request' => array( + 'port' => 8080, + 'request' => array( 'uri' => array( 'port' => 8080 ) ) - ) - , 'request' => array( + ), + 'request' => array( 'uri' => array( 'port' => 8080 - ) - , 'header' => "Host: www.cakephp.org:8080\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n" + ), + 'header' => "Host: www.cakephp.org:8080\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n" ) ) - ) - , 10 => array( - 'request' => array('method' => 'POST', 'uri' => 'https://www.cakephp.org/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today')) - , 'expectation' => array( + ), + array( + 'request' => array( + 'method' => 'POST', + 'uri' => 'https://www.cakephp.org/posts/add', + 'body' => array( + 'name' => 'HttpSocket-is-released', + 'date' => 'today' + ) + ), + 'expectation' => array( 'config' => array( - 'port' => 443 - , 'request' => array( + 'port' => 443, + 'request' => array( 'uri' => array( - 'scheme' => 'https' - , 'port' => 443 + 'scheme' => 'https', + 'port' => 443 ) ) - ) - , 'request' => array( + ), + 'request' => array( 'uri' => array( - 'scheme' => 'https' - , 'port' => 443 - ) - , 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n" + 'scheme' => 'https', + 'port' => 443 + ), + 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n" ) ) - ) - , 11 => array( + ), + array( 'request' => array( - 'method' => 'POST', - 'uri' => 'https://www.cakephp.org/posts/add', - 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today'), - 'cookies' => array('foo' => array('value' => 'bar')) - ) - , 'expectation' => array( + 'method' => 'POST', + 'uri' => 'https://www.cakephp.org/posts/add', + 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today'), + 'cookies' => array('foo' => array('value' => 'bar')) + ), + 'expectation' => array( 'request' => array( 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\nCookie: foo=bar\r\n", 'cookies' => array( @@ -526,10 +533,10 @@ class HttpSocketTest extends CakeTestCase { $this->Socket->request($test['request']); $raw = $expectation['request']['raw']; - $expectation['request']['raw'] = $expectation['request']['line'].$expectation['request']['header']."\r\n".$raw; + $expectation['request']['raw'] = $expectation['request']['line'] . $expectation['request']['header'] . "\r\n" . $raw; $r = array('config' => $this->Socket->config, 'request' => $this->Socket->request); - $v = $this->assertEquals($r, $expectation, '%s in test #'.$i.' '); + $v = $this->assertEquals($r, $expectation, 'Failed test #' . $i . ' '); $expectation['request']['raw'] = $raw; } @@ -548,10 +555,9 @@ class HttpSocketTest extends CakeTestCase { /** * testRequest2 method * - * @access public * @return void */ - function testRequest2() { + public function testRequest2() { $this->Socket->reset(); $request = array('uri' => 'htpp://www.cakephp.org/'); $number = mt_rand(0, 9999999); @@ -561,17 +567,16 @@ class HttpSocketTest extends CakeTestCase { $this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse)); $this->Socket->expects($this->once())->method('write') ->with("GET / HTTP/1.1\r\nHost: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\n\r\n"); - $response = $this->Socket->request($request); + $response = (string)$this->Socket->request($request); $this->assertEquals($response, "

    Hello, your lucky number is " . $number . "

    "); } /** * testRequest3 method * - * @access public * @return void */ - function testRequest3() { + public function testRequest3() { $request = array('uri' => 'htpp://www.cakephp.org/'); $serverResponse = "HTTP/1.x 200 OK\r\nSet-Cookie: foo=bar\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n

    This is a cookie test!

    "; $this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse)); @@ -584,17 +589,175 @@ class HttpSocketTest extends CakeTestCase { ) ); $this->assertEqual($result, $expect); - $this->assertEqual($this->Socket->config['request']['cookies'], $expect); + $this->assertEqual($this->Socket->config['request']['cookies']['www.cakephp.org'], $expect); $this->assertFalse($this->Socket->connected); } +/** + * testRequestWithResource + * + * @return void + */ + public function testRequestWithResource() { + $serverResponse = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n

    This is a test!

    "; + $this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse)); + $this->Socket->expects($this->at(2))->method('read')->will($this->returnValue(false)); + $this->Socket->expects($this->at(4))->method('read')->will($this->returnValue($serverResponse)); + $this->Socket->connected = true; + + $f = fopen(TMP . 'download.txt', 'w'); + $this->skipUnless($f, 'Can not write in TMP directory.'); + + $this->Socket->setContentResource($f); + $result = (string)$this->Socket->request('http://www.cakephp.org/'); + $this->assertEqual($result, ''); + $this->assertEqual($this->Socket->response['header']['Server'], 'CakeHttp Server'); + fclose($f); + $this->assertEqual(file_get_contents(TMP . 'download.txt'), '

    This is a test!

    '); + unlink(TMP . 'download.txt'); + + $this->Socket->setContentResource(false); + $result = (string)$this->Socket->request('http://www.cakephp.org/'); + $this->assertEqual($result, '

    This is a test!

    '); + } + +/** + * testRequestWithCrossCookie + * + * @return void + */ + public function testRequestWithCrossCookie() { + $this->Socket->connected = true; + $this->Socket->config['request']['cookies'] = array(); + + $serverResponse = "HTTP/1.x 200 OK\r\nSet-Cookie: foo=bar\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n

    This is a test!

    "; + $this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse)); + $this->Socket->expects($this->at(2))->method('read')->will($this->returnValue(false)); + $expected = array('www.cakephp.org' => array('foo' => array('value' => 'bar'))); + $this->Socket->request('http://www.cakephp.org/'); + $this->assertEqual($this->Socket->config['request']['cookies'], $expected); + + $serverResponse = "HTTP/1.x 200 OK\r\nSet-Cookie: bar=foo\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n

    This is a test!

    "; + $this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse)); + $this->Socket->expects($this->at(2))->method('read')->will($this->returnValue(false)); + $this->Socket->request('http://www.cakephp.org/other'); + $this->assertEqual($this->Socket->request['cookies'], array('foo' => array('value' => 'bar'))); + $expected['www.cakephp.org'] += array('bar' => array('value' => 'foo')); + $this->assertEqual($this->Socket->config['request']['cookies'], $expected); + + $serverResponse = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n

    This is a test!

    "; + $this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse)); + $this->Socket->expects($this->at(2))->method('read')->will($this->returnValue(false)); + $this->Socket->request('/other2'); + $this->assertEqual($this->Socket->config['request']['cookies'], $expected); + + $serverResponse = "HTTP/1.x 200 OK\r\nSet-Cookie: foobar=ok\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n

    This is a test!

    "; + $this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse)); + $this->Socket->expects($this->at(2))->method('read')->will($this->returnValue(false)); + $this->Socket->request('http://www.cake.com'); + $this->assertTrue(empty($this->Socket->request['cookies'])); + $expected['www.cake.com'] = array('foobar' => array('value' => 'ok')); + $this->assertEqual($this->Socket->config['request']['cookies'], $expected); + } + +/** + * testRequestCustomResponse + * + * @return void + */ + public function testRequestCustomResponse() { + $this->Socket->connected = true; + $serverResponse = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n

    This is a test!

    "; + $this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse)); + $this->Socket->expects($this->at(2))->method('read')->will($this->returnValue(false)); + + $this->Socket->responseClass = 'CustomResponse'; + $response = $this->Socket->request('http://www.cakephp.org/'); + $this->assertIsA($response, 'CustomResponse'); + $this->assertEqual($response->first10, 'HTTP/1.x 2'); + } + +/** + * testProxy method + * + * @return void + */ + public function testProxy() { + $this->Socket->reset(); + $this->Socket->expects($this->any())->method('connect')->will($this->returnValue(true)); + $this->Socket->expects($this->any())->method('read')->will($this->returnValue(false)); + + $this->Socket->configProxy('proxy.server', 123); + $expected = "GET http://www.cakephp.org/ HTTP/1.1\r\nHost: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\n\r\n"; + $this->Socket->request('http://www.cakephp.org/'); + $this->assertEqual($this->Socket->request['raw'], $expected); + $this->assertEqual($this->Socket->config['host'], 'proxy.server'); + $this->assertEqual($this->Socket->config['port'], 123); + $expected = array( + 'host' => 'proxy.server', + 'port' => 123, + 'method' => null, + 'user' => null, + 'pass' => null + ); + $this->assertEqual($this->Socket->request['proxy'], $expected); + + $expected = "GET http://www.cakephp.org/bakery HTTP/1.1\r\nHost: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\n\r\n"; + $this->Socket->request('/bakery'); + $this->assertEqual($this->Socket->request['raw'], $expected); + $this->assertEqual($this->Socket->config['host'], 'proxy.server'); + $this->assertEqual($this->Socket->config['port'], 123); + $expected = array( + 'host' => 'proxy.server', + 'port' => 123, + 'method' => null, + 'user' => null, + 'pass' => null + ); + $this->assertEqual($this->Socket->request['proxy'], $expected); + + $expected = "GET http://www.cakephp.org/ HTTP/1.1\r\nHost: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nProxy-Authorization: Test mark.secret\r\n\r\n"; + $this->Socket->configProxy('proxy.server', 123, 'Test', 'mark', 'secret'); + $this->Socket->request('http://www.cakephp.org/'); + $this->assertEqual($this->Socket->request['raw'], $expected); + $this->assertEqual($this->Socket->config['host'], 'proxy.server'); + $this->assertEqual($this->Socket->config['port'], 123); + $expected = array( + 'host' => 'proxy.server', + 'port' => 123, + 'method' => 'Test', + 'user' => 'mark', + 'pass' => 'secret' + ); + $this->assertEqual($this->Socket->request['proxy'], $expected); + + $this->Socket->configAuth('Test', 'login', 'passwd'); + $expected = "GET http://www.cakephp.org/ HTTP/1.1\r\nHost: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nProxy-Authorization: Test mark.secret\r\nAuthorization: Test login.passwd\r\n\r\n"; + $this->Socket->request('http://www.cakephp.org/'); + $this->assertEqual($this->Socket->request['raw'], $expected); + $expected = array( + 'host' => 'proxy.server', + 'port' => 123, + 'method' => 'Test', + 'user' => 'mark', + 'pass' => 'secret' + ); + $this->assertEqual($this->Socket->request['proxy'], $expected); + $expected = array( + 'Test' => array( + 'user' => 'login', + 'pass' => 'passwd' + ) + ); + $this->assertEqual($this->Socket->request['auth'], $expected); + } + /** * testUrl method * - * @access public * @return void */ - function testUrl() { + public function testUrl() { $this->Socket->reset(true); $this->assertEquals($this->Socket->url(true), false); @@ -646,10 +809,9 @@ class HttpSocketTest extends CakeTestCase { /** * testGet method * - * @access public * @return void */ - function testGet() { + public function testGet() { $this->RequestSocket->reset(); $this->RequestSocket->expects($this->at(0)) @@ -659,7 +821,7 @@ class HttpSocketTest extends CakeTestCase { $this->RequestSocket->expects($this->at(1)) ->method('request') ->with(array('method' => 'GET', 'uri' => 'http://www.google.com/?foo=bar')); - + $this->RequestSocket->expects($this->at(2)) ->method('request') ->with(array('method' => 'GET', 'uri' => 'http://www.google.com/?foo=bar')); @@ -670,13 +832,32 @@ class HttpSocketTest extends CakeTestCase { $this->RequestSocket->expects($this->at(4)) ->method('request') - ->with(array('method' => 'GET', 'uri' => 'http://www.google.com/', 'auth' => array('user' => 'foo', 'pass' => 'bar'))); + ->with(array('method' => 'GET', 'uri' => 'http://www.google.com/', 'version' => '1.0')); $this->RequestSocket->get('http://www.google.com/'); $this->RequestSocket->get('http://www.google.com/', array('foo' => 'bar')); $this->RequestSocket->get('http://www.google.com/', 'foo=bar'); $this->RequestSocket->get('http://www.google.com/?foo=bar', array('foobar' => '42', 'foo' => '23')); - $this->RequestSocket->get('http://www.google.com/', null, array('auth' => array('user' => 'foo', 'pass' => 'bar'))); + $this->RequestSocket->get('http://www.google.com/', null, array('version' => '1.0')); + } + +/** + * Test authentication + * + * @return void + */ + public function testAuth() { + $socket = new MockHttpSocket(); + $socket->get('http://mark:secret@example.com/test'); + $this->assertTrue(strpos($socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false); + + $socket->configAuth(false); + $socket->get('http://example.com/test'); + $this->assertFalse(strpos($socket->request['header'], 'Authorization:')); + + $socket->configAuth('Test', 'mark', 'passwd'); + $socket->get('http://example.com/test'); + $this->assertTrue(strpos($socket->request['header'], 'Authorization: Test mark.passwd') !== false); } /** @@ -684,33 +865,26 @@ class HttpSocketTest extends CakeTestCase { * * @return void */ - function testConsecutiveGetResetsAuthCredentials() { + public function testConsecutiveGetResetsAuthCredentials() { $socket = new MockHttpSocket(); - $socket->config['request']['auth'] = array( - 'method' => 'Basic', - 'user' => 'mark', - 'pass' => 'secret' - ); $socket->get('http://mark:secret@example.com/test'); $this->assertEqual($socket->request['uri']['user'], 'mark'); $this->assertEqual($socket->request['uri']['pass'], 'secret'); + $this->assertTrue(strpos($socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false); $socket->get('/test2'); - $this->assertEqual($socket->request['auth']['user'], 'mark'); - $this->assertEqual($socket->request['auth']['pass'], 'secret'); + $this->assertTrue(strpos($socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false); $socket->get('/test3'); - $this->assertEqual($socket->request['auth']['user'], 'mark'); - $this->assertEqual($socket->request['auth']['pass'], 'secret'); + $this->assertTrue(strpos($socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false); } /** * testPostPutDelete method * - * @access public * @return void */ - function testPost() { + public function testPost() { $this->RequestSocket->reset(); $this->RequestSocket->expects($this->at(0)) ->method('request') @@ -729,7 +903,12 @@ class HttpSocketTest extends CakeTestCase { $this->RequestSocket->post('http://www.google.com/', null, array('line' => 'Hey Server')); } - function testPut() { +/** + * testPut + * + * @return void + */ + public function testPut() { $this->RequestSocket->reset(); $this->RequestSocket->expects($this->at(0)) ->method('request') @@ -748,7 +927,12 @@ class HttpSocketTest extends CakeTestCase { $this->RequestSocket->put('http://www.google.com/', null, array('line' => 'Hey Server')); } - function testDelete() { +/** + * testDelete + * + * @return void + */ + public function testDelete() { $this->RequestSocket->reset(); $this->RequestSocket->expects($this->at(0)) ->method('request') @@ -767,211 +951,12 @@ class HttpSocketTest extends CakeTestCase { $this->RequestSocket->delete('http://www.google.com/', null, array('line' => 'Hey Server')); } -/** - * testParseResponse method - * - * @access public - * @return void - */ - function testParseResponse() { - $this->Socket->reset(); - - $r = $this->Socket->parseResponse(array('foo' => 'bar')); - $this->assertEquals($r, array('foo' => 'bar')); - - $r = $this->Socket->parseResponse(true); - $this->assertEquals($r, false); - - $r = $this->Socket->parseResponse("HTTP Foo\r\nBar: La"); - $this->assertEquals($r, false); - - $tests = array( - 'simple-request' => array( - 'response' => array( - 'status-line' => "HTTP/1.x 200 OK\r\n", - 'header' => "Date: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\n", - 'body' => "

    Hello World

    \r\n

    It's good to be html

    " - ) - , 'expectations' => array( - 'status.http-version' => 'HTTP/1.x', - 'status.code' => 200, - 'status.reason-phrase' => 'OK', - 'header' => $this->Socket->parseHeader("Date: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\n"), - 'body' => "

    Hello World

    \r\n

    It's good to be html

    " - ) - ), - 'no-header' => array( - 'response' => array( - 'status-line' => "HTTP/1.x 404 OK\r\n", - 'header' => null, - ) - , 'expectations' => array( - 'status.code' => 404, - 'header' => array() - ) - ), - 'chunked' => array( - 'response' => array( - 'header' => "Transfer-Encoding: chunked\r\n", - 'body' => "19\r\nThis is a chunked message\r\n0\r\n" - ), - 'expectations' => array( - 'body' => "This is a chunked message", - 'header' => $this->Socket->parseHeader("Transfer-Encoding: chunked\r\n") - ) - ), - 'enitity-header' => array( - 'response' => array( - 'body' => "19\r\nThis is a chunked message\r\n0\r\nFoo: Bar\r\n" - ), - 'expectations' => array( - 'header' => $this->Socket->parseHeader("Transfer-Encoding: chunked\r\nFoo: Bar\r\n") - ) - ), - 'enitity-header-combine' => array( - 'response' => array( - 'header' => "Transfer-Encoding: chunked\r\nFoo: Foobar\r\n" - ), - 'expectations' => array( - 'header' => $this->Socket->parseHeader("Transfer-Encoding: chunked\r\nFoo: Foobar\r\nFoo: Bar\r\n") - ) - ) - ); - - $testResponse = array(); - $expectations = array(); - - foreach ($tests as $name => $test) { - - $testResponse = array_merge($testResponse, $test['response']); - $testResponse['response'] = $testResponse['status-line'].$testResponse['header']."\r\n".$testResponse['body']; - $r = $this->Socket->parseResponse($testResponse['response']); - $expectations = array_merge($expectations, $test['expectations']); - - foreach ($expectations as $property => $expectedVal) { - $val = Set::extract($r, $property); - $this->assertEquals($val, $expectedVal, 'Test "'.$name.'": response.'.$property.' - %s'); - } - - foreach (array('status-line', 'header', 'body', 'response') as $field) { - $this->assertEquals($r['raw'][$field], $testResponse[$field], 'Test response.raw.'.$field.': %s'); - } - } - } - -/** - * testDecodeBody method - * - * @access public - * @return void - */ - function testDecodeBody() { - $this->Socket->reset(); - - $r = $this->Socket->decodeBody(true); - $this->assertEquals($r, false); - - $r = $this->Socket->decodeBody('Foobar', false); - $this->assertEquals($r, array('body' => 'Foobar', 'header' => false)); - - $encoding = 'chunked'; - $sample = array( - 'encoded' => "19\r\nThis is a chunked message\r\n0\r\n", - 'decoded' => array('body' => "This is a chunked message", 'header' => false) - ); - - $r = $this->Socket->decodeBody($sample['encoded'], $encoding); - $this->assertEquals($r, $sample['decoded']); - } - - function testDecodeFooCoded() { - $this->Socket->reset(); - - $r = $this->Socket->decodeBody(true); - $this->assertEquals($r, false); - - $r = $this->Socket->decodeBody('Foobar', false); - $this->assertEquals($r, array('body' => 'Foobar', 'header' => false)); - - $encoding = 'foo-bar'; - $sample = array( - 'encoded' => '!Foobar!', - 'decoded' => array('body' => '!Foobar!', 'header' => false), - ); - - $this->Socket->quirksMode = true; - $r = $this->Socket->decodeBody($sample['encoded'], $encoding); - $this->assertEquals($r, $sample['decoded']); - $this->Socket->quirksMode = false; - - $this->expectError(); - $r = $this->Socket->decodeBody($sample['encoded'], $encoding); - $this->assertEquals($r, $sample['decoded']); - } - -/** - * testDecodeChunkedBody method - * - * @access public - * @return void - */ - function testDecodeChunkedBody() { - $this->Socket->reset(); - - $r = $this->Socket->decodeChunkedBody(true); - $this->assertEquals($r, false); - - $encoded = "19\r\nThis is a chunked message\r\n0\r\n"; - $decoded = "This is a chunked message"; - $r = $this->Socket->decodeChunkedBody($encoded); - $this->assertEquals($r['body'], $decoded); - $this->assertEquals($r['header'], false); - - $encoded = "19 \r\nThis is a chunked message\r\n0\r\n"; - $r = $this->Socket->decodeChunkedBody($encoded); - $this->assertEquals($r['body'], $decoded); - - $encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\n0\r\n"; - $decoded = "This is a chunked message\nThat is cool\n"; - $r = $this->Socket->decodeChunkedBody($encoded); - $this->assertEquals($r['body'], $decoded); - $this->assertEquals($r['header'], false); - - $encoded = "19\r\nThis is a chunked message\r\nE;foo-chunk=5\r\n\nThat is cool\n\r\n0\r\n"; - $r = $this->Socket->decodeChunkedBody($encoded); - $this->assertEquals($r['body'], $decoded); - $this->assertEquals($r['header'], false); - - $encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\n0\r\nfoo-header: bar\r\ncake: PHP\r\n\r\n"; - $r = $this->Socket->decodeChunkedBody($encoded); - $this->assertEquals($r['body'], $decoded); - $this->assertEquals($r['header'], array('Foo-Header' => 'bar', 'Cake' => 'PHP')); - - $this->Socket->quirksMode = true; - $encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\nfoo-header: bar\r\ncake: PHP\r\n\r\n"; - $r = $this->Socket->decodeChunkedBody($encoded); - $this->assertEquals($r['body'], $decoded); - $this->assertEquals($r['header'], array('Foo-Header' => 'bar', 'Cake' => 'PHP')); - - $encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\n"; - $r = $this->Socket->decodeChunkedBody($encoded); - $this->assertEquals($r['body'], $decoded); - $this->assertEquals($r['header'], false); - - $this->Socket->quirksMode = false; - $encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\n"; - $this->expectError(); - $r = $this->Socket->decodeChunkedBody($encoded); - $this->assertEquals($r, false); - } - /** * testBuildRequestLine method * - * @access public * @return void */ - function testBuildRequestLine() { + public function testBuildRequestLine() { $this->Socket->reset(); $this->Socket->quirksMode = true; @@ -1012,7 +997,7 @@ class HttpSocketTest extends CakeTestCase { $request['method'] = 'GET'; $this->Socket->quirksMode = true; $r = $this->Socket->buildRequestLine($request); - $this->assertEquals($r, "GET * HTTP/1.1\r\n"); + $this->assertEquals($r, "GET * HTTP/1.1\r\n"); $r = $this->Socket->buildRequestLine("GET * HTTP/1.1\r\n"); $this->assertEquals($r, "GET * HTTP/1.1\r\n"); @@ -1021,10 +1006,9 @@ class HttpSocketTest extends CakeTestCase { /** * testBadBuildRequestLine method * - * @access public * @return void */ - function testBadBuildRequestLine() { + public function testBadBuildRequestLine() { $this->expectError(); $r = $this->Socket->buildRequestLine('Foo'); } @@ -1032,10 +1016,9 @@ class HttpSocketTest extends CakeTestCase { /** * testBadBuildRequestLine2 method * - * @access public * @return void */ - function testBadBuildRequestLine2() { + public function testBadBuildRequestLine2() { $this->expectError(); $r = $this->Socket->buildRequestLine("GET * HTTP/1.1\r\n"); } @@ -1043,10 +1026,9 @@ class HttpSocketTest extends CakeTestCase { /** * Asserts that HttpSocket::parseUri is working properly * - * @access public * @return void */ - function testParseUri() { + public function testParseUri() { $this->Socket->reset(); $uri = $this->Socket->parseUri(array('invalid' => 'uri-string')); @@ -1077,7 +1059,7 @@ class HttpSocketTest extends CakeTestCase { $this->assertEquals($uri, array( 'scheme' => 'http', 'host' => 'www.cakephp.org', - 'path' => '/', + 'path' => '/' )); $uri = $this->Socket->parseUri('http://www.cakephp.org', true); @@ -1142,7 +1124,7 @@ class HttpSocketTest extends CakeTestCase { $this->assertEquals($uri, array( 'scheme' => 'http', 'host' => 'www.google.com', - 'port' => 8080, + 'port' => 8080 )); $uri = $this->Socket->parseUri('http://www.cakephp.org/?param1=value1¶m2=value2%3Dvalue3'); @@ -1171,10 +1153,9 @@ class HttpSocketTest extends CakeTestCase { /** * Tests that HttpSocket::buildUri can turn all kinds of uri arrays (and strings) into fully or partially qualified URI's * - * @access public * @return void */ - function testBuildUri() { + public function testBuildUri() { $this->Socket->reset(); $r = $this->Socket->buildUri(true); @@ -1238,10 +1219,9 @@ class HttpSocketTest extends CakeTestCase { /** * Asserts that HttpSocket::parseQuery is working properly * - * @access public * @return void */ - function testParseQuery() { + public function testParseQuery() { $this->Socket->reset(); $query = $this->Socket->parseQuery(array('framework' => 'cakephp')); @@ -1290,16 +1270,10 @@ class HttpSocketTest extends CakeTestCase { $query = $this->Socket->parseQuery('a[][]=foo&a[bar]=php&a[][]=bar&a[][]=cake'); $expectedQuery = array( 'a' => array( - 0 => array( - 0 => 'foo' - ), + array('foo'), 'bar' => 'php', - 1 => array( - 0 => 'bar' - ), - array( - 0 => 'cake' - ) + array('bar'), + array('cake') ) ); $this->assertEquals($query, $expectedQuery); @@ -1345,10 +1319,9 @@ class HttpSocketTest extends CakeTestCase { * Tests that HttpSocket::buildHeader can turn a given $header array into a proper header string according to * HTTP 1.1 specs. * - * @access public * @return void */ - function testBuildHeader() { + public function testBuildHeader() { $this->Socket->reset(); $r = $this->Socket->buildHeader(true); @@ -1380,118 +1353,13 @@ class HttpSocketTest extends CakeTestCase { } -/** - * Test that HttpSocket::parseHeader can take apart a given (and valid) $header string and turn it into an array. - * - * @access public - * @return void - */ - function testParseHeader() { - $this->Socket->reset(); - - $r = $this->Socket->parseHeader(array('foo' => 'Bar', 'fOO-bAr' => 'quux')); - $this->assertEquals($r, array('Foo' => 'Bar', 'Foo-Bar' => 'quux')); - - $r = $this->Socket->parseHeader(true); - $this->assertEquals($r, false); - - $header = "Host: cakephp.org\t\r\n"; - $r = $this->Socket->parseHeader($header); - $expected = array( - 'Host' => 'cakephp.org' - ); - $this->assertEquals($r, $expected); - - $header = "Date:Sat, 07 Apr 2007 10:10:25 GMT\r\nX-Powered-By: PHP/5.1.2\r\n"; - $r = $this->Socket->parseHeader($header); - $expected = array( - 'Date' => 'Sat, 07 Apr 2007 10:10:25 GMT' - , 'X-Powered-By' => 'PHP/5.1.2' - ); - $this->assertEquals($r, $expected); - - $header = "people: Jim,John\r\nfoo-LAND: Bar\r\ncAKe-PHP: rocks\r\n"; - $r = $this->Socket->parseHeader($header); - $expected = array( - 'People' => 'Jim,John' - , 'Foo-Land' => 'Bar' - , 'Cake-Php' => 'rocks' - ); - $this->assertEquals($r, $expected); - - $header = "People: Jim,John,Tim\r\nPeople: Lisa,Tina,Chelsea\r\n"; - $r = $this->Socket->parseHeader($header); - $expected = array( - 'People' => array('Jim,John,Tim', 'Lisa,Tina,Chelsea') - ); - $this->assertEquals($r, $expected); - - $header = "Multi-Line: I am a \r\nmulti line\t\r\nfield value.\r\nSingle-Line: I am not\r\n"; - $r = $this->Socket->parseHeader($header); - $expected = array( - 'Multi-Line' => "I am a\r\nmulti line\r\nfield value." - , 'Single-Line' => 'I am not' - ); - $this->assertEquals($r, $expected); - - $header = "Esc\"@\"ped: value\r\n"; - $r = $this->Socket->parseHeader($header); - $expected = array( - 'Esc@ped' => 'value' - ); - $this->assertEquals($r, $expected); - } - -/** - * testParseCookies method - * - * @access public - * @return void - */ - function testParseCookies() { - $header = array( - 'Set-Cookie' => array( - 'foo=bar', - 'people=jim,jack,johnny";";Path=/accounts', - 'google=not=nice' - ), - 'Transfer-Encoding' => 'chunked', - 'Date' => 'Sun, 18 Nov 2007 18:57:42 GMT', - ); - $cookies = $this->Socket->parseCookies($header); - $expected = array( - 'foo' => array( - 'value' => 'bar' - ), - 'people' => array( - 'value' => 'jim,jack,johnny";"', - 'path' => '/accounts', - ), - 'google' => array( - 'value' => 'not=nice', - ) - ); - $this->assertEqual($cookies, $expected); - - $header['Set-Cookie'][] = 'cakephp=great; Secure'; - $expected['cakephp'] = array('value' => 'great', 'secure' => true); - $cookies = $this->Socket->parseCookies($header); - $this->assertEqual($cookies, $expected); - - $header['Set-Cookie'] = 'foo=bar'; - unset($expected['people'], $expected['cakephp'], $expected['google']); - $cookies = $this->Socket->parseCookies($header); - $this->assertEqual($cookies, $expected); - } - /** * testBuildCookies method * * @return void - * @access public * @todo Test more scenarios */ - function testBuildCookies() { + public function testBuildCookies() { $cookies = array( 'foo' => array( 'value' => 'bar' @@ -1509,10 +1377,9 @@ class HttpSocketTest extends CakeTestCase { /** * Tests that HttpSocket::_tokenEscapeChars() returns the right characters. * - * @access public * @return void */ - function testTokenEscapeChars() { + public function testTokenEscapeChars() { $this->Socket->reset(); $expected = array( @@ -1535,19 +1402,18 @@ class HttpSocketTest extends CakeTestCase { /** * Test that HttpSocket::escapeToken is escaping all characters as descriped in RFC 2616 (HTTP 1.1 specs) * - * @access public * @return void */ - function testEscapeToken() { + public function testEscapeToken() { $this->Socket->reset(); $this->assertEquals($this->Socket->escapeToken('Foo'), 'Foo'); $escape = $this->Socket->tokenEscapeChars(false); foreach ($escape as $char) { - $token = 'My-special-'.$char.'-Token'; + $token = 'My-special-' . $char . '-Token'; $escapedToken = $this->Socket->escapeToken($token); - $expectedToken = 'My-special-"'.$char.'"-Token'; + $expectedToken = 'My-special-"' . $char . '"-Token'; $this->assertEquals($escapedToken, $expectedToken, 'Test token escaping for ASCII '.ord($char)); } @@ -1558,40 +1424,13 @@ class HttpSocketTest extends CakeTestCase { $this->assertEquals($expectedToken, $escapedToken); } -/** - * Test that escaped token strings are properly unescaped by HttpSocket::unescapeToken - * - * @access public - * @return void - */ - function testUnescapeToken() { - $this->Socket->reset(); - - $this->assertEquals($this->Socket->unescapeToken('Foo'), 'Foo'); - - $escape = $this->Socket->tokenEscapeChars(false); - foreach ($escape as $char) { - $token = 'My-special-"'.$char.'"-Token'; - $unescapedToken = $this->Socket->unescapeToken($token); - $expectedToken = 'My-special-'.$char.'-Token'; - - $this->assertEquals($unescapedToken, $expectedToken, 'Test token unescaping for ASCII '.ord($char)); - } - - $token = 'Extreme-":"Token-" "-""""@"-test'; - $escapedToken = $this->Socket->unescapeToken($token); - $expectedToken = 'Extreme-:Token- -"@-test'; - $this->assertEquals($expectedToken, $escapedToken); - } - /** * This tests asserts HttpSocket::reset() resets a HttpSocket instance to it's initial state (before Object::__construct * got executed) * - * @access public * @return void */ - function testReset() { + public function testReset() { $this->Socket->reset(); $initialState = get_class_vars('HttpSocket'); @@ -1612,10 +1451,9 @@ class HttpSocketTest extends CakeTestCase { * This tests asserts HttpSocket::reset(false) resets certain HttpSocket properties to their initial state (before * Object::__construct got executed). * - * @access public * @return void */ - function testPartialReset() { + public function testPartialReset() { $this->Socket->reset(); $partialResetProperties = array('request', 'response'); diff --git a/cake/tests/cases/libs/i18n.test.php b/cake/tests/cases/libs/i18n.test.php index 1ca37bcb1..5fdf3a93a 100644 --- a/cake/tests/cases/libs/i18n.test.php +++ b/cake/tests/cases/libs/i18n.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.5432 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Core', 'i18n'); /** * I18nTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class I18nTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/inflector.test.php b/cake/tests/cases/libs/inflector.test.php index 4d383c887..3c04e0363 100644 --- a/cake/tests/cases/libs/inflector.test.php +++ b/cake/tests/cases/libs/inflector.test.php @@ -15,7 +15,7 @@ * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://book.cakephp.org/view/1196/Testing * @package cake.tests - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.4206 * @license Open Group Test Suite License (http://www.opensource.org/licenses/opengroup.php) */ @@ -30,7 +30,7 @@ App::import('Core', 'Inflector'); * Short description for class. * * @package cake.tests - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class InflectorTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/l10n.test.php b/cake/tests/cases/libs/l10n.test.php index a1b35aee1..dd7a5a79c 100644 --- a/cake/tests/cases/libs/l10n.test.php +++ b/cake/tests/cases/libs/l10n.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.5432 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Core', 'l10n'); /** * L10nTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class L10nTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/log/file_log.test.php b/cake/tests/cases/libs/log/file_log.test.php index f07ab9771..d861426b3 100644 --- a/cake/tests/cases/libs/log/file_log.test.php +++ b/cake/tests/cases/libs/log/file_log.test.php @@ -12,8 +12,7 @@ * * @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.log + * @package cake.tests.cases.libs.log * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Core', 'log/FileLog'); /** * CakeLogTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class FileLogTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/magic_db.test.php b/cake/tests/cases/libs/magic_db.test.php index e871a541d..80586925b 100644 --- a/cake/tests/cases/libs/magic_db.test.php +++ b/cake/tests/cases/libs/magic_db.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 1.2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ if (!class_exists('MagicDb')) { /** * The test class for the MagicDb class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class MagicDbTest extends UnitTestCase { /** @@ -144,14 +142,12 @@ class MagicDbTest extends UnitTestCase { /** * Test data holding object for MagicDb tests * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ /** * MagicDbTestData class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class MagicDbTestData extends Object { /** diff --git a/cake/tests/cases/libs/model/behavior_collection.test.php b/cake/tests/cases/libs/model/behavior_collection.test.php index 7528d3b0a..6fa7756b7 100644 --- a/cake/tests/cases/libs/model/behavior_collection.test.php +++ b/cake/tests/cases/libs/model/behavior_collection.test.php @@ -14,8 +14,7 @@ * * @copyright CakePHP(tm) : Rapid Development Framework (http://cakephp.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model * @since 1.2 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,8 +24,7 @@ require_once dirname(__FILE__) . DS . 'models.php'; /** * TestBehavior class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class TestBehavior extends ModelBehavior { @@ -46,7 +44,7 @@ class TestBehavior extends ModelBehavior { * @access public * @return void */ - function setup(&$model, $config = array()) { + function setup($model, $config = array()) { parent::setup($model, $config); if (isset($config['mangle'])) { $config['mangle'] .= ' mangled'; @@ -62,7 +60,7 @@ class TestBehavior extends ModelBehavior { * @access public * @return void */ - function beforeFind(&$model, $query) { + function beforeFind($model, $query) { $settings = $this->settings[$model->alias]; if (!isset($settings['beforeFind']) || $settings['beforeFind'] == 'off') { return parent::beforeFind($model, $query); @@ -91,7 +89,7 @@ class TestBehavior extends ModelBehavior { * @access public * @return void */ - function afterFind(&$model, $results, $primary) { + function afterFind($model, $results, $primary) { $settings = $this->settings[$model->alias]; if (!isset($settings['afterFind']) || $settings['afterFind'] == 'off') { return parent::afterFind($model, $results, $primary); @@ -119,7 +117,7 @@ class TestBehavior extends ModelBehavior { * @access public * @return void */ - function beforeSave(&$model) { + function beforeSave($model) { $settings = $this->settings[$model->alias]; if (!isset($settings['beforeSave']) || $settings['beforeSave'] == 'off') { return parent::beforeSave($model); @@ -129,7 +127,7 @@ class TestBehavior extends ModelBehavior { return false; break; case 'test': - return null; + return true; break; case 'modify': $model->data[$model->alias]['name'] .= ' modified before'; @@ -146,7 +144,7 @@ class TestBehavior extends ModelBehavior { * @access public * @return void */ - function afterSave(&$model, $created) { + function afterSave($model, $created) { $settings = $this->settings[$model->alias]; if (!isset($settings['afterSave']) || $settings['afterSave'] == 'off') { return parent::afterSave($model, $created); @@ -178,7 +176,7 @@ class TestBehavior extends ModelBehavior { * @access public * @return void */ - function beforeValidate(&$model) { + function beforeValidate($model) { $settings = $this->settings[$model->alias]; if (!isset($settings['validate']) || $settings['validate'] == 'off') { return parent::beforeValidate($model); @@ -210,7 +208,7 @@ class TestBehavior extends ModelBehavior { * @access public * @return void */ - function beforeDelete(&$model, $cascade = true) { + function beforeDelete($model, $cascade = true) { $settings = $this->settings[$model->alias]; if (!isset($settings['beforeDelete']) || $settings['beforeDelete'] == 'off') { return parent::beforeDelete($model, $cascade); @@ -227,6 +225,7 @@ class TestBehavior extends ModelBehavior { if ($cascade) { echo ' (cascading) '; } + return true; break; } } @@ -238,7 +237,7 @@ class TestBehavior extends ModelBehavior { * @access public * @return void */ - function afterDelete(&$model) { + function afterDelete($model) { $settings = $this->settings[$model->alias]; if (!isset($settings['afterDelete']) || $settings['afterDelete'] == 'off') { return parent::afterDelete($model); @@ -257,10 +256,10 @@ class TestBehavior extends ModelBehavior { * @access public * @return void */ - function onError(&$model) { + function onError($model, $error) { $settings = $this->settings[$model->alias]; if (!isset($settings['onError']) || $settings['onError'] == 'off') { - return parent::onError($model, $cascade); + return parent::onError($model, $error); } echo "onError trigger success"; } @@ -271,7 +270,7 @@ class TestBehavior extends ModelBehavior { * @access public * @return void */ - function beforeTest(&$model) { + function beforeTest($model) { if (!isset($model->beforeTestResult)) { $model->beforeTestResult = array(); } @@ -339,17 +338,24 @@ class TestBehavior extends ModelBehavior { /** * Test2Behavior class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ -class Test2Behavior extends TestBehavior{ +class Test2Behavior extends TestBehavior { + public $mapMethods = array('/mappingRobot(\w+)/' => 'mapped'); + + function resolveMethod($model, $stuff) { + + } + + function mapped($model, $method, $query) { + + } } /** * Test3Behavior class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Test3Behavior extends TestBehavior{ } @@ -357,11 +363,10 @@ class Test3Behavior extends TestBehavior{ /** * Test4Behavior class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Test4Behavior extends ModelBehavior{ - function setup(&$model, $config = null) { + function setup($model, $config = null) { $model->bindModel( array('hasMany' => array('Comment')) ); @@ -371,11 +376,10 @@ class Test4Behavior extends ModelBehavior{ /** * Test5Behavior class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Test5Behavior extends ModelBehavior{ - function setup(&$model, $config = null) { + function setup($model, $config = null) { $model->bindModel( array('belongsTo' => array('User')) ); @@ -385,11 +389,10 @@ class Test5Behavior extends ModelBehavior{ /** * Test6Behavior class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Test6Behavior extends ModelBehavior{ - function setup(&$model, $config = null) { + function setup($model, $config = null) { $model->bindModel( array('hasAndBelongsToMany' => array('Tag')) ); @@ -399,11 +402,10 @@ class Test6Behavior extends ModelBehavior{ /** * Test7Behavior class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Test7Behavior extends ModelBehavior{ - function setup(&$model, $config = null) { + function setup($model, $config = null) { $model->bindModel( array('hasOne' => array('Attachment')) ); @@ -413,8 +415,7 @@ class Test7Behavior extends ModelBehavior{ /** * BehaviorCollection class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class BehaviorCollectionTest extends CakeTestCase { @@ -429,16 +430,6 @@ class BehaviorCollectionTest extends CakeTestCase { 'core.attachment', 'core.tag', 'core.articles_tag' ); -/** - * tearDown method - * - * @access public - * @return void - */ - function endTest() { - ClassRegistry::flush(); - } - /** * testBehaviorBinding method * @@ -546,6 +537,7 @@ class BehaviorCollectionTest extends CakeTestCase { */ function testBehaviorToggling() { $Apple = new Apple(); + $expected = $Apple->find('all'); $this->assertIdentical($Apple->Behaviors->enabled(), array()); $Apple->Behaviors->init('Apple', array('Test' => array('key' => 'value'))); @@ -936,7 +928,8 @@ class BehaviorCollectionTest extends CakeTestCase { $this->assertIdentical(trim(ob_get_clean()), 'afterDelete success'); $this->assertIdentical($results, true); } - /** + +/** * testBehaviorOnErrorCallback method * * @access public @@ -947,10 +940,11 @@ class BehaviorCollectionTest extends CakeTestCase { $Apple->Behaviors->attach('Test', array('beforeFind' => 'off', 'onError' => 'on')); ob_start(); - $Apple->Behaviors->Test->onError($Apple); + $Apple->Behaviors->Test->onError($Apple, ''); $this->assertIdentical(trim(ob_get_clean()), 'onError trigger success'); } - /** + +/** * testBehaviorValidateCallback method * * @access public @@ -1041,34 +1035,6 @@ class BehaviorCollectionTest extends CakeTestCase { $this->assertTrue($Apple->testData('one', 'two', 'three', 'four', 'five', 'six')); } -/** - * testBehaviorTrigger method - * - * @access public - * @return void - */ - function testBehaviorTrigger() { - $Apple = new Apple(); - $Apple->Behaviors->attach('Test'); - $Apple->Behaviors->attach('Test2'); - $Apple->Behaviors->attach('Test3'); - - $Apple->beforeTestResult = array(); - $Apple->Behaviors->trigger($Apple, 'beforeTest'); - $expected = array('testbehavior', 'test2behavior', 'test3behavior'); - $this->assertIdentical($Apple->beforeTestResult, $expected); - - $Apple->beforeTestResult = array(); - $Apple->Behaviors->trigger($Apple, 'beforeTest', array(), array('break' => true, 'breakOn' => 'test2behavior')); - $expected = array('testbehavior', 'test2behavior'); - $this->assertIdentical($Apple->beforeTestResult, $expected); - - $Apple->beforeTestResult = array(); - $Apple->Behaviors->trigger($Apple, 'beforeTest', array(), array('break' => true, 'breakOn' => array('test2behavior', 'test3behavior'))); - $expected = array('testbehavior', 'test2behavior'); - $this->assertIdentical($Apple->beforeTestResult, $expected); - } - /** * undocumented function * @@ -1129,6 +1095,61 @@ class BehaviorCollectionTest extends CakeTestCase { $Sample->Behaviors->attach('Test2'); $Sample->Behaviors->detach('Test3'); - $Sample->Behaviors->trigger($Sample, 'beforeTest'); + $Sample->Behaviors->trigger('beforeTest', array(&$Sample)); } + +/** + * test that hasMethod works with basic functions. + * + * @return void + */ + function testHasMethodBasic() { + $Sample = new Sample(); + $Collection = new BehaviorCollection(); + $Collection->init('Sample', array('Test', 'Test2')); + + $this->assertTrue($Collection->hasMethod('testMethod')); + $this->assertTrue($Collection->hasMethod('resolveMethod')); + + $this->assertFalse($Collection->hasMethod('No method')); + } + +/** + * test that hasMethod works with mapped methods. + * + * @return void + */ + function testHasMethodMappedMethods() { + $Sample = new Sample(); + $Collection = new BehaviorCollection(); + $Collection->init('Sample', array('Test', 'Test2')); + + $this->assertTrue($Collection->hasMethod('look for the remote in the couch')); + $this->assertTrue($Collection->hasMethod('mappingRobotOnTheRoof')); + } + +/** + * test hasMethod returrning a 'callback' + * + * @return void + */ + function testHasMethodAsCallback() { + $Sample = new Sample(); + $Collection = new BehaviorCollection(); + $Collection->init('Sample', array('Test', 'Test2')); + + $result = $Collection->hasMethod('testMethod', true); + $expected = array('Test', 'testMethod'); + $this->assertEquals($expected, $result); + + $result = $Collection->hasMethod('resolveMethod', true); + $expected = array('Test2', 'resolveMethod'); + $this->assertEquals($expected, $result); + + $result = $Collection->hasMethod('mappingRobotOnTheRoof', true); + $expected = array('Test2', 'mapped', 'mappingRobotOnTheRoof'); + $this->assertEquals($expected, $result); + } + + } diff --git a/cake/tests/cases/libs/model/behaviors/acl.test.php b/cake/tests/cases/libs/model/behaviors/acl.test.php index a7705dcd9..e3ec6daf9 100644 --- a/cake/tests/cases/libs/model/behaviors/acl.test.php +++ b/cake/tests/cases/libs/model/behaviors/acl.test.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.cake.libs.tests.model.behaviors.acl + * @package cake.libs.tests.model.behaviors.acl * @since CakePHP v 1.2.0.4487 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -26,7 +25,7 @@ App::import('Core', 'db_acl'); * Test Person class - self joined model * * @package cake -* @subpackage cake.tests.cases.libs.model.behaviors +* @package cake.tests.cases.libs.model.behaviors */ class AclPerson extends CakeTestModel { @@ -106,7 +105,7 @@ class AclPerson extends CakeTestModel { * AclUser class * * @package cake -* @subpackage cake.tests.cases.libs.model.behaviors +* @package cake.tests.cases.libs.model.behaviors */ class AclUser extends CakeTestModel { @@ -147,7 +146,7 @@ class AclUser extends CakeTestModel { * AclPost class * * @package cake -* @subpackage cake.tests.cases.libs.model.behaviors +* @package cake.tests.cases.libs.model.behaviors */ class AclPost extends CakeTestModel { @@ -188,7 +187,7 @@ class AclPost extends CakeTestModel { * AclBehaviorTest class * * @package cake -* @subpackage cake.tests.cases.libs.controller.components +* @package cake.tests.cases.libs.controller.components */ class AclBehaviorTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/model/behaviors/containable.test.php b/cake/tests/cases/libs/model/behaviors/containable.test.php index 10ea65fb5..9b6e223f5 100644 --- a/cake/tests/cases/libs/model/behaviors/containable.test.php +++ b/cake/tests/cases/libs/model/behaviors/containable.test.php @@ -12,8 +12,7 @@ * * @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.model.behaviors + * @package cake.tests.cases.libs.model.behaviors * @since CakePHP(tm) v 1.2.0.5669 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ require_once(dirname(dirname(__FILE__)) . DS . 'models.php'); /** * ContainableTest class * - * @package cake - * @subpackage cake.tests.cases.libs.model.behaviors + * @package cake.tests.cases.libs.model.behaviors */ class ContainableBehaviorTest extends CakeTestCase { @@ -35,7 +33,8 @@ class ContainableBehaviorTest extends CakeTestCase { * @access public */ public $fixtures = array( - 'core.article', 'core.article_featured', 'core.article_featureds_tags', 'core.articles_tag', 'core.attachment', 'core.category', + 'core.article', 'core.article_featured', 'core.article_featureds_tags', + 'core.articles_tag', 'core.attachment', 'core.category', 'core.comment', 'core.featured', 'core.tag', 'core.user' ); @@ -43,10 +42,11 @@ class ContainableBehaviorTest extends CakeTestCase { * Method executed before each test * */ - public function startTest() { - $this->User =& ClassRegistry::init('User'); - $this->Article =& ClassRegistry::init('Article'); - $this->Tag =& ClassRegistry::init('Tag'); + public function setUp() { + parent::setUp(); + $this->User = ClassRegistry::init('User'); + $this->Article = ClassRegistry::init('Article'); + $this->Tag = ClassRegistry::init('Tag'); $this->User->bindModel(array( 'hasMany' => array('Article', 'ArticleFeatured', 'Comment') @@ -67,12 +67,11 @@ class ContainableBehaviorTest extends CakeTestCase { * Method executed after each test * */ - public function endTest() { + public function tearDown() { unset($this->Article); unset($this->User); unset($this->Tag); - - ClassRegistry::flush(); + parent::tearDown(); } /** @@ -116,15 +115,23 @@ class ContainableBehaviorTest extends CakeTestCase { $r = $this->__containments($this->Article, array('Comment' => array('limit' => 1))); $this->assertEqual(array_keys($r), array('Comment', 'Article')); - $this->assertEqual(array_shift(Set::extract('/Comment/keep', $r)), array('keep' => array())); + $result = Set::extract('/Comment/keep', $r); + $this->assertEqual(array_shift($result), array('keep' => array())); $this->assertTrue(Set::matches('/Article/keep/Comment', $r)); - $this->assertEqual(array_shift(Set::extract('/Article/keep/Comment/.', $r)), array('limit' => 1)); + $result = Set::extract('/Article/keep/Comment/.', $r); + $this->assertEqual(array_shift($result), array('limit' => 1)); $r = $this->__containments($this->Article, array('Comment.User')); $this->assertEqual(array_keys($r), array('User', 'Comment', 'Article')); - $this->assertEqual(array_shift(Set::extract('/User/keep', $r)), array('keep' => array())); - $this->assertEqual(array_shift(Set::extract('/Comment/keep', $r)), array('keep' => array('User' => array()))); - $this->assertEqual(array_shift(Set::extract('/Article/keep', $r)), array('keep' => array('Comment' => array()))); + + $result = Set::extract('/User/keep', $r); + $this->assertEqual(array_shift($result), array('keep' => array())); + + $result = Set::extract('/Comment/keep', $r); + $this->assertEqual(array_shift($result), array('keep' => array('User' => array()))); + + $result = Set::extract('/Article/keep', $r); + $this->assertEqual(array_shift($result), array('keep' => array('Comment' => array()))); $r = $this->__containments($this->Tag, array('Article' => array('User' => array('Comment' => array( 'Attachment' => array('conditions' => array('Attachment.id >' => 1)) @@ -3182,111 +3189,6 @@ class ContainableBehaviorTest extends CakeTestCase { $this->assertEqual($result, $expected); } -/** - * testPaginate method - * - * @access public - * @return void - */ - function testPaginate() { - $Controller = new Controller(); - $Controller->uses = array('Article'); - $Controller->passedArgs[] = '1'; - $Controller->params['url'] = array(); - $Controller->constructClasses(); - - $Controller->paginate = array('Article' => array('fields' => array('title'), 'contain' => array('User(user)'))); - $result = $Controller->paginate('Article'); - $expected = array( - array('Article' => array('title' => 'First Article'), 'User' => array('user' => 'mariano', 'id' => 1)), - array('Article' => array('title' => 'Second Article'), 'User' => array('user' => 'larry', 'id' => 3)), - array('Article' => array('title' => 'Third Article'), 'User' => array('user' => 'mariano', 'id' => 1)), - ); - $this->assertEqual($result, $expected); - - $r = $Controller->Article->find('all'); - $this->assertTrue(Set::matches('/Article[id=1]', $r)); - $this->assertTrue(Set::matches('/User[id=1]', $r)); - $this->assertTrue(Set::matches('/Tag[id=1]', $r)); - - $Controller->paginate = array('Article' => array('contain' => array('Comment(comment)' => 'User(user)'), 'fields' => array('title'))); - $result = $Controller->paginate('Article'); - $expected = array( - array( - 'Article' => array('title' => 'First Article', 'id' => 1), - 'Comment' => array( - array( - 'comment' => 'First Comment for First Article', - 'user_id' => 2, - 'article_id' => 1, - 'User' => array('user' => 'nate') - ), - array( - 'comment' => 'Second Comment for First Article', - 'user_id' => 4, - 'article_id' => 1, - 'User' => array('user' => 'garrett') - ), - array( - 'comment' => 'Third Comment for First Article', - 'user_id' => 1, - 'article_id' => 1, - 'User' => array('user' => 'mariano') - ), - array( - 'comment' => 'Fourth Comment for First Article', - 'user_id' => 1, - 'article_id' => 1, - 'User' => array('user' => 'mariano') - ) - ) - ), - array( - 'Article' => array('title' => 'Second Article', 'id' => 2), - 'Comment' => array( - array( - 'comment' => 'First Comment for Second Article', - 'user_id' => 1, - 'article_id' => 2, - 'User' => array('user' => 'mariano') - ), - array( - 'comment' => 'Second Comment for Second Article', - 'user_id' => 2, - 'article_id' => 2, - 'User' => array('user' => 'nate') - ) - ) - ), - array( - 'Article' => array('title' => 'Third Article', 'id' => 3), - 'Comment' => array() - ), - ); - $this->assertEqual($result, $expected); - - $r = $Controller->Article->find('all'); - $this->assertTrue(Set::matches('/Article[id=1]', $r)); - $this->assertTrue(Set::matches('/User[id=1]', $r)); - $this->assertTrue(Set::matches('/Tag[id=1]', $r)); - - $Controller->Article->unbindModel(array('hasMany' => array('Comment'), 'belongsTo' => array('User'), 'hasAndBelongsToMany' => array('Tag')), false); - $Controller->Article->bindModel(array('hasMany' => array('Comment'), 'belongsTo' => array('User')), false); - - $Controller->paginate = array('Article' => array('contain' => array('Comment(comment)', 'User(user)'), 'fields' => array('title'))); - $r = $Controller->paginate('Article'); - $this->assertTrue(Set::matches('/Article[id=1]', $r)); - $this->assertTrue(Set::matches('/User[id=1]', $r)); - $this->assertTrue(Set::matches('/Comment[article_id=1]', $r)); - $this->assertFalse(Set::matches('/Comment[id=1]', $r)); - - $r = $this->Article->find('all'); - $this->assertTrue(Set::matches('/Article[id=1]', $r)); - $this->assertTrue(Set::matches('/User[id=1]', $r)); - $this->assertTrue(Set::matches('/Comment[article_id=1]', $r)); - $this->assertTrue(Set::matches('/Comment[id=1]', $r)); - } - /** * testOriginalAssociations method * @@ -3396,6 +3298,7 @@ class ContainableBehaviorTest extends CakeTestCase { 'conditions' => array('Article.id' => 1), 'contain' => array('ArticlesTag') )); + $expected = array('Article', 'ArticlesTag'); $this->assertTrue(!empty($result)); $this->assertEqual('First Article', $result['Article']['title']); @@ -3605,7 +3508,7 @@ class ContainableBehaviorTest extends CakeTestCase { return; } - $db =& ConnectionManager::getDataSource('test2'); + $db = ConnectionManager::getDataSource('test2'); $this->_fixtures[$this->_fixtureClassMap['User']]->create($db); $this->_fixtures[$this->_fixtureClassMap['User']]->insert($db); @@ -3641,7 +3544,7 @@ class ContainableBehaviorTest extends CakeTestCase { $result = $this->Article->find('all', array( 'conditions' => array('Article.id' => 999999999) )); - $this->assertEqual($result, array(), 'Should be empty.'); + $this->assertEmpty($result, 'Should be empty.'); } /** diff --git a/cake/tests/cases/libs/model/behaviors/translate.test.php b/cake/tests/cases/libs/model/behaviors/translate.test.php index aa833dc33..24f39807d 100644 --- a/cake/tests/cases/libs/model/behaviors/translate.test.php +++ b/cake/tests/cases/libs/model/behaviors/translate.test.php @@ -12,8 +12,7 @@ * * @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.model.behaviors + * @package cake.tests.cases.libs.model.behaviors * @since CakePHP(tm) v 1.2.0.5669 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -27,8 +26,7 @@ require_once(dirname(dirname(__FILE__)) . DS . 'models.php'); /** * TranslateBehaviorTest class * - * @package cake - * @subpackage cake.tests.cases.libs.model.behaviors + * @package cake.tests.cases.libs.model.behaviors */ class TranslateBehaviorTest extends CakeTestCase { @@ -185,6 +183,7 @@ class TranslateBehaviorTest extends CakeTestCase { $TestModel = new TranslatedItem(); $TestModel->locale = 'eng'; + $result = $TestModel->read(null, 1); $expected = array( 'TranslatedItem' => array( @@ -313,17 +312,17 @@ class TranslateBehaviorTest extends CakeTestCase { $result = $TestModel->find('all', array('fields' => array('TranslatedItem.title'))); $expected = array( array( - 'TranslatedItem' => array('id' => 1, 'locale' => 'eng', 'title' => 'Title #1'), + 'TranslatedItem' => array('id' => 1, 'locale' => 'eng', 'title' => 'Title #1', 'slug' => 'first_translated'), 'Title' => array(array('foreign_key' => 1, 'content' => 'Title #1')), 'Content' => array(array('foreign_key' => 1, 'content' => 'Content #1')) ), array( - 'TranslatedItem' => array('id' => 2, 'locale' => 'eng', 'title' => 'Title #2'), + 'TranslatedItem' => array('id' => 2, 'locale' => 'eng', 'title' => 'Title #2', 'slug' => 'second_translated'), 'Title' => array(array('foreign_key' => 2, 'content' => 'Title #2')), 'Content' => array(array('foreign_key' => 2, 'content' => 'Content #2')) ), array( - 'TranslatedItem' => array('id' => 3, 'locale' => 'eng', 'title' => 'Title #3'), + 'TranslatedItem' => array('id' => 3, 'locale' => 'eng', 'title' => 'Title #3','slug' => 'third_translated'), 'Title' => array(array('foreign_key' => 3, 'content' => 'Title #3')), 'Content' => array(array('foreign_key' => 3, 'content' => 'Content #3')) ) @@ -342,16 +341,7 @@ class TranslateBehaviorTest extends CakeTestCase { $TestModel = new TranslatedItem(); $TestModel->locale = array('deu', 'eng', 'cze'); - $delete = array( - array('locale' => 'deu'), - array('foreign_key' => 1, 'field' => 'title', 'locale' => 'eng'), - array('foreign_key' => 1, 'field' => 'content', 'locale' => 'cze'), - array('foreign_key' => 2, 'field' => 'title', 'locale' => 'cze'), - array('foreign_key' => 2, 'field' => 'content', 'locale' => 'eng'), - array('foreign_key' => 3, 'field' => 'title') - ); - $I18nModel = ClassRegistry::getObject('TranslateTestModel'); - $I18nModel->deleteAll(array('or' => $delete)); + $result = $TestModel->read(null, 1); $expected = array( @@ -359,8 +349,8 @@ class TranslateBehaviorTest extends CakeTestCase { 'id' => 1, 'slug' => 'first_translated', 'locale' => 'deu', - 'title' => 'Titulek #1', - 'content' => 'Content #1' + 'title' => 'Titel #1', + 'content' => 'Inhalt #1' ) ); $this->assertEqual($result, $expected); @@ -371,28 +361,29 @@ class TranslateBehaviorTest extends CakeTestCase { 'TranslatedItem' => array( 'slug' => 'first_translated', 'locale' => 'deu', - 'title' => 'Titulek #1', - 'content' => 'Content #1' + 'content' => 'Inhalt #1', + 'title' => 'Titel #1' ) ), array( 'TranslatedItem' => array( 'slug' => 'second_translated', 'locale' => 'deu', - 'title' => 'Title #2', - 'content' => 'Obsah #2' + 'title' => 'Titel #2', + 'content' => 'Inhalt #2' ) ), array( 'TranslatedItem' => array( 'slug' => 'third_translated', 'locale' => 'deu', - 'title' => '', - 'content' => 'Content #3' + 'title' => 'Titel #3', + 'content' => 'Inhalt #3' ) ) ); - $this->assertEqual($result, $expected); + + $this->assertEquals($result, $expected); } /** @@ -640,6 +631,8 @@ class TranslateBehaviorTest extends CakeTestCase { $translations = array('title' => 'Title', 'content' => 'Content'); $TestModel->bindTranslation($translations, false); $result = $TestModel->read(null, 1); + $result['Title'] = Set::sort($result['Title'], '{n}.id', 'asc'); + $result['Content'] = Set::sort($result['Content'], '{n}.id', 'asc'); $expected = array( 'TranslatedItem' => array('id' => 1, 'slug' => 'first_translated', 'locale' => 'cze', 'title' => 'Titulek #1', 'content' => 'Upraveny obsah #1'), 'Title' => array( diff --git a/cake/tests/cases/libs/model/behaviors/tree.test.php b/cake/tests/cases/libs/model/behaviors/tree.test.php index 19d55e668..96e4e174d 100644 --- a/cake/tests/cases/libs/model/behaviors/tree.test.php +++ b/cake/tests/cases/libs/model/behaviors/tree.test.php @@ -14,8 +14,7 @@ * * @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.model.behaviors + * @package cake.tests.cases.libs.model.behaviors * @since CakePHP(tm) v 1.2.0.5330 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,8 +24,7 @@ require_once(dirname(dirname(__FILE__)) . DS . 'models.php'); /** * NumberTreeTest class * - * @package cake - * @subpackage cake.tests.cases.libs.model.behaviors + * @package cake.tests.cases.libs.model.behaviors */ class NumberTreeTest extends CakeTestCase { @@ -1279,8 +1277,7 @@ class NumberTreeTest extends CakeTestCase { /** * ScopedTreeTest class * - * @package cake - * @subpackage cake.tests.cases.libs.model.behaviors + * @package cake.tests.cases.libs.model.behaviors */ class ScopedTreeTest extends CakeTestCase { @@ -1431,7 +1428,6 @@ class ScopedTreeTest extends CakeTestCase { function testTranslatingTree() { $this->Tree = new FlagTree(); $this->Tree->cacheQueries = false; - $this->Tree->translateModel = 'TranslateTreeTestModel'; $this->Tree->Behaviors->attach('Translate', array('name')); //Save @@ -1581,8 +1577,7 @@ class ScopedTreeTest extends CakeTestCase { /** * AfterTreeTest class * - * @package cake - * @subpackage cake.tests.cases.libs.model.behaviors + * @package cake.tests.cases.libs.model.behaviors */ class AfterTreeTest extends CakeTestCase { @@ -1637,8 +1632,7 @@ class AfterTreeTest extends CakeTestCase { /** * UuidTreeTest class * - * @package cake - * @subpackage cake.tests.cases.libs.model.behaviors + * @package cake.tests.cases.libs.model.behaviors */ class UuidTreeTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/model/cake_schema.test.php b/cake/tests/cases/libs/model/cake_schema.test.php index 1eb8e7228..62050194d 100644 --- a/cake/tests/cases/libs/model/cake_schema.test.php +++ b/cake/tests/cases/libs/model/cake_schema.test.php @@ -13,8 +13,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.5550 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ App::import('Model', 'CakeSchema', false); /** * Test for Schema database management * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class MyAppSchema extends CakeSchema { @@ -125,8 +123,7 @@ class MyAppSchema extends CakeSchema { /** * TestAppSchema class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class TestAppSchema extends CakeSchema { @@ -210,7 +207,7 @@ class TestAppSchema extends CakeSchema { */ public $datatypes = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'), - 'float_field' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => ''), + 'float_field' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => '', 'collate' => null, 'comment' => null), 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)), 'tableParameters' => array() ); @@ -239,8 +236,7 @@ class TestAppSchema extends CakeSchema { /** * SchmeaPost class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class SchemaPost extends CakeTestModel { @@ -280,8 +276,7 @@ class SchemaPost extends CakeTestModel { /** * SchemaComment class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class SchemaComment extends CakeTestModel { @@ -313,8 +308,7 @@ class SchemaComment extends CakeTestModel { /** * SchemaTag class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class SchemaTag extends CakeTestModel { @@ -346,8 +340,7 @@ class SchemaTag extends CakeTestModel { /** * SchemaDatatype class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class SchemaDatatype extends CakeTestModel { @@ -377,7 +370,7 @@ class SchemaDatatype extends CakeTestModel { * * @uses CakeTestModel * @package - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Testdescribe extends CakeTestModel { @@ -393,8 +386,7 @@ class Testdescribe extends CakeTestModel { /** * SchemaCrossDatabase class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class SchemaCrossDatabase extends CakeTestModel { @@ -426,8 +418,7 @@ class SchemaCrossDatabase extends CakeTestModel { /** * SchemaCrossDatabaseFixture class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class SchemaCrossDatabaseFixture extends CakeTestFixture { @@ -472,8 +463,7 @@ class SchemaCrossDatabaseFixture extends CakeTestFixture { /** * SchemaPrefixAuthUser class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class SchemaPrefixAuthUser extends CakeTestModel { /** @@ -499,8 +489,7 @@ class SchemaPrefixAuthUser extends CakeTestModel { /** * CakeSchemaTest * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class CakeSchemaTest extends CakeTestCase { @@ -523,6 +512,7 @@ class CakeSchemaTest extends CakeTestCase { */ function setUp() { parent::setUp(); + ConnectionManager::getDataSource('test')->cacheSources = false; $this->Schema = new TestAppSchema(); } @@ -577,18 +567,28 @@ class CakeSchemaTest extends CakeTestCase { } $this->assertEqual( - $read['tables']['datatypes']['float_field'], - $this->Schema->tables['datatypes']['float_field'] + $read['tables']['datatypes']['float_field']['length'], + $this->Schema->tables['datatypes']['float_field']['length'] ); - $db =& ConnectionManager::getDataSource('test'); + $this->assertEqual( + $read['tables']['datatypes']['float_field']['type'], + $this->Schema->tables['datatypes']['float_field']['type'] + ); + + $this->assertEqual( + $read['tables']['datatypes']['float_field']['null'], + $this->Schema->tables['datatypes']['float_field']['null'] + ); + + $db = ConnectionManager::getDataSource('test'); $config = $db->config; $config['prefix'] = 'schema_test_prefix_'; ConnectionManager::create('schema_prefix', $config); $read = $this->Schema->read(array('connection' => 'schema_prefix', 'models' => false)); $this->assertTrue(empty($read['tables'])); - $SchemaPost =& ClassRegistry::init('SchemaPost'); + $SchemaPost = ClassRegistry::init('SchemaPost'); $SchemaPost->table = 'sts'; $SchemaPost->tablePrefix = 'po'; $read = $this->Schema->read(array( @@ -612,7 +612,7 @@ class CakeSchemaTest extends CakeTestCase { * @return void */ function testSchemaReadWithTablePrefix() { - $model =& new SchemaPrefixAuthUser(); + $model = new SchemaPrefixAuthUser(); $Schema = new CakeSchema(); $read = $Schema->read(array( @@ -684,7 +684,7 @@ class CakeSchemaTest extends CakeTestCase { return; } - $db2 =& ConnectionManager::getDataSource('test2'); + $db2 = ConnectionManager::getDataSource('test2'); $fixture = new SchemaCrossDatabaseFixture(); $fixture->create($db2); $fixture->insert($db2); @@ -953,7 +953,7 @@ class CakeSchemaTest extends CakeTestCase { * @return void */ function testSchemaLoading() { - $Other =& $this->Schema->load(array('name' => 'MyOtherApp', 'path' => TMP . 'tests')); + $Other = $this->Schema->load(array('name' => 'MyOtherApp', 'path' => TMP . 'tests')); $this->assertEqual($Other->name, 'MyOtherApp'); $this->assertEqual($Other->tables, $this->Schema->tables); } @@ -967,7 +967,7 @@ class CakeSchemaTest extends CakeTestCase { App::build(array( 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS) )); - $Other =& $this->Schema->load(array('name' => 'TestPluginApp', 'plugin' => 'TestPlugin')); + $Other = $this->Schema->load(array('name' => 'TestPluginApp', 'plugin' => 'TestPlugin')); $this->assertEqual($Other->name, 'TestPluginApp'); $this->assertEqual(array_keys($Other->tables), array('test_plugin_acos')); @@ -981,7 +981,7 @@ class CakeSchemaTest extends CakeTestCase { * @return void */ function testSchemaCreateTable() { - $db =& ConnectionManager::getDataSource('test'); + $db = ConnectionManager::getDataSource('test'); $db->cacheSources = false; $Schema = new CakeSchema(array( diff --git a/cake/tests/cases/libs/model/connection_manager.test.php b/cake/tests/cases/libs/model/connection_manager.test.php index d8e8b848f..54f022963 100644 --- a/cake/tests/cases/libs/model/connection_manager.test.php +++ b/cake/tests/cases/libs/model/connection_manager.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.5550 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Core', 'ConnectionManager'); /** * ConnectionManagerTest * - * @package cake - * @subpackage cake.tests.cases.models + * @package cake.tests.cases.models */ class ConnectionManagerTest extends CakeTestCase { @@ -226,7 +224,6 @@ class ConnectionManagerTest extends CakeTestCase { function testLoadDataSource() { $connections = array( array('classname' => 'DboMysql', 'filename' => 'dbo' . DS . 'dbo_mysql'), - array('classname' => 'DboMysqli', 'filename' => 'dbo' . DS . 'dbo_mysqli'), array('classname' => 'DboMssql', 'filename' => 'dbo' . DS . 'dbo_mssql'), array('classname' => 'DboOracle', 'filename' => 'dbo' . DS . 'dbo_oracle'), ); diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php index 8ea86d221..1b25e9435 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 1.2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -26,8 +25,7 @@ require_once LIBS.'model'.DS.'datasources'.DS.'dbo'.DS.'dbo_mssql.php'; /** * DboMssqlTestDb class * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources.dbo + * @package cake.tests.cases.libs.model.datasources.dbo */ class DboMssqlTestDb extends DboMssql { @@ -130,8 +128,7 @@ class DboMssqlTestDb extends DboMssql { /** * MssqlTestModel class * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources + * @package cake.tests.cases.libs.model.datasources */ class MssqlTestModel extends Model { @@ -232,8 +229,7 @@ class MssqlTestModel extends Model { /** * MssqlClientTestModel class * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources + * @package cake.tests.cases.libs.model.datasources */ class MssqlClientTestModel extends Model { /** @@ -267,8 +263,7 @@ class MssqlClientTestModel extends Model { /** * DboMssqlTest class * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources.dbo + * @package cake.tests.cases.libs.model.datasources.dbo */ class DboMssqlTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php index 5b81954c9..1e4c0ed93 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php @@ -12,153 +12,40 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 1.2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ App::import('Core', array('Model', 'DataSource', 'DboSource', 'DboMysql')); - -/** - * DboMysqlTestDb class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources - */ -class DboMysqlTestDb extends DboMysql { - -/** - * simulated property - * - * @var array - * @access public - */ - public $simulated = array(); - -/** - * testing property - * - * @var bool true - * @access public - */ - public $testing = true; - -/** - * execute method - * - * @param mixed $sql - * @access protected - * @return void - */ - function _execute($sql) { - if ($this->testing) { - $this->simulated[] = $sql; - return null; - } - return parent::_execute($sql); - } - -/** - * getLastQuery method - * - * @access public - * @return void - */ - function getLastQuery() { - return $this->simulated[count($this->simulated) - 1]; - } -} - -/** - * MysqlTestModel class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources - */ -class MysqlTestModel extends Model { - -/** - * name property - * - * @var string 'MysqlTestModel' - * @access public - */ - public $name = 'MysqlTestModel'; - -/** - * useTable property - * - * @var bool false - * @access public - */ - public $useTable = false; - -/** - * find method - * - * @param mixed $conditions - * @param mixed $fields - * @param mixed $order - * @param mixed $recursive - * @access public - * @return void - */ - function find($conditions = null, $fields = null, $order = null, $recursive = null) { - return $conditions; - } - -/** - * findAll method - * - * @param mixed $conditions - * @param mixed $fields - * @param mixed $order - * @param mixed $recursive - * @access public - * @return void - */ - function findAll($conditions = null, $fields = null, $order = null, $recursive = null) { - return $conditions; - } - -/** - * schema method - * - * @access public - * @return void - */ - function schema() { - return array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'client_id' => array('type' => 'integer', 'null' => '', 'default' => '0', 'length' => '11'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'login' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'passwd' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), - 'addr_1' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), - 'addr_2' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '25'), - 'zip_code' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'city' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'country' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'phone' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'fax' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'url' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), - 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => ''), - 'last_login'=> array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); - } -} +App::import('Model', 'App'); +require_once dirname(dirname(dirname(__FILE__))) . DS . 'models.php'; /** * DboMysqlTest class * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources.dbo + * @package cake.tests.cases.libs.model.datasources.dbo */ class DboMysqlTest extends CakeTestCase { - public $fixtures = array('core.binary_test'); +/** + * autoFixtures property + * + * @var bool false + * @access public + */ + public $autoFixtures = false; + +/** + * fixtures property + * + * @var array + * @access public + */ + public $fixtures = array( + 'core.apple', 'core.article', 'core.articles_tag', 'core.attachment', 'core.comment', + 'core.sample', 'core.tag', 'core.user', 'core.post', 'core.author', 'core.data_test', + 'core.binary_test' + ); + /** * The Dbo instance to be tested * @@ -173,6 +60,7 @@ class DboMysqlTest extends CakeTestCase { */ public function setUp() { $this->Dbo = ConnectionManager::getDataSource('test'); + $this->skipIf(!($this->Dbo instanceof DboMysql)); if ($this->Dbo->config['driver'] !== 'mysql') { $this->markTestSkipped('The MySQL extension is not available.'); } @@ -194,6 +82,7 @@ class DboMysqlTest extends CakeTestCase { /** * Test Dbo value method * + * @group quoting */ public function testQuoting() { $result = $this->Dbo->fields($this->model); @@ -236,7 +125,7 @@ class DboMysqlTest extends CakeTestCase { $result = $this->Dbo->value('', 'integer'); $this->assertEqual($expected, $result); - $expected = 0; + $expected = "'0'"; $result = $this->Dbo->value('', 'boolean'); $this->assertEqual($expected, $result); @@ -252,16 +141,17 @@ class DboMysqlTest extends CakeTestCase { /** * test that localized floats don't cause trouble. * + * @group quoting * @return void */ function testLocalizedFloats() { $restore = setlocale(LC_ALL, null); setlocale(LC_ALL, 'de_DE'); - $result = $this->db->value(3.141593, 'float'); + $result = $this->Dbo->value(3.141593, 'float'); $this->assertEqual((string)$result, '3.141593'); - - $result = $this->db->value(3.141593); + + $result = $this->Dbo->value(3.141593); $this->assertEqual((string)$result, '3.141593'); setlocale(LC_ALL, $restore); @@ -270,13 +160,13 @@ class DboMysqlTest extends CakeTestCase { /** * testTinyintCasting method * - * @access public + * * @return void */ function testTinyintCasting() { $this->Dbo->cacheSources = false; $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->Dbo->rawQuery('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( 'name' => 'Tinyint', 'table' => $tableName, 'ds' => 'test' @@ -304,47 +194,49 @@ class DboMysqlTest extends CakeTestCase { $this->assertIdentical($result['Tinyint']['small_int'], '0'); $this->model->deleteAll(true); - $this->Dbo->query('DROP TABLE ' . $this->Dbo->fullTableName($tableName)); + $this->Dbo->rawQuery('DROP TABLE ' . $this->Dbo->fullTableName($tableName)); } /** * testIndexDetection method * + * @group indices * @return void */ public function testIndexDetection() { $this->Dbo->cacheSources = false; $name = $this->Dbo->fullTableName('simple'); - $this->Dbo->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));'); + $this->Dbo->rawQuery('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)); $result = $this->Dbo->index('simple', false); + $this->Dbo->rawQuery('DROP TABLE ' . $name); $this->assertEqual($expected, $result); - $this->Dbo->query('DROP TABLE ' . $name); + $name = $this->Dbo->fullTableName('with_a_key'); - $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` ));'); + $this->Dbo->rawQuery('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ));'); $expected = array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'pointless_bool' => array('column' => 'bool', 'unique' => 0), ); $result = $this->Dbo->index('with_a_key', false); + $this->Dbo->rawQuery('DROP TABLE ' . $name); $this->assertEqual($expected, $result); - $this->Dbo->query('DROP TABLE ' . $name); $name = $this->Dbo->fullTableName('with_two_keys'); - $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` ));'); + $this->Dbo->rawQuery('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( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'pointless_bool' => array('column' => 'bool', 'unique' => 0), 'pointless_small_int' => array('column' => 'small_int', 'unique' => 0), ); $result = $this->Dbo->index('with_two_keys', false); + $this->Dbo->rawQuery('DROP TABLE ' . $name); $this->assertEqual($expected, $result); - $this->Dbo->query('DROP TABLE ' . $name); $name = $this->Dbo->fullTableName('with_compound_keys'); - $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` ));'); + $this->Dbo->rawQuery('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( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'pointless_bool' => array('column' => 'bool', 'unique' => 0), @@ -352,11 +244,11 @@ class DboMysqlTest extends CakeTestCase { 'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0), ); $result = $this->Dbo->index('with_compound_keys', false); + $this->Dbo->rawQuery('DROP TABLE ' . $name); $this->assertEqual($expected, $result); - $this->Dbo->query('DROP TABLE ' . $name); $name = $this->Dbo->fullTableName('with_multiple_compound_keys'); - $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` ));'); + $this->Dbo->rawQuery('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( 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'pointless_bool' => array('column' => 'bool', 'unique' => 0), @@ -365,14 +257,13 @@ class DboMysqlTest extends CakeTestCase { 'other_way' => array('column' => array('small_int', 'bool'), 'unique' => 0), ); $result = $this->Dbo->index('with_multiple_compound_keys', false); + $this->Dbo->rawQuery('DROP TABLE ' . $name); $this->assertEqual($expected, $result); - $this->Dbo->query('DROP TABLE ' . $name); } /** * testBuildColumn method * - * @access public * @return void */ function testBuildColumn() { @@ -409,12 +300,13 @@ class DboMysqlTest extends CakeTestCase { * MySQL 4.x returns index data in a different format, * Using a mock ensure that MySQL 4.x output is properly parsed. * + * @group indices * @return void */ function testIndexOnMySQL4Output() { $name = $this->Dbo->fullTableName('simple'); - $mockDbo = $this->getMock('DboMysql', array('query')); + $mockDbo = $this->getMock('DboMysql', array('connect', '_execute', 'getVersion')); $columnData = array( array('0' => array( 'Table' => 'with_compound_keys', @@ -487,10 +379,17 @@ class DboMysqlTest extends CakeTestCase { 'Comment' => '' )) ); + + $mockDbo->expects($this->once())->method('getVersion')->will($this->returnValue('4.1')); + $resultMock = $this->getMock('PDOStatement', array('fetch')); $mockDbo->expects($this->once()) - ->method('query') + ->method('_execute') ->with('SHOW INDEX FROM ' . $name) - ->will($this->returnValue($columnData)); + ->will($this->returnValue($resultMock)); + + foreach ($columnData as $i => $data) { + $resultMock->expects($this->at($i))->method('fetch')->will($this->returnValue((object) $data)); + } $result = $mockDbo->index($name, false); $expected = array( @@ -552,7 +451,7 @@ class DboMysqlTest extends CakeTestCase { /** * testAlterSchemaIndexes method * - * @access public + * @group indices * @return void */ function testAlterSchemaIndexes() { @@ -568,7 +467,15 @@ class DboMysqlTest extends CakeTestCase { 'group1' => array('type' => 'integer', 'null' => true), 'group2' => array('type' => 'integer', 'null' => true) ))); - $this->Dbo->query($this->Dbo->createSchema($schema1)); + $result = $this->Dbo->createSchema($schema1); + $this->assertContains('`id` int(11) DEFAULT 0 NOT NULL,', $result); + $this->assertContains('`name` varchar(50) NOT NULL,', $result); + $this->assertContains('`group1` int(11) DEFAULT NULL', $result); + $this->assertContains('`group2` int(11) DEFAULT NULL', $result); + + //Test that the string is syntactically correct + $query = $this->Dbo->getConnection()->prepare($result); + $this->assertEquals($result, $query->queryString); $schema2 = new CakeSchema(array( 'name' => 'AlterTest2', @@ -584,10 +491,17 @@ class DboMysqlTest extends CakeTestCase { 'compound_idx' => array('column' => array('group1', 'group2'), 'unique' => 0), 'PRIMARY' => array('column' => 'id', 'unique' => 1)) ))); - $this->Dbo->query($this->Dbo->alterSchema($schema2->compare($schema1))); - $indexes = $this->Dbo->index('altertest'); - $this->assertEqual($schema2->tables['altertest']['indexes'], $indexes); + $result = $this->Dbo->alterSchema($schema2->compare($schema1)); + $this->assertContains('ALTER TABLE `altertest`', $result); + $this->assertContains('ADD KEY name_idx (`name`),', $result); + $this->assertContains('ADD KEY group_idx (`group1`),', $result); + $this->assertContains('ADD KEY compound_idx (`group1`, `group2`),', $result); + $this->assertContains('ADD PRIMARY KEY (`id`);', $result); + + //Test that the string is syntactically correct + $query = $this->Dbo->getConnection()->prepare($result); + $this->assertEquals($result, $query->queryString); // Change three indexes, delete one and add another one $schema3 = new CakeSchema(array( @@ -605,35 +519,50 @@ class DboMysqlTest extends CakeTestCase { 'id_name_idx' => array('column' => array('id', 'name'), 'unique' => 0)) ))); - $this->Dbo->query($this->Dbo->alterSchema($schema3->compare($schema2))); + $result = $this->Dbo->alterSchema($schema3->compare($schema2)); + $this->assertContains('ALTER TABLE `altertest`', $result); + $this->assertContains('DROP PRIMARY KEY,', $result); + $this->assertContains('DROP KEY name_idx,', $result); + $this->assertContains('DROP KEY group_idx,', $result); + $this->assertContains('DROP KEY compound_idx,', $result); + $this->assertContains('ADD KEY id_name_idx (`id`, `name`),', $result); + $this->assertContains('ADD UNIQUE KEY name_idx (`name`),', $result); + $this->assertContains('ADD KEY group_idx (`group2`),', $result); + $this->assertContains('ADD KEY compound_idx (`group2`, `group1`);', $result); - $indexes = $this->Dbo->index('altertest'); - $this->assertEqual($schema3->tables['altertest']['indexes'], $indexes); + $query = $this->Dbo->getConnection()->prepare($result); + $this->assertEquals($result, $query->queryString); // Compare us to ourself. $this->assertEqual($schema3->compare($schema3), array()); // Drop the indexes - $this->Dbo->query($this->Dbo->alterSchema($schema1->compare($schema3))); + $result = $this->Dbo->alterSchema($schema1->compare($schema3)); - $indexes = $this->Dbo->index('altertest'); - $this->assertEqual(array(), $indexes); + $this->assertContains('ALTER TABLE `altertest`', $result); + $this->assertContains('DROP KEY name_idx,', $result); + $this->assertContains('DROP KEY group_idx,', $result); + $this->assertContains('DROP KEY compound_idx,', $result); + $this->assertContains('DROP KEY id_name_idx;', $result); - $this->Dbo->query($this->Dbo->dropSchema($schema1)); + $query = $this->Dbo->getConnection()->prepare($result); + $this->assertEquals($result, $query->queryString); } + /** * test saving and retrieval of blobs * * @return void */ function testBlobSaving() { + $this->loadFixtures('BinaryTest'); $this->Dbo->cacheSources = false; $data = "GIF87ab Ò4A¿¿¿ˇˇˇ,b ¢îè©ÀÌ#¥⁄ã≥fi:¯Ü‚Héá¶jV∂ÓúÎL≥çÀóËıÎ…>ï≈ vFE%ÒâLFI<†µw˝±≈£7˘ç^H“≤« >Éâ*∑ÇnÖA•Ù|flêèj£:=ÿ6óUàµ5'∂®àA¬ñ∆ˆGE(gt’≈àÚyÁó«7 ‚VìöÇ√˙Ç™ k”:;kÀAõ{*¡€Î˚˚[;;"; - $model = new AppModel(array('name' => 'BinaryTest', 'ds' => 'test')); + $model = new CakeTestModel(array('name' => 'BinaryTest', 'ds' => 'test')); $model->save(compact('data')); $result = $model->find('first'); @@ -662,7 +591,7 @@ class DboMysqlTest extends CakeTestCase { ) ) )); - $this->Dbo->query($this->Dbo->createSchema($schema1)); + $this->Dbo->rawQuery($this->Dbo->createSchema($schema1)); $schema2 = new CakeSchema(array( 'name' => 'AlterTest1', 'connection' => 'test', @@ -677,17 +606,17 @@ class DboMysqlTest extends CakeTestCase { ) )); $result = $this->Dbo->alterSchema($schema2->compare($schema1)); - $this->assertPattern('/DEFAULT CHARSET=utf8/', $result); - $this->assertPattern('/ENGINE=InnoDB/', $result); - $this->assertPattern('/COLLATE=utf8_general_ci/', $result); + $this->assertContains('DEFAULT CHARSET=utf8', $result); + $this->assertContains('ENGINE=InnoDB', $result); + $this->assertContains('COLLATE=utf8_general_ci', $result); - $this->Dbo->query($result); + $this->Dbo->rawQuery($result); $result = $this->Dbo->listDetailedSources('altertest'); $this->assertEqual($result['Collation'], 'utf8_general_ci'); $this->assertEqual($result['Engine'], 'InnoDB'); $this->assertEqual($result['charset'], 'utf8'); - $this->Dbo->query($this->Dbo->dropSchema($schema1)); + $this->Dbo->rawQuery($this->Dbo->dropSchema($schema1)); } /** @@ -720,7 +649,7 @@ class DboMysqlTest extends CakeTestCase { 'field_two' => array('type' => 'string', 'null' => false, 'length' => 50), ) )); - $result = $this->db->alterSchema($schema2->compare($schema1)); + $result = $this->Dbo->alterSchema($schema2->compare($schema1)); $this->assertEqual(2, substr_count($result, 'field_two'), 'Too many fields'); } @@ -733,23 +662,23 @@ class DboMysqlTest extends CakeTestCase { function testReadTableParameters() { $this->Dbo->cacheSources = $this->Dbo->testing = false; $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)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;'); + $this->Dbo->rawQuery('CREATE TABLE ' . $this->Dbo->fullTableName($tableName) . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;'); $result = $this->Dbo->readTableParameters($tableName); + $this->Dbo->rawQuery('DROP TABLE ' . $this->Dbo->fullTableName($tableName)); $expected = array( 'charset' => 'utf8', 'collate' => 'utf8_unicode_ci', 'engine' => 'InnoDB'); $this->assertEqual($result, $expected); - $this->Dbo->query('DROP TABLE ' . $this->Dbo->fullTableName($tableName)); - $this->Dbo->query('CREATE TABLE ' . $this->Dbo->fullTableName($tableName) . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=MyISAM DEFAULT CHARSET=cp1250 COLLATE=cp1250_general_ci;'); + $this->Dbo->rawQuery('CREATE TABLE ' . $this->Dbo->fullTableName($tableName) . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=MyISAM DEFAULT CHARSET=cp1250 COLLATE=cp1250_general_ci;'); $result = $this->Dbo->readTableParameters($tableName); + $this->Dbo->rawQuery('DROP TABLE ' . $this->Dbo->fullTableName($tableName)); $expected = array( 'charset' => 'cp1250', 'collate' => 'cp1250_general_ci', 'engine' => 'MyISAM'); $this->assertEqual($result, $expected); - $this->Dbo->query('DROP TABLE ' . $this->Dbo->fullTableName($tableName)); } /** @@ -792,13 +721,15 @@ class DboMysqlTest extends CakeTestCase { * @return void */ function testVirtualFieldSeparators() { + $this->loadFixtures('BinaryTest'); $model = new CakeTestModel(array('table' => 'binary_tests', 'ds' => 'test', 'name' => 'BinaryTest')); $model->virtualFields = array( 'other__field' => 'SUM(id)' ); - - $this->db->virtualFieldSeparator = '_$_'; - $result = $this->db->fields($model, null, array('data', 'other__field')); + + $this->Dbo->virtualFieldSeparator = '_$_'; + $result = $this->Dbo->fields($model, null, array('data', 'other__field')); + $expected = array('`BinaryTest`.`data`', '(SUM(id)) AS `BinaryTest_$_other__field`'); $this->assertEqual($result, $expected); } @@ -827,15 +758,2613 @@ class DboMysqlTest extends CakeTestCase { ) ) )); - $this->db->execute($this->db->createSchema($schema)); + + $this->Dbo->execute($this->Dbo->createSchema($schema)); $model = new CakeTestModel(array('table' => 'testdescribes', 'name' => 'Testdescribes')); - $result = $this->db->describe($model); + $result = $this->Dbo->describe($model); + $this->Dbo->execute($this->Dbo->dropSchema($schema)); + $this->assertEqual($result['stringy']['collate'], 'cp1250_general_ci'); $this->assertEqual($result['stringy']['charset'], 'cp1250'); $this->assertEqual($result['other_col']['comment'], 'Test Comment'); - - $this->db->execute($this->db->dropSchema($schema)); } +/** + * Tests that listSources method sends the correct query and parses the result accordingly + * @return void + */ + public function testListSources() { + $db = $this->getMock('DboMysql', array('connect', '_execute')); + $queryResult = $this->getMock('PDOStatement'); + $db->expects($this->once()) + ->method('_execute') + ->with('SHOW TABLES FROM cake') + ->will($this->returnValue($queryResult)); + $queryResult->expects($this->at(0)) + ->method('fetch') + ->will($this->returnValue(array('cake_table'))); + $queryResult->expects($this->at(1)) + ->method('fetch') + ->will($this->returnValue(array('another_table'))); + $queryResult->expects($this->at(2)) + ->method('fetch') + ->will($this->returnValue(null)); + + $tables = $db->listSources(); + $this->assertEqual($tables, array('cake_table', 'another_table')); + } + +/** + * Tests that getVersion method sends the correct query for getting the mysql version + * @return void + */ + public function testGetVersion() { + $version = $this->Dbo->getVersion(); + $this->assertTrue(is_string($version)); + } + +/** + * Tests that getVersion method sends the correct query for getting the client encoding + * @return void + */ + public function testGetEncoding() { + $db = $this->getMock('DboMysql', array('connect', '_execute')); + $queryResult = $this->getMock('PDOStatement'); + + $db->expects($this->once()) + ->method('_execute') + ->with('SHOW VARIABLES LIKE ?', array('character_set_client')) + ->will($this->returnValue($queryResult)); + $result = new StdClass; + $result->Value = 'utf-8'; + $queryResult->expects($this->once()) + ->method('fetchObject') + ->will($this->returnValue($result)); + + $encoding = $db->getEncoding(); + $this->assertEqual('utf-8', $encoding); + } + +/** + * testFieldDoubleEscaping method + * + * @access public + * @return void + */ + function testFieldDoubleEscaping() { + $test = $this->getMock('DboMysql', array('connect', '_execute', 'execute')); + $this->Model = $this->getMock('Article2', array('getDataSource')); + $this->Model->alias = 'Article'; + $this->Model->expects($this->any()) + ->method('getDataSource') + ->will($this->returnValue($test)); + + $this->assertEqual($this->Model->escapeField(), '`Article`.`id`'); + $result = $test->fields($this->Model, null, $this->Model->escapeField()); + $this->assertEqual($result, array('`Article`.`id`')); + + $test->expects($this->at(0))->method('execute') + ->with('SELECT `Article`.`id` FROM `articles` AS `Article` WHERE 1 = 1'); + + $result = $test->read($this->Model, array( + 'fields' => $this->Model->escapeField(), + 'conditions' => null, + 'recursive' => -1 + )); + + $test->startQuote = '['; + $test->endQuote = ']'; + $this->assertEqual($this->Model->escapeField(), '[Article].[id]'); + + $result = $test->fields($this->Model, null, $this->Model->escapeField()); + $this->assertEqual($result, array('[Article].[id]')); + + $test->expects($this->at(0))->method('execute') + ->with('SELECT [Article].[id] FROM [' . $test->fullTableName('articles', false) . '] AS [Article] WHERE 1 = 1'); + $result = $test->read($this->Model, array( + 'fields' => $this->Model->escapeField(), + 'conditions' => null, + 'recursive' => -1 + )); + } + +/** + * testGenerateAssociationQuerySelfJoin method + * + * @return void + */ + function testGenerateAssociationQuerySelfJoin() { + $this->Dbo = $this->getMock('DboMysql', array('connect', '_execute', 'execute')); + $this->startTime = microtime(true); + $this->Model = new Article2(); + $this->_buildRelatedModels($this->Model); + $this->_buildRelatedModels($this->Model->Category2); + $this->Model->Category2->ChildCat = new Category2(); + $this->Model->Category2->ParentCat = new Category2(); + + $queryData = array(); + + foreach ($this->Model->Category2->associations() as $type) { + foreach ($this->Model->Category2->{$type} as $assoc => $assocData) { + $linkModel = $this->Model->Category2->{$assoc}; + $external = isset($assocData['external']); + + if ($this->Model->Category2->alias == $linkModel->alias && $type != 'hasAndBelongsToMany' && $type != 'hasMany') { + $result = $this->Dbo->generateAssociationQuery($this->Model->Category2, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null); + $this->assertFalse(empty($result)); + } else { + if ($this->Model->Category2->useDbConfig == $linkModel->useDbConfig) { + $result = $this->Dbo->generateAssociationQuery($this->Model->Category2, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null); + $this->assertFalse(empty($result)); + } + } + } + } + + $query = $this->Dbo->generateAssociationQuery($this->Model->Category2, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+(.+)FROM(.+)`Category2`\.`group_id`\s+=\s+`Group`\.`id`\)\s+LEFT JOIN(.+)WHERE\s+1 = 1\s*$/', $query); + + $this->Model = new TestModel4(); + $this->Model->schema(); + $this->_buildRelatedModels($this->Model); + + $binding = array('type' => 'belongsTo', 'model' => 'TestModel4Parent'); + $queryData = array(); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + + $_queryData = $queryData; + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + $this->assertTrue($result); + + $expected = array( + 'conditions' => array(), + 'fields' => array( + '`TestModel4`.`id`', + '`TestModel4`.`name`', + '`TestModel4`.`created`', + '`TestModel4`.`updated`', + '`TestModel4Parent`.`id`', + '`TestModel4Parent`.`name`', + '`TestModel4Parent`.`created`', + '`TestModel4Parent`.`updated`' + ), + 'joins' => array( + array( + 'table' => '`test_model4`', + 'alias' => 'TestModel4Parent', + 'type' => 'LEFT', + 'conditions' => '`TestModel4`.`parent_id` = `TestModel4Parent`.`id`' + ) + ), + 'order' => array(), + 'limit' => array(), + 'offset' => array(), + 'group' => array() + ); + $this->assertEqual($queryData, $expected); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`, `TestModel4Parent`\.`id`, `TestModel4Parent`\.`name`, `TestModel4Parent`\.`created`, `TestModel4Parent`\.`updated`\s+/', $result); + $this->assertPattern('/FROM\s+`test_model4` AS `TestModel4`\s+LEFT JOIN\s+`test_model4` AS `TestModel4Parent`/', $result); + $this->assertPattern('/\s+ON\s+\(`TestModel4`.`parent_id` = `TestModel4Parent`.`id`\)\s+WHERE/', $result); + $this->assertPattern('/\s+WHERE\s+1 = 1\s+$/', $result); + + $params['assocData']['type'] = 'INNER'; + $this->Model->belongsTo['TestModel4Parent']['type'] = 'INNER'; + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $_queryData, $params['external'], $resultSet); + $this->assertTrue($result); + $this->assertEqual($_queryData['joins'][0]['type'], 'INNER'); + } + +/** + * buildRelatedModels method + * + * @param mixed $model + * @access protected + * @return void + */ + function _buildRelatedModels(&$model) { + foreach ($model->associations() as $type) { + foreach ($model->{$type} as $assoc => $assocData) { + if (is_string($assocData)) { + $className = $assocData; + } elseif (isset($assocData['className'])) { + $className = $assocData['className']; + } + $model->$className = new $className(); + $model->$className->schema(); + } + } + } + +/** + * &_prepareAssociationQuery method + * + * @param mixed $model + * @param mixed $queryData + * @param mixed $binding + * @access public + * @return void + */ + function &_prepareAssociationQuery(&$model, &$queryData, $binding) { + $type = $binding['type']; + $assoc = $binding['model']; + $assocData = $model->{$type}[$assoc]; + $className = $assocData['className']; + + $linkModel = $model->{$className}; + $external = isset($assocData['external']); + $queryData = $this->Dbo->__scrubQueryData($queryData); + + $result = array_merge(array('linkModel' => &$linkModel), compact('type', 'assoc', 'assocData', 'external')); + return $result; + } + +/** + * testGenerateInnerJoinAssociationQuery method + * + * @access public + * @return void + */ + function testGenerateInnerJoinAssociationQuery() { + $test = $this->getMock('DboMysql', array('connect', '_execute', 'execute')); + $this->Model = $this->getMock('TestModel9', array('getDataSource')); + $this->Model->expects($this->any()) + ->method('getDataSource') + ->will($this->returnValue($test)); + + $this->Model->TestModel8 = $this->getMock('TestModel8', array('getDataSource')); + $this->Model->TestModel8->expects($this->any()) + ->method('getDataSource') + ->will($this->returnValue($test)); + + $test->expects($this->at(0))->method('execute') + ->with(new PHPUnit_Framework_Constraint_PCREMatch('/`TestModel9` LEFT JOIN `test_model8`/')); + + $test->expects($this->at(1))->method('execute') + ->with(new PHPUnit_Framework_Constraint_PCREMatch('/`TestModel9` INNER JOIN `test_model8`/')); + + $test->read($this->Model, array('recursive' => 1)); + $this->Model->belongsTo['TestModel8']['type'] = 'INNER'; + $test->read($this->Model, array('recursive' => 1)); + } + +/** + * testGenerateAssociationQuerySelfJoinWithConditionsInHasOneBinding method + * + * @access public + * @return void + */ + function testGenerateAssociationQuerySelfJoinWithConditionsInHasOneBinding() { + $this->Model = new TestModel8(); + $this->Model->schema(); + $this->_buildRelatedModels($this->Model); + + $binding = array('type' => 'hasOne', 'model' => 'TestModel9'); + $queryData = array(); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + $_queryData = $queryData; + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + $this->assertTrue($result); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+`TestModel8`\.`id`, `TestModel8`\.`test_model9_id`, `TestModel8`\.`name`, `TestModel8`\.`created`, `TestModel8`\.`updated`, `TestModel9`\.`id`, `TestModel9`\.`test_model8_id`, `TestModel9`\.`name`, `TestModel9`\.`created`, `TestModel9`\.`updated`\s+/', $result); + $this->assertPattern('/FROM\s+`test_model8` AS `TestModel8`\s+LEFT JOIN\s+`test_model9` AS `TestModel9`/', $result); + $this->assertPattern('/\s+ON\s+\(`TestModel9`\.`name` != \'mariano\'\s+AND\s+`TestModel9`.`test_model8_id` = `TestModel8`.`id`\)\s+WHERE/', $result); + $this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); + } + +/** + * testGenerateAssociationQuerySelfJoinWithConditionsInBelongsToBinding method + * + * @access public + * @return void + */ + function testGenerateAssociationQuerySelfJoinWithConditionsInBelongsToBinding() { + $this->Model = new TestModel9(); + $this->Model->schema(); + $this->_buildRelatedModels($this->Model); + + $binding = array('type' => 'belongsTo', 'model' => 'TestModel8'); + $queryData = array(); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + $this->assertTrue($result); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+`TestModel9`\.`id`, `TestModel9`\.`test_model8_id`, `TestModel9`\.`name`, `TestModel9`\.`created`, `TestModel9`\.`updated`, `TestModel8`\.`id`, `TestModel8`\.`test_model9_id`, `TestModel8`\.`name`, `TestModel8`\.`created`, `TestModel8`\.`updated`\s+/', $result); + $this->assertPattern('/FROM\s+`test_model9` AS `TestModel9`\s+LEFT JOIN\s+`test_model8` AS `TestModel8`/', $result); + $this->assertPattern('/\s+ON\s+\(`TestModel8`\.`name` != \'larry\'\s+AND\s+`TestModel9`.`test_model8_id` = `TestModel8`.`id`\)\s+WHERE/', $result); + $this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); + } + +/** + * testGenerateAssociationQuerySelfJoinWithConditions method + * + * @access public + * @return void + */ + function testGenerateAssociationQuerySelfJoinWithConditions() { + $this->Model = new TestModel4(); + $this->Model->schema(); + $this->_buildRelatedModels($this->Model); + + $binding = array('type' => 'belongsTo', 'model' => 'TestModel4Parent'); + $queryData = array('conditions' => array('TestModel4Parent.name !=' => 'mariano')); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + $this->assertTrue($result); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`, `TestModel4Parent`\.`id`, `TestModel4Parent`\.`name`, `TestModel4Parent`\.`created`, `TestModel4Parent`\.`updated`\s+/', $result); + $this->assertPattern('/FROM\s+`test_model4` AS `TestModel4`\s+LEFT JOIN\s+`test_model4` AS `TestModel4Parent`/', $result); + $this->assertPattern('/\s+ON\s+\(`TestModel4`.`parent_id` = `TestModel4Parent`.`id`\)\s+WHERE/', $result); + $this->assertPattern('/\s+WHERE\s+(?:\()?`TestModel4Parent`.`name`\s+!=\s+\'mariano\'(?:\))?\s*$/', $result); + + $this->Featured2 = new Featured2(); + $this->Featured2->schema(); + + $this->Featured2->bindModel(array( + 'belongsTo' => array( + 'ArticleFeatured2' => array( + 'conditions' => 'ArticleFeatured2.published = \'Y\'', + 'fields' => 'id, title, user_id, published' + ) + ) + )); + + $this->_buildRelatedModels($this->Featured2); + + $binding = array('type' => 'belongsTo', 'model' => 'ArticleFeatured2'); + $queryData = array('conditions' => array()); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Featured2, $queryData, $binding); + + $result = $this->Dbo->generateAssociationQuery($this->Featured2, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + $this->assertTrue($result); + $result = $this->Dbo->generateAssociationQuery($this->Featured2, $null, null, null, null, $queryData, false, $null); + + $this->assertPattern( + '/^SELECT\s+`Featured2`\.`id`, `Featured2`\.`article_id`, `Featured2`\.`category_id`, `Featured2`\.`name`,\s+'. + '`ArticleFeatured2`\.`id`, `ArticleFeatured2`\.`title`, `ArticleFeatured2`\.`user_id`, `ArticleFeatured2`\.`published`\s+' . + 'FROM\s+`featured2` AS `Featured2`\s+LEFT JOIN\s+`article_featured` AS `ArticleFeatured2`' . + '\s+ON\s+\(`ArticleFeatured2`.`published` = \'Y\'\s+AND\s+`Featured2`\.`article_featured2_id` = `ArticleFeatured2`\.`id`\)' . + '\s+WHERE\s+1\s+=\s+1\s*$/', + $result + ); + } + +/** + * testGenerateAssociationQueryHasOne method + * + * @access public + * @return void + */ + function testGenerateAssociationQueryHasOne() { + $this->Model = new TestModel4(); + $this->Model->schema(); + $this->_buildRelatedModels($this->Model); + + $binding = array('type' => 'hasOne', 'model' => 'TestModel5'); + + $queryData = array(); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + $this->assertTrue($result); + + $result = $this->Dbo->buildJoinStatement($queryData['joins'][0]); + $expected = ' LEFT JOIN `test_model5` AS `TestModel5` ON (`TestModel5`.`test_model4_id` = `TestModel4`.`id`)'; + $this->assertEqual(trim($result), trim($expected)); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`, `TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model4` AS `TestModel4`\s+LEFT JOIN\s+/', $result); + $this->assertPattern('/`test_model5` AS `TestModel5`\s+ON\s+\(`TestModel5`.`test_model4_id` = `TestModel4`.`id`\)\s+WHERE/', $result); + $this->assertPattern('/\s+WHERE\s+(?:\()?\s*1 = 1\s*(?:\))?\s*$/', $result); + } + +/** + * testGenerateAssociationQueryHasOneWithConditions method + * + * @access public + * @return void + */ + function testGenerateAssociationQueryHasOneWithConditions() { + $this->Model = new TestModel4(); + $this->Model->schema(); + $this->_buildRelatedModels($this->Model); + + $binding = array('type' => 'hasOne', 'model' => 'TestModel5'); + + $queryData = array('conditions' => array('TestModel5.name !=' => 'mariano')); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + $this->assertTrue($result); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + + $this->assertPattern('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`, `TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model4` AS `TestModel4`\s+LEFT JOIN\s+`test_model5` AS `TestModel5`/', $result); + $this->assertPattern('/\s+ON\s+\(`TestModel5`.`test_model4_id`\s+=\s+`TestModel4`.`id`\)\s+WHERE/', $result); + $this->assertPattern('/\s+WHERE\s+(?:\()?\s*`TestModel5`.`name`\s+!=\s+\'mariano\'\s*(?:\))?\s*$/', $result); + } + +/** + * testGenerateAssociationQueryBelongsTo method + * + * @access public + * @return void + */ + function testGenerateAssociationQueryBelongsTo() { + $this->Model = new TestModel5(); + $this->Model->schema(); + $this->_buildRelatedModels($this->Model); + + $binding = array('type'=>'belongsTo', 'model'=>'TestModel4'); + $queryData = array(); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + $this->assertTrue($result); + + $result = $this->Dbo->buildJoinStatement($queryData['joins'][0]); + $expected = ' LEFT JOIN `test_model4` AS `TestModel4` ON (`TestModel5`.`test_model4_id` = `TestModel4`.`id`)'; + $this->assertEqual(trim($result), trim($expected)); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`, `TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+LEFT JOIN\s+`test_model4` AS `TestModel4`/', $result); + $this->assertPattern('/\s+ON\s+\(`TestModel5`.`test_model4_id` = `TestModel4`.`id`\)\s+WHERE\s+/', $result); + $this->assertPattern('/\s+WHERE\s+(?:\()?\s*1 = 1\s*(?:\))?\s*$/', $result); + } + +/** + * testGenerateAssociationQueryBelongsToWithConditions method + * + * @access public + * @return void + */ + function testGenerateAssociationQueryBelongsToWithConditions() { + $this->Model = new TestModel5(); + $this->Model->schema(); + $this->_buildRelatedModels($this->Model); + + $binding = array('type' => 'belongsTo', 'model' => 'TestModel4'); + $queryData = array('conditions' => array('TestModel5.name !=' => 'mariano')); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + $this->assertTrue($result); + + $result = $this->Dbo->buildJoinStatement($queryData['joins'][0]); + $expected = ' LEFT JOIN `test_model4` AS `TestModel4` ON (`TestModel5`.`test_model4_id` = `TestModel4`.`id`)'; + $this->assertEqual(trim($result), trim($expected)); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`, `TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+LEFT JOIN\s+`test_model4` AS `TestModel4`/', $result); + $this->assertPattern('/\s+ON\s+\(`TestModel5`.`test_model4_id` = `TestModel4`.`id`\)\s+WHERE\s+/', $result); + $this->assertPattern('/\s+WHERE\s+`TestModel5`.`name` != \'mariano\'\s*$/', $result); + } + +/** + * testGenerateAssociationQueryHasMany method + * + * @access public + * @return void + */ + function testGenerateAssociationQueryHasMany() { + $this->Model = new TestModel5(); + $this->Model->schema(); + $this->_buildRelatedModels($this->Model); + + $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); + $queryData = array(); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + + $this->assertPattern('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE/', $result); + $this->assertPattern('/\s+WHERE\s+`TestModel6`.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)/', $result); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result); + $this->assertPattern('/\s+WHERE\s+(?:\()?\s*1 = 1\s*(?:\))?\s*$/', $result); + } + +/** + * testGenerateAssociationQueryHasManyWithLimit method + * + * @access public + * @return void + */ + function testGenerateAssociationQueryHasManyWithLimit() { + $this->Model = new TestModel5(); + $this->Model->schema(); + $this->_buildRelatedModels($this->Model); + + $this->Model->hasMany['TestModel6']['limit'] = 2; + + $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); + $queryData = array(); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + $this->assertPattern( + '/^SELECT\s+' . + '`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+'. + 'FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+' . + '`TestModel6`.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)\s*'. + 'LIMIT \d*'. + '\s*$/', $result + ); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + $this->assertPattern( + '/^SELECT\s+'. + '`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+'. + 'FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+'. + '(?:\()?\s*1 = 1\s*(?:\))?'. + '\s*$/', $result + ); + } + +/** + * testGenerateAssociationQueryHasManyWithConditions method + * + * @access public + * @return void + */ + function testGenerateAssociationQueryHasManyWithConditions() { + $this->Model = new TestModel5(); + $this->Model->schema(); + $this->_buildRelatedModels($this->Model); + + $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); + $queryData = array('conditions' => array('TestModel5.name !=' => 'mariano')); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + $this->assertPattern('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result); + $this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result); + $this->assertPattern('/\s+WHERE\s+(?:\()?`TestModel5`.`name`\s+!=\s+\'mariano\'(?:\))?\s*$/', $result); + } + +/** + * testGenerateAssociationQueryHasManyWithOffsetAndLimit method + * + * @access public + * @return void + */ + function testGenerateAssociationQueryHasManyWithOffsetAndLimit() { + $this->Model = new TestModel5(); + $this->Model->schema(); + $this->_buildRelatedModels($this->Model); + + $__backup = $this->Model->hasMany['TestModel6']; + + $this->Model->hasMany['TestModel6']['offset'] = 2; + $this->Model->hasMany['TestModel6']['limit'] = 5; + + $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); + $queryData = array(); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + + $this->assertPattern('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result); + $this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result); + $this->assertPattern('/\s+LIMIT 2,\s*5\s*$/', $result); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result); + $this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); + + $this->Model->hasMany['TestModel6'] = $__backup; + } + +/** + * testGenerateAssociationQueryHasManyWithPageAndLimit method + * + * @access public + * @return void + */ + function testGenerateAssociationQueryHasManyWithPageAndLimit() { + $this->Model = new TestModel5(); + $this->Model->schema(); + $this->_buildRelatedModels($this->Model); + + $__backup = $this->Model->hasMany['TestModel6']; + + $this->Model->hasMany['TestModel6']['page'] = 2; + $this->Model->hasMany['TestModel6']['limit'] = 5; + + $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); + $queryData = array(); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + $this->assertPattern('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result); + $this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result); + $this->assertPattern('/\s+LIMIT 5,\s*5\s*$/', $result); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result); + $this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); + + $this->Model->hasMany['TestModel6'] = $__backup; + } + +/** + * testGenerateAssociationQueryHasManyWithFields method + * + * @access public + * @return void + */ + function testGenerateAssociationQueryHasManyWithFields() { + $this->Model = new TestModel5(); + $this->Model->schema(); + $this->_buildRelatedModels($this->Model); + + $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); + $queryData = array('fields' => array('`TestModel5`.`name`')); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + $this->assertPattern('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result); + $this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+`TestModel5`\.`name`, `TestModel5`\.`id`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result); + $this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); + + $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); + $queryData = array('fields' => array('`TestModel5`.`id`, `TestModel5`.`name`')); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + $this->assertPattern('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result); + $this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`name`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result); + $this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); + + $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); + $queryData = array('fields' => array('`TestModel5`.`name`', '`TestModel5`.`created`')); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + $this->assertPattern('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result); + $this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+`TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`id`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result); + $this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); + + $this->Model->hasMany['TestModel6']['fields'] = array('name'); + + $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); + $queryData = array('fields' => array('`TestModel5`.`id`', '`TestModel5`.`name`')); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + $this->assertPattern('/^SELECT\s+`TestModel6`\.`name`, `TestModel6`\.`test_model5_id`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result); + $this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`name`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result); + $this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); + + unset($this->Model->hasMany['TestModel6']['fields']); + + $this->Model->hasMany['TestModel6']['fields'] = array('id', 'name'); + + $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); + $queryData = array('fields' => array('`TestModel5`.`id`', '`TestModel5`.`name`')); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + $this->assertPattern('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`name`, `TestModel6`\.`test_model5_id`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result); + $this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`name`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result); + $this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); + + unset($this->Model->hasMany['TestModel6']['fields']); + + $this->Model->hasMany['TestModel6']['fields'] = array('test_model5_id', 'name'); + + $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); + $queryData = array('fields' => array('`TestModel5`.`id`', '`TestModel5`.`name`')); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + $this->assertPattern('/^SELECT\s+`TestModel6`\.`test_model5_id`, `TestModel6`\.`name`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result); + $this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`name`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result); + $this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); + + unset($this->Model->hasMany['TestModel6']['fields']); + } + +/** + * test generateAssociationQuery with a hasMany and an aggregate function. + * + * @return void + */ + function testGenerateAssociationQueryHasManyAndAggregateFunction() { + $this->Model = new TestModel5(); + $this->Model->schema(); + $this->_buildRelatedModels($this->Model); + + $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); + $queryData = array('fields' => array('MIN(TestModel5.test_model4_id)')); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + $this->Model->recursive = 0; + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, $params['type'], $params['assoc'], $params['assocData'], $queryData, false, $resultSet); + $this->assertPattern('/^SELECT\s+MIN\(`TestModel5`\.`test_model4_id`\)\s+FROM/', $result); + } + +/** + * testGenerateAssociationQueryHasAndBelongsToMany method + * + * @access public + * @return void + */ + function testGenerateAssociationQueryHasAndBelongsToMany() { + $this->Model = new TestModel4(); + $this->Model->schema(); + $this->_buildRelatedModels($this->Model); + + $binding = array('type' => 'hasAndBelongsToMany', 'model' => 'TestModel7'); + $queryData = array(); + $resultSet = null; + $null = null; + + $params = $this->_prepareAssociationQuery($this->Model, $queryData, $binding); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + $this->assertPattern('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model7` AS `TestModel7`\s+JOIN\s+`' . $this->Dbo->fullTableName('test_model4_test_model7', false) . '`/', $result); + $this->assertPattern('/\s+ON\s+\(`TestModel4TestModel7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}\s+AND/', $result); + $this->assertPattern('/\s+AND\s+`TestModel4TestModel7`\.`test_model7_id`\s+=\s+`TestModel7`\.`id`\)/', $result); + $this->assertPattern('/WHERE\s+(?:\()?1 = 1(?:\))?\s*$/', $result); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model4` AS `TestModel4`\s+WHERE/', $result); + $this->assertPattern('/\s+WHERE\s+(?:\()?1 = 1(?:\))?\s*$/', $result); + } + +/** + * testGenerateAssociationQueryHasAndBelongsToManyWithConditions method + * + * @access public + * @return void + */ + function testGenerateAssociationQueryHasAndBelongsToManyWithConditions() { + $this->Model = new TestModel4(); + $this->Model->schema(); + $this->_buildRelatedModels($this->Model); + + $binding = array('type'=>'hasAndBelongsToMany', 'model'=>'TestModel7'); + $queryData = array('conditions' => array('TestModel4.name !=' => 'mariano')); + $resultSet = null; + $null = null; + + $params = $this->_prepareAssociationQuery($this->Model, $queryData, $binding); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + $this->assertPattern('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model7`\s+AS\s+`TestModel7`\s+JOIN\s+`test_model4_test_model7`\s+AS\s+`TestModel4TestModel7`/', $result); + $this->assertPattern('/\s+ON\s+\(`TestModel4TestModel7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}/', $result); + $this->assertPattern('/\s+AND\s+`TestModel4TestModel7`\.`test_model7_id`\s+=\s+`TestModel7`\.`id`\)\s+WHERE\s+/', $result); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model4` AS `TestModel4`\s+WHERE\s+(?:\()?`TestModel4`.`name`\s+!=\s+\'mariano\'(?:\))?\s*$/', $result); + } + +/** + * testGenerateAssociationQueryHasAndBelongsToManyWithOffsetAndLimit method + * + * @access public + * @return void + */ + function testGenerateAssociationQueryHasAndBelongsToManyWithOffsetAndLimit() { + $this->Model = new TestModel4(); + $this->Model->schema(); + $this->_buildRelatedModels($this->Model); + + $__backup = $this->Model->hasAndBelongsToMany['TestModel7']; + + $this->Model->hasAndBelongsToMany['TestModel7']['offset'] = 2; + $this->Model->hasAndBelongsToMany['TestModel7']['limit'] = 5; + + $binding = array('type'=>'hasAndBelongsToMany', 'model'=>'TestModel7'); + $queryData = array(); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + $this->assertPattern('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model7`\s+AS\s+`TestModel7`\s+JOIN\s+`test_model4_test_model7`\s+AS\s+`TestModel4TestModel7`/', $result); + $this->assertPattern('/\s+ON\s+\(`TestModel4TestModel7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}\s+/', $result); + $this->assertPattern('/\s+AND\s+`TestModel4TestModel7`\.`test_model7_id`\s+=\s+`TestModel7`\.`id`\)\s+WHERE\s+/', $result); + $this->assertPattern('/\s+(?:\()?1\s+=\s+1(?:\))?\s*\s+LIMIT 2,\s*5\s*$/', $result); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model4` AS `TestModel4`\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); + + $this->Model->hasAndBelongsToMany['TestModel7'] = $__backup; + } + +/** + * testGenerateAssociationQueryHasAndBelongsToManyWithPageAndLimit method + * + * @access public + * @return void + */ + function testGenerateAssociationQueryHasAndBelongsToManyWithPageAndLimit() { + $this->Model = new TestModel4(); + $this->Model->schema(); + $this->_buildRelatedModels($this->Model); + + $__backup = $this->Model->hasAndBelongsToMany['TestModel7']; + + $this->Model->hasAndBelongsToMany['TestModel7']['page'] = 2; + $this->Model->hasAndBelongsToMany['TestModel7']['limit'] = 5; + + $binding = array('type'=>'hasAndBelongsToMany', 'model'=>'TestModel7'); + $queryData = array(); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); + $this->assertPattern('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model7`\s+AS\s+`TestModel7`\s+JOIN\s+`test_model4_test_model7`\s+AS\s+`TestModel4TestModel7`/', $result); + $this->assertPattern('/\s+ON\s+\(`TestModel4TestModel7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}/', $result); + $this->assertPattern('/\s+AND\s+`TestModel4TestModel7`\.`test_model7_id`\s+=\s+`TestModel7`\.`id`\)\s+WHERE\s+/', $result); + $this->assertPattern('/\s+(?:\()?1\s+=\s+1(?:\))?\s*\s+LIMIT 5,\s*5\s*$/', $result); + + $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result); + $this->assertPattern('/\s+FROM\s+`test_model4` AS `TestModel4`\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); + + $this->Model->hasAndBelongsToMany['TestModel7'] = $__backup; + } + +/** + * testSelectDistict method + * + * @access public + * @return void + */ + function testSelectDistict() { + $this->Model = new TestModel4(); + $result = $this->Dbo->fields($this->Model, 'Vendor', "DISTINCT Vendor.id, Vendor.name"); + $expected = array('DISTINCT `Vendor`.`id`', '`Vendor`.`name`'); + $this->assertEqual($result, $expected); + } + +/** + * testStringConditionsParsing method + * + * @access public + * @return void + */ + function testStringConditionsParsing() { + $result = $this->Dbo->conditions("ProjectBid.project_id = Project.id"); + $expected = " WHERE `ProjectBid`.`project_id` = `Project`.`id`"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions("Candy.name LIKE 'a' AND HardCandy.name LIKE 'c'"); + $expected = " WHERE `Candy`.`name` LIKE 'a' AND `HardCandy`.`name` LIKE 'c'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions("HardCandy.name LIKE 'a' AND Candy.name LIKE 'c'"); + $expected = " WHERE `HardCandy`.`name` LIKE 'a' AND `Candy`.`name` LIKE 'c'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions("Post.title = '1.1'"); + $expected = " WHERE `Post`.`title` = '1.1'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions("User.id != 0 AND User.user LIKE '%arr%'"); + $expected = " WHERE `User`.`id` != 0 AND `User`.`user` LIKE '%arr%'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions("SUM(Post.comments_count) > 500"); + $expected = " WHERE SUM(`Post`.`comments_count`) > 500"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions("(Post.created < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR(Post.created), MONTH(Post.created)"); + $expected = " WHERE (`Post`.`created` < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR(`Post`.`created`), MONTH(`Post`.`created`)"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions("score BETWEEN 90.1 AND 95.7"); + $expected = " WHERE score BETWEEN 90.1 AND 95.7"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('score' => array(2=>1, 2, 10))); + $expected = " WHERE score IN (1, 2, 10)"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions("Aro.rght = Aro.lft + 1.1"); + $expected = " WHERE `Aro`.`rght` = `Aro`.`lft` + 1.1"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions("(Post.created < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR(Post.created), MONTH(Post.created)"); + $expected = " WHERE (`Post`.`created` < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR(`Post`.`created`), MONTH(`Post`.`created`)"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions('Sportstaette.sportstaette LIKE "%ru%" AND Sportstaette.sportstaettenart_id = 2'); + $expected = ' WHERE `Sportstaette`.`sportstaette` LIKE "%ru%" AND `Sportstaette`.`sportstaettenart_id` = 2'; + $this->assertPattern('/\s*WHERE\s+`Sportstaette`\.`sportstaette`\s+LIKE\s+"%ru%"\s+AND\s+`Sports/', $result); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions('Sportstaette.sportstaettenart_id = 2 AND Sportstaette.sportstaette LIKE "%ru%"'); + $expected = ' WHERE `Sportstaette`.`sportstaettenart_id` = 2 AND `Sportstaette`.`sportstaette` LIKE "%ru%"'; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions('SUM(Post.comments_count) > 500 AND NOT Post.title IS NULL AND NOT Post.extended_title IS NULL'); + $expected = ' WHERE SUM(`Post`.`comments_count`) > 500 AND NOT `Post`.`title` IS NULL AND NOT `Post`.`extended_title` IS NULL'; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions('NOT Post.title IS NULL AND NOT Post.extended_title IS NULL AND SUM(Post.comments_count) > 500'); + $expected = ' WHERE NOT `Post`.`title` IS NULL AND NOT `Post`.`extended_title` IS NULL AND SUM(`Post`.`comments_count`) > 500'; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions('NOT Post.extended_title IS NULL AND NOT Post.title IS NULL AND Post.title != "" AND SPOON(SUM(Post.comments_count) + 1.1) > 500'); + $expected = ' WHERE NOT `Post`.`extended_title` IS NULL AND NOT `Post`.`title` IS NULL AND `Post`.`title` != "" AND SPOON(SUM(`Post`.`comments_count`) + 1.1) > 500'; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions('NOT Post.title_extended IS NULL AND NOT Post.title IS NULL AND Post.title_extended != Post.title'); + $expected = ' WHERE NOT `Post`.`title_extended` IS NULL AND NOT `Post`.`title` IS NULL AND `Post`.`title_extended` != `Post`.`title`'; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions("Comment.id = 'a'"); + $expected = " WHERE `Comment`.`id` = 'a'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions("lower(Article.title) LIKE 'a%'"); + $expected = " WHERE lower(`Article`.`title`) LIKE 'a%'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions('((MATCH(Video.title) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 2) + (MATCH(Video.description) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 0.4) + (MATCH(Video.tags) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 1.5))'); + $expected = ' WHERE ((MATCH(`Video`.`title`) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 2) + (MATCH(`Video`.`description`) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 0.4) + (MATCH(`Video`.`tags`) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 1.5))'; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions('DATEDIFF(NOW(),Article.published) < 1 && Article.live=1'); + $expected = " WHERE DATEDIFF(NOW(),`Article`.`published`) < 1 && `Article`.`live`=1"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions('file = "index.html"'); + $expected = ' WHERE file = "index.html"'; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions("file = 'index.html'"); + $expected = " WHERE file = 'index.html'"; + $this->assertEqual($result, $expected); + + $letter = $letter = 'd.a'; + $conditions = array('Company.name like ' => $letter . '%'); + $result = $this->Dbo->conditions($conditions); + $expected = " WHERE `Company`.`name` like 'd.a%'"; + $this->assertEqual($result, $expected); + + $conditions = array('Artist.name' => 'JUDY and MARY'); + $result = $this->Dbo->conditions($conditions); + $expected = " WHERE `Artist`.`name` = 'JUDY and MARY'"; + $this->assertEqual($result, $expected); + + $conditions = array('Artist.name' => 'JUDY AND MARY'); + $result = $this->Dbo->conditions($conditions); + $expected = " WHERE `Artist`.`name` = 'JUDY AND MARY'"; + $this->assertEqual($result, $expected); + } + +/** + * testQuotesInStringConditions method + * + * @access public + * @return void + */ + function testQuotesInStringConditions() { + $result = $this->Dbo->conditions('Member.email = \'mariano@cricava.com\''); + $expected = ' WHERE `Member`.`email` = \'mariano@cricava.com\''; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions('Member.email = "mariano@cricava.com"'); + $expected = ' WHERE `Member`.`email` = "mariano@cricava.com"'; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions('Member.email = \'mariano@cricava.com\' AND Member.user LIKE \'mariano.iglesias%\''); + $expected = ' WHERE `Member`.`email` = \'mariano@cricava.com\' AND `Member`.`user` LIKE \'mariano.iglesias%\''; + $this->assertEqual($result, $expected); + + + $result = $this->Dbo->conditions('Member.email = "mariano@cricava.com" AND Member.user LIKE "mariano.iglesias%"'); + $expected = ' WHERE `Member`.`email` = "mariano@cricava.com" AND `Member`.`user` LIKE "mariano.iglesias%"'; + $this->assertEqual($result, $expected); + } + +/** + * testParenthesisInStringConditions method + * + * @access public + * @return void + */ + function testParenthesisInStringConditions() { + $result = $this->Dbo->conditions('Member.name = \'(lu\''); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(lu\'$/', $result); + + $result = $this->Dbo->conditions('Member.name = \')lu\''); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\)lu\'$/', $result); + + $result = $this->Dbo->conditions('Member.name = \'va(lu\''); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\(lu\'$/', $result); + + $result = $this->Dbo->conditions('Member.name = \'va)lu\''); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\)lu\'$/', $result); + + $result = $this->Dbo->conditions('Member.name = \'va(lu)\''); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\(lu\)\'$/', $result); + + $result = $this->Dbo->conditions('Member.name = \'va(lu)e\''); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\(lu\)e\'$/', $result); + + $result = $this->Dbo->conditions('Member.name = \'(mariano)\''); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano\)\'$/', $result); + + $result = $this->Dbo->conditions('Member.name = \'(mariano)iglesias\''); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano\)iglesias\'$/', $result); + + $result = $this->Dbo->conditions('Member.name = \'(mariano) iglesias\''); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano\) iglesias\'$/', $result); + + $result = $this->Dbo->conditions('Member.name = \'(mariano word) iglesias\''); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano word\) iglesias\'$/', $result); + + $result = $this->Dbo->conditions('Member.name = \'(mariano.iglesias)\''); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano.iglesias\)\'$/', $result); + + $result = $this->Dbo->conditions('Member.name = \'Mariano Iglesias (mariano.iglesias)\''); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'Mariano Iglesias \(mariano.iglesias\)\'$/', $result); + + $result = $this->Dbo->conditions('Member.name = \'Mariano Iglesias (mariano.iglesias) CakePHP\''); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'Mariano Iglesias \(mariano.iglesias\) CakePHP\'$/', $result); + + $result = $this->Dbo->conditions('Member.name = \'(mariano.iglesias) CakePHP\''); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano.iglesias\) CakePHP\'$/', $result); + } + +/** + * testParenthesisInArrayConditions method + * + * @access public + * @return void + */ + function testParenthesisInArrayConditions() { + $result = $this->Dbo->conditions(array('Member.name' => '(lu')); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(lu\'$/', $result); + + $result = $this->Dbo->conditions(array('Member.name' => ')lu')); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\)lu\'$/', $result); + + $result = $this->Dbo->conditions(array('Member.name' => 'va(lu')); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\(lu\'$/', $result); + + $result = $this->Dbo->conditions(array('Member.name' => 'va)lu')); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\)lu\'$/', $result); + + $result = $this->Dbo->conditions(array('Member.name' => 'va(lu)')); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\(lu\)\'$/', $result); + + $result = $this->Dbo->conditions(array('Member.name' => 'va(lu)e')); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\(lu\)e\'$/', $result); + + $result = $this->Dbo->conditions(array('Member.name' => '(mariano)')); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano\)\'$/', $result); + + $result = $this->Dbo->conditions(array('Member.name' => '(mariano)iglesias')); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano\)iglesias\'$/', $result); + + $result = $this->Dbo->conditions(array('Member.name' => '(mariano) iglesias')); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano\) iglesias\'$/', $result); + + $result = $this->Dbo->conditions(array('Member.name' => '(mariano word) iglesias')); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano word\) iglesias\'$/', $result); + + $result = $this->Dbo->conditions(array('Member.name' => '(mariano.iglesias)')); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano.iglesias\)\'$/', $result); + + $result = $this->Dbo->conditions(array('Member.name' => 'Mariano Iglesias (mariano.iglesias)')); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'Mariano Iglesias \(mariano.iglesias\)\'$/', $result); + + $result = $this->Dbo->conditions(array('Member.name' => 'Mariano Iglesias (mariano.iglesias) CakePHP')); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'Mariano Iglesias \(mariano.iglesias\) CakePHP\'$/', $result); + + $result = $this->Dbo->conditions(array('Member.name' => '(mariano.iglesias) CakePHP')); + $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano.iglesias\) CakePHP\'$/', $result); + } + +/** + * testArrayConditionsParsing method + * + * @access public + * @return void + */ + function testArrayConditionsParsing() { + $this->loadFixtures('Post', 'Author'); + $result = $this->Dbo->conditions(array('Stereo.type' => 'in dash speakers')); + $this->assertPattern("/^\s+WHERE\s+`Stereo`.`type`\s+=\s+'in dash speakers'/", $result); + + $result = $this->Dbo->conditions(array('Candy.name LIKE' => 'a', 'HardCandy.name LIKE' => 'c')); + $this->assertPattern("/^\s+WHERE\s+`Candy`.`name` LIKE\s+'a'\s+AND\s+`HardCandy`.`name`\s+LIKE\s+'c'/", $result); + + $result = $this->Dbo->conditions(array('HardCandy.name LIKE' => 'a', 'Candy.name LIKE' => 'c')); + $expected = " WHERE `HardCandy`.`name` LIKE 'a' AND `Candy`.`name` LIKE 'c'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('HardCandy.name LIKE' => 'a%', 'Candy.name LIKE' => '%c%')); + $expected = " WHERE `HardCandy`.`name` LIKE 'a%' AND `Candy`.`name` LIKE '%c%'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('HardCandy.name LIKE' => 'to be or%', 'Candy.name LIKE' => '%not to be%')); + $expected = " WHERE `HardCandy`.`name` LIKE 'to be or%' AND `Candy`.`name` LIKE '%not to be%'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('score BETWEEN ? AND ?' => array(90.1, 95.7))); + $expected = " WHERE `score` BETWEEN 90.100000 AND 95.700000"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('Post.title' => 1.1)); + $expected = " WHERE `Post`.`title` = 1.100000"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('Post.title' => 1.1), true, true, new Post()); + $expected = " WHERE `Post`.`title` = '1.1'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('SUM(Post.comments_count) >' => '500')); + $expected = " WHERE SUM(`Post`.`comments_count`) > '500'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('MAX(Post.rating) >' => '50')); + $expected = " WHERE MAX(`Post`.`rating`) > '50'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('title LIKE' => '%hello')); + $expected = " WHERE `title` LIKE '%hello'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('Post.name' => 'mad(g)ik')); + $expected = " WHERE `Post`.`name` = 'mad(g)ik'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('score' => array(1, 2, 10))); + $expected = " WHERE score IN (1, 2, 10)"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('score' => array())); + $expected = " WHERE `score` IS NULL"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('score !=' => array())); + $expected = " WHERE `score` IS NOT NULL"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('score !=' => '20')); + $expected = " WHERE `score` != '20'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('score >' => '20')); + $expected = " WHERE `score` > '20'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('client_id >' => '20'), true, true, new TestModel()); + $expected = " WHERE `client_id` > 20"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('OR' => array( + array('User.user' => 'mariano'), + array('User.user' => 'nate') + ))); + + $expected = " WHERE ((`User`.`user` = 'mariano') OR (`User`.`user` = 'nate'))"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('or' => array( + 'score BETWEEN ? AND ?' => array('4', '5'), 'rating >' => '20' + ))); + $expected = " WHERE ((`score` BETWEEN '4' AND '5') OR (`rating` > '20'))"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('or' => array( + 'score BETWEEN ? AND ?' => array('4', '5'), array('score >' => '20') + ))); + $expected = " WHERE ((`score` BETWEEN '4' AND '5') OR (`score` > '20'))"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('and' => array( + 'score BETWEEN ? AND ?' => array('4', '5'), array('score >' => '20') + ))); + $expected = " WHERE ((`score` BETWEEN '4' AND '5') AND (`score` > '20'))"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array( + 'published' => 1, 'or' => array('score >' => '2', array('score >' => '20')) + )); + $expected = " WHERE `published` = 1 AND ((`score` > '2') OR (`score` > '20'))"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array(array('Project.removed' => false))); + $expected = " WHERE `Project`.`removed` = '0'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array(array('Project.removed' => true))); + $expected = " WHERE `Project`.`removed` = '1'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array(array('Project.removed' => null))); + $expected = " WHERE `Project`.`removed` IS NULL"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array(array('Project.removed !=' => null))); + $expected = " WHERE `Project`.`removed` IS NOT NULL"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('(Usergroup.permissions) & 4' => 4)); + $expected = " WHERE (`Usergroup`.`permissions`) & 4 = 4"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('((Usergroup.permissions) & 4)' => 4)); + $expected = " WHERE ((`Usergroup`.`permissions`) & 4) = 4"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('Post.modified >=' => 'DATE_SUB(NOW(), INTERVAL 7 DAY)')); + $expected = " WHERE `Post`.`modified` >= 'DATE_SUB(NOW(), INTERVAL 7 DAY)'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('Post.modified >= DATE_SUB(NOW(), INTERVAL 7 DAY)')); + $expected = " WHERE `Post`.`modified` >= DATE_SUB(NOW(), INTERVAL 7 DAY)"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array( + 'NOT' => array('Course.id' => null, 'Course.vet' => 'N', 'level_of_education_id' => array(912,999)), + 'Enrollment.yearcompleted >' => '0') + ); + $this->assertPattern('/^\s*WHERE\s+\(NOT\s+\(`Course`\.`id` IS NULL\)\s+AND NOT\s+\(`Course`\.`vet`\s+=\s+\'N\'\)\s+AND NOT\s+\(level_of_education_id IN \(912, 999\)\)\)\s+AND\s+`Enrollment`\.`yearcompleted`\s+>\s+\'0\'\s*$/', $result); + + $result = $this->Dbo->conditions(array('id <>' => '8')); + $this->assertPattern('/^\s*WHERE\s+`id`\s+<>\s+\'8\'\s*$/', $result); + + $result = $this->Dbo->conditions(array('TestModel.field =' => 'gribe$@()lu')); + $expected = " WHERE `TestModel`.`field` = 'gribe$@()lu'"; + $this->assertEqual($result, $expected); + + $conditions['NOT'] = array('Listing.expiration BETWEEN ? AND ?' => array("1", "100")); + $conditions[0]['OR'] = array( + "Listing.title LIKE" => "%term%", + "Listing.description LIKE" => "%term%" + ); + $conditions[1]['OR'] = array( + "Listing.title LIKE" => "%term_2%", + "Listing.description LIKE" => "%term_2%" + ); + $result = $this->Dbo->conditions($conditions); + $expected = " WHERE NOT (`Listing`.`expiration` BETWEEN '1' AND '100') AND" . + " ((`Listing`.`title` LIKE '%term%') OR (`Listing`.`description` LIKE '%term%')) AND" . + " ((`Listing`.`title` LIKE '%term_2%') OR (`Listing`.`description` LIKE '%term_2%'))"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('MD5(CONCAT(Reg.email,Reg.id))' => 'blah')); + $expected = " WHERE MD5(CONCAT(`Reg`.`email`,`Reg`.`id`)) = 'blah'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array( + 'MD5(CONCAT(Reg.email,Reg.id))' => array('blah', 'blahblah') + )); + $expected = " WHERE MD5(CONCAT(`Reg`.`email`,`Reg`.`id`)) IN ('blah', 'blahblah')"; + $this->assertEqual($result, $expected); + + $conditions = array('id' => array(2, 5, 6, 9, 12, 45, 78, 43, 76)); + $result = $this->Dbo->conditions($conditions); + $expected = " WHERE id IN (2, 5, 6, 9, 12, 45, 78, 43, 76)"; + $this->assertEqual($result, $expected); + + $conditions = array('title' => 'user(s)'); + $result = $this->Dbo->conditions($conditions); + $expected = " WHERE `title` = 'user(s)'"; + $this->assertEqual($result, $expected); + + $conditions = array('title' => 'user(s) data'); + $result = $this->Dbo->conditions($conditions); + $expected = " WHERE `title` = 'user(s) data'"; + $this->assertEqual($result, $expected); + + $conditions = array('title' => 'user(s,arg) data'); + $result = $this->Dbo->conditions($conditions); + $expected = " WHERE `title` = 'user(s,arg) data'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array("Book.book_name" => 'Java(TM)')); + $expected = " WHERE `Book`.`book_name` = 'Java(TM)'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array("Book.book_name" => 'Java(TM) ')); + $expected = " WHERE `Book`.`book_name` = 'Java(TM) '"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array("Book.id" => 0)); + $expected = " WHERE `Book`.`id` = 0"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array("Book.id" => NULL)); + $expected = " WHERE `Book`.`id` IS NULL"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('Listing.beds >=' => 0)); + $expected = " WHERE `Listing`.`beds` >= 0"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array( + 'ASCII(SUBSTRING(keyword, 1, 1)) BETWEEN ? AND ?' => array(65, 90) + )); + $expected = ' WHERE ASCII(SUBSTRING(keyword, 1, 1)) BETWEEN 65 AND 90'; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('or' => array( + '? BETWEEN Model.field1 AND Model.field2' => '2009-03-04' + ))); + $expected = " WHERE '2009-03-04' BETWEEN Model.field1 AND Model.field2"; + $this->assertEqual($result, $expected); + } + +/** + * testArrayConditionsParsingComplexKeys method + * + * @access public + * @return void + */ + function testArrayConditionsParsingComplexKeys() { + $result = $this->Dbo->conditions(array( + 'CAST(Book.created AS DATE)' => '2008-08-02' + )); + $expected = " WHERE CAST(`Book`.`created` AS DATE) = '2008-08-02'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array( + 'CAST(Book.created AS DATE) <=' => '2008-08-02' + )); + $expected = " WHERE CAST(`Book`.`created` AS DATE) <= '2008-08-02'"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array( + '(Stats.clicks * 100) / Stats.views >' => 50 + )); + $expected = " WHERE (`Stats`.`clicks` * 100) / `Stats`.`views` > 50"; + $this->assertEqual($result, $expected); + } + +/** + * testMixedConditionsParsing method + * + * @access public + * @return void + */ + function testMixedConditionsParsing() { + $conditions[] = 'User.first_name = \'Firstname\''; + $conditions[] = array('User.last_name' => 'Lastname'); + $result = $this->Dbo->conditions($conditions); + $expected = " WHERE `User`.`first_name` = 'Firstname' AND `User`.`last_name` = 'Lastname'"; + $this->assertEqual($result, $expected); + + $conditions = array( + 'Thread.project_id' => 5, + 'Thread.buyer_id' => 14, + '1=1 GROUP BY Thread.project_id' + ); + $result = $this->Dbo->conditions($conditions); + $this->assertPattern('/^\s*WHERE\s+`Thread`.`project_id`\s*=\s*5\s+AND\s+`Thread`.`buyer_id`\s*=\s*14\s+AND\s+1\s*=\s*1\s+GROUP BY `Thread`.`project_id`$/', $result); + } + +/** + * testConditionsOptionalArguments method + * + * @access public + * @return void + */ + function testConditionsOptionalArguments() { + $result = $this->Dbo->conditions( array('Member.name' => 'Mariano'), true, false); + $this->assertPattern('/^\s*`Member`.`name`\s*=\s*\'Mariano\'\s*$/', $result); + + $result = $this->Dbo->conditions( array(), true, false); + $this->assertPattern('/^\s*1\s*=\s*1\s*$/', $result); + } + +/** + * testConditionsWithModel + * + * @access public + * @return void + */ + function testConditionsWithModel() { + $this->Model = new Article2(); + + $result = $this->Dbo->conditions(array('Article2.viewed >=' => 0), true, true, $this->Model); + $expected = " WHERE `Article2`.`viewed` >= 0"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('Article2.viewed >=' => '0'), true, true, $this->Model); + $expected = " WHERE `Article2`.`viewed` >= 0"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('Article2.viewed >=' => '1'), true, true, $this->Model); + $expected = " WHERE `Article2`.`viewed` >= 1"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('Article2.rate_sum BETWEEN ? AND ?' => array(0, 10)), true, true, $this->Model); + $expected = " WHERE `Article2`.`rate_sum` BETWEEN 0 AND 10"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('Article2.rate_sum BETWEEN ? AND ?' => array('0', '10')), true, true, $this->Model); + $expected = " WHERE `Article2`.`rate_sum` BETWEEN 0 AND 10"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->conditions(array('Article2.rate_sum BETWEEN ? AND ?' => array('1', '10')), true, true, $this->Model); + $expected = " WHERE `Article2`.`rate_sum` BETWEEN 1 AND 10"; + $this->assertEqual($result, $expected); + } + +/** + * testFieldParsing method + * + * @access public + * @return void + */ + function testFieldParsing() { + $this->Model = new TestModel(); + $result = $this->Dbo->fields($this->Model, 'Vendor', "Vendor.id, COUNT(Model.vendor_id) AS `Vendor`.`count`"); + $expected = array('`Vendor`.`id`', 'COUNT(`Model`.`vendor_id`) AS `Vendor`.`count`'); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->fields($this->Model, 'Vendor', "`Vendor`.`id`, COUNT(`Model`.`vendor_id`) AS `Vendor`.`count`"); + $expected = array('`Vendor`.`id`', 'COUNT(`Model`.`vendor_id`) AS `Vendor`.`count`'); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->fields($this->Model, 'Post', "CONCAT(REPEAT(' ', COUNT(Parent.name) - 1), Node.name) AS name, Node.created"); + $expected = array("CONCAT(REPEAT(' ', COUNT(`Parent`.`name`) - 1), Node.name) AS name", "`Node`.`created`"); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->fields($this->Model, null, 'round( (3.55441 * fooField), 3 ) AS test'); + $this->assertEqual($result, array('round( (3.55441 * fooField), 3 ) AS test')); + + $result = $this->Dbo->fields($this->Model, null, 'ROUND(`Rating`.`rate_total` / `Rating`.`rate_count`,2) AS rating'); + $this->assertEqual($result, array('ROUND(`Rating`.`rate_total` / `Rating`.`rate_count`,2) AS rating')); + + $result = $this->Dbo->fields($this->Model, null, 'ROUND(Rating.rate_total / Rating.rate_count,2) AS rating'); + $this->assertEqual($result, array('ROUND(Rating.rate_total / Rating.rate_count,2) AS rating')); + + $result = $this->Dbo->fields($this->Model, 'Post', "Node.created, CONCAT(REPEAT(' ', COUNT(Parent.name) - 1), Node.name) AS name"); + $expected = array("`Node`.`created`", "CONCAT(REPEAT(' ', COUNT(`Parent`.`name`) - 1), Node.name) AS name"); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->fields($this->Model, 'Post', "2.2,COUNT(*), SUM(Something.else) as sum, Node.created, CONCAT(REPEAT(' ', COUNT(Parent.name) - 1), Node.name) AS name,Post.title,Post.1,1.1"); + $expected = array( + '2.2', 'COUNT(*)', 'SUM(`Something`.`else`) as sum', '`Node`.`created`', + "CONCAT(REPEAT(' ', COUNT(`Parent`.`name`) - 1), Node.name) AS name", '`Post`.`title`', '`Post`.`1`', '1.1' + ); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->fields($this->Model, null, "(`Provider`.`star_total` / `Provider`.`total_ratings`) as `rating`"); + $expected = array("(`Provider`.`star_total` / `Provider`.`total_ratings`) as `rating`"); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->fields($this->Model, 'Post'); + $expected = array( + '`Post`.`id`', '`Post`.`client_id`', '`Post`.`name`', '`Post`.`login`', + '`Post`.`passwd`', '`Post`.`addr_1`', '`Post`.`addr_2`', '`Post`.`zip_code`', + '`Post`.`city`', '`Post`.`country`', '`Post`.`phone`', '`Post`.`fax`', + '`Post`.`url`', '`Post`.`email`', '`Post`.`comments`', '`Post`.`last_login`', + '`Post`.`created`', '`Post`.`updated`' + ); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->fields($this->Model, 'Other'); + $expected = array( + '`Other`.`id`', '`Other`.`client_id`', '`Other`.`name`', '`Other`.`login`', + '`Other`.`passwd`', '`Other`.`addr_1`', '`Other`.`addr_2`', '`Other`.`zip_code`', + '`Other`.`city`', '`Other`.`country`', '`Other`.`phone`', '`Other`.`fax`', + '`Other`.`url`', '`Other`.`email`', '`Other`.`comments`', '`Other`.`last_login`', + '`Other`.`created`', '`Other`.`updated`' + ); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->fields($this->Model, null, array(), false); + $expected = array('id', 'client_id', 'name', 'login', 'passwd', 'addr_1', 'addr_2', 'zip_code', 'city', 'country', 'phone', 'fax', 'url', 'email', 'comments', 'last_login', 'created', 'updated'); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->fields($this->Model, null, 'COUNT(*)'); + $expected = array('COUNT(*)'); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->fields($this->Model, null, 'SUM(Thread.unread_buyer) AS ' . $this->Dbo->name('sum_unread_buyer')); + $expected = array('SUM(`Thread`.`unread_buyer`) AS `sum_unread_buyer`'); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->fields($this->Model, null, 'name, count(*)'); + $expected = array('`TestModel`.`name`', 'count(*)'); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->fields($this->Model, null, 'count(*), name'); + $expected = array('count(*)', '`TestModel`.`name`'); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->fields( + $this->Model, null, 'field1, field2, field3, count(*), name' + ); + $expected = array( + '`TestModel`.`field1`', '`TestModel`.`field2`', + '`TestModel`.`field3`', 'count(*)', '`TestModel`.`name`' + ); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->fields($this->Model, null, array('dayofyear(now())')); + $expected = array('dayofyear(now())'); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->fields($this->Model, null, array('MAX(Model.field) As Max')); + $expected = array('MAX(`Model`.`field`) As Max'); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->fields($this->Model, null, array('Model.field AS AnotherName')); + $expected = array('`Model`.`field` AS `AnotherName`'); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->fields($this->Model, null, array('field AS AnotherName')); + $expected = array('`field` AS `AnotherName`'); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->fields($this->Model, null, array( + 'TestModel.field AS AnotherName' + )); + $expected = array('`TestModel`.`field` AS `AnotherName`'); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->fields($this->Model, 'Foo', array( + 'id', 'title', '(user_count + discussion_count + post_count) AS score' + )); + $expected = array( + '`Foo`.`id`', + '`Foo`.`title`', + '(user_count + discussion_count + post_count) AS score' + ); + $this->assertEqual($result, $expected); + } + +/** + * test that fields() will accept objects made from DboSource::expression + * + * @return void + */ + function testFieldsWithExpression() { + $this->Model = new TestModel; + $expression = $this->Dbo->expression("CASE Sample.id WHEN 1 THEN 'Id One' ELSE 'Other Id' END AS case_col"); + $result = $this->Dbo->fields($this->Model, null, array("id", $expression)); + $expected = array( + '`TestModel`.`id`', + "CASE Sample.id WHEN 1 THEN 'Id One' ELSE 'Other Id' END AS case_col" + ); + $this->assertEqual($result, $expected); + } + +/** + * testRenderStatement method + * + * @access public + * @return void + */ + function testRenderStatement() { + $result = $this->Dbo->renderStatement('select', array( + 'fields' => 'id', 'table' => 'table', 'conditions' => 'WHERE 1=1', + 'alias' => '', 'joins' => '', 'order' => '', 'limit' => '', 'group' => '' + )); + $this->assertPattern('/^\s*SELECT\s+id\s+FROM\s+table\s+WHERE\s+1=1\s*$/', $result); + + $result = $this->Dbo->renderStatement('update', array('fields' => 'value=2', 'table' => 'table', 'conditions' => 'WHERE 1=1', 'alias' => '')); + $this->assertPattern('/^\s*UPDATE\s+table\s+SET\s+value=2\s+WHERE\s+1=1\s*$/', $result); + + $result = $this->Dbo->renderStatement('update', array('fields' => 'value=2', 'table' => 'table', 'conditions' => 'WHERE 1=1', 'alias' => 'alias', 'joins' => '')); + $this->assertPattern('/^\s*UPDATE\s+table\s+AS\s+alias\s+SET\s+value=2\s+WHERE\s+1=1\s*$/', $result); + + $result = $this->Dbo->renderStatement('delete', array('fields' => 'value=2', 'table' => 'table', 'conditions' => 'WHERE 1=1', 'alias' => '')); + $this->assertPattern('/^\s*DELETE\s+FROM\s+table\s+WHERE\s+1=1\s*$/', $result); + + $result = $this->Dbo->renderStatement('delete', array('fields' => 'value=2', 'table' => 'table', 'conditions' => 'WHERE 1=1', 'alias' => 'alias', 'joins' => '')); + $this->assertPattern('/^\s*DELETE\s+alias\s+FROM\s+table\s+AS\s+alias\s+WHERE\s+1=1\s*$/', $result); + } + +/** + * testSchema method + * + * @access public + * @return void + */ + function testSchema() { + $Schema = new CakeSchema(); + $Schema->tables = array('table' => array(), 'anotherTable' => array()); + + $this->expectError(); + $result = $this->Dbo->dropSchema(null); + $this->assertTrue($result === null); + + $result = $this->Dbo->dropSchema($Schema, 'non_existing'); + $this->assertTrue(empty($result)); + + $result = $this->Dbo->dropSchema($Schema, 'table'); + $this->assertPattern('/^\s*DROP TABLE IF EXISTS\s+' . $this->Dbo->fullTableName('table') . ';\s*$/s', $result); + } + +/** + * testOrderParsing method + * + * @access public + * @return void + */ + function testOrderParsing() { + $result = $this->Dbo->order("ADDTIME(Event.time_begin, '-06:00:00') ASC"); + $expected = " ORDER BY ADDTIME(`Event`.`time_begin`, '-06:00:00') ASC"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->order("title, id"); + $this->assertPattern('/^\s*ORDER BY\s+`title`\s+ASC,\s+`id`\s+ASC\s*$/', $result); + + $result = $this->Dbo->order("title desc, id desc"); + $this->assertPattern('/^\s*ORDER BY\s+`title`\s+desc,\s+`id`\s+desc\s*$/', $result); + + $result = $this->Dbo->order(array("title desc, id desc")); + $this->assertPattern('/^\s*ORDER BY\s+`title`\s+desc,\s+`id`\s+desc\s*$/', $result); + + $result = $this->Dbo->order(array("title", "id")); + $this->assertPattern('/^\s*ORDER BY\s+`title`\s+ASC,\s+`id`\s+ASC\s*$/', $result); + + $result = $this->Dbo->order(array(array('title'), array('id'))); + $this->assertPattern('/^\s*ORDER BY\s+`title`\s+ASC,\s+`id`\s+ASC\s*$/', $result); + + $result = $this->Dbo->order(array("Post.title" => 'asc', "Post.id" => 'desc')); + $this->assertPattern('/^\s*ORDER BY\s+`Post`.`title`\s+asc,\s+`Post`.`id`\s+desc\s*$/', $result); + + $result = $this->Dbo->order(array(array("Post.title" => 'asc', "Post.id" => 'desc'))); + $this->assertPattern('/^\s*ORDER BY\s+`Post`.`title`\s+asc,\s+`Post`.`id`\s+desc\s*$/', $result); + + $result = $this->Dbo->order(array("title")); + $this->assertPattern('/^\s*ORDER BY\s+`title`\s+ASC\s*$/', $result); + + $result = $this->Dbo->order(array(array("title"))); + $this->assertPattern('/^\s*ORDER BY\s+`title`\s+ASC\s*$/', $result); + + $result = $this->Dbo->order("Dealer.id = 7 desc, Dealer.id = 3 desc, Dealer.title asc"); + $expected = " ORDER BY `Dealer`.`id` = 7 desc, `Dealer`.`id` = 3 desc, `Dealer`.`title` asc"; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->order(array("Page.name" => "='test' DESC")); + $this->assertPattern("/^\s*ORDER BY\s+`Page`\.`name`\s*='test'\s+DESC\s*$/", $result); + + $result = $this->Dbo->order("Page.name = 'view' DESC"); + $this->assertPattern("/^\s*ORDER BY\s+`Page`\.`name`\s*=\s*'view'\s+DESC\s*$/", $result); + + $result = $this->Dbo->order("(Post.views)"); + $this->assertPattern("/^\s*ORDER BY\s+\(`Post`\.`views`\)\s+ASC\s*$/", $result); + + $result = $this->Dbo->order("(Post.views)*Post.views"); + $this->assertPattern("/^\s*ORDER BY\s+\(`Post`\.`views`\)\*`Post`\.`views`\s+ASC\s*$/", $result); + + $result = $this->Dbo->order("(Post.views) * Post.views"); + $this->assertPattern("/^\s*ORDER BY\s+\(`Post`\.`views`\) \* `Post`\.`views`\s+ASC\s*$/", $result); + + $result = $this->Dbo->order("(Model.field1 + Model.field2) * Model.field3"); + $this->assertPattern("/^\s*ORDER BY\s+\(`Model`\.`field1` \+ `Model`\.`field2`\) \* `Model`\.`field3`\s+ASC\s*$/", $result); + + $result = $this->Dbo->order("Model.name+0 ASC"); + $this->assertPattern("/^\s*ORDER BY\s+`Model`\.`name`\+0\s+ASC\s*$/", $result); + + $result = $this->Dbo->order("Anuncio.destaque & 2 DESC"); + $expected = ' ORDER BY `Anuncio`.`destaque` & 2 DESC'; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->order("3963.191 * id"); + $expected = ' ORDER BY 3963.191 * id ASC'; + $this->assertEqual($result, $expected); + + $result = $this->Dbo->order(array('Property.sale_price IS NULL')); + $expected = ' ORDER BY `Property`.`sale_price` IS NULL ASC'; + $this->assertEqual($result, $expected); + } + +/** + * testComplexSortExpression method + * + * @return void + */ + public function testComplexSortExpression() { + $result = $this->Dbo->order(array('(Model.field > 100) DESC', 'Model.field ASC')); + $this->assertPattern("/^\s*ORDER BY\s+\(`Model`\.`field`\s+>\s+100\)\s+DESC,\s+`Model`\.`field`\s+ASC\s*$/", $result); + } + +/** + * testCalculations method + * + * @access public + * @return void + */ + function testCalculations() { + $this->Model = new TestModel(); + $result = $this->Dbo->calculate($this->Model, 'count'); + $this->assertEqual($result, 'COUNT(*) AS `count`'); + + $result = $this->Dbo->calculate($this->Model, 'count', array('id')); + $this->assertEqual($result, 'COUNT(`id`) AS `count`'); + + $result = $this->Dbo->calculate( + $this->Model, + 'count', + array($this->Dbo->expression('DISTINCT id')) + ); + $this->assertEqual($result, 'COUNT(DISTINCT id) AS `count`'); + + $result = $this->Dbo->calculate($this->Model, 'count', array('id', 'id_count')); + $this->assertEqual($result, 'COUNT(`id`) AS `id_count`'); + + $result = $this->Dbo->calculate($this->Model, 'count', array('Model.id', 'id_count')); + $this->assertEqual($result, 'COUNT(`Model`.`id`) AS `id_count`'); + + $result = $this->Dbo->calculate($this->Model, 'max', array('id')); + $this->assertEqual($result, 'MAX(`id`) AS `id`'); + + $result = $this->Dbo->calculate($this->Model, 'max', array('Model.id', 'id')); + $this->assertEqual($result, 'MAX(`Model`.`id`) AS `id`'); + + $result = $this->Dbo->calculate($this->Model, 'max', array('`Model`.`id`', 'id')); + $this->assertEqual($result, 'MAX(`Model`.`id`) AS `id`'); + + $result = $this->Dbo->calculate($this->Model, 'min', array('`Model`.`id`', 'id')); + $this->assertEqual($result, 'MIN(`Model`.`id`) AS `id`'); + + $result = $this->Dbo->calculate($this->Model, 'min', 'left'); + $this->assertEqual($result, 'MIN(`left`) AS `left`'); + } + +/** + * testLength method + * + * @access public + * @return void + */ + function testLength() { + $result = $this->Dbo->length('varchar(255)'); + $expected = 255; + $this->assertIdentical($result, $expected); + + $result = $this->Dbo->length('int(11)'); + $expected = 11; + $this->assertIdentical($result, $expected); + + $result = $this->Dbo->length('float(5,3)'); + $expected = '5,3'; + $this->assertIdentical($result, $expected); + + $result = $this->Dbo->length('decimal(5,2)'); + $expected = '5,2'; + $this->assertIdentical($result, $expected); + + $result = $this->Dbo->length("enum('test','me','now')"); + $expected = 4; + $this->assertIdentical($result, $expected); + + $result = $this->Dbo->length("set('a','b','cd')"); + $expected = 2; + $this->assertIdentical($result, $expected); + + $this->expectError(); + $result = $this->Dbo->length(false); + $this->assertTrue($result === null); + + $result = $this->Dbo->length('datetime'); + $expected = null; + $this->assertIdentical($result, $expected); + + $result = $this->Dbo->length('text'); + $expected = null; + $this->assertIdentical($result, $expected); + } + +/** + * testBuildIndex method + * + * @access public + * @return void + */ + function testBuildIndex() { + $data = array( + 'PRIMARY' => array('column' => 'id') + ); + $result = $this->Dbo->buildIndex($data); + $expected = array('PRIMARY KEY (`id`)'); + $this->assertIdentical($result, $expected); + + $data = array( + 'MyIndex' => array('column' => 'id', 'unique' => true) + ); + $result = $this->Dbo->buildIndex($data); + $expected = array('UNIQUE KEY `MyIndex` (`id`)'); + $this->assertEqual($result, $expected); + + $data = array( + 'MyIndex' => array('column' => array('id', 'name'), 'unique' => true) + ); + $result = $this->Dbo->buildIndex($data); + $expected = array('UNIQUE KEY `MyIndex` (`id`, `name`)'); + $this->assertEqual($result, $expected); + } + +/** + * testBuildColumn method + * + * @access public + * @return void + */ + function testBuildColumn2() { + $this->expectError(); + $data = array( + 'name' => 'testName', + 'type' => 'varchar(255)', + 'default', + 'null' => true, + 'key' + ); + $this->Dbo->buildColumn($data); + + $data = array( + 'name' => 'testName', + 'type' => 'string', + 'length' => 255, + 'default', + 'null' => true, + 'key' + ); + $result = $this->Dbo->buildColumn($data); + $expected = '`testName` varchar(255) DEFAULT NULL'; + $this->assertEqual($result, $expected); + + $data = array( + 'name' => 'int_field', + 'type' => 'integer', + 'default' => '', + 'null' => false, + ); + $restore = $this->Dbo->columns; + + $this->Dbo->columns = array('integer' => array('name' => 'int', 'limit' => '11', 'formatter' => 'intval'), ); + $result = $this->Dbo->buildColumn($data); + $expected = '`int_field` int(11) NOT NULL'; + $this->assertEqual($result, $expected); + + $this->Dbo->fieldParameters['param'] = array( + 'value' => 'COLLATE', + 'quote' => false, + 'join' => ' ', + 'column' => 'Collate', + 'position' => 'beforeDefault', + 'options' => array('GOOD', 'OK') + ); + $data = array( + 'name' => 'int_field', + 'type' => 'integer', + 'default' => '', + 'null' => false, + 'param' => 'BAD' + ); + $result = $this->Dbo->buildColumn($data); + $expected = '`int_field` int(11) NOT NULL'; + $this->assertEqual($result, $expected); + + $data = array( + 'name' => 'int_field', + 'type' => 'integer', + 'default' => '', + 'null' => false, + 'param' => 'GOOD' + ); + $result = $this->Dbo->buildColumn($data); + $expected = '`int_field` int(11) COLLATE GOOD NOT NULL'; + $this->assertEqual($result, $expected); + + $this->Dbo->columns = $restore; + + $data = array( + 'name' => 'created', + 'type' => 'timestamp', + 'default' => 'current_timestamp', + 'null' => false, + ); + $result = $this->Dbo->buildColumn($data); + $expected = '`created` timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL'; + $this->assertEqual($result, $expected); + + $data = array( + 'name' => 'created', + 'type' => 'timestamp', + 'default' => 'CURRENT_TIMESTAMP', + 'null' => true, + ); + $result = $this->Dbo->buildColumn($data); + $expected = '`created` timestamp DEFAULT CURRENT_TIMESTAMP'; + $this->assertEqual($result, $expected); + + $data = array( + 'name' => 'modified', + 'type' => 'timestamp', + 'null' => true, + ); + $result = $this->Dbo->buildColumn($data); + $expected = '`modified` timestamp NULL'; + $this->assertEqual($result, $expected); + + $data = array( + 'name' => 'modified', + 'type' => 'timestamp', + 'default' => null, + 'null' => true, + ); + $result = $this->Dbo->buildColumn($data); + $expected = '`modified` timestamp NULL'; + $this->assertEqual($result, $expected); + } + +/** + * test hasAny() + * + * @return void + */ + function testHasAny() { + $this->Dbo = $this->getMock('DboMysql', array('connect', '_execute', 'execute', 'value')); + $this->Model = $this->getMock('TestModel', array('getDataSource')); + $this->Model->expects($this->any()) + ->method('getDataSource') + ->will($this->returnValue($this->Dbo)); + + $this->Dbo->expects($this->at(0))->method('value') + ->with('harry') + ->will($this->returnValue("'harry'")); + + $this->Dbo->expects($this->at(1))->method('execute') + ->with('SELECT COUNT(`TestModel`.`id`) AS count FROM `test_models` AS `TestModel` WHERE `TestModel`.`name` = \'harry\''); + $this->Dbo->expects($this->at(2))->method('execute') + ->with('SELECT COUNT(`TestModel`.`id`) AS count FROM `test_models` AS `TestModel` WHERE 1 = 1'); + + $this->Dbo->hasAny($this->Model, array('TestModel.name' => 'harry')); + $this->Dbo->hasAny($this->Model, array()); + + } + +/** + * test fields generating usable virtual fields to use in query + * + * @return void + */ + function testVirtualFields() { + $this->loadFixtures('Article', 'Comment'); + $this->Dbo->virtualFieldSeparator = '__'; + $Article = ClassRegistry::init('Article'); + $Article->virtualFields = array( + 'this_moment' => 'NOW()', + 'two' => '1 + 1', + 'comment_count' => 'SELECT COUNT(*) FROM ' . $this->Dbo->fullTableName('comments') . + ' WHERE Article.id = ' . $this->Dbo->fullTableName('comments') . '.article_id' + ); + $result = $this->Dbo->fields($Article); + $expected = array( + '`Article`.`id`', + '`Article`.`user_id`', + '`Article`.`title`', + '`Article`.`body`', + '`Article`.`published`', + '`Article`.`created`', + '`Article`.`updated`', + '(NOW()) AS `Article__this_moment`', + '(1 + 1) AS `Article__two`', + '(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) AS `Article__comment_count`' + ); + $this->assertEqual($expected, $result); + + $result = $this->Dbo->fields($Article, null, array('this_moment', 'title')); + $expected = array( + '`Article`.`title`', + '(NOW()) AS `Article__this_moment`', + ); + $this->assertEqual($expected, $result); + + $result = $this->Dbo->fields($Article, null, array('Article.title', 'Article.this_moment')); + $expected = array( + '`Article`.`title`', + '(NOW()) AS `Article__this_moment`', + ); + $this->assertEqual($expected, $result); + + $result = $this->Dbo->fields($Article, null, array('Article.this_moment', 'Article.title')); + $expected = array( + '`Article`.`title`', + '(NOW()) AS `Article__this_moment`', + ); + $this->assertEqual($expected, $result); + + $result = $this->Dbo->fields($Article, null, array('Article.*')); + $expected = array( + '`Article`.*', + '(NOW()) AS `Article__this_moment`', + '(1 + 1) AS `Article__two`', + '(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) AS `Article__comment_count`' + ); + $this->assertEqual($expected, $result); + + $result = $this->Dbo->fields($Article, null, array('*')); + $expected = array( + '*', + '(NOW()) AS `Article__this_moment`', + '(1 + 1) AS `Article__two`', + '(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) AS `Article__comment_count`' + ); + $this->assertEqual($expected, $result); + } + +/** + * test conditions to generate query conditions for virtual fields + * + * @return void + */ + function testVirtualFieldsInConditions() { + $Article = ClassRegistry::init('Article'); + $Article->virtualFields = array( + 'this_moment' => 'NOW()', + 'two' => '1 + 1', + 'comment_count' => 'SELECT COUNT(*) FROM ' . $this->Dbo->fullTableName('comments') . + ' WHERE Article.id = ' . $this->Dbo->fullTableName('comments') . '.article_id' + ); + $conditions = array('two' => 2); + $result = $this->Dbo->conditions($conditions, true, false, $Article); + $expected = '(1 + 1) = 2'; + $this->assertEqual($expected, $result); + + $conditions = array('this_moment BETWEEN ? AND ?' => array(1,2)); + $expected = 'NOW() BETWEEN 1 AND 2'; + $result = $this->Dbo->conditions($conditions, true, false, $Article); + $this->assertEqual($expected, $result); + + $conditions = array('comment_count >' => 5); + $expected = '(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) > 5'; + $result = $this->Dbo->conditions($conditions, true, false, $Article); + $this->assertEqual($expected, $result); + + $conditions = array('NOT' => array('two' => 2)); + $result = $this->Dbo->conditions($conditions, true, false, $Article); + $expected = 'NOT ((1 + 1) = 2)'; + $this->assertEqual($expected, $result); + } + +/** + * test that virtualFields with complex functions and aliases work. + * + * @return void + */ + function testConditionsWithComplexVirtualFields() { + $Article = ClassRegistry::init('Article'); + $Article->virtualFields = array( + 'distance' => 'ACOS(SIN(20 * PI() / 180) + * SIN(Article.latitude * PI() / 180) + + COS(20 * PI() / 180) + * COS(Article.latitude * PI() / 180) + * COS((50 - Article.longitude) * PI() / 180) + ) * 180 / PI() * 60 * 1.1515 * 1.609344' + ); + $conditions = array('distance >=' => 20); + $result = $this->Dbo->conditions($conditions, true, true, $Article); + + $this->assertPattern('/\) >= 20/', $result); + $this->assertPattern('/[`\'"]Article[`\'"].[`\'"]latitude[`\'"]/', $result); + $this->assertPattern('/[`\'"]Article[`\'"].[`\'"]longitude[`\'"]/', $result); + } + +/** + * test calculate to generate claculate statements on virtual fields + * + * @return void + */ + function testVirtualFieldsInCalculate() { + $Article = ClassRegistry::init('Article'); + $Article->virtualFields = array( + 'this_moment' => 'NOW()', + 'two' => '1 + 1', + 'comment_count' => 'SELECT COUNT(*) FROM ' . $this->Dbo->fullTableName('comments') . + ' WHERE Article.id = ' . $this->Dbo->fullTableName('comments'). '.article_id' + ); + + $result = $this->Dbo->calculate($Article, 'count', array('this_moment')); + $expected = 'COUNT(NOW()) AS `count`'; + $this->assertEqual($expected, $result); + + $result = $this->Dbo->calculate($Article, 'max', array('comment_count')); + $expected = 'MAX(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) AS `comment_count`'; + $this->assertEqual($expected, $result); + } + +/** + * test reading virtual fields containing newlines when recursive > 0 + * + * @return void + */ + function testReadVirtualFieldsWithNewLines() { + $Article = new Article(); + $Article->recursive = 1; + $Article->virtualFields = array( + 'test' => ' + User.id + User.id + ' + ); + $result = $this->Dbo->fields($Article, null, array()); + $result = $this->Dbo->fields($Article, $Article->alias, $result); + $this->assertPattern('/[`\"]User[`\"]\.[`\"]id[`\"] \+ [`\"]User[`\"]\.[`\"]id[`\"]/', $result[7]); + } + +/** + * test group to generate GROUP BY statements on virtual fields + * + * @return void + */ + function testVirtualFieldsInGroup() { + $Article = ClassRegistry::init('Article'); + $Article->virtualFields = array( + 'this_year' => 'YEAR(Article.created)' + ); + + $result = $this->Dbo->group('this_year', $Article); + + $expected = " GROUP BY (YEAR(`Article`.`created`))"; + $this->assertEqual($expected, $result); + } + +/** + * test that virtualFields with complex functions and aliases work. + * + * @return void + */ + function testFieldsWithComplexVirtualFields() { + $Article = new Article(); + $Article->virtualFields = array( + 'distance' => 'ACOS(SIN(20 * PI() / 180) + * SIN(Article.latitude * PI() / 180) + + COS(20 * PI() / 180) + * COS(Article.latitude * PI() / 180) + * COS((50 - Article.longitude) * PI() / 180) + ) * 180 / PI() * 60 * 1.1515 * 1.609344' + ); + + $fields = array('id', 'distance'); + $result = $this->Dbo->fields($Article, null, $fields); + $qs = $this->Dbo->startQuote; + $qe = $this->Dbo->endQuote; + + $this->assertEqual($result[0], "{$qs}Article{$qe}.{$qs}id{$qe}"); + $this->assertPattern('/Article__distance/', $result[1]); + $this->assertPattern('/[`\'"]Article[`\'"].[`\'"]latitude[`\'"]/', $result[1]); + $this->assertPattern('/[`\'"]Article[`\'"].[`\'"]longitude[`\'"]/', $result[1]); + } + +/** + * test that execute runs queries. + * + * @return void + */ + function testExecute() { + $query = 'SELECT * FROM ' . $this->Dbo->fullTableName('articles') . ' WHERE 1 = 1'; + $this->Dbo->took = null; + $this->Dbo->affected = null; + $result = $this->Dbo->execute($query, array('log' => false)); + $this->assertNotNull($result, 'No query performed! %s'); + $this->assertNull($this->Dbo->took, 'Stats were set %s'); + $this->assertNull($this->Dbo->affected, 'Stats were set %s'); + + $result = $this->Dbo->execute($query); + $this->assertNotNull($result, 'No query performed! %s'); + $this->assertNotNull($this->Dbo->took, 'Stats were not set %s'); + $this->assertNotNull($this->Dbo->affected, 'Stats were not set %s'); + } + +/** + * test a full example of using virtual fields + * + * @return void + */ + function testVirtualFieldsFetch() { + $this->loadFixtures('Article', 'Comment'); + + $Article = ClassRegistry::init('Article'); + $Article->virtualFields = array( + 'comment_count' => 'SELECT COUNT(*) FROM ' . $this->Dbo->fullTableName('comments') . + ' WHERE Article.id = ' . $this->Dbo->fullTableName('comments') . '.article_id' + ); + + $conditions = array('comment_count >' => 2); + $query = 'SELECT ' . join(',',$this->Dbo->fields($Article, null, array('id', 'comment_count'))) . + ' FROM ' . $this->Dbo->fullTableName($Article) . ' Article ' . $this->Dbo->conditions($conditions, true, true, $Article); + $result = $this->Dbo->fetchAll($query); + $expected = array(array( + 'Article' => array('id' => 1, 'comment_count' => 4) + )); + $this->assertEqual($expected, $result); + } + +/** + * test reading complex virtualFields with subqueries. + * + * @return void + */ + function testVirtualFieldsComplexRead() { + $this->loadFixtures('DataTest', 'Article', 'Comment', 'User', 'Tag', 'ArticlesTag'); + + $Article = ClassRegistry::init('Article'); + $commentTable = $this->Dbo->fullTableName('comments'); + $Article = ClassRegistry::init('Article'); + $Article->virtualFields = array( + 'comment_count' => 'SELECT COUNT(*) FROM ' . $commentTable . + ' AS Comment WHERE Article.id = Comment.article_id' + ); + $result = $Article->find('all'); + $this->assertTrue(count($result) > 0); + $this->assertTrue($result[0]['Article']['comment_count'] > 0); + + $DataTest = ClassRegistry::init('DataTest'); + $DataTest->virtualFields = array( + 'complicated' => 'ACOS(SIN(20 * PI() / 180) + * SIN(DataTest.float * PI() / 180) + + COS(20 * PI() / 180) + * COS(DataTest.count * PI() / 180) + * COS((50 - DataTest.float) * PI() / 180) + ) * 180 / PI() * 60 * 1.1515 * 1.609344' + ); + $result = $DataTest->find('all'); + $this->assertTrue(count($result) > 0); + $this->assertTrue($result[0]['DataTest']['complicated'] > 0); + } + +/** + * testIntrospectType method + * + * @access public + * @return void + */ + function testIntrospectType() { + $this->assertEqual($this->Dbo->introspectType(0), 'integer'); + $this->assertEqual($this->Dbo->introspectType(2), 'integer'); + $this->assertEqual($this->Dbo->introspectType('2'), 'string'); + $this->assertEqual($this->Dbo->introspectType('2.2'), 'string'); + $this->assertEqual($this->Dbo->introspectType(2.2), 'float'); + $this->assertEqual($this->Dbo->introspectType('stringme'), 'string'); + $this->assertEqual($this->Dbo->introspectType('0stringme'), 'string'); + + $data = array(2.2); + $this->assertEqual($this->Dbo->introspectType($data), 'float'); + + $data = array('2.2'); + $this->assertEqual($this->Dbo->introspectType($data), 'float'); + + $data = array(2); + $this->assertEqual($this->Dbo->introspectType($data), 'integer'); + + $data = array('2'); + $this->assertEqual($this->Dbo->introspectType($data), 'integer'); + + $data = array('string'); + $this->assertEqual($this->Dbo->introspectType($data), 'string'); + + $data = array(2.2, '2.2'); + $this->assertEqual($this->Dbo->introspectType($data), 'float'); + + $data = array(2, '2'); + $this->assertEqual($this->Dbo->introspectType($data), 'integer'); + + $data = array('string one', 'string two'); + $this->assertEqual($this->Dbo->introspectType($data), 'string'); + + $data = array('2.2', 3); + $this->assertEqual($this->Dbo->introspectType($data), 'integer'); + + $data = array('2.2', '0stringme'); + $this->assertEqual($this->Dbo->introspectType($data), 'string'); + + $data = array(2.2, 3); + $this->assertEqual($this->Dbo->introspectType($data), 'integer'); + + $data = array(2.2, '0stringme'); + $this->assertEqual($this->Dbo->introspectType($data), 'string'); + + $data = array(2, 'stringme'); + $this->assertEqual($this->Dbo->introspectType($data), 'string'); + + $data = array(2, '2.2', 'stringgme'); + $this->assertEqual($this->Dbo->introspectType($data), 'string'); + + $data = array(2, '2.2'); + $this->assertEqual($this->Dbo->introspectType($data), 'integer'); + + $data = array(2, 2.2); + $this->assertEqual($this->Dbo->introspectType($data), 'integer'); + + + // NULL + $result = $this->Dbo->value(null, 'boolean'); + $this->assertEqual($result, 'NULL'); + + // EMPTY STRING + $result = $this->Dbo->value('', 'boolean'); + $this->assertEqual($result, "'0'"); + + + // BOOLEAN + $result = $this->Dbo->value('true', 'boolean'); + $this->assertEqual($result, "'1'"); + + $result = $this->Dbo->value('false', 'boolean'); + $this->assertEqual($result, "'1'"); + + $result = $this->Dbo->value(true, 'boolean'); + $this->assertEqual($result, "'1'"); + + $result = $this->Dbo->value(false, 'boolean'); + $this->assertEqual($result, "'0'"); + + $result = $this->Dbo->value(1, 'boolean'); + $this->assertEqual($result, "'1'"); + + $result = $this->Dbo->value(0, 'boolean'); + $this->assertEqual($result, "'0'"); + + $result = $this->Dbo->value('abc', 'boolean'); + $this->assertEqual($result, "'1'"); + + $result = $this->Dbo->value(1.234, 'boolean'); + $this->assertEqual($result, "'1'"); + + $result = $this->Dbo->value('1.234e05', 'boolean'); + $this->assertEqual($result, "'1'"); + + // NUMBERS + $result = $this->Dbo->value(123, 'integer'); + $this->assertEqual($result, 123); + + $result = $this->Dbo->value('123', 'integer'); + $this->assertEqual($result, '123'); + + $result = $this->Dbo->value('0123', 'integer'); + $this->assertEqual($result, "'0123'"); + + $result = $this->Dbo->value('0x123ABC', 'integer'); + $this->assertEqual($result, "'0x123ABC'"); + + $result = $this->Dbo->value('0x123', 'integer'); + $this->assertEqual($result, "'0x123'"); + + $result = $this->Dbo->value(1.234, 'float'); + $this->assertEqual($result, 1.234); + + $result = $this->Dbo->value('1.234', 'float'); + $this->assertEqual($result, '1.234'); + + $result = $this->Dbo->value(' 1.234 ', 'float'); + $this->assertEqual($result, "' 1.234 '"); + + $result = $this->Dbo->value('1.234e05', 'float'); + $this->assertEqual($result, "'1.234e05'"); + + $result = $this->Dbo->value('1.234e+5', 'float'); + $this->assertEqual($result, "'1.234e+5'"); + + $result = $this->Dbo->value('1,234', 'float'); + $this->assertEqual($result, "'1,234'"); + + $result = $this->Dbo->value('FFF', 'integer'); + $this->assertEqual($result, "'FFF'"); + + $result = $this->Dbo->value('abc', 'integer'); + $this->assertEqual($result, "'abc'"); + + // STRINGS + $result = $this->Dbo->value('123', 'string'); + $this->assertEqual($result, "'123'"); + + $result = $this->Dbo->value(123, 'string'); + $this->assertEqual($result, "'123'"); + + $result = $this->Dbo->value(1.234, 'string'); + $this->assertEqual($result, "'1.234'"); + + $result = $this->Dbo->value('abc', 'string'); + $this->assertEqual($result, "'abc'"); + + $result = $this->Dbo->value(' abc ', 'string'); + $this->assertEqual($result, "' abc '"); + + $result = $this->Dbo->value('a bc', 'string'); + $this->assertEqual($result, "'a bc'"); + } + +/** + * testRealQueries method + * + * @access public + * @return void + */ + function testRealQueries() { + $this->loadFixtures('Apple', 'Article', 'User', 'Comment', 'Tag', 'Sample', 'ArticlesTag'); + + $Apple = ClassRegistry::init('Apple'); + $Article = ClassRegistry::init('Article'); + + $result = $this->Dbo->rawQuery('SELECT color, name FROM ' . $this->Dbo->fullTableName('apples')); + $this->assertTrue(!empty($result)); + + $result = $this->Dbo->fetchRow($result); + $expected = array($this->Dbo->fullTableName('apples', false) => array( + 'color' => 'Red 1', + 'name' => 'Red Apple 1' + )); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->fetchAll('SELECT name FROM ' . $this->Dbo->fullTableName('apples') . ' ORDER BY id'); + $expected = array( + array($this->Dbo->fullTableName('apples', false) => array('name' => 'Red Apple 1')), + array($this->Dbo->fullTableName('apples', false) => array('name' => 'Bright Red Apple')), + array($this->Dbo->fullTableName('apples', false) => array('name' => 'green blue')), + array($this->Dbo->fullTableName('apples', false) => array('name' => 'Test Name')), + array($this->Dbo->fullTableName('apples', false) => array('name' => 'Blue Green')), + array($this->Dbo->fullTableName('apples', false) => array('name' => 'My new apple')), + array($this->Dbo->fullTableName('apples', false) => array('name' => 'Some odd color')) + ); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->field($this->Dbo->fullTableName('apples', false), 'SELECT color, name FROM ' . $this->Dbo->fullTableName('apples') . ' ORDER BY id'); + $expected = array( + 'color' => 'Red 1', + 'name' => 'Red Apple 1' + ); + $this->assertEqual($result, $expected); + + $Apple->unbindModel(array(), false); + $result = $this->Dbo->read($Apple, array( + 'fields' => array($Apple->escapeField('name')), + 'conditions' => null, + 'recursive' => -1 + )); + $expected = array( + array('Apple' => array('name' => 'Red Apple 1')), + array('Apple' => array('name' => 'Bright Red Apple')), + array('Apple' => array('name' => 'green blue')), + array('Apple' => array('name' => 'Test Name')), + array('Apple' => array('name' => 'Blue Green')), + array('Apple' => array('name' => 'My new apple')), + array('Apple' => array('name' => 'Some odd color')) + ); + $this->assertEqual($result, $expected); + + $result = $this->Dbo->read($Article, array( + 'fields' => array('id', 'user_id', 'title'), + 'conditions' => null, + 'recursive' => 1 + )); + + $this->assertTrue(Set::matches('/Article[id=1]', $result)); + $this->assertTrue(Set::matches('/Comment[id=1]', $result)); + $this->assertTrue(Set::matches('/Comment[id=2]', $result)); + $this->assertFalse(Set::matches('/Comment[id=10]', $result)); + } } diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php deleted file mode 100644 index 4ab881478..000000000 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php +++ /dev/null @@ -1,328 +0,0 @@ -testing) { - $this->simulated[] = $sql; - return null; - } - return parent::_execute($sql); - } - -/** - * getLastQuery method - * - * @access public - * @return void - */ - function getLastQuery() { - return $this->simulated[count($this->simulated) - 1]; - } -} - -/** - * MysqliTestModel class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources - */ -class MysqliTestModel extends Model { - -/** - * name property - * - * @var string 'MysqlTestModel' - * @access public - */ - public $name = 'MysqliTestModel'; - -/** - * useTable property - * - * @var bool false - * @access public - */ - public $useTable = false; - -/** - * schema method - * - * @access public - * @return void - */ - function schema() { - return array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'client_id' => array('type' => 'integer', 'null' => '', 'default' => '0', 'length' => '11'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'login' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'passwd' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), - 'addr_1' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), - 'addr_2' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '25'), - 'zip_code' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'city' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'country' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'phone' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'fax' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'url' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), - 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => ''), - 'last_login'=> array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); - } -} - -/** - * DboMysqliTest class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources.dbo - */ -class DboMysqliTest extends CakeTestCase { - public $fixtures = array('core.datatype'); -/** - * The Dbo instance to be tested - * - * @var DboSource - * @access public - */ - public $Dbo = null; - -/** - * Sets up a Dbo class instance for testing - * - */ - public function setUp() { - $this->Dbo = ConnectionManager::getDataSource('test'); - if ($this->Dbo->config['driver'] !== 'mysqli') { - $this->markTestSkipped('The MySQLi extension is not available.'); - } - $this->model = new MysqliTestModel(); - } - -/** - * Sets up a Dbo class instance for testing - * - */ - public function tearDown() { - unset($this->model); - ClassRegistry::flush(); - } - -/** - * testIndexDetection method - * - * @return void - */ - public function testIndexDetection() { - $this->Dbo->cacheSources = false; - - $name = $this->Dbo->fullTableName('simple'); - $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)); - $result = $this->Dbo->index($name, false); - $this->assertEqual($expected, $result); - $this->Dbo->query('DROP TABLE ' . $name); - - $name = $this->Dbo->fullTableName('with_a_key'); - $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( - 'PRIMARY' => array('column' => 'id', 'unique' => 1), - 'pointless_bool' => array('column' => 'bool', 'unique' => 0), - ); - $result = $this->Dbo->index($name, false); - $this->assertEqual($expected, $result); - $this->Dbo->query('DROP TABLE ' . $name); - - $name = $this->Dbo->fullTableName('with_two_keys'); - $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( - 'PRIMARY' => array('column' => 'id', 'unique' => 1), - 'pointless_bool' => array('column' => 'bool', 'unique' => 0), - 'pointless_small_int' => array('column' => 'small_int', 'unique' => 0), - ); - $result = $this->Dbo->index($name, false); - $this->assertEqual($expected, $result); - $this->Dbo->query('DROP TABLE ' . $name); - - $name = $this->Dbo->fullTableName('with_compound_keys'); - $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( - 'PRIMARY' => array('column' => 'id', 'unique' => 1), - 'pointless_bool' => array('column' => 'bool', 'unique' => 0), - 'pointless_small_int' => array('column' => 'small_int', 'unique' => 0), - 'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0), - ); - $result = $this->Dbo->index($name, false); - $this->assertEqual($expected, $result); - $this->Dbo->query('DROP TABLE ' . $name); - - $name = $this->Dbo->fullTableName('with_multiple_compound_keys'); - $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( - 'PRIMARY' => array('column' => 'id', 'unique' => 1), - 'pointless_bool' => array('column' => 'bool', 'unique' => 0), - 'pointless_small_int' => array('column' => 'small_int', 'unique' => 0), - 'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0), - 'other_way' => array('column' => array('small_int', 'bool'), 'unique' => 0), - ); - $result = $this->Dbo->index($name, false); - $this->assertEqual($expected, $result); - $this->Dbo->query('DROP TABLE ' . $name); - } - -/** - * testColumn method - * - * @return void - */ - public function testColumn() { - $result = $this->Dbo->column('varchar(50)'); - $expected = 'string'; - $this->assertEqual($result, $expected); - - $result = $this->Dbo->column('text'); - $expected = 'text'; - $this->assertEqual($result, $expected); - - $result = $this->Dbo->column('int(11)'); - $expected = 'integer'; - $this->assertEqual($result, $expected); - - $result = $this->Dbo->column('int(11) unsigned'); - $expected = 'integer'; - $this->assertEqual($result, $expected); - - $result = $this->Dbo->column('tinyint(1)'); - $expected = 'boolean'; - $this->assertEqual($result, $expected); - - $result = $this->Dbo->column('boolean'); - $expected = 'boolean'; - $this->assertEqual($result, $expected); - - $result = $this->Dbo->column('float'); - $expected = 'float'; - $this->assertEqual($result, $expected); - - $result = $this->Dbo->column('float unsigned'); - $expected = 'float'; - $this->assertEqual($result, $expected); - - $result = $this->Dbo->column('double unsigned'); - $expected = 'float'; - $this->assertEqual($result, $expected); - - $result = $this->Dbo->column('decimal(14,7) unsigned'); - $expected = 'float'; - $this->assertEqual($result, $expected); - } - -/** - * test transaction commands. - * - * @return void - */ - public function testTransactions() { - $this->Dbo->testing = false; - $result = $this->Dbo->begin($this->model); - $this->assertTrue($result); - - $log = $this->Dbo->getLog(); - $beginSqlCalls = Set::extract('/.[query=START TRANSACTION]', $log['log']); - $this->assertEqual(1, count($beginSqlCalls)); - - $result = $this->Dbo->commit($this->model); - $this->assertTrue($result); - } -/** - * test that float values are correctly identified - * - * @return void - */ - function testFloatParsing() { - $model = new Model(array('ds' => 'test', 'table' => 'datatypes', 'name' => 'Datatype')); - $result = $this->Dbo->describe($model); - $this->assertEqual((string)$result['float_field']['length'], '5,2'); - } - -/** - * test that tableParameters like collation, charset and engine are functioning. - * - * @access public - * @return void - */ - function testReadTableParameters() { - $table = 'tinyint' . uniqid(); - $this->Dbo->cacheSources = $this->Dbo->testing = false; - $this->Dbo->query('CREATE TABLE ' . $this->Dbo->fullTableName($table) . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;'); - $result = $this->Dbo->readTableParameters($table); - $expected = array( - 'charset' => 'utf8', - 'collate' => 'utf8_unicode_ci', - 'engine' => 'InnoDB'); - $this->assertEqual($result, $expected); - - $this->Dbo->query('DROP TABLE ' . $this->Dbo->fullTableName($table)); - $this->Dbo->query('CREATE TABLE ' . $this->Dbo->fullTableName($table) . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=MyISAM DEFAULT CHARSET=cp1250 COLLATE=cp1250_general_ci;'); - $result = $this->Dbo->readTableParameters($table); - $expected = array( - 'charset' => 'cp1250', - 'collate' => 'cp1250_general_ci', - 'engine' => 'MyISAM'); - $this->assertEqual($result, $expected); - $this->Dbo->query('DROP TABLE ' . $this->Dbo->fullTableName($table)); - } -} diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_oracle.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_oracle.test.php index 3efa451bd..592b1eac0 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_oracle.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_oracle.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 1.2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,8 +23,7 @@ require_once LIBS . 'model' . DS . 'datasources' . DS . 'dbo' . DS . 'dbo_oracle /** * DboOracleTest class * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources.dbo + * @package cake.tests.cases.libs.model.datasources.dbo */ class DboOracleTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php index bf3ebd77c..35b465f63 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 1.2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,8 +23,7 @@ require_once dirname(dirname(dirname(__FILE__))) . DS . 'models.php'; /** * DboPostgresTestDb class * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources + * @package cake.tests.cases.libs.model.datasources */ class DboPostgresTestDb extends DboPostgres { @@ -44,7 +42,7 @@ class DboPostgresTestDb extends DboPostgres { * @access protected * @return void */ - function _execute($sql) { + function _execute($sql, $params = array()) { $this->simulated[] = $sql; return null; } @@ -63,8 +61,7 @@ class DboPostgresTestDb extends DboPostgres { /** * PostgresTestModel class * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources + * @package cake.tests.cases.libs.model.datasources */ class PostgresTestModel extends Model { @@ -130,7 +127,7 @@ class PostgresTestModel extends Model { * @access public * @return void */ - function schema() { + function schema($field = false) { return array( 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), 'client_id' => array('type' => 'integer', 'null' => '', 'default' => '0', 'length' => '11'), @@ -157,8 +154,7 @@ class PostgresTestModel extends Model { /** * PostgresClientTestModel class * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources + * @package cake.tests.cases.libs.model.datasources */ class PostgresClientTestModel extends Model { @@ -184,7 +180,7 @@ class PostgresClientTestModel extends Model { * @access public * @return void */ - function schema() { + function schema($field = false) { return array( 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8', 'key' => 'primary'), 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), @@ -198,8 +194,7 @@ class PostgresClientTestModel extends Model { /** * DboPostgresTest class * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources.dbo + * @package cake.tests.cases.libs.model.datasources.dbo */ class DboPostgresTest extends CakeTestCase { @@ -244,6 +239,7 @@ class DboPostgresTest extends CakeTestCase { public function setUp() { Configure::write('Cache.disable', true); $this->Dbo = ConnectionManager::getDataSource('test'); + $this->skipIf(!($this->Dbo instanceof DboPostgres)); $this->Dbo2 = new DboPostgresTestDb($this->Dbo->config, false); $this->skipUnless($this->Dbo->config['driver'] == 'postgres', 'PostgreSQL connection not available'); $this->model = new PostgresTestModel(); @@ -330,30 +326,30 @@ class DboPostgresTest extends CakeTestCase { * @return void */ function testValueQuoting() { - $this->assertIdentical($this->db2->value(1.2, 'float'), "'1.200000'"); - $this->assertEqual($this->db2->value('1,2', 'float'), "'1,2'"); + $this->assertEqual($this->Dbo->value(1.2, 'float'), "1.200000"); + $this->assertEqual($this->Dbo->value('1,2', 'float'), "'1,2'"); - $this->assertEqual($this->Dbo2->value('0', 'integer'), "'0'"); - $this->assertEqual($this->Dbo2->value('', 'integer'), 'NULL'); - $this->assertEqual($this->Dbo2->value('', 'float'), 'NULL'); - $this->assertEqual($this->Dbo2->value('', 'integer', false), "DEFAULT"); - $this->assertEqual($this->Dbo2->value('', 'float', false), "DEFAULT"); - $this->assertEqual($this->Dbo2->value('0.0', 'float'), "'0.0'"); + $this->assertEqual($this->Dbo->value('0', 'integer'), "0"); + $this->assertEqual($this->Dbo->value('', 'integer'), 'NULL'); + $this->assertEqual($this->Dbo->value('', 'float'), 'NULL'); + $this->assertEqual($this->Dbo->value('', 'integer', false), "NULL"); + $this->assertEqual($this->Dbo->value('', 'float', false), "NULL"); + $this->assertEqual($this->Dbo->value('0.0', 'float'), "'0.0'"); - $this->assertEqual($this->Dbo2->value('t', 'boolean'), "TRUE"); - $this->assertEqual($this->Dbo2->value('f', 'boolean'), "FALSE"); - $this->assertEqual($this->Dbo2->value(true), "TRUE"); - $this->assertEqual($this->Dbo2->value(false), "FALSE"); - $this->assertEqual($this->Dbo2->value('t'), "'t'"); - $this->assertEqual($this->Dbo2->value('f'), "'f'"); - $this->assertEqual($this->Dbo2->value('true', 'boolean'), 'TRUE'); - $this->assertEqual($this->Dbo2->value('false', 'boolean'), 'FALSE'); - $this->assertEqual($this->Dbo2->value('', 'boolean'), 'FALSE'); - $this->assertEqual($this->Dbo2->value(0, 'boolean'), 'FALSE'); - $this->assertEqual($this->Dbo2->value(1, 'boolean'), 'TRUE'); - $this->assertEqual($this->Dbo2->value('1', 'boolean'), 'TRUE'); - $this->assertEqual($this->Dbo2->value(null, 'boolean'), "NULL"); - $this->assertEqual($this->Dbo2->value(array()), "NULL"); + $this->assertEqual($this->Dbo->value('t', 'boolean'), "'TRUE'"); + $this->assertEqual($this->Dbo->value('f', 'boolean'), "'FALSE'"); + $this->assertEqual($this->Dbo->value(true), "'TRUE'"); + $this->assertEqual($this->Dbo->value(false), "'FALSE'"); + $this->assertEqual($this->Dbo->value('t'), "'t'"); + $this->assertEqual($this->Dbo->value('f'), "'f'"); + $this->assertEqual($this->Dbo->value('true', 'boolean'), "'TRUE'"); + $this->assertEqual($this->Dbo->value('false', 'boolean'), "'FALSE'"); + $this->assertEqual($this->Dbo->value('', 'boolean'), "'FALSE'"); + $this->assertEqual($this->Dbo->value(0, 'boolean'), "'FALSE'"); + $this->assertEqual($this->Dbo->value(1, 'boolean'), "'TRUE'"); + $this->assertEqual($this->Dbo->value('1', 'boolean'), "'TRUE'"); + $this->assertEqual($this->Dbo->value(null, 'boolean'), "NULL"); + $this->assertEqual($this->Dbo->value(array()), "NULL"); } /** @@ -366,10 +362,10 @@ class DboPostgresTest extends CakeTestCase { setlocale(LC_ALL, 'de_DE'); $result = $this->db->value(3.141593, 'float'); - $this->assertEqual((string)$result, "'3.141593'"); + $this->assertEqual((string)$result, "3.141593"); $result = $this->db->value(3.14); - $this->assertEqual((string)$result, "'3.140000'"); + $this->assertEqual((string)$result, "3.140000"); setlocale(LC_ALL, $restore); } @@ -380,17 +376,17 @@ class DboPostgresTest extends CakeTestCase { * @return void */ function testDateAndTimeAsNull() { - $this->assertEqual($this->Dbo2->value(null, 'date'), 'NULL'); - $this->assertEqual($this->Dbo2->value('', 'date'), 'NULL'); + $this->assertEqual($this->Dbo->value(null, 'date'), 'NULL'); + $this->assertEqual($this->Dbo->value('', 'date'), 'NULL'); - $this->assertEqual($this->Dbo2->value('', 'datetime'), 'NULL'); - $this->assertEqual($this->Dbo2->value(null, 'datetime'), 'NULL'); + $this->assertEqual($this->Dbo->value('', 'datetime'), 'NULL'); + $this->assertEqual($this->Dbo->value(null, 'datetime'), 'NULL'); - $this->assertEqual($this->Dbo2->value('', 'timestamp'), 'NULL'); - $this->assertEqual($this->Dbo2->value(null, 'timestamp'), 'NULL'); + $this->assertEqual($this->Dbo->value('', 'timestamp'), 'NULL'); + $this->assertEqual($this->Dbo->value(null, 'timestamp'), 'NULL'); - $this->assertEqual($this->Dbo2->value('', 'time'), 'NULL'); - $this->assertEqual($this->Dbo2->value(null, 'time'), 'NULL'); + $this->assertEqual($this->Dbo->value('', 'time'), 'NULL'); + $this->assertEqual($this->Dbo->value(null, 'time'), 'NULL'); } /** @@ -400,19 +396,19 @@ class DboPostgresTest extends CakeTestCase { * @return void */ function testBooleanNormalization() { - $this->assertTrue($this->Dbo2->boolean('t')); - $this->assertTrue($this->Dbo2->boolean('true')); - $this->assertTrue($this->Dbo2->boolean('TRUE')); - $this->assertTrue($this->Dbo2->boolean(true)); - $this->assertTrue($this->Dbo2->boolean(1)); - $this->assertTrue($this->Dbo2->boolean(" ")); + $this->assertEquals(1, $this->Dbo2->boolean('t', false)); + $this->assertEquals(1, $this->Dbo2->boolean('true', false)); + $this->assertEquals(1, $this->Dbo2->boolean('TRUE', false)); + $this->assertEquals(1, $this->Dbo2->boolean(true, false)); + $this->assertEquals(1, $this->Dbo2->boolean(1, false)); + $this->assertEquals(1, $this->Dbo2->boolean(" ", false)); - $this->assertFalse($this->Dbo2->boolean('f')); - $this->assertFalse($this->Dbo2->boolean('false')); - $this->assertFalse($this->Dbo2->boolean('FALSE')); - $this->assertFalse($this->Dbo2->boolean(false)); - $this->assertFalse($this->Dbo2->boolean(0)); - $this->assertFalse($this->Dbo2->boolean('')); + $this->assertEquals(0, $this->Dbo2->boolean('f', false)); + $this->assertEquals(0, $this->Dbo2->boolean('false', false)); + $this->assertEquals(0, $this->Dbo2->boolean('FALSE', false)); + $this->assertEquals(0, $this->Dbo2->boolean(false, false)); + $this->assertEquals(0, $this->Dbo2->boolean(0, false)); + $this->assertEquals(0, $this->Dbo2->boolean('', false)); } /** @@ -427,7 +423,7 @@ class DboPostgresTest extends CakeTestCase { $db2 = clone $db1; $db2->connect(); - $this->assertNotEqual($db1->connection, $db2->connection); + $this->assertNotSame($db1->getConnection(), $db2->getConnection()); $table = $db1->fullTableName('users', false); $password = '5f4dcc3b5aa765d61d8327deb882cf99'; @@ -556,12 +552,12 @@ class DboPostgresTest extends CakeTestCase { $db1 = ConnectionManager::getDataSource('test'); $db1->cacheSources = false; $db1->reconnect(array('persistent' => false)); - $db1->query('CREATE TABLE ' . $db1->fullTableName('datatypes') . ' ( + $db1->rawQuery('CREATE TABLE ' . $db1->fullTableName('datatypes') . ' ( id serial NOT NULL, "varchar" character varying(40) NOT NULL, "full_length" character varying NOT NULL, "timestamp" timestamp without time zone, - date date, + "date" date, CONSTRAINT test_data_types_pkey PRIMARY KEY (id) )'); $model = new Model(array('name' => 'Datatype', 'ds' => 'test')); @@ -570,21 +566,21 @@ class DboPostgresTest extends CakeTestCase { 'connection' => 'test', 'models' => array('Datatype') )); - $schema->tables = array('datatypes' => $result['tables']['datatypes']); + + $schema->tables = array('datatypes' => $result['tables']['missing']['datatypes']); $result = $db1->createSchema($schema, 'datatypes'); + $db1->rawQuery('DROP TABLE ' . $db1->fullTableName('datatypes')); $this->assertNoPattern('/timestamp DEFAULT/', $result); $this->assertPattern('/\"full_length\"\s*text\s.*,/', $result); $this->assertPattern('/timestamp\s*,/', $result); - $db1->query('DROP TABLE ' . $db1->fullTableName('datatypes')); - $db1->query($result); $result2 = $schema->read(array( 'connection' => 'test', 'models' => array('Datatype') )); - $schema->tables = array('datatypes' => $result2['tables']['datatypes']); + $schema->tables = array('datatypes' => $result2['tables']['missing']['datatypes']); $result2 = $db1->createSchema($schema, 'datatypes'); $this->assertEqual($result, $result2); @@ -602,25 +598,25 @@ class DboPostgresTest extends CakeTestCase { $this->Dbo->query('CREATE INDEX pointless_bool ON ' . $name . '("bool")'); $this->Dbo->query('CREATE UNIQUE INDEX char_index ON ' . $name . '("small_char")'); $expected = array( - 'PRIMARY' => array('column' => 'id', 'unique' => true), - 'pointless_bool' => array('column' => 'bool', 'unique' => false), - 'char_index' => array('column' => 'small_char', 'unique' => true), + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + 'pointless_bool' => array('column' => 'bool', 'unique' => 0), + 'char_index' => array('column' => 'small_char', 'unique' => 1), ); $result = $this->Dbo->index($name); + $this->Dbo->query('DROP TABLE ' . $name); $this->assertEqual($expected, $result); - $this->Dbo->query('DROP TABLE ' . $name); $name = $this->Dbo->fullTableName('index_test_2', false); $this->Dbo->query('CREATE TABLE ' . $name . ' ("id" serial NOT NULL PRIMARY KEY, "bool" integer, "small_char" varchar(50), "description" varchar(40) )'); $this->Dbo->query('CREATE UNIQUE INDEX multi_col ON ' . $name . '("small_char", "bool")'); $expected = array( - 'PRIMARY' => array('column' => 'id', 'unique' => true), - 'multi_col' => array('column' => array('small_char', 'bool'), 'unique' => true), + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + 'multi_col' => array('column' => array('small_char', 'bool'), 'unique' => 1), ); $result = $this->Dbo->index($name); - $this->assertEqual($expected, $result); $this->Dbo->query('DROP TABLE ' . $name); + $this->assertEqual($expected, $result); } /** @@ -691,21 +687,21 @@ class DboPostgresTest extends CakeTestCase { 'group2' => array('type' => 'integer', 'null' => true) ) )); - $this->Dbo->query($this->Dbo->createSchema($schema1)); + $this->Dbo->rawQuery($this->Dbo->createSchema($schema1)); $schema2 = new CakeSchema(array( 'name' => 'AlterTest2', 'connection' => 'test', 'altertest' => array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => 0), - 'name' => array('type' => 'string', 'null' => false, 'length' => 50), - 'group1' => array('type' => 'integer', 'null' => true), - 'group2' => array('type' => 'integer', 'null' => true), + 'id' => array('type' => 'integer', 'null' => 0, 'default' => 0), + 'name' => array('type' => 'string', 'null' => 0, 'length' => 50), + 'group1' => array('type' => 'integer', 'null' => 1), + 'group2' => array('type' => 'integer', 'null' => 1), 'indexes' => array( - 'name_idx' => array('column' => 'name', 'unique' => false), - 'group_idx' => array('column' => 'group1', 'unique' => false), - 'compound_idx' => array('column' => array('group1', 'group2'), 'unique' => false), - 'PRIMARY' => array('column' => 'id', 'unique' => true) + 'name_idx' => array('column' => 'name', 'unique' => 0), + 'group_idx' => array('column' => 'group1', 'unique' => 0), + 'compound_idx' => array('column' => array('group1', 'group2'), 'unique' => 0), + 'PRIMARY' => array('column' => 'id', 'unique' => 1) ) ) )); @@ -719,15 +715,15 @@ class DboPostgresTest extends CakeTestCase { 'name' => 'AlterTest3', 'connection' => 'test', 'altertest' => array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => 0), - 'name' => array('type' => 'string', 'null' => false, 'length' => 50), - 'group1' => array('type' => 'integer', 'null' => true), - 'group2' => array('type' => 'integer', 'null' => true), + 'id' => array('type' => 'integer', 'null' => 0, 'default' => 0), + 'name' => array('type' => 'string', 'null' => 0, 'length' => 50), + 'group1' => array('type' => 'integer', 'null' => 1), + 'group2' => array('type' => 'integer', 'null' => 1), 'indexes' => array( - 'name_idx' => array('column' => 'name', 'unique' => true), - 'group_idx' => array('column' => 'group2', 'unique' => false), - 'compound_idx' => array('column' => array('group2', 'group1'), 'unique' => false), - 'another_idx' => array('column' => array('group1', 'name'), 'unique' => false)) + 'name_idx' => array('column' => 'name', 'unique' => 1), + 'group_idx' => array('column' => 'group2', 'unique' => 0), + 'compound_idx' => array('column' => array('group2', 'group1'), 'unique' => 0), + 'another_idx' => array('column' => array('group1', 'name'), 'unique' => 0)) ))); $this->Dbo->query($this->Dbo->alterSchema($schema3->compare($schema2))); diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_sqlite.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_sqlite.test.php index 4cffa8e4a..a1fc1cd4a 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_sqlite.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_sqlite.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs + * @package cake.libs * @since CakePHP(tm) v 1.2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Core', array('Model', 'DataSource', 'DboSource', 'DboSqlite')); /** * DboSqliteTestDb class * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources + * @package cake.tests.cases.libs.model.datasources */ class DboSqliteTestDb extends DboSqlite { @@ -42,7 +40,7 @@ class DboSqliteTestDb extends DboSqlite { * @access protected * @return void */ - function _execute($sql) { + function _execute($sql, $params = array()) { $this->simulated[] = $sql; return null; } @@ -61,8 +59,7 @@ class DboSqliteTestDb extends DboSqlite { /** * DboSqliteTest class * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources.dbo + * @package cake.tests.cases.libs.model.datasources.dbo */ class DboSqliteTest extends CakeTestCase { @@ -90,14 +87,6 @@ class DboSqliteTest extends CakeTestCase { */ public $Dbo = null; -/** - * Simulated DB connection used in testing - * - * @var DboSource - * @access public - */ - public $Dbo2 = null; - /** * Sets up a Dbo class instance for testing * @@ -108,7 +97,6 @@ class DboSqliteTest extends CakeTestCase { if ($this->Dbo->config['driver'] !== 'sqlite') { $this->markTestSkipped('The Sqlite extension is not available.'); } - $this->Dbo2 = new DboSqliteTestDb($this->Dbo->config, false); } /** @@ -117,7 +105,6 @@ class DboSqliteTest extends CakeTestCase { */ public function tearDown() { Configure::write('Cache.disable', false); - unset($this->Dbo2); } /** @@ -127,10 +114,11 @@ class DboSqliteTest extends CakeTestCase { public function testTableListCacheDisabling() { $this->assertFalse(in_array('foo_test', $this->Dbo->listSources())); - $this->Dbo->query('CREATE TABLE foo_test (test VARCHAR(255));'); + $this->Dbo->query('CREATE TABLE foo_test (test VARCHAR(255))'); $this->assertTrue(in_array('foo_test', $this->Dbo->listSources())); - $this->Dbo->query('DROP TABLE foo_test;'); + $this->Dbo->cacheSources = false; + $this->Dbo->query('DROP TABLE foo_test'); $this->assertFalse(in_array('foo_test', $this->Dbo->listSources())); } @@ -207,7 +195,7 @@ class DboSqliteTest extends CakeTestCase { 'null' => false, ); $result = $this->Dbo->buildColumn($data); - $expected = '"int_field" integer(11) NOT NULL'; + $expected = '"int_field" integer NOT NULL'; $this->assertEqual($result, $expected); $data = array( @@ -251,7 +239,7 @@ class DboSqliteTest extends CakeTestCase { 'null' => false, ); $result = $this->Dbo->buildColumn($data); - $expected = '"testName" integer(10) DEFAULT \'10\' NOT NULL'; + $expected = '"testName" integer(10) DEFAULT 10 NOT NULL'; $this->assertEqual($result, $expected); $data = array( @@ -263,7 +251,7 @@ class DboSqliteTest extends CakeTestCase { 'collate' => 'BADVALUE' ); $result = $this->Dbo->buildColumn($data); - $expected = '"testName" integer(10) DEFAULT \'10\' NOT NULL'; + $expected = '"testName" integer(10) DEFAULT 10 NOT NULL'; $this->assertEqual($result, $expected); } diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index fc09e5d55..66b4a9cc1 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -12,8 +12,7 @@ * * @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.model.datasources + * @package cake.tests.cases.libs.model.datasources * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,1235 +20,10 @@ App::import('Model', array('Model', 'DataSource', 'DboSource', 'DboMysql', 'App')); require_once dirname(dirname(__FILE__)) . DS . 'models.php'; -/** - * TestModel class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources - */ -class TestModel extends CakeTestModel { - -/** - * name property - * - * @var string 'TestModel' - * @access public - */ - public $name = 'TestModel'; - -/** - * useTable property - * - * @var bool false - * @access public - */ - public $useTable = false; - -/** - * schema property - * - * @var array - * @access protected - */ - protected $_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'client_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '11'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'login' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'passwd' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), - 'addr_1' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), - 'addr_2' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '25'), - 'zip_code' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'city' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'country' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'phone' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'fax' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'url' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), - 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => '155'), - 'last_login' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); - -/** - * find method - * - * @param mixed $conditions - * @param mixed $fields - * @param mixed $order - * @param mixed $recursive - * @access public - * @return void - */ - function find($conditions = null, $fields = null, $order = null, $recursive = null) { - return array($conditions, $fields); - } - -/** - * findAll method - * - * @param mixed $conditions - * @param mixed $fields - * @param mixed $order - * @param mixed $recursive - * @access public - * @return void - */ - function findAll($conditions = null, $fields = null, $order = null, $recursive = null) { - return $conditions; - } -} - -/** - * TestModel2 class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources - */ -class TestModel2 extends CakeTestModel { - -/** - * name property - * - * @var string 'TestModel2' - * @access public - */ - public $name = 'TestModel2'; - -/** - * useTable property - * - * @var bool false - * @access public - */ - public $useTable = false; -} - -/** - * TestModel4 class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources - */ -class TestModel3 extends CakeTestModel { - -/** - * name property - * - * @var string 'TestModel3' - * @access public - */ - public $name = 'TestModel3'; - -/** - * useTable property - * - * @var bool false - * @access public - */ - public $useTable = false; -} - -/** - * TestModel4 class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources - */ -class TestModel4 extends CakeTestModel { - -/** - * name property - * - * @var string 'TestModel4' - * @access public - */ - public $name = 'TestModel4'; - -/** - * table property - * - * @var string 'test_model4' - * @access public - */ - public $table = 'test_model4'; - -/** - * useTable property - * - * @var bool false - * @access public - */ - public $useTable = false; - -/** - * belongsTo property - * - * @var array - * @access public - */ - public $belongsTo = array( - 'TestModel4Parent' => array( - 'className' => 'TestModel4', - 'foreignKey' => 'parent_id' - ) - ); - -/** - * hasOne property - * - * @var array - * @access public - */ - public $hasOne = array( - 'TestModel5' => array( - 'className' => 'TestModel5', - 'foreignKey' => 'test_model4_id' - ) - ); - -/** - * hasAndBelongsToMany property - * - * @var array - * @access public - */ - public $hasAndBelongsToMany = array('TestModel7' => array( - 'className' => 'TestModel7', - 'joinTable' => 'test_model4_test_model7', - 'foreignKey' => 'test_model4_id', - 'associationForeignKey' => 'test_model7_id', - 'with' => 'TestModel4TestModel7' - )); - -/** - * schema method - * - * @access public - * @return void - */ - function schema() { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); - } - return $this->_schema; - } -} - -/** - * TestModel4TestModel7 class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources - */ -class TestModel4TestModel7 extends CakeTestModel { - -/** - * name property - * - * @var string 'TestModel4TestModel7' - * @access public - */ - public $name = 'TestModel4TestModel7'; - -/** - * table property - * - * @var string 'test_model4_test_model7' - * @access public - */ - public $table = 'test_model4_test_model7'; - -/** - * useTable property - * - * @var bool false - * @access public - */ - public $useTable = false; - -/** - * schema method - * - * @access public - * @return void - */ - function schema() { - if (!isset($this->_schema)) { - $this->_schema = array( - 'test_model4_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'test_model7_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8') - ); - } - return $this->_schema; - } -} - -/** - * TestModel5 class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources - */ -class TestModel5 extends CakeTestModel { - -/** - * name property - * - * @var string 'TestModel5' - * @access public - */ - public $name = 'TestModel5'; - -/** - * table property - * - * @var string 'test_model5' - * @access public - */ - public $table = 'test_model5'; - -/** - * useTable property - * - * @var bool false - * @access public - */ - public $useTable = false; - -/** - * belongsTo property - * - * @var array - * @access public - */ - public $belongsTo = array('TestModel4' => array( - 'className' => 'TestModel4', - 'foreignKey' => 'test_model4_id' - )); - -/** - * hasMany property - * - * @var array - * @access public - */ - public $hasMany = array('TestModel6' => array( - 'className' => 'TestModel6', - 'foreignKey' => 'test_model5_id' - )); - -/** - * schema method - * - * @access public - * @return void - */ - function schema() { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'test_model4_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); - } - return $this->_schema; - } -} - -/** - * TestModel6 class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources - */ -class TestModel6 extends CakeTestModel { - -/** - * name property - * - * @var string 'TestModel6' - * @access public - */ - public $name = 'TestModel6'; - -/** - * table property - * - * @var string 'test_model6' - * @access public - */ - public $table = 'test_model6'; - -/** - * useTable property - * - * @var bool false - * @access public - */ - public $useTable = false; - -/** - * belongsTo property - * - * @var array - * @access public - */ - public $belongsTo = array('TestModel5' => array( - 'className' => 'TestModel5', - 'foreignKey' => 'test_model5_id' - )); - -/** - * schema method - * - * @access public - * @return void - */ - function schema() { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'test_model5_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); - } - return $this->_schema; - } -} - -/** - * TestModel7 class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources - */ -class TestModel7 extends CakeTestModel { - -/** - * name property - * - * @var string 'TestModel7' - * @access public - */ - public $name = 'TestModel7'; - -/** - * table property - * - * @var string 'test_model7' - * @access public - */ - public $table = 'test_model7'; - -/** - * useTable property - * - * @var bool false - * @access public - */ - public $useTable = false; - -/** - * schema method - * - * @access public - * @return void - */ - function schema() { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); - } - return $this->_schema; - } -} - -/** - * TestModel8 class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources - */ -class TestModel8 extends CakeTestModel { - -/** - * name property - * - * @var string 'TestModel8' - * @access public - */ - public $name = 'TestModel8'; - -/** - * table property - * - * @var string 'test_model8' - * @access public - */ - public $table = 'test_model8'; - -/** - * useTable property - * - * @var bool false - * @access public - */ - public $useTable = false; - -/** - * hasOne property - * - * @var array - * @access public - */ - public $hasOne = array( - 'TestModel9' => array( - 'className' => 'TestModel9', - 'foreignKey' => 'test_model8_id', - 'conditions' => 'TestModel9.name != \'mariano\'' - ) - ); - -/** - * schema method - * - * @access public - * @return void - */ - function schema() { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'test_model9_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); - } - return $this->_schema; - } -} - -/** - * TestModel9 class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources - */ -class TestModel9 extends CakeTestModel { - -/** - * name property - * - * @var string 'TestModel9' - * @access public - */ - public $name = 'TestModel9'; - -/** - * table property - * - * @var string 'test_model9' - * @access public - */ - public $table = 'test_model9'; - -/** - * useTable property - * - * @var bool false - * @access public - */ - public $useTable = false; - -/** - * belongsTo property - * - * @var array - * @access public - */ - public $belongsTo = array('TestModel8' => array( - 'className' => 'TestModel8', - 'foreignKey' => 'test_model8_id', - 'conditions' => 'TestModel8.name != \'larry\'' - )); - -/** - * schema method - * - * @access public - * @return void - */ - function schema() { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'test_model8_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '11'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); - } - return $this->_schema; - } -} - -/** - * Level class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources - */ -class Level extends CakeTestModel { - -/** - * name property - * - * @var string 'Level' - * @access public - */ - public $name = 'Level'; - -/** - * table property - * - * @var string 'level' - * @access public - */ - public $table = 'level'; - -/** - * useTable property - * - * @var bool false - * @access public - */ - public $useTable = false; - -/** - * hasMany property - * - * @var array - * @access public - */ - public $hasMany = array( - 'Group'=> array( - 'className' => 'Group' - ), - 'User2' => array( - 'className' => 'User2' - ) - ); - -/** - * schema method - * - * @access public - * @return void - */ - function schema() { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), - ); - } - return $this->_schema; - } -} - -/** - * Group class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources - */ -class Group extends CakeTestModel { - -/** - * name property - * - * @var string 'Group' - * @access public - */ - public $name = 'Group'; - -/** - * table property - * - * @var string 'group' - * @access public - */ - public $table = 'group'; - -/** - * useTable property - * - * @var bool false - * @access public - */ - public $useTable = false; - -/** - * belongsTo property - * - * @var array - * @access public - */ - public $belongsTo = array('Level'); - -/** - * hasMany property - * - * @var array - * @access public - */ - public $hasMany = array('Category2', 'User2'); - -/** - * schema method - * - * @access public - * @return void - */ - function schema() { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'level_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), - ); - } - return $this->_schema; - } - -} - -/** - * User2 class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources - */ -class User2 extends CakeTestModel { - -/** - * name property - * - * @var string 'User2' - * @access public - */ - public $name = 'User2'; - -/** - * table property - * - * @var string 'user' - * @access public - */ - public $table = 'user'; - -/** - * useTable property - * - * @var bool false - * @access public - */ - public $useTable = false; - -/** - * belongsTo property - * - * @var array - * @access public - */ - public $belongsTo = array( - 'Group' => array( - 'className' => 'Group' - ), - 'Level' => array( - 'className' => 'Level' - ) - ); - -/** - * hasMany property - * - * @var array - * @access public - */ - public $hasMany = array( - 'Article2' => array( - 'className' => 'Article2' - ), - ); - -/** - * schema method - * - * @access public - * @return void - */ - function schema() { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'group_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'level_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), - ); - } - return $this->_schema; - } -} - -/** - * Category2 class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources - */ -class Category2 extends CakeTestModel { - -/** - * name property - * - * @var string 'Category2' - * @access public - */ - public $name = 'Category2'; - -/** - * table property - * - * @var string 'category' - * @access public - */ - public $table = 'category'; - -/** - * useTable property - * - * @var bool false - * @access public - */ - public $useTable = false; - -/** - * belongsTo property - * - * @var array - * @access public - */ - public $belongsTo = array( - 'Group' => array( - 'className' => 'Group', - 'foreignKey' => 'group_id' - ), - 'ParentCat' => array( - 'className' => 'Category2', - 'foreignKey' => 'parent_id' - ) - ); - -/** - * hasMany property - * - * @var array - * @access public - */ - public $hasMany = array( - 'ChildCat' => array( - 'className' => 'Category2', - 'foreignKey' => 'parent_id' - ), - 'Article2' => array( - 'className' => 'Article2', - 'order'=>'Article2.published_date DESC', - 'foreignKey' => 'category_id', - 'limit'=>'3') - ); - -/** - * schema method - * - * @access public - * @return void - */ - function schema() { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), - 'group_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), - 'parent_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), - 'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), - 'icon' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), - 'description' => array('type' => 'text', 'null' => false, 'default' => '', 'length' => null), - - ); - } - return $this->_schema; - } -} - -/** - * Article2 class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources - */ -class Article2 extends CakeTestModel { - -/** - * name property - * - * @var string 'Article2' - * @access public - */ - public $name = 'Article2'; - -/** - * table property - * - * @var string 'article' - * @access public - */ - public $table = 'article'; - -/** - * useTable property - * - * @var bool false - * @access public - */ - public $useTable = false; - -/** - * belongsTo property - * - * @var array - * @access public - */ - public $belongsTo = array( - 'Category2' => array('className' => 'Category2'), - 'User2' => array('className' => 'User2') - ); - -/** - * schema method - * - * @access public - * @return void - */ - function schema() { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), - 'category_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'user_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'rate_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'rate_sum' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'viewed' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'version' => array('type' => 'string', 'null' => true, 'default' => '', 'length' => '45'), - 'title' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '200'), - 'intro' => array('text' => 'string', 'null' => true, 'default' => '', 'length' => null), - 'comments' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '4'), - 'body' => array('text' => 'string', 'null' => true, 'default' => '', 'length' => null), - 'isdraft' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), - 'allow_comments' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'length' => '1'), - 'moderate_comments' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'length' => '1'), - 'published' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), - 'multipage' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), - 'published_date' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null), - 'created' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null), - 'modified' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null) - ); - } - return $this->_schema; - } -} - -/** - * CategoryFeatured2 class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources - */ -class CategoryFeatured2 extends CakeTestModel { - -/** - * name property - * - * @var string 'CategoryFeatured2' - * @access public - */ - public $name = 'CategoryFeatured2'; - -/** - * table property - * - * @var string 'category_featured' - * @access public - */ - public $table = 'category_featured'; - -/** - * useTable property - * - * @var bool false - * @access public - */ - public $useTable = false; - -/** - * schema method - * - * @access public - * @return void - */ - function schema() { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), - 'parent_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), - 'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), - 'icon' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), - 'description' => array('text' => 'string', 'null' => false, 'default' => '', 'length' => null) - ); - } - return $this->_schema; - } -} - -/** - * Featured2 class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources - */ -class Featured2 extends CakeTestModel { - -/** - * name property - * - * @var string 'Featured2' - * @access public - */ - public $name = 'Featured2'; - -/** - * table property - * - * @var string 'featured2' - * @access public - */ - public $table = 'featured2'; - -/** - * useTable property - * - * @var bool false - * @access public - */ - public $useTable = false; - -/** - * belongsTo property - * - * @var array - * @access public - */ - public $belongsTo = array( - 'CategoryFeatured2' => array( - 'className' => 'CategoryFeatured2' - ) - ); - -/** - * schema method - * - * @access public - * @return void - */ - function schema() { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'article_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'category_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20') - ); - } - return $this->_schema; - } -} - -/** - * Comment2 class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources - */ -class Comment2 extends CakeTestModel { - -/** - * name property - * - * @var string 'Comment2' - * @access public - */ - public $name = 'Comment2'; - -/** - * table property - * - * @var string 'comment' - * @access public - */ - public $table = 'comment'; - -/** - * belongsTo property - * - * @var array - * @access public - */ - public $belongsTo = array('ArticleFeatured2', 'User2'); - -/** - * useTable property - * - * @var bool false - * @access public - */ - public $useTable = false; - -/** - * schema method - * - * @access public - * @return void - */ - function schema() { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'article_featured_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'user_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20') - ); - } - return $this->_schema; - } -} - -/** - * ArticleFeatured2 class - * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources - */ -class ArticleFeatured2 extends CakeTestModel { - -/** - * name property - * - * @var string 'ArticleFeatured2' - * @access public - */ - public $name = 'ArticleFeatured2'; - -/** - * table property - * - * @var string 'article_featured' - * @access public - */ - public $table = 'article_featured'; - -/** - * useTable property - * - * @var bool false - * @access public - */ - public $useTable = false; - -/** - * belongsTo property - * - * @var array - * @access public - */ - public $belongsTo = array( - 'CategoryFeatured2' => array('className' => 'CategoryFeatured2'), - 'User2' => array('className' => 'User2') - ); - -/** - * hasOne property - * - * @var array - * @access public - */ - public $hasOne = array( - 'Featured2' => array('className' => 'Featured2') - ); - -/** - * hasMany property - * - * @var array - * @access public - */ - public $hasMany = array( - 'Comment2' => array('className'=>'Comment2', 'dependent' => true) - ); - -/** - * schema method - * - * @access public - * @return void - */ - function schema() { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'category_featured_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'user_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'title' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), - 'body' => array('text' => 'string', 'null' => true, 'default' => '', 'length' => null), - 'published' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), - 'published_date' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null), - 'created' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null), - 'modified' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null) - ); - } - return $this->_schema; - } -} - /** * DboSourceTest class * - * @package cake - * @subpackage cake.tests.cases.libs.model.datasources + * @package cake.tests.cases.libs.model.datasources */ class DboSourceTest extends CakeTestCase { @@ -1339,918 +113,6 @@ class DboSourceTest extends CakeTestCase { unset($this->Model); } -/** - * testFieldDoubleEscaping method - * - * @access public - * @return void - */ - function testFieldDoubleEscaping() { - $config = array_merge($this->__config, array('driver' => 'test')); - $test = ConnectionManager::create('quoteTest', $config); - $test->simulated = array(); - - $this->Model = new Article2(array('alias' => 'Article', 'ds' => 'quoteTest')); - $this->Model->setDataSource('quoteTest'); - - $this->assertEqual($this->Model->escapeField(), '`Article`.`id`'); - $result = $test->fields($this->Model, null, $this->Model->escapeField()); - $this->assertEqual($result, array('`Article`.`id`')); - - $result = $test->read($this->Model, array( - 'fields' => $this->Model->escapeField(), - 'conditions' => null, - 'recursive' => -1 - )); - $this->assertEqual(trim($test->simulated[0]), 'SELECT `Article`.`id` FROM `' . $this->testDb->fullTableName('article', false) . '` AS `Article` WHERE 1 = 1'); - - $test->startQuote = '['; - $test->endQuote = ']'; - $this->assertEqual($this->Model->escapeField(), '[Article].[id]'); - - $result = $test->fields($this->Model, null, $this->Model->escapeField()); - $this->assertEqual($result, array('[Article].[id]')); - - $result = $test->read($this->Model, array( - 'fields' => $this->Model->escapeField(), - 'conditions' => null, - 'recursive' => -1 - )); - $this->assertEqual(trim($test->simulated[1]), 'SELECT [Article].[id] FROM [' . $this->testDb->fullTableName('article', false) . '] AS [Article] WHERE 1 = 1'); - - ClassRegistry::removeObject('Article'); - } - -/** - * testGenerateAssociationQuerySelfJoin method - * - * @access public - * @return void - */ - function testGenerateAssociationQuerySelfJoin() { - $this->startTime = microtime(true); - $this->Model = new Article2(); - $this->_buildRelatedModels($this->Model); - $this->_buildRelatedModels($this->Model->Category2); - $this->Model->Category2->ChildCat = new Category2(); - $this->Model->Category2->ParentCat = new Category2(); - - $queryData = array(); - - foreach ($this->Model->Category2->associations() as $type) { - foreach ($this->Model->Category2->{$type} as $assoc => $assocData) { - $linkModel = $this->Model->Category2->{$assoc}; - $external = isset($assocData['external']); - - if ($this->Model->Category2->alias == $linkModel->alias && $type != 'hasAndBelongsToMany' && $type != 'hasMany') { - $result = $this->testDb->generateAssociationQuery($this->Model->Category2, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null); - $this->assertFalse(empty($result)); - } else { - if ($this->Model->Category2->useDbConfig == $linkModel->useDbConfig) { - $result = $this->testDb->generateAssociationQuery($this->Model->Category2, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null); - $this->assertFalse(empty($result)); - } - } - } - } - - $query = $this->testDb->generateAssociationQuery($this->Model->Category2, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+(.+)FROM(.+)`Category2`\.`group_id`\s+=\s+`Group`\.`id`\)\s+LEFT JOIN(.+)WHERE\s+1 = 1\s*$/', $query); - - $this->Model = new TestModel4(); - $this->Model->schema(); - $this->_buildRelatedModels($this->Model); - - $binding = array('type' => 'belongsTo', 'model' => 'TestModel4Parent'); - $queryData = array(); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - - $_queryData = $queryData; - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - $this->assertTrue($result); - - $expected = array( - 'conditions' => array(), - 'fields' => array( - '`TestModel4`.`id`', - '`TestModel4`.`name`', - '`TestModel4`.`created`', - '`TestModel4`.`updated`', - '`TestModel4Parent`.`id`', - '`TestModel4Parent`.`name`', - '`TestModel4Parent`.`created`', - '`TestModel4Parent`.`updated`' - ), - 'joins' => array( - array( - 'table' => '`test_model4`', - 'alias' => 'TestModel4Parent', - 'type' => 'LEFT', - 'conditions' => '`TestModel4`.`parent_id` = `TestModel4Parent`.`id`' - ) - ), - 'order' => array(), - 'limit' => array(), - 'offset' => array(), - 'group' => array() - ); - $this->assertEqual($queryData, $expected); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`, `TestModel4Parent`\.`id`, `TestModel4Parent`\.`name`, `TestModel4Parent`\.`created`, `TestModel4Parent`\.`updated`\s+/', $result); - $this->assertPattern('/FROM\s+`test_model4` AS `TestModel4`\s+LEFT JOIN\s+`test_model4` AS `TestModel4Parent`/', $result); - $this->assertPattern('/\s+ON\s+\(`TestModel4`.`parent_id` = `TestModel4Parent`.`id`\)\s+WHERE/', $result); - $this->assertPattern('/\s+WHERE\s+1 = 1\s+$/', $result); - - $params['assocData']['type'] = 'INNER'; - $this->Model->belongsTo['TestModel4Parent']['type'] = 'INNER'; - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $_queryData, $params['external'], $resultSet); - $this->assertTrue($result); - $this->assertEqual($_queryData['joins'][0]['type'], 'INNER'); - } - -/** - * testGenerateInnerJoinAssociationQuery method - * - * @access public - * @return void - */ - function testGenerateInnerJoinAssociationQuery() { - $this->Model = new TestModel9(); - $test = ConnectionManager::create('test2', $this->__config); - $this->Model->setDataSource('test2'); - $this->Model->TestModel8 = new TestModel8(); - $this->Model->TestModel8->setDataSource('test2'); - - $this->testDb->read($this->Model, array('recursive' => 1)); - $result = $this->testDb->getLastQuery(); - $this->assertPattern('/`TestModel9` LEFT JOIN `' . $this->testDb->fullTableName('test_model8', false) . '`/', $result); - - $this->Model->belongsTo['TestModel8']['type'] = 'INNER'; - $this->testDb->read($this->Model, array('recursive' => 1)); - $result = $this->testDb->getLastQuery(); - $this->assertPattern('/`TestModel9` INNER JOIN `' . $this->testDb->fullTableName('test_model8', false) . '`/', $result); - - } - -/** - * testGenerateAssociationQuerySelfJoinWithConditionsInHasOneBinding method - * - * @access public - * @return void - */ - function testGenerateAssociationQuerySelfJoinWithConditionsInHasOneBinding() { - $this->Model = new TestModel8(); - $this->Model->schema(); - $this->_buildRelatedModels($this->Model); - - $binding = array('type' => 'hasOne', 'model' => 'TestModel9'); - $queryData = array(); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - $_queryData = $queryData; - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - $this->assertTrue($result); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+`TestModel8`\.`id`, `TestModel8`\.`test_model9_id`, `TestModel8`\.`name`, `TestModel8`\.`created`, `TestModel8`\.`updated`, `TestModel9`\.`id`, `TestModel9`\.`test_model8_id`, `TestModel9`\.`name`, `TestModel9`\.`created`, `TestModel9`\.`updated`\s+/', $result); - $this->assertPattern('/FROM\s+`test_model8` AS `TestModel8`\s+LEFT JOIN\s+`test_model9` AS `TestModel9`/', $result); - $this->assertPattern('/\s+ON\s+\(`TestModel9`\.`name` != \'mariano\'\s+AND\s+`TestModel9`.`test_model8_id` = `TestModel8`.`id`\)\s+WHERE/', $result); - $this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); - } - -/** - * testGenerateAssociationQuerySelfJoinWithConditionsInBelongsToBinding method - * - * @access public - * @return void - */ - function testGenerateAssociationQuerySelfJoinWithConditionsInBelongsToBinding() { - $this->Model = new TestModel9(); - $this->Model->schema(); - $this->_buildRelatedModels($this->Model); - - $binding = array('type' => 'belongsTo', 'model' => 'TestModel8'); - $queryData = array(); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - $this->assertTrue($result); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+`TestModel9`\.`id`, `TestModel9`\.`test_model8_id`, `TestModel9`\.`name`, `TestModel9`\.`created`, `TestModel9`\.`updated`, `TestModel8`\.`id`, `TestModel8`\.`test_model9_id`, `TestModel8`\.`name`, `TestModel8`\.`created`, `TestModel8`\.`updated`\s+/', $result); - $this->assertPattern('/FROM\s+`test_model9` AS `TestModel9`\s+LEFT JOIN\s+`test_model8` AS `TestModel8`/', $result); - $this->assertPattern('/\s+ON\s+\(`TestModel8`\.`name` != \'larry\'\s+AND\s+`TestModel9`.`test_model8_id` = `TestModel8`.`id`\)\s+WHERE/', $result); - $this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); - } - -/** - * testGenerateAssociationQuerySelfJoinWithConditions method - * - * @access public - * @return void - */ - function testGenerateAssociationQuerySelfJoinWithConditions() { - $this->Model = new TestModel4(); - $this->Model->schema(); - $this->_buildRelatedModels($this->Model); - - $binding = array('type' => 'belongsTo', 'model' => 'TestModel4Parent'); - $queryData = array('conditions' => array('TestModel4Parent.name !=' => 'mariano')); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - $this->assertTrue($result); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`, `TestModel4Parent`\.`id`, `TestModel4Parent`\.`name`, `TestModel4Parent`\.`created`, `TestModel4Parent`\.`updated`\s+/', $result); - $this->assertPattern('/FROM\s+`test_model4` AS `TestModel4`\s+LEFT JOIN\s+`test_model4` AS `TestModel4Parent`/', $result); - $this->assertPattern('/\s+ON\s+\(`TestModel4`.`parent_id` = `TestModel4Parent`.`id`\)\s+WHERE/', $result); - $this->assertPattern('/\s+WHERE\s+(?:\()?`TestModel4Parent`.`name`\s+!=\s+\'mariano\'(?:\))?\s*$/', $result); - - $this->Featured2 = new Featured2(); - $this->Featured2->schema(); - - $this->Featured2->bindModel(array( - 'belongsTo' => array( - 'ArticleFeatured2' => array( - 'conditions' => 'ArticleFeatured2.published = \'Y\'', - 'fields' => 'id, title, user_id, published' - ) - ) - )); - - $this->_buildRelatedModels($this->Featured2); - - $binding = array('type' => 'belongsTo', 'model' => 'ArticleFeatured2'); - $queryData = array('conditions' => array()); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Featured2, $queryData, $binding); - - $result = $this->testDb->generateAssociationQuery($this->Featured2, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - $this->assertTrue($result); - $result = $this->testDb->generateAssociationQuery($this->Featured2, $null, null, null, null, $queryData, false, $null); - - $this->assertPattern( - '/^SELECT\s+`Featured2`\.`id`, `Featured2`\.`article_id`, `Featured2`\.`category_id`, `Featured2`\.`name`,\s+'. - '`ArticleFeatured2`\.`id`, `ArticleFeatured2`\.`title`, `ArticleFeatured2`\.`user_id`, `ArticleFeatured2`\.`published`\s+' . - 'FROM\s+`featured2` AS `Featured2`\s+LEFT JOIN\s+`article_featured` AS `ArticleFeatured2`' . - '\s+ON\s+\(`ArticleFeatured2`.`published` = \'Y\'\s+AND\s+`Featured2`\.`article_featured2_id` = `ArticleFeatured2`\.`id`\)' . - '\s+WHERE\s+1\s+=\s+1\s*$/', - $result - ); - } - -/** - * testGenerateAssociationQueryHasOne method - * - * @access public - * @return void - */ - function testGenerateAssociationQueryHasOne() { - $this->Model = new TestModel4(); - $this->Model->schema(); - $this->_buildRelatedModels($this->Model); - - $binding = array('type' => 'hasOne', 'model' => 'TestModel5'); - - $queryData = array(); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - $this->assertTrue($result); - - $result = $this->testDb->buildJoinStatement($queryData['joins'][0]); - $expected = ' LEFT JOIN `test_model5` AS `TestModel5` ON (`TestModel5`.`test_model4_id` = `TestModel4`.`id`)'; - $this->assertEqual(trim($result), trim($expected)); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`, `TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model4` AS `TestModel4`\s+LEFT JOIN\s+/', $result); - $this->assertPattern('/`test_model5` AS `TestModel5`\s+ON\s+\(`TestModel5`.`test_model4_id` = `TestModel4`.`id`\)\s+WHERE/', $result); - $this->assertPattern('/\s+WHERE\s+(?:\()?\s*1 = 1\s*(?:\))?\s*$/', $result); - } - -/** - * testGenerateAssociationQueryHasOneWithConditions method - * - * @access public - * @return void - */ - function testGenerateAssociationQueryHasOneWithConditions() { - $this->Model = new TestModel4(); - $this->Model->schema(); - $this->_buildRelatedModels($this->Model); - - $binding = array('type' => 'hasOne', 'model' => 'TestModel5'); - - $queryData = array('conditions' => array('TestModel5.name !=' => 'mariano')); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - $this->assertTrue($result); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - - $this->assertPattern('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`, `TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model4` AS `TestModel4`\s+LEFT JOIN\s+`test_model5` AS `TestModel5`/', $result); - $this->assertPattern('/\s+ON\s+\(`TestModel5`.`test_model4_id`\s+=\s+`TestModel4`.`id`\)\s+WHERE/', $result); - $this->assertPattern('/\s+WHERE\s+(?:\()?\s*`TestModel5`.`name`\s+!=\s+\'mariano\'\s*(?:\))?\s*$/', $result); - } - -/** - * testGenerateAssociationQueryBelongsTo method - * - * @access public - * @return void - */ - function testGenerateAssociationQueryBelongsTo() { - $this->Model = new TestModel5(); - $this->Model->schema(); - $this->_buildRelatedModels($this->Model); - - $binding = array('type'=>'belongsTo', 'model'=>'TestModel4'); - $queryData = array(); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - $this->assertTrue($result); - - $result = $this->testDb->buildJoinStatement($queryData['joins'][0]); - $expected = ' LEFT JOIN `test_model4` AS `TestModel4` ON (`TestModel5`.`test_model4_id` = `TestModel4`.`id`)'; - $this->assertEqual(trim($result), trim($expected)); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`, `TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+LEFT JOIN\s+`test_model4` AS `TestModel4`/', $result); - $this->assertPattern('/\s+ON\s+\(`TestModel5`.`test_model4_id` = `TestModel4`.`id`\)\s+WHERE\s+/', $result); - $this->assertPattern('/\s+WHERE\s+(?:\()?\s*1 = 1\s*(?:\))?\s*$/', $result); - } - -/** - * testGenerateAssociationQueryBelongsToWithConditions method - * - * @access public - * @return void - */ - function testGenerateAssociationQueryBelongsToWithConditions() { - $this->Model = new TestModel5(); - $this->Model->schema(); - $this->_buildRelatedModels($this->Model); - - $binding = array('type' => 'belongsTo', 'model' => 'TestModel4'); - $queryData = array('conditions' => array('TestModel5.name !=' => 'mariano')); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - $this->assertTrue($result); - - $result = $this->testDb->buildJoinStatement($queryData['joins'][0]); - $expected = ' LEFT JOIN `test_model4` AS `TestModel4` ON (`TestModel5`.`test_model4_id` = `TestModel4`.`id`)'; - $this->assertEqual(trim($result), trim($expected)); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`, `TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+LEFT JOIN\s+`test_model4` AS `TestModel4`/', $result); - $this->assertPattern('/\s+ON\s+\(`TestModel5`.`test_model4_id` = `TestModel4`.`id`\)\s+WHERE\s+/', $result); - $this->assertPattern('/\s+WHERE\s+`TestModel5`.`name` != \'mariano\'\s*$/', $result); - } - -/** - * testGenerateAssociationQueryHasMany method - * - * @access public - * @return void - */ - function testGenerateAssociationQueryHasMany() { - $this->Model = new TestModel5(); - $this->Model->schema(); - $this->_buildRelatedModels($this->Model); - - $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); - $queryData = array(); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - - $this->assertPattern('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE/', $result); - $this->assertPattern('/\s+WHERE\s+`TestModel6`.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)/', $result); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result); - $this->assertPattern('/\s+WHERE\s+(?:\()?\s*1 = 1\s*(?:\))?\s*$/', $result); - } - -/** - * testGenerateAssociationQueryHasManyWithLimit method - * - * @access public - * @return void - */ - function testGenerateAssociationQueryHasManyWithLimit() { - $this->Model = new TestModel5(); - $this->Model->schema(); - $this->_buildRelatedModels($this->Model); - - $this->Model->hasMany['TestModel6']['limit'] = 2; - - $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); - $queryData = array(); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - $this->assertPattern( - '/^SELECT\s+' . - '`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+'. - 'FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+' . - '`TestModel6`.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)\s*'. - 'LIMIT \d*'. - '\s*$/', $result - ); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern( - '/^SELECT\s+'. - '`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+'. - 'FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+'. - '(?:\()?\s*1 = 1\s*(?:\))?'. - '\s*$/', $result - ); - } - -/** - * testGenerateAssociationQueryHasManyWithConditions method - * - * @access public - * @return void - */ - function testGenerateAssociationQueryHasManyWithConditions() { - $this->Model = new TestModel5(); - $this->Model->schema(); - $this->_buildRelatedModels($this->Model); - - $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); - $queryData = array('conditions' => array('TestModel5.name !=' => 'mariano')); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - $this->assertPattern('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result); - $this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result); - $this->assertPattern('/\s+WHERE\s+(?:\()?`TestModel5`.`name`\s+!=\s+\'mariano\'(?:\))?\s*$/', $result); - } - -/** - * testGenerateAssociationQueryHasManyWithOffsetAndLimit method - * - * @access public - * @return void - */ - function testGenerateAssociationQueryHasManyWithOffsetAndLimit() { - $this->Model = new TestModel5(); - $this->Model->schema(); - $this->_buildRelatedModels($this->Model); - - $__backup = $this->Model->hasMany['TestModel6']; - - $this->Model->hasMany['TestModel6']['offset'] = 2; - $this->Model->hasMany['TestModel6']['limit'] = 5; - - $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); - $queryData = array(); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - - $this->assertPattern('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result); - $this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result); - $this->assertPattern('/\s+LIMIT 2,\s*5\s*$/', $result); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result); - $this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); - - $this->Model->hasMany['TestModel6'] = $__backup; - } - -/** - * testGenerateAssociationQueryHasManyWithPageAndLimit method - * - * @access public - * @return void - */ - function testGenerateAssociationQueryHasManyWithPageAndLimit() { - $this->Model = new TestModel5(); - $this->Model->schema(); - $this->_buildRelatedModels($this->Model); - - $__backup = $this->Model->hasMany['TestModel6']; - - $this->Model->hasMany['TestModel6']['page'] = 2; - $this->Model->hasMany['TestModel6']['limit'] = 5; - - $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); - $queryData = array(); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - $this->assertPattern('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result); - $this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result); - $this->assertPattern('/\s+LIMIT 5,\s*5\s*$/', $result); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result); - $this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); - - $this->Model->hasMany['TestModel6'] = $__backup; - } - -/** - * testGenerateAssociationQueryHasManyWithFields method - * - * @access public - * @return void - */ - function testGenerateAssociationQueryHasManyWithFields() { - $this->Model = new TestModel5(); - $this->Model->schema(); - $this->_buildRelatedModels($this->Model); - - $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); - $queryData = array('fields' => array('`TestModel5`.`name`')); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - $this->assertPattern('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result); - $this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+`TestModel5`\.`name`, `TestModel5`\.`id`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result); - $this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); - - $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); - $queryData = array('fields' => array('`TestModel5`.`id`, `TestModel5`.`name`')); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - $this->assertPattern('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result); - $this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`name`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result); - $this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); - - $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); - $queryData = array('fields' => array('`TestModel5`.`name`', '`TestModel5`.`created`')); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - $this->assertPattern('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result); - $this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+`TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`id`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result); - $this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); - - $this->Model->hasMany['TestModel6']['fields'] = array('name'); - - $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); - $queryData = array('fields' => array('`TestModel5`.`id`', '`TestModel5`.`name`')); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - $this->assertPattern('/^SELECT\s+`TestModel6`\.`name`, `TestModel6`\.`test_model5_id`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result); - $this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`name`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result); - $this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); - - unset($this->Model->hasMany['TestModel6']['fields']); - - $this->Model->hasMany['TestModel6']['fields'] = array('id', 'name'); - - $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); - $queryData = array('fields' => array('`TestModel5`.`id`', '`TestModel5`.`name`')); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - $this->assertPattern('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`name`, `TestModel6`\.`test_model5_id`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result); - $this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`name`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result); - $this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); - - unset($this->Model->hasMany['TestModel6']['fields']); - - $this->Model->hasMany['TestModel6']['fields'] = array('test_model5_id', 'name'); - - $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); - $queryData = array('fields' => array('`TestModel5`.`id`', '`TestModel5`.`name`')); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - $this->assertPattern('/^SELECT\s+`TestModel6`\.`test_model5_id`, `TestModel6`\.`name`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result); - $this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`name`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result); - $this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); - - unset($this->Model->hasMany['TestModel6']['fields']); - } - -/** - * test generateAssociationQuery with a hasMany and an aggregate function. - * - * @return void - */ - function testGenerateAssociationQueryHasManyAndAggregateFunction() { - $this->Model = new TestModel5(); - $this->Model->schema(); - $this->_buildRelatedModels($this->Model); - - $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); - $queryData = array('fields' => array('MIN(TestModel5.test_model4_id)')); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - $this->Model->recursive = 0; - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, $params['type'], $params['assoc'], $params['assocData'], $queryData, false, $resultSet); - $this->assertPattern('/^SELECT\s+MIN\(`TestModel5`\.`test_model4_id`\)\s+FROM/', $result); - } - -/** - * testGenerateAssociationQueryHasAndBelongsToMany method - * - * @access public - * @return void - */ - function testGenerateAssociationQueryHasAndBelongsToMany() { - $this->Model = new TestModel4(); - $this->Model->schema(); - $this->_buildRelatedModels($this->Model); - - $binding = array('type' => 'hasAndBelongsToMany', 'model' => 'TestModel7'); - $queryData = array(); - $resultSet = null; - $null = null; - - $params = $this->_prepareAssociationQuery($this->Model, $queryData, $binding); - - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - $this->assertPattern('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model7` AS `TestModel7`\s+JOIN\s+`' . $this->testDb->fullTableName('test_model4_test_model7', false) . '`/', $result); - $this->assertPattern('/\s+ON\s+\(`TestModel4TestModel7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}\s+AND/', $result); - $this->assertPattern('/\s+AND\s+`TestModel4TestModel7`\.`test_model7_id`\s+=\s+`TestModel7`\.`id`\)/', $result); - $this->assertPattern('/WHERE\s+(?:\()?1 = 1(?:\))?\s*$/', $result); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model4` AS `TestModel4`\s+WHERE/', $result); - $this->assertPattern('/\s+WHERE\s+(?:\()?1 = 1(?:\))?\s*$/', $result); - } - -/** - * testGenerateAssociationQueryHasAndBelongsToManyWithConditions method - * - * @access public - * @return void - */ - function testGenerateAssociationQueryHasAndBelongsToManyWithConditions() { - $this->Model = new TestModel4(); - $this->Model->schema(); - $this->_buildRelatedModels($this->Model); - - $binding = array('type'=>'hasAndBelongsToMany', 'model'=>'TestModel7'); - $queryData = array('conditions' => array('TestModel4.name !=' => 'mariano')); - $resultSet = null; - $null = null; - - $params = $this->_prepareAssociationQuery($this->Model, $queryData, $binding); - - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - $this->assertPattern('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model7`\s+AS\s+`TestModel7`\s+JOIN\s+`test_model4_test_model7`\s+AS\s+`TestModel4TestModel7`/', $result); - $this->assertPattern('/\s+ON\s+\(`TestModel4TestModel7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}/', $result); - $this->assertPattern('/\s+AND\s+`TestModel4TestModel7`\.`test_model7_id`\s+=\s+`TestModel7`\.`id`\)\s+WHERE\s+/', $result); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model4` AS `TestModel4`\s+WHERE\s+(?:\()?`TestModel4`.`name`\s+!=\s+\'mariano\'(?:\))?\s*$/', $result); - } - -/** - * testGenerateAssociationQueryHasAndBelongsToManyWithOffsetAndLimit method - * - * @access public - * @return void - */ - function testGenerateAssociationQueryHasAndBelongsToManyWithOffsetAndLimit() { - $this->Model = new TestModel4(); - $this->Model->schema(); - $this->_buildRelatedModels($this->Model); - - $__backup = $this->Model->hasAndBelongsToMany['TestModel7']; - - $this->Model->hasAndBelongsToMany['TestModel7']['offset'] = 2; - $this->Model->hasAndBelongsToMany['TestModel7']['limit'] = 5; - - $binding = array('type'=>'hasAndBelongsToMany', 'model'=>'TestModel7'); - $queryData = array(); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - $this->assertPattern('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model7`\s+AS\s+`TestModel7`\s+JOIN\s+`test_model4_test_model7`\s+AS\s+`TestModel4TestModel7`/', $result); - $this->assertPattern('/\s+ON\s+\(`TestModel4TestModel7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}\s+/', $result); - $this->assertPattern('/\s+AND\s+`TestModel4TestModel7`\.`test_model7_id`\s+=\s+`TestModel7`\.`id`\)\s+WHERE\s+/', $result); - $this->assertPattern('/\s+(?:\()?1\s+=\s+1(?:\))?\s*\s+LIMIT 2,\s*5\s*$/', $result); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model4` AS `TestModel4`\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); - - $this->Model->hasAndBelongsToMany['TestModel7'] = $__backup; - } - -/** - * testGenerateAssociationQueryHasAndBelongsToManyWithPageAndLimit method - * - * @access public - * @return void - */ - function testGenerateAssociationQueryHasAndBelongsToManyWithPageAndLimit() { - $this->Model = new TestModel4(); - $this->Model->schema(); - $this->_buildRelatedModels($this->Model); - - $__backup = $this->Model->hasAndBelongsToMany['TestModel7']; - - $this->Model->hasAndBelongsToMany['TestModel7']['page'] = 2; - $this->Model->hasAndBelongsToMany['TestModel7']['limit'] = 5; - - $binding = array('type'=>'hasAndBelongsToMany', 'model'=>'TestModel7'); - $queryData = array(); - $resultSet = null; - $null = null; - - $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - - $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); - $this->assertPattern('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model7`\s+AS\s+`TestModel7`\s+JOIN\s+`test_model4_test_model7`\s+AS\s+`TestModel4TestModel7`/', $result); - $this->assertPattern('/\s+ON\s+\(`TestModel4TestModel7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}/', $result); - $this->assertPattern('/\s+AND\s+`TestModel4TestModel7`\.`test_model7_id`\s+=\s+`TestModel7`\.`id`\)\s+WHERE\s+/', $result); - $this->assertPattern('/\s+(?:\()?1\s+=\s+1(?:\))?\s*\s+LIMIT 5,\s*5\s*$/', $result); - - $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result); - $this->assertPattern('/\s+FROM\s+`test_model4` AS `TestModel4`\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result); - - $this->Model->hasAndBelongsToMany['TestModel7'] = $__backup; - } - -/** - * buildRelatedModels method - * - * @param mixed $model - * @access protected - * @return void - */ - function _buildRelatedModels(&$model) { - foreach ($model->associations() as $type) { - foreach ($model->{$type} as $assoc => $assocData) { - if (is_string($assocData)) { - $className = $assocData; - } elseif (isset($assocData['className'])) { - $className = $assocData['className']; - } - $model->$className = new $className(); - $model->$className->schema(); - } - } - } - -/** - * &_prepareAssociationQuery method - * - * @param mixed $model - * @param mixed $queryData - * @param mixed $binding - * @access public - * @return void - */ - function &_prepareAssociationQuery(&$model, &$queryData, $binding) { - $type = $binding['type']; - $assoc = $binding['model']; - $assocData = $model->{$type}[$assoc]; - $className = $assocData['className']; - - $linkModel = $model->{$className}; - $external = isset($assocData['external']); - $queryData = $this->testDb->__scrubQueryData($queryData); - - $result = array_merge(array('linkModel' => &$linkModel), compact('type', 'assoc', 'assocData', 'external')); - return $result; - } - -/** - * testSelectDistict method - * - * @access public - * @return void - */ - function testSelectDistict() { - $result = $this->testDb->fields($this->Model, 'Vendor', "DISTINCT Vendor.id, Vendor.name"); - $expected = array('DISTINCT `Vendor`.`id`', '`Vendor`.`name`'); - $this->assertEqual($result, $expected); - } /** * test that booleans and null make logical condition strings. @@ -2276,716 +138,6 @@ class DboSourceTest extends CakeTestCase { $result = $this->testDb->conditions(' ', '" " conditions failed %s'); $this->assertEqual($result, ' WHERE 1 = 1'); } -/** - * testStringConditionsParsing method - * - * @access public - * @return void - */ - function testStringConditionsParsing() { - $result = $this->testDb->conditions("ProjectBid.project_id = Project.id"); - $expected = " WHERE `ProjectBid`.`project_id` = `Project`.`id`"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions("Candy.name LIKE 'a' AND HardCandy.name LIKE 'c'"); - $expected = " WHERE `Candy`.`name` LIKE 'a' AND `HardCandy`.`name` LIKE 'c'"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions("HardCandy.name LIKE 'a' AND Candy.name LIKE 'c'"); - $expected = " WHERE `HardCandy`.`name` LIKE 'a' AND `Candy`.`name` LIKE 'c'"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions("Post.title = '1.1'"); - $expected = " WHERE `Post`.`title` = '1.1'"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions("User.id != 0 AND User.user LIKE '%arr%'"); - $expected = " WHERE `User`.`id` != 0 AND `User`.`user` LIKE '%arr%'"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions("SUM(Post.comments_count) > 500"); - $expected = " WHERE SUM(`Post`.`comments_count`) > 500"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions("(Post.created < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR(Post.created), MONTH(Post.created)"); - $expected = " WHERE (`Post`.`created` < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR(`Post`.`created`), MONTH(`Post`.`created`)"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions("score BETWEEN 90.1 AND 95.7"); - $expected = " WHERE score BETWEEN 90.1 AND 95.7"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('score' => array(2=>1, 2, 10))); - $expected = " WHERE score IN (1, 2, 10)"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions("Aro.rght = Aro.lft + 1.1"); - $expected = " WHERE `Aro`.`rght` = `Aro`.`lft` + 1.1"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions("(Post.created < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR(Post.created), MONTH(Post.created)"); - $expected = " WHERE (`Post`.`created` < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR(`Post`.`created`), MONTH(`Post`.`created`)"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions('Sportstaette.sportstaette LIKE "%ru%" AND Sportstaette.sportstaettenart_id = 2'); - $expected = ' WHERE `Sportstaette`.`sportstaette` LIKE "%ru%" AND `Sportstaette`.`sportstaettenart_id` = 2'; - $this->assertPattern('/\s*WHERE\s+`Sportstaette`\.`sportstaette`\s+LIKE\s+"%ru%"\s+AND\s+`Sports/', $result); - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions('Sportstaette.sportstaettenart_id = 2 AND Sportstaette.sportstaette LIKE "%ru%"'); - $expected = ' WHERE `Sportstaette`.`sportstaettenart_id` = 2 AND `Sportstaette`.`sportstaette` LIKE "%ru%"'; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions('SUM(Post.comments_count) > 500 AND NOT Post.title IS NULL AND NOT Post.extended_title IS NULL'); - $expected = ' WHERE SUM(`Post`.`comments_count`) > 500 AND NOT `Post`.`title` IS NULL AND NOT `Post`.`extended_title` IS NULL'; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions('NOT Post.title IS NULL AND NOT Post.extended_title IS NULL AND SUM(Post.comments_count) > 500'); - $expected = ' WHERE NOT `Post`.`title` IS NULL AND NOT `Post`.`extended_title` IS NULL AND SUM(`Post`.`comments_count`) > 500'; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions('NOT Post.extended_title IS NULL AND NOT Post.title IS NULL AND Post.title != "" AND SPOON(SUM(Post.comments_count) + 1.1) > 500'); - $expected = ' WHERE NOT `Post`.`extended_title` IS NULL AND NOT `Post`.`title` IS NULL AND `Post`.`title` != "" AND SPOON(SUM(`Post`.`comments_count`) + 1.1) > 500'; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions('NOT Post.title_extended IS NULL AND NOT Post.title IS NULL AND Post.title_extended != Post.title'); - $expected = ' WHERE NOT `Post`.`title_extended` IS NULL AND NOT `Post`.`title` IS NULL AND `Post`.`title_extended` != `Post`.`title`'; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions("Comment.id = 'a'"); - $expected = " WHERE `Comment`.`id` = 'a'"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions("lower(Article.title) LIKE 'a%'"); - $expected = " WHERE lower(`Article`.`title`) LIKE 'a%'"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions('((MATCH(Video.title) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 2) + (MATCH(Video.description) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 0.4) + (MATCH(Video.tags) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 1.5))'); - $expected = ' WHERE ((MATCH(`Video`.`title`) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 2) + (MATCH(`Video`.`description`) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 0.4) + (MATCH(`Video`.`tags`) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 1.5))'; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions('DATEDIFF(NOW(),Article.published) < 1 && Article.live=1'); - $expected = " WHERE DATEDIFF(NOW(),`Article`.`published`) < 1 && `Article`.`live`=1"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions('file = "index.html"'); - $expected = ' WHERE file = "index.html"'; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions("file = 'index.html'"); - $expected = " WHERE file = 'index.html'"; - $this->assertEqual($result, $expected); - - $letter = $letter = 'd.a'; - $conditions = array('Company.name like ' => $letter . '%'); - $result = $this->testDb->conditions($conditions); - $expected = " WHERE `Company`.`name` like 'd.a%'"; - $this->assertEqual($result, $expected); - - $conditions = array('Artist.name' => 'JUDY and MARY'); - $result = $this->testDb->conditions($conditions); - $expected = " WHERE `Artist`.`name` = 'JUDY and MARY'"; - $this->assertEqual($result, $expected); - - $conditions = array('Artist.name' => 'JUDY AND MARY'); - $result = $this->testDb->conditions($conditions); - $expected = " WHERE `Artist`.`name` = 'JUDY AND MARY'"; - $this->assertEqual($result, $expected); - } - -/** - * testQuotesInStringConditions method - * - * @access public - * @return void - */ - function testQuotesInStringConditions() { - $result = $this->testDb->conditions('Member.email = \'mariano@cricava.com\''); - $expected = ' WHERE `Member`.`email` = \'mariano@cricava.com\''; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions('Member.email = "mariano@cricava.com"'); - $expected = ' WHERE `Member`.`email` = "mariano@cricava.com"'; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions('Member.email = \'mariano@cricava.com\' AND Member.user LIKE \'mariano.iglesias%\''); - $expected = ' WHERE `Member`.`email` = \'mariano@cricava.com\' AND `Member`.`user` LIKE \'mariano.iglesias%\''; - $this->assertEqual($result, $expected); - - - $result = $this->testDb->conditions('Member.email = "mariano@cricava.com" AND Member.user LIKE "mariano.iglesias%"'); - $expected = ' WHERE `Member`.`email` = "mariano@cricava.com" AND `Member`.`user` LIKE "mariano.iglesias%"'; - $this->assertEqual($result, $expected); - } - -/** - * testParenthesisInStringConditions method - * - * @access public - * @return void - */ - function testParenthesisInStringConditions() { - $result = $this->testDb->conditions('Member.name = \'(lu\''); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(lu\'$/', $result); - - $result = $this->testDb->conditions('Member.name = \')lu\''); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\)lu\'$/', $result); - - $result = $this->testDb->conditions('Member.name = \'va(lu\''); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\(lu\'$/', $result); - - $result = $this->testDb->conditions('Member.name = \'va)lu\''); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\)lu\'$/', $result); - - $result = $this->testDb->conditions('Member.name = \'va(lu)\''); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\(lu\)\'$/', $result); - - $result = $this->testDb->conditions('Member.name = \'va(lu)e\''); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\(lu\)e\'$/', $result); - - $result = $this->testDb->conditions('Member.name = \'(mariano)\''); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano\)\'$/', $result); - - $result = $this->testDb->conditions('Member.name = \'(mariano)iglesias\''); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano\)iglesias\'$/', $result); - - $result = $this->testDb->conditions('Member.name = \'(mariano) iglesias\''); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano\) iglesias\'$/', $result); - - $result = $this->testDb->conditions('Member.name = \'(mariano word) iglesias\''); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano word\) iglesias\'$/', $result); - - $result = $this->testDb->conditions('Member.name = \'(mariano.iglesias)\''); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano.iglesias\)\'$/', $result); - - $result = $this->testDb->conditions('Member.name = \'Mariano Iglesias (mariano.iglesias)\''); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'Mariano Iglesias \(mariano.iglesias\)\'$/', $result); - - $result = $this->testDb->conditions('Member.name = \'Mariano Iglesias (mariano.iglesias) CakePHP\''); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'Mariano Iglesias \(mariano.iglesias\) CakePHP\'$/', $result); - - $result = $this->testDb->conditions('Member.name = \'(mariano.iglesias) CakePHP\''); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano.iglesias\) CakePHP\'$/', $result); - } - -/** - * testParenthesisInArrayConditions method - * - * @access public - * @return void - */ - function testParenthesisInArrayConditions() { - $result = $this->testDb->conditions(array('Member.name' => '(lu')); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(lu\'$/', $result); - - $result = $this->testDb->conditions(array('Member.name' => ')lu')); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\)lu\'$/', $result); - - $result = $this->testDb->conditions(array('Member.name' => 'va(lu')); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\(lu\'$/', $result); - - $result = $this->testDb->conditions(array('Member.name' => 'va)lu')); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\)lu\'$/', $result); - - $result = $this->testDb->conditions(array('Member.name' => 'va(lu)')); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\(lu\)\'$/', $result); - - $result = $this->testDb->conditions(array('Member.name' => 'va(lu)e')); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\(lu\)e\'$/', $result); - - $result = $this->testDb->conditions(array('Member.name' => '(mariano)')); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano\)\'$/', $result); - - $result = $this->testDb->conditions(array('Member.name' => '(mariano)iglesias')); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano\)iglesias\'$/', $result); - - $result = $this->testDb->conditions(array('Member.name' => '(mariano) iglesias')); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano\) iglesias\'$/', $result); - - $result = $this->testDb->conditions(array('Member.name' => '(mariano word) iglesias')); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano word\) iglesias\'$/', $result); - - $result = $this->testDb->conditions(array('Member.name' => '(mariano.iglesias)')); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano.iglesias\)\'$/', $result); - - $result = $this->testDb->conditions(array('Member.name' => 'Mariano Iglesias (mariano.iglesias)')); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'Mariano Iglesias \(mariano.iglesias\)\'$/', $result); - - $result = $this->testDb->conditions(array('Member.name' => 'Mariano Iglesias (mariano.iglesias) CakePHP')); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'Mariano Iglesias \(mariano.iglesias\) CakePHP\'$/', $result); - - $result = $this->testDb->conditions(array('Member.name' => '(mariano.iglesias) CakePHP')); - $this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano.iglesias\) CakePHP\'$/', $result); - } - -/** - * testArrayConditionsParsing method - * - * @access public - * @return void - */ - function testArrayConditionsParsing() { - $this->loadFixtures('Post', 'Author'); - $result = $this->testDb->conditions(array('Stereo.type' => 'in dash speakers')); - $this->assertPattern("/^\s+WHERE\s+`Stereo`.`type`\s+=\s+'in dash speakers'/", $result); - - $result = $this->testDb->conditions(array('Candy.name LIKE' => 'a', 'HardCandy.name LIKE' => 'c')); - $this->assertPattern("/^\s+WHERE\s+`Candy`.`name` LIKE\s+'a'\s+AND\s+`HardCandy`.`name`\s+LIKE\s+'c'/", $result); - - $result = $this->testDb->conditions(array('HardCandy.name LIKE' => 'a', 'Candy.name LIKE' => 'c')); - $expected = " WHERE `HardCandy`.`name` LIKE 'a' AND `Candy`.`name` LIKE 'c'"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('HardCandy.name LIKE' => 'a%', 'Candy.name LIKE' => '%c%')); - $expected = " WHERE `HardCandy`.`name` LIKE 'a%' AND `Candy`.`name` LIKE '%c%'"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('HardCandy.name LIKE' => 'to be or%', 'Candy.name LIKE' => '%not to be%')); - $expected = " WHERE `HardCandy`.`name` LIKE 'to be or%' AND `Candy`.`name` LIKE '%not to be%'"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('score BETWEEN ? AND ?' => array(90.1, 95.7))); - $expected = " WHERE `score` BETWEEN 90.100000 AND 95.700000"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('Post.title' => 1.1)); - $expected = " WHERE `Post`.`title` = 1.100000"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('Post.title' => 1.1), true, true, new Post()); - $expected = " WHERE `Post`.`title` = '1.1'"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('SUM(Post.comments_count) >' => '500')); - $expected = " WHERE SUM(`Post`.`comments_count`) > '500'"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('MAX(Post.rating) >' => '50')); - $expected = " WHERE MAX(`Post`.`rating`) > '50'"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('title LIKE' => '%hello')); - $expected = " WHERE `title` LIKE '%hello'"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('Post.name' => 'mad(g)ik')); - $expected = " WHERE `Post`.`name` = 'mad(g)ik'"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('score' => array(1, 2, 10))); - $expected = " WHERE score IN (1, 2, 10)"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('score' => array())); - $expected = " WHERE `score` IS NULL"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('score !=' => array())); - $expected = " WHERE `score` IS NOT NULL"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('score !=' => '20')); - $expected = " WHERE `score` != '20'"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('score >' => '20')); - $expected = " WHERE `score` > '20'"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('client_id >' => '20'), true, true, new TestModel()); - $expected = " WHERE `client_id` > 20"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('OR' => array( - array('User.user' => 'mariano'), - array('User.user' => 'nate') - ))); - - $expected = " WHERE ((`User`.`user` = 'mariano') OR (`User`.`user` = 'nate'))"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('or' => array( - 'score BETWEEN ? AND ?' => array('4', '5'), 'rating >' => '20' - ))); - $expected = " WHERE ((`score` BETWEEN '4' AND '5') OR (`rating` > '20'))"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('or' => array( - 'score BETWEEN ? AND ?' => array('4', '5'), array('score >' => '20') - ))); - $expected = " WHERE ((`score` BETWEEN '4' AND '5') OR (`score` > '20'))"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('and' => array( - 'score BETWEEN ? AND ?' => array('4', '5'), array('score >' => '20') - ))); - $expected = " WHERE ((`score` BETWEEN '4' AND '5') AND (`score` > '20'))"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array( - 'published' => 1, 'or' => array('score >' => '2', array('score >' => '20')) - )); - $expected = " WHERE `published` = 1 AND ((`score` > '2') OR (`score` > '20'))"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array(array('Project.removed' => false))); - $expected = " WHERE `Project`.`removed` = 0"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array(array('Project.removed' => true))); - $expected = " WHERE `Project`.`removed` = 1"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array(array('Project.removed' => null))); - $expected = " WHERE `Project`.`removed` IS NULL"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array(array('Project.removed !=' => null))); - $expected = " WHERE `Project`.`removed` IS NOT NULL"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('(Usergroup.permissions) & 4' => 4)); - $expected = " WHERE (`Usergroup`.`permissions`) & 4 = 4"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('((Usergroup.permissions) & 4)' => 4)); - $expected = " WHERE ((`Usergroup`.`permissions`) & 4) = 4"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('Post.modified >=' => 'DATE_SUB(NOW(), INTERVAL 7 DAY)')); - $expected = " WHERE `Post`.`modified` >= 'DATE_SUB(NOW(), INTERVAL 7 DAY)'"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('Post.modified >= DATE_SUB(NOW(), INTERVAL 7 DAY)')); - $expected = " WHERE `Post`.`modified` >= DATE_SUB(NOW(), INTERVAL 7 DAY)"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array( - 'NOT' => array('Course.id' => null, 'Course.vet' => 'N', 'level_of_education_id' => array(912,999)), - 'Enrollment.yearcompleted >' => '0') - ); - $this->assertPattern('/^\s*WHERE\s+\(NOT\s+\(`Course`\.`id` IS NULL\)\s+AND NOT\s+\(`Course`\.`vet`\s+=\s+\'N\'\)\s+AND NOT\s+\(level_of_education_id IN \(912, 999\)\)\)\s+AND\s+`Enrollment`\.`yearcompleted`\s+>\s+\'0\'\s*$/', $result); - - $result = $this->testDb->conditions(array('id <>' => '8')); - $this->assertPattern('/^\s*WHERE\s+`id`\s+<>\s+\'8\'\s*$/', $result); - - $result = $this->testDb->conditions(array('TestModel.field =' => 'gribe$@()lu')); - $expected = " WHERE `TestModel`.`field` = 'gribe$@()lu'"; - $this->assertEqual($result, $expected); - - $conditions['NOT'] = array('Listing.expiration BETWEEN ? AND ?' => array("1", "100")); - $conditions[0]['OR'] = array( - "Listing.title LIKE" => "%term%", - "Listing.description LIKE" => "%term%" - ); - $conditions[1]['OR'] = array( - "Listing.title LIKE" => "%term_2%", - "Listing.description LIKE" => "%term_2%" - ); - $result = $this->testDb->conditions($conditions); - $expected = " WHERE NOT (`Listing`.`expiration` BETWEEN '1' AND '100') AND" . - " ((`Listing`.`title` LIKE '%term%') OR (`Listing`.`description` LIKE '%term%')) AND" . - " ((`Listing`.`title` LIKE '%term_2%') OR (`Listing`.`description` LIKE '%term_2%'))"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('MD5(CONCAT(Reg.email,Reg.id))' => 'blah')); - $expected = " WHERE MD5(CONCAT(`Reg`.`email`,`Reg`.`id`)) = 'blah'"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array( - 'MD5(CONCAT(Reg.email,Reg.id))' => array('blah', 'blahblah') - )); - $expected = " WHERE MD5(CONCAT(`Reg`.`email`,`Reg`.`id`)) IN ('blah', 'blahblah')"; - $this->assertEqual($result, $expected); - - $conditions = array('id' => array(2, 5, 6, 9, 12, 45, 78, 43, 76)); - $result = $this->testDb->conditions($conditions); - $expected = " WHERE id IN (2, 5, 6, 9, 12, 45, 78, 43, 76)"; - $this->assertEqual($result, $expected); - - $conditions = array('title' => 'user(s)'); - $result = $this->testDb->conditions($conditions); - $expected = " WHERE `title` = 'user(s)'"; - $this->assertEqual($result, $expected); - - $conditions = array('title' => 'user(s) data'); - $result = $this->testDb->conditions($conditions); - $expected = " WHERE `title` = 'user(s) data'"; - $this->assertEqual($result, $expected); - - $conditions = array('title' => 'user(s,arg) data'); - $result = $this->testDb->conditions($conditions); - $expected = " WHERE `title` = 'user(s,arg) data'"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array("Book.book_name" => 'Java(TM)')); - $expected = " WHERE `Book`.`book_name` = 'Java(TM)'"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array("Book.book_name" => 'Java(TM) ')); - $expected = " WHERE `Book`.`book_name` = 'Java(TM) '"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array("Book.id" => 0)); - $expected = " WHERE `Book`.`id` = 0"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array("Book.id" => NULL)); - $expected = " WHERE `Book`.`id` IS NULL"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('Listing.beds >=' => 0)); - $expected = " WHERE `Listing`.`beds` >= 0"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array( - 'ASCII(SUBSTRING(keyword, 1, 1)) BETWEEN ? AND ?' => array(65, 90) - )); - $expected = ' WHERE ASCII(SUBSTRING(keyword, 1, 1)) BETWEEN 65 AND 90'; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('or' => array( - '? BETWEEN Model.field1 AND Model.field2' => '2009-03-04' - ))); - $expected = " WHERE '2009-03-04' BETWEEN Model.field1 AND Model.field2"; - $this->assertEqual($result, $expected); - } - -/** - * testArrayConditionsParsingComplexKeys method - * - * @access public - * @return void - */ - function testArrayConditionsParsingComplexKeys() { - $result = $this->testDb->conditions(array( - 'CAST(Book.created AS DATE)' => '2008-08-02' - )); - $expected = " WHERE CAST(`Book`.`created` AS DATE) = '2008-08-02'"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array( - 'CAST(Book.created AS DATE) <=' => '2008-08-02' - )); - $expected = " WHERE CAST(`Book`.`created` AS DATE) <= '2008-08-02'"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array( - '(Stats.clicks * 100) / Stats.views >' => 50 - )); - $expected = " WHERE (`Stats`.`clicks` * 100) / `Stats`.`views` > 50"; - $this->assertEqual($result, $expected); - } - -/** - * testMixedConditionsParsing method - * - * @access public - * @return void - */ - function testMixedConditionsParsing() { - $conditions[] = 'User.first_name = \'Firstname\''; - $conditions[] = array('User.last_name' => 'Lastname'); - $result = $this->testDb->conditions($conditions); - $expected = " WHERE `User`.`first_name` = 'Firstname' AND `User`.`last_name` = 'Lastname'"; - $this->assertEqual($result, $expected); - - $conditions = array( - 'Thread.project_id' => 5, - 'Thread.buyer_id' => 14, - '1=1 GROUP BY Thread.project_id' - ); - $result = $this->testDb->conditions($conditions); - $this->assertPattern('/^\s*WHERE\s+`Thread`.`project_id`\s*=\s*5\s+AND\s+`Thread`.`buyer_id`\s*=\s*14\s+AND\s+1\s*=\s*1\s+GROUP BY `Thread`.`project_id`$/', $result); - } - -/** - * testConditionsOptionalArguments method - * - * @access public - * @return void - */ - function testConditionsOptionalArguments() { - $result = $this->testDb->conditions( array('Member.name' => 'Mariano'), true, false); - $this->assertPattern('/^\s*`Member`.`name`\s*=\s*\'Mariano\'\s*$/', $result); - - $result = $this->testDb->conditions( array(), true, false); - $this->assertPattern('/^\s*1\s*=\s*1\s*$/', $result); - } - -/** - * testConditionsWithModel - * - * @access public - * @return void - */ - function testConditionsWithModel() { - $this->Model = new Article2(); - - $result = $this->testDb->conditions(array('Article2.viewed >=' => 0), true, true, $this->Model); - $expected = " WHERE `Article2`.`viewed` >= 0"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('Article2.viewed >=' => '0'), true, true, $this->Model); - $expected = " WHERE `Article2`.`viewed` >= 0"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('Article2.viewed >=' => '1'), true, true, $this->Model); - $expected = " WHERE `Article2`.`viewed` >= 1"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('Article2.rate_sum BETWEEN ? AND ?' => array(0, 10)), true, true, $this->Model); - $expected = " WHERE `Article2`.`rate_sum` BETWEEN 0 AND 10"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('Article2.rate_sum BETWEEN ? AND ?' => array('0', '10')), true, true, $this->Model); - $expected = " WHERE `Article2`.`rate_sum` BETWEEN 0 AND 10"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->conditions(array('Article2.rate_sum BETWEEN ? AND ?' => array('1', '10')), true, true, $this->Model); - $expected = " WHERE `Article2`.`rate_sum` BETWEEN 1 AND 10"; - $this->assertEqual($result, $expected); - } - -/** - * testFieldParsing method - * - * @access public - * @return void - */ - function testFieldParsing() { - $result = $this->testDb->fields($this->Model, 'Vendor', "Vendor.id, COUNT(Model.vendor_id) AS `Vendor`.`count`"); - $expected = array('`Vendor`.`id`', 'COUNT(`Model`.`vendor_id`) AS `Vendor`.`count`'); - $this->assertEqual($result, $expected); - - $result = $this->testDb->fields($this->Model, 'Vendor', "`Vendor`.`id`, COUNT(`Model`.`vendor_id`) AS `Vendor`.`count`"); - $expected = array('`Vendor`.`id`', 'COUNT(`Model`.`vendor_id`) AS `Vendor`.`count`'); - $this->assertEqual($result, $expected); - - $result = $this->testDb->fields($this->Model, 'Post', "CONCAT(REPEAT(' ', COUNT(Parent.name) - 1), Node.name) AS name, Node.created"); - $expected = array("CONCAT(REPEAT(' ', COUNT(`Parent`.`name`) - 1), Node.name) AS name", "`Node`.`created`"); - $this->assertEqual($result, $expected); - - $result = $this->testDb->fields($this->Model, null, 'round( (3.55441 * fooField), 3 ) AS test'); - $this->assertEqual($result, array('round( (3.55441 * fooField), 3 ) AS test')); - - $result = $this->testDb->fields($this->Model, null, 'ROUND(`Rating`.`rate_total` / `Rating`.`rate_count`,2) AS rating'); - $this->assertEqual($result, array('ROUND(`Rating`.`rate_total` / `Rating`.`rate_count`,2) AS rating')); - - $result = $this->testDb->fields($this->Model, null, 'ROUND(Rating.rate_total / Rating.rate_count,2) AS rating'); - $this->assertEqual($result, array('ROUND(Rating.rate_total / Rating.rate_count,2) AS rating')); - - $result = $this->testDb->fields($this->Model, 'Post', "Node.created, CONCAT(REPEAT(' ', COUNT(Parent.name) - 1), Node.name) AS name"); - $expected = array("`Node`.`created`", "CONCAT(REPEAT(' ', COUNT(`Parent`.`name`) - 1), Node.name) AS name"); - $this->assertEqual($result, $expected); - - $result = $this->testDb->fields($this->Model, 'Post', "2.2,COUNT(*), SUM(Something.else) as sum, Node.created, CONCAT(REPEAT(' ', COUNT(Parent.name) - 1), Node.name) AS name,Post.title,Post.1,1.1"); - $expected = array( - '2.2', 'COUNT(*)', 'SUM(`Something`.`else`) as sum', '`Node`.`created`', - "CONCAT(REPEAT(' ', COUNT(`Parent`.`name`) - 1), Node.name) AS name", '`Post`.`title`', '`Post`.`1`', '1.1' - ); - $this->assertEqual($result, $expected); - - $result = $this->testDb->fields($this->Model, null, "(`Provider`.`star_total` / `Provider`.`total_ratings`) as `rating`"); - $expected = array("(`Provider`.`star_total` / `Provider`.`total_ratings`) as `rating`"); - $this->assertEqual($result, $expected); - - $result = $this->testDb->fields($this->Model, 'Post'); - $expected = array( - '`Post`.`id`', '`Post`.`client_id`', '`Post`.`name`', '`Post`.`login`', - '`Post`.`passwd`', '`Post`.`addr_1`', '`Post`.`addr_2`', '`Post`.`zip_code`', - '`Post`.`city`', '`Post`.`country`', '`Post`.`phone`', '`Post`.`fax`', - '`Post`.`url`', '`Post`.`email`', '`Post`.`comments`', '`Post`.`last_login`', - '`Post`.`created`', '`Post`.`updated`' - ); - $this->assertEqual($result, $expected); - - $result = $this->testDb->fields($this->Model, 'Other'); - $expected = array( - '`Other`.`id`', '`Other`.`client_id`', '`Other`.`name`', '`Other`.`login`', - '`Other`.`passwd`', '`Other`.`addr_1`', '`Other`.`addr_2`', '`Other`.`zip_code`', - '`Other`.`city`', '`Other`.`country`', '`Other`.`phone`', '`Other`.`fax`', - '`Other`.`url`', '`Other`.`email`', '`Other`.`comments`', '`Other`.`last_login`', - '`Other`.`created`', '`Other`.`updated`' - ); - $this->assertEqual($result, $expected); - - $result = $this->testDb->fields($this->Model, null, array(), false); - $expected = array('id', 'client_id', 'name', 'login', 'passwd', 'addr_1', 'addr_2', 'zip_code', 'city', 'country', 'phone', 'fax', 'url', 'email', 'comments', 'last_login', 'created', 'updated'); - $this->assertEqual($result, $expected); - - $result = $this->testDb->fields($this->Model, null, 'COUNT(*)'); - $expected = array('COUNT(*)'); - $this->assertEqual($result, $expected); - - $result = $this->testDb->fields($this->Model, null, 'SUM(Thread.unread_buyer) AS ' . $this->testDb->name('sum_unread_buyer')); - $expected = array('SUM(`Thread`.`unread_buyer`) AS `sum_unread_buyer`'); - $this->assertEqual($result, $expected); - - $result = $this->testDb->fields($this->Model, null, 'name, count(*)'); - $expected = array('`TestModel`.`name`', 'count(*)'); - $this->assertEqual($result, $expected); - - $result = $this->testDb->fields($this->Model, null, 'count(*), name'); - $expected = array('count(*)', '`TestModel`.`name`'); - $this->assertEqual($result, $expected); - - $result = $this->testDb->fields( - $this->Model, null, 'field1, field2, field3, count(*), name' - ); - $expected = array( - '`TestModel`.`field1`', '`TestModel`.`field2`', - '`TestModel`.`field3`', 'count(*)', '`TestModel`.`name`' - ); - $this->assertEqual($result, $expected); - - $result = $this->testDb->fields($this->Model, null, array('dayofyear(now())')); - $expected = array('dayofyear(now())'); - $this->assertEqual($result, $expected); - - $result = $this->testDb->fields($this->Model, null, array('MAX(Model.field) As Max')); - $expected = array('MAX(`Model`.`field`) As Max'); - $this->assertEqual($result, $expected); - - $result = $this->testDb->fields($this->Model, null, array('Model.field AS AnotherName')); - $expected = array('`Model`.`field` AS `AnotherName`'); - $this->assertEqual($result, $expected); - - $result = $this->testDb->fields($this->Model, null, array('field AS AnotherName')); - $expected = array('`field` AS `AnotherName`'); - $this->assertEqual($result, $expected); - - $result = $this->testDb->fields($this->Model, null, array( - 'TestModel.field AS AnotherName' - )); - $expected = array('`TestModel`.`field` AS `AnotherName`'); - $this->assertEqual($result, $expected); - - $result = $this->testDb->fields($this->Model, 'Foo', array( - 'id', 'title', '(user_count + discussion_count + post_count) AS score' - )); - $expected = array( - '`Foo`.`id`', - '`Foo`.`title`', - '(user_count + discussion_count + post_count) AS score' - ); - $this->assertEqual($result, $expected); - } - -/** - * test that fields() will accept objects made from DboSource::expression - * - * @return void - */ - function testFieldsWithExpression() { - $expression = $this->testDb->expression("CASE Sample.id WHEN 1 THEN 'Id One' ELSE 'Other Id' END AS case_col"); - $result = $this->testDb->fields($this->Model, null, array("id", $expression)); - $expected = array( - '`TestModel`.`id`', - "CASE Sample.id WHEN 1 THEN 'Id One' ELSE 'Other Id' END AS case_col" - ); - $this->assertEqual($result, $expected); - } /** * test that order() will accept objects made from DboSource::expression @@ -3273,96 +425,6 @@ class DboSourceTest extends CakeTestCase { $this->assertEqual($data, $expected); } -/** - * testRenderStatement method - * - * @access public - * @return void - */ - function testRenderStatement() { - $result = $this->testDb->renderStatement('select', array( - 'fields' => 'id', 'table' => 'table', 'conditions' => 'WHERE 1=1', - 'alias' => '', 'joins' => '', 'order' => '', 'limit' => '', 'group' => '' - )); - $this->assertPattern('/^\s*SELECT\s+id\s+FROM\s+table\s+WHERE\s+1=1\s*$/', $result); - - $result = $this->testDb->renderStatement('update', array('fields' => 'value=2', 'table' => 'table', 'conditions' => 'WHERE 1=1', 'alias' => '')); - $this->assertPattern('/^\s*UPDATE\s+table\s+SET\s+value=2\s+WHERE\s+1=1\s*$/', $result); - - $result = $this->testDb->renderStatement('update', array('fields' => 'value=2', 'table' => 'table', 'conditions' => 'WHERE 1=1', 'alias' => 'alias', 'joins' => '')); - $this->assertPattern('/^\s*UPDATE\s+table\s+AS\s+alias\s+SET\s+value=2\s+WHERE\s+1=1\s*$/', $result); - - $result = $this->testDb->renderStatement('delete', array('fields' => 'value=2', 'table' => 'table', 'conditions' => 'WHERE 1=1', 'alias' => '')); - $this->assertPattern('/^\s*DELETE\s+FROM\s+table\s+WHERE\s+1=1\s*$/', $result); - - $result = $this->testDb->renderStatement('delete', array('fields' => 'value=2', 'table' => 'table', 'conditions' => 'WHERE 1=1', 'alias' => 'alias', 'joins' => '')); - $this->assertPattern('/^\s*DELETE\s+alias\s+FROM\s+table\s+AS\s+alias\s+WHERE\s+1=1\s*$/', $result); - } - -/** - * testStatements method - * - * @access public - * @return void - */ - function testStatements() { - $this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'Attachment', 'ArticlesTag'); - $Article = new Article(); - - $result = $this->testDb->update($Article, array('field1'), array('value1')); - $this->assertFalse($result); - $result = $this->testDb->getLastQuery(); - $this->assertPattern('/^\s*UPDATE\s+' . $this->testDb->fullTableName('articles') . '\s+SET\s+`field1`\s*=\s*\'value1\'\s+WHERE\s+1 = 1\s*$/', $result); - - $result = $this->testDb->update($Article, array('field1'), array('2'), '2=2'); - $this->assertFalse($result); - $result = $this->testDb->getLastQuery(); - $this->assertPattern('/^\s*UPDATE\s+' . $this->testDb->fullTableName('articles') . ' AS `Article`\s+LEFT JOIN\s+' . $this->testDb->fullTableName('users') . ' AS `User` ON \(`Article`.`user_id` = `User`.`id`\)\s+SET\s+`Article`\.`field1`\s*=\s*2\s+WHERE\s+2\s*=\s*2\s*$/', $result); - - $result = $this->testDb->delete($Article); - $this->assertTrue($result); - $result = $this->testDb->getLastQuery(); - $this->assertPattern('/^\s*DELETE\s+FROM\s+' . $this->testDb->fullTableName('articles') . '\s+WHERE\s+1 = 1\s*$/', $result); - - $result = $this->testDb->delete($Article, true); - $this->assertTrue($result); - $result = $this->testDb->getLastQuery(); - $this->assertPattern('/^\s*DELETE\s+`Article`\s+FROM\s+' . $this->testDb->fullTableName('articles') . '\s+AS `Article`\s+LEFT JOIN\s+' . $this->testDb->fullTableName('users') . ' AS `User` ON \(`Article`.`user_id` = `User`.`id`\)\s+WHERE\s+1\s*=\s*1\s*$/', $result); - - $result = $this->testDb->delete($Article, '2=2'); - $this->assertTrue($result); - $result = $this->testDb->getLastQuery(); - $this->assertPattern('/^\s*DELETE\s+`Article`\s+FROM\s+' . $this->testDb->fullTableName('articles') . '\s+AS `Article`\s+LEFT JOIN\s+' . $this->testDb->fullTableName('users') . ' AS `User` ON \(`Article`.`user_id` = `User`.`id`\)\s+WHERE\s+2\s*=\s*2\s*$/', $result); - - $result = $this->testDb->hasAny($Article, '1=2'); - $this->assertFalse($result); - - $result = $this->testDb->insertMulti('articles', array('field'), array('(1)', '(2)')); - $this->assertNull($result); - $result = $this->testDb->getLastQuery(); - $this->assertPattern('/^\s*INSERT INTO\s+' . $this->testDb->fullTableName('articles') . '\s+\(`field`\)\s+VALUES\s+\(1\),\s*\(2\)\s*$/', $result); - } - -/** - * testSchema method - * - * @access public - * @return void - */ - function testSchema() { - $Schema = new CakeSchema(); - $Schema->tables = array('table' => array(), 'anotherTable' => array()); - - $this->expectError(); - $result = $this->testDb->dropSchema(null); - $this->assertTrue($result === null); - - $result = $this->testDb->dropSchema($Schema, 'non_existing'); - $this->assertTrue(empty($result)); - - $result = $this->testDb->dropSchema($Schema, 'table'); - $this->assertPattern('/^\s*DROP TABLE IF EXISTS\s+' . $this->testDb->fullTableName('table') . ';\s*$/s', $result); - } /** * testMagicMethodQuerying method @@ -3436,496 +498,6 @@ class DboSourceTest extends CakeTestCase { $this->assertFalse($result); } -/** - * testOrderParsing method - * - * @access public - * @return void - */ - function testOrderParsing() { - $result = $this->testDb->order("ADDTIME(Event.time_begin, '-06:00:00') ASC"); - $expected = " ORDER BY ADDTIME(`Event`.`time_begin`, '-06:00:00') ASC"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->order("title, id"); - $this->assertPattern('/^\s*ORDER BY\s+`title`\s+ASC,\s+`id`\s+ASC\s*$/', $result); - - $result = $this->testDb->order("title desc, id desc"); - $this->assertPattern('/^\s*ORDER BY\s+`title`\s+desc,\s+`id`\s+desc\s*$/', $result); - - $result = $this->testDb->order(array("title desc, id desc")); - $this->assertPattern('/^\s*ORDER BY\s+`title`\s+desc,\s+`id`\s+desc\s*$/', $result); - - $result = $this->testDb->order(array("title", "id")); - $this->assertPattern('/^\s*ORDER BY\s+`title`\s+ASC,\s+`id`\s+ASC\s*$/', $result); - - $result = $this->testDb->order(array(array('title'), array('id'))); - $this->assertPattern('/^\s*ORDER BY\s+`title`\s+ASC,\s+`id`\s+ASC\s*$/', $result); - - $result = $this->testDb->order(array("Post.title" => 'asc', "Post.id" => 'desc')); - $this->assertPattern('/^\s*ORDER BY\s+`Post`.`title`\s+asc,\s+`Post`.`id`\s+desc\s*$/', $result); - - $result = $this->testDb->order(array(array("Post.title" => 'asc', "Post.id" => 'desc'))); - $this->assertPattern('/^\s*ORDER BY\s+`Post`.`title`\s+asc,\s+`Post`.`id`\s+desc\s*$/', $result); - - $result = $this->testDb->order(array("title")); - $this->assertPattern('/^\s*ORDER BY\s+`title`\s+ASC\s*$/', $result); - - $result = $this->testDb->order(array(array("title"))); - $this->assertPattern('/^\s*ORDER BY\s+`title`\s+ASC\s*$/', $result); - - $result = $this->testDb->order("Dealer.id = 7 desc, Dealer.id = 3 desc, Dealer.title asc"); - $expected = " ORDER BY `Dealer`.`id` = 7 desc, `Dealer`.`id` = 3 desc, `Dealer`.`title` asc"; - $this->assertEqual($result, $expected); - - $result = $this->testDb->order(array("Page.name" => "='test' DESC")); - $this->assertPattern("/^\s*ORDER BY\s+`Page`\.`name`\s*='test'\s+DESC\s*$/", $result); - - $result = $this->testDb->order("Page.name = 'view' DESC"); - $this->assertPattern("/^\s*ORDER BY\s+`Page`\.`name`\s*=\s*'view'\s+DESC\s*$/", $result); - - $result = $this->testDb->order("(Post.views)"); - $this->assertPattern("/^\s*ORDER BY\s+\(`Post`\.`views`\)\s+ASC\s*$/", $result); - - $result = $this->testDb->order("(Post.views)*Post.views"); - $this->assertPattern("/^\s*ORDER BY\s+\(`Post`\.`views`\)\*`Post`\.`views`\s+ASC\s*$/", $result); - - $result = $this->testDb->order("(Post.views) * Post.views"); - $this->assertPattern("/^\s*ORDER BY\s+\(`Post`\.`views`\) \* `Post`\.`views`\s+ASC\s*$/", $result); - - $result = $this->testDb->order("(Model.field1 + Model.field2) * Model.field3"); - $this->assertPattern("/^\s*ORDER BY\s+\(`Model`\.`field1` \+ `Model`\.`field2`\) \* `Model`\.`field3`\s+ASC\s*$/", $result); - - $result = $this->testDb->order("Model.name+0 ASC"); - $this->assertPattern("/^\s*ORDER BY\s+`Model`\.`name`\+0\s+ASC\s*$/", $result); - - $result = $this->testDb->order("Anuncio.destaque & 2 DESC"); - $expected = ' ORDER BY `Anuncio`.`destaque` & 2 DESC'; - $this->assertEqual($result, $expected); - - $result = $this->testDb->order("3963.191 * id"); - $expected = ' ORDER BY 3963.191 * id ASC'; - $this->assertEqual($result, $expected); - - $result = $this->testDb->order(array('Property.sale_price IS NULL')); - $expected = ' ORDER BY `Property`.`sale_price` IS NULL ASC'; - $this->assertEqual($result, $expected); - } - -/** - * testComplexSortExpression method - * - * @return void - */ - public function testComplexSortExpression() { - $result = $this->testDb->order(array('(Model.field > 100) DESC', 'Model.field ASC')); - $this->assertPattern("/^\s*ORDER BY\s+\(`Model`\.`field`\s+>\s+100\)\s+DESC,\s+`Model`\.`field`\s+ASC\s*$/", $result); - } - -/** - * testCalculations method - * - * @access public - * @return void - */ - function testCalculations() { - $result = $this->testDb->calculate($this->Model, 'count'); - $this->assertEqual($result, 'COUNT(*) AS `count`'); - - $result = $this->testDb->calculate($this->Model, 'count', array('id')); - $this->assertEqual($result, 'COUNT(`id`) AS `count`'); - - $result = $this->testDb->calculate( - $this->Model, - 'count', - array($this->testDb->expression('DISTINCT id')) - ); - $this->assertEqual($result, 'COUNT(DISTINCT id) AS `count`'); - - $result = $this->testDb->calculate($this->Model, 'count', array('id', 'id_count')); - $this->assertEqual($result, 'COUNT(`id`) AS `id_count`'); - - $result = $this->testDb->calculate($this->Model, 'count', array('Model.id', 'id_count')); - $this->assertEqual($result, 'COUNT(`Model`.`id`) AS `id_count`'); - - $result = $this->testDb->calculate($this->Model, 'max', array('id')); - $this->assertEqual($result, 'MAX(`id`) AS `id`'); - - $result = $this->testDb->calculate($this->Model, 'max', array('Model.id', 'id')); - $this->assertEqual($result, 'MAX(`Model`.`id`) AS `id`'); - - $result = $this->testDb->calculate($this->Model, 'max', array('`Model`.`id`', 'id')); - $this->assertEqual($result, 'MAX(`Model`.`id`) AS `id`'); - - $result = $this->testDb->calculate($this->Model, 'min', array('`Model`.`id`', 'id')); - $this->assertEqual($result, 'MIN(`Model`.`id`) AS `id`'); - - $result = $this->testDb->calculate($this->Model, 'min', 'left'); - $this->assertEqual($result, 'MIN(`left`) AS `left`'); - } - -/** - * testLength method - * - * @access public - * @return void - */ - function testLength() { - $result = $this->testDb->length('varchar(255)'); - $expected = 255; - $this->assertIdentical($result, $expected); - - $result = $this->testDb->length('int(11)'); - $expected = 11; - $this->assertIdentical($result, $expected); - - $result = $this->testDb->length('float(5,3)'); - $expected = '5,3'; - $this->assertIdentical($result, $expected); - - $result = $this->testDb->length('decimal(5,2)'); - $expected = '5,2'; - $this->assertIdentical($result, $expected); - - $result = $this->testDb->length("enum('test','me','now')"); - $expected = 4; - $this->assertIdentical($result, $expected); - - $result = $this->testDb->length("set('a','b','cd')"); - $expected = 2; - $this->assertIdentical($result, $expected); - - $this->expectError(); - $result = $this->testDb->length(false); - $this->assertTrue($result === null); - - $result = $this->testDb->length('datetime'); - $expected = null; - $this->assertIdentical($result, $expected); - - $result = $this->testDb->length('text'); - $expected = null; - $this->assertIdentical($result, $expected); - } - -/** - * testBuildIndex method - * - * @access public - * @return void - */ - function testBuildIndex() { - $data = array( - 'PRIMARY' => array('column' => 'id') - ); - $result = $this->testDb->buildIndex($data); - $expected = array('PRIMARY KEY (`id`)'); - $this->assertIdentical($result, $expected); - - $data = array( - 'MyIndex' => array('column' => 'id', 'unique' => true) - ); - $result = $this->testDb->buildIndex($data); - $expected = array('UNIQUE KEY `MyIndex` (`id`)'); - $this->assertEqual($result, $expected); - - $data = array( - 'MyIndex' => array('column' => array('id', 'name'), 'unique' => true) - ); - $result = $this->testDb->buildIndex($data); - $expected = array('UNIQUE KEY `MyIndex` (`id`, `name`)'); - $this->assertEqual($result, $expected); - } - -/** - * testBuildColumn method - * - * @access public - * @return void - */ - function testBuildColumn() { - $this->expectError(); - $data = array( - 'name' => 'testName', - 'type' => 'varchar(255)', - 'default', - 'null' => true, - 'key' - ); - $this->testDb->buildColumn($data); - - $data = array( - 'name' => 'testName', - 'type' => 'string', - 'length' => 255, - 'default', - 'null' => true, - 'key' - ); - $result = $this->testDb->buildColumn($data); - $expected = '`testName` varchar(255) DEFAULT NULL'; - $this->assertEqual($result, $expected); - - $data = array( - 'name' => 'int_field', - 'type' => 'integer', - 'default' => '', - 'null' => false, - ); - $restore = $this->testDb->columns; - - $this->testDb->columns = array('integer' => array('name' => 'int', 'limit' => '11', 'formatter' => 'intval'), ); - $result = $this->testDb->buildColumn($data); - $expected = '`int_field` int(11) NOT NULL'; - $this->assertEqual($result, $expected); - - $this->testDb->fieldParameters['param'] = array( - 'value' => 'COLLATE', - 'quote' => false, - 'join' => ' ', - 'column' => 'Collate', - 'position' => 'beforeDefault', - 'options' => array('GOOD', 'OK') - ); - $data = array( - 'name' => 'int_field', - 'type' => 'integer', - 'default' => '', - 'null' => false, - 'param' => 'BAD' - ); - $result = $this->testDb->buildColumn($data); - $expected = '`int_field` int(11) NOT NULL'; - $this->assertEqual($result, $expected); - - $data = array( - 'name' => 'int_field', - 'type' => 'integer', - 'default' => '', - 'null' => false, - 'param' => 'GOOD' - ); - $result = $this->testDb->buildColumn($data); - $expected = '`int_field` int(11) COLLATE GOOD NOT NULL'; - $this->assertEqual($result, $expected); - - $this->testDb->columns = $restore; - - $data = array( - 'name' => 'created', - 'type' => 'timestamp', - 'default' => 'current_timestamp', - 'null' => false, - ); - $result = $this->db->buildColumn($data); - $expected = '`created` timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL'; - $this->assertEqual($result, $expected); - - $data = array( - 'name' => 'created', - 'type' => 'timestamp', - 'default' => 'CURRENT_TIMESTAMP', - 'null' => true, - ); - $result = $this->db->buildColumn($data); - $expected = '`created` timestamp DEFAULT CURRENT_TIMESTAMP'; - $this->assertEqual($result, $expected); - - $data = array( - 'name' => 'modified', - 'type' => 'timestamp', - 'null' => true, - ); - $result = $this->db->buildColumn($data); - $expected = '`modified` timestamp NULL'; - $this->assertEqual($result, $expected); - - $data = array( - 'name' => 'modified', - 'type' => 'timestamp', - 'default' => null, - 'null' => true, - ); - $result = $this->db->buildColumn($data); - $expected = '`modified` timestamp NULL'; - $this->assertEqual($result, $expected); - } - -/** - * test hasAny() - * - * @return void - */ - function testHasAny() { - $this->testDb->hasAny($this->Model, array()); - $expected = 'SELECT COUNT(`TestModel`.`id`) AS count FROM `test_models` AS `TestModel` WHERE 1 = 1'; - $this->assertEqual(end($this->testDb->simulated), $expected); - - $this->testDb->hasAny($this->Model, array('TestModel.name' => 'harry')); - $expected = "SELECT COUNT(`TestModel`.`id`) AS count FROM `test_models` AS `TestModel` WHERE `TestModel`.`name` = 'harry'"; - $this->assertEqual(end($this->testDb->simulated), $expected); - } - -/** - * testIntrospectType method - * - * @access public - * @return void - */ - function testIntrospectType() { - $this->assertEqual($this->testDb->introspectType(0), 'integer'); - $this->assertEqual($this->testDb->introspectType(2), 'integer'); - $this->assertEqual($this->testDb->introspectType('2'), 'string'); - $this->assertEqual($this->testDb->introspectType('2.2'), 'string'); - $this->assertEqual($this->testDb->introspectType(2.2), 'float'); - $this->assertEqual($this->testDb->introspectType('stringme'), 'string'); - $this->assertEqual($this->testDb->introspectType('0stringme'), 'string'); - - $data = array(2.2); - $this->assertEqual($this->testDb->introspectType($data), 'float'); - - $data = array('2.2'); - $this->assertEqual($this->testDb->introspectType($data), 'float'); - - $data = array(2); - $this->assertEqual($this->testDb->introspectType($data), 'integer'); - - $data = array('2'); - $this->assertEqual($this->testDb->introspectType($data), 'integer'); - - $data = array('string'); - $this->assertEqual($this->testDb->introspectType($data), 'string'); - - $data = array(2.2, '2.2'); - $this->assertEqual($this->testDb->introspectType($data), 'float'); - - $data = array(2, '2'); - $this->assertEqual($this->testDb->introspectType($data), 'integer'); - - $data = array('string one', 'string two'); - $this->assertEqual($this->testDb->introspectType($data), 'string'); - - $data = array('2.2', 3); - $this->assertEqual($this->testDb->introspectType($data), 'integer'); - - $data = array('2.2', '0stringme'); - $this->assertEqual($this->testDb->introspectType($data), 'string'); - - $data = array(2.2, 3); - $this->assertEqual($this->testDb->introspectType($data), 'integer'); - - $data = array(2.2, '0stringme'); - $this->assertEqual($this->testDb->introspectType($data), 'string'); - - $data = array(2, 'stringme'); - $this->assertEqual($this->testDb->introspectType($data), 'string'); - - $data = array(2, '2.2', 'stringgme'); - $this->assertEqual($this->testDb->introspectType($data), 'string'); - - $data = array(2, '2.2'); - $this->assertEqual($this->testDb->introspectType($data), 'integer'); - - $data = array(2, 2.2); - $this->assertEqual($this->testDb->introspectType($data), 'integer'); - - - // NULL - $result = $this->testDb->value(null, 'boolean'); - $this->assertEqual($result, 'NULL'); - - // EMPTY STRING - $result = $this->testDb->value('', 'boolean'); - $this->assertEqual($result, 0); - - - // BOOLEAN - $result = $this->testDb->value('true', 'boolean'); - $this->assertEqual($result, 1); - - $result = $this->testDb->value('false', 'boolean'); - $this->assertEqual($result, 1); - - $result = $this->testDb->value(true, 'boolean'); - $this->assertEqual($result, 1); - - $result = $this->testDb->value(false, 'boolean'); - $this->assertEqual($result, 0); - - $result = $this->testDb->value(1, 'boolean'); - $this->assertEqual($result, 1); - - $result = $this->testDb->value(0, 'boolean'); - $this->assertEqual($result, 0); - - $result = $this->testDb->value('abc', 'boolean'); - $this->assertEqual($result, 1); - - $result = $this->testDb->value(1.234, 'boolean'); - $this->assertEqual($result, 1); - - $result = $this->testDb->value('1.234e05', 'boolean'); - $this->assertEqual($result, 1); - - // NUMBERS - $result = $this->testDb->value(123, 'integer'); - $this->assertEqual($result, 123); - - $result = $this->testDb->value('123', 'integer'); - $this->assertEqual($result, '123'); - - $result = $this->testDb->value('0123', 'integer'); - $this->assertEqual($result, "'0123'"); - - $result = $this->testDb->value('0x123ABC', 'integer'); - $this->assertEqual($result, "'0x123ABC'"); - - $result = $this->testDb->value('0x123', 'integer'); - $this->assertEqual($result, "'0x123'"); - - $result = $this->testDb->value(1.234, 'float'); - $this->assertEqual($result, 1.234); - - $result = $this->testDb->value('1.234', 'float'); - $this->assertEqual($result, '1.234'); - - $result = $this->testDb->value(' 1.234 ', 'float'); - $this->assertEqual($result, "' 1.234 '"); - - $result = $this->testDb->value('1.234e05', 'float'); - $this->assertEqual($result, "'1.234e05'"); - - $result = $this->testDb->value('1.234e+5', 'float'); - $this->assertEqual($result, "'1.234e+5'"); - - $result = $this->testDb->value('1,234', 'float'); - $this->assertEqual($result, "'1,234'"); - - $result = $this->testDb->value('FFF', 'integer'); - $this->assertEqual($result, "'FFF'"); - - $result = $this->testDb->value('abc', 'integer'); - $this->assertEqual($result, "'abc'"); - - // STRINGS - $result = $this->testDb->value('123', 'string'); - $this->assertEqual($result, "'123'"); - - $result = $this->testDb->value(123, 'string'); - $this->assertEqual($result, "'123'"); - - $result = $this->testDb->value(1.234, 'string'); - $this->assertEqual($result, "'1.234'"); - - $result = $this->testDb->value('abc', 'string'); - $this->assertEqual($result, "'abc'"); - - $result = $this->testDb->value(' abc ', 'string'); - $this->assertEqual($result, "' abc '"); - - $result = $this->testDb->value('a bc', 'string'); - $this->assertEqual($result, "'a bc'"); - } /** * testValue method @@ -3954,76 +526,6 @@ class DboSourceTest extends CakeTestCase { $this->assertEqual($this->testDb->config['prefix'], 'foo'); } -/** - * testRealQueries method - * - * @access public - * @return void - */ - function testRealQueries() { - $this->loadFixtures('Apple', 'Article', 'User', 'Comment', 'Tag', 'Sample'); - - $Apple = ClassRegistry::init('Apple'); - $Article = ClassRegistry::init('Article'); - - $result = $this->db->rawQuery('SELECT color, name FROM ' . $this->db->fullTableName('apples')); - $this->assertTrue(!empty($result)); - - $result = $this->db->fetchRow($result); - $expected = array($this->db->fullTableName('apples', false) => array( - 'color' => 'Red 1', - 'name' => 'Red Apple 1' - )); - $this->assertEqual($result, $expected); - - $result = $this->db->fetchAll('SELECT name FROM ' . $this->testDb->fullTableName('apples') . ' ORDER BY id'); - $expected = array( - array($this->db->fullTableName('apples', false) => array('name' => 'Red Apple 1')), - array($this->db->fullTableName('apples', false) => array('name' => 'Bright Red Apple')), - array($this->db->fullTableName('apples', false) => array('name' => 'green blue')), - array($this->db->fullTableName('apples', false) => array('name' => 'Test Name')), - array($this->db->fullTableName('apples', false) => array('name' => 'Blue Green')), - array($this->db->fullTableName('apples', false) => array('name' => 'My new apple')), - array($this->db->fullTableName('apples', false) => array('name' => 'Some odd color')) - ); - $this->assertEqual($result, $expected); - - $result = $this->db->field($this->testDb->fullTableName('apples', false), 'SELECT color, name FROM ' . $this->testDb->fullTableName('apples') . ' ORDER BY id'); - $expected = array( - 'color' => 'Red 1', - 'name' => 'Red Apple 1' - ); - $this->assertEqual($result, $expected); - - $Apple->unbindModel(array(), false); - $result = $this->db->read($Apple, array( - 'fields' => array($Apple->escapeField('name')), - 'conditions' => null, - 'recursive' => -1 - )); - $expected = array( - array('Apple' => array('name' => 'Red Apple 1')), - array('Apple' => array('name' => 'Bright Red Apple')), - array('Apple' => array('name' => 'green blue')), - array('Apple' => array('name' => 'Test Name')), - array('Apple' => array('name' => 'Blue Green')), - array('Apple' => array('name' => 'My new apple')), - array('Apple' => array('name' => 'Some odd color')) - ); - $this->assertEqual($result, $expected); - - $result = $this->db->read($Article, array( - 'fields' => array('id', 'user_id', 'title'), - 'conditions' => null, - 'recursive' => 1 - )); - - $this->assertTrue(Set::matches('/Article[id=1]', $result)); - $this->assertTrue(Set::matches('/Comment[id=1]', $result)); - $this->assertTrue(Set::matches('/Comment[id=2]', $result)); - $this->assertFalse(Set::matches('/Comment[id=10]', $result)); - } - /** * testName method * @@ -4074,6 +576,10 @@ class DboSourceTest extends CakeTestCase { $result = $this->testDb->name(array('my-name', 'Foo-Model.*')); $expected = array('`my-name`', '`Foo-Model`.*'); $this->assertEqual($result, $expected); + + $result = $this->testDb->name(array('Team.P%', 'Team.G/G')); + $expected = array('`Team`.`P%`', '`Team`.`G/G`'); + $this->assertEqual($result, $expected); } /** @@ -4189,26 +695,6 @@ class DboSourceTest extends CakeTestCase { $this->assertEqual($log['log'][2], $expected); } -/** - * test that execute runs queries. - * - * @return void - */ - function testExecute() { - $query = 'SELECT * FROM ' . $this->testDb->fullTableName('articles') . ' WHERE 1 = 1'; - $this->db->took = null; - $this->db->affected = null; - $result = $this->db->execute($query, array('stats' => false)); - $this->assertNotNull($result, 'No query performed! %s'); - $this->assertNull($this->db->took, 'Stats were set %s'); - $this->assertNull($this->db->affected, 'Stats were set %s'); - - $result = $this->db->execute($query); - $this->assertNotNull($result, 'No query performed! %s'); - $this->assertNotNull($this->db->took, 'Stats were not set %s'); - $this->assertNotNull($this->db->affected, 'Stats were not set %s'); - } - /** * test that query() returns boolean values from operations like CREATE TABLE * @@ -4218,11 +704,11 @@ class DboSourceTest extends CakeTestCase { $name = $this->db->fullTableName('test_query'); $query = "CREATE TABLE {$name} (name varchar(10));"; $result = $this->db->query($query); - $this->assertTrue($result, 'Query did not return a boolean. %s'); + $this->assertTrue($result, 'Query did not return a boolean'); $query = "DROP TABLE {$name};"; - $result = $this->db->fetchAll($query); - $this->assertTrue($result, 'Query did not return a boolean. %s'); + $result = $this->db->query($query); + $this->assertTrue($result, 'Query did not return a boolean'); } /** @@ -4241,140 +727,13 @@ class DboSourceTest extends CakeTestCase { $this->assertPattern('/Took:/s', $contents); } -/** - * test fields generating usable virtual fields to use in query - * - * @return void - */ - function testVirtualFields() { - $this->loadFixtures('Article'); - - $Article = ClassRegistry::init('Article'); - $Article->virtualFields = array( - 'this_moment' => 'NOW()', - 'two' => '1 + 1', - 'comment_count' => 'SELECT COUNT(*) FROM ' . $this->db->fullTableName('comments') . - ' WHERE Article.id = ' . $this->db->fullTableName('comments') . '.article_id' - ); - $result = $this->db->fields($Article); - $expected = array( - '`Article`.`id`', - '`Article`.`user_id`', - '`Article`.`title`', - '`Article`.`body`', - '`Article`.`published`', - '`Article`.`created`', - '`Article`.`updated`', - '(NOW()) AS `Article__this_moment`', - '(1 + 1) AS `Article__two`', - '(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) AS `Article__comment_count`' - ); - $this->assertEqual($expected, $result); - - $result = $this->db->fields($Article, null, array('this_moment', 'title')); - $expected = array( - '`Article`.`title`', - '(NOW()) AS `Article__this_moment`', - ); - $this->assertEqual($expected, $result); - - $result = $this->db->fields($Article, null, array('Article.title', 'Article.this_moment')); - $expected = array( - '`Article`.`title`', - '(NOW()) AS `Article__this_moment`', - ); - $this->assertEqual($expected, $result); - - $result = $this->db->fields($Article, null, array('Article.this_moment', 'Article.title')); - $expected = array( - '`Article`.`title`', - '(NOW()) AS `Article__this_moment`', - ); - $this->assertEqual($expected, $result); - - $result = $this->db->fields($Article, null, array('Article.*')); - $expected = array( - '`Article`.*', - '(NOW()) AS `Article__this_moment`', - '(1 + 1) AS `Article__two`', - '(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) AS `Article__comment_count`' - ); - $this->assertEqual($expected, $result); - - $result = $this->db->fields($Article, null, array('*')); - $expected = array( - '*', - '(NOW()) AS `Article__this_moment`', - '(1 + 1) AS `Article__two`', - '(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) AS `Article__comment_count`' - ); - $this->assertEqual($expected, $result); - } - -/** - * test conditions to generate query conditions for virtual fields - * - * @return void - */ - function testVirtualFieldsInConditions() { - $Article =& ClassRegistry::init('Article'); - $Article->virtualFields = array( - 'this_moment' => 'NOW()', - 'two' => '1 + 1', - 'comment_count' => 'SELECT COUNT(*) FROM ' . $this->db->fullTableName('comments') . - ' WHERE Article.id = ' . $this->db->fullTableName('comments') . '.article_id' - ); - $conditions = array('two' => 2); - $result = $this->db->conditions($conditions, true, false, $Article); - $expected = '(1 + 1) = 2'; - $this->assertEqual($expected, $result); - - $conditions = array('this_moment BETWEEN ? AND ?' => array(1,2)); - $expected = 'NOW() BETWEEN 1 AND 2'; - $result = $this->db->conditions($conditions, true, false, $Article); - $this->assertEqual($expected, $result); - - $conditions = array('comment_count >' => 5); - $expected = '(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) > 5'; - $result = $this->db->conditions($conditions, true, false, $Article); - $this->assertEqual($expected, $result); - - $conditions = array('NOT' => array('two' => 2)); - $result = $this->db->conditions($conditions, true, false, $Article); - $expected = 'NOT ((1 + 1) = 2)'; - $this->assertEqual($expected, $result); - } - -/** - * test that virtualFields with complex functions and aliases work. - * - * @return void - */ - function testConditionsWithComplexVirtualFields() { - $Article =& ClassRegistry::init('Article'); - $Article->virtualFields = array( - 'distance' => 'ACOS(SIN(20 * PI() / 180) - * SIN(Article.latitude * PI() / 180) - + COS(20 * PI() / 180) - * COS(Article.latitude * PI() / 180) - * COS((50 - Article.longitude) * PI() / 180) - ) * 180 / PI() * 60 * 1.1515 * 1.609344' - ); - $conditions = array('distance >=' => 20); - $result = $this->db->conditions($conditions, true, true, $Article); - - $this->assertPattern('/\) >= 20/', $result); - $this->assertPattern('/[`\'"]Article[`\'"].[`\'"]latitude[`\'"]/', $result); - $this->assertPattern('/[`\'"]Article[`\'"].[`\'"]longitude[`\'"]/', $result); - } - /** * test order to generate query order clause for virtual fields * * @return void */ function testVirtualFieldsInOrder() { - $Article =& ClassRegistry::init('Article'); + $Article = ClassRegistry::init('Article'); $Article->virtualFields = array( 'this_moment' => 'NOW()', 'two' => '1 + 1', @@ -4390,147 +749,7 @@ class DboSourceTest extends CakeTestCase { $this->assertEqual($expected, $result); } -/** - * test calculate to generate claculate statements on virtual fields - * - * @return void - */ - function testVirtualFieldsInCalculate() { - $Article =& ClassRegistry::init('Article'); - $Article->virtualFields = array( - 'this_moment' => 'NOW()', - 'two' => '1 + 1', - 'comment_count' => 'SELECT COUNT(*) FROM ' . $this->db->fullTableName('comments') . - ' WHERE Article.id = ' . $this->db->fullTableName('comments'). '.article_id' - ); - $result = $this->db->calculate($Article, 'count', array('this_moment')); - $expected = 'COUNT(NOW()) AS `count`'; - $this->assertEqual($expected, $result); - - $result = $this->db->calculate($Article, 'max', array('comment_count')); - $expected = 'MAX(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) AS `comment_count`'; - $this->assertEqual($expected, $result); - } - -/** - * test a full example of using virtual fields - * - * @return void - */ - function testVirtualFieldsFetch() { - $this->loadFixtures('Article', 'Comment'); - - $Article = ClassRegistry::init('Article'); - $Article->virtualFields = array( - 'comment_count' => 'SELECT COUNT(*) FROM ' . $this->db->fullTableName('comments') . - ' WHERE Article.id = ' . $this->db->fullTableName('comments') . '.article_id' - ); - - $conditions = array('comment_count >' => 2); - $query = 'SELECT ' . join(',',$this->db->fields($Article, null, array('id', 'comment_count'))) . - ' FROM ' . $this->db->fullTableName($Article) . ' Article ' . $this->db->conditions($conditions, true, true, $Article); - $result = $this->db->fetchAll($query); - $expected = array(array( - 'Article' => array('id' => 1, 'comment_count' => 4) - )); - $this->assertEqual($expected, $result); - } - -/** - * test reading complex virtualFields with subqueries. - * - * @return void - */ - function testVirtualFieldsComplexRead() { - $this->loadFixtures('DataTest', 'Article', 'Comment'); - - $Article =& ClassRegistry::init('Article'); - $commentTable = $this->db->fullTableName('comments'); - $Article =& ClassRegistry::init('Article'); - $Article->virtualFields = array( - 'comment_count' => 'SELECT COUNT(*) FROM ' . $commentTable . - ' AS Comment WHERE Article.id = Comment.article_id' - ); - $result = $Article->find('all'); - $this->assertTrue(count($result) > 0); - $this->assertTrue($result[0]['Article']['comment_count'] > 0); - - $DataTest =& ClassRegistry::init('DataTest'); - $DataTest->virtualFields = array( - 'complicated' => 'ACOS(SIN(20 * PI() / 180) - * SIN(DataTest.float * PI() / 180) - + COS(20 * PI() / 180) - * COS(DataTest.count * PI() / 180) - * COS((50 - DataTest.float) * PI() / 180) - ) * 180 / PI() * 60 * 1.1515 * 1.609344' - ); - $result = $DataTest->find('all'); - $this->assertTrue(count($result) > 0); - $this->assertTrue($result[0]['DataTest']['complicated'] > 0); - } - -/** - * test that virtualFields with complex functions and aliases work. - * - * @return void - */ - function testFieldsWithComplexVirtualFields() { - $Article = new Article(); - $Article->virtualFields = array( - 'distance' => 'ACOS(SIN(20 * PI() / 180) - * SIN(Article.latitude * PI() / 180) - + COS(20 * PI() / 180) - * COS(Article.latitude * PI() / 180) - * COS((50 - Article.longitude) * PI() / 180) - ) * 180 / PI() * 60 * 1.1515 * 1.609344' - ); - - $fields = array('id', 'distance'); - $result = $this->db->fields($Article, null, $fields); - $qs = $this->db->startQuote; - $qe = $this->db->endQuote; - - $this->assertEqual($result[0], "{$qs}Article{$qe}.{$qs}id{$qe}"); - $this->assertPattern('/Article__distance/', $result[1]); - $this->assertPattern('/[`\'"]Article[`\'"].[`\'"]latitude[`\'"]/', $result[1]); - $this->assertPattern('/[`\'"]Article[`\'"].[`\'"]longitude[`\'"]/', $result[1]); - } - -/** - * test reading virtual fields containing newlines when recursive > 0 - * - * @return void - */ - function testReadVirtualFieldsWithNewLines() { - $Article = new Article(); - $Article->recursive = 1; - $Article->virtualFields = array( - 'test' => ' - User.id + User.id - ' - ); - $result = $this->db->fields($Article, null, array()); - $result = $this->db->fields($Article, $Article->alias, $result); - $this->assertPattern('/[`\"]User[`\"]\.[`\"]id[`\"] \+ [`\"]User[`\"]\.[`\"]id[`\"]/', $result[7]); - } - -/** - * test group to generate GROUP BY statements on virtual fields - * - * @return void - */ - function testVirtualFieldsInGroup() { - $Article =& ClassRegistry::init('Article'); - $Article->virtualFields = array( - 'this_year' => 'YEAR(Article.created)' - ); - - $result = $this->db->group('this_year', $Article); - - $expected = " GROUP BY (YEAR(`Article`.`created`))"; - $this->assertEqual($expected, $result); - } /** * test the permutations of fullTableName() @@ -4538,7 +757,7 @@ class DboSourceTest extends CakeTestCase { * @return void */ function testFullTablePermutations() { - $Article =& ClassRegistry::init('Article'); + $Article = ClassRegistry::init('Article'); $result = $this->testDb->fullTableName($Article, false); $this->assertEqual($result, 'articles'); @@ -4558,10 +777,11 @@ class DboSourceTest extends CakeTestCase { * @return void */ function testReadOnlyCallingQueryAssociationWhenDefined() { + $this->loadFixtures('Article', 'User', 'ArticlesTag', 'Tag'); ConnectionManager::create('test_no_queryAssociation', array( 'datasource' => 'data' )); - $Article =& ClassRegistry::init('Article'); + $Article = ClassRegistry::init('Article'); $Article->Comment->useDbConfig = 'test_no_queryAssociation'; $result = $Article->find('all'); $this->assertTrue(is_array($result)); @@ -4576,8 +796,48 @@ class DboSourceTest extends CakeTestCase { $this->testDb->cacheMethods = false; $this->assertTrue(empty($this->testDb->methodCache['fields']), 'Cache not empty'); - $Article =& ClassRegistry::init('Article'); + $Article = ClassRegistry::init('Article'); $this->testDb->fields($Article, null, array('title', 'body', 'published')); $this->assertTrue(empty($this->testDb->methodCache['fields']), 'Cache not empty'); } + +/** + * testStatements method + * + * @access public + * @return void + */ + function testStatements() { + $this->skipIf(!$this->testDb instanceof DboMysql); + $this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'Attachment', 'ArticlesTag'); + $Article = new Article(); + + $result = $this->testDb->update($Article, array('field1'), array('value1')); + $this->assertFalse($result); + $result = $this->testDb->getLastQuery(); + $this->assertPattern('/^\s*UPDATE\s+' . $this->testDb->fullTableName('articles') . '\s+SET\s+`field1`\s*=\s*\'value1\'\s+WHERE\s+1 = 1\s*$/', $result); + + $result = $this->testDb->update($Article, array('field1'), array('2'), '2=2'); + $this->assertFalse($result); + $result = $this->testDb->getLastQuery(); + $this->assertPattern('/^\s*UPDATE\s+' . $this->testDb->fullTableName('articles') . ' AS `Article`\s+LEFT JOIN\s+' . $this->testDb->fullTableName('users') . ' AS `User` ON \(`Article`.`user_id` = `User`.`id`\)\s+SET\s+`Article`\.`field1`\s*=\s*2\s+WHERE\s+2\s*=\s*2\s*$/', $result); + + $result = $this->testDb->delete($Article); + $this->assertTrue($result); + $result = $this->testDb->getLastQuery(); + $this->assertPattern('/^\s*DELETE\s+FROM\s+' . $this->testDb->fullTableName('articles') . '\s+WHERE\s+1 = 1\s*$/', $result); + + $result = $this->testDb->delete($Article, true); + $this->assertTrue($result); + $result = $this->testDb->getLastQuery(); + $this->assertPattern('/^\s*DELETE\s+`Article`\s+FROM\s+' . $this->testDb->fullTableName('articles') . '\s+AS `Article`\s+LEFT JOIN\s+' . $this->testDb->fullTableName('users') . ' AS `User` ON \(`Article`.`user_id` = `User`.`id`\)\s+WHERE\s+1\s*=\s*1\s*$/', $result); + + $result = $this->testDb->delete($Article, '2=2'); + $this->assertTrue($result); + $result = $this->testDb->getLastQuery(); + $this->assertPattern('/^\s*DELETE\s+`Article`\s+FROM\s+' . $this->testDb->fullTableName('articles') . '\s+AS `Article`\s+LEFT JOIN\s+' . $this->testDb->fullTableName('users') . ' AS `User` ON \(`Article`.`user_id` = `User`.`id`\)\s+WHERE\s+2\s*=\s*2\s*$/', $result); + + $result = $this->testDb->hasAny($Article, '1=2'); + $this->assertFalse($result); + } } diff --git a/cake/tests/cases/libs/model/db_acl.test.php b/cake/tests/cases/libs/model/db_acl.test.php index fb0a9f3f3..537f2f361 100644 --- a/cake/tests/cases/libs/model/db_acl.test.php +++ b/cake/tests/cases/libs/model/db_acl.test.php @@ -12,8 +12,7 @@ * * @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.controller.components.dbacl.models + * @package cake.tests.cases.libs.controller.components.dbacl.models * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ App::import('Core', 'db_acl'); /** * DB ACL wrapper test class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class DbAclNodeTestBase extends AclNode { @@ -48,8 +46,7 @@ class DbAclNodeTestBase extends AclNode { /** * Aro Test Wrapper * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class DbAroTest extends DbAclNodeTestBase { @@ -81,8 +78,7 @@ class DbAroTest extends DbAclNodeTestBase { /** * Aco Test Wrapper * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class DbAcoTest extends DbAclNodeTestBase { @@ -114,8 +110,7 @@ class DbAcoTest extends DbAclNodeTestBase { /** * Permission Test Wrapper * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class DbPermissionTest extends CakeTestModel { @@ -155,8 +150,7 @@ class DbPermissionTest extends CakeTestModel { /** * DboActionTest class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class DbAcoActionTest extends CakeTestModel { @@ -188,8 +182,7 @@ class DbAcoActionTest extends CakeTestModel { /** * DbAroUserTest class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class DbAroUserTest extends CakeTestModel { @@ -227,8 +220,7 @@ class DbAroUserTest extends CakeTestModel { /** * TestDbAcl class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components + * @package cake.tests.cases.libs.controller.components */ class TestDbAcl extends DbAcl { @@ -249,8 +241,7 @@ class TestDbAcl extends DbAcl { /** * AclNodeTest class * - * @package cake - * @subpackage cake.tests.cases.libs.controller.components.dbacl.models + * @package cake.tests.cases.libs.controller.components.dbacl.models */ class AclNodeTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 9809b3a0d..3fa31afd6 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -12,8 +12,7 @@ * * @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.model + * @package cake.tests.cases.libs.model * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,8 +24,7 @@ PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'DEFAULT'); /** * ModelBaseTest * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ abstract class BaseModelTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/model/model_delete.test.php b/cake/tests/cases/libs/model/model_delete.test.php index e61865e57..ae4045743 100644 --- a/cake/tests/cases/libs/model/model_delete.test.php +++ b/cake/tests/cases/libs/model/model_delete.test.php @@ -12,8 +12,7 @@ * * @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.model + * @package cake.tests.cases.libs.model * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ require_once dirname(__FILE__) . DS . 'model.test.php'; /** * ModelDeleteTest * - * @package cake - * @subpackage cake.tests.cases.libs.model.operations + * @package cake.tests.cases.libs.model.operations */ class ModelDeleteTest extends BaseModelTest { diff --git a/cake/tests/cases/libs/model/model_integration.test.php b/cake/tests/cases/libs/model/model_integration.test.php index b3d78af1a..94714a276 100644 --- a/cake/tests/cases/libs/model/model_integration.test.php +++ b/cake/tests/cases/libs/model/model_integration.test.php @@ -14,8 +14,7 @@ * * @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.model + * @package cake.tests.cases.libs.model * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -45,8 +44,7 @@ class DboMock extends DboSource { /** * ModelIntegrationTest * - * @package cake - * @subpackage cake.tests.cases.libs.model.operations + * @package cake.tests.cases.libs.model.operations */ class ModelIntegrationTest extends BaseModelTest { @@ -61,27 +59,27 @@ class ModelIntegrationTest extends BaseModelTest { $Article = new ArticleFeatured(); $this->assertTrue(isset($Article->belongsTo['User'])); $this->assertFalse(property_exists($Article, 'User')); - $this->assertType('User', $Article->User); + $this->assertInstanceOf('User', $Article->User); $this->assertTrue(isset($Article->belongsTo['Category'])); $this->assertFalse(property_exists($Article, 'Category')); $this->assertTrue(isset($Article->Category)); - $this->assertType('Category', $Article->Category); + $this->assertInstanceOf('Category', $Article->Category); $this->assertTrue(isset($Article->hasMany['Comment'])); $this->assertFalse(property_exists($Article, 'Comment')); $this->assertTrue(isset($Article->Comment)); - $this->assertType('Comment', $Article->Comment); + $this->assertInstanceOf('Comment', $Article->Comment); $this->assertTrue(isset($Article->hasAndBelongsToMany['Tag'])); //There was not enough information to setup the association (joinTable and associationForeignKey) //so the model was not lazy loaded $this->assertTrue(property_exists($Article, 'Tag')); $this->assertTrue(isset($Article->Tag)); - $this->assertType('Tag', $Article->Tag); + $this->assertInstanceOf('Tag', $Article->Tag); $this->assertFalse(property_exists($Article, 'ArticleFeaturedsTag')); - $this->assertType('AppModel', $Article->ArticleFeaturedsTag); + $this->assertInstanceOf('AppModel', $Article->ArticleFeaturedsTag); $this->assertEquals($Article->hasAndBelongsToMany['Tag']['joinTable'], 'article_featureds_tags'); $this->assertEquals($Article->hasAndBelongsToMany['Tag']['associationForeignKey'], 'tag_id'); } @@ -97,10 +95,10 @@ class ModelIntegrationTest extends BaseModelTest { $Article = new ArticleB(); $this->assertTrue(isset($Article->hasAndBelongsToMany['TagB'])); $this->assertFalse(property_exists($Article, 'TagB')); - $this->assertType('TagB', $Article->TagB); + $this->assertInstanceOf('TagB', $Article->TagB); $this->assertFalse(property_exists($Article, 'ArticlesTag')); - $this->assertType('AppModel', $Article->ArticlesTag); + $this->assertInstanceOf('AppModel', $Article->ArticlesTag); $UuidTag = new UuidTag(); $this->assertTrue(isset($UuidTag->hasAndBelongsToMany['Fruit'])); @@ -110,7 +108,7 @@ class ModelIntegrationTest extends BaseModelTest { $this->assertFalse(property_exists($UuidTag, 'FruitsUuidTag')); $this->assertTrue(isset($UuidTag->FruitsUuidTag)); - $this->assertType('FruitsUuidTag', $UuidTag->FruitsUuidTag); + $this->assertInstanceOf('FruitsUuidTag', $UuidTag->FruitsUuidTag); } /** @@ -129,7 +127,7 @@ class ModelIntegrationTest extends BaseModelTest { $Article->bindModel(array('belongsTo' => array('User'))); $this->assertTrue(isset($Article->belongsTo['User'])); $this->assertFalse(property_exists($Article, 'User')); - $this->assertType('User', $Article->User); + $this->assertInstanceOf('User', $Article->User); } /** @@ -184,7 +182,7 @@ class ModelIntegrationTest extends BaseModelTest { */ function testPkInHabtmLinkModel() { //Test Nonconformant Models - $this->loadFixtures('Content', 'ContentAccount', 'Account', 'JoinC', 'JoinAC'); + $this->loadFixtures('Content', 'ContentAccount', 'Account', 'JoinC', 'JoinAC', 'ItemsPortfolio'); $TestModel = new Content(); $this->assertEqual($TestModel->ContentAccount->primaryKey, 'iContentAccountsId'); @@ -1867,7 +1865,7 @@ class ModelIntegrationTest extends BaseModelTest { * @return void */ function testCreation() { - $this->loadFixtures('Article', 'ArticleFeaturedsTags'); + $this->loadFixtures('Article', 'ArticleFeaturedsTags', 'User', 'Featured'); $TestModel = new Test(); $result = $TestModel->create(); $expected = array('Test' => array('notes' => 'write some notes here')); @@ -1882,9 +1880,10 @@ class ModelIntegrationTest extends BaseModelTest { } else { $intLength = 11; } - foreach (array('collate', 'charset') as $type) { - unset($result['user'][$type]); - unset($result['password'][$type]); + foreach (array('collate', 'charset', 'comment') as $type) { + foreach ($result as $i => $r) { + unset($result[$i][$type]); + } } $expected = array( @@ -1946,8 +1945,8 @@ class ModelIntegrationTest extends BaseModelTest { 'Featured' => array( 'article_featured_id' => 1, 'category_id' => 1, - 'published_date' => '2008-6-11 00:00:00', - 'end_date' => '2008-6-20 00:00:00' + 'published_date' => '2008-06-11 00:00:00', + 'end_date' => '2008-06-20 00:00:00' )); $this->assertEqual($FeaturedModel->create($data), $expected); @@ -1969,8 +1968,8 @@ class ModelIntegrationTest extends BaseModelTest { $expected = array( 'Featured' => array( - 'published_date' => '2008-6-11 00:00:00', - 'end_date' => '2008-6-20 00:00:00', + 'published_date' => '2008-06-11 00:00:00', + 'end_date' => '2008-06-20 00:00:00', 'article_featured_id' => 1, 'category_id' => 1 )); @@ -2009,4 +2008,27 @@ class ModelIntegrationTest extends BaseModelTest { $expected = $db->name('Domain.DomainHandle'); $this->assertEqual($result, $expected); } + +/** + * test that model->hasMethod checks self and behaviors. + * + * @return void + */ + function testHasMethod() { + $Article = new Article(); + $Article->Behaviors = $this->getMock('BehaviorCollection'); + + $Article->Behaviors->expects($this->at(0)) + ->method('hasMethod') + ->will($this->returnValue(true)); + + $Article->Behaviors->expects($this->at(1)) + ->method('hasMethod') + ->will($this->returnValue(false)); + + $this->assertTrue($Article->hasMethod('find')); + + $this->assertTrue($Article->hasMethod('pass')); + $this->assertFalse($Article->hasMethod('fail')); + } } diff --git a/cake/tests/cases/libs/model/model_read.test.php b/cake/tests/cases/libs/model/model_read.test.php index 1a3118763..5be36aaf3 100755 --- a/cake/tests/cases/libs/model/model_read.test.php +++ b/cake/tests/cases/libs/model/model_read.test.php @@ -12,8 +12,7 @@ * * @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.model + * @package cake.tests.cases.libs.model * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ require_once dirname(__FILE__) . DS . 'model.test.php'; /** * ModelReadTest * - * @package cake - * @subpackage cake.tests.cases.libs.model.operations + * @package cake.tests.cases.libs.model.operations */ class ModelReadTest extends BaseModelTest { @@ -52,15 +50,17 @@ class ModelReadTest extends BaseModelTest { ) ); + $Something->JoinThing->create($joinThingData); $Something->JoinThing->save(); $result = $Something->JoinThing->find('all', array('conditions' => array('something_else_id' => 2))); - $this->assertEqual($result[0]['JoinThing']['doomed'], '1'); - $this->assertEqual($result[1]['JoinThing']['doomed'], '0'); + $this->assertEqual((bool)$result[0]['JoinThing']['doomed'], true); + $this->assertEqual((bool)$result[1]['JoinThing']['doomed'], false); $result = $Something->find('first'); + $this->assertEqual(count($result['SomethingElse']), 2); $doomed = Set::extract('/JoinThing/doomed', $result['SomethingElse']); @@ -79,7 +79,7 @@ class ModelReadTest extends BaseModelTest { */ function testGroupBy() { $db = ConnectionManager::getDataSource('test'); - $isStrictGroupBy = in_array($db->config['driver'], array('postgres', 'oracle')); + $isStrictGroupBy = in_array($db->config['driver'], array('postgres', 'oracle', 'sqlite')); $message = '%s Postgres and Oracle have strict GROUP BY and are incompatible with this test.'; if ($this->skipIf($isStrictGroupBy, $message )) { @@ -279,13 +279,6 @@ class ModelReadTest extends BaseModelTest { $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag'); $Article = new Article(); - $finalQuery = 'SELECT title, published FROM '; - $finalQuery .= $this->db->fullTableName('articles'); - $finalQuery .= ' WHERE ' . $this->db->fullTableName('articles'); - $finalQuery .= '.id = ' . $this->db->value(1); - $finalQuery .= ' AND ' . $this->db->fullTableName('articles'); - $finalQuery .= '.published = ' . $this->db->value('Y'); - $query = 'SELECT title, published FROM '; $query .= $this->db->fullTableName('articles'); $query .= ' WHERE ' . $this->db->fullTableName('articles'); @@ -305,14 +298,9 @@ class ModelReadTest extends BaseModelTest { } $this->assertEqual($result, $expected); - $result = $this->db->getQueryCache($finalQuery); + $result = $this->db->getQueryCache($query, $params); $this->assertFalse(empty($result)); - $finalQuery = 'SELECT id, created FROM '; - $finalQuery .= $this->db->fullTableName('articles'); - $finalQuery .= ' WHERE ' . $this->db->fullTableName('articles'); - $finalQuery .= '.title = ' . $this->db->value('First Article'); - $query = 'SELECT id, created FROM '; $query .= $this->db->fullTableName('articles'); $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title = ?'; @@ -324,7 +312,7 @@ class ModelReadTest extends BaseModelTest { isset($result[0][$this->db->fullTableName('articles', false)]) || isset($result[0][0]) ); - $result = $this->db->getQueryCache($finalQuery); + $result = $this->db->getQueryCache($query, $params); $this->assertTrue(empty($result)); $query = 'SELECT title FROM '; @@ -345,10 +333,7 @@ class ModelReadTest extends BaseModelTest { $params = array('First? Article', 'Y'); $Article->query($query, $params); - $expected = 'SELECT title FROM '; - $expected .= $this->db->fullTableName('articles'); - $expected .= " WHERE title = 'First? Article' AND published = 'Y'"; - $result = $this->db->getQueryCache($expected); + $result = $this->db->getQueryCache($query, $params); $this->assertFalse($result === false); } @@ -5091,7 +5076,7 @@ class ModelReadTest extends BaseModelTest { 'typ' => 2 ))); - $this->assertEqual($result, $expected); + $this->assertEqual($expected, $result); } /** @@ -5661,7 +5646,7 @@ class ModelReadTest extends BaseModelTest { 'name' => 'computer' )))))); - $this->assertIdentical($result, $expected); + $this->assertEquals($result, $expected); } /** @@ -7478,7 +7463,7 @@ class ModelReadTest extends BaseModelTest { $result = $Post->field('other_field'); $this->assertEqual($result, 4); - if ($this->skipIf($this->db->config['driver'] == 'postgres', 'The rest of virtualFieds test is not compatible with Postgres')) { + if ($this->skipIf($this->db->config['driver'] != 'mysql', 'The rest of virtualFieds test is not compatible with Postgres')) { return; } ClassRegistry::flush(); @@ -7486,20 +7471,20 @@ class ModelReadTest extends BaseModelTest { $Post->create(); $Post->virtualFields = array( - 'year' => 'YEAR(Post.created)', + 'low_title' => 'lower(Post.title)', 'unique_test_field' => 'COUNT(Post.id)' ); $expectation = array( 'Post' => array( - 'year' => 2007, - 'unique_test_field' => 3 + 'low_title' => 'first post', + 'unique_test_field' => 1 ) ); $result = $Post->find('first', array( 'fields' => array_keys($Post->virtualFields), - 'group' => array('year') + 'group' => array('low_title') )); $this->assertEqual($result, $expectation); diff --git a/cake/tests/cases/libs/model/model_validation.test.php b/cake/tests/cases/libs/model/model_validation.test.php index d921618c0..0da3c18e9 100644 --- a/cake/tests/cases/libs/model/model_validation.test.php +++ b/cake/tests/cases/libs/model/model_validation.test.php @@ -14,8 +14,7 @@ * * @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.model + * @package cake.tests.cases.libs.model * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,8 +23,7 @@ require_once dirname(__FILE__) . DS . 'model.test.php'; /** * ModelValidationTest * - * @package cake - * @subpackage cake.tests.cases.libs.model.operations + * @package cake.tests.cases.libs.model.operations */ class ModelValidationTest extends BaseModelTest { diff --git a/cake/tests/cases/libs/model/model_write.test.php b/cake/tests/cases/libs/model/model_write.test.php index 744e50db5..44a6585c6 100644 --- a/cake/tests/cases/libs/model/model_write.test.php +++ b/cake/tests/cases/libs/model/model_write.test.php @@ -12,8 +12,7 @@ * * @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.model + * @package cake.tests.cases.libs.model * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ require_once dirname(__FILE__) . DS . 'model.test.php'; /** * ModelWriteTest * - * @package cake - * @subpackage cake.tests.cases.libs.model.operations + * @package cake.tests.cases.libs.model.operations */ class ModelWriteTest extends BaseModelTest { @@ -201,8 +199,8 @@ class ModelWriteTest extends BaseModelTest { $TestModel->create(array()); $TestModel->save(); $result = $TestModel->findById($TestModel->id); - $this->assertIdentical($result['DataTest']['count'], '0'); - $this->assertIdentical($result['DataTest']['float'], '0'); + $this->assertEquals($result['DataTest']['count'], 0); + $this->assertEquals($result['DataTest']['float'], 0); } /** @@ -286,20 +284,20 @@ class ModelWriteTest extends BaseModelTest { )); $result = $TestModel->findById(1); - $this->assertIdentical($result['Syfile']['item_count'], '2'); + $this->assertEquals($result['Syfile']['item_count'], 2); $TestModel2->delete(1); $result = $TestModel->findById(1); - $this->assertIdentical($result['Syfile']['item_count'], '1'); + $this->assertEquals($result['Syfile']['item_count'], 1); $TestModel2->id = 2; $TestModel2->saveField('syfile_id', 1); $result = $TestModel->findById(1); - $this->assertIdentical($result['Syfile']['item_count'], '2'); + $this->assertEquals($result['Syfile']['item_count'], 2); $result = $TestModel->findById(2); - $this->assertIdentical($result['Syfile']['item_count'], '0'); + $this->assertEquals($result['Syfile']['item_count'], 0); } /** @@ -437,7 +435,7 @@ class ModelWriteTest extends BaseModelTest { * @return void */ function testSaveWithCounterCacheScope() { - $this->loadFixtures('Syfile', 'Item'); + $this->loadFixtures('Syfile', 'Item', 'Image', 'ItemsPortfolio', 'Portfolio'); $TestModel = new Syfile(); $TestModel2 = new Item(); $TestModel2->belongsTo['Syfile']['counterCache'] = true; @@ -453,12 +451,13 @@ class ModelWriteTest extends BaseModelTest { )); $result = $TestModel->findById(1); - $this->assertIdentical($result['Syfile']['item_count'], '1'); + + $this->assertEquals($result['Syfile']['item_count'], 1); $TestModel2->id = 1; $TestModel2->saveField('published', true); $result = $TestModel->findById(1); - $this->assertIdentical($result['Syfile']['item_count'], '2'); + $this->assertEquals($result['Syfile']['item_count'], 2); $TestModel2->save(array( 'id' => 1, @@ -467,7 +466,7 @@ class ModelWriteTest extends BaseModelTest { )); $result = $TestModel->findById(1); - $this->assertIdentical($result['Syfile']['item_count'], '1'); + $this->assertEquals($result['Syfile']['item_count'], 1); } /** @@ -1013,6 +1012,7 @@ class ModelWriteTest extends BaseModelTest { * @return void */ function testSaveFromXml() { + $this->markTestSkipped('This feature needs to be fixed or dropped'); $this->loadFixtures('Article'); App::import('Core', 'Xml'); @@ -1579,7 +1579,7 @@ class ModelWriteTest extends BaseModelTest { 'DoomedSomethingElse' => array( 'className' => 'SomethingElse', 'joinTable' => 'join_things', - 'conditions' => 'JoinThing.doomed = true', + 'conditions' => array('JoinThing.doomed' => true), 'unique' => true ), 'NotDoomedSomethingElse' => array( @@ -2434,7 +2434,7 @@ class ModelWriteTest extends BaseModelTest { * @return void */ function testSaveAll() { - $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment'); + $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment', 'Article', 'User'); $TestModel = new Post(); $result = $TestModel->find('all'); @@ -2574,7 +2574,7 @@ class ModelWriteTest extends BaseModelTest { * @return void */ function testSaveAllHabtm() { - $this->loadFixtures('Article', 'Tag', 'Comment', 'User'); + $this->loadFixtures('Article', 'Tag', 'Comment', 'User', 'ArticlesTag'); $data = array( 'Article' => array( 'user_id' => 1, @@ -3066,7 +3066,7 @@ class ModelWriteTest extends BaseModelTest { */ function testSaveAllNestedSaveAll() { $this->loadFixtures('Sample'); - $TransactionTestModel =& new TransactionTestModel(); + $TransactionTestModel = new TransactionTestModel(); $data = array( array('apple_id' => 1, 'name' => 'sample5'), @@ -3839,8 +3839,8 @@ class ModelWriteTest extends BaseModelTest { */ function testProductUpdateAll() { $this->skipIf( - $this->db->config['driver'] == 'postgres', - '%s Currently, there is no way of doing joins in an update statement in postgresql' + $this->db->config['driver'] != 'mysql', + '%s Currently, there is no way of doing joins in an update statement in postgresql or sqlite' ); $this->loadFixtures('ProductUpdateAll', 'GroupUpdateAll'); $ProductUpdateAll = new ProductUpdateAll(); @@ -3890,7 +3890,7 @@ class ModelWriteTest extends BaseModelTest { */ function testProductUpdateAllWithoutForeignKey() { $this->skipIf( - $this->db->config['driver'] == 'postgres', + $this->db->config['driver'] != 'mysql', '%s Currently, there is no way of doing joins in an update statement in postgresql' ); $this->loadFixtures('ProductUpdateAll', 'GroupUpdateAll'); diff --git a/cake/tests/cases/libs/model/models.php b/cake/tests/cases/libs/model/models.php index b92543e49..6c61254fb 100644 --- a/cake/tests/cases/libs/model/models.php +++ b/cake/tests/cases/libs/model/models.php @@ -14,8 +14,7 @@ * * @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.model + * @package cake.tests.cases.libs.model * @since CakePHP(tm) v 1.2.0.6464 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,8 +24,7 @@ PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'DEFAULT'); /** * Test class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Test extends CakeTestModel { @@ -65,8 +63,7 @@ class Test extends CakeTestModel { /** * TestAlias class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class TestAlias extends CakeTestModel { @@ -113,8 +110,7 @@ class TestAlias extends CakeTestModel { /** * TestValidate class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class TestValidate extends CakeTestModel { @@ -178,8 +174,7 @@ class TestValidate extends CakeTestModel { /** * User class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class User extends CakeTestModel { @@ -203,8 +198,7 @@ class User extends CakeTestModel { /** * Article class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Article extends CakeTestModel { @@ -262,7 +256,7 @@ class Article extends CakeTestModel { * @access public * @return void */ - function beforeSave() { + function beforeSave($options = array()) { return $this->beforeSaveReturn; } @@ -273,7 +267,7 @@ class Article extends CakeTestModel { * @access public * @return void */ - function titleDuplicate ($title) { + static function titleDuplicate ($title) { if ($title === 'My Article Title') { return false; } @@ -293,7 +287,7 @@ class BeforeDeleteComment extends CakeTestModel { var $useTable = 'comments'; function beforeDelete($cascade = true) { - $db =& $this->getDataSource(); + $db = $this->getDataSource(); $db->delete($this, array($this->alias . '.' . $this->primaryKey => array(1, 3))); return true; } @@ -302,8 +296,7 @@ class BeforeDeleteComment extends CakeTestModel { /** * NumericArticle class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class NumericArticle extends CakeTestModel { @@ -327,8 +320,7 @@ class NumericArticle extends CakeTestModel { /** * Article10 class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Article10 extends CakeTestModel { @@ -360,8 +352,7 @@ class Article10 extends CakeTestModel { /** * ArticleFeatured class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class ArticleFeatured extends CakeTestModel { @@ -417,8 +408,7 @@ class ArticleFeatured extends CakeTestModel { /** * Featured class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Featured extends CakeTestModel { @@ -442,8 +432,7 @@ class Featured extends CakeTestModel { /** * Tag class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Tag extends CakeTestModel { @@ -459,8 +448,7 @@ class Tag extends CakeTestModel { /** * ArticlesTag class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class ArticlesTag extends CakeTestModel { @@ -476,8 +464,7 @@ class ArticlesTag extends CakeTestModel { /** * ArticleFeaturedsTag class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class ArticleFeaturedsTag extends CakeTestModel { @@ -493,8 +480,7 @@ class ArticleFeaturedsTag extends CakeTestModel { /** * Comment class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Comment extends CakeTestModel { @@ -526,8 +512,7 @@ class Comment extends CakeTestModel { /** * Modified Comment Class has afterFind Callback * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class ModifiedComment extends CakeTestModel { @@ -560,7 +545,7 @@ class ModifiedComment extends CakeTestModel { * * @return void */ - function afterFind($results) { + function afterFind($results, $primary = false) { if (isset($results[0])) { $results[0]['Comment']['callback'] = 'Fire'; } @@ -571,8 +556,7 @@ class ModifiedComment extends CakeTestModel { /** * Modified Comment Class has afterFind Callback * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class AgainModifiedComment extends CakeTestModel { @@ -605,7 +589,7 @@ class AgainModifiedComment extends CakeTestModel { * * @return void */ - function afterFind($results) { + function afterFind($results, $primary = false) { if (isset($results[0])) { $results[0]['Comment']['querytype'] = $this->findQueryType; } @@ -616,8 +600,7 @@ class AgainModifiedComment extends CakeTestModel { /** * MergeVarPluginAppModel class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class MergeVarPluginAppModel extends AppModel { @@ -634,8 +617,7 @@ class MergeVarPluginAppModel extends AppModel { /** * MergeVarPluginPost class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class MergeVarPluginPost extends MergeVarPluginAppModel { @@ -659,8 +641,7 @@ class MergeVarPluginPost extends MergeVarPluginAppModel { /** * MergeVarPluginComment class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class MergeVarPluginComment extends MergeVarPluginAppModel { @@ -685,8 +666,7 @@ class MergeVarPluginComment extends MergeVarPluginAppModel { /** * Attachment class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Attachment extends CakeTestModel { @@ -702,8 +682,7 @@ class Attachment extends CakeTestModel { /** * Category class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Category extends CakeTestModel { @@ -719,8 +698,7 @@ class Category extends CakeTestModel { /** * CategoryThread class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class CategoryThread extends CakeTestModel { @@ -744,8 +722,7 @@ class CategoryThread extends CakeTestModel { /** * Apple class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Apple extends CakeTestModel { @@ -793,8 +770,7 @@ class Apple extends CakeTestModel { /** * Sample class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Sample extends CakeTestModel { @@ -818,8 +794,7 @@ class Sample extends CakeTestModel { /** * AnotherArticle class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class AnotherArticle extends CakeTestModel { @@ -843,8 +818,7 @@ class AnotherArticle extends CakeTestModel { /** * Advertisement class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Advertisement extends CakeTestModel { @@ -868,8 +842,7 @@ class Advertisement extends CakeTestModel { /** * Home class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Home extends CakeTestModel { @@ -893,8 +866,7 @@ class Home extends CakeTestModel { /** * Post class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Post extends CakeTestModel { @@ -921,7 +893,7 @@ class Post extends CakeTestModel { return true; } - function afterFind($results) { + function afterFind($results, $primary = false) { $this->useDbConfig = 'test'; return $results; } @@ -930,8 +902,7 @@ class Post extends CakeTestModel { /** * Author class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Author extends CakeTestModel { @@ -958,7 +929,7 @@ class Author extends CakeTestModel { * @access public * @return void */ - function afterFind($results) { + function afterFind($results, $primary = false) { $results[0]['Author']['test'] = 'working'; return $results; } @@ -967,8 +938,7 @@ class Author extends CakeTestModel { /** * ModifiedAuthor class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class ModifiedAuthor extends Author { @@ -987,7 +957,7 @@ class ModifiedAuthor extends Author { * @access public * @return void */ - function afterFind($results) { + function afterFind($results, $primary = false) { foreach($results as $index => $result) { $results[$index]['Author']['user'] .= ' (CakePHP)'; } @@ -998,8 +968,7 @@ class ModifiedAuthor extends Author { /** * Project class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Project extends CakeTestModel { @@ -1023,8 +992,7 @@ class Project extends CakeTestModel { /** * Thread class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Thread extends CakeTestModel { @@ -1056,8 +1024,7 @@ class Thread extends CakeTestModel { /** * Message class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Message extends CakeTestModel { @@ -1081,8 +1048,7 @@ class Message extends CakeTestModel { /** * Bid class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Bid extends CakeTestModel { @@ -1106,8 +1072,7 @@ class Bid extends CakeTestModel { /** * NodeAfterFind class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class NodeAfterFind extends CakeTestModel { @@ -1166,7 +1131,7 @@ class NodeAfterFind extends CakeTestModel { * @access public * @return void */ - function afterFind($results) { + function afterFind($results, $primary = false) { return $results; } } @@ -1174,8 +1139,7 @@ class NodeAfterFind extends CakeTestModel { /** * NodeAfterFindSample class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class NodeAfterFindSample extends CakeTestModel { @@ -1207,8 +1171,7 @@ class NodeAfterFindSample extends CakeTestModel { /** * NodeNoAfterFind class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class NodeNoAfterFind extends CakeTestModel { @@ -1264,8 +1227,7 @@ class NodeNoAfterFind extends CakeTestModel { /** * Node class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Node extends CakeTestModel{ @@ -1297,8 +1259,7 @@ class Node extends CakeTestModel{ /** * Dependency class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Dependency extends CakeTestModel { @@ -1314,8 +1275,7 @@ class Dependency extends CakeTestModel { /** * ModelA class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class ModelA extends CakeTestModel { @@ -1347,8 +1307,7 @@ class ModelA extends CakeTestModel { /** * ModelB class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class ModelB extends CakeTestModel { @@ -1380,8 +1339,7 @@ class ModelB extends CakeTestModel { /** * ModelC class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class ModelC extends CakeTestModel { @@ -1413,8 +1371,7 @@ class ModelC extends CakeTestModel { /** * ModelD class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class ModelD extends CakeTestModel { @@ -1438,8 +1395,7 @@ class ModelD extends CakeTestModel { /** * Something class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Something extends CakeTestModel { @@ -1463,8 +1419,7 @@ class Something extends CakeTestModel { /** * SomethingElse class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class SomethingElse extends CakeTestModel { @@ -1488,8 +1443,7 @@ class SomethingElse extends CakeTestModel { /** * JoinThing class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class JoinThing extends CakeTestModel { @@ -1513,8 +1467,7 @@ class JoinThing extends CakeTestModel { /** * Portfolio class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Portfolio extends CakeTestModel { @@ -1538,8 +1491,7 @@ class Portfolio extends CakeTestModel { /** * Item class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Item extends CakeTestModel { @@ -1571,8 +1523,7 @@ class Item extends CakeTestModel { /** * ItemsPortfolio class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class ItemsPortfolio extends CakeTestModel { @@ -1588,8 +1539,7 @@ class ItemsPortfolio extends CakeTestModel { /** * Syfile class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Syfile extends CakeTestModel { @@ -1613,8 +1563,7 @@ class Syfile extends CakeTestModel { /** * Image class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Image extends CakeTestModel { @@ -1630,8 +1579,7 @@ class Image extends CakeTestModel { /** * DeviceType class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class DeviceType extends CakeTestModel { @@ -1675,8 +1623,7 @@ class DeviceType extends CakeTestModel { /** * DeviceTypeCategory class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class DeviceTypeCategory extends CakeTestModel { @@ -1692,8 +1639,7 @@ class DeviceTypeCategory extends CakeTestModel { /** * FeatureSet class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class FeatureSet extends CakeTestModel { @@ -1709,8 +1655,7 @@ class FeatureSet extends CakeTestModel { /** * ExteriorTypeCategory class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class ExteriorTypeCategory extends CakeTestModel { @@ -1734,8 +1679,7 @@ class ExteriorTypeCategory extends CakeTestModel { /** * Document class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Document extends CakeTestModel { @@ -1759,8 +1703,7 @@ class Document extends CakeTestModel { /** * Device class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Device extends CakeTestModel { @@ -1776,8 +1719,7 @@ class Device extends CakeTestModel { /** * DocumentDirectory class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class DocumentDirectory extends CakeTestModel { @@ -1793,8 +1735,7 @@ class DocumentDirectory extends CakeTestModel { /** * PrimaryModel class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class PrimaryModel extends CakeTestModel { @@ -1810,8 +1751,7 @@ class PrimaryModel extends CakeTestModel { /** * SecondaryModel class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class SecondaryModel extends CakeTestModel { @@ -1827,8 +1767,7 @@ class SecondaryModel extends CakeTestModel { /** * JoinA class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class JoinA extends CakeTestModel { @@ -1852,8 +1791,7 @@ class JoinA extends CakeTestModel { /** * JoinB class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class JoinB extends CakeTestModel { @@ -1877,8 +1815,7 @@ class JoinB extends CakeTestModel { /** * JoinC class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class JoinC extends CakeTestModel { @@ -1902,8 +1839,7 @@ class JoinC extends CakeTestModel { /** * ThePaper class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class ThePaper extends CakeTestModel { @@ -1943,8 +1879,7 @@ class ThePaper extends CakeTestModel { /** * Monkey class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Monkey extends CakeTestModel { @@ -1968,8 +1903,7 @@ class Monkey extends CakeTestModel { /** * AssociationTest1 class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class AssociationTest1 extends CakeTestModel { @@ -2003,8 +1937,7 @@ class AssociationTest1 extends CakeTestModel { /** * AssociationTest2 class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class AssociationTest2 extends CakeTestModel { @@ -2038,8 +1971,7 @@ class AssociationTest2 extends CakeTestModel { /** * Callback class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Callback extends CakeTestModel { @@ -2047,8 +1979,7 @@ class Callback extends CakeTestModel { /** * CallbackPostTestModel class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class CallbackPostTestModel extends CakeTestModel { public $useTable = 'posts'; @@ -2075,7 +2006,7 @@ class CallbackPostTestModel extends CakeTestModel { * * @return void */ - function beforeSave($options) { + function beforeSave($options = array()) { return $this->beforeSaveReturn; } /** @@ -2083,7 +2014,7 @@ class CallbackPostTestModel extends CakeTestModel { * * @return void */ - function beforeValidate($options) { + function beforeValidate($options = array()) { return $this->beforeValidateReturn; } /** @@ -2099,8 +2030,7 @@ class CallbackPostTestModel extends CakeTestModel { /** * Uuid class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Uuid extends CakeTestModel { @@ -2116,8 +2046,7 @@ class Uuid extends CakeTestModel { /** * DataTest class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class DataTest extends CakeTestModel { @@ -2133,8 +2062,7 @@ class DataTest extends CakeTestModel { /** * TheVoid class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class TheVoid extends CakeTestModel { @@ -2158,8 +2086,7 @@ class TheVoid extends CakeTestModel { /** * ValidationTest1 class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class ValidationTest1 extends CakeTestModel { @@ -2250,8 +2177,7 @@ class ValidationTest1 extends CakeTestModel { /** * ValidationTest2 class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class ValidationTest2 extends CakeTestModel { @@ -2304,7 +2230,7 @@ class ValidationTest2 extends CakeTestModel { * @access public * @return void */ - function schema() { + public function schema($field = false) { return array(); } } @@ -2312,8 +2238,7 @@ class ValidationTest2 extends CakeTestModel { /** * Person class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Person extends CakeTestModel { @@ -2343,8 +2268,7 @@ class Person extends CakeTestModel { /** * UnderscoreField class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class UnderscoreField extends CakeTestModel { @@ -2360,8 +2284,7 @@ class UnderscoreField extends CakeTestModel { /** * Product class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Product extends CakeTestModel { @@ -2377,8 +2300,7 @@ class Product extends CakeTestModel { /** * Story class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Story extends CakeTestModel { @@ -2418,8 +2340,7 @@ class Story extends CakeTestModel { /** * Cd class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Cd extends CakeTestModel { @@ -2443,8 +2364,7 @@ class Cd extends CakeTestModel { /** * Book class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Book extends CakeTestModel { @@ -2468,8 +2388,7 @@ class Book extends CakeTestModel { /** * OverallFavorite class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class OverallFavorite extends CakeTestModel { @@ -2485,8 +2404,7 @@ class OverallFavorite extends CakeTestModel { /** * MyUser class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class MyUser extends CakeTestModel { @@ -2510,8 +2428,7 @@ class MyUser extends CakeTestModel { /** * MyCategory class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class MyCategory extends CakeTestModel { @@ -2535,8 +2452,7 @@ class MyCategory extends CakeTestModel { /** * MyProduct class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class MyProduct extends CakeTestModel { @@ -2560,8 +2476,7 @@ class MyProduct extends CakeTestModel { /** * MyCategoriesMyUser class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class MyCategoriesMyUser extends CakeTestModel { @@ -2577,8 +2492,7 @@ class MyCategoriesMyUser extends CakeTestModel { /** * MyCategoriesMyProduct class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class MyCategoriesMyProduct extends CakeTestModel { @@ -2591,44 +2505,11 @@ class MyCategoriesMyProduct extends CakeTestModel { public $name = 'MyCategoriesMyProduct'; } -/** - * I18nModel class - * - * @package cake - * @subpackage cake.tests.cases.libs.model - */ -class I18nModel extends CakeTestModel { - -/** - * name property - * - * @var string 'I18nModel' - * @access public - */ - public $name = 'I18nModel'; - -/** - * useTable property - * - * @var string 'i18n' - * @access public - */ - public $useTable = 'i18n'; - -/** - * displayField property - * - * @var string 'field' - * @access public - */ - public $displayField = 'field'; -} /** * NumberTree class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class NumberTree extends CakeTestModel { @@ -2662,7 +2543,7 @@ class NumberTree extends CakeTestModel { */ function initialize($levelLimit = 3, $childLimit = 3, $currentLevel = null, $parent_id = null, $prefix = '1', $hierachial = true) { if (!$parent_id) { - $db =& ConnectionManager::getDataSource($this->useDbConfig); + $db = ConnectionManager::getDataSource($this->useDbConfig); $db->truncate($this->table); $this->save(array($this->name => array('name' => '1. Root'))); $this->initialize($levelLimit, $childLimit, 1, $this->id, '1', $hierachial); @@ -2694,8 +2575,7 @@ class NumberTree extends CakeTestModel { /** * NumberTreeTwo class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class NumberTreeTwo extends NumberTree { @@ -2719,8 +2599,7 @@ class NumberTreeTwo extends NumberTree { /** * FlagTree class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class FlagTree extends NumberTree { @@ -2736,8 +2615,7 @@ class FlagTree extends NumberTree { /** * UnconventionalTree class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class UnconventionalTree extends NumberTree { @@ -2760,8 +2638,7 @@ class UnconventionalTree extends NumberTree { /** * UuidTree class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class UuidTree extends NumberTree { @@ -2777,8 +2654,7 @@ class UuidTree extends NumberTree { /** * Campaign class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Campaign extends CakeTestModel { @@ -2802,8 +2678,7 @@ class Campaign extends CakeTestModel { /** * Ad class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Ad extends CakeTestModel { @@ -2835,8 +2710,7 @@ class Ad extends CakeTestModel { /** * AfterTree class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class AfterTree extends NumberTree { @@ -2866,8 +2740,7 @@ class AfterTree extends NumberTree { /** * Nonconformant Content class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Content extends CakeTestModel { @@ -2907,8 +2780,7 @@ class Content extends CakeTestModel { /** * Nonconformant Account class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Account extends CakeTestModel { @@ -2940,8 +2812,7 @@ class Account extends CakeTestModel { /** * Nonconformant ContentAccount class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class ContentAccount extends CakeTestModel { @@ -2973,8 +2844,7 @@ class ContentAccount extends CakeTestModel { /** * FilmFile class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class FilmFile extends CakeTestModel { public $name = 'FilmFile'; @@ -2983,8 +2853,7 @@ class FilmFile extends CakeTestModel { /** * Basket test model * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Basket extends CakeTestModel { public $name = 'Basket'; @@ -3003,8 +2872,7 @@ class Basket extends CakeTestModel { /** * TestPluginArticle class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class TestPluginArticle extends CakeTestModel { @@ -3042,8 +2910,7 @@ class TestPluginArticle extends CakeTestModel { /** * TestPluginComment class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class TestPluginComment extends CakeTestModel { @@ -3073,8 +2940,7 @@ class TestPluginComment extends CakeTestModel { /** * Uuidportfolio class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Uuidportfolio extends CakeTestModel { @@ -3098,8 +2964,7 @@ class Uuidportfolio extends CakeTestModel { /** * Uuiditem class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class Uuiditem extends CakeTestModel { @@ -3124,8 +2989,7 @@ class Uuiditem extends CakeTestModel { /** * UuiditemsPortfolio class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class UuiditemsUuidportfolio extends CakeTestModel { @@ -3141,8 +3005,7 @@ class UuiditemsUuidportfolio extends CakeTestModel { /** * UuiditemsPortfolioNumericid class * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class UuiditemsUuidportfolioNumericid extends CakeTestModel { @@ -3158,8 +3021,7 @@ class UuiditemsUuidportfolioNumericid extends CakeTestModel { /** * TranslateTestModel class. * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class TranslateTestModel extends CakeTestModel { @@ -3191,8 +3053,7 @@ class TranslateTestModel extends CakeTestModel { /** * TranslateTestModel class. * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class TranslateWithPrefix extends CakeTestModel { /** @@ -3220,8 +3081,7 @@ class TranslateWithPrefix extends CakeTestModel { /** * TranslatedItem class. * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class TranslatedItem extends CakeTestModel { @@ -3261,8 +3121,7 @@ class TranslatedItem extends CakeTestModel { /** * TranslatedItem class. * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class TranslatedItem2 extends CakeTestModel { /** @@ -3297,8 +3156,7 @@ class TranslatedItem2 extends CakeTestModel { /** * TranslatedItemWithTable class. * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class TranslatedItemWithTable extends CakeTestModel { @@ -3354,8 +3212,7 @@ class TranslatedItemWithTable extends CakeTestModel { /** * TranslateArticleModel class. * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class TranslateArticleModel extends CakeTestModel { @@ -3387,8 +3244,7 @@ class TranslateArticleModel extends CakeTestModel { /** * TranslatedArticle class. * - * @package cake - * @subpackage cake.tests.cases.libs.model + * @package cake.tests.cases.libs.model */ class TranslatedArticle extends CakeTestModel { @@ -3592,3 +3448,1289 @@ class TransactionTestModel extends CakeTestModel { $this->saveAll($data, array('atomic' => true, 'callbacks' => false)); } } + +/** + * TestModel class + * + * @package cake.tests.cases.libs.model.datasources + */ +class TestModel extends CakeTestModel { + +/** + * name property + * + * @var string 'TestModel' + * @access public + */ + public $name = 'TestModel'; + +/** + * useTable property + * + * @var bool false + * @access public + */ + public $useTable = false; + +/** + * schema property + * + * @var array + * @access protected + */ + protected $_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'client_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '11'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'login' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'passwd' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), + 'addr_1' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), + 'addr_2' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '25'), + 'zip_code' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'city' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'country' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'phone' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'fax' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'url' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), + 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => '155'), + 'last_login' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); + +/** + * find method + * + * @param mixed $conditions + * @param mixed $fields + * @param mixed $order + * @param mixed $recursive + * @access public + * @return void + */ + function find($conditions = null, $fields = null, $order = null, $recursive = null) { + return array($conditions, $fields); + } + +/** + * findAll method + * + * @param mixed $conditions + * @param mixed $fields + * @param mixed $order + * @param mixed $recursive + * @access public + * @return void + */ + function findAll($conditions = null, $fields = null, $order = null, $recursive = null) { + return $conditions; + } +} + +/** + * TestModel2 class + * + * @package cake.tests.cases.libs.model.datasources + */ +class TestModel2 extends CakeTestModel { + +/** + * name property + * + * @var string 'TestModel2' + * @access public + */ + public $name = 'TestModel2'; + +/** + * useTable property + * + * @var bool false + * @access public + */ + public $useTable = false; +} + +/** + * TestModel4 class + * + * @package cake.tests.cases.libs.model.datasources + */ +class TestModel3 extends CakeTestModel { + +/** + * name property + * + * @var string 'TestModel3' + * @access public + */ + public $name = 'TestModel3'; + +/** + * useTable property + * + * @var bool false + * @access public + */ + public $useTable = false; +} + +/** + * TestModel4 class + * + * @package cake.tests.cases.libs.model.datasources + */ +class TestModel4 extends CakeTestModel { + +/** + * name property + * + * @var string 'TestModel4' + * @access public + */ + public $name = 'TestModel4'; + +/** + * table property + * + * @var string 'test_model4' + * @access public + */ + public $table = 'test_model4'; + +/** + * useTable property + * + * @var bool false + * @access public + */ + public $useTable = false; + +/** + * belongsTo property + * + * @var array + * @access public + */ + public $belongsTo = array( + 'TestModel4Parent' => array( + 'className' => 'TestModel4', + 'foreignKey' => 'parent_id' + ) + ); + +/** + * hasOne property + * + * @var array + * @access public + */ + public $hasOne = array( + 'TestModel5' => array( + 'className' => 'TestModel5', + 'foreignKey' => 'test_model4_id' + ) + ); + +/** + * hasAndBelongsToMany property + * + * @var array + * @access public + */ + public $hasAndBelongsToMany = array('TestModel7' => array( + 'className' => 'TestModel7', + 'joinTable' => 'test_model4_test_model7', + 'foreignKey' => 'test_model4_id', + 'associationForeignKey' => 'test_model7_id', + 'with' => 'TestModel4TestModel7' + )); + +/** + * schema method + * + * @access public + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); + } + return $this->_schema; + } +} + +/** + * TestModel4TestModel7 class + * + * @package cake.tests.cases.libs.model.datasources + */ +class TestModel4TestModel7 extends CakeTestModel { + +/** + * name property + * + * @var string 'TestModel4TestModel7' + * @access public + */ + public $name = 'TestModel4TestModel7'; + +/** + * table property + * + * @var string 'test_model4_test_model7' + * @access public + */ + public $table = 'test_model4_test_model7'; + +/** + * useTable property + * + * @var bool false + * @access public + */ + public $useTable = false; + +/** + * schema method + * + * @access public + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'test_model4_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'test_model7_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8') + ); + } + return $this->_schema; + } +} + +/** + * TestModel5 class + * + * @package cake.tests.cases.libs.model.datasources + */ +class TestModel5 extends CakeTestModel { + +/** + * name property + * + * @var string 'TestModel5' + * @access public + */ + public $name = 'TestModel5'; + +/** + * table property + * + * @var string 'test_model5' + * @access public + */ + public $table = 'test_model5'; + +/** + * useTable property + * + * @var bool false + * @access public + */ + public $useTable = false; + +/** + * belongsTo property + * + * @var array + * @access public + */ + public $belongsTo = array('TestModel4' => array( + 'className' => 'TestModel4', + 'foreignKey' => 'test_model4_id' + )); + +/** + * hasMany property + * + * @var array + * @access public + */ + public $hasMany = array('TestModel6' => array( + 'className' => 'TestModel6', + 'foreignKey' => 'test_model5_id' + )); + +/** + * schema method + * + * @access public + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'test_model4_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); + } + return $this->_schema; + } +} + +/** + * TestModel6 class + * + * @package cake.tests.cases.libs.model.datasources + */ +class TestModel6 extends CakeTestModel { + +/** + * name property + * + * @var string 'TestModel6' + * @access public + */ + public $name = 'TestModel6'; + +/** + * table property + * + * @var string 'test_model6' + * @access public + */ + public $table = 'test_model6'; + +/** + * useTable property + * + * @var bool false + * @access public + */ + public $useTable = false; + +/** + * belongsTo property + * + * @var array + * @access public + */ + public $belongsTo = array('TestModel5' => array( + 'className' => 'TestModel5', + 'foreignKey' => 'test_model5_id' + )); + +/** + * schema method + * + * @access public + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'test_model5_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); + } + return $this->_schema; + } +} + +/** + * TestModel7 class + * + * @package cake.tests.cases.libs.model.datasources + */ +class TestModel7 extends CakeTestModel { + +/** + * name property + * + * @var string 'TestModel7' + * @access public + */ + public $name = 'TestModel7'; + +/** + * table property + * + * @var string 'test_model7' + * @access public + */ + public $table = 'test_model7'; + +/** + * useTable property + * + * @var bool false + * @access public + */ + public $useTable = false; + +/** + * schema method + * + * @access public + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); + } + return $this->_schema; + } +} + +/** + * TestModel8 class + * + * @package cake.tests.cases.libs.model.datasources + */ +class TestModel8 extends CakeTestModel { + +/** + * name property + * + * @var string 'TestModel8' + * @access public + */ + public $name = 'TestModel8'; + +/** + * table property + * + * @var string 'test_model8' + * @access public + */ + public $table = 'test_model8'; + +/** + * useTable property + * + * @var bool false + * @access public + */ + public $useTable = false; + +/** + * hasOne property + * + * @var array + * @access public + */ + public $hasOne = array( + 'TestModel9' => array( + 'className' => 'TestModel9', + 'foreignKey' => 'test_model8_id', + 'conditions' => 'TestModel9.name != \'mariano\'' + ) + ); + +/** + * schema method + * + * @access public + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'test_model9_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); + } + return $this->_schema; + } +} + +/** + * TestModel9 class + * + * @package cake.tests.cases.libs.model.datasources + */ +class TestModel9 extends CakeTestModel { + +/** + * name property + * + * @var string 'TestModel9' + * @access public + */ + public $name = 'TestModel9'; + +/** + * table property + * + * @var string 'test_model9' + * @access public + */ + public $table = 'test_model9'; + +/** + * useTable property + * + * @var bool false + * @access public + */ + public $useTable = false; + +/** + * belongsTo property + * + * @var array + * @access public + */ + public $belongsTo = array('TestModel8' => array( + 'className' => 'TestModel8', + 'foreignKey' => 'test_model8_id', + 'conditions' => 'TestModel8.name != \'larry\'' + )); + +/** + * schema method + * + * @access public + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'test_model8_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '11'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); + } + return $this->_schema; + } +} + +/** + * Level class + * + * @package cake.tests.cases.libs.model.datasources + */ +class Level extends CakeTestModel { + +/** + * name property + * + * @var string 'Level' + * @access public + */ + public $name = 'Level'; + +/** + * table property + * + * @var string 'level' + * @access public + */ + public $table = 'level'; + +/** + * useTable property + * + * @var bool false + * @access public + */ + public $useTable = false; + +/** + * hasMany property + * + * @var array + * @access public + */ + public $hasMany = array( + 'Group'=> array( + 'className' => 'Group' + ), + 'User2' => array( + 'className' => 'User2' + ) + ); + +/** + * schema method + * + * @access public + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), + ); + } + return $this->_schema; + } +} + +/** + * Group class + * + * @package cake.tests.cases.libs.model.datasources + */ +class Group extends CakeTestModel { + +/** + * name property + * + * @var string 'Group' + * @access public + */ + public $name = 'Group'; + +/** + * table property + * + * @var string 'group' + * @access public + */ + public $table = 'group'; + +/** + * useTable property + * + * @var bool false + * @access public + */ + public $useTable = false; + +/** + * belongsTo property + * + * @var array + * @access public + */ + public $belongsTo = array('Level'); + +/** + * hasMany property + * + * @var array + * @access public + */ + public $hasMany = array('Category2', 'User2'); + +/** + * schema method + * + * @access public + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'level_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), + ); + } + return $this->_schema; + } + +} + +/** + * User2 class + * + * @package cake.tests.cases.libs.model.datasources + */ +class User2 extends CakeTestModel { + +/** + * name property + * + * @var string 'User2' + * @access public + */ + public $name = 'User2'; + +/** + * table property + * + * @var string 'user' + * @access public + */ + public $table = 'user'; + +/** + * useTable property + * + * @var bool false + * @access public + */ + public $useTable = false; + +/** + * belongsTo property + * + * @var array + * @access public + */ + public $belongsTo = array( + 'Group' => array( + 'className' => 'Group' + ), + 'Level' => array( + 'className' => 'Level' + ) + ); + +/** + * hasMany property + * + * @var array + * @access public + */ + public $hasMany = array( + 'Article2' => array( + 'className' => 'Article2' + ), + ); + +/** + * schema method + * + * @access public + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'group_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'level_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), + ); + } + return $this->_schema; + } +} + +/** + * Category2 class + * + * @package cake.tests.cases.libs.model.datasources + */ +class Category2 extends CakeTestModel { + +/** + * name property + * + * @var string 'Category2' + * @access public + */ + public $name = 'Category2'; + +/** + * table property + * + * @var string 'category' + * @access public + */ + public $table = 'category'; + +/** + * useTable property + * + * @var bool false + * @access public + */ + public $useTable = false; + +/** + * belongsTo property + * + * @var array + * @access public + */ + public $belongsTo = array( + 'Group' => array( + 'className' => 'Group', + 'foreignKey' => 'group_id' + ), + 'ParentCat' => array( + 'className' => 'Category2', + 'foreignKey' => 'parent_id' + ) + ); + +/** + * hasMany property + * + * @var array + * @access public + */ + public $hasMany = array( + 'ChildCat' => array( + 'className' => 'Category2', + 'foreignKey' => 'parent_id' + ), + 'Article2' => array( + 'className' => 'Article2', + 'order'=>'Article2.published_date DESC', + 'foreignKey' => 'category_id', + 'limit'=>'3') + ); + +/** + * schema method + * + * @access public + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), + 'group_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), + 'parent_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), + 'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), + 'icon' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), + 'description' => array('type' => 'text', 'null' => false, 'default' => '', 'length' => null), + + ); + } + return $this->_schema; + } +} + +/** + * Article2 class + * + * @package cake.tests.cases.libs.model.datasources + */ +class Article2 extends CakeTestModel { + +/** + * name property + * + * @var string 'Article2' + * @access public + */ + public $name = 'Article2'; + +/** + * table property + * + * @var string 'article' + * @access public + */ + public $table = 'articles'; + +/** + * useTable property + * + * @var bool false + * @access public + */ + public $useTable = false; + +/** + * belongsTo property + * + * @var array + * @access public + */ + public $belongsTo = array( + 'Category2' => array('className' => 'Category2'), + 'User2' => array('className' => 'User2') + ); + +/** + * schema method + * + * @access public + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), + 'category_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'user_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'rate_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'rate_sum' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'viewed' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'version' => array('type' => 'string', 'null' => true, 'default' => '', 'length' => '45'), + 'title' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '200'), + 'intro' => array('text' => 'string', 'null' => true, 'default' => '', 'length' => null), + 'comments' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '4'), + 'body' => array('text' => 'string', 'null' => true, 'default' => '', 'length' => null), + 'isdraft' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), + 'allow_comments' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'length' => '1'), + 'moderate_comments' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'length' => '1'), + 'published' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), + 'multipage' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), + 'published_date' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null), + 'created' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null), + 'modified' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null) + ); + } + return $this->_schema; + } +} + +/** + * CategoryFeatured2 class + * + * @package cake.tests.cases.libs.model.datasources + */ +class CategoryFeatured2 extends CakeTestModel { + +/** + * name property + * + * @var string 'CategoryFeatured2' + * @access public + */ + public $name = 'CategoryFeatured2'; + +/** + * table property + * + * @var string 'category_featured' + * @access public + */ + public $table = 'category_featured'; + +/** + * useTable property + * + * @var bool false + * @access public + */ + public $useTable = false; + +/** + * schema method + * + * @access public + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), + 'parent_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), + 'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), + 'icon' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), + 'description' => array('text' => 'string', 'null' => false, 'default' => '', 'length' => null) + ); + } + return $this->_schema; + } +} + +/** + * Featured2 class + * + * @package cake.tests.cases.libs.model.datasources + */ +class Featured2 extends CakeTestModel { + +/** + * name property + * + * @var string 'Featured2' + * @access public + */ + public $name = 'Featured2'; + +/** + * table property + * + * @var string 'featured2' + * @access public + */ + public $table = 'featured2'; + +/** + * useTable property + * + * @var bool false + * @access public + */ + public $useTable = false; + +/** + * belongsTo property + * + * @var array + * @access public + */ + public $belongsTo = array( + 'CategoryFeatured2' => array( + 'className' => 'CategoryFeatured2' + ) + ); + +/** + * schema method + * + * @access public + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'article_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'category_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20') + ); + } + return $this->_schema; + } +} + +/** + * Comment2 class + * + * @package cake.tests.cases.libs.model.datasources + */ +class Comment2 extends CakeTestModel { + +/** + * name property + * + * @var string 'Comment2' + * @access public + */ + public $name = 'Comment2'; + +/** + * table property + * + * @var string 'comment' + * @access public + */ + public $table = 'comment'; + +/** + * belongsTo property + * + * @var array + * @access public + */ + public $belongsTo = array('ArticleFeatured2', 'User2'); + +/** + * useTable property + * + * @var bool false + * @access public + */ + public $useTable = false; + +/** + * schema method + * + * @access public + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'article_featured_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'user_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20') + ); + } + return $this->_schema; + } +} + +/** + * ArticleFeatured2 class + * + * @package cake.tests.cases.libs.model.datasources + */ +class ArticleFeatured2 extends CakeTestModel { + +/** + * name property + * + * @var string 'ArticleFeatured2' + * @access public + */ + public $name = 'ArticleFeatured2'; + +/** + * table property + * + * @var string 'article_featured' + * @access public + */ + public $table = 'article_featured'; + +/** + * useTable property + * + * @var bool false + * @access public + */ + public $useTable = false; + +/** + * belongsTo property + * + * @var array + * @access public + */ + public $belongsTo = array( + 'CategoryFeatured2' => array('className' => 'CategoryFeatured2'), + 'User2' => array('className' => 'User2') + ); + +/** + * hasOne property + * + * @var array + * @access public + */ + public $hasOne = array( + 'Featured2' => array('className' => 'Featured2') + ); + +/** + * hasMany property + * + * @var array + * @access public + */ + public $hasMany = array( + 'Comment2' => array('className'=>'Comment2', 'dependent' => true) + ); + +/** + * schema method + * + * @access public + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'category_featured_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'user_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'title' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), + 'body' => array('text' => 'string', 'null' => true, 'default' => '', 'length' => null), + 'published' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), + 'published_date' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null), + 'created' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null), + 'modified' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null) + ); + } + return $this->_schema; + } +} + +/** + * MysqlTestModel class + * + * @package cake.tests.cases.libs.model.datasources + */ +class MysqlTestModel extends Model { + +/** + * name property + * + * @var string 'MysqlTestModel' + * @access public + */ + public $name = 'MysqlTestModel'; + +/** + * useTable property + * + * @var bool false + * @access public + */ + public $useTable = false; + +/** + * find method + * + * @param mixed $conditions + * @param mixed $fields + * @param mixed $order + * @param mixed $recursive + * @access public + * @return void + */ + function find($conditions = null, $fields = null, $order = null, $recursive = null) { + return $conditions; + } + +/** + * findAll method + * + * @param mixed $conditions + * @param mixed $fields + * @param mixed $order + * @param mixed $recursive + * @access public + * @return void + */ + function findAll($conditions = null, $fields = null, $order = null, $recursive = null) { + return $conditions; + } + +/** + * schema method + * + * @access public + * @return void + */ + public function schema($field = false) { + return array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'client_id' => array('type' => 'integer', 'null' => '', 'default' => '0', 'length' => '11'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'login' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'passwd' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), + 'addr_1' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), + 'addr_2' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '25'), + 'zip_code' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'city' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'country' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'phone' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'fax' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'url' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), + 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => ''), + 'last_login'=> array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); + } +} diff --git a/cake/tests/cases/libs/multibyte.test.php b/cake/tests/cases/libs/multibyte.test.php index 9ec3538ea..f9998cdf9 100644 --- a/cake/tests/cases/libs/multibyte.test.php +++ b/cake/tests/cases/libs/multibyte.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.6833 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Core', 'Multibyte'); /** * MultibyteTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class MultibyteTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/object.test.php b/cake/tests/cases/libs/object.test.php index a371cf9f2..45126a053 100644 --- a/cake/tests/cases/libs/object.test.php +++ b/cake/tests/cases/libs/object.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.5432 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Core', array('Object', 'Controller', 'Model')); /** * RequestActionPost class * - * @package cake - * @subpackage cake.tests.cases.libs.object + * @package cake.tests.cases.libs.object */ class RequestActionPost extends CakeTestModel { @@ -47,8 +45,7 @@ class RequestActionPost extends CakeTestModel { /** * RequestActionController class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class RequestActionController extends Controller { @@ -134,8 +131,7 @@ class RequestActionController extends Controller { /** * RequestActionPersistentController class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class RequestActionPersistentController extends Controller { @@ -168,8 +164,7 @@ class RequestActionPersistentController extends Controller { /** * TestObject class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class TestObject extends Object { @@ -319,8 +314,7 @@ class TestObject extends Object { /** * ObjectTestModel class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class ObjectTestModel extends CakeTestModel { public $useTable = false; @@ -330,8 +324,7 @@ class ObjectTestModel extends CakeTestModel { /** * Object Test class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class ObjectTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/object_collection.test.php b/cake/tests/cases/libs/object_collection.test.php new file mode 100644 index 000000000..cfb177378 --- /dev/null +++ b/cake/tests/cases/libs/object_collection.test.php @@ -0,0 +1,388 @@ +_loaded[$name])) { + return $this->_loaded[$name]; + } + $objectClass = $name . 'GenericObject'; + $this->_loaded[$name] = new $objectClass($this, $settings); + if ($enable === true) { + $this->_enabled[] = $name; + } + return $this->_loaded[$name]; + } +} + +class ObjectCollectionTest extends CakeTestCase { +/** + * setup + * + * @return void + */ + function setup() { + $this->Objects = new GenericObjectCollection(); + } + +/** + * teardown + * + * @return void + */ + function teardown() { + unset($this->Objects); + } + +/** + * test triggering callbacks on loaded helpers + * + * @return void + */ + function testLoad() { + $result = $this->Objects->load('First'); + $this->assertInstanceOf('FirstGenericObject', $result); + $this->assertInstanceOf('FirstGenericObject', $this->Objects->First); + + $result = $this->Objects->attached(); + $this->assertEquals(array('First'), $result, 'attached() results are wrong.'); + + $this->assertTrue($this->Objects->enabled('First')); + + $result = $this->Objects->load('First'); + $this->assertSame($result, $this->Objects->First); + } + +/** + * test unload() + * + * @return void + */ + function testUnload() { + $this->Objects->load('First'); + $this->Objects->load('Second'); + + $result = $this->Objects->attached(); + $this->assertEquals(array('First', 'Second'), $result, 'loaded objects are wrong'); + + $this->Objects->unload('First'); + $this->assertFalse(isset($this->Objects->First)); + $this->assertTrue(isset($this->Objects->Second)); + + $result = $this->Objects->attached(); + $this->assertEquals(array('Second'), $result, 'loaded objects are wrong'); + + $result = $this->Objects->enabled(); + $this->assertEquals(array('Second'), $result, 'enabled objects are wrong'); + } + +/** + * Tests set() + * + * @return void + */ + function testSet() { + $this->Objects->load('First'); + + $result = $this->Objects->attached(); + $this->assertEquals(array('First'), $result, 'loaded objects are wrong'); + + $result = $this->Objects->set('First', new SecondGenericObject()); + $this->assertIsA($result['First'], 'SecondGenericObject', 'set failed'); + + $result = $this->Objects->set('Second', new SecondGenericObject()); + $this->assertIsA($result['Second'], 'SecondGenericObject', 'set failed'); + + $this->assertEquals(count($result), 2); + } + +/** + * creates mock classes for testing + * + * @return void + */ + protected function _makeMockClasses() { + if (!class_exists('TriggerMockFirstGenericObject')) { + $this->getMock('FirstGenericObject', array(), array(), 'TriggerMockFirstGenericObject', false); + } + if (!class_exists('TriggerMockSecondGenericObject')) { + $this->getMock('SecondGenericObject', array(), array(), 'TriggerMockSecondGenericObject', false); + } + } + +/** + * test triggering callbacks. + * + * @return void + */ + function testTrigger() { + $this->_makeMockClasses(); + $this->Objects->load('TriggerMockFirst'); + $this->Objects->load('TriggerMockSecond'); + + $this->Objects->TriggerMockFirst->expects($this->once()) + ->method('callback') + ->will($this->returnValue(true)); + $this->Objects->TriggerMockSecond->expects($this->once()) + ->method('callback') + ->will($this->returnValue(true)); + + $this->assertTrue($this->Objects->trigger('callback')); + } + +/** + * test that the initalize callback is triggered on all components even those that are disabled. + * + * @return void + */ + function testTriggerWithTriggerDisabledObjects() { + $this->_makeMockClasses(); + $this->Objects->load('TriggerMockFirst', array(), false); + $this->Objects->load('TriggerMockSecond'); + + $this->Objects->TriggerMockFirst->expects($this->once()) + ->method('callback') + ->will($this->returnValue(true)); + $this->Objects->TriggerMockSecond->expects($this->once()) + ->method('callback') + ->will($this->returnValue(true)); + + $result = $this->Objects->trigger('callback', array(), array('triggerDisabled' => true)); + $this->assertTrue($result); + } + +/** + * test trigger and disabled objects + * + * @return void + */ + function testTriggerWithDisabledObjects() { + $this->_makeMockClasses(); + $this->Objects->load('TriggerMockFirst'); + $this->Objects->load('TriggerMockSecond'); + + $this->Objects->TriggerMockFirst->expects($this->once()) + ->method('callback') + ->will($this->returnValue(true)); + $this->Objects->TriggerMockSecond->expects($this->never()) + ->method('callback') + ->will($this->returnValue(true)); + + $this->Objects->disable('TriggerMockSecond'); + + $this->assertTrue($this->Objects->trigger('callback', array())); + } + +/** + * test that the collectReturn option works. + * + * @return void + */ + function testTriggerWithCollectReturn() { + $this->_makeMockClasses(); + $this->Objects->load('TriggerMockFirst'); + $this->Objects->load('TriggerMockSecond'); + + $this->Objects->TriggerMockFirst->expects($this->once()) + ->method('callback') + ->will($this->returnValue(array('one', 'two'))); + $this->Objects->TriggerMockSecond->expects($this->once()) + ->method('callback') + ->will($this->returnValue(array('three', 'four'))); + + $result = $this->Objects->trigger('callback', array(), array('collectReturn' => true)); + $expected = array( + array('one', 'two'), + array('three', 'four') + ); + $this->assertEquals($expected, $result); + } + +/** + * test that trigger with break & breakOn works. + * + * @return void + */ + function testTriggerWithBreak() { + $this->_makeMockClasses(); + $this->Objects->load('TriggerMockFirst'); + $this->Objects->load('TriggerMockSecond'); + + $this->Objects->TriggerMockFirst->expects($this->once()) + ->method('callback') + ->will($this->returnValue(false)); + $this->Objects->TriggerMockSecond->expects($this->never()) + ->method('callback'); + + $result = $this->Objects->trigger( + 'callback', + array(), + array('break' => true, 'breakOn' => false) + ); + $this->assertFalse($result); + } + +/** + * test that trigger with modParams works. + * + * @return void + */ + function testTriggerWithModParams() { + $this->_makeMockClasses(); + $this->Objects->load('TriggerMockFirst'); + $this->Objects->load('TriggerMockSecond'); + + $this->Objects->TriggerMockFirst->expects($this->once()) + ->method('callback') + ->with(array('value')) + ->will($this->returnValue(array('new value'))); + + $this->Objects->TriggerMockSecond->expects($this->once()) + ->method('callback') + ->with(array('new value')) + ->will($this->returnValue(array('newer value'))); + + $result = $this->Objects->trigger( + 'callback', + array(array('value')), + array('modParams' => 0) + ); + $this->assertEquals(array('newer value'), $result); + } + +/** + * test that setting modParams to an index that doesn't exist doesn't cause errors. + * + * @expectedException CakeException + * @return void + */ + function testTriggerModParamsInvalidIndex() { + $this->_makeMockClasses(); + $this->Objects->load('TriggerMockFirst'); + $this->Objects->load('TriggerMockSecond'); + + $this->Objects->TriggerMockFirst->expects($this->once()) + ->method('callback') + ->with(array('value')) + ->will($this->returnValue(array('new value'))); + + $this->Objects->TriggerMockSecond->expects($this->once()) + ->method('callback') + ->with(array('value')) + ->will($this->returnValue(array('newer value'))); + + $result = $this->Objects->trigger( + 'callback', + array(array('value')), + array('modParams' => 2) + ); + } + +/** + * test that returrning null doesn't modify parameters. + * + * @expectedException CakeException + * @return void + */ + function testTriggerModParamsNullIgnored() { + $this->_makeMockClasses(); + $this->Objects->load('TriggerMockFirst'); + $this->Objects->load('TriggerMockSecond'); + + $this->Objects->TriggerMockFirst->expects($this->once()) + ->method('callback') + ->with(array('value')) + ->will($this->returnValue(null)); + + $this->Objects->TriggerMockSecond->expects($this->once()) + ->method('callback') + ->with(array('value')) + ->will($this->returnValue(array('new value'))); + + $result = $this->Objects->trigger( + 'callback', + array(array('value')), + array('modParams' => 2) + ); + $this->assertEquals('new value', $result); + } + +/** + * test normalizeObjectArray + * + * @return void + */ + function testnormalizeObjectArray() { + $components = array( + 'Html', + 'Foo.Bar' => array('one', 'two'), + 'Something', + 'Banana.Apple' => array('foo' => 'bar') + ); + $result = ObjectCollection::normalizeObjectArray($components); + $expected = array( + 'Html' => array('class' => 'Html', 'settings' => array()), + 'Bar' => array('class' => 'Foo.Bar', 'settings' => array('one', 'two')), + 'Something' => array('class' => 'Something', 'settings' => array()), + 'Apple' => array('class' => 'Banana.Apple', 'settings' => array('foo' => 'bar')), + ); + $this->assertEquals($expected, $result); + } + +} \ No newline at end of file diff --git a/cake/tests/cases/libs/route/cake_route.test.php b/cake/tests/cases/libs/route/cake_route.test.php index dae305b23..c1433451c 100644 --- a/cake/tests/cases/libs/route/cake_route.test.php +++ b/cake/tests/cases/libs/route/cake_route.test.php @@ -191,8 +191,7 @@ class CakeRouteTestCase extends CakeTestCase { $this->assertEqual($route->options, array('extra' => '[a-z1-9_]*', 'slug' => '[a-z1-9_]+', 'action' => 'view')); $expected = array( 'controller' => 'pages', - 'action' => 'view', - 'extra' => null, + 'action' => 'view' ); $this->assertEqual($route->defaults, $expected); @@ -289,6 +288,45 @@ class CakeRouteTestCase extends CakeTestCase { $this->assertEqual($result, $expected); } +/** + * test that non-greedy routes fail with extra passed args + * + * @return void + */ + function testGreedyRouteFailurePassedArg() { + $route = new CakeRoute('/:controller/:action', array('plugin' => null)); + $result = $route->match(array('controller' => 'posts', 'action' => 'view', '0')); + $this->assertFalse($result); + + $route = new CakeRoute('/:controller/:action', array('plugin' => null)); + $result = $route->match(array('controller' => 'posts', 'action' => 'view', 'test')); + $this->assertFalse($result); + } + +/** + * test that non-greedy routes fail with extra passed args + * + * @return void + */ + function testGreedyRouteFailureNamedParam() { + $route = new CakeRoute('/:controller/:action', array('plugin' => null)); + $result = $route->match(array('controller' => 'posts', 'action' => 'view', 'page' => 1)); + $this->assertFalse($result); + } + +/** + * test that falsey values do not interrupt a match. + * + * @return void + */ + function testMatchWithFalseyValues() { + $route = new CakeRoute('/:controller/:action/*', array('plugin' => null)); + $result = $route->match(array( + 'controller' => 'posts', 'action' => 'index', 'plugin' => null, 'admin' => false + )); + $this->assertEqual($result, '/posts/index/'); + } + /** * test match() with greedy routes, named parameters and passed args. * @@ -304,6 +342,12 @@ class CakeRouteTestCase extends CakeTestCase { $result = $route->match(array('controller' => 'posts', 'action' => 'view', 'plugin' => null, 5)); $this->assertEqual($result, '/posts/view/5'); + $result = $route->match(array('controller' => 'posts', 'action' => 'view', 'plugin' => null, 0)); + $this->assertEqual($result, '/posts/view/0'); + + $result = $route->match(array('controller' => 'posts', 'action' => 'view', 'plugin' => null, '0')); + $this->assertEqual($result, '/posts/view/0'); + $result = $route->match(array('controller' => 'posts', 'action' => 'view', 'plugin' => null, 5, 'page' => 1, 'limit' => 20, 'order' => 'title')); $this->assertEqual($result, '/posts/view/5/page:1/limit:20/order:title'); @@ -319,6 +363,17 @@ class CakeRouteTestCase extends CakeTestCase { $this->assertFalse($result); } +/** + * test that named params with null/false are excluded + * + * @return void + */ + function testNamedParamsWithNullFalse() { + $route = new CakeRoute('/:controller/:action/*'); + $result = $route->match(array('controller' => 'posts', 'action' => 'index', 'page' => null, 'sort' => false)); + $this->assertEquals('/posts/index/', $result); + } + /** * test that match with patterns works. * @@ -417,4 +472,5 @@ class CakeRouteTestCase extends CakeTestCase { $result = $route->parse('/blog/foobar'); $this->assertFalse($result); } + } \ No newline at end of file diff --git a/cake/tests/cases/libs/router.test.php b/cake/tests/cases/libs/router.test.php index 92c3f0971..930674093 100644 --- a/cake/tests/cases/libs/router.test.php +++ b/cake/tests/cases/libs/router.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -27,8 +26,7 @@ if (!defined('FULL_BASE_URL')) { /** * RouterTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class RouterTest extends CakeTestCase { @@ -383,6 +381,113 @@ class RouterTest extends CakeTestCase { $this->assertEqual($result, $expected); } +/** + * Tests using arrays in named parameters + * + * @return void + */ + function testArrayNamedParameters() { + $result = Router::url(array('controller' => 'tests', 'pages' => array( + 1, 2, 3 + ))); + $expected = '/tests/index/pages[0]:1/pages[1]:2/pages[2]:3'; + $this->assertEqual($result, $expected); + + $result = Router::url(array('controller' => 'tests', + 'pages' => array( + 'param1' => array( + 'one', + 'two' + ), + 'three' + ) + )); + $expected = '/tests/index/pages[param1][0]:one/pages[param1][1]:two/pages[0]:three'; + $this->assertEqual($result, $expected); + + $result = Router::url(array('controller' => 'tests', + 'pages' => array( + 'param1' => array( + 'one' => 1, + 'two' => 2 + ), + 'three' + ) + )); + $expected = '/tests/index/pages[param1][one]:1/pages[param1][two]:2/pages[0]:three'; + $this->assertEqual($result, $expected); + + $result = Router::url(array('controller' => 'tests', + 'super' => array( + 'nested' => array( + 'array' => 'awesome', + 'something' => 'else' + ), + 'cool' + ) + )); + $expected = '/tests/index/super[nested][array]:awesome/super[nested][something]:else/super[0]:cool'; + $this->assertEqual($result, $expected); + + $result = Router::url(array('controller' => 'tests', 'namedParam' => array( + 'keyed' => 'is an array', + 'test' + ))); + $expected = '/tests/index/namedParam[keyed]:is an array/namedParam[0]:test'; + $this->assertEqual($result, $expected); + + $result = Router::parse('/tests/action/var[]:val1/var[]:val2'); + $expected = array( + 'controller' => 'tests', + 'action' => 'action', + 'named' => array( + 'var' => array( + 'val1', + 'val2' + ) + ), + 'pass' => array(), + 'plugin' => null + ); + $this->assertEqual($result, $expected); + + $result = Router::parse('/tests/action/theanswer[is]:42/var[]:val2/var[]:val3'); + $expected = array( + 'controller' => 'tests', + 'action' => 'action', + 'named' => array( + 'theanswer' => array( + 'is' => 42 + ), + 'var' => array( + 'val2', + 'val3' + ) + ), + 'pass' => array(), + 'plugin' => null + ); + $this->assertEqual($result, $expected); + + $result = Router::parse('/tests/action/theanswer[is][not]:42/theanswer[]:5/theanswer[is]:6'); + $expected = array( + 'controller' => 'tests', + 'action' => 'action', + 'named' => array( + 'theanswer' => array( + 5, + 'is' => array( + 6, + 'not' => 42 + ) + ), + ), + 'pass' => array(), + 'plugin' => null + ); + $this->assertEqual($result, $expected); + } + /** * Test generation of routes with query string parameters. * @@ -543,7 +648,7 @@ class RouterTest extends CakeTestCase { $result = Router::url(array('page' => 3)); $expected = '/magazine/admin/subscriptions/index/page:3'; - $this->assertEqual($result, $expected); + $this->assertEquals($expected, $result); Router::reload(); Router::connect('/admin/subscriptions/:action/*', array('controller' => 'subscribe', 'admin' => true, 'prefix' => 'admin')); @@ -1228,14 +1333,14 @@ class RouterTest extends CakeTestCase { Router::reload(); Router::connect('/foo/*', array('controller' => 'bar', 'action' => 'fubar')); - Router::connectNamed(array(), array('argSeparator' => '=')); + Router::connectNamed(array(), array('separator' => '=')); $result = Router::parse('/foo/param1=value1/param2=value2'); $expected = array('pass' => array(), 'named' => array('param1' => 'value1', 'param2' => 'value2'), 'controller' => 'bar', 'action' => 'fubar', 'plugin' => null); $this->assertEqual($result, $expected); Router::reload(); Router::connect('/controller/action/*', array('controller' => 'controller', 'action' => 'action'), array('named' => array('param1' => 'value[\d]'))); - Router::connectNamed(array(), array('greedy' => false, 'argSeparator' => '=')); + Router::connectNamed(array(), array('greedy' => false, 'separator' => '=')); $result = Router::parse('/controller/action/param1=value1/param2=value2'); $expected = array('pass' => array('param2=value2'), 'named' => array('param1' => 'value1'), 'controller' => 'controller', 'action' => 'action', 'plugin' => null); $this->assertEqual($result, $expected); @@ -1243,7 +1348,7 @@ class RouterTest extends CakeTestCase { Router::reload(); Router::connect('/:controller/:action/*'); Router::connectNamed(array('page'), array('default' => false, 'greedy' => false)); - $result = Router::parse('/categories/index?limit=5'); + $result = Router::parse('/categories/index/limit=5'); $this->assertTrue(empty($result['named'])); } @@ -1409,7 +1514,7 @@ class RouterTest extends CakeTestCase { $result = Router::url(array('controller' => 'images', 'action' => 'add')); $expected = '/images/add'; - $this->assertEqual($result, $expected); + $this->assertEquals($expected, $result); $result = Router::url(array('controller' => 'images', 'action' => 'add', 'protected' => true)); $expected = '/protected/images/add'; @@ -2273,7 +2378,7 @@ class RouterTest extends CakeTestCase { * @return void */ function testPatternOnAction() { - $route =& new CakeRoute( + $route = new CakeRoute( '/blog/:action/*', array('controller' => 'blog_posts'), array('action' => 'other|actions') diff --git a/cake/tests/cases/libs/sanitize.test.php b/cake/tests/cases/libs/sanitize.test.php index 35013ca53..c3f420782 100644 --- a/cake/tests/cases/libs/sanitize.test.php +++ b/cake/tests/cases/libs/sanitize.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.5428 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Core', 'Sanitize'); /** * DataTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class SanitizeDataTest extends CakeTestModel { @@ -47,8 +45,7 @@ class SanitizeDataTest extends CakeTestModel { /** * Article class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class SanitizeArticle extends CakeTestModel { @@ -72,8 +69,7 @@ class SanitizeArticle extends CakeTestModel { /** * SanitizeTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class SanitizeTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/security.test.php b/cake/tests/cases/libs/security.test.php index da37e7e7c..a1c7a18af 100644 --- a/cake/tests/cases/libs/security.test.php +++ b/cake/tests/cases/libs/security.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.5432 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Core', 'Security'); /** * SecurityTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class SecurityTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/session/cache_session.test.php b/cake/tests/cases/libs/session/cache_session.test.php index 264318c2a..9f0572cd0 100644 --- a/cake/tests/cases/libs/session/cache_session.test.php +++ b/cake/tests/cases/libs/session/cache_session.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases.libs.session + * @package cake.tests.cases.libs.session * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/cases/libs/session/database_session.test.php b/cake/tests/cases/libs/session/database_session.test.php index 013ea6f2d..b3c457c2d 100644 --- a/cake/tests/cases/libs/session/database_session.test.php +++ b/cake/tests/cases/libs/session/database_session.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.cases.libs.session + * @package cake.tests.cases.libs.session * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -96,7 +95,7 @@ class DatabaseSessionTest extends CakeTestCase { $storage = new DatabaseSession(); $session = ClassRegistry::getObject('session'); - $this->assertType('SessionTestModel', $session); + $this->assertInstanceOf('SessionTestModel', $session); $this->assertEquals('Session', $session->alias); $this->assertEquals('test', $session->useDbConfig); } diff --git a/cake/tests/cases/libs/set.test.php b/cake/tests/cases/libs/set.test.php index 9fbc4086b..c648940bb 100644 --- a/cake/tests/cases/libs/set.test.php +++ b/cake/tests/cases/libs/set.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Core', 'Set'); /** * SetTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class SetTest extends CakeTestCase { @@ -354,6 +352,33 @@ class SetTest extends CakeTestCase { $this->assertEqual($result, $expected); } +/** + * test sorting with out of order keys. + * + * @return void + */ + function testSortWithOutOfOrderKeys() { + $data = array( + 9 => array('class' => 510, 'test2' => 2), + 1 => array('class' => 500, 'test2' => 1), + 2 => array('class' => 600, 'test2' => 2), + 5 => array('class' => 625, 'test2' => 4), + 0 => array('class' => 605, 'test2' => 3), + ); + $expected = array( + array('class' => 500, 'test2' => 1), + array('class' => 510, 'test2' => 2), + array('class' => 600, 'test2' => 2), + array('class' => 605, 'test2' => 3), + array('class' => 625, 'test2' => 4), + ); + $result = Set::sort($data, '{n}.class', 'asc'); + $this->assertEqual($expected, $result); + + $result = Set::sort($data, '{n}.test2', 'asc'); + $this->assertEqual($expected, $result); + } + /** * testExtract method * @@ -2088,20 +2113,6 @@ class SetTest extends CakeTestCase { $result = Set::reverse($class); $this->assertEquals($result, $expected); - $model = new Model(array('id' => false, 'name' => 'Model', 'table' => false)); - $expected = array( - 'Behaviors' => array('modelName' => 'Model'), - 'useDbConfig' => 'default', 'useTable' => false, 'displayField' => null, 'id' => false, 'data' => array(), 'table' => 'models', 'primaryKey' => 'id', 'validate' => array(), - 'validationErrors' => array(), 'tablePrefix' => null, 'name' => 'Model', 'alias' => 'Model', 'tableToModel' => array(), 'logTransactions' => false, 'cacheQueries' => false, - 'belongsTo' => array(), 'hasOne' => array(), 'hasMany' => array(), 'hasAndBelongsToMany' => array(), 'actsAs' => null, 'whitelist' => array(), 'cacheSources' => true, - 'findQueryType' => null, 'recursive' => 1, 'order' => null, 'virtualFields' => array(), -); - $result = Set::reverse($model); - - ksort($result); - ksort($expected); - $this->assertEquals($result, $expected); - $class = new stdClass; $class->User = new stdClass; $class->User->id = 100; @@ -2693,10 +2704,9 @@ class SetTest extends CakeTestCase { /** * Helper method to test Set::apply() * - * @access protected * @return void */ - function _method($val1, $val2) { + static function _method($val1, $val2) { $val1 += $val2; return $val1; } diff --git a/cake/tests/cases/libs/string.test.php b/cake/tests/cases/libs/string.test.php index 1e5e84d54..124e252d7 100644 --- a/cake/tests/cases/libs/string.test.php +++ b/cake/tests/cases/libs/string.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.5432 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Core', 'String'); /** * StringTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class StringTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/test_manager.test.php b/cake/tests/cases/libs/test_manager.test.php index ae4c90dc1..524e77fc3 100644 --- a/cake/tests/cases/libs/test_manager.test.php +++ b/cake/tests/cases/libs/test_manager.test.php @@ -14,8 +14,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -30,8 +29,7 @@ class TestTestManager extends TestManager { /** * TestManagerTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class TestManagerTest extends CakeTestCase { @@ -106,7 +104,7 @@ class TestManagerTest extends CakeTestCase { $file = 'libs/test_manager.test.php'; $result = $this->TestManager->runTestCase($file, $this->Reporter, true); $this->assertEquals(1, $this->_countFiles); - $this->assertType('PHPUnit_Framework_TestResult', $result); + $this->assertInstanceOf('PHPUnit_Framework_TestResult', $result); } } diff --git a/cake/tests/cases/libs/validation.test.php b/cake/tests/cases/libs/validation.test.php index 89b58b4ea..2766823b9 100644 --- a/cake/tests/cases/libs/validation.test.php +++ b/cake/tests/cases/libs/validation.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Core', 'Validation'); /** * CustomValidator class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class CustomValidator { @@ -34,7 +32,7 @@ class CustomValidator { * @return boolean * @access public */ - function customValidate($check) { + static function customValidate($check) { return (bool)preg_match('/^[0-9]{3}$/', $check); } } @@ -53,7 +51,7 @@ class TestNlValidation { * @param string $check * @return void */ - function postal($check) { + static function postal($check) { return true; } /** @@ -61,7 +59,7 @@ class TestNlValidation { * * @return void */ - function ssn($check) { + static function ssn($check) { return true; } } @@ -80,7 +78,7 @@ class TestDeValidation { * @param string $check * @return void */ - function phone($check) { + static function phone($check) { return true; } } @@ -88,8 +86,7 @@ class TestDeValidation { /** * Test Case for Validation Class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class ValidationTest extends CakeTestCase { @@ -1813,6 +1810,39 @@ class ValidationTest extends CakeTestCase { $this->assertFalse(Validation::url('www.cakephp.org', true)); $this->assertTrue(Validation::url('http://www.cakephp.org', true)); $this->assertTrue(Validation::url('http://example.com/~userdir/')); + + $this->assertTrue(Validation::url('http://example.com/~userdir/subdir/index.html')); + $this->assertTrue(Validation::url('http://www.zwischenraume.de')); + $this->assertTrue(Validation::url('http://www.zwischenraume.cz')); + $this->assertTrue(Validation::url('http://www.last.fm/music/浜崎あゆみ'), 'utf8 path failed'); + + $this->assertTrue(Validation::url('http://cakephp.org:80')); + $this->assertTrue(Validation::url('http://cakephp.org:443')); + $this->assertTrue(Validation::url('http://cakephp.org:2000')); + $this->assertTrue(Validation::url('http://cakephp.org:27000')); + $this->assertTrue(Validation::url('http://cakephp.org:65000')); + + $this->assertTrue(Validation::url('[2001:0db8::1428:57ab]')); + $this->assertTrue(Validation::url('[::1]')); + $this->assertTrue(Validation::url('[2001:0db8::1428:57ab]:80')); + $this->assertTrue(Validation::url('[::1]:80')); + $this->assertTrue(Validation::url('http://[2001:0db8::1428:57ab]')); + $this->assertTrue(Validation::url('http://[::1]')); + $this->assertTrue(Validation::url('http://[2001:0db8::1428:57ab]:80')); + $this->assertTrue(Validation::url('http://[::1]:80')); + + $this->assertFalse(Validation::url('[1::2::3]')); + } + + function testUuid() { + $this->assertTrue(Validation::uuid('550e8400-e29b-11d4-a716-446655440000')); + $this->assertFalse(Validation::uuid('BRAP-e29b-11d4-a716-446655440000')); + $this->assertTrue(Validation::uuid('550E8400-e29b-11D4-A716-446655440000')); + $this->assertFalse(Validation::uuid('550e8400-e29b11d4-a716-446655440000')); + $this->assertFalse(Validation::uuid('550e8400-e29b-11d4-a716-4466440000')); + $this->assertFalse(Validation::uuid('550e8400-e29b-11d4-a71-446655440000')); + $this->assertFalse(Validation::uuid('550e8400-e29b-11d-a716-446655440000')); + $this->assertFalse(Validation::uuid('550e8400-e29-11d4-a716-446655440000')); } /** diff --git a/cake/tests/cases/libs/view/helper.test.php b/cake/tests/cases/libs/view/helper.test.php index b30c2a767..44b38f903 100644 --- a/cake/tests/cases/libs/view/helper.test.php +++ b/cake/tests/cases/libs/view/helper.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Core', array('View', 'Helper', 'Router')); /** * HelperTestPost class * - * @package cake - * @subpackage cake.tests.cases.libs.view + * @package cake.tests.cases.libs.view */ class HelperTestPost extends Model { @@ -41,7 +39,7 @@ class HelperTestPost extends Model { * @access public * @return void */ - function schema() { + function schema($field = false) { $this->_schema = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'), 'title' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), @@ -66,8 +64,7 @@ class HelperTestPost extends Model { /** * HelperTestComment class * - * @package cake - * @subpackage cake.tests.cases.libs.view + * @package cake.tests.cases.libs.view */ class HelperTestComment extends Model { @@ -85,7 +82,7 @@ class HelperTestComment extends Model { * @access public * @return void */ - function schema() { + function schema($field = false) { $this->_schema = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'), 'author_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'), @@ -101,8 +98,7 @@ class HelperTestComment extends Model { /** * HelperTestTag class * - * @package cake - * @subpackage cake.tests.cases.libs.view + * @package cake.tests.cases.libs.view */ class HelperTestTag extends Model { @@ -120,7 +116,7 @@ class HelperTestTag extends Model { * @access public * @return void */ - function schema() { + function schema($field = false) { $this->_schema = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'), 'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), @@ -134,8 +130,7 @@ class HelperTestTag extends Model { /** * HelperTestPostsTag class * - * @package cake - * @subpackage cake.tests.cases.libs.view + * @package cake.tests.cases.libs.view */ class HelperTestPostsTag extends Model { @@ -153,7 +148,7 @@ class HelperTestPostsTag extends Model { * @access public * @return void */ - function schema() { + function schema($field = false) { $this->_schema = array( 'helper_test_post_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'), 'helper_test_tag_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'), @@ -184,11 +179,39 @@ class TestHelper extends Helper { } } +/** + * Html5TestHelper class + * + * @package cake.tests.cases.libs.view + */ +class Html5TestHelper extends TestHelper { + +/** + * Minimized + * + * @var array + */ + protected $_minimizedAttributes = array('require', 'checked'); + +/** + * Allow compact use in HTML + * + * @var string + */ + protected $_minimizedAttributeFormat = '%s'; + +/** + * Test to attribute format + * + * @var string + */ + protected $_attributeFormat = 'data-%s="%s"'; +} + /** * HelperTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs.view */ class HelperTest extends CakeTestCase { @@ -809,6 +832,13 @@ class HelperTest extends CakeTestCase { $this->assertEqual($helper->parseAttributes($attrs), $expected, '%s Failed on ' . $value); } } + $this->assertEqual($helper->parseAttributes(array('compact')), ' compact="compact"'); + + $helper = new Html5TestHelper($this->View); + $expected = ' require'; + $this->assertEqual($helper->parseAttributes(array('require')), $expected); + $this->assertEqual($helper->parseAttributes(array('require' => true)), $expected); + $this->assertEqual($helper->parseAttributes(array('require' => false)), ''); } /** @@ -821,8 +851,8 @@ class HelperTest extends CakeTestCase { 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS), )); $Helper = new TestHelper($this->View); - $this->assertType('OtherHelperHelper', $Helper->OtherHelper); - $this->assertType('HtmlHelper', $Helper->Html); + $this->assertInstanceOf('OtherHelperHelper', $Helper->OtherHelper); + $this->assertInstanceOf('HtmlHelper', $Helper->Html); App::build(); } diff --git a/cake/tests/cases/libs/view/helper_collection.test.php b/cake/tests/cases/libs/view/helper_collection.test.php index 8d60f0109..e87d67a2b 100644 --- a/cake/tests/cases/libs/view/helper_collection.test.php +++ b/cake/tests/cases/libs/view/helper_collection.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -48,8 +47,8 @@ class HelperCollectionTest extends CakeTestCase { */ function testLoad() { $result = $this->Helpers->load('Html'); - $this->assertType('HtmlHelper', $result); - $this->assertType('HtmlHelper', $this->Helpers->Html); + $this->assertInstanceOf('HtmlHelper', $result); + $this->assertInstanceOf('HtmlHelper', $this->Helpers->Html); $result = $this->Helpers->attached(); $this->assertEquals(array('Html'), $result, 'attached() results are wrong.'); @@ -64,8 +63,8 @@ class HelperCollectionTest extends CakeTestCase { */ function testLoadWithEnabledFalse() { $result = $this->Helpers->load('Html', array('enabled' => false)); - $this->assertType('HtmlHelper', $result); - $this->assertType('HtmlHelper', $this->Helpers->Html); + $this->assertInstanceOf('HtmlHelper', $result); + $this->assertInstanceOf('HtmlHelper', $this->Helpers->Html); $this->assertFalse($this->Helpers->enabled('Html'), 'Html should be disabled'); } @@ -90,8 +89,8 @@ class HelperCollectionTest extends CakeTestCase { 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS), )); $result = $this->Helpers->load('TestPlugin.OtherHelper'); - $this->assertType('OtherHelperHelper', $result, 'Helper class is wrong.'); - $this->assertType('OtherHelperHelper', $this->Helpers->OtherHelper, 'Class is wrong'); + $this->assertInstanceOf('OtherHelperHelper', $result, 'Helper class is wrong.'); + $this->assertInstanceOf('OtherHelperHelper', $this->Helpers->OtherHelper, 'Class is wrong'); App::build(); } @@ -116,75 +115,4 @@ class HelperCollectionTest extends CakeTestCase { $this->assertEquals(array('Form'), $result, 'loaded helpers is wrong'); } -/** - * test triggering callbacks. - * - * @return void - */ - function testTrigger() { - if (!class_exists('TriggerMockHtmlHelper')) { - $this->getMock('HtmlHelper', array(), array($this->View), 'TriggerMockHtmlHelper'); - $this->getMock('FormHelper', array(), array($this->View), 'TriggerMockFormHelper'); - } - - $this->Helpers->load('TriggerMockHtml'); - $this->Helpers->load('TriggerMockForm'); - - $this->Helpers->TriggerMockHtml->expects($this->once())->method('beforeRender') - ->with('one', 'two'); - $this->Helpers->TriggerMockForm->expects($this->once())->method('beforeRender') - ->with('one', 'two'); - - $this->mockObjects[] = $this->Helpers->TriggerMockForm; - - $this->assertTrue($this->Helpers->trigger('beforeRender', array('one', 'two'))); - } - -/** - * test trigger and disabled helpers. - * - * @return void - */ - function testTriggerWithDisabledHelpers() { - if (!class_exists('TriggerMockHtmlHelper')) { - $this->getMock('HtmlHelper', array(), array(), 'TriggerMockHtmlHelper', false); - $this->getMock('FormHelper', array(), array(), 'TriggerMockFormHelper', false); - } - - $this->Helpers->load('TriggerMockHtml'); - $this->Helpers->load('TriggerMockForm'); - - $this->Helpers->TriggerMockHtml->expects($this->once())->method('beforeRender') - ->with('one', 'two'); - $this->Helpers->TriggerMockForm->expects($this->never())->method('beforeRender'); - - $this->mockObjects[] = $this->Helpers->TriggerMockForm; - $this->mockObjects[] = $this->Helpers->TriggerMockHtml; - - $this->Helpers->disable('TriggerMockForm'); - - $this->assertTrue($this->Helpers->trigger('beforeRender', array('one', 'two'))); - } - -/** - * test normalizeObjectArray - * - * @return void - */ - function testnormalizeObjectArray() { - $helpers = array( - 'Html', - 'Foo.Bar' => array('one', 'two'), - 'Something', - 'Banana.Apple' => array('foo' => 'bar') - ); - $result = ObjectCollection::normalizeObjectArray($helpers); - $expected = array( - 'Html' => array('class' => 'Html', 'settings' => array()), - 'Bar' => array('class' => 'Foo.Bar', 'settings' => array('one', 'two')), - 'Something' => array('class' => 'Something', 'settings' => array()), - 'Apple' => array('class' => 'Banana.Apple', 'settings' => array('foo' => 'bar')), - ); - $this->assertEquals($expected, $result); - } } \ No newline at end of file diff --git a/cake/tests/cases/libs/view/helpers/cache.test.php b/cake/tests/cases/libs/view/helpers/cache.test.php index 95d8e9a01..cc08e4d83 100644 --- a/cake/tests/cases/libs/view/helpers/cache.test.php +++ b/cake/tests/cases/libs/view/helpers/cache.test.php @@ -12,8 +12,7 @@ * * @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.view.helpers + * @package cake.tests.cases.libs.view.helpers * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ App::import('Helper', 'Cache'); /** * CacheTestController class * - * @package cake - * @subpackage cake.tests.cases.libs.view.helpers + * @package cake.tests.cases.libs.view.helpers */ class CacheTestController extends Controller { @@ -55,8 +53,7 @@ class CacheTestController extends Controller { /** * CacheHelperTest class * - * @package cake - * @subpackage cake.tests.cases.libs.view.helpers + * @package cake.tests.cases.libs.view.helpers */ class CacheHelperTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 494fa778b..dccaf21c0 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests - * @package cake - * @subpackage cake.tests.cases.libs.view.helpers + * @package cake.tests.cases.libs.view.helpers * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,7 +24,7 @@ App::import('Helper', 'Form'); * ContactTestController class * * @package cake - * @subpackage cake.tests.cases.libs.view.helpers + * @package cake.tests.cases.libs.view.helpers */ class ContactTestController extends Controller { @@ -50,7 +49,7 @@ class ContactTestController extends Controller { * Contact class * * @package cake - * @subpackage cake.tests.cases.libs.view.helpers + * @package cake.tests.cases.libs.view.helpers */ class Contact extends CakeTestModel { @@ -147,7 +146,7 @@ class Contact extends CakeTestModel { * ContactTagsContact class * * @package cake - * @subpackage cake.tests.cases.libs.view.helpers + * @package cake.tests.cases.libs.view.helpers */ class ContactTagsContact extends CakeTestModel { @@ -195,7 +194,7 @@ class ContactTagsContact extends CakeTestModel { * ContactNonStandardPk class * * @package cake - * @subpackage cake.tests.cases.libs.view.helpers + * @package cake.tests.cases.libs.view.helpers */ class ContactNonStandardPk extends Contact { @@ -221,7 +220,7 @@ class ContactNonStandardPk extends Contact { * @access public * @return void */ - function schema() { + function schema($field = false) { $this->_schema = parent::schema(); $this->_schema['pk'] = $this->_schema['id']; unset($this->_schema['id']); @@ -233,7 +232,7 @@ class ContactNonStandardPk extends Contact { * ContactTag class * * @package cake - * @subpackage cake.tests.cases.libs.view.helpers + * @package cake.tests.cases.libs.view.helpers */ class ContactTag extends Model { @@ -263,7 +262,7 @@ class ContactTag extends Model { * UserForm class * * @package cake - * @subpackage cake.tests.cases.libs.view.helpers + * @package cake.tests.cases.libs.view.helpers */ class UserForm extends CakeTestModel { @@ -323,7 +322,7 @@ class UserForm extends CakeTestModel { * OpenidUrl class * * @package cake - * @subpackage cake.tests.cases.libs.view.helpers + * @package cake.tests.cases.libs.view.helpers */ class OpenidUrl extends CakeTestModel { @@ -389,7 +388,7 @@ class OpenidUrl extends CakeTestModel { * @access public * @return void */ - function beforeValidate() { + function beforeValidate($options = array()) { $this->invalidate('openid_not_registered'); return true; } @@ -399,7 +398,7 @@ class OpenidUrl extends CakeTestModel { * ValidateUser class * * @package cake - * @subpackage cake.tests.cases.libs.view.helpers + * @package cake.tests.cases.libs.view.helpers */ class ValidateUser extends CakeTestModel { @@ -458,7 +457,7 @@ class ValidateUser extends CakeTestModel { * @access public * @return void */ - function beforeValidate() { + function beforeValidate($options = array()) { $this->invalidate('email'); return false; } @@ -468,7 +467,7 @@ class ValidateUser extends CakeTestModel { * ValidateProfile class * * @package cake - * @subpackage cake.tests.cases.libs.view.helpers + * @package cake.tests.cases.libs.view.helpers */ class ValidateProfile extends CakeTestModel { @@ -537,7 +536,7 @@ class ValidateProfile extends CakeTestModel { * @access public * @return void */ - function beforeValidate() { + function beforeValidate($options = array()) { $this->invalidate('full_name'); $this->invalidate('city'); return false; @@ -548,7 +547,7 @@ class ValidateProfile extends CakeTestModel { * ValidateItem class * * @package cake - * @subpackage cake.tests.cases.libs.view.helpers + * @package cake.tests.cases.libs.view.helpers */ class ValidateItem extends CakeTestModel { @@ -607,7 +606,7 @@ class ValidateItem extends CakeTestModel { * @access public * @return void */ - function beforeValidate() { + function beforeValidate($options = array()) { $this->invalidate('description'); return false; } @@ -617,7 +616,7 @@ class ValidateItem extends CakeTestModel { * TestMail class * * @package cake - * @subpackage cake.tests.cases.libs.view.helpers + * @package cake.tests.cases.libs.view.helpers */ class TestMail extends CakeTestModel { @@ -650,7 +649,7 @@ class TestMail extends CakeTestModel { * FormHelperTest class * * @package cake - * @subpackage cake.tests.cases.libs.view.helpers + * @package cake.tests.cases.libs.view.helpers */ class FormHelperTest extends CakeTestCase { @@ -829,7 +828,7 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->secure($fields); $expected = Security::hash(serialize($fields) . Configure::read('Security.salt')); - $expected .= ':' . str_rot13(serialize(array('Model.valid'))); + $expected .= ':' . 'Model.valid'; $expected = array( 'div' => array('style' => 'display:none;'), @@ -891,9 +890,8 @@ class FormHelperTest extends CakeTestCase { $this->Form->request['_Token'] = array('key' => $key); $result = $this->Form->secure($fields); - $hash = '51e3b55a6edd82020b3f29c9ae200e14bbeb7ee5%3An%3A4%3A%7Bv%3A0%3Bf%3A14%3A%22Zbqry.'; - $hash .= '0.uvqqra%22%3Bv%3A1%3Bf%3A13%3A%22Zbqry.0.inyvq%22%3Bv%3A2%3Bf%3A14%3A%22Zbqry.1'; - $hash .= '.uvqqra%22%3Bv%3A3%3Bf%3A13%3A%22Zbqry.1.inyvq%22%3B%7D'; + $hash = '51e3b55a6edd82020b3f29c9ae200e14bbeb7ee5%3AModel.0.hidden%7CModel.0.valid'; + $hash .= '%7CModel.1.hidden%7CModel.1.valid'; $expected = array( 'div' => array('style' => 'display:none;'), @@ -982,8 +980,7 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->secure($this->Form->fields); - $hash = 'c9118120e680a7201b543f562e5301006ccfcbe2%3An%3A2%3A%7Bv%3A0%3Bf%3A14%'; - $hash .= '3A%22Nqqerffrf.0.vq%22%3Bv%3A1%3Bf%3A14%3A%22Nqqerffrf.1.vq%22%3B%7D'; + $hash = 'c9118120e680a7201b543f562e5301006ccfcbe2%3AAddresses.0.id%7CAddresses.1.id'; $expected = array( 'div' => array('style' => 'display:none;'), @@ -1028,8 +1025,7 @@ class FormHelperTest extends CakeTestCase { $this->Form->input('Addresses.1.phone'); $result = $this->Form->secure($this->Form->fields); - $hash = '774df31936dc850b7d8a5277dc0b890123788b09%3An%3A2%3A%7Bv%3A0%3Bf%3A14%3A%22Nqqerf'; - $hash .= 'frf.0.vq%22%3Bv%3A1%3Bf%3A14%3A%22Nqqerffrf.1.vq%22%3B%7D'; + $hash = '774df31936dc850b7d8a5277dc0b890123788b09%3AAddresses.0.id%7CAddresses.1.id'; $expected = array( 'div' => array('style' => 'display:none;'), @@ -1075,8 +1071,7 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->secure($expected); - $hash = '449b7e889128e8e52c5e81d19df68f5346571492%3An%3A1%3A%'; - $hash .= '7Bv%3A0%3Bf%3A12%3A%22Nqqerffrf.vq%22%3B%7D'; + $hash = '449b7e889128e8e52c5e81d19df68f5346571492%3AAddresses.id'; $expected = array( 'div' => array('style' => 'display:none;'), 'input' => array( @@ -1180,8 +1175,7 @@ class FormHelperTest extends CakeTestCase { ); $this->assertEqual($result, $expected); - $hash = 'bd7c4a654e5361f9a433a43f488ff9a1065d0aaf%3An%3A2%3A%7Bv%3A0%3Bf%3A15%3'; - $hash .= 'A%22HfreSbez.uvqqra%22%3Bv%3A1%3Bf%3A14%3A%22HfreSbez.fghss%22%3B%7D'; + $hash = 'bd7c4a654e5361f9a433a43f488ff9a1065d0aaf%3AUserForm.hidden%7CUserForm.stuff'; $result = $this->Form->secure($this->Form->fields); $expected = array( @@ -3567,7 +3561,7 @@ class FormHelperTest extends CakeTestCase { $this->assertEqual($this->Form->fields, array('Model.multi_field')); $result = $this->Form->secure($this->Form->fields); - $key = 'f7d573650a295b94e0938d32b323fde775e5f32b%3An%3A0%3A%7B%7D'; + $key = 'f7d573650a295b94e0938d32b323fde775e5f32b%3A'; $this->assertPattern('/"' . $key . '"/', $result); } @@ -6705,7 +6699,7 @@ class FormHelperTest extends CakeTestCase { /** * - * @expectedException Exception + * @expectedException CakeException * @return void */ function testHtml5InputException() { diff --git a/cake/tests/cases/libs/view/helpers/html.test.php b/cake/tests/cases/libs/view/helpers/html.test.php index 2defe93ab..142fe91b5 100644 --- a/cake/tests/cases/libs/view/helpers/html.test.php +++ b/cake/tests/cases/libs/view/helpers/html.test.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests - * @package cake - * @subpackage cake.tests.cases.libs.view.helpers + * @package cake.tests.cases.libs.view.helpers * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -27,8 +26,7 @@ if (!defined('FULL_BASE_URL')) { /** * TheHtmlTestController class * - * @package cake - * @subpackage cake.tests.cases.libs.view.helpers + * @package cake.tests.cases.libs.view.helpers */ class TheHtmlTestController extends Controller { @@ -52,8 +50,7 @@ class TheHtmlTestController extends Controller { /** * HtmlHelperTest class * - * @package cake - * @subpackage cake.tests.cases.libs.view.helpers + * @package cake.tests.cases.libs.view.helpers */ class HtmlHelperTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/view/helpers/jquery_engine.test.php b/cake/tests/cases/libs/view/helpers/jquery_engine.test.php index 87c2b8b2b..868581ff6 100644 --- a/cake/tests/cases/libs/view/helpers/jquery_engine.test.php +++ b/cake/tests/cases/libs/view/helpers/jquery_engine.test.php @@ -15,7 +15,7 @@ * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project * @package cake.tests - * @subpackage cake.tests.cases.views.helpers + * @package cake.tests.cases.views.helpers * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ App::import('Helper', array('Html', 'Js', 'JqueryEngine')); diff --git a/cake/tests/cases/libs/view/helpers/js.test.php b/cake/tests/cases/libs/view/helpers/js.test.php index 1fd1602a7..8926ab94e 100644 --- a/cake/tests/cases/libs/view/helpers/js.test.php +++ b/cake/tests/cases/libs/view/helpers/js.test.php @@ -14,8 +14,7 @@ * * @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.view.helpers + * @package cake.tests.cases.libs.view.helpers * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -64,8 +63,7 @@ class OptionEngineHelper extends JsBaseEngineHelper { /** * JsHelper TestCase. * - * @package cake - * @subpackage cake.tests.cases.libs.view.helpers + * @package cake.tests.cases.libs.view.helpers */ class JsHelperTest extends CakeTestCase { /** diff --git a/cake/tests/cases/libs/view/helpers/mootools_engine.test.php b/cake/tests/cases/libs/view/helpers/mootools_engine.test.php index 53af75a80..1b44d4497 100644 --- a/cake/tests/cases/libs/view/helpers/mootools_engine.test.php +++ b/cake/tests/cases/libs/view/helpers/mootools_engine.test.php @@ -17,7 +17,7 @@ * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project * @package cake.tests - * @subpackage cake.tests.cases.views.helpers + * @package cake.tests.cases.views.helpers * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ App::import('Helper', array('Html', 'Js', 'MootoolsEngine')); diff --git a/cake/tests/cases/libs/view/helpers/number.test.php b/cake/tests/cases/libs/view/helpers/number.test.php index 1d1d04c4c..99857df99 100644 --- a/cake/tests/cases/libs/view/helpers/number.test.php +++ b/cake/tests/cases/libs/view/helpers/number.test.php @@ -12,18 +12,17 @@ * * @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.view.helpers + * @package cake.tests.cases.libs.view.helpers * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ App::import('Helper', 'Number'); +App::import('View', 'View'); /** * NumberHelperTest class * - * @package cake - * @subpackage cake.tests.cases.libs.view.helpers + * @package cake.tests.cases.libs.view.helpers */ class NumberHelperTest extends CakeTestCase { @@ -322,6 +321,14 @@ class NumberHelperTest extends CakeTestCase { $expected = '£1,234,568'; $this->assertEqual($expected, $result); + $result = $this->Number->currency('1234567.8912345', null, array('before' => 'GBP', 'places' => 3)); + $expected = 'GBP1,234,567.891'; + $this->assertEqual($expected, $result); + + $result = $this->Number->currency('650.120001', null, array('before' => 'GBP', 'places' => 4)); + $expected = 'GBP650.1200'; + $this->assertEqual($expected, $result); + $result = $this->Number->currency($value, 'GBP', array('escape' => true)); $expected = '&#163;1,234,567.89'; $this->assertEqual($expected, $result); diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php index 2d0bda4a9..ce4497536 100644 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/cake/tests/cases/libs/view/helpers/paginator.test.php @@ -12,8 +12,7 @@ * * @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.view.helpers + * @package cake.tests.cases.libs.view.helpers * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -27,8 +26,7 @@ if (!defined('FULL_BASE_URL')) { /** * PaginatorHelperTest class * - * @package cake - * @subpackage cake.tests.cases.libs.view.helpers + * @package cake.tests.cases.libs.view.helpers */ class PaginatorHelperTest extends CakeTestCase { @@ -47,22 +45,17 @@ class PaginatorHelperTest extends CakeTestCase { $this->Paginator->request->addParams(array( 'paging' => array( 'Article' => array( + 'page' => 2, 'current' => 9, 'count' => 62, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 7, - 'defaults' => array( - 'order' => array('Article.date' => 'asc'), - 'limit' => 9, - 'conditions' => array() - ), 'options' => array( - 'order' => array('Article.date' => 'asc'), - 'limit' => 9, 'page' => 1, 'conditions' => array() - ) + ), + 'paramType' => 'named' ) ) )); @@ -139,10 +132,26 @@ class PaginatorHelperTest extends CakeTestCase { Router::reload(); Router::parse('/'); Router::setRequestInfo(array( - array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/'), 'bare' => 0), - array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/', 'passedArgs' => array()) + array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'url' => array('url' => 'accounts/')), + array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/') )); $this->Paginator->options(array('url' => array('param'))); + $this->Paginator->request['paging'] = array( + 'Article' => array( + 'current' => 9, + 'count' => 62, + 'prevPage' => false, + 'nextPage' => true, + 'pageCount' => 7, + 'options' => array( + 'page' => 1, + 'order' => array('date' => 'asc'), + 'conditions' => array() + ), + 'paramType' => 'named' + ) + ); + $result = $this->Paginator->sort('title'); $expected = array( 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:asc'), @@ -279,9 +288,8 @@ class PaginatorHelperTest extends CakeTestCase { Router::parse('/'); Router::setRequestInfo(array( array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), - 'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0), - array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/', 'here' => '/accounts/', - 'webroot' => '/', 'passedArgs' => array()) + 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true')), + array('base' => '/', 'here' => '/accounts/', 'webroot' => '/',) )); $this->Paginator->options(array('url' => array('param'))); @@ -313,7 +321,7 @@ class PaginatorHelperTest extends CakeTestCase { Router::parse('/'); Router::setRequestInfo(array( array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0), - array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/', 'passedArgs' => array()) + array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/') )); $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc'); @@ -444,7 +452,7 @@ class PaginatorHelperTest extends CakeTestCase { Router::reload(); Router::setRequestInfo(array( - array('pass' => array(), 'named' => array(), 'controller' => 'users', 'plugin' => null, 'action' => 'admin_index', 'prefix' => 'admin', 'admin' => true, 'url' => array('ext' => 'html', 'url' => 'admin/users'), 'form' => array()), + array('pass' => array(), 'named' => array(), 'controller' => 'users', 'plugin' => null, 'action' => 'admin_index', 'prefix' => 'admin', 'admin' => true, 'url' => array('ext' => 'html', 'url' => 'admin/users')), array('base' => '', 'here' => '/admin/users', 'webroot' => '/') )); Router::parse('/admin/users'); @@ -452,7 +460,7 @@ class PaginatorHelperTest extends CakeTestCase { $result = $this->Paginator->next('Next'); $expected = array( ' array('href' => '/admin/users/index/page:2', 'class' => 'next'), + 'a' => array('href' => '/admin/users/index/page:2', 'class' => 'next', 'rel' => 'next'), 'Next', '/a', '/span' @@ -461,8 +469,8 @@ class PaginatorHelperTest extends CakeTestCase { Router::reload(); Router::setRequestInfo(array( - array('plugin' => null, 'controller' => 'test', 'action' => 'admin_index', 'pass' => array(), 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/test')), - array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/test', 'webroot' => '/') + array('plugin' => null, 'controller' => 'test', 'action' => 'admin_index', 'pass' => array(), 'prefix' => 'admin', 'admin' => true, 'url' => array('url' => 'admin/test')), + array('base' => '', 'here' => '/admin/test', 'webroot' => '/') )); Router::parse('/'); $this->Paginator->options(array('url' => array('param'))); @@ -532,7 +540,7 @@ class PaginatorHelperTest extends CakeTestCase { Router::setRequestInfo( array( array('controller' => 'posts', 'action' => 'index', 'form' => array(), 'url' => array(), 'plugin' => null), - array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => 'posts/index', 'webroot' => '/') + array('base' => '', 'here' => 'posts/index', 'webroot' => '/') )); $this->Paginator->request->params['paging']['Article']['options']['page'] = 2; @@ -555,7 +563,7 @@ class PaginatorHelperTest extends CakeTestCase { $result = $this->Paginator->next('next', array('url' => $options)); $expected = array( ' array('href' => '/members/posts/index/page:3', 'class' => 'next'), + 'a' => array('href' => '/members/posts/index/page:3', 'class' => 'next', 'rel' => 'next'), 'next', '/a', '/span' @@ -565,7 +573,7 @@ class PaginatorHelperTest extends CakeTestCase { $result = $this->Paginator->prev('prev', array('url' => $options)); $expected = array( ' array('href' => '/members/posts/index/page:1', 'class' => 'prev'), + 'a' => array('href' => '/members/posts/index/page:1', 'class' => 'prev', 'rel' => 'prev'), 'prev', '/a', '/span' @@ -643,19 +651,19 @@ class PaginatorHelperTest extends CakeTestCase { Router::reload(); Router::parse('/'); Router::setRequestInfo(array( - array('plugin' => null, 'controller' => 'articles', 'action' => 'index', 'pass' => array('2'), 'named' => array('foo' => 'bar'), 'form' => array(), 'url' => array('url' => 'articles/index/2/foo:bar'), 'bare' => 0), - array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/', 'here' => '/articles/', 'webroot' => '/', 'passedArgs' => array(0 => '2', 'foo' => 'bar')) + array('plugin' => null, 'controller' => 'articles', 'action' => 'index', 'pass' => array('2'), 'named' => array('foo' => 'bar'), 'url' => array('url' => 'articles/index/2/foo:bar')), + array('base' => '/', 'here' => '/articles/', 'webroot' => '/') )); $this->Paginator->request->params['paging'] = array( 'Article' => array( 'page' => 1, 'current' => 3, 'count' => 13, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 8, - 'defaults' => array( - 'limit' => 3, 'step' => 1, 'order' => array(), 'conditions' => array() - ), 'options' => array( - 'page' => 1, 'limit' => 3, 'order' => array(), 'conditions' => array() - ) + 'page' => 1, + 'order' => array(), + 'conditions' => array() + ), + 'paramType' => 'named' ) ); @@ -692,7 +700,7 @@ class PaginatorHelperTest extends CakeTestCase { $result = $this->Paginator->next('Next'); $expected = array( ' array('href' => '/articles/index/2/page:2/foo:bar', 'class' => 'next'), + 'a' => array('href' => '/articles/index/2/page:2/foo:bar', 'class' => 'next', 'rel' => 'next'), 'Next', '/a', '/span' @@ -707,10 +715,19 @@ class PaginatorHelperTest extends CakeTestCase { * @return void */ function testPagingLinks() { - $this->Paginator->request->params['paging'] = array('Client' => array( - 'page' => 1, 'current' => 3, 'count' => 13, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 5, - 'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()), - 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())) + $this->Paginator->request->params['paging'] = array( + 'Client' => array( + 'page' => 1, + 'current' => 3, + 'count' => 13, + 'prevPage' => false, + 'nextPage' => true, + 'pageCount' => 5, + 'options' => array( + 'page' => 1, + ), + 'paramType' => 'named' + ) ); $result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled')); $expected = array( @@ -733,7 +750,7 @@ class PaginatorHelperTest extends CakeTestCase { $result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled')); $expected = array( ' array('href' => '/index/page:1', 'class' => 'prev'), + 'a' => array('href' => '/index/page:1', 'class' => 'prev', 'rel' => 'prev'), '<< Previous', '/a', '/span' @@ -743,7 +760,7 @@ class PaginatorHelperTest extends CakeTestCase { $result = $this->Paginator->next('Next'); $expected = array( ' array('href' => '/index/page:3', 'class' => 'next'), + 'a' => array('href' => '/index/page:3', 'class' => 'next', 'rel' => 'next'), 'Next', '/a', '/span' @@ -753,7 +770,7 @@ class PaginatorHelperTest extends CakeTestCase { $result = $this->Paginator->next('Next', array('tag' => 'li')); $expected = array( ' array('href' => '/index/page:3', 'class' => 'next'), + 'a' => array('href' => '/index/page:3', 'class' => 'next', 'rel' => 'next'), 'Next', '/a', '/li' @@ -763,7 +780,7 @@ class PaginatorHelperTest extends CakeTestCase { $result = $this->Paginator->prev('<< Previous', array('escape' => true)); $expected = array( ' array('href' => '/index/page:1', 'class' => 'prev'), + 'a' => array('href' => '/index/page:1', 'class' => 'prev', 'rel' => 'prev'), '<< Previous', '/a', '/span' @@ -773,17 +790,26 @@ class PaginatorHelperTest extends CakeTestCase { $result = $this->Paginator->prev('<< Previous', array('escape' => false)); $expected = array( ' array('href' => '/index/page:1', 'class' => 'prev'), + 'a' => array('href' => '/index/page:1', 'class' => 'prev', 'rel' => 'prev'), 'preg:/<< Previous/', '/a', '/span' ); $this->assertTags($result, $expected); - $this->Paginator->request->params['paging'] = array('Client' => array( - 'page' => 1, 'current' => 1, 'count' => 13, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 5, - 'defaults' => array(), - 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())) + $this->Paginator->request->params['paging'] = array( + 'Client' => array( + 'page' => 1, + 'current' => 1, + 'count' => 13, + 'prevPage' => false, + 'nextPage' => true, + 'pageCount' => 5, + 'options' => array( + 'page' => 1, + ), + 'paramType' => 'named' + ) ); $result = $this->Paginator->prev('<< Previous', null, 'Disabled'); @@ -810,10 +836,21 @@ class PaginatorHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $this->Paginator->request->params['paging'] = array('Client' => array( - 'page' => 1, 'current' => 3, 'count' => 13, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 5, - 'defaults' => array(), - 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())) + $this->Paginator->request->params['paging'] = array( + 'Client' => array( + 'page' => 1, + 'current' => 3, + 'count' => 13, + 'prevPage' => false, + 'nextPage' => true, + 'pageCount' => 5, + 'options' => array( + 'page' => 1, + 'limit' => 3, + 'order' => array('Client.name' => 'DESC'), + ), + 'paramType' => 'named' + ) ); $this->Paginator->request->params['paging']['Client']['page'] = 2; @@ -821,7 +858,11 @@ class PaginatorHelperTest extends CakeTestCase { $result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled')); $expected = array( ' array('href' => '/index/page:1/limit:3/sort:Client.name/direction:DESC', 'class' => 'prev'), + 'a' => array( + 'href' => '/index/page:1/limit:3/sort:Client.name/direction:DESC', + 'class' => 'prev', + 'rel' => 'prev' + ), '<< Previous', '/a', '/span' @@ -831,22 +872,38 @@ class PaginatorHelperTest extends CakeTestCase { $result = $this->Paginator->next('Next'); $expected = array( ' array('href' => '/index/page:3/limit:3/sort:Client.name/direction:DESC', 'class' => 'next'), + 'a' => array( + 'href' => '/index/page:3/limit:3/sort:Client.name/direction:DESC', + 'class' => 'next', + 'rel' => 'next' + ), 'Next', '/a', '/span' ); $this->assertTags($result, $expected); - $this->Paginator->request->params['paging'] = array('Client' => array( - 'page' => 2, 'current' => 1, 'count' => 13, 'prevPage' => true, 'nextPage' => false, 'pageCount' => 2, - 'defaults' => array(), - 'options' => array('page' => 2, 'limit' => 10, 'order' => array(), 'conditions' => array()) - )); + $this->Paginator->request->params['paging'] = array( + 'Client' => array( + 'page' => 2, + 'current' => 1, + 'count' => 13, + 'prevPage' => true, + 'nextPage' => false, + 'pageCount' => 2, + 'options' => array( + 'page' => 2, + 'limit' => 10, + 'order' => array(), + 'conditions' => array() + ), + 'paramType' => 'named' + ) + ); $result = $this->Paginator->prev('Prev'); $expected = array( ' array('href' => '/index/page:1/limit:10', 'class' => 'prev'), + 'a' => array('href' => '/index/page:1/limit:10', 'class' => 'prev', 'rel' => 'prev'), 'Prev', '/a', '/span' @@ -860,14 +917,15 @@ class PaginatorHelperTest extends CakeTestCase { 'defaults' => array(), 'options' => array( 'page' => 2, 'limit' => 10, 'order' => array(), 'conditions' => array() - ) + ), + 'paramType' => 'named' ) ); $this->Paginator->options(array('url' => array(12, 'page' => 3))); $result = $this->Paginator->prev('Prev', array('url' => array('foo' => 'bar'))); $expected = array( ' array('href' => '/index/12/page:1/limit:10/foo:bar', 'class' => 'prev'), + 'a' => array('href' => '/index/12/page:1/limit:10/foo:bar', 'class' => 'prev', 'rel' => 'prev'), 'Prev', '/a', '/span' @@ -884,14 +942,16 @@ class PaginatorHelperTest extends CakeTestCase { function testPagingLinksOptionsReplaceEmptyDisabledOptions() { $this->Paginator->request->params['paging'] = array( 'Client' => array( - 'page' => 1, 'current' => 3, 'count' => 13, 'prevPage' => false, - 'nextPage' => true, 'pageCount' => 5, - 'defaults' => array( - 'limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array() - ), + 'page' => 1, + 'current' => 3, + 'count' => 13, + 'prevPage' => false, + 'nextPage' => true, + 'pageCount' => 5, 'options' => array( - 'page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array() - ) + 'page' => 1, + ), + 'paramType' => 'named' ) ); $result = $this->Paginator->prev('<< Previous', array('escape' => false)); @@ -905,7 +965,7 @@ class PaginatorHelperTest extends CakeTestCase { $result = $this->Paginator->next('Next >>', array('escape' => false)); $expected = array( ' array('href' => '/index/page:2', 'class' => 'next'), + 'a' => array('href' => '/index/page:2', 'class' => 'next', 'rel' => 'next'), 'preg:/Next >>/', '/a', '/span' @@ -925,20 +985,34 @@ class PaginatorHelperTest extends CakeTestCase { // Multiple Model Paginate $this->Paginator->request->params['paging'] = array( 'Client' => array( - 'page' => 1, 'current' => 3, 'count' => 13, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 5, - 'defaults' => array( 'limit'=>3, 'order' => array('Client.name' => 'DESC')), - 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()) + 'page' => 1, + 'current' => 3, + 'count' => 13, + 'prevPage' => false, + 'nextPage' => true, + 'pageCount' => 5, + 'options' => array( + 'page' => 1, + ), + 'paramType' => 'named' ), 'Server' => array( - 'page' => 1, 'current' => 1, 'count' => 5, 'prevPage' => false, 'nextPage' => false, 'pageCount' => 5, - 'defaults' => array(), - 'options' => array('page' => 1, 'limit' => 5, 'order' => array('Server.name' => 'ASC'), 'conditions' => array()) + 'page' => 1, + 'current' => 1, + 'count' => 5, + 'prevPage' => false, + 'nextPage' => false, + 'pageCount' => 5, + 'options' => array( + 'page' => 1, + ), + 'paramType' => 'named' ) ); $result = $this->Paginator->next('Next', array('model' => 'Client')); $expected = array( ' array('href' => '/index/page:2', 'class' => 'next'), + 'a' => array('href' => '/index/page:2', 'class' => 'next', 'rel' => 'next'), 'Next', '/a', '/span' @@ -1031,10 +1105,19 @@ class PaginatorHelperTest extends CakeTestCase { * @return void */ function testNumbers() { - $this->Paginator->request->params['paging'] = array('Client' => array( - 'page' => 8, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15, - 'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()), - 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())) + $this->Paginator->request->params['paging'] = array( + 'Client' => array( + 'page' => 8, + 'current' => 3, + 'count' => 30, + 'prevPage' => false, + 'nextPage' => 2, + 'pageCount' => 15, + 'options' => array( + 'page' => 1, + ), + 'paramType' => 'named' + ) ); $result = $this->Paginator->numbers(); $expected = array( @@ -1096,7 +1179,7 @@ class PaginatorHelperTest extends CakeTestCase { $result = $this->Paginator->numbers(true); $expected = array( - array('span' => array()), array('a' => array('href' => '/index/page:1')), 'first', '/a', '/span', + array('span' => array()), array('a' => array('href' => '/index/page:1', 'rel' => 'first')), 'first', '/a', '/span', ' | ', array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', ' | ', @@ -1116,14 +1199,23 @@ class PaginatorHelperTest extends CakeTestCase { ' | ', array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span', ' | ', - array('span' => array()), array('a' => array('href' => '/index/page:15')), 'last', '/a', '/span', + array('span' => array()), array('a' => array('href' => '/index/page:15', 'rel' => 'last')), 'last', '/a', '/span', ); $this->assertTags($result, $expected); - $this->Paginator->request->params['paging'] = array('Client' => array( - 'page' => 1, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15, - 'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()), - 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())) + $this->Paginator->request->params['paging'] = array( + 'Client' => array( + 'page' => 1, + 'current' => 3, + 'count' => 30, + 'prevPage' => false, + 'nextPage' => 2, + 'pageCount' => 15, + 'options' => array( + 'page' => 1, + ), + 'paramType' => 'named' + ) ); $result = $this->Paginator->numbers(); $expected = array( @@ -1148,10 +1240,19 @@ class PaginatorHelperTest extends CakeTestCase { $this->assertTags($result, $expected); - $this->Paginator->request->params['paging'] = array('Client' => array( - 'page' => 14, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15, - 'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()), - 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())) + $this->Paginator->request->params['paging'] = array( + 'Client' => array( + 'page' => 14, + 'current' => 3, + 'count' => 30, + 'prevPage' => false, + 'nextPage' => 2, + 'pageCount' => 15, + 'options' => array( + 'page' => 1, + ), + 'paramType' => 'named' + ) ); $result = $this->Paginator->numbers(); $expected = array( @@ -1175,10 +1276,19 @@ class PaginatorHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $this->Paginator->request->params['paging'] = array('Client' => array( - 'page' => 2, 'current' => 3, 'count' => 27, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 9, - 'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()), - 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())) + $this->Paginator->request->params['paging'] = array( + 'Client' => array( + 'page' => 2, + 'current' => 3, + 'count' => 27, + 'prevPage' => false, + 'nextPage' => 2, + 'pageCount' => 9, + 'options' => array( + 'page' => 1, + ), + 'paramType' => 'named' + ) ); $result = $this->Paginator->numbers(array('first' => 1)); @@ -1225,10 +1335,19 @@ class PaginatorHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $this->Paginator->request->params['paging'] = array('Client' => array( - 'page' => 15, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15, - 'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()), - 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())) + $this->Paginator->request->params['paging'] = array( + 'Client' => array( + 'page' => 15, + 'current' => 3, + 'count' => 30, + 'prevPage' => false, + 'nextPage' => 2, + 'pageCount' => 15, + 'options' => array( + 'page' => 1, + ), + 'paramType' => 'named' + ) ); $result = $this->Paginator->numbers(array('first' => 1)); @@ -1256,10 +1375,19 @@ class PaginatorHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $this->Paginator->request->params['paging'] = array('Client' => array( - 'page' => 10, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15, - 'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()), - 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())) + $this->Paginator->request->params['paging'] = array( + 'Client' => array( + 'page' => 10, + 'current' => 3, + 'count' => 30, + 'prevPage' => false, + 'nextPage' => 2, + 'pageCount' => 15, + 'options' => array( + 'page' => 1, + ), + 'paramType' => 'named' + ) ); $result = $this->Paginator->numbers(array('first' => 1, 'last' => 1)); @@ -1288,10 +1416,19 @@ class PaginatorHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $this->Paginator->request->params['paging'] = array('Client' => array( - 'page' => 6, 'current' => 15, 'count' => 623, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 42, - 'defaults' => array('limit' => 15, 'step' => 1, 'page' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()), - 'options' => array('page' => 6, 'limit' => 15, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())) + $this->Paginator->request->params['paging'] = array( + 'Client' => array( + 'page' => 6, + 'current' => 15, + 'count' => 623, + 'prevPage' => 1, + 'nextPage' => 1, + 'pageCount' => 42, + 'options' => array( + 'page' => 6, + ), + 'paramType' => 'named' + ) ); $result = $this->Paginator->numbers(array('first' => 1, 'last' => 1)); @@ -1320,10 +1457,19 @@ class PaginatorHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $this->Paginator->request->params['paging'] = array('Client' => array( - 'page' => 37, 'current' => 15, 'count' => 623, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 42, - 'defaults' => array('limit' => 15, 'step' => 1, 'page' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()), - 'options' => array('page' => 37, 'limit' => 15, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())) + $this->Paginator->request->params['paging'] = array( + 'Client' => array( + 'page' => 37, + 'current' => 15, + 'count' => 623, + 'prevPage' => 1, + 'nextPage' => 1, + 'pageCount' => 42, + 'options' => array( + 'page' => 37, + ), + 'paramType' => 'named' + ) ); $result = $this->Paginator->numbers(array('first' => 1, 'last' => 1)); @@ -1360,18 +1506,10 @@ class PaginatorHelperTest extends CakeTestCase { 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 3, - 'defaults' => array( - 'limit' => 3, - 'step' => 1, - 'order' => array('Client.name' => 'DESC'), - 'conditions' => array() - ), 'options' => array( 'page' => 1, - 'limit' => 3, - 'order' => array('Client.name' => 'DESC'), - 'conditions' => array() - ) + ), + 'paramType' => 'named' ) ); $options = array('modulus' => 10); @@ -1385,10 +1523,20 @@ class PaginatorHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $this->Paginator->request->params['paging'] = array('Client' => array( - 'page' => 2, 'current' => 10, 'count' => 31, 'prevPage' => true, 'nextPage' => true, 'pageCount' => 4, - 'defaults' => array('limit' => 10), - 'options' => array('page' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())) + $this->Paginator->request->params['paging'] = array( + 'Client' => array( + 'page' => 2, + 'current' => 10, + 'count' => 31, + 'prevPage' => true, + 'nextPage' => true, + 'pageCount' => 4, + 'options' => array( + 'page' => 1, + 'order' => array('Client.name' => 'DESC'), + ), + 'paramType' => 'named' + ) ); $result = $this->Paginator->numbers(); $expected = array( @@ -1403,10 +1551,19 @@ class PaginatorHelperTest extends CakeTestCase { $this->assertTags($result, $expected); - $this->Paginator->request->params['paging'] = array('Client' => array( - 'page' => 4895, 'current' => 10, 'count' => 48962, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 4897, - 'defaults' => array('limit' => 10), - 'options' => array('page' => 4894, 'limit' => 10, 'order' => 'Client.name DESC', 'conditions' => array())) + $this->Paginator->request->params['paging'] = array( + 'Client' => array( + 'page' => 4895, + 'current' => 10, + 'count' => 48962, + 'prevPage' => 1, + 'nextPage' => 1, + 'pageCount' => 4897, + 'options' => array( + 'page' => 4894, + ), + 'paramType' => 'named' + ) ); $result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2)); @@ -1614,52 +1771,130 @@ class PaginatorHelperTest extends CakeTestCase { } /** - * testFirstAndLast method + * test first() and last() with tag options * - * @access public * @return void */ - function testFirstAndLast() { - $this->Paginator->request->params['paging'] = array('Client' => array( - 'page' => 1, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15, - 'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()), - 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())) - ); - - $result = $this->Paginator->first(); - $expected = ''; - $this->assertEqual($result, $expected); - - $this->Paginator->request->params['paging'] = array('Client' => array( - 'page' => 4, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15, - 'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()), - 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())) - ); - - $result = $this->Paginator->first(); - $expected = array( - ' array('href' => '/index/page:1'), - '<< first', - '/a', - '/span' - ); - $this->assertTags($result, $expected); - + function testFirstAndLastTag() { $result = $this->Paginator->first('<<', array('tag' => 'li')); $expected = array( ' array('href' => '/index/page:1'), + 'a' => array('href' => '/index/page:1', 'rel' => 'first'), '<<', '/a', '/li' ); $this->assertTags($result, $expected); + $result = $this->Paginator->last(2, array('tag' => 'li')); + + $expected = array( + '...', + ' array('href' => '/index/page:6')), '6', '/a', + '/li', + ' | ', + ' array('href' => '/index/page:7')), '7', '/a', + '/li', + ); + $this->assertTags($result, $expected); + } + +/** + * test that on the last page you don't get a link ot the last page. + * + * @return void + */ + function testLastNoOutput() { + $this->Paginator->request->params['paging']['Article']['page'] = 15; + $this->Paginator->request->params['paging']['Article']['pageCount'] = 15; + + $result = $this->Paginator->last(); + $expected = ''; + $this->assertEqual($result, $expected); + } + +/** + * test first() on the first page. + * + * @return void + */ + function testFirstEmpty() { + $this->Paginator->request->params['paging']['Article']['page'] = 1; + + $result = $this->Paginator->first(); + $expected = ''; + $this->assertEqual($result, $expected); + } + +/** + * test first() and options() + * + * @return void + */ + function testFirstFullBaseUrl() { + $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'DESC'); + + $this->Paginator->options(array('url' => array('full_base' => true))); + + $result = $this->Paginator->first(); + $expected = array( + ' array( + 'href' => FULL_BASE_URL . '/index/page:1/sort:Article.title/direction:DESC', 'rel' => 'first' + )), + '<< first', + '/a', + '/span', + ); + $this->assertTags($result, $expected); + } + +/** + * test first() on the fence-post + * + * @return void + */ + function testFirstBoundaries() { + $result = $this->Paginator->first(); + $expected = array( + ' array('href' => '/index/page:1', 'rel' => 'first'), + '<< first', + '/a', + '/span' + ); + $this->assertTags($result, $expected); + + $result = $this->Paginator->first(2); + $expected = array( + ' array('href' => '/index/page:1')), '1', '/a', + '/span', + ' | ', + ' array('href' => '/index/page:2')), '2', '/a', + '/span' + ); + $this->assertTags($result, $expected); + + $this->Paginator->request->params['paging']['Article']['page'] = 2; + $result = $this->Paginator->first(3); + $this->assertEquals('', $result, 'When inside the first links range, no links should be made'); + } + +/** + * test Last method + * + * @access public + * @return void + */ + function testLast() { $result = $this->Paginator->last(); $expected = array( ' array('href' => '/index/page:15'), + 'a' => array('href' => '/index/page:7', 'rel' => 'last'), 'last >>', '/a', '/span' @@ -1670,70 +1905,66 @@ class PaginatorHelperTest extends CakeTestCase { $expected = array( '...', ' array('href' => '/index/page:15'), - '15', + 'a' => array('href' => '/index/page:7'), + '7', '/a', '/span' ); $this->assertTags($result, $expected); + $this->Paginator->request->params['paging']['Article']['page'] = 6; + $result = $this->Paginator->last(2); $expected = array( '...', ' array('href' => '/index/page:14')), '14', '/a', + array('a' => array('href' => '/index/page:6')), '6', '/a', '/span', ' | ', ' array('href' => '/index/page:15')), '15', '/a', + array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', ); $this->assertTags($result, $expected); - $result = $this->Paginator->last(2, array('tag' => 'li')); - $expected = array( - '...', - ' array('href' => '/index/page:14')), '14', '/a', - '/li', - ' | ', - ' array('href' => '/index/page:15')), '15', '/a', - '/li', + $result = $this->Paginator->last(3); + $this->assertEquals('', $result, 'When inside the last links range, no links should be made'); + } + +/** + * undocumented function + * + * @return void + */ + function testLastOptions() { + $this->Paginator->request->params['paging'] = array( + 'Client' => array( + 'page' => 4, + 'current' => 3, + 'count' => 30, + 'prevPage' => false, + 'nextPage' => 2, + 'pageCount' => 15, + 'options' => array( + 'page' => 1, + 'order' => array('Client.name' => 'DESC'), + ), + 'paramType' => 'named' + ) ); - $this->assertTags($result, $expected); - - $this->Paginator->request->params['paging'] = array('Client' => array( - 'page' => 15, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15, - 'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()), - 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())) - ); - $result = $this->Paginator->last(); - $expected = ''; - $this->assertEqual($result, $expected); - - $this->Paginator->request->params['paging'] = array('Client' => array( - 'page' => 4, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15, - 'defaults' => array('limit' => 3), - 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())) - ); - - $result = $this->Paginator->first(); - $expected = array( - ' array('href' => '/index/page:1/sort:Client.name/direction:DESC')), '<< first', '/a', - '/span', - ); - $this->assertTags($result, $expected); $result = $this->Paginator->last(); $expected = array( ' array('href' => '/index/page:15/sort:Client.name/direction:DESC')), 'last >>', '/a', + array('a' => array( + 'href' => '/index/page:15/sort:Client.name/direction:DESC', + 'rel' => 'last' + )), + 'last >>', '/a', '/span', ); $this->assertTags($result, $expected); - + $result = $this->Paginator->last(1); $expected = array( '...', @@ -1756,19 +1987,6 @@ class PaginatorHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $result = $this->Paginator->last(2, array('ellipsis' => '~~~')); - $expected = array( - '~~~', - ' array('href' => '/index/page:14/sort:Client.name/direction:DESC')), '14', '/a', - '/span', - ' | ', - ' array('href' => '/index/page:15/sort:Client.name/direction:DESC')), '15', '/a', - '/span', - ); - $this->assertTags($result, $expected); - $result = $this->Paginator->last(2, array('ellipsis' => '...')); $expected = array( array('span' => array('class' => 'ellipsis')), '...', '/span', @@ -1781,15 +1999,6 @@ class PaginatorHelperTest extends CakeTestCase { '/span', ); $this->assertTags($result, $expected); - - $this->Paginator->options(array('url' => array('full_base' => true))); - $result = $this->Paginator->first(); - $expected = array( - ' array('href' => FULL_BASE_URL . '/index/page:1/sort:Client.name/direction:DESC')), '<< first', '/a', - '/span', - ); - $this->assertTags($result, $expected); } /** @@ -1807,19 +2016,12 @@ class PaginatorHelperTest extends CakeTestCase { 'prevPage' => false, 'nextPage' => true, 'pageCount' => 5, - 'defaults' => array( - 'limit' => 3, - 'step' => 1, - 'order' => array('Client.name' => 'DESC'), - 'conditions' => array() - ), + 'limit' => 3, 'options' => array( 'page' => 1, - 'limit' => 3, 'order' => array('Client.name' => 'DESC'), - 'conditions' => array(), - 'separator' => 'of' ), + 'paramType' => 'named' ) ); $input = 'Page %page% of %pages%, showing %current% records out of %count% total, '; @@ -1932,8 +2134,8 @@ class PaginatorHelperTest extends CakeTestCase { Router::reload(); Router::parse('/'); Router::setRequestInfo(array( - array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0), - array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/', 'passedArgs' => array()) + array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'url' => array('url' => 'accounts/')), + array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/', 'passedArgs' => array()) )); $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc'); @@ -1949,7 +2151,11 @@ class PaginatorHelperTest extends CakeTestCase { $result = $this->Paginator->next('Next'); $expected = array( ' array('href' => '/officespace/accounts/index/page:2/sort:Article.title/direction:asc', 'class' => 'next'), + 'a' => array( + 'href' => '/officespace/accounts/index/page:2/sort:Article.title/direction:asc', + 'class' => 'next', + 'rel' => 'next' + ), 'Next', '/a', '/span', @@ -2001,7 +2207,8 @@ class PaginatorHelperTest extends CakeTestCase { 'nextPage' => true, 'pageCount' => 7, 'defaults' => array(), - 'options' => array() + 'options' => array(), + 'paramType' => 'named' ) ); $Paginator->PaginatorMockJs = $mock; @@ -2011,4 +2218,82 @@ class PaginatorHelperTest extends CakeTestCase { $this->expectException(); $Paginator = new PaginatorHelper($this->View, array('ajax' => 'Form')); } + +/** + * test that querystring urls can be generated. + * + * @return void + */ + function testQuerystringUrlGeneration() { + $this->Paginator->request->params['paging']['Article']['paramType'] = 'querystring'; + $result = $this->Paginator->url(array('page' => '4')); + $expected = '/?page=4'; + $this->assertEquals($expected, $result); + + $result = $this->Paginator->url(array('page' => '4', 'limit' => 10, 'something' => 'else')); + $expected = '/index/something:else?page=4&limit=10'; + $this->assertEquals($expected, $result); + } + +/** + * test querystring paging link. + * + * @return void + */ + function testQuerystringNextAndPrev() { + $this->Paginator->request->params['paging']['Article']['paramType'] = 'querystring'; + $this->Paginator->request->params['paging']['Article']['page'] = 2; + $this->Paginator->request->params['paging']['Article']['nextPage'] = true; + $this->Paginator->request->params['paging']['Article']['prevPage'] = true; + + $result = $this->Paginator->next('Next'); + $expected = array( + ' array('href' => '/?page=3', 'class' => 'next', 'rel' => 'next'), + 'Next', + '/a', + '/span' + ); + $this->assertTags($result, $expected); + + $result = $this->Paginator->prev('Prev'); + $expected = array( + ' array('href' => '/?page=1', 'class' => 'prev', 'rel' => 'prev'), + 'Prev', + '/a', + '/span' + ); + $this->assertTags($result, $expected); + } + +/** + * test that additional keys can be flagged as query string args. + * + * @return void + */ + function testOptionsConvertKeys() { + $this->Paginator->options(array( + 'convertKeys' => array('something'), + 'Article' => array('paramType' => 'querystring') + )); + $result = $this->Paginator->url(array('page' => '4', 'something' => 'bar')); + $expected = '/?page=4&something=bar'; + $this->assertEquals($expected, $result); + } + + +/** + * test the current() method + * + * @return void + */ + function testCurrent() { + $result = $this->Paginator->current(); + $this->assertEquals($this->Paginator->request->params['paging']['Article']['page'], $result); + + $result = $this->Paginator->current('Incorrect'); + $this->assertEquals(1, $result); + } + } diff --git a/cake/tests/cases/libs/view/helpers/prototype_engine.test.php b/cake/tests/cases/libs/view/helpers/prototype_engine.test.php index 395b25cd7..86b8d3a73 100644 --- a/cake/tests/cases/libs/view/helpers/prototype_engine.test.php +++ b/cake/tests/cases/libs/view/helpers/prototype_engine.test.php @@ -15,7 +15,7 @@ * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project * @package cake.tests - * @subpackage cake.tests.cases.views.helpers + * @package cake.tests.cases.views.helpers * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ App::import('Helper', array('Html', 'Js', 'PrototypeEngine')); diff --git a/cake/tests/cases/libs/view/helpers/rss.test.php b/cake/tests/cases/libs/view/helpers/rss.test.php index afc3e54e9..93c344d67 100644 --- a/cake/tests/cases/libs/view/helpers/rss.test.php +++ b/cake/tests/cases/libs/view/helpers/rss.test.php @@ -12,8 +12,7 @@ * * @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.view.helpers + * @package cake.tests.cases.libs.view.helpers * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ App::import('Helper', array('Rss', 'Time')); /** * RssHelperTest class * - * @package cake - * @subpackage cake.tests.cases.libs.view.helpers + * @package cake.tests.cases.libs.view.helpers */ class RssHelperTest extends CakeTestCase { @@ -108,7 +106,7 @@ class RssHelperTest extends CakeTestCase { 'title', '/title', 'Rss->url('/', true), '/link', ' array('url' => RssHelper::url('/test.flv', true)), + 'enclosure' => array('url' => $this->Rss->url('/test.flv', true)), 'assertEqual(date('M jS, H:i', $time), $this->Time->niceShort($time)); } else { - $this->assertEqual(date('M jSY, H:i', $time), $this->Time->niceShort($time)); + $this->assertEqual(date('M jS Y, H:i', $time), $this->Time->niceShort($time)); } $time = time(); - $this->assertEqual('Today, '.date('H:i', $time), $this->Time->niceShort($time)); + $this->assertEqual('Today, ' . date('H:i', $time), $this->Time->niceShort($time)); $time = time() - DAY; - $this->assertEqual('Yesterday, '.date('H:i', $time), $this->Time->niceShort($time)); + $this->assertEqual('Yesterday, ' . date('H:i', $time), $this->Time->niceShort($time)); } /** diff --git a/cake/tests/cases/libs/view/media.test.php b/cake/tests/cases/libs/view/media.test.php index 39b9d190d..115f74505 100644 --- a/cake/tests/cases/libs/view/media.test.php +++ b/cake/tests/cases/libs/view/media.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Core', array('Media', 'Controller', 'CakeResponse')); /** * MediaViewTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class MediaViewTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/view/theme.test.php b/cake/tests/cases/libs/view/theme.test.php index 314d38ba7..dc03b6663 100644 --- a/cake/tests/cases/libs/view/theme.test.php +++ b/cake/tests/cases/libs/view/theme.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,8 +24,7 @@ App::import('Core', 'Controller'); /** * ThemePostsController class * - * @package cake - * @subpackage cake.tests.cases.libs.view + * @package cake.tests.cases.libs.view */ class ThemePostsController extends Controller { @@ -57,8 +55,7 @@ class ThemePostsController extends Controller { /** * TestThemeView class * - * @package cake - * @subpackage cake.tests.cases.libs.view + * @package cake.tests.cases.libs.view */ class TestThemeView extends ThemeView { @@ -101,8 +98,7 @@ class TestThemeView extends ThemeView { /** * ThemeViewTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class ThemeViewTest extends CakeTestCase { diff --git a/cake/tests/cases/libs/view/view.test.php b/cake/tests/cases/libs/view/view.test.php index 8038ff010..70ef8a6ca 100644 --- a/cake/tests/cases/libs/view/view.test.php +++ b/cake/tests/cases/libs/view/view.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,8 +24,7 @@ App::import('Core', array('ErrorHandler')); /** * ViewPostsController class * - * @package cake - * @subpackage cake.tests.cases.libs.view + * @package cake.tests.cases.libs.view */ class ViewPostsController extends Controller { @@ -74,8 +72,7 @@ class ViewPostsController extends Controller { /** * TestView class * - * @package cake - * @subpackage cake.tests.cases.libs.view + * @package cake.tests.cases.libs.view */ class TestView extends View { @@ -121,7 +118,6 @@ class TestView extends View { * @param string $loadHelpers * @param string $cached * @return void - * @author Mark Story */ function render_($___viewFn, $___dataForView, $loadHelpers = true, $cached = false) { return $this->_render($___viewFn, $___dataForView, $loadHelpers, $cached); @@ -140,8 +136,7 @@ class TestView extends View { /** * TestAfterHelper class * - * @package cake - * @subpackage cake.tests.cases.libs.view + * @package cake.tests.cases.libs.view */ class TestAfterHelper extends Helper { @@ -177,8 +172,7 @@ class TestAfterHelper extends Helper { /** * ViewTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class ViewTest extends CakeTestCase { @@ -455,6 +449,24 @@ class ViewTest extends CakeTestCase { $this->View->element('test_element', array(), true); $this->mockObjects[] = $this->View->ElementCallbackMockHtml; } +/** + * test that additional element viewVars don't get overwritten with helpers. + * + * @return void + */ + function testElementParamsDontOverwriteHelpers() { + $Controller = new ViewPostsController(); + $Controller->helpers = array('Form'); + + $View = new View($Controller); + $result = $View->element('type_check', array('form' => 'string'), true); + $this->assertEqual('string', $result); + + $View->set('form', 'string'); + $result = $View->element('type_check', array(), true); + $this->assertEqual('string', $result); + } + /** * testElementCacheHelperNoCache method * @@ -529,7 +541,7 @@ class ViewTest extends CakeTestCase { function test__get() { $View = new View($this->PostsController); $View->loadHelper('Html'); - $this->assertType('HtmlHelper', $View->Html); + $this->assertInstanceOf('HtmlHelper', $View->Html); } /** @@ -544,8 +556,8 @@ class ViewTest extends CakeTestCase { $View->helpers = array('Html', 'Form'); $View->loadHelpers(); - $this->assertType('HtmlHelper', $View->Html, 'Object type is wrong.'); - $this->assertType('FormHelper', $View->Form, 'Object type is wrong.'); + $this->assertInstanceOf('HtmlHelper', $View->Html, 'Object type is wrong.'); + $this->assertInstanceOf('FormHelper', $View->Form, 'Object type is wrong.'); } /** diff --git a/cake/tests/cases/libs/xml.test.php b/cake/tests/cases/libs/xml.test.php index 666a4f45d..169c38933 100644 --- a/cake/tests/cases/libs/xml.test.php +++ b/cake/tests/cases/libs/xml.test.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.5432 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ App::import('Core', 'Xml'); /** * Article class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class XmlArticle extends CakeTestModel { @@ -50,8 +48,7 @@ class XmlArticle extends CakeTestModel { /** * User class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class XmlUser extends CakeTestModel { @@ -73,8 +70,7 @@ class XmlUser extends CakeTestModel { /** * XmlTest class * - * @package cake - * @subpackage cake.tests.cases.libs + * @package cake.tests.cases.libs */ class XmlTest extends CakeTestCase { diff --git a/cake/tests/fixtures/account_fixture.php b/cake/tests/fixtures/account_fixture.php index f4f948dfa..756d92355 100644 --- a/cake/tests/fixtures/account_fixture.php +++ b/cake/tests/fixtures/account_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class AccountFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/aco_action_fixture.php b/cake/tests/fixtures/aco_action_fixture.php index e95de48e8..93fc08664 100644 --- a/cake/tests/fixtures/aco_action_fixture.php +++ b/cake/tests/fixtures/aco_action_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class AcoActionFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/aco_fixture.php b/cake/tests/fixtures/aco_fixture.php index e6c649a15..77c625781 100644 --- a/cake/tests/fixtures/aco_fixture.php +++ b/cake/tests/fixtures/aco_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class AcoFixture extends CakeTestFixture { @@ -57,17 +55,17 @@ class AcoFixture extends CakeTestFixture { * @access public */ public $records = array( - array('parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'ROOT', 'lft' => 1, 'rght' => 24), - array('parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Controller1', 'lft' => 2, 'rght' => 9), - array('parent_id' => 2, 'model' => null, 'foreign_key' => null, 'alias' => 'action1', 'lft' => 3, 'rght' => 6), - array('parent_id' => 3, 'model' => null, 'foreign_key' => null, 'alias' => 'record1', 'lft' => 4, 'rght' => 5), - array('parent_id' => 2, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 7, 'rght' => 8), - array('parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Controller2','lft' => 10, 'rght' => 17), - array('parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action1', 'lft' => 11, 'rght' => 14), - array('parent_id' => 7, 'model' => null, 'foreign_key' => null, 'alias' => 'record1', 'lft' => 12, 'rght' => 13), - array('parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 15, 'rght' => 16), - array('parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Users', 'lft' => 18, 'rght' => 23), - array('parent_id' => 9, 'model' => null, 'foreign_key' => null, 'alias' => 'Users', 'lft' => 19, 'rght' => 22), - array('parent_id' => 10, 'model' => null, 'foreign_key' => null, 'alias' => 'view', 'lft' => 20, 'rght' => 21), + array('id' => 1, 'parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'ROOT', 'lft' => 1, 'rght' => 24), + array('id' => 2, 'parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Controller1', 'lft' => 2, 'rght' => 9), + array('id' => 3, 'parent_id' => 2, 'model' => null, 'foreign_key' => null, 'alias' => 'action1', 'lft' => 3, 'rght' => 6), + array('id' => 4, 'parent_id' => 3, 'model' => null, 'foreign_key' => null, 'alias' => 'record1', 'lft' => 4, 'rght' => 5), + array('id' => 5, 'parent_id' => 2, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 7, 'rght' => 8), + array('id' => 6, 'parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Controller2','lft' => 10, 'rght' => 17), + array('id' => 7, 'parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action1', 'lft' => 11, 'rght' => 14), + array('id' => 8, 'parent_id' => 7, 'model' => null, 'foreign_key' => null, 'alias' => 'record1', 'lft' => 12, 'rght' => 13), + array('id' => 9, 'parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 15, 'rght' => 16), + array('id' => 10, 'parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Users', 'lft' => 18, 'rght' => 23), + array('id' => 11, 'parent_id' => 9, 'model' => null, 'foreign_key' => null, 'alias' => 'Users', 'lft' => 19, 'rght' => 22), + array('id' => 12, 'parent_id' => 10, 'model' => null, 'foreign_key' => null, 'alias' => 'view', 'lft' => 20, 'rght' => 21), ); } diff --git a/cake/tests/fixtures/aco_two_fixture.php b/cake/tests/fixtures/aco_two_fixture.php index d277beea1..a45c2dc6e 100644 --- a/cake/tests/fixtures/aco_two_fixture.php +++ b/cake/tests/fixtures/aco_two_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class AcoTwoFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/ad_fixture.php b/cake/tests/fixtures/ad_fixture.php index c6f955da4..56989b072 100644 --- a/cake/tests/fixtures/ad_fixture.php +++ b/cake/tests/fixtures/ad_fixture.php @@ -13,8 +13,7 @@ * * @copyright CakePHP(tm) : Rapid Development Framework (http://cakephp.org) * @link http://www.cakephp.org - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures * @since 1.2 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ /** * AdFixture class * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class AdFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/advertisement_fixture.php b/cake/tests/fixtures/advertisement_fixture.php index 8c1e8b629..32c7bca5e 100644 --- a/cake/tests/fixtures/advertisement_fixture.php +++ b/cake/tests/fixtures/advertisement_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class AdvertisementFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/after_tree_fixture.php b/cake/tests/fixtures/after_tree_fixture.php index 098863888..1c5fa8e9c 100644 --- a/cake/tests/fixtures/after_tree_fixture.php +++ b/cake/tests/fixtures/after_tree_fixture.php @@ -13,8 +13,7 @@ * * @copyright CakePHP(tm) : Rapid Development Framework (http://cakephp.org) * @link http://www.cakephp.org - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures * @since 1.2 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ /** * AdFixture class * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class AfterTreeFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/another_article_fixture.php b/cake/tests/fixtures/another_article_fixture.php index d0807c788..a62287a06 100644 --- a/cake/tests/fixtures/another_article_fixture.php +++ b/cake/tests/fixtures/another_article_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class AnotherArticleFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/apple_fixture.php b/cake/tests/fixtures/apple_fixture.php index 0de5f3bea..e0e9d3e88 100644 --- a/cake/tests/fixtures/apple_fixture.php +++ b/cake/tests/fixtures/apple_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class AppleFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/aro_fixture.php b/cake/tests/fixtures/aro_fixture.php index f224dfc97..f0f5adceb 100644 --- a/cake/tests/fixtures/aro_fixture.php +++ b/cake/tests/fixtures/aro_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class AroFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/aro_two_fixture.php b/cake/tests/fixtures/aro_two_fixture.php index 86b774720..409be3489 100644 --- a/cake/tests/fixtures/aro_two_fixture.php +++ b/cake/tests/fixtures/aro_two_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class AroTwoFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/aros_aco_fixture.php b/cake/tests/fixtures/aros_aco_fixture.php index 6c204fc49..4265bf011 100644 --- a/cake/tests/fixtures/aros_aco_fixture.php +++ b/cake/tests/fixtures/aros_aco_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class ArosAcoFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/aros_aco_two_fixture.php b/cake/tests/fixtures/aros_aco_two_fixture.php index 9c3251d64..e62e48306 100644 --- a/cake/tests/fixtures/aros_aco_two_fixture.php +++ b/cake/tests/fixtures/aros_aco_two_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class ArosAcoTwoFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/article_featured_fixture.php b/cake/tests/fixtures/article_featured_fixture.php index 64c4bc38c..062813621 100644 --- a/cake/tests/fixtures/article_featured_fixture.php +++ b/cake/tests/fixtures/article_featured_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class ArticleFeaturedFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/article_featureds_tags_fixture.php b/cake/tests/fixtures/article_featureds_tags_fixture.php index e84b863d5..60c8c7096 100644 --- a/cake/tests/fixtures/article_featureds_tags_fixture.php +++ b/cake/tests/fixtures/article_featureds_tags_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class ArticleFeaturedsTagsFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/article_fixture.php b/cake/tests/fixtures/article_fixture.php index b6f21e7b3..41b256da1 100644 --- a/cake/tests/fixtures/article_fixture.php +++ b/cake/tests/fixtures/article_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class ArticleFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/articles_tag_fixture.php b/cake/tests/fixtures/articles_tag_fixture.php index 1091901a6..c475d87a4 100644 --- a/cake/tests/fixtures/articles_tag_fixture.php +++ b/cake/tests/fixtures/articles_tag_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class ArticlesTagFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/assert_tags_test_case.php b/cake/tests/fixtures/assert_tags_test_case.php index 27cc08d19..1cef87aea 100644 --- a/cake/tests/fixtures/assert_tags_test_case.php +++ b/cake/tests/fixtures/assert_tags_test_case.php @@ -5,8 +5,7 @@ PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'DEFAULT'); /** * This class helpes in indirectly testing the functionaliteies of CakeTestCase::assertTags * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class AssertTagsTestCase extends CakeTestCase { diff --git a/cake/tests/fixtures/attachment_fixture.php b/cake/tests/fixtures/attachment_fixture.php index d43defa4f..748c10d78 100644 --- a/cake/tests/fixtures/attachment_fixture.php +++ b/cake/tests/fixtures/attachment_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class AttachmentFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/auth_user_custom_field_fixture.php b/cake/tests/fixtures/auth_user_custom_field_fixture.php index fb727e6a7..8c82b6717 100644 --- a/cake/tests/fixtures/auth_user_custom_field_fixture.php +++ b/cake/tests/fixtures/auth_user_custom_field_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.1.8013 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class AuthUserCustomFieldFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/auth_user_fixture.php b/cake/tests/fixtures/auth_user_fixture.php index 2613b3d64..5efc6be2e 100644 --- a/cake/tests/fixtures/auth_user_fixture.php +++ b/cake/tests/fixtures/auth_user_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class AuthUserFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/author_fixture.php b/cake/tests/fixtures/author_fixture.php index 2f9381621..8f705f4fe 100644 --- a/cake/tests/fixtures/author_fixture.php +++ b/cake/tests/fixtures/author_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class AuthorFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/bake_article_fixture.php b/cake/tests/fixtures/bake_article_fixture.php index 304bd6b3c..8543ee6ba 100644 --- a/cake/tests/fixtures/bake_article_fixture.php +++ b/cake/tests/fixtures/bake_article_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class BakeArticleFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/bake_articles_bake_tag_fixture.php b/cake/tests/fixtures/bake_articles_bake_tag_fixture.php index d1f6ef5d8..d046718b3 100644 --- a/cake/tests/fixtures/bake_articles_bake_tag_fixture.php +++ b/cake/tests/fixtures/bake_articles_bake_tag_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class BakeArticlesBakeTagFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/bake_comment_fixture.php b/cake/tests/fixtures/bake_comment_fixture.php index 8de6696be..b75d0821b 100644 --- a/cake/tests/fixtures/bake_comment_fixture.php +++ b/cake/tests/fixtures/bake_comment_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * BakeCommentFixture fixture for testing bake * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class BakeCommentFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/bake_tag_fixture.php b/cake/tests/fixtures/bake_tag_fixture.php index e5057385e..74dfa473b 100644 --- a/cake/tests/fixtures/bake_tag_fixture.php +++ b/cake/tests/fixtures/bake_tag_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class BakeTagFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/basket_fixture.php b/cake/tests/fixtures/basket_fixture.php index 7ad9f8d0d..3984c65b1 100644 --- a/cake/tests/fixtures/basket_fixture.php +++ b/cake/tests/fixtures/basket_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class BasketFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/bid_fixture.php b/cake/tests/fixtures/bid_fixture.php index dd1b4c130..df915dc71 100644 --- a/cake/tests/fixtures/bid_fixture.php +++ b/cake/tests/fixtures/bid_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class BidFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/binary_test_fixture.php b/cake/tests/fixtures/binary_test_fixture.php index f1cd03351..868ee4c5c 100644 --- a/cake/tests/fixtures/binary_test_fixture.php +++ b/cake/tests/fixtures/binary_test_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.6700 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class BinaryTestFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/book_fixture.php b/cake/tests/fixtures/book_fixture.php index 83e1b6f09..bf85000af 100644 --- a/cake/tests/fixtures/book_fixture.php +++ b/cake/tests/fixtures/book_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.7198 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class BookFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/cache_test_model_fixture.php b/cake/tests/fixtures/cache_test_model_fixture.php index ace714d5b..84b1a64b1 100644 --- a/cake/tests/fixtures/cache_test_model_fixture.php +++ b/cake/tests/fixtures/cache_test_model_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class CacheTestModelFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/callback_fixture.php b/cake/tests/fixtures/callback_fixture.php index 6d6103ca0..f28c6277f 100644 --- a/cake/tests/fixtures/callback_fixture.php +++ b/cake/tests/fixtures/callback_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class CallbackFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/campaign_fixture.php b/cake/tests/fixtures/campaign_fixture.php index 1d4fb7edb..ec0411b76 100644 --- a/cake/tests/fixtures/campaign_fixture.php +++ b/cake/tests/fixtures/campaign_fixture.php @@ -13,8 +13,7 @@ * * @copyright CakePHP(tm) : Rapid Development Framework (http://cakephp.org) * @link http://www.cakephp.org - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures * @since 1.2 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ /** * CampaignFixture class * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class CampaignFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/category_fixture.php b/cake/tests/fixtures/category_fixture.php index 419699773..7ea0fba2d 100644 --- a/cake/tests/fixtures/category_fixture.php +++ b/cake/tests/fixtures/category_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class CategoryFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/category_thread_fixture.php b/cake/tests/fixtures/category_thread_fixture.php index 65b840cbc..92563dd7b 100644 --- a/cake/tests/fixtures/category_thread_fixture.php +++ b/cake/tests/fixtures/category_thread_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class CategoryThreadFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/cd_fixture.php b/cake/tests/fixtures/cd_fixture.php index 59b4952cf..c2e668c0a 100644 --- a/cake/tests/fixtures/cd_fixture.php +++ b/cake/tests/fixtures/cd_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.7198 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class CdFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/comment_fixture.php b/cake/tests/fixtures/comment_fixture.php index 559c78e00..2f5cfaa26 100644 --- a/cake/tests/fixtures/comment_fixture.php +++ b/cake/tests/fixtures/comment_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class CommentFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/content_account_fixture.php b/cake/tests/fixtures/content_account_fixture.php index b765fc403..4cf803a22 100644 --- a/cake/tests/fixtures/content_account_fixture.php +++ b/cake/tests/fixtures/content_account_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class ContentAccountFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/content_fixture.php b/cake/tests/fixtures/content_fixture.php index a7e9eb5ca..067410fbf 100644 --- a/cake/tests/fixtures/content_fixture.php +++ b/cake/tests/fixtures/content_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class ContentFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/counter_cache_post_fixture.php b/cake/tests/fixtures/counter_cache_post_fixture.php index 9aa3f2ce1..ea7ec7b9b 100644 --- a/cake/tests/fixtures/counter_cache_post_fixture.php +++ b/cake/tests/fixtures/counter_cache_post_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class CounterCachePostFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/counter_cache_post_nonstandard_primary_key_fixture.php b/cake/tests/fixtures/counter_cache_post_nonstandard_primary_key_fixture.php index efa9c553c..cdb05f0da 100644 --- a/cake/tests/fixtures/counter_cache_post_nonstandard_primary_key_fixture.php +++ b/cake/tests/fixtures/counter_cache_post_nonstandard_primary_key_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class CounterCachePostNonstandardPrimaryKeyFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/counter_cache_user_fixture.php b/cake/tests/fixtures/counter_cache_user_fixture.php index 9ebc2e3ac..4d47c33cd 100644 --- a/cake/tests/fixtures/counter_cache_user_fixture.php +++ b/cake/tests/fixtures/counter_cache_user_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class CounterCacheUserFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/counter_cache_user_nonstandard_primary_key_fixture.php b/cake/tests/fixtures/counter_cache_user_nonstandard_primary_key_fixture.php index 3134f4650..3fe938bc6 100644 --- a/cake/tests/fixtures/counter_cache_user_nonstandard_primary_key_fixture.php +++ b/cake/tests/fixtures/counter_cache_user_nonstandard_primary_key_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class CounterCacheUserNonstandardPrimaryKeyFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/data_test_fixture.php b/cake/tests/fixtures/data_test_fixture.php index 43c4fd7d3..273777c2f 100644 --- a/cake/tests/fixtures/data_test_fixture.php +++ b/cake/tests/fixtures/data_test_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.6700 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class DataTestFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/datatype_fixture.php b/cake/tests/fixtures/datatype_fixture.php index 9bfaad3d7..39055a018 100644 --- a/cake/tests/fixtures/datatype_fixture.php +++ b/cake/tests/fixtures/datatype_fixture.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.7026 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class DatatypeFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/dependency_fixture.php b/cake/tests/fixtures/dependency_fixture.php index 5514e696e..d9765317a 100644 --- a/cake/tests/fixtures/dependency_fixture.php +++ b/cake/tests/fixtures/dependency_fixture.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.6879//Correct version number as needed** * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for file. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.6879//Correct version number as needed** */ class DependencyFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/device_fixture.php b/cake/tests/fixtures/device_fixture.php index c927feeda..8371cbe21 100644 --- a/cake/tests/fixtures/device_fixture.php +++ b/cake/tests/fixtures/device_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class DeviceFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/device_type_category_fixture.php b/cake/tests/fixtures/device_type_category_fixture.php index 6750ac7ed..7feb7b97c 100644 --- a/cake/tests/fixtures/device_type_category_fixture.php +++ b/cake/tests/fixtures/device_type_category_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class DeviceTypeCategoryFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/device_type_fixture.php b/cake/tests/fixtures/device_type_fixture.php index ecbdb2091..ddd82adc1 100644 --- a/cake/tests/fixtures/device_type_fixture.php +++ b/cake/tests/fixtures/device_type_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class DeviceTypeFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/document_directory_fixture.php b/cake/tests/fixtures/document_directory_fixture.php index 485cdeca4..732eae1f2 100644 --- a/cake/tests/fixtures/document_directory_fixture.php +++ b/cake/tests/fixtures/document_directory_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class DocumentDirectoryFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/document_fixture.php b/cake/tests/fixtures/document_fixture.php index 5d9f438bf..93c1ec4ae 100644 --- a/cake/tests/fixtures/document_fixture.php +++ b/cake/tests/fixtures/document_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class DocumentFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/exterior_type_category_fixture.php b/cake/tests/fixtures/exterior_type_category_fixture.php index f7b609ed7..cbc27668c 100644 --- a/cake/tests/fixtures/exterior_type_category_fixture.php +++ b/cake/tests/fixtures/exterior_type_category_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class ExteriorTypeCategoryFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/feature_set_fixture.php b/cake/tests/fixtures/feature_set_fixture.php index 3e26310ff..a42084973 100644 --- a/cake/tests/fixtures/feature_set_fixture.php +++ b/cake/tests/fixtures/feature_set_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class FeatureSetFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/featured_fixture.php b/cake/tests/fixtures/featured_fixture.php index 4777e2d36..1070e2732 100644 --- a/cake/tests/fixtures/featured_fixture.php +++ b/cake/tests/fixtures/featured_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class FeaturedFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/film_file_fixture.php b/cake/tests/fixtures/film_file_fixture.php index fa9fe736b..9a07df3cd 100644 --- a/cake/tests/fixtures/film_file_fixture.php +++ b/cake/tests/fixtures/film_file_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class FilmFileFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/fixturized_test_case.php b/cake/tests/fixtures/fixturized_test_case.php index c9b932b3e..810a2089f 100644 --- a/cake/tests/fixtures/fixturized_test_case.php +++ b/cake/tests/fixtures/fixturized_test_case.php @@ -5,8 +5,7 @@ PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'DEFAULT'); /** * This class helps in testing the life-cycle of fixtures inside a CakeTestCase * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class FixturizedTestCase extends CakeTestCase { @@ -22,7 +21,7 @@ class FixturizedTestCase extends CakeTestCase { * @return void */ public function testFixturePresent() { - $this->assertType('CakeFixtureManager', $this->fixtureManager); + $this->assertInstanceOf('CakeFixtureManager', $this->fixtureManager); } /** diff --git a/cake/tests/fixtures/flag_tree_fixture.php b/cake/tests/fixtures/flag_tree_fixture.php index 31c39e1a6..229ad81eb 100644 --- a/cake/tests/fixtures/flag_tree_fixture.php +++ b/cake/tests/fixtures/flag_tree_fixture.php @@ -14,8 +14,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.5331 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,8 +24,7 @@ * * Like Number Tree, but uses a flag for testing scope parameters * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class FlagTreeFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/fruit_fixture.php b/cake/tests/fixtures/fruit_fixture.php index 484b99478..abd9eeaa4 100644 --- a/cake/tests/fixtures/fruit_fixture.php +++ b/cake/tests/fixtures/fruit_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.7953 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class FruitFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/fruits_uuid_tag_fixture.php b/cake/tests/fixtures/fruits_uuid_tag_fixture.php index 8d7cff938..afa328b38 100644 --- a/cake/tests/fixtures/fruits_uuid_tag_fixture.php +++ b/cake/tests/fixtures/fruits_uuid_tag_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.7953 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class FruitsUuidTagFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/group_update_all_fixture.php b/cake/tests/fixtures/group_update_all_fixture.php index e1dd56bcc..ebd320b99 100644 --- a/cake/tests/fixtures/group_update_all_fixture.php +++ b/cake/tests/fixtures/group_update_all_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class GroupUpdateAllFixture extends CakeTestFixture { public $name = 'GroupUpdateAll'; diff --git a/cake/tests/fixtures/home_fixture.php b/cake/tests/fixtures/home_fixture.php index e3988bcc4..2f90ea64a 100644 --- a/cake/tests/fixtures/home_fixture.php +++ b/cake/tests/fixtures/home_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class HomeFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/image_fixture.php b/cake/tests/fixtures/image_fixture.php index 369b877b9..1eaaae118 100644 --- a/cake/tests/fixtures/image_fixture.php +++ b/cake/tests/fixtures/image_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class ImageFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/item_fixture.php b/cake/tests/fixtures/item_fixture.php index fdca77fcb..8aa2487a1 100644 --- a/cake/tests/fixtures/item_fixture.php +++ b/cake/tests/fixtures/item_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class ItemFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/items_portfolio_fixture.php b/cake/tests/fixtures/items_portfolio_fixture.php index 88029e048..fd128a1eb 100644 --- a/cake/tests/fixtures/items_portfolio_fixture.php +++ b/cake/tests/fixtures/items_portfolio_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class ItemsPortfolioFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/join_a_b_fixture.php b/cake/tests/fixtures/join_a_b_fixture.php index f9d9776a3..d979f30c4 100644 --- a/cake/tests/fixtures/join_a_b_fixture.php +++ b/cake/tests/fixtures/join_a_b_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.6317 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class JoinABFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/join_a_c_fixture.php b/cake/tests/fixtures/join_a_c_fixture.php index b8c9786ca..f66fa499f 100644 --- a/cake/tests/fixtures/join_a_c_fixture.php +++ b/cake/tests/fixtures/join_a_c_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.6317 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class JoinACFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/join_a_fixture.php b/cake/tests/fixtures/join_a_fixture.php index 0910b132d..891697321 100644 --- a/cake/tests/fixtures/join_a_fixture.php +++ b/cake/tests/fixtures/join_a_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.6317 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class JoinAFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/join_b_fixture.php b/cake/tests/fixtures/join_b_fixture.php index e9f5a9019..a636e7243 100644 --- a/cake/tests/fixtures/join_b_fixture.php +++ b/cake/tests/fixtures/join_b_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.6317 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class JoinBFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/join_c_fixture.php b/cake/tests/fixtures/join_c_fixture.php index c50a606e8..d858a5e11 100644 --- a/cake/tests/fixtures/join_c_fixture.php +++ b/cake/tests/fixtures/join_c_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.6317 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class JoinCFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/join_thing_fixture.php b/cake/tests/fixtures/join_thing_fixture.php index 75c009f28..13b8dc8f6 100644 --- a/cake/tests/fixtures/join_thing_fixture.php +++ b/cake/tests/fixtures/join_thing_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class JoinThingFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/message_fixture.php b/cake/tests/fixtures/message_fixture.php index 0c62b85f9..e491f031f 100644 --- a/cake/tests/fixtures/message_fixture.php +++ b/cake/tests/fixtures/message_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class MessageFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/my_categories_my_products_fixture.php b/cake/tests/fixtures/my_categories_my_products_fixture.php index a20ad3daa..d33fafa86 100644 --- a/cake/tests/fixtures/my_categories_my_products_fixture.php +++ b/cake/tests/fixtures/my_categories_my_products_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class MyCategoriesMyProductsFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/my_categories_my_users_fixture.php b/cake/tests/fixtures/my_categories_my_users_fixture.php index 0366794dd..c6c557e0f 100644 --- a/cake/tests/fixtures/my_categories_my_users_fixture.php +++ b/cake/tests/fixtures/my_categories_my_users_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class MyCategoriesMyUsersFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/my_category_fixture.php b/cake/tests/fixtures/my_category_fixture.php index ba1225a1c..954a2d429 100644 --- a/cake/tests/fixtures/my_category_fixture.php +++ b/cake/tests/fixtures/my_category_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class MyCategoryFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/my_product_fixture.php b/cake/tests/fixtures/my_product_fixture.php index e934e4447..424c820c9 100644 --- a/cake/tests/fixtures/my_product_fixture.php +++ b/cake/tests/fixtures/my_product_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class MyProductFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/my_user_fixture.php b/cake/tests/fixtures/my_user_fixture.php index fb2d0c236..09922a594 100644 --- a/cake/tests/fixtures/my_user_fixture.php +++ b/cake/tests/fixtures/my_user_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class MyUserFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/node_fixture.php b/cake/tests/fixtures/node_fixture.php index e5f88c49d..3e527eb0e 100644 --- a/cake/tests/fixtures/node_fixture.php +++ b/cake/tests/fixtures/node_fixture.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.6879 //Correct version number as needed** * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for file. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.6879 //Correct version number as needed** */ class NodeFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/number_tree_fixture.php b/cake/tests/fixtures/number_tree_fixture.php index 80ce2970e..84ea86fce 100644 --- a/cake/tests/fixtures/number_tree_fixture.php +++ b/cake/tests/fixtures/number_tree_fixture.php @@ -14,8 +14,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.5331 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,8 +24,7 @@ * * Generates a tree of data for use testing the tree behavior * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class NumberTreeFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/number_tree_two_fixture.php b/cake/tests/fixtures/number_tree_two_fixture.php index 20f154844..2414acb60 100644 --- a/cake/tests/fixtures/number_tree_two_fixture.php +++ b/cake/tests/fixtures/number_tree_two_fixture.php @@ -14,8 +14,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.5331 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -25,8 +24,7 @@ * * Generates a tree of data for use testing the tree behavior * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class NumberTreeTwoFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/numeric_article_fixture.php b/cake/tests/fixtures/numeric_article_fixture.php index dc5b3b45f..06f86e289 100644 --- a/cake/tests/fixtures/numeric_article_fixture.php +++ b/cake/tests/fixtures/numeric_article_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class NumericArticleFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/overall_favorite_fixture.php b/cake/tests/fixtures/overall_favorite_fixture.php index ddb555496..fb46f74d1 100644 --- a/cake/tests/fixtures/overall_favorite_fixture.php +++ b/cake/tests/fixtures/overall_favorite_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.7198 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class OverallFavoriteFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/person_fixture.php b/cake/tests/fixtures/person_fixture.php index ae8b9391d..652b1dc31 100644 --- a/cake/tests/fixtures/person_fixture.php +++ b/cake/tests/fixtures/person_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.6700 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class PersonFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/portfolio_fixture.php b/cake/tests/fixtures/portfolio_fixture.php index 40a18c7b7..a3c9c3985 100644 --- a/cake/tests/fixtures/portfolio_fixture.php +++ b/cake/tests/fixtures/portfolio_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class PortfolioFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/post_fixture.php b/cake/tests/fixtures/post_fixture.php index 98264bd68..dcc808a60 100644 --- a/cake/tests/fixtures/post_fixture.php +++ b/cake/tests/fixtures/post_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class PostFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/posts_tag_fixture.php b/cake/tests/fixtures/posts_tag_fixture.php index cddf3e4ee..9a1217569 100644 --- a/cake/tests/fixtures/posts_tag_fixture.php +++ b/cake/tests/fixtures/posts_tag_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class PostsTagFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/primary_model_fixture.php b/cake/tests/fixtures/primary_model_fixture.php index 4194f97a7..058489f58 100644 --- a/cake/tests/fixtures/primary_model_fixture.php +++ b/cake/tests/fixtures/primary_model_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class PrimaryModelFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/product_fixture.php b/cake/tests/fixtures/product_fixture.php index 207ae2073..effee768a 100644 --- a/cake/tests/fixtures/product_fixture.php +++ b/cake/tests/fixtures/product_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class ProductFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/product_update_all_fixture.php b/cake/tests/fixtures/product_update_all_fixture.php index 6ca5377f9..80d11cb2f 100644 --- a/cake/tests/fixtures/product_update_all_fixture.php +++ b/cake/tests/fixtures/product_update_all_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class ProductUpdateAllFixture extends CakeTestFixture { public $name = 'ProductUpdateAll'; diff --git a/cake/tests/fixtures/project_fixture.php b/cake/tests/fixtures/project_fixture.php index d28aa1578..961cf532a 100644 --- a/cake/tests/fixtures/project_fixture.php +++ b/cake/tests/fixtures/project_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class ProjectFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/sample_fixture.php b/cake/tests/fixtures/sample_fixture.php index f5e915765..fa150a748 100644 --- a/cake/tests/fixtures/sample_fixture.php +++ b/cake/tests/fixtures/sample_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class SampleFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/secondary_model_fixture.php b/cake/tests/fixtures/secondary_model_fixture.php index c273850d5..0fcf88699 100644 --- a/cake/tests/fixtures/secondary_model_fixture.php +++ b/cake/tests/fixtures/secondary_model_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class SecondaryModelFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/session_fixture.php b/cake/tests/fixtures/session_fixture.php index d517730b1..cbbc89d5c 100644 --- a/cake/tests/fixtures/session_fixture.php +++ b/cake/tests/fixtures/session_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class SessionFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/something_else_fixture.php b/cake/tests/fixtures/something_else_fixture.php index 5b57d72b1..b6d965298 100644 --- a/cake/tests/fixtures/something_else_fixture.php +++ b/cake/tests/fixtures/something_else_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class SomethingElseFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/something_fixture.php b/cake/tests/fixtures/something_fixture.php index c0dfccd6f..356b533ca 100644 --- a/cake/tests/fixtures/something_fixture.php +++ b/cake/tests/fixtures/something_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class SomethingFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/stories_tag_fixture.php b/cake/tests/fixtures/stories_tag_fixture.php index cc2bcf619..4e441b64f 100644 --- a/cake/tests/fixtures/stories_tag_fixture.php +++ b/cake/tests/fixtures/stories_tag_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class StoriesTagFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/story_fixture.php b/cake/tests/fixtures/story_fixture.php index 4604a202f..3a8cdfa6a 100644 --- a/cake/tests/fixtures/story_fixture.php +++ b/cake/tests/fixtures/story_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class StoryFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/syfile_fixture.php b/cake/tests/fixtures/syfile_fixture.php index 59fb672f9..f143adc33 100644 --- a/cake/tests/fixtures/syfile_fixture.php +++ b/cake/tests/fixtures/syfile_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class SyfileFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/tag_fixture.php b/cake/tests/fixtures/tag_fixture.php index a56e4c485..fb792236c 100644 --- a/cake/tests/fixtures/tag_fixture.php +++ b/cake/tests/fixtures/tag_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class TagFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/test_plugin_article_fixture.php b/cake/tests/fixtures/test_plugin_article_fixture.php index af5dfd8ea..79c3c36ff 100644 --- a/cake/tests/fixtures/test_plugin_article_fixture.php +++ b/cake/tests/fixtures/test_plugin_article_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 7660 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class TestPluginArticleFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/test_plugin_comment_fixture.php b/cake/tests/fixtures/test_plugin_comment_fixture.php index 854e098bf..d70038e32 100644 --- a/cake/tests/fixtures/test_plugin_comment_fixture.php +++ b/cake/tests/fixtures/test_plugin_comment_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 7660 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class TestPluginCommentFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/the_paper_monkies_fixture.php b/cake/tests/fixtures/the_paper_monkies_fixture.php index 24060d815..4d64767ce 100644 --- a/cake/tests/fixtures/the_paper_monkies_fixture.php +++ b/cake/tests/fixtures/the_paper_monkies_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class ThePaperMonkiesFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/thread_fixture.php b/cake/tests/fixtures/thread_fixture.php index 76bb1d28b..ed24b6b82 100644 --- a/cake/tests/fixtures/thread_fixture.php +++ b/cake/tests/fixtures/thread_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class ThreadFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/translate_article_fixture.php b/cake/tests/fixtures/translate_article_fixture.php index 756153814..d28417539 100644 --- a/cake/tests/fixtures/translate_article_fixture.php +++ b/cake/tests/fixtures/translate_article_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.5669 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class TranslateArticleFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/translate_fixture.php b/cake/tests/fixtures/translate_fixture.php index c056d3e8c..730dfad64 100644 --- a/cake/tests/fixtures/translate_fixture.php +++ b/cake/tests/fixtures/translate_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.5669 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class TranslateFixture extends CakeTestFixture { @@ -64,23 +62,23 @@ class TranslateFixture extends CakeTestFixture { * @access public */ public $records = array( - array('id' => 1, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Title #1'), - array('id' => 2, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Content #1'), - array('id' => 3, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titel #1'), - array('id' => 4, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Inhalt #1'), - array('id' => 5, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titulek #1'), - array('id' => 6, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Obsah #1'), - array('id' => 7, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 2, 'field' => 'title', 'content' => 'Title #2'), - array('id' => 8, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 2, 'field' => 'content', 'content' => 'Content #2'), - array('id' => 9, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 2, 'field' => 'title', 'content' => 'Titel #2'), - array('id' => 10, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 2, 'field' => 'content', 'content' => 'Inhalt #2'), - array('id' => 11, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 2, 'field' => 'title', 'content' => 'Titulek #2'), - array('id' => 12, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 2, 'field' => 'content', 'content' => 'Obsah #2'), - array('id' => 13, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 3, 'field' => 'title', 'content' => 'Title #3'), - array('id' => 14, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 3, 'field' => 'content', 'content' => 'Content #3'), - array('id' => 15, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 3, 'field' => 'title', 'content' => 'Titel #3'), - array('id' => 16, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 3, 'field' => 'content', 'content' => 'Inhalt #3'), - array('id' => 17, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 3, 'field' => 'title', 'content' => 'Titulek #3'), - array('id' => 18, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 3, 'field' => 'content', 'content' => 'Obsah #3') + array('locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Title #1'), + array('locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Content #1'), + array('locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titel #1'), + array('locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Inhalt #1'), + array('locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titulek #1'), + array('locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Obsah #1'), + array('locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 2, 'field' => 'title', 'content' => 'Title #2'), + array('locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 2, 'field' => 'content', 'content' => 'Content #2'), + array('locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 2, 'field' => 'title', 'content' => 'Titel #2'), + array('locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 2, 'field' => 'content', 'content' => 'Inhalt #2'), + array('locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 2, 'field' => 'title', 'content' => 'Titulek #2'), + array('locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 2, 'field' => 'content', 'content' => 'Obsah #2'), + array('locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 3, 'field' => 'title', 'content' => 'Title #3'), + array('locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 3, 'field' => 'content', 'content' => 'Content #3'), + array('locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 3, 'field' => 'title', 'content' => 'Titel #3'), + array('locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 3, 'field' => 'content', 'content' => 'Inhalt #3'), + array('locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 3, 'field' => 'title', 'content' => 'Titulek #3'), + array('locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 3, 'field' => 'content', 'content' => 'Obsah #3') ); } diff --git a/cake/tests/fixtures/translate_table_fixture.php b/cake/tests/fixtures/translate_table_fixture.php index bae466c86..08a0a3d9a 100644 --- a/cake/tests/fixtures/translate_table_fixture.php +++ b/cake/tests/fixtures/translate_table_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.5669 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class TranslateTableFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/translate_with_prefix_fixture.php b/cake/tests/fixtures/translate_with_prefix_fixture.php index 04549b02e..87045605f 100644 --- a/cake/tests/fixtures/translate_with_prefix_fixture.php +++ b/cake/tests/fixtures/translate_with_prefix_fixture.php @@ -15,8 +15,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.5669 * @version $Revision$ * @modifiedby $LastChangedBy$ @@ -26,8 +25,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class TranslateWithPrefixFixture extends CakeTestFixture { /** diff --git a/cake/tests/fixtures/translated_article_fixture.php b/cake/tests/fixtures/translated_article_fixture.php index 978a8b5f3..b5238baae 100644 --- a/cake/tests/fixtures/translated_article_fixture.php +++ b/cake/tests/fixtures/translated_article_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.5669 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class TranslatedArticleFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/translated_item_fixture.php b/cake/tests/fixtures/translated_item_fixture.php index 91a0571eb..95eede406 100644 --- a/cake/tests/fixtures/translated_item_fixture.php +++ b/cake/tests/fixtures/translated_item_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.5669 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class TranslatedItemFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/unconventional_tree_fixture.php b/cake/tests/fixtures/unconventional_tree_fixture.php index 7d1b39838..ea57f6f06 100644 --- a/cake/tests/fixtures/unconventional_tree_fixture.php +++ b/cake/tests/fixtures/unconventional_tree_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.7879 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,8 +23,7 @@ * Like Number tree, but doesn't use the default values for lft and rght or parent_id * * @uses CakeTestFixture - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class UnconventionalTreeFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/underscore_field_fixture.php b/cake/tests/fixtures/underscore_field_fixture.php index 3322284b1..1962e403d 100644 --- a/cake/tests/fixtures/underscore_field_fixture.php +++ b/cake/tests/fixtures/underscore_field_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * UnderscoreFieldFixture class * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class UnderscoreFieldFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/user_fixture.php b/cake/tests/fixtures/user_fixture.php index 86683d2e9..2adb7841f 100644 --- a/cake/tests/fixtures/user_fixture.php +++ b/cake/tests/fixtures/user_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class UserFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/uuid_fixture.php b/cake/tests/fixtures/uuid_fixture.php index 559dc810b..50f735ceb 100644 --- a/cake/tests/fixtures/uuid_fixture.php +++ b/cake/tests/fixtures/uuid_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.6700 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class UuidFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/uuid_tag_fixture.php b/cake/tests/fixtures/uuid_tag_fixture.php index a126903e8..94e1ba7bc 100644 --- a/cake/tests/fixtures/uuid_tag_fixture.php +++ b/cake/tests/fixtures/uuid_tag_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.7953 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class UuidTagFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/uuid_tree_fixture.php b/cake/tests/fixtures/uuid_tree_fixture.php index c34bc2c3c..5828533e2 100644 --- a/cake/tests/fixtures/uuid_tree_fixture.php +++ b/cake/tests/fixtures/uuid_tree_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.7984 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ * UuidTreeFixture class * * @uses CakeTestFixture - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class UuidTreeFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/uuiditem_fixture.php b/cake/tests/fixtures/uuiditem_fixture.php index 1e70eb287..5b6e15e8e 100644 --- a/cake/tests/fixtures/uuiditem_fixture.php +++ b/cake/tests/fixtures/uuiditem_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class UuiditemFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/uuiditems_uuidportfolio_fixture.php b/cake/tests/fixtures/uuiditems_uuidportfolio_fixture.php index 94a5a2e49..eeafb752d 100644 --- a/cake/tests/fixtures/uuiditems_uuidportfolio_fixture.php +++ b/cake/tests/fixtures/uuiditems_uuidportfolio_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class UuiditemsUuidportfolioFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/uuiditems_uuidportfolio_numericid_fixture.php b/cake/tests/fixtures/uuiditems_uuidportfolio_numericid_fixture.php index c4ae9c768..f8f6baedc 100644 --- a/cake/tests/fixtures/uuiditems_uuidportfolio_numericid_fixture.php +++ b/cake/tests/fixtures/uuiditems_uuidportfolio_numericid_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class UuiditemsUuidportfolioNumericidFixture extends CakeTestFixture { diff --git a/cake/tests/fixtures/uuidportfolio_fixture.php b/cake/tests/fixtures/uuidportfolio_fixture.php index fb3745d3b..3c6b86f28 100644 --- a/cake/tests/fixtures/uuidportfolio_fixture.php +++ b/cake/tests/fixtures/uuidportfolio_fixture.php @@ -12,8 +12,7 @@ * * @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.fixtures + * @package cake.tests.fixtures * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Short description for class. * - * @package cake - * @subpackage cake.tests.fixtures + * @package cake.tests.fixtures */ class UuidportfolioFixture extends CakeTestFixture { diff --git a/cake/tests/lib/cake_fixture_manager.php b/cake/tests/lib/cake_fixture_manager.php index d0a3cba4b..2615847ca 100644 --- a/cake/tests/lib/cake_fixture_manager.php +++ b/cake/tests/lib/cake_fixture_manager.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.tests.libs + * @package cake.tests.libs * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -177,8 +176,8 @@ class CakeFixtureManager { $cacheSources = $db->cacheSources; $db->cacheSources = false; - $db->cacheSources = $cacheSources; $sources = $db->listSources(); + $db->cacheSources = $cacheSources; $table = $db->config['prefix'] . $fixture->table; if ($drop && in_array($table, $sources)) { @@ -206,6 +205,7 @@ class CakeFixtureManager { return; } + $test->db->begin(); foreach ($fixtures as $f) { if (!empty($this->_loaded[$f])) { $fixture = $this->_loaded[$f]; @@ -213,6 +213,7 @@ class CakeFixtureManager { $fixture->insert($test->db); } } + $test->db->commit(); } /** diff --git a/cake/tests/lib/cake_test_case.php b/cake/tests/lib/cake_test_case.php index 184dc7912..7581bd6a8 100644 --- a/cake/tests/lib/cake_test_case.php +++ b/cake/tests/lib/cake_test_case.php @@ -12,8 +12,7 @@ * * @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.cake.tests.libs + * @package cake.tests.libs * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -27,8 +26,7 @@ require_once CAKE_TESTS_LIB . 'cake_test_fixture.php'; /** * CakeTestCase class * - * @package cake - * @subpackage cake.cake.tests.lib + * @package cake.tests.lib */ class CakeTestCase extends PHPUnit_Framework_TestCase { @@ -494,7 +492,7 @@ class CakeTestCase extends PHPUnit_Framework_TestCase { * @return void */ protected function assertIsA($object, $type, $message = '') { - return $this->assertType($type, $object, $message); + return $this->assertInstanceOf($type, $object, $message); } /** diff --git a/cake/tests/lib/cake_test_fixture.php b/cake/tests/lib/cake_test_fixture.php index eeeae5c9d..ec56d09ec 100644 --- a/cake/tests/lib/cake_test_fixture.php +++ b/cake/tests/lib/cake_test_fixture.php @@ -12,8 +12,7 @@ * * @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.cake.tests.libs + * @package cake.tests.libs * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -23,8 +22,7 @@ PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'DEFAULT'); /** * Short description for class. * - * @package cake - * @subpackage cake.cake.tests.lib + * @package cake.tests.lib */ class CakeTestFixture { @@ -165,11 +163,10 @@ class CakeTestFixture { public function insert(&$db) { if (!isset($this->_insert)) { $values = array(); - if (isset($this->records) && !empty($this->records)) { foreach ($this->records as $record) { $fields = array_keys($record); - $values[] = '(' . implode(', ', array_map(array(&$db, 'value'), array_values($record))) . ')'; + $values[] = array_values($record); } return $db->insertMulti($this->table, $fields, $values); } diff --git a/cake/tests/lib/cake_test_model.php b/cake/tests/lib/cake_test_model.php index 819c3cbe2..a896a50d9 100644 --- a/cake/tests/lib/cake_test_model.php +++ b/cake/tests/lib/cake_test_model.php @@ -12,8 +12,7 @@ * * @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.cake.tests.libs + * @package cake.tests.libs * @since CakePHP(tm) v 1.2.0.4667 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -22,8 +21,7 @@ require_once LIBS.'model'.DS.'model.php'; /** * Short description for class. * - * @package cake - * @subpackage cake.cake.tests.lib + * @package cake.tests.lib */ class CakeTestModel extends Model { public $useDbConfig = 'test'; diff --git a/cake/tests/lib/cake_test_suite.php b/cake/tests/lib/cake_test_suite.php index c1ad5adb5..f7d7497d5 100644 --- a/cake/tests/lib/cake_test_suite.php +++ b/cake/tests/lib/cake_test_suite.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.tests.libs + * @package cake.tests.libs * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/lib/cake_test_suite_dispatcher.php b/cake/tests/lib/cake_test_suite_dispatcher.php index 4642dc2b4..36937ed2c 100644 --- a/cake/tests/lib/cake_test_suite_dispatcher.php +++ b/cake/tests/lib/cake_test_suite_dispatcher.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.tests.lib + * @package cake.tests.lib * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/lib/cake_web_test_case.php b/cake/tests/lib/cake_web_test_case.php index 8a98e3525..256e75933 100644 --- a/cake/tests/lib/cake_web_test_case.php +++ b/cake/tests/lib/cake_web_test_case.php @@ -12,8 +12,7 @@ * * @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.cake.tests.lib + * @package cake.tests.lib * @since CakePHP(tm) v 1.2.0.4433 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -21,8 +20,7 @@ /** * Simple wrapper for the WebTestCase provided by SimpleTest * - * @package cake - * @subpackage cake.cake.tests.lib + * @package cake.tests.lib */ class CakeWebTestCase extends WebTestCase { } diff --git a/cake/tests/lib/controller_test_case.php b/cake/tests/lib/controller_test_case.php new file mode 100644 index 000000000..97e71303e --- /dev/null +++ b/cake/tests/lib/controller_test_case.php @@ -0,0 +1,307 @@ + + * 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://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests + * @package cake.tests.libs + * @since CakePHP(tm) v 2.0 + * @license MIT License (http://www.opensource.org/licenses/mit-license.php) + */ + +PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'DEFAULT'); + +require_once CAKE . 'libs' . DS . 'dispatcher.php'; +require_once CAKE_TESTS_LIB . 'cake_test_case.php'; +App::import('Core', array('Router', 'CakeRequest', 'CakeResponse', 'Helper')); + +/** + * ControllerTestDispatcher class + * + * @package cake.tests.lib + */ +class ControllerTestDispatcher extends Dispatcher { + +/** + * The controller to use in the dispatch process + * + * @var Controller + */ + public $testController = null; + +/** + * Use custom routes during tests + * + * @var boolean + */ + public $loadRoutes = true; + +/** + * Returns the test controller + * + * @return Controller + */ + function _getController($request) { + if ($this->testController === null) { + $this->testController = parent::_getController($request); + } + $this->testController->helpers = array_merge(array('InterceptContent'), $this->testController->helpers); + $this->testController->setRequest($request); + $this->testController->response = $this->response; + return $this->testController; + } + +/** + * Loads routes and resets if the test case dictates it should + * + * @return void + */ + protected function _loadRoutes() { + parent::_loadRoutes(); + if (!$this->loadRoutes) { + Router::reload(); + } + } +} + +/** + * InterceptContentHelper class + * + * @package cake.tests.lib + */ +class InterceptContentHelper extends Helper { + +/** + * Intercepts and stores the contents of the view before the layout is rendered + * + * @param string $viewFile The view file + */ + function afterRender($viewFile) { + $this->_View->_viewNoLayout = $this->_View->output; + $this->_View->Helpers->unload('InterceptContent'); + } +} + +/** + * ControllerTestCase class + * + * @package cake.tests.lib + */ +class ControllerTestCase extends CakeTestCase { + +/** + * The controller to test in testAction + * + * @var Controller + */ + public $controller = null; + +/** + * Automatically mock controllers that aren't mocked + * + * @var boolean + */ + public $autoMock = false; + +/** + * Use custom routes during tests + * + * @var boolean + */ + public $loadRoutes = true; + +/** + * The resulting view vars of the last testAction call + * + * @var array + */ + public $vars = null; + +/** + * The resulting rendered view of the last testAction call + * + * @var string + */ + public $view = null; + +/** + * The resulting rendered layout+view of the last testAction call + * + * @var string + */ + public $contents = null; + +/** + * The returned result of the dispatch (requestAction), if any + * + * @var string + */ + public $result = null; + +/** + * The headers that would have been sent by the action + * + * @var string + */ + public $headers = null; + +/** + * Used to enable calling ControllerTestCase::testAction() without the testing + * framework thinking that it's a test case + * + * @param string $name The name of the function + * @param array $arguments Array of arguments + * @return Function + */ + public function __call($name, $arguments) { + if ($name == 'testAction') { + return call_user_func_array(array($this, '_testAction'), $arguments); + } + } + +/** + * Tests a controller action. + * + * ### Options: + * - `data` POST or GET data to pass + * - `method` POST or GET + * + * @param string $url The url to test + * @param array $options See options + */ + private function _testAction($url = '', $options = array()) { + $this->vars = $this->result = $this->view = $this->contents = $this->headers = null; + + $options = array_merge(array( + 'data' => array(), + 'method' => 'POST', + 'return' => 'result' + ), $options); + + if (strtoupper($options['method']) == 'GET') { + $_GET = $options['data']; + $_POST = array(); + } else { + $_POST = array('data' => $options['data']); + $_GET = array(); + } + $request = new CakeRequest($url); + $Dispatch = new ControllerTestDispatcher(); + foreach (Router::$routes as $route) { + if (is_a($route, 'RedirectRoute')) { + $route->response = $this->getMock('CakeResponse', array('send')); + } + } + $Dispatch->loadRoutes = $this->loadRoutes; + $request = $Dispatch->parseParams($request); + if (!isset($request->params['controller'])) { + $this->headers = Router::currentRoute()->response->header(); + return; + } + if ($this->controller !== null && Inflector::camelize($request->params['controller']) !== $this->controller->name) { + $this->controller = null; + } + if ($this->controller === null && $this->autoMock) { + $this->generate(Inflector::camelize($request->params['controller'])); + } + $params = array(); + if ($options['return'] == 'result') { + $params['return'] = 1; + $params['bare'] = 1; + $params['requested'] = 1; + } + $Dispatch->testController = $this->controller; + $Dispatch->response = $this->getMock('CakeResponse', array('send')); + $this->result = $Dispatch->dispatch($request, $params); + $this->controller = $Dispatch->testController; + if ($options['return'] != 'result') { + $this->vars = $this->controller->View->viewVars; + $this->view = $this->controller->View->_viewNoLayout; + $this->contents = $this->controller->response->body(); + } + $this->headers = $Dispatch->response->header(); + return $this->{$options['return']}; + } + +/** + * Generates a mocked controller and mocks any classes passed to `$mocks`. By + * default, `_stop()` is stubbed as is sending the response headers, so to not + * interfere with testing. + * + * ### Mocks: + * + * - `methods` Methods to mock on the controller. `_stop()` is mocked by default + * - `models` Models to mock. Models are added to the ClassRegistry so they any + * time they are instatiated the mock will be created. Pass as key value pairs + * with the value being specific methods on the model to mock. If `true` or + * no value is passed, the entire model will be mocked. + * - `components` Components to mock. Components are only mocked on this controller + * and not within each other (i.e., components on components) + * + * @param string $controller Controller name + * @param array $mocks List of classes and methods to mock + * @return Controller Mocked controller + */ + public function generate($controller, $mocks = array()) { + if (!class_exists($controller.'Controller') && App::import('Controller', $controller) === false) { + throw new MissingControllerException(array('controller' => $controller.'Controller')); + } + ClassRegistry::flush(); + + $mocks = array_merge_recursive(array( + 'methods' => array('_stop'), + 'models' => array(), + 'components' => array() + ), (array)$mocks); + + $_controller = $this->getMock($controller.'Controller', $mocks['methods'], array(), '', false); + $_controller->name = $controller; + $_controller->__construct(); + + $config = ClassRegistry::config('Model'); + foreach ($mocks['models'] as $model => $methods) { + if (is_string($methods)) { + $model = $methods; + $methods = true; + } + if ($methods === true) { + $methods = array(); + } + $config = array_merge((array)$config, array('name' => $model)); + $_model = $this->getMock($model, $methods, array($config)); + ClassRegistry::removeObject($model); + ClassRegistry::addObject($model, $_model); + } + + foreach ($mocks['components'] as $component => $methods) { + if (is_string($methods)) { + $component = $methods; + $methods = true; + } + if ($methods === true) { + $methods = array(); + } + if (!App::import('Component', $component)) { + throw new MissingComponentFileException(array( + 'file' => Inflector::underscore($component) . '.php', + 'class' => $componentClass + )); + } + $_component = $this->getMock($component.'Component', $methods, array(), '', false); + $_controller->Components->set($component, $_component); + } + + $_controller->constructClasses(); + + $this->controller = $_controller; + return $this->controller; + } +} \ No newline at end of file diff --git a/cake/tests/lib/coverage/base_coverage_report.php b/cake/tests/lib/coverage/base_coverage_report.php index d532f06d6..7960a6e75 100644 --- a/cake/tests/lib/coverage/base_coverage_report.php +++ b/cake/tests/lib/coverage/base_coverage_report.php @@ -14,7 +14,6 @@ * @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) */ diff --git a/cake/tests/lib/coverage/html_coverage_report.php b/cake/tests/lib/coverage/html_coverage_report.php index ae4fa081c..bdd18e972 100644 --- a/cake/tests/lib/coverage/html_coverage_report.php +++ b/cake/tests/lib/coverage/html_coverage_report.php @@ -13,7 +13,6 @@ * @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) */ diff --git a/cake/tests/lib/coverage/text_coverage_report.php b/cake/tests/lib/coverage/text_coverage_report.php index 3450f2b36..66e84d32e 100644 --- a/cake/tests/lib/coverage/text_coverage_report.php +++ b/cake/tests/lib/coverage/text_coverage_report.php @@ -13,7 +13,6 @@ * @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) */ diff --git a/cake/tests/lib/reporter/cake_base_reporter.php b/cake/tests/lib/reporter/cake_base_reporter.php index f20bf1928..9f4b3d3ec 100644 --- a/cake/tests/lib/reporter/cake_base_reporter.php +++ b/cake/tests/lib/reporter/cake_base_reporter.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.libs.reporter + * @package cake.tests.libs.reporter * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,7 +23,7 @@ PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'DEFAULT'); * CakeBaseReporter contains common reporting features used in the CakePHP Test suite * * @package cake - * @subpackage cake.tests.lib + * @package cake.tests.lib */ class CakeBaseReporter implements PHPUnit_Framework_TestListener { diff --git a/cake/tests/lib/reporter/cake_html_reporter.php b/cake/tests/lib/reporter/cake_html_reporter.php index 186c3fe73..63153ba9c 100755 --- a/cake/tests/lib/reporter/cake_html_reporter.php +++ b/cake/tests/lib/reporter/cake_html_reporter.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.libs.reporter + * @package cake.tests.libs.reporter * @since CakePHP(tm) v 1.2.0.4433 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -26,7 +25,7 @@ PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'DEFAULT'); * in an HTML format / context. * * @package cake - * @subpackage cake.tests.lib + * @package cake.tests.lib */ class CakeHtmlReporter extends CakeBaseReporter { @@ -62,7 +61,7 @@ class CakeHtmlReporter extends CakeBaseReporter { */ public function paintTestMenu() { $cases = $this->baseUrl() . '?show=cases'; - $plugins = App::objects('plugin'); + $plugins = App::objects('plugin', null, false); sort($plugins); include CAKE_TESTS_LIB . 'templates' . DS . 'menu.php'; } diff --git a/cake/tests/lib/reporter/cake_text_reporter.php b/cake/tests/lib/reporter/cake_text_reporter.php index 070855c1b..cf4cea447 100644 --- a/cake/tests/lib/reporter/cake_text_reporter.php +++ b/cake/tests/lib/reporter/cake_text_reporter.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.libs.reporter + * @package cake.tests.libs.reporter * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -26,7 +25,7 @@ PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'DEFAULT'); * CakeTextReporter contains reporting features used for plain text based output * * @package cake - * @subpackage cake.tests.lib + * @package cake.tests.lib */ class CakeTextReporter extends CakeBaseReporter { diff --git a/cake/tests/lib/templates/footer.php b/cake/tests/lib/templates/footer.php index e9b6c6746..0f6ab6a69 100644 --- a/cake/tests/lib/templates/footer.php +++ b/cake/tests/lib/templates/footer.php @@ -12,8 +12,7 @@ * * @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.cake.tests.lib + * @package cake.tests.lib * @since CakePHP(tm) v 1.2.0.4433 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/lib/templates/header.php b/cake/tests/lib/templates/header.php index 5f80658c1..df19f02d9 100644 --- a/cake/tests/lib/templates/header.php +++ b/cake/tests/lib/templates/header.php @@ -12,8 +12,7 @@ * * @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.cake.tests.lib + * @package cake.tests.lib * @since CakePHP(tm) v 1.2.0.4433 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/lib/templates/menu.php b/cake/tests/lib/templates/menu.php index a596ac139..bb81dc7cf 100644 --- a/cake/tests/lib/templates/menu.php +++ b/cake/tests/lib/templates/menu.php @@ -12,8 +12,7 @@ * * @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.cake.tests.lib + * @package cake.tests.lib * @since CakePHP(tm) v 1.2.0.4433 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/lib/templates/missing_conenction.php b/cake/tests/lib/templates/missing_conenction.php index 37c242507..eb88d1aaa 100644 --- a/cake/tests/lib/templates/missing_conenction.php +++ b/cake/tests/lib/templates/missing_conenction.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests - * @package cake - * @subpackage cake.cake.tests.libs + * @package cake.tests.libs * @since CakePHP(tm) v 1.2.0.4433 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/lib/templates/phpunit.php b/cake/tests/lib/templates/phpunit.php index 4a865523b..0e525d5ab 100644 --- a/cake/tests/lib/templates/phpunit.php +++ b/cake/tests/lib/templates/phpunit.php @@ -13,8 +13,7 @@ * * @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.cake.tests.libs + * @package cake.tests.libs * @since CakePHP(tm) v 1.2.0.4433 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/lib/templates/xdebug.php b/cake/tests/lib/templates/xdebug.php index 5722a91ff..f826509eb 100644 --- a/cake/tests/lib/templates/xdebug.php +++ b/cake/tests/lib/templates/xdebug.php @@ -12,8 +12,7 @@ * * @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.cake.tests.libs + * @package cake.tests.libs * @since CakePHP(tm) v 1.2.0.4433 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/lib/test_manager.php b/cake/tests/lib/test_manager.php index f4f5b4571..7cb6a3fdd 100644 --- a/cake/tests/lib/test_manager.php +++ b/cake/tests/lib/test_manager.php @@ -12,8 +12,7 @@ * * @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.cake.tests.lib + * @package cake.tests.lib * @since CakePHP(tm) v 1.2.0.4433 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -29,8 +28,7 @@ require_once CAKE_TESTS_LIB . 'cake_test_suite.php'; * TestManager is the base class that handles loading and initiating the running * of TestCase and TestSuite classes that the user has selected. * - * @package cake - * @subpackage cake.cake.tests.lib + * @package cake.tests.lib */ class TestManager { /** @@ -89,6 +87,7 @@ class TestManager { */ public function __construct($params = array()) { require_once(CAKE_TESTS_LIB . 'cake_test_case.php'); + require_once(CAKE_TESTS_LIB . 'controller_test_case.php'); $this->params = $params; if (isset($params['app'])) { diff --git a/cake/tests/lib/test_runner.php b/cake/tests/lib/test_runner.php index c2ca7f809..22def2a23 100644 --- a/cake/tests/lib/test_runner.php +++ b/cake/tests/lib/test_runner.php @@ -12,8 +12,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.tests.libs + * @package cake.tests.libs * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -27,8 +26,7 @@ PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'DEFAULT'); /** * Class to customize loading of test suites from CLI * - * @package cake - * @subpackage cake.cake.tests.lib + * @package cake.tests.lib */ class TestRunner extends PHPUnit_TextUI_Command { diff --git a/cake/tests/test_app/config/acl.ini.php b/cake/tests/test_app/config/acl.ini.php index 3c53bfde1..d2f06fc4d 100644 --- a/cake/tests/test_app/config/acl.ini.php +++ b/cake/tests/test_app/config/acl.ini.php @@ -14,8 +14,7 @@ ; * ; * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) ; * @link http://cakephp.org CakePHP(tm) Project -; * @package cake -; * @subpackage cake.app.config +;; * @package app.config ; * @since CakePHP(tm) v 0.10.0.1076 ; * @license MIT License (http://www.opensource.org/licenses/mit-license.php) ; */ diff --git a/cake/tests/test_app/config/empty.php b/cake/tests/test_app/config/empty.php new file mode 100644 index 000000000..01d4f0a16 --- /dev/null +++ b/cake/tests/test_app/config/empty.php @@ -0,0 +1,2 @@ + 'tests_apps', 'action' => 'some_method')); +Router::redirect('/redirect_me_now', 'http://cakephp.org'); +Router::redirect('/redirect_me', array('controller' => 'tests_apps', 'action' => 'some_method')); \ No newline at end of file diff --git a/cake/tests/test_app/config/var_test.php b/cake/tests/test_app/config/var_test.php new file mode 100644 index 000000000..e0f3ae2a1 --- /dev/null +++ b/cake/tests/test_app/config/var_test.php @@ -0,0 +1,9 @@ + 'value', + 'Deep' => array( + 'Deeper' => array( + 'Deepest' => 'buried' + ) + ) +); \ No newline at end of file diff --git a/cake/tests/test_app/console/shells/sample.php b/cake/tests/test_app/console/shells/sample.php index 8994803e8..aa892b1ec 100644 --- a/cake/tests/test_app/console/shells/sample.php +++ b/cake/tests/test_app/console/shells/sample.php @@ -12,8 +12,7 @@ * * @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.test_app.vendors.shells + * @package cake.tests.test_app.vendors.shells * @since CakePHP(tm) v 1.2.0.7871 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/controllers/tests_apps_controller.php b/cake/tests/test_app/controllers/tests_apps_controller.php index 28ed43f53..24f193b48 100644 --- a/cake/tests/test_app/controllers/tests_apps_controller.php +++ b/cake/tests/test_app/controllers/tests_apps_controller.php @@ -12,8 +12,7 @@ * * @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.test_app.plugins.test_plugin.views.helpers + * @package cake.tests.test_app.plugins.test_plugin.views.helpers * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -32,4 +31,8 @@ class TestsAppsController extends AppController { $this->set('var', 'string'); $this->render('index'); } + + function redirect_to() { + $this->redirect('http://cakephp.org'); + } } diff --git a/cake/tests/test_app/controllers/tests_apps_posts_controller.php b/cake/tests/test_app/controllers/tests_apps_posts_controller.php index 0b11bd068..af28f42c4 100644 --- a/cake/tests/test_app/controllers/tests_apps_posts_controller.php +++ b/cake/tests/test_app/controllers/tests_apps_posts_controller.php @@ -12,8 +12,7 @@ * * @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.test_app.plugins.test_plugin.views.helpers + * @package cake.tests.test_app.plugins.test_plugin.views.helpers * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/libs/cache/test_app_cache.php b/cake/tests/test_app/libs/cache/test_app_cache.php index d138764d3..1a8a47ac0 100644 --- a/cake/tests/test_app/libs/cache/test_app_cache.php +++ b/cake/tests/test_app/libs/cache/test_app_cache.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/libs/library.php b/cake/tests/test_app/libs/library.php index 5047e0868..10fc5f10f 100644 --- a/cake/tests/test_app/libs/library.php +++ b/cake/tests/test_app/libs/library.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/libs/log/test_app_log.php b/cake/tests/test_app/libs/log/test_app_log.php index bd65581dc..129e1b65d 100644 --- a/cake/tests/test_app/libs/log/test_app_log.php +++ b/cake/tests/test_app/libs/log/test_app_log.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/models/behaviors/persister_one_behavior.php b/cake/tests/test_app/models/behaviors/persister_one_behavior.php index eebe0ba5d..8ef3cf6af 100644 --- a/cake/tests/test_app/models/behaviors/persister_one_behavior.php +++ b/cake/tests/test_app/models/behaviors/persister_one_behavior.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.test_app.models + * @package cake.tests.test_app.models * @since CakePHP(tm) v 1.2.0.5669 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,8 +23,7 @@ * Behavior to allow for dynamic and atomic manipulation of a Model's associations used for a find call. Most useful for limiting * the amount of associations and data returned. * - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.libs */ class PersisterOneBehaviorBehavior extends ModelBehavior { } diff --git a/cake/tests/test_app/models/behaviors/persister_two_behavior.php b/cake/tests/test_app/models/behaviors/persister_two_behavior.php index e17180e24..6cbd0483b 100644 --- a/cake/tests/test_app/models/behaviors/persister_two_behavior.php +++ b/cake/tests/test_app/models/behaviors/persister_two_behavior.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.test_app.models + * @package cake.tests.test_app.models * @since CakePHP(tm) v 1.2.0.5669 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ @@ -24,8 +23,7 @@ * Behavior to allow for dynamic and atomic manipulation of a Model's associations used for a find call. Most useful for limiting * the amount of associations and data returned. * - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.libs */ class PersisterTwoBehaviorBehavior extends ModelBehavior { } diff --git a/cake/tests/test_app/models/comment.php b/cake/tests/test_app/models/comment.php index 9ded58dde..0f0b142d8 100644 --- a/cake/tests/test_app/models/comment.php +++ b/cake/tests/test_app/models/comment.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.cake.libs. + * @package cake.libs. * @since CakePHP v 1.2.0.7726 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/models/persister_one.php b/cake/tests/test_app/models/persister_one.php index a13bc3c65..26e1b1dd6 100644 --- a/cake/tests/test_app/models/persister_one.php +++ b/cake/tests/test_app/models/persister_one.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.tests.test_app.models + * @package cake.tests.test_app.models * @since CakePHP v 1.2.0.7726 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/models/persister_two.php b/cake/tests/test_app/models/persister_two.php index b157e7850..68313cd6e 100644 --- a/cake/tests/test_app/models/persister_two.php +++ b/cake/tests/test_app/models/persister_two.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.tests.test_app.models + * @package cake.tests.test_app.models * @since CakePHP v 1.2.0.7726 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/models/post.php b/cake/tests/test_app/models/post.php index 2155d970d..5a1c15370 100644 --- a/cake/tests/test_app/models/post.php +++ b/cake/tests/test_app/models/post.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.cake.libs. + * @package cake.libs. * @since CakePHP v 1.2.0.7726 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/config/load.php b/cake/tests/test_app/plugins/test_plugin/config/load.php index 709468c0a..07576e051 100644 --- a/cake/tests/test_app/plugins/test_plugin/config/load.php +++ b/cake/tests/test_app/plugins/test_plugin/config/load.php @@ -12,8 +12,7 @@ * * @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.test_app + * @package cake.tests.test_app * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/config/more.load.php b/cake/tests/test_app/plugins/test_plugin/config/more.load.php index bedf5cff0..f0c9744f8 100644 --- a/cake/tests/test_app/plugins/test_plugin/config/more.load.php +++ b/cake/tests/test_app/plugins/test_plugin/config/more.load.php @@ -12,8 +12,7 @@ * * @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.test_app + * @package cake.tests.test_app * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/config/schema/schema.php b/cake/tests/test_app/plugins/test_plugin/config/schema/schema.php index fd3a283c8..9f9bd3571 100644 --- a/cake/tests/test_app/plugins/test_plugin/config/schema/schema.php +++ b/cake/tests/test_app/plugins/test_plugin/config/schema/schema.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.app.config.sql + * @package app.config.sql * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/console/shells/example.php b/cake/tests/test_app/plugins/test_plugin/console/shells/example.php index 8380eb901..76e750913 100644 --- a/cake/tests/test_app/plugins/test_plugin/console/shells/example.php +++ b/cake/tests/test_app/plugins/test_plugin/console/shells/example.php @@ -12,8 +12,7 @@ * * @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.test_app.plugins.test_plugin.vendors.shells + * @package cake.tests.test_app.plugins.test_plugin.vendors.shells * @since CakePHP(tm) v 1.2.0.7871 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/console/shells/tasks/other_task.php b/cake/tests/test_app/plugins/test_plugin/console/shells/tasks/other_task.php index 4c4dc2823..ca6668b2f 100644 --- a/cake/tests/test_app/plugins/test_plugin/console/shells/tasks/other_task.php +++ b/cake/tests/test_app/plugins/test_plugin/console/shells/tasks/other_task.php @@ -12,8 +12,7 @@ * * @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.test_app.plugins.test_plugin.vendors.shells + * @package cake.tests.test_app.plugins.test_plugin.vendors.shells * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/controllers/components/other_component.php b/cake/tests/test_app/plugins/test_plugin/controllers/components/other_component.php index 08168bb27..cff9b4a0d 100644 --- a/cake/tests/test_app/plugins/test_plugin/controllers/components/other_component.php +++ b/cake/tests/test_app/plugins/test_plugin/controllers/components/other_component.php @@ -12,8 +12,7 @@ * * @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.test_app.plugins.test_plugin.views.helpers + * @package cake.tests.test_app.plugins.test_plugin.views.helpers * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/controllers/components/plugins_component.php b/cake/tests/test_app/plugins/test_plugin/controllers/components/plugins_component.php index b3bd6f25f..8c478bba6 100644 --- a/cake/tests/test_app/plugins/test_plugin/controllers/components/plugins_component.php +++ b/cake/tests/test_app/plugins/test_plugin/controllers/components/plugins_component.php @@ -12,8 +12,7 @@ * * @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.test_app.plugins.test_plugin.views.helpers + * @package cake.tests.test_app.plugins.test_plugin.views.helpers * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/controllers/components/test_plugin_component.php b/cake/tests/test_app/plugins/test_plugin/controllers/components/test_plugin_component.php index 78e87ce56..c09948394 100644 --- a/cake/tests/test_app/plugins/test_plugin/controllers/components/test_plugin_component.php +++ b/cake/tests/test_app/plugins/test_plugin/controllers/components/test_plugin_component.php @@ -12,8 +12,7 @@ * * @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.test_app.plugins.test_plugin.views.helpers + * @package cake.tests.test_app.plugins.test_plugin.views.helpers * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/controllers/components/test_plugin_other_component.php b/cake/tests/test_app/plugins/test_plugin/controllers/components/test_plugin_other_component.php index 3b2bb344d..28acded03 100644 --- a/cake/tests/test_app/plugins/test_plugin/controllers/components/test_plugin_other_component.php +++ b/cake/tests/test_app/plugins/test_plugin/controllers/components/test_plugin_other_component.php @@ -12,8 +12,7 @@ * * @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.test_app.plugins.test_plugin.views.helpers + * @package cake.tests.test_app.plugins.test_plugin.views.helpers * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/controllers/test_plugin_controller.php b/cake/tests/test_app/plugins/test_plugin/controllers/test_plugin_controller.php index 87fd60dc7..2ad779059 100644 --- a/cake/tests/test_app/plugins/test_plugin/controllers/test_plugin_controller.php +++ b/cake/tests/test_app/plugins/test_plugin/controllers/test_plugin_controller.php @@ -12,8 +12,7 @@ * * @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.test_app.plugins.test_plugin.views.helpers + * @package cake.tests.test_app.plugins.test_plugin.views.helpers * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/controllers/tests_controller.php b/cake/tests/test_app/plugins/test_plugin/controllers/tests_controller.php index ea74c447e..36d67e950 100644 --- a/cake/tests/test_app/plugins/test_plugin/controllers/tests_controller.php +++ b/cake/tests/test_app/plugins/test_plugin/controllers/tests_controller.php @@ -12,8 +12,7 @@ * * @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.test_app.plugins.test_plugin.views.helpers + * @package cake.tests.test_app.plugins.test_plugin.views.helpers * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/libs/cache/test_plugin_cache.php b/cake/tests/test_app/plugins/test_plugin/libs/cache/test_plugin_cache.php index 3342755dc..a1afa5d46 100644 --- a/cake/tests/test_app/plugins/test_plugin/libs/cache/test_plugin_cache.php +++ b/cake/tests/test_app/plugins/test_plugin/libs/cache/test_plugin_cache.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/libs/log/test_plugin_log.php b/cake/tests/test_app/plugins/test_plugin/libs/log/test_plugin_log.php index 3ce8c9837..3072ca08e 100644 --- a/cake/tests/test_app/plugins/test_plugin/libs/log/test_plugin_log.php +++ b/cake/tests/test_app/plugins/test_plugin/libs/log/test_plugin_log.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/libs/test_plugin_library.php b/cake/tests/test_app/plugins/test_plugin/libs/test_plugin_library.php index decf3ef66..647e33177 100644 --- a/cake/tests/test_app/plugins/test_plugin/libs/test_plugin_library.php +++ b/cake/tests/test_app/plugins/test_plugin/libs/test_plugin_library.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.5432 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/models/behaviors/test_plugin_persister_one.php b/cake/tests/test_app/plugins/test_plugin/models/behaviors/test_plugin_persister_one.php index 4a54e3554..669ac584c 100644 --- a/cake/tests/test_app/plugins/test_plugin/models/behaviors/test_plugin_persister_one.php +++ b/cake/tests/test_app/plugins/test_plugin/models/behaviors/test_plugin_persister_one.php @@ -15,8 +15,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.test_app.models + * @package cake.tests.test_app.models * @since CakePHP(tm) v 1.2.0.5669 * @version $Revision$ * @modifiedby $LastChangedBy$ @@ -27,8 +26,7 @@ * Behavior to allow for dynamic and atomic manipulation of a Model's associations used for a find call. Most useful for limiting * the amount of associations and data returned. * - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.libs */ class TestPluginPersisterOneBehavior extends ModelBehavior { } diff --git a/cake/tests/test_app/plugins/test_plugin/models/behaviors/test_plugin_persister_two.php b/cake/tests/test_app/plugins/test_plugin/models/behaviors/test_plugin_persister_two.php index 90ba761e0..162078e51 100644 --- a/cake/tests/test_app/plugins/test_plugin/models/behaviors/test_plugin_persister_two.php +++ b/cake/tests/test_app/plugins/test_plugin/models/behaviors/test_plugin_persister_two.php @@ -15,8 +15,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.tests.test_app.models + * @package cake.tests.test_app.models * @since CakePHP(tm) v 1.2.0.5669 * @version $Revision$ * @modifiedby $LastChangedBy$ @@ -27,8 +26,7 @@ * Behavior to allow for dynamic and atomic manipulation of a Model's associations used for a find call. Most useful for limiting * the amount of associations and data returned. * - * @package cake - * @subpackage cake.cake.console.libs + * @package cake.console.libs */ class TestPluginPersisterTwoBehavior extends ModelBehavior { } diff --git a/cake/tests/test_app/plugins/test_plugin/models/test_plugin_auth_user.php b/cake/tests/test_app/plugins/test_plugin/models/test_plugin_auth_user.php index 430d5c446..74519a19d 100644 --- a/cake/tests/test_app/plugins/test_plugin/models/test_plugin_auth_user.php +++ b/cake/tests/test_app/plugins/test_plugin/models/test_plugin_auth_user.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.cake.tests.test_app.plugins.test_plugin + * @package cake.tests.test_app.plugins.test_plugin * @since CakePHP v 1.2.0.4487 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/models/test_plugin_authors.php b/cake/tests/test_app/plugins/test_plugin/models/test_plugin_authors.php index ac9782643..0edd39cf1 100644 --- a/cake/tests/test_app/plugins/test_plugin/models/test_plugin_authors.php +++ b/cake/tests/test_app/plugins/test_plugin/models/test_plugin_authors.php @@ -15,8 +15,7 @@ * * @copyright Copyright 2006-2008, Cake Software Foundation, Inc. * @link http://cakefoundation.org/projects/info/cakephp CakePHP Project - * @package cake - * @subpackage cake.cake.libs. + * @package cake.libs. * @since CakePHP v 1.2.0.7726 * @version $Revision$ * @modifiedby $LastChangedBy$ diff --git a/cake/tests/test_app/plugins/test_plugin/models/test_plugin_comment.php b/cake/tests/test_app/plugins/test_plugin/models/test_plugin_comment.php index 781841fa2..afef031a3 100644 --- a/cake/tests/test_app/plugins/test_plugin/models/test_plugin_comment.php +++ b/cake/tests/test_app/plugins/test_plugin/models/test_plugin_comment.php @@ -15,8 +15,7 @@ * * @copyright Copyright 2006-2008, Cake Software Foundation, Inc. * @link http://cakefoundation.org/projects/info/cakephp CakePHP Project - * @package cake - * @subpackage cake.cake.libs. + * @package cake.libs. * @since CakePHP v 1.2.0.7726 * @version $Revision$ * @modifiedby $LastChangedBy$ diff --git a/cake/tests/test_app/plugins/test_plugin/models/test_plugin_post.php b/cake/tests/test_app/plugins/test_plugin/models/test_plugin_post.php index 0c6090a76..b0441191f 100644 --- a/cake/tests/test_app/plugins/test_plugin/models/test_plugin_post.php +++ b/cake/tests/test_app/plugins/test_plugin/models/test_plugin_post.php @@ -14,8 +14,7 @@ * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://cakephp.org CakePHP Project - * @package cake - * @subpackage cake.cake.tests.test_app.plugins.test_plugin + * @package cake.tests.test_app.plugins.test_plugin * @since CakePHP v 1.2.0.4487 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/test_plugin_app_controller.php b/cake/tests/test_app/plugins/test_plugin/test_plugin_app_controller.php index 89b70da0d..f8c2265d5 100644 --- a/cake/tests/test_app/plugins/test_plugin/test_plugin_app_controller.php +++ b/cake/tests/test_app/plugins/test_plugin/test_plugin_app_controller.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.5432 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/test_plugin_app_model.php b/cake/tests/test_app/plugins/test_plugin/test_plugin_app_model.php index 5f6162fcc..6dc24ad8b 100644 --- a/cake/tests/test_app/plugins/test_plugin/test_plugin_app_model.php +++ b/cake/tests/test_app/plugins/test_plugin/test_plugin_app_model.php @@ -12,8 +12,7 @@ * * @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 + * @package cake.tests.cases.libs * @since CakePHP(tm) v 1.2.0.5432 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/vendors/sample/sample_plugin.php b/cake/tests/test_app/plugins/test_plugin/vendors/sample/sample_plugin.php index 2566444f9..435b67a84 100644 --- a/cake/tests/test_app/plugins/test_plugin/vendors/sample/sample_plugin.php +++ b/cake/tests/test_app/plugins/test_plugin/vendors/sample/sample_plugin.php @@ -12,8 +12,7 @@ * * @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.test_app.plugins.test_plugin.vendors.sample + * @package cake.tests.test_app.plugins.test_plugin.vendors.sample * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/vendors/welcome.php b/cake/tests/test_app/plugins/test_plugin/vendors/welcome.php index 50dbe616f..41d62cbd0 100644 --- a/cake/tests/test_app/plugins/test_plugin/vendors/welcome.php +++ b/cake/tests/test_app/plugins/test_plugin/vendors/welcome.php @@ -12,8 +12,7 @@ * * @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.test_app.plugins.test_plugin.vendors + * @package cake.tests.test_app.plugins.test_plugin.vendors * @since CakePHP(tm) v 1.2.0.7629 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/views/helpers/other_helper.php b/cake/tests/test_app/plugins/test_plugin/views/helpers/other_helper.php index 07b109f6b..eb70d228c 100644 --- a/cake/tests/test_app/plugins/test_plugin/views/helpers/other_helper.php +++ b/cake/tests/test_app/plugins/test_plugin/views/helpers/other_helper.php @@ -12,8 +12,7 @@ * * @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.test_app.plugins.test_plugin.views.helpers + * @package cake.tests.test_app.plugins.test_plugin.views.helpers * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/views/helpers/plugged_helper.php b/cake/tests/test_app/plugins/test_plugin/views/helpers/plugged_helper.php index fee89f004..d92752535 100644 --- a/cake/tests/test_app/plugins/test_plugin/views/helpers/plugged_helper.php +++ b/cake/tests/test_app/plugins/test_plugin/views/helpers/plugged_helper.php @@ -12,8 +12,7 @@ * * @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.test_app.plugins.test_plugin.views.helpers + * @package cake.tests.test_app.plugins.test_plugin.views.helpers * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin/views/tests/scaffold.edit.ctp b/cake/tests/test_app/plugins/test_plugin/views/tests/scaffold.form.ctp similarity index 100% rename from cake/tests/test_app/plugins/test_plugin/views/tests/scaffold.edit.ctp rename to cake/tests/test_app/plugins/test_plugin/views/tests/scaffold.form.ctp diff --git a/cake/tests/test_app/plugins/test_plugin_two/console/shells/example.php b/cake/tests/test_app/plugins/test_plugin_two/console/shells/example.php index dea25fd74..290188779 100644 --- a/cake/tests/test_app/plugins/test_plugin_two/console/shells/example.php +++ b/cake/tests/test_app/plugins/test_plugin_two/console/shells/example.php @@ -12,8 +12,7 @@ * * @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.test_app.plugins.test_plugin_two.vendors.shells + * @package cake.tests.test_app.plugins.test_plugin_two.vendors.shells * @since CakePHP(tm) v 1.2.0.7871 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/plugins/test_plugin_two/console/shells/welcome.php b/cake/tests/test_app/plugins/test_plugin_two/console/shells/welcome.php index 7c091ea92..7c7da0c3a 100644 --- a/cake/tests/test_app/plugins/test_plugin_two/console/shells/welcome.php +++ b/cake/tests/test_app/plugins/test_plugin_two/console/shells/welcome.php @@ -12,8 +12,7 @@ * * @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.test_app.plugins.test_plugin_two.vendors.shells + * @package cake.tests.test_app.plugins.test_plugin_two.vendors.shells * @since CakePHP(tm) v 1.2.0.7871 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/vendors/Test/MyTest.php b/cake/tests/test_app/vendors/Test/MyTest.php index 888c9395d..d1a94d55b 100644 --- a/cake/tests/test_app/vendors/Test/MyTest.php +++ b/cake/tests/test_app/vendors/Test/MyTest.php @@ -12,8 +12,7 @@ * * @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.test_app.vendors.somename + * @package cake.tests.test_app.vendors.somename * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/vendors/Test/hello.php b/cake/tests/test_app/vendors/Test/hello.php index e6cd3fbba..7f886aef0 100644 --- a/cake/tests/test_app/vendors/Test/hello.php +++ b/cake/tests/test_app/vendors/Test/hello.php @@ -12,8 +12,7 @@ * * @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.test_app.vendors.Test + * @package cake.tests.test_app.vendors.Test * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/vendors/sample/configure_test_vendor_sample.php b/cake/tests/test_app/vendors/sample/configure_test_vendor_sample.php index 16ba606ba..58e797165 100644 --- a/cake/tests/test_app/vendors/sample/configure_test_vendor_sample.php +++ b/cake/tests/test_app/vendors/sample/configure_test_vendor_sample.php @@ -12,8 +12,7 @@ * * @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.test_app.vendors.sample + * @package cake.tests.test_app.vendors.sample * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/vendors/somename/some.name.php b/cake/tests/test_app/vendors/somename/some.name.php index 54c144fe3..1394bf894 100644 --- a/cake/tests/test_app/vendors/somename/some.name.php +++ b/cake/tests/test_app/vendors/somename/some.name.php @@ -12,8 +12,7 @@ * * @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.test_app.vendors.somename + * @package cake.tests.test_app.vendors.somename * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/vendors/welcome.php b/cake/tests/test_app/vendors/welcome.php index dedd3e196..6b36caf0c 100644 --- a/cake/tests/test_app/vendors/welcome.php +++ b/cake/tests/test_app/vendors/welcome.php @@ -12,8 +12,7 @@ * * @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.test_app.vendors + * @package cake.tests.test_app.vendors * @since CakePHP(tm) v 1.2.0.7629 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/views/elements/email/html/custom.ctp b/cake/tests/test_app/views/elements/email/html/custom.ctp index 6b46d7c65..6d1b5702a 100644 --- a/cake/tests/test_app/views/elements/email/html/custom.ctp +++ b/cake/tests/test_app/views/elements/email/html/custom.ctp @@ -13,8 +13,7 @@ * * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.elements.email.html + * @package cake.libs.view.templates.elements.email.html * @since CakePHP(tm) v 0.10.0.1076 * @version $Revision$ * @modifiedby $LastChangedBy$ diff --git a/cake/tests/test_app/views/elements/email/html/default.ctp b/cake/tests/test_app/views/elements/email/html/default.ctp index de87b4eb8..8efbaa94d 100644 --- a/cake/tests/test_app/views/elements/email/html/default.ctp +++ b/cake/tests/test_app/views/elements/email/html/default.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.elements.email.html + * @package cake.libs.view.templates.elements.email.html * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/views/elements/email/html/nested_element.ctp b/cake/tests/test_app/views/elements/email/html/nested_element.ctp new file mode 100644 index 000000000..49858200e --- /dev/null +++ b/cake/tests/test_app/views/elements/email/html/nested_element.ctp @@ -0,0 +1,3 @@ +Before the element. +element('html_call'); ?> +After the element. \ No newline at end of file diff --git a/cake/tests/test_app/views/elements/email/text/custom.ctp b/cake/tests/test_app/views/elements/email/text/custom.ctp index 623dba240..601023b74 100644 --- a/cake/tests/test_app/views/elements/email/text/custom.ctp +++ b/cake/tests/test_app/views/elements/email/text/custom.ctp @@ -13,8 +13,7 @@ * * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.elements.email.text + * @package cake.libs.view.templates.elements.email.text * @since CakePHP(tm) v 0.10.0.1076 * @version $Revision$ * @modifiedby $LastChangedBy$ diff --git a/cake/tests/test_app/views/elements/email/text/default.ctp b/cake/tests/test_app/views/elements/email/text/default.ctp index 9d384e3f8..7655f1430 100644 --- a/cake/tests/test_app/views/elements/email/text/default.ctp +++ b/cake/tests/test_app/views/elements/email/text/default.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.elements.email.text + * @package cake.libs.view.templates.elements.email.text * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/views/elements/email/text/wide.ctp b/cake/tests/test_app/views/elements/email/text/wide.ctp index 67b03b057..1e476fbee 100644 --- a/cake/tests/test_app/views/elements/email/text/wide.ctp +++ b/cake/tests/test_app/views/elements/email/text/wide.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.elements.email.text + * @package cake.libs.view.templates.elements.email.text * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/views/elements/html_call.ctp b/cake/tests/test_app/views/elements/html_call.ctp new file mode 100644 index 000000000..8c2c08978 --- /dev/null +++ b/cake/tests/test_app/views/elements/html_call.ctp @@ -0,0 +1,3 @@ +Html->link('Test', 'http://example.com'); +?> \ No newline at end of file diff --git a/cake/tests/test_app/views/elements/type_check.ctp b/cake/tests/test_app/views/elements/type_check.ctp new file mode 100644 index 000000000..a863c2b48 --- /dev/null +++ b/cake/tests/test_app/views/elements/type_check.ctp @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/cake/tests/test_app/views/helpers/banana.php b/cake/tests/test_app/views/helpers/banana.php index 0489d80f2..f57db5219 100644 --- a/cake/tests/test_app/views/helpers/banana.php +++ b/cake/tests/test_app/views/helpers/banana.php @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.layouts + * @package cake.libs.view.templates.layouts * @since CakePHP(tm) v 1.3 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/views/layouts/ajax.ctp b/cake/tests/test_app/views/layouts/ajax.ctp index dadf156ed..93371552b 100644 --- a/cake/tests/test_app/views/layouts/ajax.ctp +++ b/cake/tests/test_app/views/layouts/ajax.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.layouts + * @package cake.libs.view.templates.layouts * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/views/layouts/ajax2.ctp b/cake/tests/test_app/views/layouts/ajax2.ctp index 0fa4fbacb..673abbaab 100644 --- a/cake/tests/test_app/views/layouts/ajax2.ctp +++ b/cake/tests/test_app/views/layouts/ajax2.ctp @@ -13,8 +13,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.layouts + * @package cake.libs.view.templates.layouts * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/views/layouts/cache_layout.ctp b/cake/tests/test_app/views/layouts/cache_layout.ctp index 1fd6ff624..d76c26936 100644 --- a/cake/tests/test_app/views/layouts/cache_layout.ctp +++ b/cake/tests/test_app/views/layouts/cache_layout.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.layouts + * @package cake.libs.view.templates.layouts * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/views/layouts/default.ctp b/cake/tests/test_app/views/layouts/default.ctp index f75592f05..21dacb2d9 100644 --- a/cake/tests/test_app/views/layouts/default.ctp +++ b/cake/tests/test_app/views/layouts/default.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.pages + * @package cake.libs.view.templates.pages * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/views/layouts/email/html/default.ctp b/cake/tests/test_app/views/layouts/email/html/default.ctp index 8b5a339f8..cc4364bb1 100644 --- a/cake/tests/test_app/views/layouts/email/html/default.ctp +++ b/cake/tests/test_app/views/layouts/email/html/default.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.layouts.email.html + * @package cake.libs.view.templates.layouts.email.html * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/views/layouts/email/html/thin.ctp b/cake/tests/test_app/views/layouts/email/html/thin.ctp index 21ef3747f..87ece8384 100644 --- a/cake/tests/test_app/views/layouts/email/html/thin.ctp +++ b/cake/tests/test_app/views/layouts/email/html/thin.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.layouts.email.html + * @package cake.libs.view.templates.layouts.email.html * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/views/layouts/email/text/default.ctp b/cake/tests/test_app/views/layouts/email/text/default.ctp index eb9a46daa..ad1aee411 100644 --- a/cake/tests/test_app/views/layouts/email/text/default.ctp +++ b/cake/tests/test_app/views/layouts/email/text/default.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.layouts.email.text + * @package cake.libs.view.templates.layouts.email.text * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/views/layouts/flash.ctp b/cake/tests/test_app/views/layouts/flash.ctp index 1b7745cf2..bed0624c4 100644 --- a/cake/tests/test_app/views/layouts/flash.ctp +++ b/cake/tests/test_app/views/layouts/flash.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.layouts + * @package cake.libs.view.templates.layouts * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/views/layouts/json/default.ctp b/cake/tests/test_app/views/layouts/json/default.ctp new file mode 100644 index 000000000..3f290130e --- /dev/null +++ b/cake/tests/test_app/views/layouts/json/default.ctp @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/cake/tests/test_app/views/layouts/multi_cache.ctp b/cake/tests/test_app/views/layouts/multi_cache.ctp index d3bb46503..d14ce36de 100644 --- a/cake/tests/test_app/views/layouts/multi_cache.ctp +++ b/cake/tests/test_app/views/layouts/multi_cache.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.layouts + * @package cake.libs.view.templates.layouts * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/views/posts/scaffold.edit.ctp b/cake/tests/test_app/views/posts/scaffold.form.ctp similarity index 100% rename from cake/tests/test_app/views/posts/scaffold.edit.ctp rename to cake/tests/test_app/views/posts/scaffold.form.ctp diff --git a/cake/tests/test_app/views/posts/sequencial_nocache.ctp b/cake/tests/test_app/views/posts/sequencial_nocache.ctp index 7fa93fa5c..c6aa3eb09 100644 --- a/cake/tests/test_app/views/posts/sequencial_nocache.ctp +++ b/cake/tests/test_app/views/posts/sequencial_nocache.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.pages + * @package cake.libs.view.templates.pages * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/views/posts/test_nocache_tags.ctp b/cake/tests/test_app/views/posts/test_nocache_tags.ctp index b3ee6f828..745ef4ad9 100644 --- a/cake/tests/test_app/views/posts/test_nocache_tags.ctp +++ b/cake/tests/test_app/views/posts/test_nocache_tags.ctp @@ -11,8 +11,7 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake - * @subpackage cake.cake.libs.view.templates.pages + * @package cake.libs.view.templates.pages * @since CakePHP(tm) v 0.10.0.1076 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ diff --git a/cake/tests/test_app/views/tests_apps/json/index.ctp b/cake/tests/test_app/views/tests_apps/json/index.ctp new file mode 100644 index 000000000..49236e795 --- /dev/null +++ b/cake/tests/test_app/views/tests_apps/json/index.ctp @@ -0,0 +1 @@ +{"cakephp":"cool"} \ No newline at end of file diff --git a/index.php b/index.php index cb0352b8a..265576a3c 100644 --- a/index.php +++ b/index.php @@ -17,7 +17,6 @@ * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project - * @package cake * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */