Merge remote branch 'origin/2.0' into 2.0-plugin-loader

This commit is contained in:
Jose Lorenzo Rodriguez 2011-04-23 23:25:31 -04:30
commit 64db00706e
111 changed files with 3766 additions and 1829 deletions

View file

@ -41,7 +41,7 @@
*
* Options:
*
* - `handler` - callback - The callback to handle errors. You can set this to any callback type,
* - `handler` - callback - The callback to handle errors. You can set this to any callback type,
* including anonymous functions.
* - `level` - int - The level of errors you are interested in capturing.
* - `trace` - boolean - Include stack traces for errors in log files.
@ -55,14 +55,14 @@
));
/**
* Configure the Exception handler used for uncaught exceptions. By default,
* ErrorHandler::handleException() is used. It will display a HTML page for the exception, and
* while debug > 0, framework errors like Missing Controller will be displayed. When debug = 0,
* Configure the Exception handler used for uncaught exceptions. By default,
* ErrorHandler::handleException() is used. It will display a HTML page for the exception, and
* while debug > 0, framework errors like Missing Controller will be displayed. When debug = 0,
* framework errors will be coerced into generic HTTP errors.
*
* Options:
*
* - `handler` - callback - The callback to handle exceptions. You can set this to any callback type,
* - `handler` - callback - The callback to handle exceptions. You can set this to any callback type,
* including anonymous functions.
* - `renderer` - string - The class responsible for rendering uncaught exceptions. If you choose a custom class you
* should place the file for that class in app/libs. This class needs to implement a render method.
@ -138,7 +138,7 @@
/**
* Session configuration.
*
* Contains an array of settings to use for session configuration. The defaults key is
* Contains an array of settings to use for session configuration. The defaults key is
* used to define a default preset to use for sessions, any settings declared here will override
* the settings of the default config.
*
@ -147,14 +147,14 @@
* - `Session.name` - The name of the cookie to use. Defaults to 'CAKEPHP'
* - `Session.timeout` - The number of minutes you want sessions to live for. This timeout is handled by CakePHP
* - `Session.cookieTimeout` - The number of minutes you want session cookies to live for.
* - `Session.checkAgent` - Do you want the user agent to be checked when starting sessions? You might want to set the
* - `Session.checkAgent` - Do you want the user agent to be checked when starting sessions? You might want to set the
* value to false, when dealing with older versions of IE, Chrome Frame or certain web-browsing devices and AJAX
* - `Session.defaults` - The default configuration set to use as a basis for your session.
* There are four builtins: php, cake, cache, database.
* - `Session.handler` - Can be used to enable a custom session handler. Expects an array of of callables,
* that can be used with `session_save_handler`. Using this option will automatically add `session.save_handler`
* to the ini array.
* - `Session.autoRegenerate` - Enabling this setting, turns on automatic renewal of sessions, and
* - `Session.autoRegenerate` - Enabling this setting, turns on automatic renewal of sessions, and
* sessionids that change frequently. See CakeSession::$requestCountdown.
* - `Session.ini` - An associative array of additional ini values to set.
*
@ -284,9 +284,13 @@
*
*/
// Pick the caching engine to use. If APC is enabled use it.
/**
* Pick the caching engine to use. If APC is enabled use it.
* If running via cli - apc is disabled by default. ensure it's avaiable and enabled in this case
*
*/
$engine = 'File';
if (extension_loaded('apc')) {
if (extension_loaded('apc') && (php_sapi_name() !== 'cli' || ini_get('apc.enable_cli'))) {
$engine = 'Apc';
}
@ -309,7 +313,7 @@ Cache::config('_cake_core_', array(
));
/**
* Configure the cache for model, and datasource caches. This cache configuration
* Configure the cache for model, and datasource caches. This cache configuration
* is used to store schema descriptions, and table listings in connections.
*/
Cache::config('_cake_model_', array(
@ -319,4 +323,3 @@ Cache::config('_cake_model_', array(
'serialize' => ($engine === 'File'),
'duration' => $duration
));

View file

@ -0,0 +1,88 @@
<?php
/**
* This is email configuration file.
*
* Use it to configure email transports of Cake.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package app.config
* @since CakePHP(tm) v 2.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* In this file you set up your send email details.
*
* @package cake.config
*/
/**
* Email configuration class.
* You can specify multiple configurations for production, development and testing.
*
* transport => The name of a supported transport; valid options are as follows:
* mail - Send using PHP mail function
* smtp - Send using SMTP
*
* You can add custom transports (or override existing transports) by adding the
* appropriate file to app/Network/Email. Transports should be named 'YourTransport.php',
* where 'Your' is the name of the transport.
*
* from =>
* The origin email. See CakeEmail::from() about the valid values
*
*/
class EmailConfig {
public $default = array(
'transport' => 'mail',
'from' => 'you@localhost'
);
public $smtp = array(
'transport' => 'smtp',
'from' => array('My Site', 'site@localhost'),
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null
);
public $fast = array(
'from' => 'you@localhost',
'sender' => null,
'to' => null,
'cc' => null,
'bcc' => null,
'replyTo' => null,
'readReceipt' => null,
'returnPath' => null,
'messageId' => true,
'subject' => null,
'message' => null,
'headers' => null,
'viewRender' => null,
'template' => false,
'layout' => false,
'viewVars' => null,
'attachments' => null,
'emailFormat' => null,
'transport' => 'smtp',
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null
);
}

View file

@ -1,93 +0,0 @@
<?php
/**
* CSS helping functions
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package app.webroot
* @since CakePHP(tm) v 0.2.9
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
header('HTTP/1.1 404 Not Found');
exit('File Not Found');
}
/**
* Ensure required classes are available.
*/
App::import('Core', 'File');
/**
* Make clean CSS
*
* @param unknown_type $path
* @param unknown_type $name
* @return unknown
*/
function make_clean_css($path, $name) {
App::import('Vendor', 'csspp' . DS . 'csspp');
$data = file_get_contents($path);
$csspp = new csspp();
$output = $csspp->compress($data);
$ratio = 100 - (round(strlen($output) / strlen($data), 3) * 100);
$output = " /* file: $name, ratio: $ratio% */ " . $output;
return $output;
}
/**
* Write CSS cache
*
* @param unknown_type $path
* @param unknown_type $content
* @return unknown
*/
function write_css_cache($path, $content) {
if (!is_dir(dirname($path))) {
mkdir(dirname($path));
}
$cache = new File($path);
return $cache->write($content);
}
if (preg_match('|\.\.|', $url) || !preg_match('|^ccss/(.+)$|i', $url, $regs)) {
die('Wrong file name.');
}
$filename = 'css/' . $regs[1];
$filepath = CSS . $regs[1];
$cachepath = CACHE . 'css' . DS . str_replace(array('/','\\'), '-', $regs[1]);
if (!file_exists($filepath)) {
die('Wrong file name.');
}
if (file_exists($cachepath)) {
$templateModified = filemtime($filepath);
$cacheModified = filemtime($cachepath);
if ($templateModified > $cacheModified) {
$output = make_clean_css($filepath, $filename);
write_css_cache($cachepath, $output);
} else {
$output = file_get_contents($cachepath);
}
} else {
$output = make_clean_css($filepath, $filename);
write_css_cache($cachepath, $output);
$templateModified = time();
}
header("Date: " . date("D, j M Y G:i:s ", $templateModified) . 'GMT');
header("Content-Type: text/css");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + DAY) . " GMT");
header("Cache-Control: max-age=86400, must-revalidate"); // HTTP/1.1
header("Pragma: cache"); // HTTP/1.0
print $output;

View file

@ -34,7 +34,7 @@
* Full path to the directory containing "cake". Do not add trailing directory separator
*/
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('CAKE_CORE_INCLUDE_PATH', ROOT);
define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');
}
/**

View file

@ -96,7 +96,7 @@ class Cache {
* - `duration` Specify how long items in this cache configuration last.
* - `prefix` Prefix appended to all entries. Good for when you need to share a keyspace
* with either another cache config or annother application.
* - `probability` Probability of hitting a cache gc cleanup. Setting to 0 will disable
* - `probability` Probability of hitting a cache gc cleanup. Setting to 0 will disable
* cache::gc from ever being called automatically.
* - `servers' Used by memcache. Give the address of the memcached servers to use.
* - `compress` Used by memcache. Enables memcache's compressed format.
@ -298,7 +298,12 @@ class Cache {
self::set(null, $config);
if ($success === false && $value !== '') {
trigger_error(
__d('cake_dev', "%s cache was unable to write '%s' to cache", $config, $key),
__d('cake_dev',
"%s cache was unable to write '%s' to %s cache",
$config,
$key,
self::$_engines[$config]->settings['engine']
),
E_USER_WARNING
);
}
@ -371,7 +376,7 @@ class Cache {
* Decrement a number under the key and return decremented value.
*
* @param string $key Identifier for the data
* @param integer $offset How much to substract
* @param integer $offset How much to subtract
* @param string $config Optional string configuration name. Defaults to 'default'
* @return mixed new value, or false if the data doesn't exist, is not integer,
* or if there was an error fetching it
@ -409,7 +414,7 @@ class Cache {
*
* @param string $key Identifier for the data
* @param string $config name of the configuration to use. Defaults to 'default'
* @return boolean True if the value was succesfully deleted, false if it didn't exist or couldn't be removed
* @return boolean True if the value was successfully deleted, false if it didn't exist or couldn't be removed
*/
public static function delete($key, $config = 'default') {
$settings = self::settings($config);
@ -435,7 +440,7 @@ class Cache {
*
* @param boolean $check if true will check expiration, otherwise delete all
* @param string $config name of the configuration to use. Defaults to 'default'
* @return boolean True if the cache was succesfully cleared, false otherwise
* @return boolean True if the cache was successfully cleared, false otherwise
*/
public static function clear($check = false, $config = 'default') {
if (!self::isInitialized($config)) {
@ -449,21 +454,20 @@ class Cache {
/**
* Check if Cache has initialized a working config for the given name.
*
* @param string $engine Name of the engine, Defaults to default
* @param string $config Name of the configuration setting
* @param string $config name of the configuration to use. Defaults to 'default'
* @return bool Whether or not the config name has been initialized.
*/
public static function isInitialized($name = 'default') {
public static function isInitialized($config = 'default') {
if (Configure::read('Cache.disable')) {
return false;
}
return isset(self::$_engines[$name]);
return isset(self::$_engines[$config]);
}
/**
* Return the settings for the named cache engine.
*
* @param string $engine Name of the configuration to get settings for. Defaults to 'default'
* @param string $name Name of the configuration to get settings for. Defaults to 'default'
* @return array list of settings for this engine
* @see Cache::config()
* @access public
@ -497,8 +501,8 @@ abstract class CacheEngine {
*
* Called automatically by the cache frontend
*
* @param array $params Associative array of parameters for the engine
* @return boolean True if the engine has been succesfully initialized, false if not
* @param array $settings Associative array of parameters for the engine
* @return boolean True if the engine has been successfully initialized, false if not
*/
public function init($settings = array()) {
$this->settings = array_merge(
@ -526,7 +530,7 @@ abstract class CacheEngine {
* @param string $key Identifier for the data
* @param mixed $value Data to be cached
* @param mixed $duration How long to cache for.
* @return boolean True if the data was succesfully cached, false on failure
* @return boolean True if the data was successfully cached, false on failure
*/
abstract public function write($key, $value, $duration);
@ -551,7 +555,7 @@ abstract class CacheEngine {
* Decrement a number under the key and return decremented value
*
* @param string $key Identifier for the data
* @param integer $value How much to substract
* @param integer $offset How much to subtract
* @return New incremented value, false otherwise
*/
abstract public function decrement($key, $offset = 1);
@ -560,7 +564,7 @@ abstract class CacheEngine {
* Delete a key from the cache
*
* @param string $key Identifier for the data
* @return boolean True if the value was succesfully deleted, false if it didn't exist or couldn't be removed
* @return boolean True if the value was successfully deleted, false if it didn't exist or couldn't be removed
*/
abstract public function delete($key);
@ -568,7 +572,7 @@ abstract class CacheEngine {
* Delete all keys from the cache
*
* @param boolean $check if true will check expiration, otherwise delete all
* @return boolean True if the cache was succesfully cleared, false otherwise
* @return boolean True if the cache was successfully cleared, false otherwise
*/
abstract public function clear($check);

View file

@ -31,7 +31,7 @@ class ApcEngine extends CacheEngine {
* Called automatically by the cache frontend
* To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
*
* @param array $setting array of setting for the engine
* @param array $settings array of setting for the engine
* @return boolean True if the engine has been successfully initialized, false if not
* @see CacheEngine::__defaults
*/
@ -46,7 +46,7 @@ class ApcEngine extends CacheEngine {
* @param string $key Identifier for the data
* @param mixed $value Data to be cached
* @param integer $duration How long to cache the data, in seconds
* @return boolean True if the data was succesfully cached, false on failure
* @return boolean True if the data was successfully cached, false on failure
*/
public function write($key, $value, $duration) {
$expires = time() + $duration;
@ -74,7 +74,6 @@ class ApcEngine extends CacheEngine {
*
* @param string $key Identifier for the data
* @param integer $offset How much to increment
* @param integer $duration How long to cache the data, in seconds
* @return New incremented value, false otherwise
*/
public function increment($key, $offset = 1) {
@ -85,8 +84,7 @@ class ApcEngine extends CacheEngine {
* Decrements the value of an integer cached key
*
* @param string $key Identifier for the data
* @param integer $offset How much to substract
* @param integer $duration How long to cache the data, in seconds
* @param integer $offset How much to subtract
* @return New decremented value, false otherwise
*/
public function decrement($key, $offset = 1) {
@ -97,7 +95,7 @@ class ApcEngine extends CacheEngine {
* Delete a key from the cache
*
* @param string $key Identifier for the data
* @return boolean True if the value was succesfully deleted, false if it didn't exist or couldn't be removed
* @return boolean True if the value was successfully deleted, false if it didn't exist or couldn't be removed
*/
public function delete($key) {
return apc_delete($key);
@ -106,7 +104,7 @@ class ApcEngine extends CacheEngine {
/**
* Delete all keys from the cache. This will clear every cache config using APC.
*
* @return boolean True if the cache was succesfully cleared, false otherwise
* @return boolean True if the cache was successfully cleared, false otherwise
*/
public function clear($check) {
return apc_clear_cache('user');

View file

@ -63,7 +63,7 @@ class FileEngine extends CacheEngine {
* Called automatically by the cache frontend
* To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
*
* @param array $setting array of setting for the engine
* @param array $settings array of setting for the engine
* @return boolean True if the engine has been successfully initialized, false if not
*/
public function init($settings = array()) {
@ -99,7 +99,7 @@ class FileEngine extends CacheEngine {
* @param string $key Identifier for the data
* @param mixed $data Data to be cached
* @param mixed $duration How long to cache the data, in seconds
* @return boolean True if the data was succesfully cached, false on failure
* @return boolean True if the data was successfully cached, false on failure
*/
public function write($key, $data, $duration) {
if ($data === '' || !$this->_init) {
@ -204,7 +204,7 @@ class FileEngine extends CacheEngine {
* Delete all values from the cache
*
* @param boolean $check Optional - only delete expired cache items
* @return boolean True if the cache was succesfully cleared, false otherwise
* @return boolean True if the cache was successfully cleared, false otherwise
*/
public function clear($check) {
if (!$this->_init) {

View file

@ -53,7 +53,7 @@ class MemcacheEngine extends CacheEngine {
* Called automatically by the cache frontend
* To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
*
* @param array $setting array of setting for the engine
* @param array $settings array of setting for the engine
* @return boolean True if the engine has been successfully initialized, false if not
*/
public function init($settings = array()) {
@ -121,7 +121,7 @@ class MemcacheEngine extends CacheEngine {
* @param string $key Identifier for the data
* @param mixed $value Data to be cached
* @param integer $duration How long to cache the data, in seconds
* @return boolean True if the data was succesfully cached, false on failure
* @return boolean True if the data was successfully cached, false on failure
* @see http://php.net/manual/en/memcache.set.php
*/
public function write($key, $value, $duration) {
@ -146,7 +146,6 @@ class MemcacheEngine extends CacheEngine {
*
* @param string $key Identifier for the data
* @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 CacheException when you try to increment with compress = true
*/
@ -163,8 +162,7 @@ class MemcacheEngine extends CacheEngine {
* Decrements the value of an integer cached key
*
* @param string $key Identifier for the data
* @param integer $offset How much to substract
* @param integer $duration How long to cache the data, in seconds
* @param integer $offset How much to subtract
* @return New decremented value, false otherwise
* @throws CacheException when you try to decrement with compress = true
*/
@ -181,7 +179,7 @@ class MemcacheEngine extends CacheEngine {
* Delete a key from the cache
*
* @param string $key Identifier for the data
* @return boolean True if the value was succesfully deleted, false if it didn't exist or couldn't be removed
* @return boolean True if the value was successfully deleted, false if it didn't exist or couldn't be removed
*/
public function delete($key) {
return $this->_Memcache->delete($key);
@ -190,7 +188,7 @@ class MemcacheEngine extends CacheEngine {
/**
* Delete all keys from the cache
*
* @return boolean True if the cache was succesfully cleared, false otherwise
* @return boolean True if the cache was successfully cleared, false otherwise
*/
public function clear($check) {
return $this->_Memcache->flush();

View file

@ -42,7 +42,7 @@ class XcacheEngine extends CacheEngine {
* Called automatically by the cache frontend
* To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
*
* @param array $setting array of setting for the engine
* @param array $settings array of setting for the engine
* @return boolean True if the engine has been successfully initialized, false if not
*/
public function init($settings) {
@ -62,7 +62,7 @@ class XcacheEngine extends CacheEngine {
* @param string $key Identifier for the data
* @param mixed $value Data to be cached
* @param integer $duration How long to cache the data, in seconds
* @return boolean True if the data was succesfully cached, false on failure
* @return boolean True if the data was successfully cached, false on failure
*/
public function write($key, $value, $duration) {
$expires = time() + $duration;
@ -94,7 +94,6 @@ class XcacheEngine extends CacheEngine {
*
* @param string $key Identifier for the data
* @param integer $offset How much to increment
* @param integer $duration How long to cache the data, in seconds
* @return New incremented value, false otherwise
*/
public function increment($key, $offset = 1) {
@ -106,8 +105,7 @@ class XcacheEngine extends CacheEngine {
* If the cache key is not an integer it will be treated as 0
*
* @param string $key Identifier for the data
* @param integer $offset How much to substract
* @param integer $duration How long to cache the data, in seconds
* @param integer $offset How much to subtract
* @return New decremented value, false otherwise
*/
public function decrement($key, $offset = 1) {
@ -117,7 +115,7 @@ class XcacheEngine extends CacheEngine {
* Delete a key from the cache
*
* @param string $key Identifier for the data
* @return boolean True if the value was succesfully deleted, false if it didn't exist or couldn't be removed
* @return boolean True if the value was successfully deleted, false if it didn't exist or couldn't be removed
*/
public function delete($key) {
return xcache_unset($key);
@ -126,7 +124,7 @@ class XcacheEngine extends CacheEngine {
/**
* Delete all keys from the cache
*
* @return boolean True if the cache was succesfully cleared, false otherwise
* @return boolean True if the cache was successfully cleared, false otherwise
*/
public function clear($check) {
$this->__auth();
@ -145,7 +143,7 @@ class XcacheEngine extends CacheEngine {
* This has to be done because xcache_clear_cache() needs to pass Basic Http Auth
* (see xcache.admin configuration settings)
*
* @param boolean Revert changes
* @param boolean $reverse Revert changes
* @access private
*/
function __auth($reverse = false) {

View file

@ -20,6 +20,7 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('File', 'Utility');
App::uses('Folder', 'Utility');
App::uses('CakeSchema', 'Model');
/**
@ -60,7 +61,7 @@ class SchemaShell extends Shell {
*
*/
public function startup() {
$name = $file = $path = $connection = $plugin = null;
$name = $path = $connection = $plugin = null;
if (!empty($this->params['name'])) {
$name = $this->params['name'];
} elseif (!empty($this->args[0])) {
@ -150,7 +151,7 @@ class SchemaShell extends Shell {
$content = $this->Schema->read($options);
$content['file'] = $this->params['file'];
Configure::write('Cache.disable', $cacheDisable);
if ($snapshot === true) {
@ -271,7 +272,7 @@ class SchemaShell extends Shell {
if (!empty($this->params['plugin'])) {
$plugin = $this->params['plugin'];
}
if (!empty($this->params['dry'])) {
$this->__dry = true;
$this->out(__d('cake_console', 'Performing a dry run.'));
@ -463,7 +464,7 @@ class SchemaShell extends Shell {
$write = array(
'help' => __d('cake_console', 'Write the dumped SQL to a file.')
);
$parser = parent::getOptionParser();
$parser->description(
'The Schema Shell generates a schema object from' .

View file

@ -17,6 +17,8 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('File', 'Utility');
App::uses('Folder', 'Utility');
/**
* Language string extractor
*
@ -112,7 +114,7 @@ class ExtractTask extends Shell {
$this->__paths = explode(',', $this->params['paths']);
} else {
$defaultPath = APP_PATH;
$message = __d('cake_console', "What is the full path you would like to extract?\nExample: %s\n[Q]uit [D]one", $defaultPath);
$message = __d('cake_console', "What is the path you would like to extract?\n[Q]uit [D]one");
while (true) {
$response = $this->in($message, null, $defaultPath);
if (strtoupper($response) === 'Q') {
@ -134,7 +136,7 @@ class ExtractTask extends Shell {
if (isset($this->params['output'])) {
$this->__output = $this->params['output'];
} else {
$message = __d('cake_console', "What is the full path you would like to output?\nExample: %s\n[Q]uit", $this->__paths[0] . DS . 'locale');
$message = __d('cake_console', "What is the path you would like to output?\n[Q]uit", $this->__paths[0] . DS . 'locale');
while (true) {
$response = $this->in($message, null, $this->__paths[0] . DS . 'locale');
if (strtoupper($response) === 'Q') {
@ -199,13 +201,13 @@ class ExtractTask extends Shell {
$parser = parent::getOptionParser();
return $parser->description(__d('cake_console', 'CakePHP Language String Extraction:'))
->addOption('app', array('help' => __d('cake_console', 'Directory where your application is located.')))
->addOption('paths', array('help' => __d('cake_console', 'Comma separted list of paths, full paths are needed.')))
->addOption('paths', array('help' => __d('cake_console', 'Comma separted list of paths.')))
->addOption('merge', array(
'help' => __d('cake_console', 'Merge all domain strings into the default.po file.'),
'choices' => array('yes', 'no')
))
->addOption('output', array('help' => __d('cake_console', 'Full path to output directory.')))
->addOption('files', array('help' => __d('cake_console', 'Comma separated list of files, full paths are needed.')))
->addOption('files', array('help' => __d('cake_console', 'Comma separated list of files.')))
->addOption('exclude', array(
'help' => __d('cake_console', 'Comma separated list of directories to exclude. Any path containing a path segment with the provided values will be skipped. E.g. test,vendors')
));
@ -229,10 +231,10 @@ class ExtractTask extends Shell {
$this->out(__d('cake_console', ' -app [path...]: directory where your application is located'));
$this->out(__d('cake_console', ' -root [path...]: path to install'));
$this->out(__d('cake_console', ' -core [path...]: path to cake directory'));
$this->out(__d('cake_console', ' -paths [comma separated list of paths, full path is needed]'));
$this->out(__d('cake_console', ' -paths [comma separated list of paths]'));
$this->out(__d('cake_console', ' -merge [yes|no]: Merge all domains strings into the default.pot file'));
$this->out(__d('cake_console', ' -output [path...]: Full path to output directory'));
$this->out(__d('cake_console', ' -files: [comma separated list of files, full path to file is needed]'));
$this->out(__d('cake_console', ' -files: [comma separated list of files]'));
$this->out();
$this->out(__d('cake_console', 'Commands:'));
$this->out(__d('cake_console', ' cake i18n extract help: Shows this help message.'));
@ -415,7 +417,7 @@ class ExtractTask extends Shell {
if (strtoupper($response) === 'N') {
$response = '';
while ($response == '') {
$response = $this->in(__d('cake_console', "What would you like to name this file?\nExample: %s", 'new_' . $filename), null, 'new_' . $filename);
$response = $this->in(__d('cake_console', "What would you like to name this file?"), null, 'new_' . $filename);
$File = new File($this->__output . $response);
$filename = $response;
}
@ -515,7 +517,7 @@ class ExtractTask extends Shell {
function __searchFiles() {
$pattern = false;
if (!empty($this->_exclude)) {
$pattern = '/[\/\\\\]' . implode('|', $this->_exclude) . '[\/\\\\]/';
$pattern = '/[\/\\\\]' . implode('|', $this->_exclude) . '[\/\\\\]/';
}
foreach ($this->__paths as $path) {
$Folder = new Folder($path);

View file

@ -140,7 +140,6 @@ class FixtureTask extends BakeTask {
$this->out(sprintf("Bake Fixture\nPath: %s", $this->path));
$this->hr();
$useDbConfig = $this->connection;
if (!isset($this->connection)) {
$this->connection = $this->DbConfig->getConfig();
}

View file

@ -462,7 +462,6 @@ class ModelTask extends BakeTask {
$associations = array(
'belongsTo' => array(), 'hasMany' => array(), 'hasOne'=> array(), 'hasAndBelongsToMany' => array()
);
$possibleKeys = array();
$associations = $this->findBelongsTo($model, $associations);
$associations = $this->findHasOneAndMany($model, $associations);
@ -608,8 +607,6 @@ class ModelTask extends BakeTask {
public function confirmAssociations($model, $associations) {
foreach ($associations as $type => $settings) {
if (!empty($associations[$type])) {
$count = count($associations[$type]);
$response = 'y';
foreach ($associations[$type] as $i => $assoc) {
$prompt = "{$model->name} {$type} {$assoc['alias']}?";
$response = $this->in($prompt, array('y','n'), 'y');
@ -647,7 +644,6 @@ class ModelTask extends BakeTask {
$alias = $this->in(__d('cake_console', 'What is the alias for this association?'));
$className = $this->in(__d('cake_console', 'What className will %s use?', $alias), null, $alias );
$suggestedForeignKey = null;
if ($assocType == 0) {
$showKeys = $possibleKeys[$model->table];

View file

@ -50,8 +50,6 @@ class PluginTask extends Shell {
* @return void
*/
public function execute() {
$plugin = null;
if (isset($this->args[0])) {
$plugin = Inflector::camelize($this->args[0]);
$pluginPath = $this->_pluginPath($plugin);
@ -107,19 +105,16 @@ class PluginTask extends Shell {
$Folder = new Folder($this->path . $pluginPath);
$directories = array(
'config' . DS . 'schema',
'models' . DS . 'behaviors',
'models' . DS . 'datasources',
'console' . DS . 'shells' . DS . 'tasks',
'controllers' . DS . 'components',
'libs',
'views' . DS . 'helpers',
'tests' . DS . 'cases' . DS . 'components',
'tests' . DS . 'cases' . DS . 'helpers',
'tests' . DS . 'cases' . DS . 'behaviors',
'tests' . DS . 'cases' . DS . 'controllers',
'tests' . DS . 'cases' . DS . 'models',
'tests' . DS . 'groups',
'tests' . DS . 'fixtures',
'Model' . DS . 'Behavior',
'Model' . DS . 'Datasource',
'Console' . DS . 'Command' . DS . 'Task',
'Controller' . DS . 'Component',
'Lib',
'View' . DS . 'Helper',
'tests' . DS . 'Case' . DS . 'Controller' . DS . 'Component',
'tests' . DS . 'Case' . DS . 'View' . DS . 'Helper',
'tests' . DS . 'Case' . DS . 'Model' . DS . 'Behavior',
'tests' . DS . 'Fixture',
'vendors',
'webroot'
);
@ -139,21 +134,21 @@ class PluginTask extends Shell {
return false;
}
$controllerFileName = $pluginPath . '_app_controller.php';
$controllerFileName = $plugin . 'AppController.php';
$out = "<?php\n\n";
$out .= "class {$plugin}AppController extends AppController {\n\n";
$out .= "}\n\n";
$out .= "?>";
$this->createFile($this->path . $pluginPath. DS . $controllerFileName, $out);
$this->createFile($this->path . $pluginPath. DS . 'Controller' . DS . $controllerFileName, $out);
$modelFileName = $pluginPath . '_app_model.php';
$modelFileName = $plugin . 'AppModel.php';
$out = "<?php\n\n";
$out .= "class {$plugin}AppModel extends AppModel {\n\n";
$out .= "}\n\n";
$out .= "?>";
$this->createFile($this->path . $pluginPath . DS . $modelFileName, $out);
$this->createFile($this->path . $pluginPath . DS . 'Model' . DS . $modelFileName, $out);
$this->hr();
$this->out(__d('cake_console', '<success>Created:</success> %s in %s', $plugin, $this->path . $pluginPath), 2);

View file

@ -19,6 +19,7 @@
*/
App::uses('File', 'Utility');
App::uses('Folder', 'Utility');
App::uses('String', 'Utility');
App::uses('Security', 'Utility');
@ -53,9 +54,8 @@ class ProjectTask extends Shell {
}
while (!$project) {
$prompt = __d('cake_console', "What is the full path for this app including the app directory name?\n Example:");
$default = APP_PATH . 'myapp';
$project = $this->in($prompt . $default, null, $default);
$prompt = __d('cake_console', "What is the path to the project you want to bake?");
$project = $this->in($prompt, null, APP_PATH . 'myapp');
}
if ($project) {
@ -201,7 +201,7 @@ class ProjectTask extends Shell {
*/
public function createHome($dir) {
$app = basename($dir);
$path = $dir . 'views' . DS . 'pages' . DS;
$path = $dir . 'View' . DS . 'pages' . DS;
$source = LIBS . 'Console' . DS . 'templates' . DS .'default' . DS . 'views' . DS . 'home.ctp';
include($source);
return $this->createFile($path.'home.ctp', $output);
@ -392,4 +392,4 @@ class ProjectTask extends Shell {
));
}
}
}

View file

@ -106,7 +106,6 @@ class TemplateTask extends Shell {
* @return void
*/
public function set($one, $two = null) {
$data = null;
if (is_array($one)) {
if (is_array($two)) {
$data = array_combine($one, $two);

View file

@ -220,7 +220,7 @@ class TestTask extends BakeTask {
/**
* Checks whether the chosen type can find its own fixtures.
* Currently only model, and controller are supported
*
*
* @param string $type The Type of object you are generating tests for eg. controller
* @param string $className the Classname of the class the test is being generated for.
* @return boolean

View file

@ -106,7 +106,7 @@ class ViewTask extends BakeTask {
if (!isset($this->connection)) {
$this->connection = 'default';
}
$controller = $action = $alias = null;
$action = null;
$this->controllerName = $this->_controllerName($this->args[0]);
$this->controllerPath = $this->_controllerPath($this->controllerName);

View file

@ -163,7 +163,10 @@ class TestsuiteShell extends Shell {
*/
public function initialize() {
$this->_dispatcher = new CakeTestSuiteDispatcher();
$this->_dispatcher->loadTestFramework();
$sucess = $this->_dispatcher->loadTestFramework();
if (!$sucess) {
throw new Exception(__d('cake_dev', 'Please install PHPUnit framework <info>(http://www.phpunit.de)</info>'));
}
}
/**
@ -289,9 +292,7 @@ class TestsuiteShell extends Shell {
$i = 1;
$cases = array();
foreach ($testCases as $testCaseFile => $testCase) {
$case = explode(DS, str_replace('Test.php', '', $testCase));
$case[count($case) - 1] = $case[count($case) - 1];
$case = implode('/', $case);
$case = str_replace('Test.php', '', $testCase);
$this->out("[$i] $case");
$cases[$i] = $case;
$i++;

View file

@ -165,7 +165,7 @@ class Shell extends Object {
if ($this->stdin == null) {
$this->stdin = new ConsoleInput('php://stdin');
}
$parent = get_parent_class($this);
if ($this->tasks !== null && $this->tasks !== false) {
$this->_mergeVars(array('tasks'), $parent, true);
@ -200,7 +200,6 @@ class Shell extends Object {
*
*/
protected function _welcome() {
$this->clear();
$this->out();
$this->out('<info>Welcome to CakePHP v' . Configure::version() . ' Console</info>');
$this->hr();
@ -296,16 +295,16 @@ class Shell extends Object {
* but intended for running shells from other shells.
*
* ### Usage:
*
*
* With a string commmand:
*
* `return $this->dispatchShell('schema create DbAcl');`
*
* With an array command:
*
* `return $this->dispatchShell('schema', 'create', 'i18n', '--dry');`
* `return $this->dispatchShell('schema', 'create', 'i18n', '--dry');`
*
* @param mixed $command Either an array of args similar to $argv. Or a string command, that can be
* @param mixed $command Either an array of args similar to $argv. Or a string command, that can be
* exploded on space to simulate argv.
* @return mixed. The return of the other shell.
*/
@ -334,10 +333,14 @@ class Shell extends Object {
array_shift($argv);
}
$this->OptionParser = $this->getOptionParser();
list($this->params, $this->args) = $this->OptionParser->parse($argv, $command);
try {
$this->OptionParser = $this->getOptionParser();
list($this->params, $this->args) = $this->OptionParser->parse($argv, $command);
} catch (ConsoleException $e) {
return $this->out($this->OptionParser->help($command));
}
$this->command = $command;
if (!empty($this->params['help'])) {
return $this->_displayHelp($command);
}
@ -471,7 +474,7 @@ class Shell extends Object {
/**
* Wrap a block of text.
* Allows you to set the width, and indenting on a block of text.
* Allows you to set the width, and indenting on a block of text.
*
* ### Options
*
@ -480,7 +483,7 @@ class Shell extends Object {
* - `indent` Indent the text with the string provided. Defaults to null.
*
* @param string $text Text the text to format.
* @param mixed $options Array of options to use, or an integer to wrap the text to.
* @param mixed $options Array of options to use, or an integer to wrap the text to.
* @return string Wrapped / indented text
* @see String::wrap()
*/

View file

@ -58,7 +58,6 @@ class TaskCollection extends ObjectCollection {
if (isset($this->_loaded[$name])) {
return $this->_loaded[$name];
}
$taskFile = Inflector::underscore($name);
$taskClass = $name . 'Task';
App::uses($taskClass, $plugin . 'Console/Command/Task');
if (!class_exists($taskClass)) {

View file

@ -19,6 +19,6 @@
* @since CakePHP(tm) v 1.2.0.5012
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
require_once(__CAKE_PATH__ . 'shell_dispatcher.php');
require_once(__CAKE_PATH__ . 'ShellDispatcher.php');
return ShellDispatcher::run($argv);

View file

@ -41,7 +41,7 @@
*
* Options:
*
* - `handler` - callback - The callback to handle errors. You can set this to any callback type,
* - `handler` - callback - The callback to handle errors. You can set this to any callback type,
* including anonymous functions.
* - `level` - int - The level of errors you are interested in capturing.
* - `trace` - boolean - Include stack traces for errors in log files.
@ -55,14 +55,14 @@
));
/**
* Configure the Exception handler used for uncaught exceptions. By default,
* ErrorHandler::handleException() is used. It will display a HTML page for the exception, and
* while debug > 0, framework errors like Missing Controller will be displayed. When debug = 0,
* Configure the Exception handler used for uncaught exceptions. By default,
* ErrorHandler::handleException() is used. It will display a HTML page for the exception, and
* while debug > 0, framework errors like Missing Controller will be displayed. When debug = 0,
* framework errors will be coerced into generic HTTP errors.
*
* Options:
*
* - `handler` - callback - The callback to handle exceptions. You can set this to any callback type,
* - `handler` - callback - The callback to handle exceptions. You can set this to any callback type,
* including anonymous functions.
* - `renderer` - string - The class responsible for rendering uncaught exceptions. If you choose a custom class you
* should place the file for that class in app/libs. This class needs to implement a render method.
@ -138,7 +138,7 @@
/**
* Session configuration.
*
* Contains an array of settings to use for session configuration. The defaults key is
* Contains an array of settings to use for session configuration. The defaults key is
* used to define a default preset to use for sessions, any settings declared here will override
* the settings of the default config.
*
@ -147,14 +147,14 @@
* - `Session.name` - The name of the cookie to use. Defaults to 'CAKEPHP'
* - `Session.timeout` - The number of minutes you want sessions to live for. This timeout is handled by CakePHP
* - `Session.cookieTimeout` - The number of minutes you want session cookies to live for.
* - `Session.checkAgent` - Do you want the user agent to be checked when starting sessions? You might want to set the
* - `Session.checkAgent` - Do you want the user agent to be checked when starting sessions? You might want to set the
* value to false, when dealing with older versions of IE, Chrome Frame or certain web-browsing devices and AJAX
* - `Session.defaults` - The default configuration set to use as a basis for your session.
* There are four builtins: php, cake, cache, database.
* - `Session.handler` - Can be used to enable a custom session handler. Expects an array of of callables,
* that can be used with `session_save_handler`. Using this option will automatically add `session.save_handler`
* to the ini array.
* - `Session.autoRegenerate` - Enabling this setting, turns on automatic renewal of sessions, and
* - `Session.autoRegenerate` - Enabling this setting, turns on automatic renewal of sessions, and
* sessionids that change frequently. See CakeSession::$requestCountdown.
* - `Session.ini` - An associative array of additional ini values to set.
*
@ -284,9 +284,13 @@
*
*/
// Pick the caching engine to use. If APC is enabled use it.
/**
* Pick the caching engine to use. If APC is enabled use it.
* If running via cli - apc is disabled by default. ensure it's avaiable and enabled in this case
*
*/
$engine = 'File';
if (extension_loaded('apc')) {
if (extension_loaded('apc') && (php_sapi_name() !== 'cli' || ini_get('apc.enable_cli'))) {
$engine = 'Apc';
}
@ -309,7 +313,7 @@ Cache::config('_cake_core_', array(
));
/**
* Configure the cache for model, and datasource caches. This cache configuration
* Configure the cache for model, and datasource caches. This cache configuration
* is used to store schema descriptions, and table listings in connections.
*/
Cache::config('_cake_model_', array(

View file

@ -0,0 +1,88 @@
<?php
/**
* This is email configuration file.
*
* Use it to configure email transports of Cake.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package app.config
* @since CakePHP(tm) v 2.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* In this file you set up your send email details.
*
* @package cake.config
*/
/**
* Email configuration class.
* You can specify multiple configurations for production, development and testing.
*
* transport => The name of a supported transport; valid options are as follows:
* mail - Send using PHP mail function
* smtp - Send using SMTP
*
* You can add custom transports (or override existing transports) by adding the
* appropriate file to app/Network/Email. Transports should be named 'YourTransport.php',
* where 'Your' is the name of the transport.
*
* from =>
* The origin email. See CakeEmail::from() about the valid values
*
*/
class EmailConfig {
public $default = array(
'transport' => 'mail',
'from' => 'you@localhost'
);
public $smtp = array(
'transport' => 'smtp',
'from' => array('My Site', 'site@localhost'),
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null
);
public $fast = array(
'from' => 'you@localhost',
'sender' => null,
'to' => null,
'cc' => null,
'bcc' => null,
'replyTo' => null,
'readReceipt' => null,
'returnPath' => null,
'messageId' => true,
'subject' => null,
'message' => null,
'headers' => null,
'viewRender' => null,
'template' => false,
'layout' => false,
'viewVars' => null,
'attachments' => null,
'emailFormat' => null,
'transport' => 'smtp',
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null
);
}

View file

@ -1,96 +0,0 @@
<?php
/**
* CSS Functions
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package app.webroot
* @since CakePHP(tm) v 0.2.9
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
header('HTTP/1.1 404 Not Found');
exit('File Not Found');
}
/**
* Ensure required files are included
*/
if (!class_exists('File')) {
require LIBS . 'file.php';
}
/**
* Make clean CSS
*
* @param unknown_type $path
* @param unknown_type $name
* @return unknown
*/
function make_clean_css($path, $name) {
App::import('Vendor', 'csspp' . DS . 'csspp');
$data = file_get_contents($path);
$csspp = new csspp();
$output = $csspp->compress($data);
$ratio = 100 - (round(strlen($output) / strlen($data), 3) * 100);
$output = " /* file: $name, ratio: $ratio% */ " . $output;
return $output;
}
/**
* Write CSS cache
*
* @param unknown_type $path
* @param unknown_type $content
* @return unknown
*/
function write_css_cache($path, $content) {
if (!is_dir(dirname($path))) {
mkdir(dirname($path));
}
$cache = new File($path);
return $cache->write($content);
}
if (preg_match('|\.\.|', $url) || !preg_match('|^ccss/(.+)$|i', $url, $regs)) {
exit('Wrong file name.');
}
$filename = 'css/' . $regs[1];
$filepath = CSS . $regs[1];
$cachepath = CACHE . 'css' . DS . str_replace(array('/','\\'), '-', $regs[1]);
if (!file_exists($filepath)) {
exit('Wrong file name.');
}
if (file_exists($cachepath)) {
$templateModified = filemtime($filepath);
$cacheModified = filemtime($cachepath);
if ($templateModified > $cacheModified) {
$output = make_clean_css($filepath, $filename);
write_css_cache($cachepath, $output);
} else {
$output = file_get_contents($cachepath);
}
} else {
$output = make_clean_css($filepath, $filename);
write_css_cache($cachepath, $output);
$templateModified = time();
}
header("Date: " . date("D, j M Y G:i:s ", $templateModified) . 'GMT');
header("Content-Type: text/css");
header("Expires: " . gmdate("D, j M Y H:i:s", time() + DAY) . " GMT");
header("Cache-Control: max-age=86400, must-revalidate"); // HTTP/1.1
header("Pragma: cache"); // HTTP/1.0
print $output;

View file

@ -75,6 +75,6 @@
return;
}
require LIBS . 'Routing' . DS .'Dispatcher.php';
App::uses('Dispatcher', 'Routing');
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(new CakeRequest());

View file

@ -308,9 +308,6 @@ class DbAcl extends Object implements AclInterface {
return false;
}
$aroNode = $aroPath[0];
$acoNode = $acoPath[0];
if ($action != '*' && !in_array('_' . $action, $permKeys)) {
trigger_error(__d('cake_dev', "ACO permissions key %s does not exist in DbAcl::check()", $action), E_USER_NOTICE);
return false;

View file

@ -459,23 +459,24 @@ class CookieComponent extends Component {
* Implode method to keep keys are multidimensional arrays
*
* @param array $array Map of key and values
* @return string String in the form key1|value1,key2|value2
* @return string A json encoded string.
*/
protected function _implode($array) {
$string = '';
foreach ($array as $key => $value) {
$string .= ',' . $key . '|' . $value;
}
return substr($string, 1);
protected function _implode(array $array) {
return json_encode($array);
}
/**
* Explode method to return array from string set in CookieComponent::_implode()
* Maintains reading backwards compatibility with 1.x CookieComponent::_implode().
*
* @param string $string String in the form key1|value1,key2|value2
* @param string $string A string containing JSON encoded data, or a bare string.
* @return array Map of key and values
*/
protected function _explode($string) {
if ($string[0] === '{' || $string[0] === '[') {
$ret = json_decode($string, true);
return ($ret != null) ? $ret : $string;
}
$array = array();
foreach (explode(',', $string) as $pair) {
$key = explode('|', $pair);

View file

@ -19,6 +19,7 @@
App::uses('Component', 'Controller');
App::uses('Multibyte', 'I18n');
App::uses('CakeEmail', 'Network');
/**
* EmailComponent
@ -28,7 +29,7 @@ App::uses('Multibyte', 'I18n');
*
* @package cake.libs.controller.components
* @link http://book.cakephp.org/view/1283/Email
*
* @deprecated Use Network/CakeEmail
*/
class EmailComponent extends Component {
@ -149,14 +150,6 @@ class EmailComponent extends Component {
*/
public $template = null;
/**
* as per RFC2822 Section 2.1.1
*
* @var integer
* @access public
*/
public $lineLength = 70;
/**
* Line feed character(s) to be used when sending using mail() function
* By default PHP_EOL is used.
@ -167,12 +160,7 @@ class EmailComponent extends Component {
* @var string
* @access public
*/
var $lineFeed = PHP_EOL;
/**
* @deprecated see lineLength
*/
protected $_lineLength = null;
public $lineFeed = PHP_EOL;
/**
* What format should the email be sent in
@ -251,15 +239,6 @@ class EmailComponent extends Component {
*/
public $smtpOptions = array();
/**
* Placeholder for any errors that might happen with the
* smtp mail methods
*
* @var string
* @access public
*/
public $smtpError = null;
/**
* Contains the rendered plain text message if one was sent.
*
@ -291,36 +270,11 @@ class EmailComponent extends Component {
public $messageId = true;
/**
* Temporary store of message header lines
* Controller reference
*
* @var array
* @access protected
* @var object Controller
*/
protected $_header = array();
/**
* If set, boundary to use for multipart mime messages
*
* @var string
* @access protected
*/
protected $_boundary = null;
/**
* Temporary store of message lines
*
* @var array
* @access protected
*/
protected $_message = array();
/**
* Variable that holds SMTP connection
*
* @var resource
* @access protected
*/
protected $_smtpConnection = null;
protected $_controller = null;
/**
* Constructor
@ -329,7 +283,7 @@ class EmailComponent extends Component {
* @param array $settings Array of configuration settings.
*/
public function __construct(ComponentCollection $collection, $settings = array()) {
$this->Controller = $collection->getController();
$this->_controller = $collection->getController();
parent::__construct($collection, $settings);
}
@ -344,13 +298,6 @@ class EmailComponent extends Component {
}
}
/**
* Startup component
*
* @param object $controller Instantiating controller
*/
public function startup($controller) {}
/**
* Send an email using the specified content, template and layout
*
@ -361,59 +308,71 @@ class EmailComponent extends Component {
* @return boolean Success
*/
public function send($content = null, $template = null, $layout = null) {
$this->_createHeader();
$lib = new CakeEmail();
$lib->charset = $this->charset;
$lib->from($this->_formatAddresses((array)$this->from));
if (!empty($this->to)) {
$lib->to($this->_formatAddresses((array)$this->to));
}
if (!empty($this->cc)) {
$lib->cc($this->_formatAddresses((array)$this->cc));
}
if (!empty($this->bcc)) {
$lib->bcc($this->_formatAddresses((array)$this->bcc));
}
if (!empty($this->replyTo)) {
$lib->replyTo($this->_formatAddresses((array)$this->replyTo));
}
if (!empty($this->return)) {
$lib->returnPath($this->_formatAddresses((array)$this->return));
}
if (!empty($readReceipt)) {
$lib->readReceipt($this->_formatAddresses((array)$this->readReceipt));
}
$lib->subject($this->subject)->messageID($this->messageId);
$headers = array('X-Mailer' => $this->xMailer);
foreach ($this->headers as $key => $value) {
$headers['X-' . $key] = $value;
}
if ($this->date != false) {
$headers['Date'] = $this->date;
}
$lib->setHeaders($headers);
if ($template) {
$this->template = $template;
}
if ($layout) {
$this->layout = $layout;
}
if (is_array($content)) {
$content = implode("\n", $content) . "\n";
}
$this->htmlMessage = $this->textMessage = null;
if ($content) {
if ($this->sendAs === 'html') {
$this->htmlMessage = $content;
} elseif ($this->sendAs === 'text') {
$this->textMessage = $content;
} else {
$this->htmlMessage = $this->textMessage = $content;
}
}
if ($this->sendAs === 'text') {
$message = $this->_wrap($content);
} else {
$message = $this->_wrap($content, 998);
}
if ($this->template === null) {
$message = $this->_formatMessage($message);
} else {
$message = $this->_render($message);
}
$message[] = '';
$this->_message = $message;
$lib->template($this->template, $this->layout)->viewVars($this->_controller->viewVars)->emailFormat($this->sendAs);
if (!empty($this->attachments)) {
$this->_attachFiles();
$lib->attachments($this->_formatAttachFiles());
}
if (!is_null($this->_boundary)) {
$this->_message[] = '';
$this->_message[] = '--' . $this->_boundary . '--';
$this->_message[] = '';
$lib->transport($this->delivery);
if ($this->delivery === 'mail') {
$lib->config(array('eol' => $this->lineFeed, 'additionalParameters' => $this->additionalParams));
} elseif ($this->delivery === 'smtp') {
$lib->config($this->smtpOptions);
} else {
$lib->config(array());
}
$sent = $lib->send($content);
$_method = '_' . $this->delivery;
$sent = $this->$_method();
$this->htmlMessage = $lib->message(CakeEmail::MESSAGE_HTML);
if (empty($this->htmlMessage)) {
$this->htmlMessage = null;
}
$this->textMessage = $lib->message(CakeEmail::MESSAGE_TEXT);
if (empty($this->textMessage)) {
$this->textMessage = null;
}
$this->_header = array();
$this->_message = array();
@ -437,232 +396,18 @@ class EmailComponent extends Component {
$this->subject = null;
$this->additionalParams = null;
$this->date = null;
$this->smtpError = null;
$this->attachments = array();
$this->htmlMessage = null;
$this->textMessage = null;
$this->messageId = true;
$this->_header = array();
$this->_boundary = null;
$this->_message = array();
}
/**
* Render the contents using the current layout and template.
* Format the attach array
*
* @param string $content Content to render
* @return array Email ready to be sent
* @access private
* @return array
*/
function _render($content) {
$viewClass = $this->Controller->view;
if ($viewClass != 'View') {
list($plugin, $viewClass) = pluginSplit($viewClass, true);
$viewClass = $viewClass . 'View';
App::uses($viewClass, $plugin . 'View');
}
$View = new $viewClass($this->Controller);
$View->layout = $this->layout;
$msg = array();
$content = implode("\n", $content);
if ($this->sendAs === 'both') {
$htmlContent = $content;
if (!empty($this->attachments)) {
$msg[] = '--' . $this->_boundary;
$msg[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->_boundary . '"';
$msg[] = '';
}
$msg[] = '--alt-' . $this->_boundary;
$msg[] = 'Content-Type: text/plain; charset=' . $this->charset;
$msg[] = 'Content-Transfer-Encoding: 7bit';
$msg[] = '';
$content = $View->element('email' . DS . 'text' . DS . $this->template, array('content' => $content), true);
$View->layoutPath = 'email' . DS . 'text';
$content = explode("\n", $this->textMessage = str_replace(array("\r\n", "\r"), "\n", $View->renderLayout($content)));
$msg = array_merge($msg, $content);
$msg[] = '';
$msg[] = '--alt-' . $this->_boundary;
$msg[] = 'Content-Type: text/html; charset=' . $this->charset;
$msg[] = 'Content-Transfer-Encoding: 7bit';
$msg[] = '';
$htmlContent = $View->element('email' . DS . 'html' . DS . $this->template, array('content' => $htmlContent), true);
$View->layoutPath = 'email' . DS . 'html';
$htmlContent = explode("\n", $this->htmlMessage = str_replace(array("\r\n", "\r"), "\n", $View->renderLayout($htmlContent)));
$msg = array_merge($msg, $htmlContent);
$msg[] = '';
$msg[] = '--alt-' . $this->_boundary . '--';
$msg[] = '';
ClassRegistry::removeObject('view');
return $msg;
}
if (!empty($this->attachments)) {
if ($this->sendAs === 'html') {
$msg[] = '';
$msg[] = '--' . $this->_boundary;
$msg[] = 'Content-Type: text/html; charset=' . $this->charset;
$msg[] = 'Content-Transfer-Encoding: 7bit';
$msg[] = '';
} else {
$msg[] = '--' . $this->_boundary;
$msg[] = 'Content-Type: text/plain; charset=' . $this->charset;
$msg[] = 'Content-Transfer-Encoding: 7bit';
$msg[] = '';
}
}
$content = $View->element('email' . DS . $this->sendAs . DS . $this->template, array('content' => $content), true);
$View->layoutPath = 'email' . DS . $this->sendAs;
$content = explode("\n", $rendered = str_replace(array("\r\n", "\r"), "\n", $View->renderLayout($content)));
if ($this->sendAs === 'html') {
$this->htmlMessage = $rendered;
} else {
$this->textMessage = $rendered;
}
$msg = array_merge($msg, $content);
ClassRegistry::removeObject('view');
return $msg;
}
/**
* Create unique boundary identifier
*
* @access private
*/
function _createboundary() {
$this->_boundary = md5(uniqid(time()));
}
/**
* Sets headers for the message
*
* @access public
* @param array Associative array containing headers to be set.
*/
function header($headers) {
foreach ($headers as $header => $value) {
$this->_header[] = sprintf('%s: %s', trim($header), trim($value));
}
}
/**
* Create emails headers including (but not limited to) from email address, reply to,
* bcc and cc.
*
* @access private
*/
function _createHeader() {
$headers = array();
if ($this->delivery == 'smtp') {
$headers['To'] = implode(', ', array_map(array($this, '_formatAddress'), (array)$this->to));
}
$headers['From'] = $this->_formatAddress($this->from);
if (!empty($this->replyTo)) {
$headers['Reply-To'] = $this->_formatAddress($this->replyTo);
}
if (!empty($this->return)) {
$headers['Return-Path'] = $this->_formatAddress($this->return);
}
if (!empty($this->readReceipt)) {
$headers['Disposition-Notification-To'] = $this->_formatAddress($this->readReceipt);
}
if (!empty($this->cc)) {
$headers['Cc'] = implode(', ', array_map(array($this, '_formatAddress'), (array)$this->cc));
}
if (!empty($this->bcc) && $this->delivery != 'smtp') {
$headers['Bcc'] = implode(', ', array_map(array($this, '_formatAddress'), (array)$this->bcc));
}
if ($this->delivery == 'smtp') {
$headers['Subject'] = $this->_encode($this->subject);
}
if ($this->messageId !== false) {
if ($this->messageId === true) {
$headers['Message-ID'] = '<' . String::UUID() . '@' . env('HTTP_HOST') . '>';
} else {
$headers['Message-ID'] = $this->messageId;
}
}
$date = $this->date;
if ($date == false) {
$date = date(DATE_RFC2822);
}
$headers['Date'] = $date;
$headers['X-Mailer'] = $this->xMailer;
if (!empty($this->headers)) {
foreach ($this->headers as $key => $val) {
$headers['X-' . $key] = $val;
}
}
if (!empty($this->attachments)) {
$this->_createBoundary();
$headers['MIME-Version'] = '1.0';
$headers['Content-Type'] = 'multipart/mixed; boundary="' . $this->_boundary . '"';
$headers[] = 'This part of the E-mail should never be seen. If';
$headers[] = 'you are reading this, consider upgrading your e-mail';
$headers[] = 'client to a MIME-compatible client.';
} elseif ($this->sendAs === 'text') {
$headers['Content-Type'] = 'text/plain; charset=' . $this->charset;
} elseif ($this->sendAs === 'html') {
$headers['Content-Type'] = 'text/html; charset=' . $this->charset;
} elseif ($this->sendAs === 'both') {
$headers['Content-Type'] = 'multipart/alternative; boundary="alt-' . $this->_boundary . '"';
}
$headers['Content-Transfer-Encoding'] = '7bit';
$this->header($headers);
}
/**
* Format the message by seeing if it has attachments.
*
* @param string $message Message to format
* @access private
*/
function _formatMessage($message) {
if (!empty($this->attachments)) {
$prefix = array('--' . $this->_boundary);
if ($this->sendAs === 'text') {
$prefix[] = 'Content-Type: text/plain; charset=' . $this->charset;
} elseif ($this->sendAs === 'html') {
$prefix[] = 'Content-Type: text/html; charset=' . $this->charset;
} elseif ($this->sendAs === 'both') {
$prefix[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->_boundary . '"';
}
$prefix[] = 'Content-Transfer-Encoding: 7bit';
$prefix[] = '';
$message = array_merge($prefix, $message);
}
return $message;
}
/**
* Attach files by adding file contents inside boundaries.
*
* @access private
* @TODO: modify to use the core File class?
*/
function _attachFiles() {
protected function _formatAttachFiles() {
$files = array();
foreach ($this->attachments as $filename => $attachment) {
$file = $this->_findFiles($attachment);
@ -673,21 +418,7 @@ class EmailComponent extends Component {
$files[$filename] = $file;
}
}
foreach ($files as $filename => $file) {
$handle = fopen($file, 'rb');
$data = fread($handle, filesize($file));
$data = chunk_split(base64_encode($data)) ;
fclose($handle);
$this->_message[] = '--' . $this->_boundary;
$this->_message[] = 'Content-Type: application/octet-stream';
$this->_message[] = 'Content-Transfer-Encoding: base64';
$this->_message[] = 'Content-Disposition: attachment; filename="' . basename($filename) . '"';
$this->_message[] = '';
$this->_message[] = $data;
$this->_message[] = '';
}
return $files;
}
/**
@ -710,39 +441,6 @@ class EmailComponent extends Component {
return null;
}
/**
* Wrap the message using EmailComponent::$lineLength
*
* @param string $message Message to wrap
* @param integer $lineLength Max length of line
* @return array Wrapped message
* @access protected
*/
function _wrap($message, $lineLength = null) {
$message = $this->_strip($message, true);
$message = str_replace(array("\r\n","\r"), "\n", $message);
$lines = explode("\n", $message);
$formatted = array();
if ($this->_lineLength !== null) {
trigger_error(__d('cake_dev', '_lineLength cannot be accessed please use lineLength'), E_USER_WARNING);
$this->lineLength = $this->_lineLength;
}
if (!$lineLength) {
$lineLength = $this->lineLength;
}
foreach ($lines as $line) {
if (substr($line, 0, 1) == '.') {
$line = '.' . $line;
}
$formatted = array_merge($formatted, explode("\n", wordwrap($line, $lineLength, "\n", true)));
}
$formatted[] = '';
return $formatted;
}
/**
* Encode the specified string using the current charset
*
@ -770,24 +468,22 @@ class EmailComponent extends Component {
}
/**
* Format a string as an email address
* Format addresses to be an array with email as key and alias as value
*
* @param string $string String representing an email address
* @return string Email address suitable for email headers or smtp pipe
* @access private
* @param array $addresses
* @return array
*/
function _formatAddress($string, $smtp = false) {
$hasAlias = preg_match('/((.*))?\s?<(.+)>/', $string, $matches);
if ($smtp && $hasAlias) {
return $this->_strip('<' . $matches[3] . '>');
} elseif ($smtp) {
return $this->_strip('<' . $string . '>');
protected function _formatAddresses($addresses) {
$formatted = array();
foreach ($addresses as $address) {
if (preg_match('/((.*))?\s?<(.+)>/', $address, $matches) && !empty($matches[2])) {
$formatted[$this->_strip($matches[3])] = $this->_encode($matches[2]);
} else {
$address = $this->_strip($address);
$formatted[$address] = $address;
}
}
if ($hasAlias && !empty($matches[2])) {
return $this->_encode($matches[2]) . $this->_strip(' <' . $matches[3] . '>');
}
return $this->_strip($string);
return $formatted;
}
/**
@ -813,197 +509,4 @@ class EmailComponent extends Component {
return $value;
}
/**
* Wrapper for PHP mail function used for sending out emails
*
* @return bool Success
* @access private
*/
function _mail() {
$header = implode($this->lineFeed, $this->_header);
$message = implode($this->lineFeed, $this->_message);
if (is_array($this->to)) {
$to = implode(', ', array_map(array($this, '_formatAddress'), $this->to));
} else {
$to = $this->to;
}
if (ini_get('safe_mode')) {
return @mail($to, $this->_encode($this->subject), $message, $header);
}
return @mail($to, $this->_encode($this->subject), $message, $header, $this->additionalParams);
}
/**
* Helper method to get socket, overridden in tests
*
* @param array $config Config data for the socket.
* @return void
* @access protected
*/
function _getSocket($config) {
$this->_smtpConnection = new CakeSocket($config);
}
/**
* Sends out email via SMTP
*
* @return bool Success
* @access private
*/
function _smtp() {
App::uses('CakeSocket', 'Network');
$defaults = array(
'host' => 'localhost',
'port' => 25,
'protocol' => 'smtp',
'timeout' => 30
);
$this->smtpOptions = array_merge($defaults, $this->smtpOptions);
$this->_getSocket($this->smtpOptions);
if (!$this->_smtpConnection->connect()) {
$this->smtpError = $this->_smtpConnection->lastError();
return false;
} elseif (!$this->_smtpSend(null, '220')) {
return false;
}
$httpHost = env('HTTP_HOST');
if (isset($this->smtpOptions['client'])) {
$host = $this->smtpOptions['client'];
} elseif (!empty($httpHost)) {
list($host) = explode(':', $httpHost);
} else {
$host = 'localhost';
}
if (!$this->_smtpSend("EHLO {$host}", '250') && !$this->_smtpSend("HELO {$host}", '250')) {
return false;
}
if (isset($this->smtpOptions['username']) && isset($this->smtpOptions['password'])) {
$authRequired = $this->_smtpSend('AUTH LOGIN', '334|503');
if ($authRequired == '334') {
if (!$this->_smtpSend(base64_encode($this->smtpOptions['username']), '334')) {
return false;
}
if (!$this->_smtpSend(base64_encode($this->smtpOptions['password']), '235')) {
return false;
}
} elseif ($authRequired != '503') {
return false;
}
}
if (!$this->_smtpSend('MAIL FROM: ' . $this->_formatAddress($this->from, true))) {
return false;
}
if (!is_array($this->to)) {
$tos = array_map('trim', explode(',', $this->to));
} else {
$tos = $this->to;
}
foreach ($tos as $to) {
if (!$this->_smtpSend('RCPT TO: ' . $this->_formatAddress($to, true))) {
return false;
}
}
foreach ($this->cc as $cc) {
if (!$this->_smtpSend('RCPT TO: ' . $this->_formatAddress($cc, true))) {
return false;
}
}
foreach ($this->bcc as $bcc) {
if (!$this->_smtpSend('RCPT TO: ' . $this->_formatAddress($bcc, true))) {
return false;
}
}
if (!$this->_smtpSend('DATA', '354')) {
return false;
}
$header = implode("\r\n", $this->_header);
$message = implode("\r\n", $this->_message);
if (!$this->_smtpSend($header . "\r\n\r\n" . $message . "\r\n\r\n\r\n.")) {
return false;
}
$this->_smtpSend('QUIT', false);
$this->_smtpConnection->disconnect();
return true;
}
/**
* Protected method for sending data to SMTP connection
*
* @param string $data data to be sent to SMTP server
* @param mixed $checkCode code to check for in server response, false to skip
* @return bool Success
* @access protected
*/
function _smtpSend($data, $checkCode = '250') {
if (!is_null($data)) {
$this->_smtpConnection->write($data . "\r\n");
}
while ($checkCode !== false) {
$response = '';
$startTime = time();
while (substr($response, -2) !== "\r\n" && ((time() - $startTime) < $this->smtpOptions['timeout'])) {
$response .= $this->_smtpConnection->read();
}
if (substr($response, -2) !== "\r\n") {
$this->smtpError = 'timeout';
return false;
}
$response = end(explode("\r\n", rtrim($response, "\r\n")));
if (preg_match('/^(' . $checkCode . ')(.)/', $response, $code)) {
if ($code[2] === '-') {
continue;
}
return $code[1];
}
$this->smtpError = $response;
return false;
}
return true;
}
/**
* Set as controller flash message a debug message showing current settings in component
*
* @return boolean Success
* @access private
*/
function _debug() {
$nl = "\n";
$header = implode($nl, $this->_header);
$message = implode($nl, $this->_message);
$fm = '<pre>';
if (is_array($this->to)) {
$to = implode(', ', array_map(array($this, '_formatAddress'), $this->to));
} else {
$to = $this->to;
}
$fm .= sprintf('%s %s%s', 'To:', $to, $nl);
$fm .= sprintf('%s %s%s', 'From:', $this->from, $nl);
$fm .= sprintf('%s %s%s', 'Subject:', $this->_encode($this->subject), $nl);
$fm .= sprintf('%s%3$s%3$s%s', 'Header:', $header, $nl);
$fm .= sprintf('%s%3$s%3$s%s', 'Parameters:', $this->additionalParams, $nl);
$fm .= sprintf('%s%3$s%3$s%s', 'Message:', $message, $nl);
$fm .= '</pre>';
if (isset($this->Controller->Session)) {
$this->Controller->Session->setFlash($fm, 'default', null, 'email');
return true;
}
return $fm;
}
}

View file

@ -565,7 +565,6 @@ class RequestHandlerComponent extends Component {
$defaults = array('index' => null, 'charset' => null, 'attachment' => false);
$options = $options + $defaults;
$cType = null;
if (strpos($type, '/') === false) {
$cType = $this->response->getMimeType($type);
if ($cType === false) {

View file

@ -32,7 +32,7 @@ class ComponentCollection extends ObjectCollection {
* Initializes all the Components for a controller.
* Attaches a reference of each component to the Controller.
*
* @param Controller $controller Controller to initialize components for.
* @param Controller $Controller Controller to initialize components for.
* @return void
*/
public function init(Controller $Controller) {

View file

@ -353,7 +353,7 @@ class Controller extends Object {
}
/**
* Provides backwards compatbility access to the request object properties.
* Provides backwards compatibility access to the request object properties.
* Also provides the params alias.
*
* @return void
@ -376,7 +376,7 @@ class Controller extends Object {
}
/**
* Provides backwards compatiblity access for setting values to the request object.
* Provides backwards compatibility access for setting values to the request object.
*
* @return void
*/
@ -732,8 +732,6 @@ class Controller extends Object {
* @link http://book.cakephp.org/view/979/set
*/
public function set($one, $two = null) {
$data = array();
if (is_array($one)) {
if (is_array($two)) {
$data = array_combine($one, $two);

View file

@ -289,7 +289,10 @@ class App {
'%s' . 'locale' . DS
),
'vendors' => array('%s' . 'vendors' . DS, VENDORS),
'plugins' => array(APP . 'plugins' . DS, CAKE_CORE_INCLUDE_PATH . DS . 'plugins' . DS)
'plugins' => array(
APP . 'plugins' . DS,
dirname(dirname(CAKE)) . DS . 'plugins' . DS
)
);
}
@ -320,9 +323,6 @@ class App {
}
}
$mergeExclude = array('Lib', 'locales', 'vendors', 'plugins');
$appLibs = empty($paths['Lib']) ? $defaults['Lib'] : $paths['Lib'];
foreach ($defaults as $type => $default) {
if (empty(self::$__packages[$type]) || empty($paths)) {
self::$__packages[$type] = $default;
@ -408,7 +408,6 @@ class App {
* @return mixed Either false on incorrect / miss. Or an array of found objects.
*/
public static function objects($type, $path = null, $cache = true) {
$objects = array();
$extension = '/\.php$/';
$includeDirectories = false;
$name = $type;
@ -448,8 +447,6 @@ class App {
$path = self::path($type, $plugin);
}
$items = array();
foreach ((array)$path as $dir) {
if ($dir != APP && is_dir($dir)) {
$files = new RegexIterator(new DirectoryIterator($dir), $extension);
@ -525,45 +522,47 @@ class App {
* @param string $className the name of the class to load
*/
public static function load($className) {
if (isset(self::$__classMap[$className])) {
if ($file = self::__mapped($className)) {
if (!isset(self::$__classMap[$className])) {
return false;
}
if ($file = self::__mapped($className)) {
return include $file;
}
$parts = explode('.', self::$__classMap[$className], 2);
list($plugin, $package) = count($parts) > 1 ? $parts : array(null, current($parts));
$paths = self::path($package, $plugin);
if (empty($plugin)) {
$appLibs = empty(self::$__packages['Lib']) ? APPLIBS : current(self::$__packages['Lib']);
$paths[] = $appLibs . $package . DS;
$paths[] = LIBS . $package . DS;
}
foreach ($paths as $path) {
$file = $path . $className . '.php';
if (file_exists($file)) {
self::__map($file, $className);
return include $file;
}
}
$parts = explode('.', self::$__classMap[$className], 2);
list($plugin, $package) = count($parts) > 1 ? $parts : array(null, current($parts));
$paths = self::path($package, $plugin);
if (empty($plugin)) {
$appLibs = empty(self::$__packages['Lib']) ? APPLIBS : current(self::$__packages['Lib']);
$paths[] = $appLibs . $package . DS;
$paths[] = LIBS . $package . DS;
//To help apps migrate to 2.0 old style file names are allowed
foreach ($paths as $path) {
$underscored = Inflector::underscore($className);
$tries = array($path . $underscored . '.php');
$parts = explode('_', $underscored);
if (count($parts) > 1) {
array_pop($parts);
$tries[] = $path . implode('_', $parts) . '.php';
}
foreach ($paths as $path) {
$file = $path . $className . '.php';
foreach ($tries as $file) {
if (file_exists($file)) {
self::__map($file, $className);
return include $file;
}
}
//To help apps migrate to 2.0 old style file names are allowed
foreach ($paths as $path) {
$underscored = Inflector::underscore($className);
$tries = array($path . $underscored . '.php');
$parts = explode('_', $underscored);
if (count($parts) > 1) {
array_pop($parts);
$tries[] = $path . implode('_', $parts) . '.php';
}
foreach ($tries as $file) {
if (file_exists($file)) {
self::__map($file, $className);
return include $file;
}
}
}
}
return false;
@ -588,7 +587,7 @@ class App {
* @return boolean true if Class is already in memory or if file is found and loaded, false if not
*/
public static function import($type = null, $name = null, $parent = true, $search = array(), $file = null, $return = false) {
$ext = $plugin = $directory = null;
$ext = null;
if (is_array($type)) {
extract($type, EXTR_OVERWRITE);

View file

@ -467,8 +467,8 @@ class CakeSessionException extends CakeException { }
class ConfigureException extends CakeException { }
/**
* Exception class for Socket. This exception will be thrown from CakeSocket, HttpSocket and HttpResponse when it
* encounters an error.
* Exception class for Socket. This exception will be thrown from CakeSocket, CakeEmail, HttpSocket
* and HttpResponse when it encounters an error.
*
* @package cake.libs
*/

View file

@ -772,7 +772,6 @@ class Multibyte {
$length = count($utf8Map);
$lowerCase = array();
$matched = false;
for ($i = 0 ; $i < $length; $i++) {
$char = $utf8Map[$i];
@ -819,7 +818,6 @@ class Multibyte {
$utf8Map = Multibyte::utf8($string);
$length = count($utf8Map);
$matched = false;
$replaced = array();
$upperCase = array();
@ -947,7 +945,6 @@ class Multibyte {
}
$string = Multibyte::utf8($string);
$stringCount = count($string);
for ($i = 1; $i <= $start; $i++) {
unset($string[$i - 1]);
@ -1068,7 +1065,6 @@ class Multibyte {
* @return array
*/
private static function __find($char, $type = 'lower') {
$value = false;
$found = array();
if (!isset(self::$__codeRange[$char])) {
$range = self::__codepoint($char);

View file

@ -16,6 +16,9 @@
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Cache', 'Cache');
/**
* CacheSession provides method for saving sessions into a Cache engine. Used with CakeSession
*

View file

@ -2589,7 +2589,7 @@ class Model extends Object {
'allowEmpty' => null,
'required' => null,
'rule' => 'blank',
'last' => false,
'last' => true,
'on' => null
);
@ -2728,7 +2728,7 @@ class Model extends Object {
if (!is_array($this->validationErrors)) {
$this->validationErrors = array();
}
$this->validationErrors[$field] = $value;
$this->validationErrors[$field] []= $value;
}
/**

File diff suppressed because it is too large Load diff

View file

@ -363,10 +363,12 @@ class CakeResponse {
* @return void
*/
protected function _sendHeader($name, $value = null) {
if (is_null($value)) {
header($name);
} else {
header("{$name}: {$value}");
if (!headers_sent()) {
if (is_null($value)) {
header($name);
} else {
header("{$name}: {$value}");
}
}
}
@ -571,7 +573,6 @@ class CakeResponse {
return array_map(array($this, 'mapType'), $ctype);
}
$keys = array_keys($this->_mimeTypes);
$count = count($keys);
foreach ($this->_mimeTypes as $alias => $types) {
if (is_array($types) && in_array($ctype, $types)) {

View file

@ -0,0 +1,75 @@
<?php
/**
* Abstract send email
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package cake.libs.email
* @since CakePHP(tm) v 2.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Abstract class
*
* @package cake.libs.email
*/
abstract class AbstractTransport {
/**
* Configurations
*
* @var array
*/
protected $_config = array();
/**
* Send mail
*
* @params object $email CakeEmail
* @return boolean
*/
abstract public function send(CakeEmail $email);
/**
* Set the config
*
* @param array $config
* @return object $this
*/
public function config($config = array()) {
if (!empty($config)) {
$this->_config = $config;
}
}
/**
* Help to convert headers in string
*
* @param array $headers Headers in format key => value
* @param string $eol
* @return string
*/
protected function _headersToString($headers, $eol = "\r\n") {
$out = '';
foreach ($headers as $key => $value) {
if ($value === false || $value === null || $value === '') {
continue;
}
$out .= $key . ': ' . $value . $eol;
}
if (!empty($out)) {
$out = substr($out, 0, -1 * strlen($eol));
}
return $out;
}
}

View file

@ -0,0 +1,49 @@
<?php
/**
* Send mail using mail() function
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package cake.libs.email
* @since CakePHP(tm) v 2.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Mail class
*
* @package cake.libs.email
*/
class MailTransport extends AbstractTransport {
/**
* Send mail
*
* @params object $email CakeEmail
* @return boolean
*/
public function send(CakeEmail $email) {
$eol = PHP_EOL;
if (isset($this->_config['eol'])) {
$eol = $this->_config['eol'];
}
$headers = $email->getHeaders(array_fill_keys(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc'), true));
$to = $headers['To'];
unset($headers['To']);
$header = $this->_headersToString($headers, $eol);
$message = implode($eol, $email->message());
if (ini_get('safe_mode') || !isset($this->_config['additionalParameters'])) {
return @mail($to, $email->subject(), $message, $header);
}
return @mail($to, $email->subject(), $message, $header, $this->_config['additionalParameters']);
}
}

View file

@ -0,0 +1,221 @@
<?php
/**
* Send mail using SMTP protocol
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package cake.libs.email
* @since CakePHP(tm) v 2.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('CakeSocket', 'Network');
/**
* SendEmail class
*
* @package cake.libs.email
*/
class SmtpTransport extends AbstractTransport {
/**
* Socket to SMTP server
*
* @var object CakeScoket
*/
protected $_socket;
/**
* CakeEmail
*
* @var object CakeEmail
*/
protected $_cakeEmail;
/**
* Send mail
*
* @params object $email CakeEmail
* @return boolean
* @thrown SocketException
*/
public function send(CakeEmail $email) {
$this->_cakeEmail = $email;
$this->_connect();
$this->_auth();
$this->_sendRcpt();
$this->_sendData();
$this->_disconnect();
return true;
}
/**
* Set the configuration
*
* @param array $config
* @return object $this
*/
public function config($config = array()) {
$default = array(
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => null,
'password' => null,
'client' => null
);
$this->_config = $config + $default;
}
/**
* Connect to SMTP Server
*
* @return void
* @thrown SocketException
*/
protected function _connect() {
$this->_generateSocket();
if (!$this->_socket->connect()) {
throw new SocketException(__d('cake', 'Unable to connect in SMTP server.'));
}
$this->_smtpSend(null, '220');
if (isset($this->_config['client'])) {
$host = $this->_config['client'];
} elseif ($httpHost = env('HTTP_HOST')) {
list($host) = explode(':', $httpHost);
} else {
$host = 'localhost';
}
try {
$this->_smtpSend("EHLO {$host}", '250');
} catch (SocketException $e) {
try {
$this->_smtpSend("HELO {$host}", '250');
} catch (SocketException $e2) {
throw new SocketException(__d('cake', 'SMTP server not accepted the connection.'));
}
}
}
/**
* Send authentication
*
* @return void
* @thrown SocketException
*/
protected function _auth() {
if (isset($this->_config['username']) && isset($this->_config['password'])) {
$authRequired = $this->_smtpSend('AUTH LOGIN', '334|503');
if ($authRequired == '334') {
if (!$this->_smtpSend(base64_encode($this->_config['username']), '334')) {
throw new SocketException(__d('cake', 'SMTP server not accepted the username.'));
}
if (!$this->_smtpSend(base64_encode($this->_config['password']), '235')) {
throw new SocketException(__d('cake', 'SMTP server not accepted the password.'));
}
} elseif ($authRequired != '503') {
throw new SocketException(__d('cake', 'SMTP do not require authentication.'));
}
}
}
/**
* Send emails
*
* @return void
* @thrown SocketException
*/
protected function _sendRcpt() {
$from = $this->_cakeEmail->from();
$this->_smtpSend('MAIL FROM:<' . key($from) . '>');
$to = $this->_cakeEmail->to();
$cc = $this->_cakeEmail->cc();
$bcc = $this->_cakeEmail->bcc();
$emails = array_merge(array_keys($to), array_keys($cc), array_keys($bcc));
foreach ($emails as $email) {
$this->_smtpSend('RCPT TO:<' . $email . '>');
}
}
/**
* Send Data
*
* @return void
* @thrown SocketException
*/
protected function _sendData() {
$this->_smtpSend('DATA', '354');
$headers = $this->_cakeEmail->getHeaders(array_fill_keys(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject'), true));
$headers = $this->_headersToString($headers);
$message = implode("\r\n", $this->_cakeEmail->message());
$this->_smtpSend($headers . "\r\n\r\n" . $message . "\r\n\r\n\r\n.");
}
/**
* Disconnect
*
* @return void
* @thrown SocketException
*/
protected function _disconnect() {
$this->_smtpSend('QUIT', false);
$this->_socket->disconnect();
}
/**
* Helper method to generate socket
*
* @return void
* @thrown SocketException
*/
protected function _generateSocket() {
$this->_socket = new CakeSocket($this->_config);
}
/**
* Protected method for sending data to SMTP connection
*
* @param string $data data to be sent to SMTP server
* @param mixed $checkCode code to check for in server response, false to skip
* @return void
* @thrown SocketException
*/
function _smtpSend($data, $checkCode = '250') {
if (!is_null($data)) {
$this->_socket->write($data . "\r\n");
}
while ($checkCode !== false) {
$response = '';
$startTime = time();
while (substr($response, -2) !== "\r\n" && ((time() - $startTime) < $this->_config['timeout'])) {
$response .= $this->_socket->read();
}
if (substr($response, -2) !== "\r\n") {
throw new SocketException(__d('cake', 'SMTP timeout.'));
}
$response = end(explode("\r\n", rtrim($response, "\r\n")));
if (preg_match('/^(' . $checkCode . ')(.)/', $response, $code)) {
if ($code[2] === '-') {
continue;
}
return $code[1];
}
throw new SocketException(__d('cake', 'SMTP Error: %s', $response));
}
}
}

View file

@ -350,7 +350,6 @@ class HttpResponse implements ArrayAccess {
if ($hex == false) {
return $escape;
}
$regexChars = '';
foreach ($escape as $key => $char) {
$escape[$key] = '\\x' . str_pad(dechex(ord($char)), 2, '0', STR_PAD_LEFT);
}

View file

@ -917,7 +917,6 @@ class HttpSocket extends CakeSocket {
if ($hex == false) {
return $escape;
}
$regexChars = '';
foreach ($escape as $key => $char) {
$escape[$key] = '\\x' . str_pad(dechex(ord($char)), 2, '0', STR_PAD_LEFT);
}

View file

@ -299,7 +299,6 @@ class Dispatcher {
include WWW_ROOT . DS . $filters['js'];
return true;
}
$controller = null;
$pathSegments = explode('.', $url);
$ext = array_pop($pathSegments);
$parts = explode('/', $url);

View file

@ -399,7 +399,7 @@ class CakeRoute {
$greedyNamed = $namedConfig['greedyNamed'];
$allowedNamedParams = $namedConfig['rules'];
$named = $pass = $_query = array();
$named = $pass = array();
foreach ($url as $key => $value) {

View file

@ -487,7 +487,7 @@ class Router {
'named' => array()
);
$r = $ext = null;
$ext = null;
if ($url && strpos($url, '/') !== 0) {
$url = '/' . $url;
@ -771,7 +771,7 @@ class Router {
* @return string Full translated URL with base path.
*/
public static function url($url = null, $full = false) {
$defaults = $params = array('plugin' => null, 'controller' => null, 'action' => 'index');
$params = array('plugin' => null, 'controller' => null, 'action' => 'index');
if (is_bool($full)) {
$escape = false;
@ -792,7 +792,7 @@ class Router {
}
$base = $path['base'];
$extension = $output = $mapped = $q = $frag = null;
$extension = $output = $q = $frag = null;
if (empty($url)) {
$output = isset($path['here']) ? $path['here'] : '/';

View file

@ -72,6 +72,7 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
*/
protected $_configure = array();
/**
* Runs the test case and collects the results in a TestResult object.
* If no TestResult object is passed a new one will be created.

View file

@ -22,8 +22,8 @@ class CakeTestLoader extends PHPUnit_Runner_StandardTestSuiteLoader {
/**
* Load a file and find the first test case / suite in that file.
*
* @param string $filePath
* @param string $params
* @param string $filePath
* @param string $params
* @return ReflectionClass
*/
public function load($filePath, $params = '') {
@ -45,7 +45,7 @@ class CakeTestLoader extends PHPUnit_Runner_StandardTestSuiteLoader {
/**
* Generates the base path to a set of tests based on the parameters.
*
* @param array $params
* @param array $params
* @return string The base path.
*/
protected static function _basePath($params) {
@ -76,6 +76,7 @@ class CakeTestLoader extends PHPUnit_Runner_StandardTestSuiteLoader {
$case = str_replace('Test.php', '', $case);
$testCases[$testCaseFile] = $case;
}
sort($testCases);
return $testCases;
}

View file

@ -93,7 +93,7 @@ class ClassRegistry {
*/
public static function &init($class, $type = null) {
$_this = ClassRegistry::getInstance();
$id = $false = false;
$false = false;
$true = true;
if (!$type) {

View file

@ -274,7 +274,6 @@ class Debugger {
break;
}
$helpCode = null;
if (!empty($_this->helpPath) && preg_match('/.*\[([0-9]+)\]$/', $description, $codes)) {
if (isset($codes[1])) {
$helpID = $codes[1];
@ -418,7 +417,7 @@ class Debugger {
* @link http://book.cakephp.org/view/1191/Using-the-Debugger-Class
*/
public static function excerpt($file, $line, $context = 2) {
$data = $lines = array();
$lines = array();
if (!file_exists($file)) {
return array();
}

View file

@ -415,7 +415,6 @@ class Set {
$matches[] = $context;
continue;
}
$match = false;
if ($token === '@*' && is_array($context['item'])) {
$matches[] = array(
'trace' => array_merge($context['trace'], (array)$key),

View file

@ -33,7 +33,6 @@ class String {
*/
public static function uuid() {
$node = env('SERVER_ADDR');
$pid = null;
if (strpos($node, ':') !== false) {
if (substr_count($node, '::')) {

View file

@ -194,7 +194,6 @@ class Xml {
$value = '';
}
$isNamespace = strpos($key, 'xmlns:');
$nsUri = null;
if ($isNamespace !== false) {
$node->setAttributeNS('http://www.w3.org/2000/xmlns/', $key, $value);
continue;

View file

@ -469,8 +469,8 @@ class FormHelper extends AppHelper {
* - `class` string The classname for the error message
*
* @param string $field A field name, like "Modelname.fieldname"
* @param mixed $text Error message or array of $options. If array, `attributes` key
* will get used as html attributes for error container
* @param mixed $text Error message as string or array of messages.
* If array contains `attributes` key it will be used as options for error container
* @param array $options Rendering options for <div /> wrapper tag
* @return string If there are errors this method returns an error message, otherwise null.
* @access public
@ -482,36 +482,63 @@ class FormHelper extends AppHelper {
$this->setEntity($field);
if ($error = $this->tagIsInvalid()) {
if (is_array($error)) {
list(,,$field) = explode('.', $field);
if (isset($error[$field])) {
$error = $error[$field];
} else {
return null;
}
}
if (is_array($text) && is_numeric($error) && $error > 0) {
$error--;
}
if (is_array($text)) {
$options = array_merge($options, array_intersect_key($text, $defaults));
if (isset($text['attributes']) && is_array($text['attributes'])) {
$options = array_merge($options, $text['attributes']);
unset($text['attributes']);
}
$text = isset($text[$error]) ? $text[$error] : null;
unset($options[$error]);
$tmp = array();
foreach ($error as &$e) {
if (isset($text[$e])) {
$tmp []= $text[$e];
} else {
$tmp []= $e;
}
}
$text = $tmp;
}
if ($text != null) {
$error = $text;
} elseif (is_numeric($error)) {
$error = __d('cake', 'Error in field %s', Inflector::humanize($this->field()));
}
if (is_array($error)) {
foreach ($error as &$e) {
if (is_numeric($e)) {
$e = __d('cake', 'Error in field %s', Inflector::humanize($this->field()));
}
}
}
if ($options['escape']) {
$error = h($error);
unset($options['escape']);
}
if (is_array($error)) {
if (count($error) > 1) {
$listParams = array();
if (isset($options['listOptions'])) {
if (is_string($options['listOptions'])) {
$listParams []= $options['listOptions'];
} else {
if (isset($options['listOptions']['itemOptions'])) {
$listParams []= $options['listOptions']['itemOptions'];
unset($options['listOptions']['itemOptions']);
} else {
$listParams []= array();
}
if (isset($options['listOptions']['tag'])) {
$listParams []= $options['listOptions']['tag'];
unset($options['listOptions']['tag']);
}
array_unshift($listParams, $options['listOptions']);
}
unset($options['listOptions']);
}
array_unshift($listParams, $error);
$error = call_user_func_array(array($this->Html, 'nestedList'), $listParams);
} else {
$error = array_pop($error);
}
}
if ($options['wrap']) {
$tag = is_string($options['wrap']) ? $options['wrap'] : 'div';
unset($options['wrap']);
@ -1211,7 +1238,7 @@ class FormHelper extends AppHelper {
$this->__secure(null, '' . $options['value']);
}
return $this->Html->useTag('hidden', $options['name'], array_diff_key($options, array('name' => '', 'class' => '')));
return $this->Html->useTag('hidden', $options['name'], array_diff_key($options, array('name' => '')));
}
/**

View file

@ -1,6 +1,6 @@
<?php
/**
* AllCacheEnginesTest file
* AllCacheTest file
*
* PHP 5
*
@ -18,13 +18,13 @@
*/
/**
* AllCacheEnginesTest class
* AllCacheTest class
*
* This test group will run cache engine tests.
*
* @package cake.tests.groups
*/
class AllCacheEnginesTest extends PHPUnit_Framework_TestSuite {
class AllCacheTest extends PHPUnit_Framework_TestSuite {
/**
* suite method, defines tests for this suite.
@ -34,6 +34,7 @@ class AllCacheEnginesTest extends PHPUnit_Framework_TestSuite {
public static function suite() {
$suite = new CakeTestSuite('All Cache related class tests');
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'Cache');
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'Cache' . DS . 'Engine');
return $suite;
}
}

View file

@ -20,7 +20,7 @@
/**
* AllConfigureTest class
*
* This test group will run cache engine tests.
* This test group will run configure tests.
*
* @package cake.tests.groups
*/
@ -32,9 +32,8 @@ class AllConfigureTest extends PHPUnit_Framework_TestSuite {
* @return void
*/
public static function suite() {
$suite = new CakeTestSuite('All Configure and Core related tests');
$suite = new CakeTestSuite('All Configure related tests');
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'Core');
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'Configure');
return $suite;
}

View file

@ -0,0 +1,44 @@
<?php
/**
* AllConsoleTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package cake.tests.cases
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* AllConsoleTest class
*
* This test group will run all console classes.
*
* @package cake.tests.cases.console
*/
class AllConsoleTest extends PHPUnit_Framework_TestSuite {
/**
* suite method, defines tests for this suite.
*
* @return void
*/
public static function suite() {
$suite = new CakeTestSuite('All console classes');
$path = CORE_TEST_CASES . DS . 'Console' . DS;
$suite->addTestFile($path . 'AllConsoleLibsTest.php');
$suite->addTestFile($path . 'AllTasksTest.php');
$suite->addTestFile($path . 'AllShellsTest.php');
return $suite;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* AllXmlTest file
* AllCoreTest file
*
* PHP 5
*
@ -18,13 +18,13 @@
*/
/**
* AllXmlTest class
* AllCoreTest class
*
* This test group will run xml class tests
* This test group will run all core class tests
*
* @package cake.tests.groups
*/
class AllXmlTest extends PHPUnit_Framework_TestSuite {
class AllCoreTest extends PHPUnit_Framework_TestSuite {
/**
* suite method, defines tests for this suite.
@ -32,10 +32,10 @@ class AllXmlTest extends PHPUnit_Framework_TestSuite {
* @return void
*/
public static function suite() {
$suite = new PHPUnit_Framework_TestSuite('All Xml related class tests');
$suite = new CakeTestSuite('All Core class tests');
$suite->addTestFile(CORE_TEST_CASES . DS . 'Utility' . DS . 'XmlTest.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'View' . DS . 'Helper' . DS . 'RssHelperTest.php');
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'Core');
return $suite;
}
}
}

View file

@ -32,12 +32,11 @@ class AllErrorTest extends PHPUnit_Framework_TestSuite {
* @return void
*/
public static function suite() {
$suite = new PHPUnit_Framework_TestSuite('All Error handling tests');
$suite = new CakeTestSuite('All Error handling tests');
$libs = CORE_TEST_CASES . DS;
$suite->addTestFile($libs . 'Error' . DS . 'ErrorHandlerTest.php');
$suite->addTestFile($libs . 'Error' . DS . 'ExceptionRendererTest.php');
$suite->addTestDirectory($libs . 'Error');
return $suite;
}
}

View file

@ -1,44 +0,0 @@
<?php
/**
* AllJavascriptHelpersTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package cake.tests.cases
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* AllJavascriptHelpersTest class
*
* This test group will run all test in the cases/libs/view/helpers directory related
* to Js helper and its engines
*
* @package cake.tests.groups
*/
class AllJavascriptHelpersTest extends PHPUnit_Framework_TestSuite {
/**
* Suite define the tests for this suite
*
* @return void
*/
public static function suite() {
$suite = new PHPUnit_Framework_TestSuite('Js Helper and all Engine Helpers');
$helperTestPath = CORE_TEST_CASES . DS . 'View' . DS . 'Helper' . DS;
$suite->addTestFile($helperTestPath . 'JsHelperTest.php');
$suite->addTestFile($helperTestPath . 'JqueryEngineHelperTest.php');
$suite->addTestFile($helperTestPath . 'MootoolsEngineHelperTest.php');
$suite->addTestFile($helperTestPath . 'PrototypeEngineHelperTest.php');
return $suite;
}
}

View file

@ -0,0 +1,41 @@
<?php
/**
* AllLogTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package cake.tests.cases
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* AllLogTest class
*
* This test group will run log tests.
*
* @package cake.tests.groups
*/
class AllLogTest extends PHPUnit_Framework_TestSuite {
/**
* suite method, defines tests for this suite.
*
* @return void
*/
public static function suite() {
$suite = new CakeTestSuite('All Logging related class tests');
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'Log');
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'Log' . DS . 'Engine');
return $suite;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* AllSocketTest file
* AllNetworkTest file
*
* PHP 5
*
@ -18,13 +18,13 @@
*/
/**
* AllSocketTest class
* AllNetworkTest class
*
* This test group will run socket class tests
*
* @package cake.tests.groups
*/
class AllSocketTest extends PHPUnit_Framework_TestSuite {
class AllNetworkTest extends PHPUnit_Framework_TestSuite {
/**
* suite method, defines tests for this suite.
@ -32,10 +32,10 @@ class AllSocketTest extends PHPUnit_Framework_TestSuite {
* @return void
*/
public static function suite() {
$suite = new CakeTestSuite('All Socket related class tests');
$suite = new CakeTestSuite('All Network related class tests');
$suite->addTestFile(CORE_TEST_CASES . DS . 'Network' . DS . 'CakeSocketTest.php');
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'Network');
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'Network' . DS . 'Http');
return $suite;
}
}
}

View file

@ -32,13 +32,12 @@ class AllRoutingTest extends PHPUnit_Framework_TestSuite {
* @return void
*/
public static function suite() {
$suite = new CakeTestSuite('All Router and Dispatcher class tests');
$suite = new CakeTestSuite('All Routing class tests');
$libs = CORE_TEST_CASES . DS;
$suite->addTestDirectory($libs . 'Routing');
$suite->addTestFile($libs . 'Network' . DS . 'CakeResponseTest.php');
$suite->addTestFile($libs . 'Network' . DS . 'CakeRequestTest.php');
$suite->addTestDirectory($libs . 'Routing' . DS . 'Route');
return $suite;
}
}

View file

@ -34,25 +34,26 @@ class AllTests extends PHPUnit_Framework_TestSuite {
$suite = new PHPUnit_Framework_TestSuite('All Tests');
$path = CORE_TEST_CASES . DS;
$console = $path . 'Console' . DS;
$suite->addTestFile($console . 'AllConsoleTest.php');
$suite->addTestFile($path . 'BasicsTest.php');
$suite->addTestFile($path . 'AllConsoleTest.php');
$suite->addTestFile($path . 'AllBehaviorsTest.php');
$suite->addTestFile($path . 'AllCacheEnginesTest.php');
$suite->addTestFile($path . 'AllCacheTest.php');
$suite->addTestFile($path . 'AllComponentsTest.php');
$suite->addTestFile($path . 'AllConfigureTest.php');
$suite->addTestFile($path . 'AllControllersTest.php');
$suite->addTestFile($path . 'AllCoreTest.php');
$suite->addTestFile($path . 'AllControllerTest.php');
$suite->addTestFile($path . 'AllDatabaseTest.php');
$suite->addTestFile($path . 'AllErrorTest.php');
$suite->addTestFile($path . 'AllHelpersTest.php');
$suite->addTestFile($path . 'AllLibsTest.php');
$suite->addTestFile($path . 'AllLocalizationTest.php');
$suite->addTestFile($path . 'AllLogTest.php');
$suite->addTestFile($path . 'AllI18nTest.php');
$suite->addTestFile($path . 'AllModelTest.php');
$suite->addTestFile($path . 'AllRoutingTest.php');
$suite->addTestFile($path . 'AllSocketTest.php');
$suite->addTestFile($path . 'AllNetworkTest.php');
$suite->addTestFile($path . 'AllTestSuiteTest.php');;
$suite->addTestFile($path . 'AllViewsTest.php');
$suite->addTestFile($path . 'AllXmlTest.php');
$suite->addTestFile($path . 'AllUtilityTest.php');
$suite->addTestFile($path . 'AllViewTest.php');
return $suite;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* AllLibsTest file
* AllUtilityTest file
*
* PHP 5
*
@ -18,13 +18,13 @@
*/
/**
* AllLibsTest class
* AllUtilityTest class
*
* This test group will run all non mvc related lib class tests
*
* @package cake.tests.cases
*/
class AllLibsTest extends PHPUnit_Framework_TestSuite {
class AllUtilityTest extends PHPUnit_Framework_TestSuite {
/**
* suite method, defines tests for this suite.
@ -32,13 +32,8 @@ class AllLibsTest extends PHPUnit_Framework_TestSuite {
* @return void
*/
public static function suite() {
$suite = new CakeTestSuite('All non-MVC lib class tests');
$suite->addTestFile(CORE_TEST_CASES . DS . 'BasicsTest.php');
$suite = new CakeTestSuite('All Utility class tests');
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'Utility');
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'Log');
$suite->addTestFile(CORE_TEST_CASES . DS . 'Model' . DS . 'Datasource' . DS . 'CakeSessionTest.php');
//$suite->addTestDirectory(CORE_TEST_CASES . DS . 'Model' . DS . 'Datasource' . DS . 'Session');
return $suite;
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* AllViewsTest file
* AllViewTest file
*
* PHP 5
*
@ -18,13 +18,13 @@
*/
/**
* AllViewsTest class
* AllViewTest class
*
* This test group will run view class tests (view, theme)
*
* @package cake.tests.groups
*/
class AllViewsTest extends PHPUnit_Framework_TestSuite {
class AllViewTest extends PHPUnit_Framework_TestSuite {
/**
* suite method, defines tests for this suite.

View file

@ -41,4 +41,4 @@ class AllConsoleTest extends PHPUnit_Framework_TestSuite {
$suite->addTestFile($path . 'AllShellsTest.php');
return $suite;
}
}
}

View file

@ -170,20 +170,20 @@ class ShellTest extends CakeTestCase {
public function testInitialize() {
App::build(array(
'plugins' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
'models' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'models' . DS)
'models' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'Model' . DS)
), true);
$this->Shell->uses = array('TestPlugin.TestPluginPost');
$this->Shell->initialize();
$this->assertTrue(isset($this->Shell->TestPluginPost));
$this->assertIsA($this->Shell->TestPluginPost, 'TestPluginPost');
$this->assertInstanceOf('TestPluginPost', $this->Shell->TestPluginPost);
$this->assertEqual($this->Shell->modelClass, 'TestPluginPost');
$this->Shell->uses = array('Comment');
$this->Shell->initialize();
$this->assertTrue(isset($this->Shell->Comment));
$this->assertIsA($this->Shell->Comment, 'Comment');
$this->assertInstanceOf('Comment', $this->Shell->Comment);
$this->assertEqual($this->Shell->modelClass, 'Comment');
App::build();

View file

@ -94,6 +94,7 @@ class ControllerTaskTest extends CakeTestCase {
public function teardown() {
unset($this->Task);
ClassRegistry::flush();
App::build();
}
/**

View file

@ -67,11 +67,11 @@ class PluginTaskTest extends CakeTestCase {
$path = $this->Task->path . 'bake_test_plugin';
$file = $path . DS . 'bake_test_plugin_app_controller.php';
$file = $path . DS . 'Controller' . DS .'BakeTestPluginAppController.php';
$this->Task->expects($this->at(2))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$file = $path . DS . 'bake_test_plugin_app_model.php';
$file = $path . DS . 'Model' . DS . 'BakeTestPluginAppModel.php';
$this->Task->expects($this->at(3))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
@ -82,19 +82,16 @@ class PluginTaskTest extends CakeTestCase {
$directories = array(
'config' . DS . 'schema',
'models' . DS . 'behaviors',
'models' . DS . 'datasources',
'console' . DS . 'shells' . DS . 'tasks',
'controllers' . DS . 'components',
'libs',
'views' . DS . 'helpers',
'tests' . DS . 'cases' . DS . 'components',
'tests' . DS . 'cases' . DS . 'helpers',
'tests' . DS . 'cases' . DS . 'behaviors',
'tests' . DS . 'cases' . DS . 'controllers',
'tests' . DS . 'cases' . DS . 'models',
'tests' . DS . 'groups',
'tests' . DS . 'fixtures',
'Model' . DS . 'Behavior',
'Model' . DS . 'Datasource',
'Console' . DS . 'Command' . DS . 'Task',
'Controller' . DS . 'Component',
'Lib',
'View' . DS . 'Helper',
'tests' . DS . 'Case' . DS . 'Controller' . DS . 'Component',
'tests' . DS . 'Case' . DS . 'View' . DS . 'Helper',
'tests' . DS . 'Case' . DS . 'Model' . DS . 'Behavior',
'tests' . DS . 'Fixture',
'vendors',
'webroot'
);
@ -117,11 +114,11 @@ class PluginTaskTest extends CakeTestCase {
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('y'));
$path = $this->Task->path . 'test_plugin';
$file = $path . DS . 'test_plugin_app_controller.php';
$file = $path . DS . 'Controller' . DS . 'TestPluginAppController.php';
$this->Task->expects($this->at(3))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$file = $path . DS . 'test_plugin_app_model.php';
$file = $path . DS . 'Model' . DS . 'TestPluginAppModel.php';
$this->Task->expects($this->at(4))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
@ -144,12 +141,12 @@ class PluginTaskTest extends CakeTestCase {
->will($this->returnValue('y'));
$path = $this->Task->path . 'bake_test_plugin';
$file = $path . DS . 'bake_test_plugin_app_controller.php';
$file = $path . DS . 'Controller' . DS . 'BakeTestPluginAppController.php';
$this->Task->expects($this->at(2))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$path = $this->Task->path . 'bake_test_plugin';
$file = $path . DS . 'bake_test_plugin_app_model.php';
$file = $path . DS . 'Model' . DS . 'BakeTestPluginAppModel.php';
$this->Task->expects($this->at(3))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());

View file

@ -238,6 +238,19 @@ class CookieComponentTest extends CakeTestCase {
$this->Cookie->delete('tag');
}
/**
* test writing values that are not scalars
*
* @return void
*/
function testWriteArrayValues() {
$this->Cookie->secure = false;
$this->Cookie->expects($this->once())->method('_setcookie')
->with('CakeTestCookie[Testing]', '[1,2,3]', time() + 10, '/', '', false, false);
$this->Cookie->write('Testing', array(1, 2, 3), false);
}
/**
* testReadingCookieValue
*
@ -359,7 +372,6 @@ class CookieComponentTest extends CakeTestCase {
* @return void
*/
function testReadingCookieDataOnStartup() {
$data = $this->Cookie->read('Encrytped_array');
$this->assertNull($data);
@ -378,28 +390,29 @@ class CookieComponentTest extends CakeTestCase {
'name' => $this->__encrypt('CakePHP'),
'version' => $this->__encrypt('1.2.0.x'),
'tag' => $this->__encrypt('CakePHP Rocks!')),
'Plain_array' => 'name|CakePHP,version|1.2.0.x,tag|CakePHP Rocks!',
'Plain_array' => '{"name":"CakePHP","version":"1.2.0.x","tag":"CakePHP Rocks!"}',
'Plain_multi_cookies' => array(
'name' => 'CakePHP',
'version' => '1.2.0.x',
'tag' => 'CakePHP Rocks!'));
$this->Cookie->startup(null);
$data = $this->Cookie->read('Encrytped_array');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$this->assertEquals($expected, $data);
$data = $this->Cookie->read('Encrytped_multi_cookies');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$this->assertEquals($expected, $data);
$data = $this->Cookie->read('Plain_array');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$this->assertEquals($expected, $data);
$data = $this->Cookie->read('Plain_multi_cookies');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$this->assertEquals($expected, $data);
$this->Cookie->destroy();
unset($_COOKIE['CakeTestCookie']);
}
@ -413,19 +426,19 @@ class CookieComponentTest extends CakeTestCase {
function testReadingCookieDataWithoutStartup() {
$data = $this->Cookie->read('Encrytped_array');
$expected = null;
$this->assertEqual($data, $expected);
$this->assertEquals($expected, $data);
$data = $this->Cookie->read('Encrytped_multi_cookies');
$expected = null;
$this->assertEqual($data, $expected);
$this->assertEquals($expected, $data);
$data = $this->Cookie->read('Plain_array');
$expected = null;
$this->assertEqual($data, $expected);
$this->assertEquals($expected, $data);
$data = $this->Cookie->read('Plain_multi_cookies');
$expected = null;
$this->assertEqual($data, $expected);
$this->assertEquals($expected, $data);
$_COOKIE['CakeTestCookie'] = array(
'Encrytped_array' => $this->__encrypt(array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')),
@ -433,7 +446,7 @@ class CookieComponentTest extends CakeTestCase {
'name' => $this->__encrypt('CakePHP'),
'version' => $this->__encrypt('1.2.0.x'),
'tag' => $this->__encrypt('CakePHP Rocks!')),
'Plain_array' => 'name|CakePHP,version|1.2.0.x,tag|CakePHP Rocks!',
'Plain_array' => '{"name":"CakePHP","version":"1.2.0.x","tag":"CakePHP Rocks!"}',
'Plain_multi_cookies' => array(
'name' => 'CakePHP',
'version' => '1.2.0.x',
@ -441,23 +454,36 @@ class CookieComponentTest extends CakeTestCase {
$data = $this->Cookie->read('Encrytped_array');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$this->assertEquals($expected, $data);
$data = $this->Cookie->read('Encrytped_multi_cookies');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$this->assertEquals($expected, $data);
$data = $this->Cookie->read('Plain_array');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$this->assertEquals($expected, $data);
$data = $this->Cookie->read('Plain_multi_cookies');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$this->assertEquals($expected, $data);
$this->Cookie->destroy();
unset($_COOKIE['CakeTestCookie']);
}
/**
* Test Reading legacy cookie values.
*
* @return void
*/
function testReadLegacyCookieValue() {
$_COOKIE['CakeTestCookie'] = array(
'Legacy' => array('value' => $this->_oldImplode(array(1, 2, 3)))
);
$result = $this->Cookie->read('Legacy.value');
$expected = array(1, 2, 3);
$this->assertEquals($expected, $result);
}
/**
* test that no error is issued for non array data.
@ -470,6 +496,29 @@ class CookieComponentTest extends CakeTestCase {
$this->assertNull($this->Cookie->read('value'));
}
/**
* Helper method for generating old style encoded cookie values.
*
* @return string.
*/
protected function _oldImplode(array $array) {
$string = '';
foreach ($array as $key => $value) {
$string .= ',' . $key . '|' . $value;
}
return substr($string, 1);
}
/**
* Implode method to keep keys are multidimensional arrays
*
* @param array $array Map of key and values
* @return string String in the form key1|value1,key2|value2
*/
protected function _implode(array $array) {
return json_encode($array);
}
/**
* encrypt method
@ -480,23 +529,9 @@ class CookieComponentTest extends CakeTestCase {
*/
function __encrypt($value) {
if (is_array($value)) {
$value = $this->__implode($value);
$value = $this->_implode($value);
}
return "Q2FrZQ==." . base64_encode(Security::cipher($value, $this->Cookie->key));
}
/**
* implode method
*
* @param array $value
* @return string
* @access private
*/
function __implode($array) {
$string = '';
foreach ($array as $key => $value) {
$string .= ',' . $key . '|' . $value;
}
return substr($string, 1);
}
}

View file

@ -1040,7 +1040,7 @@ class ControllerTest extends CakeTestCase {
$comment = new ControllerComment($request);
$comment->set('someVar', 'data');
$result = $TestController->validateErrors($comment);
$expected = array('some_field' => 'error_message', 'some_field2' => 'error_message2');
$expected = array('some_field' => array('error_message'), 'some_field2' => array('error_message2'));
$this->assertIdentical($result, $expected);
$this->assertEqual($TestController->validate($comment), 2);
}
@ -1058,7 +1058,7 @@ class ControllerTest extends CakeTestCase {
$Post->set('title', '');
$result = $TestController->validateErrors($Post);
$expected = array('title' => 'This field cannot be left blank');
$expected = array('title' => array('This field cannot be left blank'));
$this->assertEqual($result, $expected);
}

View file

@ -683,9 +683,9 @@ class ObjectTest extends CakeTestCase {
*/
function testRequestAction() {
App::build(array(
'models' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'models' . DS),
'views' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'views' . DS),
'controllers' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'controllers' . DS)
'models' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'Model' . DS),
'views' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'View' . DS),
'controllers' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'Controller' . DS)
));
$result = $this->object->requestAction('');
$this->assertFalse($result);
@ -763,9 +763,9 @@ class ObjectTest extends CakeTestCase {
*/
function testRequestActionArray() {
App::build(array(
'models' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'models' . DS),
'views' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'views' . DS),
'controllers' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'controllers' . DS)
'models' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'Model' . DS),
'views' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'View' . DS),
'controllers' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'Controller' . DS)
));
$result = $this->object->requestAction(
@ -819,8 +819,7 @@ class ObjectTest extends CakeTestCase {
*/
function testRequestActionParamParseAndPass() {
$result = $this->object->requestAction('/request_action/params_pass');
$this->assertTrue(isset($result['url']['url']));
$this->assertEqual($result['url']['url'], 'request_action/params_pass');
$this->assertEqual($result->url, 'request_action/params_pass');
$this->assertEqual($result['controller'], 'request_action');
$this->assertEqual($result['action'], 'params_pass');
$this->assertEqual($result['form'], array());

View file

@ -36,7 +36,7 @@ class ErrorHandlerTest extends CakeTestCase {
*/
function setUp() {
App::build(array(
'views' => array(
'View' => array(
LIBS . 'tests' . DS . 'test_app' . DS . 'views'. DS,
LIBS . 'libs' . DS . 'view' . DS
)

View file

@ -6592,7 +6592,7 @@ class MultibyteTest extends CakeTestCase {
$string = 'ԀԂԄԆԈԊԌԎԐԒ';
$result = mb_strtolower($string);
$expected = 'ԁԃԅԇԉԋԍԏԐԒ';
$expected = 'ԁԃԅԇԉԋԍԏԑԓ';
$this->assertEqual($result, $expected);
$string = 'ԱԲԳԴԵԶԷԸԹԺԻԼԽԾԿՀՁՂՃՄՅՆՇՈՉՊՋՌՍՎՏՐՑՒՓՔՕՖև';

View file

@ -670,7 +670,7 @@ class TranslateBehaviorTest extends CakeTestCase {
));
$TestModel->create();
$this->assertFalse($TestModel->save($data));
$this->assertEqual($TestModel->validationErrors['title'], 'This field cannot be left blank');
$this->assertEqual($TestModel->validationErrors['title'], array('This field cannot be left blank'));
$TestModel->locale = 'eng';
$TestModel->validate['title'] = '/Only this title/';

View file

@ -990,11 +990,11 @@ class BehaviorCollectionTest extends CakeTestCase {
$Apple->Behaviors->attach('Test', array('validate' => 'on'));
$this->assertIdentical($Apple->validates(), false);
$this->assertIdentical($Apple->validationErrors, array('name' => true));
$this->assertIdentical($Apple->validationErrors, array('name' => array(true)));
$Apple->Behaviors->attach('Test', array('validate' => 'stop'));
$this->assertIdentical($Apple->validates(), false);
$this->assertIdentical($Apple->validationErrors, array('name' => true));
$this->assertIdentical($Apple->validationErrors, array('name' => array(true, true)));
$Apple->Behaviors->attach('Test', array('validate' => 'whitelist'));
$Apple->validates();

View file

@ -49,7 +49,7 @@ class ModelValidationTest extends BaseModelTest {
'validator' => array(
'rule' => 'customValidatorWithParams',
'on' => null,
'last' => false,
'last' => true,
'allowEmpty' => false,
'required' => true
),
@ -63,7 +63,7 @@ class ModelValidationTest extends BaseModelTest {
'required' => true
);
$expected = array(
'title' => 'This field will *never* validate! Muhahaha!'
'title' => array('This field will *never* validate! Muhahaha!')
);
$this->assertEqual($TestModel->invalidFields(), $expected);
@ -85,7 +85,7 @@ class ModelValidationTest extends BaseModelTest {
'five' => array(
'rule' => array(1 => 'one', 2 => 'two', 3 => null, 4 => 'four'),
'on' => null,
'last' => false,
'last' => true,
'allowEmpty' => false,
'required' => true
),
@ -111,7 +111,7 @@ class ModelValidationTest extends BaseModelTest {
'six' => array(
'rule' => array(1 => 'one', 2 => array('two'), 3 => null, 4 => 'four', 5 => array('five' => 5)),
'on' => null,
'last' => false,
'last' => true,
'allowEmpty' => false,
'required' => true
)
@ -139,29 +139,29 @@ class ModelValidationTest extends BaseModelTest {
$TestModel->set(array('title' => '$$', 'name' => '##'));
$TestModel->invalidFields(array('fieldList' => array('title')));
$expected = array(
'title' => 'This field cannot be left blank'
'title' => array('This field cannot be left blank')
);
$this->assertEqual($TestModel->validationErrors, $expected);
$TestModel->validationErrors = array();
$TestModel->invalidFields(array('fieldList' => array('name')));
$expected = array(
'name' => 'This field cannot be left blank'
'name' => array('This field cannot be left blank')
);
$this->assertEqual($TestModel->validationErrors, $expected);
$TestModel->validationErrors = array();
$TestModel->invalidFields(array('fieldList' => array('name', 'title')));
$expected = array(
'name' => 'This field cannot be left blank',
'title' => 'This field cannot be left blank'
'name' => array('This field cannot be left blank'),
'title' => array('This field cannot be left blank')
);
$this->assertEqual($TestModel->validationErrors, $expected);
$TestModel->validationErrors = array();
$TestModel->whitelist = array('name');
$TestModel->invalidFields();
$expected = array('name' => 'This field cannot be left blank');
$expected = array('name' => array('This field cannot be left blank'));
$this->assertEqual($TestModel->validationErrors, $expected);
$this->assertEqual($TestModel->validate, $validate);
@ -187,7 +187,7 @@ class ModelValidationTest extends BaseModelTest {
$TestModel->whitelist = array('name');
$TestModel->save(array('name' => '#$$#', 'title' => '$$$$'));
$expected = array('name' => 'This field cannot be left blank');
$expected = array('name' => array('This field cannot be left blank'));
$this->assertEqual($TestModel->validationErrors, $expected);
}
@ -518,7 +518,7 @@ class ModelValidationTest extends BaseModelTest {
$this->assertFalse($result);
$result = $TestModel->validationErrors;
$expected = array(
'title' => 'onlyLetters'
'title' => array('tooShort')
);
$this->assertEqual($result, $expected);
@ -526,7 +526,7 @@ class ModelValidationTest extends BaseModelTest {
'title' => array(
'tooShort' => array(
'rule' => array('minLength', 50),
'last' => true
'last' => false
),
'onlyLetters' => array('rule' => '/^[a-z]+$/i')
),
@ -539,7 +539,7 @@ class ModelValidationTest extends BaseModelTest {
$this->assertFalse($result);
$result = $TestModel->validationErrors;
$expected = array(
'title' => 'tooShort'
'title' => array('tooShort', 'onlyLetters')
);
$this->assertEqual($result, $expected);
}
@ -569,7 +569,7 @@ class ModelValidationTest extends BaseModelTest {
$JoinThing->validate = array('doomed' => array('rule' => 'notEmpty'));
$expectedError = array('doomed' => 'This field cannot be left blank');
$expectedError = array('doomed' => array('This field cannot be left blank'));
$Something->create();
$result = $Something->save($data);
@ -621,7 +621,7 @@ class ModelValidationTest extends BaseModelTest {
$JoinThing =& $Something->JoinThing;
$JoinThing->validate = array('doomed' => array('rule' => 'notEmpty'));
$expectedError = array('doomed' => 'This field cannot be left blank');
$expectedError = array('doomed' => array('This field cannot be left blank'));
$Something->create();
$result = $Something->saveAll($data, array('validate' => 'only'));

View file

@ -2765,8 +2765,8 @@ class ModelWriteTest extends BaseModelTest {
array('validate' => 'first')
), false);
$expected = array(
'Comment' => array('comment' => 'This field cannot be left blank'),
'Attachment' => array('attachment' => 'This field cannot be left blank')
'Comment' => array('comment' => array('This field cannot be left blank')),
'Attachment' => array('attachment' => array('This field cannot be left blank'))
);
$this->assertEqual($model->validationErrors, $expected['Comment']);
$this->assertEqual($model->Attachment->validationErrors, $expected['Attachment']);
@ -2956,11 +2956,11 @@ class ModelWriteTest extends BaseModelTest {
$this->assertEqual($result, $expected);
$expected = array('Comment' => array(
array('comment' => 'This field cannot be left blank')
array('comment' => array('This field cannot be left blank'))
));
$this->assertEqual($TestModel->validationErrors, $expected);
$expected = array(
array('comment' => 'This field cannot be left blank')
array('comment' => array('This field cannot be left blank'))
);
$this->assertEqual($TestModel->Comment->validationErrors, $expected);
@ -3356,7 +3356,7 @@ class ModelWriteTest extends BaseModelTest {
$this->assertFalse($result);
$result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC'));
$errors = array(1 => array('title' => 'This field cannot be left blank'));
$errors = array(1 => array('title' => array('This field cannot be left blank')));
$transactionWorked = Set::matches('/Post[1][title=Baleeted First Post]', $result);
if (!$transactionWorked) {
$this->assertTrue(Set::matches('/Post[1][title=Un-Baleeted First Post]', $result));
@ -3381,7 +3381,7 @@ class ModelWriteTest extends BaseModelTest {
$result = $TestModel->saveAll($data, array('validate' => true, 'atomic' => false));
$this->assertEqual($result, array(true, false));
$result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC'));
$errors = array(1 => array('title' => 'This field cannot be left blank'));
$errors = array(1 => array('title' => array('This field cannot be left blank')));
$newTs = date('Y-m-d H:i:s');
$expected = array(
array(
@ -3494,7 +3494,7 @@ class ModelWriteTest extends BaseModelTest {
);
$this->assertFalse($result);
$expected = array(
0 => array('title' => 'This field cannot be left blank'),
0 => array('title' => array('This field cannot be left blank')),
);
$this->assertEqual($TestModel->validationErrors, $expected);
@ -3508,7 +3508,7 @@ class ModelWriteTest extends BaseModelTest {
);
$this->assertFalse($result);
$expected = array(
1 => array('title' => 'This field cannot be left blank'),
1 => array('title' => array('This field cannot be left blank')),
);
$this->assertEqual($TestModel->validationErrors, $expected);
}
@ -3541,7 +3541,7 @@ class ModelWriteTest extends BaseModelTest {
$result = $model->find('all');
$this->assertEqual($result, array());
$expected = array('Comment' => array(
1 => array('comment' => 'This field cannot be left blank')
1 => array('comment' => array('This field cannot be left blank'))
));
$this->assertEqual($model->Comment->validationErrors, $expected['Comment']);
@ -3747,14 +3747,14 @@ class ModelWriteTest extends BaseModelTest {
$this->assertIdentical($result, $expected);
$expected = array('Comment' => array(
0 => array('comment' => 'This field cannot be left blank'),
2 => array('comment' => 'This field cannot be left blank')
0 => array('comment' => array('This field cannot be left blank')),
2 => array('comment' => array('This field cannot be left blank'))
));
$this->assertEqual($TestModel->validationErrors, $expected);
$expected = array(
0 => array('comment' => 'This field cannot be left blank'),
2 => array('comment' => 'This field cannot be left blank')
0 => array('comment' => array('This field cannot be left blank')),
2 => array('comment' => array('This field cannot be left blank'))
);
$this->assertEqual($TestModel->Comment->validationErrors, $expected);
}

View file

@ -0,0 +1,827 @@
<?php
/**
* CakeEmailTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, 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 2.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('CakeEmail', 'Network');
/**
* Help to test CakeEmail
*
*/
class TestCakeEmail extends CakeEmail {
/**
* Config
*
*/
protected $_config = array();
/**
* Wrap to protected method
*
*/
public function formatAddress($address) {
return parent::_formatAddress($address);
}
/**
* Wrap to protected method
*
*/
public function wrap($text) {
return parent::_wrap($text);
}
/**
* Get the boundary attribute
*
* @return string
*/
public function getBoundary() {
return $this->_boundary;
}
}
/**
* Debug transport email
*
*/
class DebugTransport extends AbstractTransport {
/**
* Last email body
*
* @var string
*/
public static $lastEmail = '';
/**
* Last email header
*
* @var string
*/
public static $lastHeader = '';
/**
* Include addresses in header
*
* @var boolean
*/
public static $includeAddresses = false;
/**
* Config
*
* @var array
*/
public static $config = array();
/**
* Config
*
* @param mixed $config
* @return mixed
*/
public function config($config) {
self::$config = $config;
}
/**
* Send
*
* @param object $email CakeEmail
* @return boolean
*/
public function send(CakeEmail $email) {
self::$lastEmail = implode("\r\n", $email->message());
$options = array();
if (self::$includeAddresses) {
$options = array_fill_keys(array('from', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc'), true);
}
self::$lastHeader = $this->_headersToString($email->getHeaders($options));
return true;
}
}
/**
* CakeEmailTest class
*
* @package cake.tests.cases.libs
*/
class CakeEmailTest extends CakeTestCase {
/**
* setUp
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->CakeEmail = new TestCakeEmail();
App::build(array(
'views' => array(CAKE . 'tests' . DS . 'test_app' . DS . 'View'. DS)
));
}
/**
* tearDown method
*
* @return void
*/
function tearDown() {
parent::tearDown();
App::build();
}
/**
* testFrom method
*
* @return void
*/
public function testFrom() {
$this->assertIdentical($this->CakeEmail->from(), array());
$this->CakeEmail->from('cake@cakephp.org');
$expected = array('cake@cakephp.org' => 'cake@cakephp.org');
$this->assertIdentical($this->CakeEmail->from(), $expected);
$this->CakeEmail->from(array('cake@cakephp.org'));
$this->assertIdentical($this->CakeEmail->from(), $expected);
$this->CakeEmail->from('cake@cakephp.org', 'CakePHP');
$expected = array('cake@cakephp.org' => 'CakePHP');
$this->assertIdentical($this->CakeEmail->from(), $expected);
$result = $this->CakeEmail->from(array('cake@cakephp.org' => 'CakePHP'));
$this->assertIdentical($this->CakeEmail->from(), $expected);
$this->assertIdentical($this->CakeEmail, $result);
}
/**
* testSender method
*
* @return void
*/
public function testSender() {
$this->CakeEmail->reset();
$this->assertIdentical($this->CakeEmail->sender(), array());
$this->CakeEmail->sender('cake@cakephp.org', 'Name');
$expected = array('cake@cakephp.org' => 'Name');
$this->assertIdentical($this->CakeEmail->sender(), $expected);
$headers = $this->CakeEmail->getHeaders(array('from' => true, 'sender' => true));
$this->assertIdentical($headers['From'], false);
$this->assertIdentical($headers['Sender'], 'Name <cake@cakephp.org>');
$this->CakeEmail->from('cake@cakephp.org', 'CakePHP');
$headers = $this->CakeEmail->getHeaders(array('from' => true, 'sender' => true));
$this->assertIdentical($headers['From'], 'CakePHP <cake@cakephp.org>');
$this->assertIdentical($headers['Sender'], '');
}
/**
* testTo method
*
* @return void
*/
public function testTo() {
$this->assertIdentical($this->CakeEmail->to(), array());
$result = $this->CakeEmail->to('cake@cakephp.org');
$expected = array('cake@cakephp.org' => 'cake@cakephp.org');
$this->assertIdentical($this->CakeEmail->to(), $expected);
$this->assertIdentical($this->CakeEmail, $result);
$this->CakeEmail->to('cake@cakephp.org', 'CakePHP');
$expected = array('cake@cakephp.org' => 'CakePHP');
$this->assertIdentical($this->CakeEmail->to(), $expected);
$list = array(
'cake@cakephp.org' => 'Cake PHP',
'cake-php@googlegroups.com' => 'Cake Groups',
'root@cakephp.org'
);
$this->CakeEmail->to($list);
$expected = array(
'cake@cakephp.org' => 'Cake PHP',
'cake-php@googlegroups.com' => 'Cake Groups',
'root@cakephp.org' => 'root@cakephp.org'
);
$this->assertIdentical($this->CakeEmail->to(), $expected);
$this->CakeEmail->addTo('jrbasso@cakephp.org');
$this->CakeEmail->addTo('mark_story@cakephp.org', 'Mark Story');
$result = $this->CakeEmail->addTo(array('phpnut@cakephp.org' => 'PhpNut', 'jose_zap@cakephp.org'));
$expected = array(
'cake@cakephp.org' => 'Cake PHP',
'cake-php@googlegroups.com' => 'Cake Groups',
'root@cakephp.org' => 'root@cakephp.org',
'jrbasso@cakephp.org' => 'jrbasso@cakephp.org',
'mark_story@cakephp.org' => 'Mark Story',
'phpnut@cakephp.org' => 'PhpNut',
'jose_zap@cakephp.org' => 'jose_zap@cakephp.org'
);
$this->assertIdentical($this->CakeEmail->to(), $expected);
$this->assertIdentical($this->CakeEmail, $result);
}
/**
* Data provider function for testBuildInvalidData
*
* @return array
*/
public static function invalidEmails() {
return array(
array(1.0),
array(''),
array('string'),
array('<tag>'),
array('some@one.whereis'),
array(array('ok@cakephp.org', 1.0, '', 'string'))
);
}
/**
* testBuildInvalidData
*
* @dataProvider invalidEmails
* @expectedException SocketException
* @return void
*/
public function testInvalidEmail($value) {
$this->CakeEmail->to($value);
}
/**
* testFormatAddress method
*
* @return void
*/
public function testFormatAddress() {
$result = $this->CakeEmail->formatAddress(array('cake@cakephp.org' => 'cake@cakephp.org'));
$expected = array('cake@cakephp.org');
$this->assertIdentical($result, $expected);
$result = $this->CakeEmail->formatAddress(array('cake@cakephp.org' => 'cake@cakephp.org', 'php@cakephp.org' => 'php@cakephp.org'));
$expected = array('cake@cakephp.org', 'php@cakephp.org');
$this->assertIdentical($result, $expected);
$result = $this->CakeEmail->formatAddress(array('cake@cakephp.org' => 'CakePHP', 'php@cakephp.org' => 'Cake'));
$expected = array('CakePHP <cake@cakephp.org>', 'Cake <php@cakephp.org>');
$this->assertIdentical($result, $expected);
$result = $this->CakeEmail->formatAddress(array('cake@cakephp.org' => 'ÄÖÜTest'));
$expected = array('=?UTF-8?B?w4TDlsOcVGVzdA==?= <cake@cakephp.org>');
$this->assertIdentical($result, $expected);
}
/**
* testAddresses method
*
* @return void
*/
public function testAddresses() {
$this->CakeEmail->reset();
$this->CakeEmail->from('cake@cakephp.org', 'CakePHP');
$this->CakeEmail->replyTo('replyto@cakephp.org', 'ReplyTo CakePHP');
$this->CakeEmail->readReceipt('readreceipt@cakephp.org', 'ReadReceipt CakePHP');
$this->CakeEmail->returnPath('returnpath@cakephp.org', 'ReturnPath CakePHP');
$this->CakeEmail->to('to@cakephp.org', 'To CakePHP');
$this->CakeEmail->cc('cc@cakephp.org', 'Cc CakePHP');
$this->CakeEmail->bcc('bcc@cakephp.org', 'Bcc CakePHP');
$this->CakeEmail->addTo('to2@cakephp.org', 'To2 CakePHP');
$this->CakeEmail->addCc('cc2@cakephp.org', 'Cc2 CakePHP');
$this->CakeEmail->addBcc('bcc2@cakephp.org', 'Bcc2 CakePHP');
$this->assertIdentical($this->CakeEmail->from(), array('cake@cakephp.org' => 'CakePHP'));
$this->assertIdentical($this->CakeEmail->replyTo(), array('replyto@cakephp.org' => 'ReplyTo CakePHP'));
$this->assertIdentical($this->CakeEmail->readReceipt(), array('readreceipt@cakephp.org' => 'ReadReceipt CakePHP'));
$this->assertIdentical($this->CakeEmail->returnPath(), array('returnpath@cakephp.org' => 'ReturnPath CakePHP'));
$this->assertIdentical($this->CakeEmail->to(), array('to@cakephp.org' => 'To CakePHP', 'to2@cakephp.org' => 'To2 CakePHP'));
$this->assertIdentical($this->CakeEmail->cc(), array('cc@cakephp.org' => 'Cc CakePHP', 'cc2@cakephp.org' => 'Cc2 CakePHP'));
$this->assertIdentical($this->CakeEmail->bcc(), array('bcc@cakephp.org' => 'Bcc CakePHP', 'bcc2@cakephp.org' => 'Bcc2 CakePHP'));
$headers = $this->CakeEmail->getHeaders(array_fill_keys(array('from', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc'), true));
$this->assertIdentical($headers['From'], 'CakePHP <cake@cakephp.org>');
$this->assertIdentical($headers['Reply-To'], 'ReplyTo CakePHP <replyto@cakephp.org>');
$this->assertIdentical($headers['Disposition-Notification-To'], 'ReadReceipt CakePHP <readreceipt@cakephp.org>');
$this->assertIdentical($headers['Return-Path'], 'ReturnPath CakePHP <returnpath@cakephp.org>');
$this->assertIdentical($headers['To'], 'To CakePHP <to@cakephp.org>, To2 CakePHP <to2@cakephp.org>');
$this->assertIdentical($headers['Cc'], 'Cc CakePHP <cc@cakephp.org>, Cc2 CakePHP <cc2@cakephp.org>');
$this->assertIdentical($headers['Bcc'], 'Bcc CakePHP <bcc@cakephp.org>, Bcc2 CakePHP <bcc2@cakephp.org>');
}
/**
* testMessageId method
*
* @return void
*/
public function testMessageId() {
$this->CakeEmail->messageId(true);
$result = $this->CakeEmail->getHeaders();
$this->assertTrue(isset($result['Message-ID']));
$this->CakeEmail->messageId(false);
$result = $this->CakeEmail->getHeaders();
$this->assertFalse(isset($result['Message-ID']));
$result = $this->CakeEmail->messageId('<my-email@localhost>');
$this->assertIdentical($this->CakeEmail, $result);
$result = $this->CakeEmail->getHeaders();
$this->assertIdentical($result['Message-ID'], '<my-email@localhost>');
}
/**
* testMessageIdInvalid method
*
* @return void
* @expectedException SocketException
*/
public function testMessageIdInvalid() {
$this->CakeEmail->messageId('my-email@localhost');
}
/**
* testSubject method
*
* @return void
*/
public function testSubject() {
$this->CakeEmail->subject('You have a new message.');
$this->assertIdentical($this->CakeEmail->subject(), 'You have a new message.');
$this->CakeEmail->subject(1);
$this->assertIdentical($this->CakeEmail->subject(), '1');
$result = $this->CakeEmail->subject(array('something'));
$this->assertIdentical($this->CakeEmail->subject(), 'Array');
$this->assertIdentical($this->CakeEmail, $result);
$this->CakeEmail->subject('هذه رسالة بعنوان طويل مرسل للمستلم');
$expected = '=?UTF-8?B?2YfYsNmHINix2LPYp9mE2Kkg2KjYudmG2YjYp9mGINi32YjZitmEINmF2LE=?=' . "\r\n" . ' =?UTF-8?B?2LPZhCDZhNmE2YXYs9iq2YTZhQ==?=';
$this->assertIdentical($this->CakeEmail->subject(), $expected);
}
/**
* testHeaders method
*
* @return void
*/
public function testHeaders() {
$this->CakeEmail->messageId(false);
$this->CakeEmail->setHeaders(array('X-Something' => 'nice'));
$expected = array(
'X-Something' => 'nice',
'X-Mailer' => 'CakePHP Email',
'Date' => date(DATE_RFC2822),
'MIME-Version' => '1.0',
'Content-Type' => 'text/plain; charset=UTF-8',
'Content-Transfer-Encoding' => '7bit'
);
$this->assertIdentical($this->CakeEmail->getHeaders(), $expected);
$this->CakeEmail->addHeaders(array('X-Something' => 'very nice', 'X-Other' => 'cool'));
$expected = array(
'X-Something' => 'very nice',
'X-Other' => 'cool',
'X-Mailer' => 'CakePHP Email',
'Date' => date(DATE_RFC2822),
'MIME-Version' => '1.0',
'Content-Type' => 'text/plain; charset=UTF-8',
'Content-Transfer-Encoding' => '7bit'
);
$this->assertIdentical($this->CakeEmail->getHeaders(), $expected);
$this->CakeEmail->from('cake@cakephp.org');
$this->assertIdentical($this->CakeEmail->getHeaders(), $expected);
$expected = array(
'From' => 'cake@cakephp.org',
'X-Something' => 'very nice',
'X-Other' => 'cool',
'X-Mailer' => 'CakePHP Email',
'Date' => date(DATE_RFC2822),
'MIME-Version' => '1.0',
'Content-Type' => 'text/plain; charset=UTF-8',
'Content-Transfer-Encoding' => '7bit'
);
$this->assertIdentical($this->CakeEmail->getHeaders(array('from' => true)), $expected);
$this->CakeEmail->from('cake@cakephp.org', 'CakePHP');
$expected['From'] = 'CakePHP <cake@cakephp.org>';
$this->assertIdentical($this->CakeEmail->getHeaders(array('from' => true)), $expected);
$this->CakeEmail->to(array('cake@cakephp.org', 'php@cakephp.org' => 'CakePHP'));
$expected = array(
'From' => 'CakePHP <cake@cakephp.org>',
'To' => 'cake@cakephp.org, CakePHP <php@cakephp.org>',
'X-Something' => 'very nice',
'X-Other' => 'cool',
'X-Mailer' => 'CakePHP Email',
'Date' => date(DATE_RFC2822),
'MIME-Version' => '1.0',
'Content-Type' => 'text/plain; charset=UTF-8',
'Content-Transfer-Encoding' => '7bit'
);
$this->assertIdentical($this->CakeEmail->getHeaders(array('from' => true, 'to' => true)), $expected);
}
/**
* testTemplate method
*
* @return void
*/
public function testTemplate() {
$this->CakeEmail->template('template', 'layout');
$expected = array('template' => 'template', 'layout' => 'layout');
$this->assertIdentical($this->CakeEmail->template(), $expected);
$this->CakeEmail->template('new_template');
$expected = array('template' => 'new_template', 'layout' => 'layout');
$this->assertIdentical($this->CakeEmail->template(), $expected);
$this->CakeEmail->template('template', null);
$expected = array('template' => 'template', 'layout' => null);
$this->assertIdentical($this->CakeEmail->template(), $expected);
$this->CakeEmail->template(null, null);
$expected = array('template' => null, 'layout' => null);
$this->assertIdentical($this->CakeEmail->template(), $expected);
}
/**
* testViewVars method
*
* @return void
*/
public function testViewVars() {
$this->assertIdentical($this->CakeEmail->viewVars(), array());
$this->CakeEmail->viewVars(array('value' => 12345));
$this->assertIdentical($this->CakeEmail->viewVars(), array('value' => 12345));
$this->CakeEmail->viewVars(array('name' => 'CakePHP'));
$this->assertIdentical($this->CakeEmail->viewVars(), array('value' => 12345, 'name' => 'CakePHP'));
$this->CakeEmail->viewVars(array('value' => 4567));
$this->assertIdentical($this->CakeEmail->viewVars(), array('value' => 4567, 'name' => 'CakePHP'));
}
/**
* testAttachments method
*
* @return void
*/
public function testAttachments() {
$this->CakeEmail->attachments(CAKE . 'basics.php');
$expected = array('basics.php' => array('file' => CAKE . 'basics.php', 'mimetype' => 'application/octet-stream'));
$this->assertIdentical($this->CakeEmail->attachments(), $expected);
$this->CakeEmail->attachments(array());
$this->assertIdentical($this->CakeEmail->attachments(), array());
$this->CakeEmail->attachments(array(array('file' => CAKE . 'basics.php', 'mimetype' => 'text/plain')));
$this->CakeEmail->addAttachments(CAKE . 'bootstrap.php');
$this->CakeEmail->addAttachments(array(CAKE . 'bootstrap.php'));
$this->CakeEmail->addAttachments(array('other.txt' => CAKE . 'bootstrap.php', 'license' => CAKE . 'LICENSE.txt'));
$expected = array(
'basics.php' => array('file' => CAKE . 'basics.php', 'mimetype' => 'text/plain'),
'bootstrap.php' => array('file' => CAKE . 'bootstrap.php', 'mimetype' => 'application/octet-stream'),
'other.txt' => array('file' => CAKE . 'bootstrap.php', 'mimetype' => 'application/octet-stream'),
'license' => array('file' => CAKE . 'LICENSE.txt', 'mimetype' => 'application/octet-stream')
);
$this->assertIdentical($this->CakeEmail->attachments(), $expected);
}
/**
* testTransport method
*
* @return void
*/
public function testTransport() {
$result = $this->CakeEmail->transport('debug');
$this->assertIdentical($this->CakeEmail, $result);
$this->assertIdentical($this->CakeEmail->transport(), 'debug');
$result = $this->CakeEmail->transportClass();
$this->assertIsA($result, 'DebugTransport');
}
/**
* testConfig method
*
* @return void
*/
public function testConfig() {
$this->CakeEmail->transport('debug')->transportClass();
DebugTransport::$config = array();
$config = array('test' => 'ok', 'test2' => true);
$this->CakeEmail->config($config);
$this->assertIdentical(DebugTransport::$config, $config);
$this->assertIdentical($this->CakeEmail->config(), $config);
$this->CakeEmail->config(array());
$this->assertIdentical(DebugTransport::$config, array());
}
/**
* testSendWithContent method
*
* @return void
*/
public function testSendWithContent() {
$this->CakeEmail->reset();
$this->CakeEmail->transport('debug');
DebugTransport::$includeAddresses = false;
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->config(array('empty'));
$result = $this->CakeEmail->send("Here is my body, with multi lines.\nThis is the second line.\r\n\r\nAnd the last.");
$this->assertTrue($result);
$expected = "Here is my body, with multi lines.\r\nThis is the second line.\r\n\r\nAnd the last.\r\n\r\n";
$this->assertIdentical(DebugTransport::$lastEmail, $expected);
$this->assertTrue((bool)strpos(DebugTransport::$lastHeader, 'Date: '));
$this->assertTrue((bool)strpos(DebugTransport::$lastHeader, 'Message-ID: '));
$this->assertFalse(strpos(DebugTransport::$lastHeader, 'To: '));
DebugTransport::$includeAddresses = true;
$this->CakeEmail->send("Other body");
$this->assertIdentical(DebugTransport::$lastEmail, "Other body\r\n\r\n");
$this->assertTrue((bool)strpos(DebugTransport::$lastHeader, 'Message-ID: '));
$this->assertTrue((bool)strpos(DebugTransport::$lastHeader, 'To: '));
}
/**
* testSendRender method
*
* @return void
*/
public function testSendRender() {
$this->CakeEmail->reset();
$this->CakeEmail->transport('debug');
DebugTransport::$includeAddresses = true;
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->config(array('empty'));
$this->CakeEmail->template('default', 'default');
$result = $this->CakeEmail->send();
$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, 'This email was sent using the CakePHP Framework'));
$this->assertTrue((bool)strpos(DebugTransport::$lastHeader, 'Message-ID: '));
$this->assertTrue((bool)strpos(DebugTransport::$lastHeader, 'To: '));
}
/**
* testSendRenderWithVars method
*
* @return void
*/
public function testSendRenderWithVars() {
$this->CakeEmail->reset();
$this->CakeEmail->transport('debug');
DebugTransport::$includeAddresses = true;
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->config(array('empty'));
$this->CakeEmail->template('custom', 'default');
$this->CakeEmail->viewVars(array('value' => 12345));
$result = $this->CakeEmail->send();
$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, 'Here is your value: 12345'));
}
/**
* testSendMultipleMIME method
*
* @return void
*/
public function testSendMultipleMIME() {
$this->CakeEmail->reset();
$this->CakeEmail->transport('debug');
DebugTransport::$includeAddresses = true;
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->template('custom', 'default');
$this->CakeEmail->config(array());
$this->CakeEmail->viewVars(array('value' => 12345));
$this->CakeEmail->emailFormat('both');
$result = $this->CakeEmail->send();
$message = $this->CakeEmail->message();
$boundary = $this->CakeEmail->getBoundary();
$this->assertFalse(empty($boundary));
$this->assertFalse(in_array('--' . $boundary, $message));
$this->assertFalse(in_array('--' . $boundary . '--', $message));
$this->assertTrue(in_array('--alt-' . $boundary, $message));
$this->assertTrue(in_array('--alt-' . $boundary . '--', $message));
$this->CakeEmail->attachments(array('fake.php' => __FILE__));
$this->CakeEmail->send();
$message = $this->CakeEmail->message();
$boundary = $this->CakeEmail->getBoundary();
$this->assertFalse(empty($boundary));
$this->assertTrue(in_array('--' . $boundary, $message));
$this->assertTrue(in_array('--' . $boundary . '--', $message));
$this->assertTrue(in_array('--alt-' . $boundary, $message));
$this->assertTrue(in_array('--alt-' . $boundary . '--', $message));
}
/**
* testSendAttachment method
*
* @return void
*/
public function testSendAttachment() {
$this->CakeEmail->reset();
$this->CakeEmail->transport('debug');
DebugTransport::$includeAddresses = false;
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->config(array());
$this->CakeEmail->attachments(array(CAKE . 'basics.php'));
$this->CakeEmail->send('body');
$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, "Content-Type: application/octet-stream\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename=\"basics.php\""));
$this->CakeEmail->attachments(array('my.file.txt' => CAKE . 'basics.php'));
$this->CakeEmail->send('body');
$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, "Content-Type: application/octet-stream\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename=\"my.file.txt\""));
$this->CakeEmail->attachments(array('file.txt' => array('file' => CAKE . 'basics.php', 'mimetype' => 'text/plain')));
$this->CakeEmail->send('body');
$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, "Content-Type: text/plain\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename=\"file.txt\""));
$this->CakeEmail->attachments(array('file.txt' => array('file' => CAKE . 'basics.php', 'mimetype' => 'text/plain', 'contentId' => 'a1b1c1')));
$this->CakeEmail->send('body');
$this->assertTrue((bool)strpos(DebugTransport::$lastEmail, "Content-Type: text/plain\r\nContent-Transfer-Encoding: base64\r\nContent-ID: <a1b1c1>\r\nContent-Disposition: inline; filename=\"file.txt\""));
}
/**
* testDeliver method
*
* @return void
*/
public function testDeliver() {
$instance = CakeEmail::deliver('all@cakephp.org', 'About', 'Everything ok', array('from' => 'root@cakephp.org'), false);
$this->assertIsA($instance, 'CakeEmail');
$this->assertIdentical($instance->to(), array('all@cakephp.org' => 'all@cakephp.org'));
$this->assertIdentical($instance->subject(), 'About');
$this->assertIdentical($instance->from(), array('root@cakephp.org' => 'root@cakephp.org'));
$config = array(
'from' => 'cake@cakephp.org',
'to' => 'debug@cakephp.org',
'subject' => 'Update ok',
'template' => 'custom',
'layout' => 'custom_layout',
'viewVars' => array('value' => 123),
'cc' => array('cake@cakephp.org' => 'Myself')
);
$instance = CakeEmail::deliver(null, null, array('name' => 'CakePHP'), $config, false);
$this->assertIdentical($instance->from(), array('cake@cakephp.org' => 'cake@cakephp.org'));
$this->assertIdentical($instance->to(), array('debug@cakephp.org' => 'debug@cakephp.org'));
$this->assertIdentical($instance->subject(), 'Update ok');
$this->assertIdentical($instance->template(), array('template' => 'custom', 'layout' => 'custom_layout'));
$this->assertIdentical($instance->viewVars(), array('value' => 123, 'name' => 'CakePHP'));
$this->assertIdentical($instance->cc(), array('cake@cakephp.org' => 'Myself'));
}
/**
* testMessage method
*
* @return void
*/
public function testMessage() {
$this->CakeEmail->reset();
$this->CakeEmail->transport('debug');
DebugTransport::$includeAddresses = true;
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->config(array('empty'));
$this->CakeEmail->template('default', 'default');
$this->CakeEmail->emailFormat('both');
$result = $this->CakeEmail->send();
$expected = '<p>This email was sent using the <a href="http://cakephp.org">CakePHP Framework</a></p>';
$this->assertTrue((bool)strpos($this->CakeEmail->message(CakeEmail::MESSAGE_HTML), $expected));
$expected = 'This email was sent using the CakePHP Framework, http://cakephp.org.';
$this->assertTrue((bool)strpos($this->CakeEmail->message(CakeEmail::MESSAGE_TEXT), $expected));
$message = $this->CakeEmail->message();
$this->assertTrue(in_array('Content-Type: text/plain; charset=UTF-8', $message));
$this->assertTrue(in_array('Content-Type: text/html; charset=UTF-8', $message));
}
/**
* testReset method
*
* @return void
*/
public function testReset() {
$this->CakeEmail->to('cake@cakephp.org');
$this->assertIdentical($this->CakeEmail->to(), array('cake@cakephp.org' => 'cake@cakephp.org'));
$this->CakeEmail->reset();
$this->assertIdentical($this->CakeEmail->to(), array());
}
/**
* testWrap method
*
* @return void
*/
public function testWrap() {
$text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac turpis orci, non commodo odio. Morbi nibh nisi, vehicula pellentesque accumsan amet.';
$result = $this->CakeEmail->wrap($text);
$expected = array(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac turpis orci,',
'non commodo odio. Morbi nibh nisi, vehicula pellentesque accumsan amet.',
''
);
$this->assertIdentical($result, $expected);
$text = 'Lorem ipsum dolor sit amet, consectetur < adipiscing elit. Donec ac turpis orci, non commodo odio. Morbi nibh nisi, vehicula > pellentesque accumsan amet.';
$result = $this->CakeEmail->wrap($text);
$expected = array(
'Lorem ipsum dolor sit amet, consectetur < adipiscing elit. Donec ac turpis',
'orci, non commodo odio. Morbi nibh nisi, vehicula > pellentesque accumsan',
'amet.',
''
);
$this->assertIdentical($result, $expected);
$text = '<p>Lorem ipsum dolor sit amet,<br> consectetur adipiscing elit.<br> Donec ac turpis orci, non <b>commodo</b> odio. <br /> Morbi nibh nisi, vehicula pellentesque accumsan amet.<hr></p>';
$result = $this->CakeEmail->wrap($text);
$expected = array(
'<p>Lorem ipsum dolor sit amet,<br> consectetur adipiscing elit.<br> Donec ac',
'turpis orci, non <b>commodo</b> odio. <br /> Morbi nibh nisi, vehicula',
'pellentesque accumsan amet.<hr></p>',
''
);
$this->assertIdentical($result, $expected);
$text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac <a href="http://cakephp.org">turpis</a> orci, non commodo odio. Morbi nibh nisi, vehicula pellentesque accumsan amet.';
$result = $this->CakeEmail->wrap($text);
$expected = array(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac',
'<a href="http://cakephp.org">turpis</a> orci, non commodo odio. Morbi nibh',
'nisi, vehicula pellentesque accumsan amet.',
''
);
$this->assertIdentical($result, $expected);
$text = 'Lorem ipsum <a href="http://www.cakephp.org/controller/action/param1/param2" class="nice cool fine amazing awesome">ok</a>';
$result = $this->CakeEmail->wrap($text);
$expected = array(
'Lorem ipsum',
'<a href="http://www.cakephp.org/controller/action/param1/param2" class="nice cool fine amazing awesome">',
'ok</a>',
''
);
$this->assertIdentical($result, $expected);
$text = 'Lorem ipsum withonewordverybigMorethanthelineshouldsizeofrfcspecificationbyieeeavailableonieeesite ok.';
$result = $this->CakeEmail->wrap($text);
$expected = array(
'Lorem ipsum',
'withonewordverybigMorethanthelineshouldsizeofrfcspecificationbyieeeavailableonieeesite',
'ok.',
''
);
$this->assertIdentical($result, $expected);
}
}

View file

@ -170,17 +170,26 @@ class CakeSocketTest extends CakeTestCase {
$this->Socket->connect();
$this->assertEqual($this->Socket->read(26), null);
$config = array('host' => '127.0.0.1', 'timeout' => 0.5);
$this->Socket = new CakeSocket($config);
$this->assertTrue($this->Socket->connect());
$this->assertFalse($this->Socket->read(1024 * 1024));
$this->assertEqual($this->Socket->lastError(), '2: ' . __d('cake_dev', 'Connection timed out'));
$config = array('host' => 'cakephp.org', 'port' => 80, 'timeout' => 20);
$config = array('host' => 'google.com', 'port' => 80, 'timeout' => 1);
$this->Socket = new CakeSocket($config);
$this->assertTrue($this->Socket->connect());
$this->assertEqual($this->Socket->read(26), null);
$this->assertEqual($this->Socket->lastError(), null);
$this->assertEqual($this->Socket->lastError(), '2: ' . __d('cake_dev', 'Connection timed out'));
}
/**
* testTimeOutConnection method
*
* @return void
*/
function testTimeOutConnection() {
$config = array('host' => '127.0.0.1', 'timeout' => 0.5);
$this->Socket = new CakeSocket($config);
$this->assertTrue($this->Socket->connect());
$config = array('host' => '127.0.0.1', 'timeout' => 0.00001);
$this->assertFalse($this->Socket->read(1024 * 1024));
$this->assertEqual($this->Socket->lastError(), '2: ' . __d('cake_dev', 'Connection timed out'));
}
/**

View file

@ -0,0 +1,261 @@
<?php
/**
* SmtpTransportTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package cake.tests.cases.libs.email
* @since CakePHP(tm) v 2.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('CakeEmail', 'Network');
App::uses('AbstractTransport', 'Network/Email');
App::uses('SmtpTransport', 'Network/Email');
/**
* Help to test SmtpTransport
*
*/
class SmtpTestTransport extends SmtpTransport {
/**
* Helper to change the socket
*
* @param object $socket
* @return void
*/
public function setSocket(CakeSocket $socket) {
$this->_socket = $socket;
}
/**
* Helper to change the CakeEmail
*
* @param object $cakeEmail
* @return void
*/
public function setCakeEmail($cakeEmail) {
$this->_cakeEmail = $cakeEmail;
}
/**
* Disabled the socket change
*
* @return void
*/
protected function _generateSocket() {
return;
}
/**
* Magic function to call protected methods
*
* @param string $method
* @param string $args
* @return mixed
*/
public function __call($method, $args) {
$method = '_' . $method;
return $this->$method();
}
}
/**
* Test case
*
*/
class StmpProtocolTest extends CakeTestCase {
/**
* Setup
*
* @return void
*/
public function setUp() {
if (!class_exists('MockSocket')) {
$this->getMock('CakeSocket', array('read', 'write', 'connect'), array(), 'MockSocket');
}
$this->socket = new MockSocket();
$this->SmtpTransport = new SmtpTestTransport();
$this->SmtpTransport->setSocket($this->socket);
$this->SmtpTransport->config();
}
/**
* testConnectEhlo method
*
* @return void
*/
public function testConnectEhlo() {
$this->socket->expects($this->any())->method('connect')->will($this->returnValue(true));
$this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n"));
$this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n");
$this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(4))->method('read')->will($this->returnValue("250 Accepted\r\n"));
$this->SmtpTransport->connect();
}
/**
* testConnectHelo method
*
* @return void
*/
public function testConnectHelo() {
$this->socket->expects($this->any())->method('connect')->will($this->returnValue(true));
$this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n"));
$this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n");
$this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(4))->method('read')->will($this->returnValue("200 Not Accepted\r\n"));
$this->socket->expects($this->at(5))->method('write')->with("HELO localhost\r\n");
$this->socket->expects($this->at(6))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(7))->method('read')->will($this->returnValue("250 Accepted\r\n"));
$this->SmtpTransport->connect();
}
/**
* testConnectFail method
*
* @expectedException Exception
* @return void
*/
public function testConnetFail() {
$this->socket->expects($this->any())->method('connect')->will($this->returnValue(true));
$this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n"));
$this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n");
$this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(4))->method('read')->will($this->returnValue("200 Not Accepted\r\n"));
$this->socket->expects($this->at(5))->method('write')->with("HELO localhost\r\n");
$this->socket->expects($this->at(6))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(7))->method('read')->will($this->returnValue("200 Not Accepted\r\n"));
$this->SmtpTransport->connect();
}
/**
* testAuth method
*
* @return void
*/
public function testAuth() {
$this->socket->expects($this->at(0))->method('write')->with("AUTH LOGIN\r\n");
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(2))->method('read')->will($this->returnValue("334 Login\r\n"));
$this->socket->expects($this->at(3))->method('write')->with("bWFyaw==\r\n");
$this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(5))->method('read')->will($this->returnValue("334 Pass\r\n"));
$this->socket->expects($this->at(6))->method('write')->with("c3Rvcnk=\r\n");
$this->socket->expects($this->at(7))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(8))->method('read')->will($this->returnValue("235 OK\r\n"));
$this->SmtpTransport->config(array('username' => 'mark', 'password' => 'story'));
$this->SmtpTransport->auth();
}
/**
* testAuthNoAuth method
*
* @return void
*/
public function testAuthNoAuth() {
$this->socket->expects($this->never())->method('write')->with("AUTH LOGIN\r\n");
$this->SmtpTransport->config(array('username' => null, 'password' => null));
$this->SmtpTransport->auth();
}
/**
* testRcpt method
*
* @return void
*/
public function testRcpt() {
$email = new CakeEmail();
$email->from('noreply@cakephp.org', 'CakePHP Test');
$email->to('cake@cakephp.org', 'CakePHP');
$email->bcc('phpnut@cakephp.org');
$email->cc(array('mark@cakephp.org' => 'Mark Story', 'juan@cakephp.org' => 'Juan Basso'));
$this->socket->expects($this->at(0))->method('write')->with("MAIL FROM:<noreply@cakephp.org>\r\n");
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(2))->method('read')->will($this->returnValue("250 OK\r\n"));
$this->socket->expects($this->at(3))->method('write')->with("RCPT TO:<cake@cakephp.org>\r\n");
$this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250 OK\r\n"));
$this->socket->expects($this->at(6))->method('write')->with("RCPT TO:<mark@cakephp.org>\r\n");
$this->socket->expects($this->at(7))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(8))->method('read')->will($this->returnValue("250 OK\r\n"));
$this->socket->expects($this->at(9))->method('write')->with("RCPT TO:<juan@cakephp.org>\r\n");
$this->socket->expects($this->at(10))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(11))->method('read')->will($this->returnValue("250 OK\r\n"));
$this->socket->expects($this->at(12))->method('write')->with("RCPT TO:<phpnut@cakephp.org>\r\n");
$this->socket->expects($this->at(13))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(14))->method('read')->will($this->returnValue("250 OK\r\n"));
$this->SmtpTransport->setCakeEmail($email);
$this->SmtpTransport->sendRcpt();
}
/**
* testSendData method
*
* @return void
*/
public function testSendData() {
$this->getMock('CakeEmail', array('message'), array(), 'TestCakeEmail');
$email = new TestCakeEmail();
$email->from('noreply@cakephp.org', 'CakePHP Test');
$email->to('cake@cakephp.org', 'CakePHP');
$email->cc(array('mark@cakephp.org' => 'Mark Story', 'juan@cakephp.org' => 'Juan Basso'));
$email->bcc('phpnut@cakephp.org');
$email->messageID('<4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>');
$email->subject('Testing SMTP');
$email->expects($this->any())->method('message')->will($this->returnValue(array('First Line', 'Second Line', '')));
$data = "From: CakePHP Test <noreply@cakephp.org>\r\n";
$data .= "To: CakePHP <cake@cakephp.org>\r\n";
$data .= "Cc: Mark Story <mark@cakephp.org>, Juan Basso <juan@cakephp.org>\r\n";
$data .= "Bcc: phpnut@cakephp.org\r\n";
$data .= "X-Mailer: CakePHP Email Component\r\n";
$data .= "Date: " . date(DATE_RFC2822) . "\r\n";
$data .= "Message-ID: <4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>\r\n";
$data .= "Subject: Testing SMTP\r\n";
$data .= "Content-Type: text/plain; charset=UTF-8\r\n";
$data .= "Content-Transfer-Encoding: 7bit\r\n";
$data .= "\r\n";
$data .= "First Line\r\n";
$data .= "Second Line\r\n";
$data .= "\r\n";
$data .= "\r\n\r\n.\r\n";
$this->socket->expects($this->at(0))->method('write')->with("DATA\r\n");
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(2))->method('read')->will($this->returnValue("354 OK\r\n"));
$this->socket->expects($this->at(3))->method('write')->with($data);
$this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250 OK\r\n"));
$this->SmtpTransport->setCakeEmail($email);
$this->SmtpTransport->sendData();
}
/**
* testQuit method
*
* @return void
*/
public function testQuit() {
$this->socket->expects($this->at(0))->method('write')->with("QUIT\r\n");
$this->SmtpTransport->disconnect();
}
}

View file

@ -17,6 +17,7 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('File', 'Utility');
App::uses('Folder', 'Utility');
/**
* FileTest class
@ -487,4 +488,4 @@ class FileTest extends CakeTestCase {
}
return false;
}
}
}

Some files were not shown because too many files have changed in this diff Show more