Merge branch '1.3' of code.cakephp.org:cakephp into 1.3

This commit is contained in:
phpnut 2009-11-03 22:03:09 -06:00
commit 2bf630f209
68 changed files with 1435 additions and 790 deletions

View file

@ -81,6 +81,8 @@ class BakeShell extends Shell {
if (!is_dir($this->DbConfig->path)) {
if ($this->Project->execute()) {
$this->DbConfig->path = $this->params['working'] . DS . 'config' . DS;
} else {
return false;
}
}

View file

@ -45,6 +45,14 @@ class ExtractTask extends Shell {
*/
var $__files = array();
/**
* Merge all domains string into the default.pot file
*
* @var boolean
* @access public
*/
var $__merge = false;
/**
* Current file being processed
*
@ -137,6 +145,14 @@ class ExtractTask extends Shell {
}
}
if (isset($this->params['merge'])) {
$this->__merge = !(strtolower($this->params['merge']) === 'no');
} else {
$this->out();
$response = $this->in(sprintf(__('Would you like to merge all domains strings into the default.pot file?', true)), array('y', 'n'), 'n');
$this->__merge = strtolower($response) === 'y';
}
if (empty($this->__files)) {
$this->__searchFiles();
}
@ -176,15 +192,18 @@ class ExtractTask extends Shell {
$this->out(__('By default the .pot file(s) will be place in the locale directory of -app', true));
$this->out(__('By default -app is ROOT/app', true));
$this->hr();
$this->out(__('Usage: cake i18n extract [command] [path...]', true));
$this->out(__('Usage: cake i18n extract <command> <param1> <param2>...', true));
$this->out();
$this->out(__('Commands:', true));
$this->out(__('Params:', true));
$this->out(__(' -app [path...]: directory where your application is located', true));
$this->out(__(' -root [path...]: path to install', true));
$this->out(__(' -core [path...]: path to cake directory', true));
$this->out(__(' -paths [comma separated list of paths, full path is needed]', true));
$this->out(__(' -merge [yes|no]: Merge all domains strings into the default.pot file', true));
$this->out(__(' -output [path...]: Full path to output directory', true));
$this->out(__(' -files: [comma separated list of files, full path to file is needed]', true));
$this->out();
$this->out(__('Commands:', true));
$this->out(__(' cake i18n extract help: Shows this help message.', true));
$this->out();
}
@ -322,7 +341,7 @@ class ExtractTask extends Shell {
}
$this->__store($domain, $header, $sentence);
if ($domain != 'default') {
if ($domain != 'default' && $this->__merge) {
$this->__store('default', $header, $sentence);
}
}

View file

@ -73,9 +73,6 @@ class FixtureTask extends Shell {
function __construct(&$dispatch) {
parent::__construct($dispatch);
$this->path = $this->params['working'] . DS . 'tests' . DS . 'fixtures' . DS;
if (!class_exists('CakeSchema')) {
App::import('Model', 'CakeSchema', false);
}
}
/**
@ -85,6 +82,10 @@ class FixtureTask extends Shell {
* @access public
*/
function execute() {
if (!class_exists('CakeSchema')) {
App::import('Model', 'CakeSchema', false);
}
if (empty($this->args)) {
$this->__interactive();
}

View file

@ -0,0 +1,2 @@
<?php echo $xml->header(); ?>
<?php echo $content_for_layout; ?>

View file

@ -55,7 +55,7 @@
<?php echo $html->link(
$html->image('cake.power.gif', array('alt'=>__("CakePHP: the rapid development php framework", true), 'border'=>"0")),
'http://www.cakephp.org/',
array('target'=>'_blank', 'escape'=>false), null
array('target' => '_blank', 'escape' => false)
);
?>
</div>

View file

@ -641,15 +641,15 @@ class CakeSession extends Object {
function __regenerateId() {
$oldSessionId = session_id();
if ($oldSessionId) {
$sessionpath = session_save_path();
if (empty($sessionpath)) {
$sessionpath = "/tmp";
}
if (session_id() != "" || isset($_COOKIE[session_name()])) {
if (session_id() != ''|| isset($_COOKIE[session_name()])) {
setcookie(Configure::read('Session.cookie'), '', time() - 42000, $this->path);
}
session_regenerate_id(true);
if (PHP_VERSION < 5.1) {
$sessionPath = session_save_path();
if (empty($sessionPath)) {
$sessionPath = '/tmp';
}
$newSessid = session_id();
if (function_exists('session_write_close')) {
@ -659,7 +659,7 @@ class CakeSession extends Object {
session_id($oldSessionId);
session_start();
session_destroy();
$file = $sessionpath . DS . "sess_$oldSessionId";
$file = $sessionPath . DS . 'sess_' . $oldSessionId;
@unlink($file);
$this->__initSession();
session_id($newSessid);

View file

@ -450,10 +450,10 @@ class AuthComponent extends Object {
return false;
}
$defaults = array(
'loginAction' => Router::normalize(array(
'controller'=> Inflector::underscore(Inflector::pluralize($this->userModel)),
'loginAction' => array(
'controller' => Inflector::underscore(Inflector::pluralize($this->userModel)),
'action' => 'login'
)),
),
'sessionKey' => 'Auth.' . $this->userModel,
'logoutRedirect' => $this->loginAction,
'loginError' => __('Login failed. Invalid username or password.', true),

View file

@ -74,6 +74,9 @@ class Controller extends Object {
*
* Example: var $uses = array('Product', 'Post', 'Comment');
*
* Can be set to array() to use no models. Can be set to false to
* use no models and prevent the merging of $uses with AppController
*
* @var mixed A single name as a string or a list of names as an array.
* @access protected
* @link http://book.cakephp.org/view/53/components-helpers-and-uses

View file

@ -434,10 +434,7 @@ class Scaffold extends Object {
/**
* When methods are now present in a controller
* scaffoldView is used to call default Scaffold methods if:
* <code>
* var $scaffold;
* </code>
* is placed in the controller's class definition.
* `var $scaffold;` is placed in the controller's class definition.
*
* @param array $params Parameters for scaffolding
* @return mixed A rendered view of scaffold action, or showing the error
@ -445,43 +442,44 @@ class Scaffold extends Object {
*/
function __scaffold($params) {
$db = &ConnectionManager::getDataSource($this->ScaffoldModel->useDbConfig);
$admin = Configure::read('Routing.admin');
$prefixes = Configure::read('Routing.prefixes');
$scaffoldPrefix = $this->scaffoldActions;
if (isset($db)) {
if (empty($this->scaffoldActions)) {
$this->scaffoldActions = array(
'index', 'list', 'view', 'add', 'create', 'edit', 'update', 'delete'
);
} elseif (!empty($admin) && $this->scaffoldActions === $admin) {
} elseif (!empty($prefixes) && in_array($scaffoldPrefix, $prefixes)) {
$this->scaffoldActions = array(
$admin .'_index', $admin .'_list', $admin .'_view', $admin .'_add',
$admin .'_create', $admin .'_edit', $admin .'_update', $admin .'_delete'
$scaffoldPrefix . '_index',
$scaffoldPrefix . '_list',
$scaffoldPrefix . '_view',
$scaffoldPrefix . '_add',
$scaffoldPrefix . '_create',
$scaffoldPrefix . '_edit',
$scaffoldPrefix . '_update',
$scaffoldPrefix . '_delete'
);
}
if (in_array($params['action'], $this->scaffoldActions)) {
if (!empty($admin)) {
$params['action'] = str_replace($admin . '_', '', $params['action']);
if (!empty($prefixes)) {
$params['action'] = str_replace($scaffoldPrefix . '_', '', $params['action']);
}
switch ($params['action']) {
case 'index':
case 'list':
$this->__scaffoldIndex($params);
break;
case 'view':
$this->__scaffoldView($params);
break;
case 'list':
$this->__scaffoldIndex($params);
break;
case 'add':
$this->__scaffoldSave($params, 'add');
break;
case 'edit':
$this->__scaffoldSave($params, 'edit');
break;
case 'create':
$this->__scaffoldSave($params, 'add');
break;
case 'edit':
case 'update':
$this->__scaffoldSave($params, 'edit');
break;
@ -556,10 +554,15 @@ class ScaffoldView extends ThemeView {
$name = $this->action;
}
$name = Inflector::underscore($name);
$admin = Configure::read('Routing.admin');
$prefixes = Configure::read('Routing.prefixes');
if (!empty($admin) && strpos($name, $admin . '_') !== false) {
$name = substr($name, strlen($admin) + 1);
if (!empty($prefixes)) {
foreach ($prefixes as $prefix) {
if (strpos($name, $prefix . '_') !== false) {
$name = substr($name, strlen($prefix) + 1);
break;
}
}
}
if ($name === 'add') {

View file

@ -229,16 +229,8 @@ class Debugger extends Object {
*/
function log($var, $level = LOG_DEBUG) {
$_this = Debugger::getInstance();
$trace = $_this->trace(array('start' => 1, 'depth' => 2, 'format' => 'array'));
$source = null;
if (is_object($trace[0]['object']) && isset($trace[0]['object']->_reporter->_test_stack)) {
$stack = $trace[0]['object']->_reporter->_test_stack;
$source = sprintf('[%1$s, %3$s::%2$s()]' . "\n",
array_shift($stack), array_pop($stack), array_pop($stack));
}
CakeLog::write($level, $source . $_this->exportVar($var));
$source = $_this->trace(array('start' => 1)) . "\n";
CakeLog::write($level, "\n" . $source . $_this->exportVar($var));
}
/**

View file

@ -326,7 +326,7 @@ class Folder extends Object {
* @static
*/
function addPathElement($path, $element) {
return Folder::slashTerm($path) . $element;
return rtrim($path, DS) . DS . $element;
}
/**

View file

@ -693,7 +693,7 @@ class HttpSocket extends CakeSocket {
foreach ($items as $item) {
if (strpos($item, '=') !== false) {
list($key, $value) = explode('=', $item);
list($key, $value) = explode('=', $item, 2);
} else {
$key = $item;
$value = null;

View file

@ -474,7 +474,7 @@ class TreeBehavior extends ModelBehavior {
'fields' => array($Model->primaryKey, $left, $right), 'recursive' => $recursive)
);
if ($nextNode) {
list($nextNode)= array_values($nextNode);
list($nextNode) = array_values($nextNode);
} else {
return false;
}
@ -657,6 +657,8 @@ class TreeBehavior extends ModelBehavior {
$sort = $field . ' ' . $order;
$nodes = $this->children($Model, $id, true, $fields, $sort, null, null, $recursive);
$cacheQueries = $Model->cacheQueries;
$Model->cacheQueries = false;
if ($nodes) {
foreach ($nodes as $node) {
$id = $node[$Model->alias][$Model->primaryKey];
@ -666,6 +668,7 @@ class TreeBehavior extends ModelBehavior {
}
}
}
$Model->cacheQueries = $cacheQueries;
return true;
}

View file

@ -320,45 +320,53 @@ class DataSource extends Object {
}
/**
* Used to create new records. The "C" CRUD.
*
* To-be-overridden in subclasses.
*
* @param unknown_type $model
* @param unknown_type $fields
* @param unknown_type $values
* @return unknown
* @param Model $model The Model to be created.
* @param array $fields An Array of fields to be saved.
* @param array $values An Array of values to save.
* @return boolean success
*/
function create(&$model, $fields = null, $values = null) {
return false;
}
/**
* Used to read records from the Datasource. The "R" in CRUD
*
* To-be-overridden in subclasses.
*
* @param unknown_type $model
* @param unknown_type $queryData
* @return unknown
* @param Model $model The model being read.
* @param array $queryData An array of query data used to find the data you want
* @return mixed
*/
function read(&$model, $queryData = array()) {
return false;
}
/**
* Update a record(s) in the datasource.
*
* To-be-overridden in subclasses.
*
* @param unknown_type $model
* @param unknown_type $fields
* @param unknown_type $values
* @return unknown
* @param Model $model Instance of the model class being updated
* @param array $fields Array of fields to be updated
* @param array $values Array of values to be update $fields to.
* @return boolean Success
*/
function update(&$model, $fields = null, $values = null) {
return false;
}
/**
* Delete a record(s) in the datasource.
*
* To-be-overridden in subclasses.
*
* @param unknown_type $model
* @param unknown_type $id
* @param Model $model The model class having record(s) deleted
* @param mixed $id Primary key of the model
*/
function delete(&$model, $id = null) {
if ($id == null) {
@ -396,6 +404,16 @@ class DataSource extends Object {
return false;
}
/**
* Check whether the conditions for the Datasource being available
* are satisfied. Often used from connect() to check for support
* before establishing a connection.
*
* @return boolean Whether or not the Datasources conditions for use are met.
**/
function enabled() {
return true;
}
/**
* Returns true if the DataSource supports the given interface (method)
*

View file

@ -110,7 +110,9 @@ class DboAdodb extends DboSource {
$adodb_driver = substr($config['connect'], 0, $persistent);
$connect = 'PConnect';
}
if (!$this->enabled()) {
return false;
}
$this->_adodb = NewADOConnection($adodb_driver);
$this->_adodbDataDict = NewDataDictionary($this->_adodb, $adodb_driver);
@ -123,6 +125,14 @@ class DboAdodb extends DboSource {
return $this->connected;
}
/**
* Check that AdoDB is available.
*
* @return boolean
**/
function enabled() {
return function_exists('NewADOConnection');
}
/**
* Disconnects from database.
*

View file

@ -146,6 +146,14 @@ class DboDb2 extends DboSource {
return $this->connected;
}
/**
* Check that the DB2 extension is installed/loaded
*
* @return boolean
**/
function enabled() {
return extension_loaded('ibm_db2');
}
/**
* Disconnects from database.
*

View file

@ -140,10 +140,19 @@ class DboFirebird extends DboSource {
$connect = $config['connect'];
$this->connected = false;
$this->connection = $connect($config['host'] . ':' . $config['database'], $config['login'], $config['password']);
$this->connected = true;
}
/**
* Check that the interbase extension is loaded
*
* @return boolean
**/
function enabled() {
return extension_loaded('interbase');
}
/**
* Disconnects from database.
*

View file

@ -164,6 +164,14 @@ class DboMssql extends DboSource {
return $this->connected;
}
/**
* Check that MsSQL is installed/loaded
*
* @return boolean
**/
function enabled() {
return extension_loaded('mssql');
}
/**
* Disconnects from database.
*

View file

@ -118,6 +118,40 @@ class DboMysqlBase extends DboSource {
'boolean' => array('name' => 'tinyint', 'limit' => '1')
);
/**
* Returns an array of the fields in given table name.
*
* @param string $tableName Name of database table to inspect
* @return array Fields in table. Keys are name and type
*/
function describe(&$model) {
$cache = parent::describe($model);
if ($cache != null) {
return $cache;
}
$fields = false;
$cols = $this->query('DESCRIBE ' . $this->fullTableName($model));
foreach ($cols as $column) {
$colKey = array_keys($column);
if (isset($column[$colKey[0]]) && !isset($column[0])) {
$column[0] = $column[$colKey[0]];
}
if (isset($column[0])) {
$fields[$column[0]['Field']] = array(
'type' => $this->column($column[0]['Type']),
'null' => ($column[0]['Null'] == 'YES' ? true : false),
'default' => $column[0]['Default'],
'length' => $this->length($column[0]['Type']),
);
if (!empty($column[0]['Key']) && isset($this->index[$column[0]['Key']])) {
$fields[$column[0]['Field']]['key'] = $this->index[$column[0]['Key']];
}
}
}
$this->__cacheDescription($this->fullTableName($model, false), $fields);
return $fields;
}
/**
* Generates and executes an SQL UPDATE statement for given model, fields, and values.
*
@ -498,6 +532,14 @@ class DboMysql extends DboMysqlBase {
return $this->connected;
}
/**
* Check whether the MySQL extension is installed/loaded
*
* @return boolean
**/
function enabled() {
return extension_loaded('mysql');
}
/**
* Disconnects from database.
*
@ -547,52 +589,6 @@ class DboMysql extends DboMysqlBase {
}
}
/**
* Returns an array of the fields in given table name.
*
* @param string $tableName Name of database table to inspect
* @return array Fields in table. Keys are name and type
*/
function describe(&$model) {
$cache = parent::describe($model);
if ($cache != null) {
return $cache;
}
$fields = false;
$cols = $this->query('SHOW FULL COLUMNS FROM ' . $this->fullTableName($model));
foreach ($cols as $column) {
$colKey = array_keys($column);
if (isset($column[$colKey[0]]) && !isset($column[0])) {
$column[0] = $column[$colKey[0]];
}
if (isset($column[0])) {
$fields[$column[0]['Field']] = array(
'type' => $this->column($column[0]['Type']),
'null' => ($column[0]['Null'] == 'YES' ? true : false),
'default' => $column[0]['Default'],
'length' => $this->length($column[0]['Type']),
);
if (!empty($column[0]['Key']) && isset($this->index[$column[0]['Key']])) {
$fields[$column[0]['Field']]['key'] = $this->index[$column[0]['Key']];
}
foreach ($this->fieldParameters as $name => $value) {
if (!empty($column[0][$value['column']])) {
$fields[$column[0]['Field']][$name] = $column[0][$value['column']];
}
}
if (isset($fields[$column[0]['Field']]['collate'])) {
$charset = $this->getCharsetName($fields[$column[0]['Field']]['collate']);
if ($charset) {
$fields[$column[0]['Field']]['charset'] = $charset;
}
}
}
}
$this->__cacheDescription($this->fullTableName($model, false), $fields);
return $fields;
}
/**
* Returns a quoted and escaped string of $data for use in an SQL statement.
*

View file

@ -89,6 +89,14 @@ class DboMysqli extends DboMysqlBase {
return $this->connected;
}
/**
* Check that MySQLi is installed/enabled
*
* @return boolean
**/
function enabled() {
return extension_loaded('mysqli');
}
/**
* Disconnects from database.
*
@ -159,44 +167,6 @@ class DboMysqli extends DboMysqlBase {
return $tables;
}
/**
* Returns an array of the fields in given table name.
*
* @param string $tableName Name of database table to inspect
* @return array Fields in table. Keys are name and type
*/
function describe(&$model) {
$cache = parent::describe($model);
if ($cache != null) {
return $cache;
}
$fields = false;
$cols = $this->query('DESCRIBE ' . $this->fullTableName($model));
foreach ($cols as $column) {
$colKey = array_keys($column);
if (isset($column[$colKey[0]]) && !isset($column[0])) {
$column[0] = $column[$colKey[0]];
}
if (isset($column[0])) {
$fields[$column[0]['Field']] = array(
'type' => $this->column($column[0]['Type']),
'null' => ($column[0]['Null'] == 'YES' ? true : false),
'default' => $column[0]['Default'],
'length' => $this->length($column[0]['Type'])
);
if (!empty($column[0]['Key']) && isset($this->index[$column[0]['Key']])) {
$fields[$column[0]['Field']]['key'] = $this->index[$column[0]['Key']];
}
}
}
$this->__cacheDescription($this->fullTableName($model, false), $fields);
return $fields;
}
/**
* Returns a quoted and escaped string of $data for use in an SQL statement.
*
@ -344,26 +314,6 @@ class DboMysqli extends DboMysqlBase {
return 'text';
}
/**
* Gets the length of a database-native column description, or null if no length
*
* @param string $real Real database-layer column type (i.e. "varchar(255)")
* @return integer An integer representing the length of the column
*/
function length($real) {
$col = str_replace(array(')', 'unsigned'), '', $real);
$limit = null;
if (strpos($col, '(') !== false) {
list($col, $limit) = explode('(', $col);
}
if ($limit != null) {
return intval($limit);
}
return null;
}
/**
* Enter description here...
*

View file

@ -112,6 +112,14 @@ class DboOdbc extends DboSource {
return $this->connected;
}
/**
* Check if the ODBC extension is installed/loaded
*
* @return boolean
**/
function enabled() {
return extension_loaded('odbc');
}
/**
* Disconnects from database.
*

View file

@ -129,6 +129,14 @@ class DboPostgres extends DboSource {
return $this->connected;
}
/**
* Check if PostgreSQL is enabled/loaded
*
* @return boolean
**/
function enabled() {
return extension_loaded('pgsql');
}
/**
* Disconnects from database.
*
@ -289,6 +297,7 @@ class DboPostgres extends DboSource {
case 'date':
case 'datetime':
case 'timestamp':
case 'time':
if ($data === '') {
return $read ? 'NULL' : 'DEFAULT';
}

View file

@ -107,6 +107,25 @@ class DboSqlite extends DboSource {
'boolean' => array('name' => 'boolean')
);
/**
* List of engine specific additional field parameters used on table creating
*
* @var array
* @access public
*/
var $fieldParameters = array(
'collate' => array(
'value' => 'COLLATE',
'quote' => false,
'join' => ' ',
'column' => 'Collate',
'position' => 'afterDefault',
'options' => array(
'BINARY', 'NOCASE', 'RTRIM'
)
),
);
/**
* Connects to the database using config['database'] as a filename.
*
@ -124,6 +143,14 @@ class DboSqlite extends DboSource {
return $this->connected;
}
/**
* Check that SQLite is enabled/installed
*
* @return boolean
**/
function enabled() {
return extension_loaded('sqlite');
}
/**
* Disconnects from database.
*
@ -481,32 +508,7 @@ class DboSqlite extends DboSource {
if (isset($column['key']) && $column['key'] == 'primary' && $type == 'integer') {
return $this->name($name) . ' ' . $this->columns['primary_key']['name'];
}
if (isset($real['limit']) || isset($real['length']) || isset($column['limit']) || isset($column['length'])) {
if (isset($column['length'])) {
$length = $column['length'];
} elseif (isset($column['limit'])) {
$length = $column['limit'];
} elseif (isset($real['length'])) {
$length = $real['length'];
} else {
$length = $real['limit'];
}
$out .= '(' . $length . ')';
}
if (isset($column['key']) && $column['key'] == 'primary' && $type == 'integer') {
$out .= ' ' . $this->columns['primary_key']['name'];
} elseif (isset($column['key']) && $column['key'] == 'primary') {
$out .= ' NOT NULL';
} elseif (isset($column['default']) && isset($column['null']) && $column['null'] == false) {
$out .= ' DEFAULT ' . $this->value($column['default'], $type) . ' NOT NULL';
} elseif (isset($column['default'])) {
$out .= ' DEFAULT ' . $this->value($column['default'], $type);
} elseif (isset($column['null']) && $column['null'] == true) {
$out .= ' DEFAULT NULL';
} elseif (isset($column['null']) && $column['null'] == false) {
$out .= ' NOT NULL';
}
return $out;
return parent::buildColumn($column);
}
/**

View file

@ -111,6 +111,14 @@ class DboSybase extends DboSource {
return $this->connected;
}
/**
* Check that one of the sybase extensions is installed
*
* @return boolean
**/
function enabled() {
return extension_loaded('sybase') || extension_loaded('sybase_ct');
}
/**
* Disconnects from database.
*

View file

@ -116,7 +116,9 @@ class DboSource extends DataSource {
}
parent::__construct($config);
$this->fullDebug = Configure::read() > 1;
if (!$this->enabled()) {
return false;
}
if ($autoConnect) {
return $this->connect();
} else {
@ -383,8 +385,10 @@ class DboSource extends DataSource {
$this->_queryCache[$sql] = $out;
}
}
if (empty($out) && is_bool($this->_result)) {
return $this->_result;
}
return $out;
} else {
return false;
}
@ -2459,16 +2463,7 @@ class DboSource extends DataSource {
if (($column['type'] == 'integer' || $column['type'] == 'float' ) && isset($column['default']) && $column['default'] === '') {
$column['default'] = null;
}
foreach ($this->fieldParameters as $paramName => $value) {
if (isset($column[$paramName]) && $value['position'] == 'beforeDefault') {
$val = $column[$paramName];
if ($value['quote']) {
$val = $this->value($val);
}
$out .= ' ' . $value['value'] . $value['join'] . $val;
}
}
$out = $this->_buildFieldParameters($out, $column, 'beforeDefault');
if (isset($column['key']) && $column['key'] == 'primary' && $type == 'integer') {
$out .= ' ' . $this->columns['primary_key']['name'];
@ -2483,18 +2478,32 @@ class DboSource extends DataSource {
} elseif (isset($column['null']) && $column['null'] == false) {
$out .= ' NOT NULL';
}
$out = $this->_buildFieldParameters($out, $column, 'afterDefault');
return $out;
}
/**
* Build the field parameters, in a position
*
* @param string $columnString The partially built column string
* @param array $columnData The array of column data.
* @param string $position The position type to use. 'beforeDefault' or 'afterDefault' are common
* @return string a built column with the field parameters added.
**/
function _buildFieldParameters($columnString, $columnData, $position) {
foreach ($this->fieldParameters as $paramName => $value) {
if (isset($column[$paramName]) && $value['position'] == 'afterDefault') {
$val = $column[$paramName];
if (isset($columnData[$paramName]) && $value['position'] == $position) {
if (isset($value['options']) && !in_array($columnData[$paramName], $value['options'])) {
continue;
}
$val = $columnData[$paramName];
if ($value['quote']) {
$val = $this->value($val);
}
$out .= ' ' . $value['value'] . $value['join'] . $val;
$columnString .= ' ' . $value['value'] . $value['join'] . $val;
}
}
return $out;
return $columnString;
}
/**

View file

@ -34,8 +34,10 @@ class String {
* @return object String instance
* @access public
* @static
* @deprecated
*/
function &getInstance() {
trigger_error('String::getInstance() is deprecated. All String methods are called statically.', E_USER_WARNING);
static $instance = array();
if (!$instance) {
@ -227,6 +229,9 @@ class String {
$options += $defaults;
$format = $options['format'];
$data = (array)$data;
if (empty($data)) {
return ($options['clean']) ? String::cleanInsert($str, $options) : $str;
}
if (!isset($format)) {
$format = sprintf(

View file

@ -546,26 +546,6 @@ class Validation extends Object {
return false;
}
/**
* Check that value is a file name
*
* @param mixed $check Value to check
* @access public
* @todo finish implementation
*/
function file($check) {
// if (is_array($check)) {
// foreach ($check as $value) {
// if (!Validation::file($value)) {
// return false;
// }
// }
// return true;
// }
//
// return preg_match('/[\w| |_]+\.[\w]+/', $check);
}
/**
* Validation of an IPv4 address.
*

View file

@ -81,15 +81,15 @@ class CacheHelper extends AppHelper {
$cacheTime = 0;
$useCallbacks = false;
if (is_array($this->cacheAction)) {
$contoller = Inflector::underscore($this->controllerName);
$controller = Inflector::underscore($this->controllerName);
$check = str_replace('/', '_', $this->here);
$replace = str_replace('/', '_', $this->base);
$match = str_replace($this->base, '', $this->here);
$match = str_replace('//', '/', $match);
$match = str_replace('/' . $contoller . '/', '', $match);
$match = str_replace('/' . $controller . '/', '', $match);
$match = str_replace('/' . $this->controllerName . '/', '', $match);
$check = str_replace($replace, '', $check);
$check = str_replace('_' . $contoller . '_', '', $check);
$check = str_replace('_' . $controller . '_', '', $check);
$check = str_replace('_' . $this->controllerName . '_', '', $check);
$check = Inflector::slug($check);
$check = preg_replace('/^_+/', '', $check);
@ -179,7 +179,6 @@ class CacheHelper extends AppHelper {
$outputResult = array_values($outputResult);
}
if (!empty($fileResult)) {
$i = 0;
foreach ($fileResult as $cacheBlock) {
@ -202,24 +201,23 @@ class CacheHelper extends AppHelper {
function __parseOutput($cache) {
$count = 0;
if (!empty($this->__match)) {
foreach ($this->__match as $found) {
$original = $cache;
$length = strlen($found);
$position = 0;
for ($i = 1; $i <= 1; $i++) {
$position = strpos($cache, $found, $position);
for ($i = 1; $i <= 1; $i++) {
$position = strpos($cache, $found, $position);
if ($position !== false) {
$cache = substr($original, 0, $position);
$cache .= $this->__replace[$count];
$cache .= substr($original, $position + $length);
} else {
break;
}
if ($position !== false) {
$cache = substr($original, 0, $position);
$cache .= $this->__replace[$count];
$cache .= substr($original, $position + $length);
} else {
break;
}
$count++;
}
$count++;
}
return $cache;
}
@ -301,5 +299,4 @@ class CacheHelper extends AppHelper {
return cache('views' . DS . $cache, $file, $timestamp);
}
}
?>

View file

@ -72,8 +72,30 @@ class FormHelper extends AppHelper {
*/
var $requestType = null;
/**
* The default model being used for the current form.
*
* @var string
*/
var $defaultModel = null;
/**
* Persistent default options used by input(). Set by FormHelper::create().
*
* @var array
* @access protected
*/
var $_inputDefaults = array();
/**
* Introspects model information and extracts information related
* to validation, field length and field type. Appends information into
* $this->fieldset.
*
* @return Model Returns a model instance
* @access protected
*/
function &_introspectModel($model) {
$object = null;
if (is_string($model) && strpos($model, '.') !== false) {
@ -122,27 +144,20 @@ class FormHelper extends AppHelper {
return $object;
}
/**
* Persistent default options used by input(). Set by FormHelper::create().
*
* @var array
* @access protected
*/
var $_inputDefaults = array();
/**
* Returns an HTML FORM element.
*
* #### Options:
*
* - 'type' Form method defaults to POST
* - 'action' The Action the form submits to. Can be a string or array,
* - 'url' The url the form submits to. Can be a string or a url array,
* - 'default' Allows for the creation of Ajax forms.
* - 'onsubmit' Used in conjunction with 'default' to create ajax forms.
* - 'inputDefaults' set the default $options for FormHelper::input(). Any options that would
* - `type` Form method defaults to POST
* - `action` The Action the form submits to. Can be a string or array,
* - `url` The url the form submits to. Can be a string or a url array,
* - `default` Allows for the creation of Ajax forms.
* - `onsubmit` Used in conjunction with 'default' to create ajax forms.
* - `inputDefaults' set the default $options for FormHelper::input(). Any options that would
* be set when using FormHelper::input() can be set here. Options set with `inputDefaults`
* can be overridden when calling input()
* - `encoding` Set the accept-charset encoding for the form. Defaults to `Configure::read('App.encoding')`
*
* @access public
* @param string $model The model object which the form is being defined for
@ -181,7 +196,6 @@ class FormHelper extends AppHelper {
$data = $this->fieldset[$this->model()];
$recordExists = (
isset($this->data[$model]) &&
isset($this->data[$model][$data['key']]) &&
!empty($this->data[$model][$data['key']])
);
@ -190,11 +204,13 @@ class FormHelper extends AppHelper {
$id = $this->data[$model][$data['key']];
}
}
$options = array_merge(array(
'type' => ($created && empty($options['action'])) ? 'put' : 'post',
'action' => null,
'url' => null,
'default' => true,
'encoding' => strtolower(Configure::read('App.encoding')),
'inputDefaults' => array()),
$options);
$this->_inputDefaults = $options['inputDefaults'];
@ -209,7 +225,7 @@ class FormHelper extends AppHelper {
}
}
if (empty($options['action'])) {
$options['action'] = ($created) ? 'edit' : 'add';
$options['action'] = $this->params['action'];
}
$actionDefaults = array(
@ -256,6 +272,12 @@ class FormHelper extends AppHelper {
$htmlAttributes['onsubmit'] = 'event.returnValue = false; return false;';
}
}
if (!empty($options['encoding'])) {
$htmlAttributes['accept-charset'] = $options['encoding'];
unset($options['encoding']);
}
unset($options['default']);
$htmlAttributes = array_merge($options, $htmlAttributes);
@ -624,7 +646,6 @@ class FormHelper extends AppHelper {
* @return string Completed form widget
*/
function input($fieldName, $options = array()) {
$view =& ClassRegistry::getObject('view');
$this->setEntity($fieldName);
$options = array_merge(
@ -632,25 +653,26 @@ class FormHelper extends AppHelper {
$this->_inputDefaults,
$options
);
$defaults = array('before' => null, 'between' => null, 'after' => null);
$options = array_merge($defaults, $options);
if (!isset($this->fieldset[$this->model()])) {
//Try to load fieldset for this model
$this->_introspectModel($this->model());
$modelKey = $this->model();
$fieldKey = $this->field();
if (!isset($this->fieldset[$modelKey])) {
$this->_introspectModel($modelKey);
}
if (!isset($options['type'])) {
$userType = isset($options['type']) ? true : false;
if (!$userType) {
$options['type'] = 'text';
$fieldDef = array();
if (isset($options['options'])) {
$options['type'] = 'select';
} elseif (in_array($this->field(), array('psword', 'passwd', 'password'))) {
} elseif (in_array($fieldKey, array('psword', 'passwd', 'password'))) {
$options['type'] = 'password';
} elseif (isset($this->fieldset[$this->model()]['fields'][$this->field()])) {
$fieldDef = $this->fieldset[$this->model()]['fields'][$this->field()];
} elseif (isset($this->fieldset[$modelKey]['fields'][$fieldKey])) {
$fieldDef = $this->fieldset[$modelKey]['fields'][$fieldKey];
$type = $fieldDef['type'];
$primaryKey = $this->fieldset[$this->model()]['key'];
$primaryKey = $this->fieldset[$modelKey]['key'];
}
if (isset($type)) {
@ -666,12 +688,12 @@ class FormHelper extends AppHelper {
} elseif (isset($map[$type])) {
$options['type'] = $map[$type];
}
if ($this->field() == $primaryKey) {
if ($fieldKey == $primaryKey) {
$options['type'] = 'hidden';
}
}
if ($this->model() === $this->field()) {
if ($modelKey === $fieldKey) {
$options['type'] = 'select';
if (!isset($options['multiple'])) {
$options['multiple'] = 'multiple';
@ -680,10 +702,10 @@ class FormHelper extends AppHelper {
}
$types = array('text', 'checkbox', 'radio', 'select');
if (!isset($options['options']) && in_array($options['type'], $types)) {
if (!isset($options['options']) && in_array($options['type'], $types) && !$userType) {
$view =& ClassRegistry::getObject('view');
$varName = Inflector::variable(
Inflector::pluralize(preg_replace('/_id$/', '', $this->field()))
Inflector::pluralize(preg_replace('/_id$/', '', $fieldKey))
);
$varOptions = $view->getVar($varName);
if (is_array($varOptions)) {
@ -720,8 +742,8 @@ class FormHelper extends AppHelper {
$divOptions = array_merge($divOptions, $div);
}
if (
isset($this->fieldset[$this->model()]) &&
in_array($this->field(), $this->fieldset[$this->model()]['validates'])
isset($this->fieldset[$modelKey]) &&
in_array($fieldKey, $this->fieldset[$modelKey]['validates'])
) {
$divOptions = $this->addClass($divOptions, 'required');
}
@ -750,9 +772,13 @@ class FormHelper extends AppHelper {
if ($label !== false) {
$labelAttributes = $this->domId(array(), 'for');
if (in_array($options['type'], array('date', 'datetime'))) {
$labelAttributes['for'] .= 'Month';
} else if ($options['type'] === 'time') {
if ($options['type'] === 'date' || $options['type'] === 'datetime') {
if (isset($options['dateFormat']) && $options['dateFormat'] === 'NONE') {
$labelAttributes['for'] .= 'Hour';
} else {
$labelAttributes['for'] .= 'Month';
}
} elseif ($options['type'] === 'time') {
$labelAttributes['for'] .= 'Hour';
}
@ -884,30 +910,34 @@ class FormHelper extends AppHelper {
*
* - `value` - the value of the checkbox
* - `checked` - boolean indicate that this checkbox is checked.
* - `hiddenField` - boolean to indicate if you want the results of checkbox() to include
* a hidden input with a value of ''.
*
* @param string $fieldName Name of a field, like this "Modelname.fieldname"
* @param array $options Array of HTML attributes.
* @todo Right now, automatically setting the 'checked' value is dependent on whether or not the
* checkbox is bound to a model. This should probably be re-evaluated in future versions.
* @return string An HTML text input element
*/
function checkbox($fieldName, $options = array()) {
$options = $this->_initInputField($fieldName, $options);
$options = $this->_initInputField($fieldName, $options) + array('hiddenField' => true);
$value = current($this->value());
$output = "";
if (!isset($options['value']) || empty($options['value'])) {
if (empty($options['value'])) {
$options['value'] = 1;
} elseif (!empty($value) && $value === $options['value']) {
$options['checked'] = 'checked';
}
$hiddenOptions = array(
'id' => $options['id'] . '_', 'name' => $options['name'],
'value' => '0', 'secure' => false
);
if (isset($options['disabled']) && $options['disabled'] == true) {
$hiddenOptions['disabled'] = 'disabled';
if ($options['hiddenField']) {
$hiddenOptions = array(
'id' => $options['id'] . '_', 'name' => $options['name'],
'value' => '0', 'secure' => false
);
if (isset($options['disabled']) && $options['disabled'] == true) {
$hiddenOptions['disabled'] = 'disabled';
}
$output = $this->hidden($fieldName, $hiddenOptions);
}
$output = $this->hidden($fieldName, $hiddenOptions);
unset($options['hiddenField']);
return $this->output($output . sprintf(
$this->Html->tags['checkbox'],
@ -925,6 +955,8 @@ class FormHelper extends AppHelper {
* - `legend` - control whether or not the widget set has a fieldset & legend
* - `value` - indicate a value that is should be checked
* - `label` - boolean to indicate whether or not labels for widgets show be displayed
* - `hiddenField` - boolean to indicate if you want the results of radio() to include
* a hidden input with a value of ''. This is useful for creating radio sets that non-continuous
*
* @param string $fieldName Name of a field, like this "Modelname.fieldname"
* @param array $options Radio button options array.
@ -961,6 +993,9 @@ class FormHelper extends AppHelper {
}
$out = array();
$hiddenField = isset($attributes['hiddenField']) ? $attributes['hiddenField'] : true;
unset($attributes['hiddenField']);
foreach ($options as $optValue => $optTitle) {
$optionsHere = array('value' => $optValue);
@ -985,10 +1020,12 @@ class FormHelper extends AppHelper {
}
$hidden = null;
if (!isset($value) || $value === '') {
$hidden = $this->hidden($fieldName, array(
'id' => $attributes['id'] . '_', 'value' => '', 'name' => $attributes['name']
));
if ($hiddenField) {
if (!isset($value) || $value === '') {
$hidden = $this->hidden($fieldName, array(
'id' => $attributes['id'] . '_', 'value' => '', 'name' => $attributes['name']
));
}
}
$out = $hidden . join($inbetween, $out);
@ -1160,7 +1197,7 @@ class FormHelper extends AppHelper {
$div = $options['div'];
unset($options['div']);
}
$options += array('type' => 'submit');
$options += array('type' => 'submit', 'before' => null, 'after' => null);
$divOptions = array('tag' => 'div');
if ($div === true) {
@ -1173,13 +1210,17 @@ class FormHelper extends AppHelper {
$divOptions = array_merge(array('class' => 'submit', 'tag' => 'div'), $div);
}
$before = $options['before'];
$after = $options['after'];
unset($options['before'], $options['after']);
if (strpos($caption, '://') !== false) {
unset($options['type']);
$out .= $this->output(sprintf(
$out .= $this->output($before . sprintf(
$this->Html->tags['submitimage'],
$caption,
$this->_parseAttributes($options, null, '', ' ')
));
) . $after);
} elseif (preg_match('/\.(jpg|jpe|jpeg|gif|png|ico)$/', $caption)) {
unset($options['type']);
if ($caption{0} !== '/') {
@ -1188,17 +1229,17 @@ class FormHelper extends AppHelper {
$caption = trim($caption, '/');
$url = $this->webroot($caption);
}
$out .= $this->output(sprintf(
$out .= $this->output($before . sprintf(
$this->Html->tags['submitimage'],
$url,
$this->_parseAttributes($options, null, '', ' ')
));
) . $after);
} else {
$options['value'] = $caption;
$out .= $this->output(sprintf(
$out .= $this->output($before . sprintf(
$this->Html->tags['submit'],
$this->_parseAttributes($options, null, '', ' ')
));
). $after);
}
if (isset($divOptions)) {
@ -1779,7 +1820,7 @@ class FormHelper extends AppHelper {
}
if ($name !== null) {
if ((!$selectedIsEmpty && $selected == $name) || ($selectedIsArray && in_array($name, $selected))) {
if ((!$selectedIsEmpty && (string)$selected == (string)$name) || ($selectedIsArray && in_array($name, $selected))) {
if ($attributes['style'] === 'checkbox') {
$htmlOptions['checked'] = true;
} else {

View file

@ -250,11 +250,13 @@ class PaginatorHelper extends AppHelper {
}
/**
* Generates a sorting link
* Generates a sorting link. Sets named parameters for the sort and direction. Handles
* direction switching automatically.
*
* @param string $title Title for the link.
* @param string $key The name of the key that the recordset should be sorted.
* @param array $options Options for sorting link. See #options for list of keys.
* @param string $title Title for the link.
* @param string $key The name of the key that the recordset should be sorted. If $key is null
* $title will be used for the key, and a title will be generated by inflection.
* @param array $options Options for sorting link. See #options for list of keys.
* @return string A link sorting default by 'asc'. If the resultset is sorted 'asc' by the specified
* key the returned link will sort by 'desc'.
*/

View file

@ -46,43 +46,51 @@ class TextHelper extends AppHelper {
* Highlights a given phrase in a text. You can specify any expression in highlighter that
* may include the \1 expression to include the $phrase found.
*
* Options:
*
* - 'format' The piece of html with that the phrase will be highlighted
* - 'html' If true, will ignore any HTML tags, ensuring that only the correct text is highlighted
*
* @param string $text Text to search the phrase in
* @param string $phrase The phrase that will be searched
* @param string $highlighter The piece of html with that the phrase will be highlighted
* @param boolean $considerHtml If true, will ignore any HTML tags, ensuring that only the correct text is highlighted
* @param array $options An array of html attributes and options.
* @return string The highlighted text
* @access public
*/
function highlight($text, $phrase, $highlighter = '<span class="highlight">\1</span>', $considerHtml = false) {
function highlight($text, $phrase, $options = array()) {
if (empty($phrase)) {
return $text;
}
if (is_array($phrase)) {
$default = array(
'format' => '<span class="highlight">\1</span>',
'html' => false
);
$options = array_merge($default, $options);
extract($options);
if (is_array($phrase)) {
$replace = array();
$with = array();
foreach ($phrase as $key => $segment) {
$segment = "($segment)";
if ($considerHtml) {
if ($html) {
$segment = "(?![^<]+>)$segment(?![^<]+>)";
}
$with[] = (is_array($highlighter)) ? $highlighter[$key] : $highlighter;
$with[] = (is_array($format)) ? $format[$key] : $format;
$replace[] = "|$segment|iu";
}
return preg_replace($replace, $with, $text);
} else {
$phrase = "($phrase)";
if ($considerHtml) {
if ($html) {
$phrase = "(?![^<]+>)$phrase(?![^<]+>)";
}
return preg_replace("|$phrase|iu", $highlighter, $text);
return preg_replace("|$phrase|iu", $format, $text);
}
}
@ -102,56 +110,55 @@ class TextHelper extends AppHelper {
* strings like http:// and ftp://.
*
* @param string $text Text to add links to
* @param array $htmlOptions Array of HTML options.
* @param array $options Array of HTML options.
* @return string The text with links
* @access public
*/
function autoLinkUrls($text, $htmlOptions = array()) {
$options = 'array(';
foreach ($htmlOptions as $option => $value) {
function autoLinkUrls($text, $options = array()) {
$linkOptions = 'array(';
foreach ($options as $option => $value) {
$value = var_export($value, true);
$options .= "'$option' => $value, ";
$linkOptions .= "'$option' => $value, ";
}
$options .= ')';
$linkOptions .= ')';
$text = preg_replace_callback('#(?<!href="|">)((?:http|https|ftp|nntp)://[^ <]+)#i', create_function('$matches',
'$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], $matches[0],' . $options . ');'), $text);
'$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], $matches[0],' . $linkOptions . ');'), $text);
return preg_replace_callback('#(?<!href="|">)(?<!http://|https://|ftp://|nntp://)(www\.[^\n\%\ <]+[^<\n\%\,\.\ <])(?<!\))#i',
create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "http://" . strtolower($matches[0]),' . $options . ');'), $text);
create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "http://" . strtolower($matches[0]),' . $linkOptions . ');'), $text);
}
/**
* Adds email links (<a href="mailto:....) to a given text.
*
* @param string $text Text
* @param array $htmlOptions Array of HTML options.
* @param array $options Array of HTML options.
* @return string The text with links
* @access public
*/
function autoLinkEmails($text, $htmlOptions = array()) {
$options = 'array(';
foreach ($htmlOptions as $option => $value) {
function autoLinkEmails($text, $options = array()) {
$linkOptions = 'array(';
foreach ($options as $option => $value) {
$value = var_export($value, true);
$options .= "'$option' => $value, ";
$linkOptions .= "'$option' => $value, ";
}
$options .= ')';
$linkOptions .= ')';
return preg_replace_callback('#([_A-Za-z0-9+-]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#',
create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "mailto:" . $matches[0],' . $options . ');'), $text);
create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "mailto:" . $matches[0],' . $linkOptions . ');'), $text);
}
/**
* Convert all links and email adresses to HTML links.
*
* @param string $text Text
* @param array $htmlOptions Array of HTML options.
* @param array $options Array of HTML options.
* @return string The text with links
* @access public
*/
function autoLink($text, $htmlOptions = array()) {
return $this->autoLinkEmails($this->autoLinkUrls($text, $htmlOptions), $htmlOptions);
function autoLink($text, $options = array()) {
return $this->autoLinkEmails($this->autoLinkUrls($text, $options), $options);
}
/**
@ -160,24 +167,32 @@ class TextHelper extends AppHelper {
* Cuts a string to the length of $length and replaces the last characters
* with the ending if the text is longer than length.
*
* Options:
*
* - 'ending' Will be used as Ending and appended to the trimmed string
* - 'exact' If false, $text will not be cut mid-word
* - 'html' If true, HTML tags would be handled correctly
*
* @param string $text String to truncate.
* @param integer $length Length of returned string, including ellipsis.
* @param mixed $ending If string, will be used as Ending and appended to the trimmed string. Can also be an associative array that can contain the last three params of this method.
* @param boolean $exact If false, $text will not be cut mid-word
* @param boolean $considerHtml If true, HTML tags would be handled correctly
* @param array $options An array of html attributes and options.
* @return string Trimmed string.
*/
function truncate($text, $length = 100, $ending = '...', $exact = true, $considerHtml = false) {
if (is_array($ending)) {
extract($ending);
}
if ($considerHtml) {
function truncate($text, $length = 100, $options = array()) {
$default = array(
'ending' => '...', 'exact' => true, 'html' => false
);
$options = array_merge($default, $options);
extract($options);
if ($html) {
if (mb_strlen(preg_replace('/<.*?>/', '', $text)) <= $length) {
return $text;
}
$totalLength = mb_strlen($ending);
$openTags = array();
$truncate = '';
preg_match_all('/(<\/?([\w+]+)[^>]*>)?([^<>]*)/', $text, $tags, PREG_SET_ORDER);
foreach ($tags as $tag) {
if (!preg_match('/img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param/s', $tag[2])) {
@ -217,7 +232,6 @@ class TextHelper extends AppHelper {
break;
}
}
} else {
if (mb_strlen($text) <= $length) {
return $text;
@ -228,7 +242,7 @@ class TextHelper extends AppHelper {
if (!$exact) {
$spacepos = mb_strrpos($truncate, ' ');
if (isset($spacepos)) {
if ($considerHtml) {
if ($html) {
$bits = mb_substr($truncate, $spacepos);
preg_match_all('/<\/([a-z]+)>/', $bits, $droppedTags, PREG_SET_ORDER);
if (!empty($droppedTags)) {
@ -242,10 +256,9 @@ class TextHelper extends AppHelper {
$truncate = mb_substr($truncate, 0, $spacepos);
}
}
$truncate .= $ending;
if ($considerHtml) {
if ($html) {
foreach ($openTags as $tag) {
$truncate .= '</'.$tag.'>';
}
@ -276,9 +289,9 @@ class TextHelper extends AppHelper {
* @return string Modified string
* @access public
*/
function excerpt($text, $phrase, $radius = 100, $ending = "...") {
function excerpt($text, $phrase, $radius = 100, $ending = '...') {
if (empty($text) or empty($phrase)) {
return $this->truncate($text, $radius * 2, $ending);
return $this->truncate($text, $radius * 2, array('ending' => $ending));
}
$phraseLen = mb_strlen($phrase);

View file

@ -55,7 +55,7 @@
<?php echo $html->link(
$html->image('cake.power.gif', array('alt'=> __("CakePHP: the rapid development php framework", true), 'border'=>"0")),
'http://www.cakephp.org/',
array('target'=>'_blank'), null, false
array('target' => '_blank', 'escape' => false)
);
?>
</div>

View file

@ -95,7 +95,7 @@ class ApiShellTest extends CakeTestCase {
'3. beforeRender()',
'4. constructClasses()',
'5. disableCache()',
'6. flash($message, $url, $pause = 1)',
'6. flash($message, $url, $pause = 1, $layout = \'flash\')',
'7. header($status)',
'8. isAuthorized()',
'9. loadModel($modelClass = null, $id = null)',

View file

@ -1,6 +1,7 @@
<?php
/* SVN FILE: $Id$ */
/**
* TestTaskTest file
* ModelTaskTest file
*
* Test Case for test generation shell task
*
@ -17,7 +18,7 @@
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
* @package cake
* @subpackage cake.tests.cases.console.libs.tasks
* @since CakePHP v 1.3
* @since CakePHP v 1.2.6
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
App::import('Shell', 'Shell', false);
@ -37,12 +38,10 @@ require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php';
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'fixture.php';
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
Mock::generatePartial(
'ShellDispatcher', 'TestModelTaskMockShellDispatcher',
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
);
Mock::generatePartial(
'ModelTask', 'MockModelTask',
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest')
@ -217,9 +216,9 @@ class ModelTaskTest extends CakeTestCase {
function testInteractiveFieldValidation() {
$this->Task->initValidations();
$this->Task->interactive = true;
$this->Task->setReturnValueAt(0, 'in', '20');
$this->Task->setReturnValueAt(0, 'in', '19');
$this->Task->setReturnValueAt(1, 'in', 'y');
$this->Task->setReturnValueAt(2, 'in', '16');
$this->Task->setReturnValueAt(2, 'in', '15');
$this->Task->setReturnValueAt(3, 'in', 'n');
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));

View file

@ -84,6 +84,7 @@ class CakeTestCaseTest extends CakeTestCase {
* @return void
*/
function setUp() {
$this->_debug = Configure::read('debug');
$this->Case =& new SubjectCakeTestCase();
$reporter =& new MockCakeHtmlReporter();
$this->Case->setReporter($reporter);
@ -97,6 +98,7 @@ class CakeTestCaseTest extends CakeTestCase {
* @return void
*/
function tearDown() {
Configure::write('debug', $this->_debug);
unset($this->Case);
unset($this->Reporter);
}

View file

@ -89,7 +89,7 @@ class CodeCoverageManagerTest extends CakeTestCase {
App::import('Core', 'Folder');
$folder = new Folder();
$folder->cd($path);
$contents = $folder->ls();
$contents = $folder->read();
/**
* remove method

View file

@ -389,6 +389,7 @@ class ComponentTest extends CakeTestCase {
function testNestedComponentLoading() {
$Controller =& new ComponentTestController();
$Controller->components = array('Apple');
$Controller->uses = false;
$Controller->constructClasses();
$Controller->Component->initialize($Controller);
@ -409,6 +410,7 @@ class ComponentTest extends CakeTestCase {
function testComponentStartup() {
$Controller =& new ComponentTestController();
$Controller->components = array('Apple');
$Controller->uses = false;
$Controller->constructClasses();
$Controller->Component->initialize($Controller);
$Controller->beforeFilter();
@ -429,6 +431,7 @@ class ComponentTest extends CakeTestCase {
*/
function testMultipleComponentInitialize() {
$Controller =& new ComponentTestController();
$Controller->uses = false;
$Controller->components = array('Orange', 'Banana');
$Controller->constructClasses();
$Controller->Component->initialize($Controller);
@ -450,7 +453,7 @@ class ComponentTest extends CakeTestCase {
$Controller =& new ComponentTestController();
$Controller->components = array('ParamTest' => array('test' => 'value', 'flag'), 'Apple');
$Controller->uses = false;
$Controller->constructClasses();
$Controller->Component->initialize($Controller);
@ -482,8 +485,12 @@ class ComponentTest extends CakeTestCase {
* @return void
**/
function testComponentParamsNoDuplication() {
if ($this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController')) {
return;
}
$Controller =& new ComponentTestController();
$Controller->components = array('Orange' => array('setting' => array('itemx')));
$Controller->uses = false;
$Controller->constructClasses();
$Controller->Component->initialize($Controller);
@ -499,6 +506,7 @@ class ComponentTest extends CakeTestCase {
function testMutuallyReferencingComponents() {
$Controller =& new ComponentTestController();
$Controller->components = array('MutuallyReferencingOne');
$Controller->uses = false;
$Controller->constructClasses();
$Controller->Component->initialize($Controller);
@ -524,6 +532,7 @@ class ComponentTest extends CakeTestCase {
function testSomethingReferencingEmailComponent() {
$Controller =& new ComponentTestController();
$Controller->components = array('SomethingWithEmail');
$Controller->uses = false;
$Controller->constructClasses();
$Controller->Component->initialize($Controller);
$Controller->beforeFilter();
@ -550,14 +559,17 @@ class ComponentTest extends CakeTestCase {
* @access public
*/
function testDoubleLoadingOfSessionComponent() {
$this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController');
if ($this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController')) {
return;
}
$Controller =& new ComponentTestController();
$Controller->uses = array();
$Controller->uses = false;
$Controller->components = array('Session');
$Controller->constructClasses();
$this->assertEqual($Controller->components, array('Session' => '', 'Orange' => array('colour' => 'blood orange')));
}
}
?>

View file

@ -408,8 +408,6 @@ HEADBLOC;
This is the body of the message
This email was sent using the CakePHP Framework, http://cakephp.org.
TEXTBLOC;
$html = <<<HTMLBLOC
@ -417,7 +415,7 @@ TEXTBLOC;
<html>
<head>
<title>EmailTest</title>
<title>Email Test</title>
</head>
<body>
@ -425,7 +423,6 @@ TEXTBLOC;
<p>This email was sent using the <a href="http://cakephp.org">CakePHP Framework</a></p>
</body>
</html>
HTMLBLOC;
$this->Controller->EmailTest->sendAs = 'text';
@ -452,7 +449,7 @@ HTMLBLOC;
<html>
<head>
<title>EmailTest</title>
<title>Email Test</title>
</head>
<body>
@ -477,8 +474,6 @@ standards.
This is the body of the message
This email was sent using the CakePHP Framework, http://cakephp.org.
TEXTBLOC;
$this->Controller->EmailTest->sendAs = 'text';

View file

@ -561,7 +561,9 @@ class RequestHandlerComponentTest extends CakeTestCase {
function testAjaxRedirectAsRequestAction() {
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
$this->_init();
App::build(array('views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)));
App::build(array(
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
), true);
$this->Controller->RequestHandler = new NoStopRequestHandler($this);
$this->Controller->RequestHandler->expectOnce('_stop');
@ -574,6 +576,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
$this->assertPattern('/posts index/', $result, 'RequestAction redirect failed.');
unset($_SERVER['HTTP_X_REQUESTED_WITH']);
App::build();
}
}
?>

View file

@ -222,6 +222,7 @@ class SecurityComponentTest extends CakeTestCase {
* @return void
*/
function testRequireSecureFail() {
$_SERVER['HTTPS'] = 'off';
$_SERVER['REQUEST_METHOD'] = 'POST';
$this->Controller->action = 'posted';
$this->Controller->Security->requireSecure('posted');

View file

@ -772,7 +772,9 @@ class ControllerTest extends CakeTestCase {
* @return void
*/
function testRender() {
App::build(array('views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)));
App::build(array(
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
), true);
$Controller =& new Controller();
$Controller->viewPath = 'posts';
@ -797,6 +799,7 @@ class ControllerTest extends CakeTestCase {
$Controller->ControllerComment->validationErrors = array();
ClassRegistry::flush();
App::build();
}
/**

View file

@ -131,7 +131,14 @@ class MergePostsController extends MergeVarPluginAppController {
* @package cake.tests.cases.libs.controller
**/
class ControllerMergeVarsTestCase extends CakeTestCase {
/**
* Skips the case if APP_CONTROLLER_EXISTS is defined
*
* @return void
**/
function skip() {
$this->skipIf(defined('APP_CONTROLLER_EXISTS'), 'APP_CONTROLLER_EXISTS cannot run. %s');
}
/**
* end test
*

View file

@ -315,8 +315,8 @@ class ScaffoldViewTest extends CakeTestCase {
* @return void
*/
function testGetViewFilename() {
$_admin = Configure::read('Routing.admin');
Configure::write('Routing.admin', 'admin');
$_admin = Configure::read('Routing.prefixes');
Configure::write('Routing.prefixes', array('admin'));
$this->Controller->action = 'index';
$ScaffoldView =& new TestScaffoldView($this->Controller);
@ -385,7 +385,7 @@ class ScaffoldViewTest extends CakeTestCase {
. DS .'test_plugin' . DS . 'views' . DS . 'tests' . DS . 'scaffold.edit.ctp';
$this->assertEqual($result, $expected);
Configure::write('Routing.admin', $_admin);
Configure::write('Routing.prefixes', $_admin);
}
/**
@ -499,7 +499,7 @@ class ScaffoldViewTest extends CakeTestCase {
new Scaffold($this->Controller, $params);
$result = ob_get_clean();
$this->assertPattern('/<form id="ScaffoldMockEditForm" method="post" action="\/scaffold_mock\/edit\/1">/', $result);
$this->assertPattern('/<form id="ScaffoldMockEditForm" method="post" action="\/scaffold_mock\/edit\/1"/', $result);
$this->assertPattern('/<legend>Edit Scaffold Mock<\/legend>/', $result);
$this->assertPattern('/input type="hidden" name="data\[ScaffoldMock\]\[id\]" value="1" id="ScaffoldMockId"/', $result);
@ -509,6 +509,7 @@ class ScaffoldViewTest extends CakeTestCase {
$this->assertPattern('/textarea name="data\[ScaffoldMock\]\[body\]" cols="30" rows="6" id="ScaffoldMockBody"/', $result);
$this->assertPattern('/<li><a href="\/scaffold_mock\/delete\/1"[^>]*>Delete<\/a>\s*<\/li>/', $result);
}
/**
* Test Admin Index Scaffolding.
*
@ -516,9 +517,9 @@ class ScaffoldViewTest extends CakeTestCase {
* @return void
**/
function testAdminIndexScaffold() {
$_backAdmin = Configure::read('Routing.admin');
$_backAdmin = Configure::read('Routing.prefixes');
Configure::write('Routing.admin', 'admin');
Configure::write('Routing.prefixes', array('admin'));
$params = array(
'plugin' => null,
'pass' => array(),
@ -551,7 +552,7 @@ class ScaffoldViewTest extends CakeTestCase {
//TODO: add testing for table generation
$this->assertPattern('/<li><a href="\/admin\/scaffold_mock\/add\/">New Scaffold Mock<\/a><\/li>/', $result);
Configure::write('Routing.admin', $_backAdmin);
Configure::write('Routing.prefixes', $_backAdmin);
}
/**
@ -561,9 +562,9 @@ class ScaffoldViewTest extends CakeTestCase {
* @return void
**/
function testAdminEditScaffold() {
$_backAdmin = Configure::read('Routing.admin');
$_backAdmin = Configure::read('Routing.prefixes');
Configure::write('Routing.admin', 'admin');
Configure::write('Routing.prefixes', array('admin'));
$params = array(
'plugin' => null,
'pass' => array(),
@ -594,8 +595,54 @@ class ScaffoldViewTest extends CakeTestCase {
$this->assertPattern('#admin/scaffold_mock/edit/1#', $result);
$this->assertPattern('#Scaffold Mock#', $result);
Configure::write('Routing.admin', $_backAdmin);
Configure::write('Routing.prefixes', $_backAdmin);
}
/**
* Test Admin Index Scaffolding.
*
* @access public
* @return void
**/
function testMultiplePrefixScaffold() {
$_backAdmin = Configure::read('Routing.prefixes');
Configure::write('Routing.prefixes', array('admin', 'member'));
$params = array(
'plugin' => null,
'pass' => array(),
'form' => array(),
'named' => array(),
'prefix' => 'member',
'url' => array('url' =>'member/scaffold_mock'),
'controller' => 'scaffold_mock',
'action' => 'member_index',
'member' => 1,
);
//reset, and set router.
Router::reload();
Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/member/scaffold_mock', 'webroot' => '/')));
$this->Controller->params = $params;
$this->Controller->controller = 'scaffold_mock';
$this->Controller->base = '/';
$this->Controller->action = 'member_index';
$this->Controller->here = '/tests/member/scaffold_mock';
$this->Controller->webroot = '/';
$this->Controller->scaffold = 'member';
$this->Controller->constructClasses();
ob_start();
$Scaffold = new Scaffold($this->Controller, $params);
$result = ob_get_clean();
$this->assertPattern('/<h2>Scaffold Mock<\/h2>/', $result);
$this->assertPattern('/<table cellpadding="0" cellspacing="0">/', $result);
//TODO: add testing for table generation
$this->assertPattern('/<li><a href="\/member\/scaffold_mock\/add\/">New Scaffold Mock<\/a><\/li>/', $result);
Configure::write('Routing.prefixes', $_backAdmin);
}
}
/**

View file

@ -286,6 +286,7 @@ class DebuggerTest extends CakeTestCase {
Debugger::log(array('whatever', 'here'));
$result = file_get_contents(TMP . 'logs' . DS . 'debug.log');
$this->assertPattern('/DebuggerTest\:\:testLog/', $result);
$this->assertPattern('/\[main\]/', $result);
$this->assertPattern('/array/', $result);
$this->assertPattern('/"whatever",/', $result);
$this->assertPattern('/"here"/', $result);

View file

@ -219,6 +219,18 @@ class FolderTest extends CakeTestCase {
$this->assertTrue($result);
}
/**
* test Adding path elements to a path
*
* @return void
**/
function testAddPathElement() {
$result = Folder::addPathElement(DS . 'some' . DS . 'dir', 'another_path');
$this->assertEqual($result, DS . 'some' . DS . 'dir' . DS . 'another_path');
$result = Folder::addPathElement(DS . 'some' . DS . 'dir' . DS, 'another_path');
$this->assertEqual($result, DS . 'some' . DS . 'dir' . DS . 'another_path');
}
/**
* testFolderRead method
*

View file

@ -1026,6 +1026,28 @@ class HttpSocketTest extends CakeTestCase {
'host' => 'www.google.com',
'port' => 8080,
));
$uri = $this->Socket->parseUri('http://www.cakephp.org/?param1=value1&param2=value2%3Dvalue3');
$this->assertIdentical($uri, array(
'scheme' => 'http',
'host' => 'www.cakephp.org',
'path' => '/',
'query' => array(
'param1' => 'value1',
'param2' => 'value2=value3'
)
));
$uri = $this->Socket->parseUri('http://www.cakephp.org/?param1=value1&param2=value2=value3');
$this->assertIdentical($uri, array(
'scheme' => 'http',
'host' => 'www.cakephp.org',
'path' => '/',
'query' => array(
'param1' => 'value1',
'param2' => 'value2=value3'
)
));
}
/**

View file

@ -2603,7 +2603,7 @@ class I18nTest extends CakeTestCase {
* @access private
* @return void
*/
function __domainCategorySingular($domain = 'test_plugin', $category = LC_MONETARY) {
function __domainCategorySingular($domain = 'test_plugin', $category = 3) {
$singular = __dc($domain, 'Plural Rule 1', $category, true);
return $singular;
}
@ -2614,7 +2614,7 @@ class I18nTest extends CakeTestCase {
* @access private
* @return void
*/
function __domainCategoryPlural($domain = 'test_plugin', $category = LC_MONETARY) {
function __domainCategoryPlural($domain = 'test_plugin', $category = 3) {
$plurals = array();
for ($number = 0; $number <= 25; $number++) {
$plurals[] = sprintf(__dcn($domain, '%d = 1', '%d = 0 or > 1', (float)$number, $category, true), (float)$number);
@ -2653,7 +2653,7 @@ class I18nTest extends CakeTestCase {
* @access private
* @return void
*/
function __category($category = LC_MONETARY) {
function __category($category = 3) {
$singular = __c('Plural Rule 1', $category, true);
return $singular;
}

View file

@ -1220,6 +1220,25 @@ class NumberTreeTest extends CakeTestCase {
$this->assertIdentical($nodes, $sortedNodes);
}
/**
* test reordering large-ish trees with cacheQueries = true.
* This caused infinite loops when moving down elements as stale data is returned
* from the memory cache
*
* @access public
* @return void
*/
function testReorderBigTreeWithQueryCaching() {
extract($this->settings);
$this->Tree =& new $modelClass();
$this->Tree->initialize(2, 10);
$original = $this->Tree->cacheQueries;
$this->Tree->cacheQueries = true;
$this->Tree->reorder(array('field' => 'name', 'direction' => 'DESC'));
$this->assertTrue($this->Tree->cacheQueries, 'cacheQueries was not restored after reorder(). %s');
$this->Tree->cacheQueries = $original;
}
/**
* testGenerateTreeListWithSelfJoin method
*

View file

@ -161,7 +161,7 @@ class MysqlTestModel extends Model {
* @subpackage cake.tests.cases.libs.model.datasources.dbo
*/
class DboMysqlTest extends CakeTestCase {
var $fixtures = array('core.binary_test');
/**
* The Dbo instance to be tested
*
@ -187,7 +187,6 @@ class DboMysqlTest extends CakeTestCase {
*/
function startTest() {
$db = ConnectionManager::getDataSource('test_suite');
$this->db = new DboMysqlTestDb($db->config);
$this->model = new MysqlTestModel();
}
@ -196,8 +195,9 @@ class DboMysqlTest extends CakeTestCase {
*
* @access public
*/
function endTest() {
unset($this->db);
function tearDown() {
unset($this->model);
ClassRegistry::flush();
}
/**
@ -285,11 +285,11 @@ class DboMysqlTest extends CakeTestCase {
* @return void
*/
function testTinyintCasting() {
$this->db->cacheSources = $this->db->testing = false;
$this->db->cacheSources = false;
$this->db->query('CREATE TABLE ' . $this->db->fullTableName('tinyint') . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));');
$this->model = new CakeTestModel(array(
'name' => 'Tinyint', 'table' => $this->db->fullTableName('tinyint', false)
'name' => 'Tinyint', 'table' => 'tinyint', 'ds' => 'test_suite'
));
$result = $this->model->schema();
@ -324,12 +324,12 @@ class DboMysqlTest extends CakeTestCase {
* @access public
*/
function testIndexDetection() {
$this->db->cacheSources = $this->db->testing = false;
$this->db->cacheSources = false;
$name = $this->db->fullTableName('simple');
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));');
$expected = array('PRIMARY' => array('column' => 'id', 'unique' => 1));
$result = $this->db->index($name, false);
$result = $this->db->index('simple', false);
$this->assertEqual($expected, $result);
$this->db->query('DROP TABLE ' . $name);
@ -339,7 +339,7 @@ class DboMysqlTest extends CakeTestCase {
'PRIMARY' => array('column' => 'id', 'unique' => 1),
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
);
$result = $this->db->index($name, false);
$result = $this->db->index('with_a_key', false);
$this->assertEqual($expected, $result);
$this->db->query('DROP TABLE ' . $name);
@ -350,7 +350,7 @@ class DboMysqlTest extends CakeTestCase {
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
'pointless_small_int' => array('column' => 'small_int', 'unique' => 0),
);
$result = $this->db->index($name, false);
$result = $this->db->index('with_two_keys', false);
$this->assertEqual($expected, $result);
$this->db->query('DROP TABLE ' . $name);
@ -362,7 +362,7 @@ class DboMysqlTest extends CakeTestCase {
'pointless_small_int' => array('column' => 'small_int', 'unique' => 0),
'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0),
);
$result = $this->db->index($name, false);
$result = $this->db->index('with_compound_keys', false);
$this->assertEqual($expected, $result);
$this->db->query('DROP TABLE ' . $name);
@ -375,7 +375,7 @@ class DboMysqlTest extends CakeTestCase {
'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0),
'other_way' => array('column' => array('small_int', 'bool'), 'unique' => 0),
);
$result = $this->db->index($name, false);
$result = $this->db->index('with_multiple_compound_keys', false);
$this->assertEqual($expected, $result);
$this->db->query('DROP TABLE ' . $name);
}
@ -628,6 +628,24 @@ class DboMysqlTest extends CakeTestCase {
$this->db->query($this->db->dropSchema($schema1));
}
/**
* test saving and retrieval of blobs
*
* @return void
**/
function testBlobSaving() {
$this->db->cacheSources = false;
$data = "GIF87ab
Ò4A¿¿¿ˇˇˇ,b
¢îè©ÀÌ#¥⁄ã≥fi:¯Üá¶jV∂ÓúÎL≥çÀóËıÎ…>ï vFE%ÒâLFI<†µw˝±≈£7˘ç^H“≤« >Éâ*∑ÇnÖA•Ù|flêèj£:=ÿ6óUàµ5'∂®àA¬ñ∆ˆGE(gt≈àÚyÁó«7 VìöÇ√˙Ç™
k”:;kÀAõ{*¡€Î˚˚[;;";
$model =& new AppModel(array('name' => 'BinaryTest', 'ds' => 'test_suite'));
$model->save(compact('data'));
$result = $model->find('first');
$this->assertEqual($result['BinaryTest']['data'], $data);
}
/**
* test altering the table settings with schema.

View file

@ -139,7 +139,7 @@ class MysqliTestModel extends Model {
* @subpackage cake.tests.cases.libs.model.datasources.dbo
*/
class DboMysqliTest extends CakeTestCase {
var $fixtures = array('core.datatype');
/**
* The Dbo instance to be tested
*
@ -164,8 +164,6 @@ class DboMysqliTest extends CakeTestCase {
* @access public
*/
function setUp() {
$db = ConnectionManager::getDataSource('test_suite');
$this->db = new DboMysqliTestDb($db->config);
$this->model = new MysqliTestModel();
}
@ -175,7 +173,8 @@ class DboMysqliTest extends CakeTestCase {
* @access public
*/
function tearDown() {
unset($this->db);
unset($this->model);
ClassRegistry::flush();
}
/**
@ -185,7 +184,7 @@ class DboMysqliTest extends CakeTestCase {
* @access public
*/
function testIndexDetection() {
$this->db->cacheSources = $this->db->testing = false;
$this->db->cacheSources = false;
$name = $this->db->fullTableName('simple');
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));');
@ -306,6 +305,16 @@ class DboMysqliTest extends CakeTestCase {
$result = $this->db->commit($this->model);
$this->assertTrue($result);
}
/**
* test that float values are correctly identified
*
* @return void
**/
function testFloatParsing() {
$model =& new Model(array('ds' => 'test_suite', 'table' => 'datatypes', 'name' => 'Datatype'));
$result = $this->db->describe($model);
$this->assertEqual((string)$result['float_field']['length'], '5,2');
}
/**
* test that tableParameters like collation, charset and engine are functioning.

View file

@ -315,11 +315,11 @@ class DboPostgresTest extends CakeTestCase {
}
/**
* test that date columns do not generate errors with null and nullish values.
* test that date and time columns do not generate errors with null and nullish values.
*
* @return void
**/
function testDateAsNull() {
function testDateAndTimeAsNull() {
$this->assertEqual($this->db2->value(null, 'date'), 'NULL');
$this->assertEqual($this->db2->value('', 'date'), 'NULL');
@ -328,6 +328,9 @@ class DboPostgresTest extends CakeTestCase {
$this->assertEqual($this->db2->value('', 'timestamp'), 'NULL');
$this->assertEqual($this->db2->value(null, 'timestamp'), 'NULL');
$this->assertEqual($this->db2->value('', 'time'), 'NULL');
$this->assertEqual($this->db2->value(null, 'time'), 'NULL');
}
/**

View file

@ -222,6 +222,78 @@ class DboSqliteTest extends CakeTestCase {
Configure::write('Cache.disable', true);
}
/**
* test building columns with SQLite
*
* @return void
**/
function testBuildColumn() {
$data = array(
'name' => 'int_field',
'type' => 'integer',
'null' => false,
);
$result = $this->db->buildColumn($data);
$expected = '"int_field" integer(11) NOT NULL';
$this->assertEqual($result, $expected);
$data = array(
'name' => 'name',
'type' => 'string',
'length' => 20,
'null' => false,
);
$result = $this->db->buildColumn($data);
$expected = '"name" varchar(20) NOT NULL';
$this->assertEqual($result, $expected);
$data = array(
'name' => 'testName',
'type' => 'string',
'length' => 20,
'default' => null,
'null' => true,
'collate' => 'NOCASE'
);
$result = $this->db->buildColumn($data);
$expected = '"testName" varchar(20) DEFAULT NULL COLLATE NOCASE';
$this->assertEqual($result, $expected);
$data = array(
'name' => 'testName',
'type' => 'string',
'length' => 20,
'default' => 'test-value',
'null' => false,
);
$result = $this->db->buildColumn($data);
$expected = '"testName" varchar(20) DEFAULT \'test-value\' NOT NULL';
$this->assertEqual($result, $expected);
$data = array(
'name' => 'testName',
'type' => 'integer',
'length' => 10,
'default' => 10,
'null' => false,
);
$result = $this->db->buildColumn($data);
$expected = '"testName" integer(10) DEFAULT \'10\' NOT NULL';
$this->assertEqual($result, $expected);
$data = array(
'name' => 'testName',
'type' => 'integer',
'length' => 10,
'default' => 10,
'null' => false,
'collate' => 'BADVALUE'
);
$result = $this->db->buildColumn($data);
$expected = '"testName" integer(10) DEFAULT \'10\' NOT NULL';
$this->assertEqual($result, $expected);
}
/**
* test describe() and normal results.
*

View file

@ -3591,16 +3591,16 @@ class DboSourceTest extends CakeTestCase {
);
$this->testDb->buildColumn($data);
$this->testDb->columns = array('varchar(255)' => 1);
$data = array(
'name' => 'testName',
'type' => 'varchar(255)',
'type' => 'string',
'length' => 255,
'default',
'null' => true,
'key'
);
$result = $this->testDb->buildColumn($data);
$expected = '`testName` DEFAULT NULL';
$expected = '`testName` varchar(255) DEFAULT NULL';
$this->assertEqual($result, $expected);
$data = array(
@ -3612,7 +3612,37 @@ class DboSourceTest extends CakeTestCase {
$this->testDb->columns = array('integer' => array('name' => 'int', 'limit' => '11', 'formatter' => 'intval'), );
$result = $this->testDb->buildColumn($data);
$expected = '`int_field` int(11) NOT NULL';
$this->assertTrue($result, $expected);
$this->assertEqual($result, $expected);
$this->testDb->fieldParameters['param'] = array(
'value' => 'COLLATE',
'quote' => false,
'join' => ' ',
'column' => 'Collate',
'position' => 'beforeDefault',
'options' => array('GOOD', 'OK')
);
$data = array(
'name' => 'int_field',
'type' => 'integer',
'default' => '',
'null' => false,
'param' => 'BAD'
);
$result = $this->testDb->buildColumn($data);
$expected = '`int_field` int(11) NOT NULL';
$this->assertEqual($result, $expected);
$data = array(
'name' => 'int_field',
'type' => 'integer',
'default' => '',
'null' => false,
'param' => 'GOOD'
);
$result = $this->testDb->buildColumn($data);
$expected = '`int_field` int(11) COLLATE GOOD NOT NULL';
$this->assertEqual($result, $expected);
}
/**
@ -3623,11 +3653,11 @@ class DboSourceTest extends CakeTestCase {
function testHasAny() {
$this->testDb->hasAny($this->Model, array());
$expected = 'SELECT COUNT(`TestModel`.`id`) AS count FROM `test_models` AS `TestModel` WHERE 1 = 1';
$this->assertEqual($this->testDb->simulated[1], $expected);
$this->assertEqual(end($this->testDb->simulated), $expected);
$this->testDb->hasAny($this->Model, array('TestModel.name' => 'harry'));
$expected = "SELECT COUNT(`TestModel`.`id`) AS count FROM `test_models` AS `TestModel` WHERE `TestModel`.`name` = 'harry'";
$this->assertEqual($this->testDb->simulated[2], $expected);
$this->assertEqual(end($this->testDb->simulated), $expected);
}
/**
@ -4017,6 +4047,23 @@ class DboSourceTest extends CakeTestCase {
$this->assertNotNull($this->db->took, 'Stats were not set %s');
$this->assertNotNull($this->db->affected, 'Stats were not set %s');
}
/**
* test that query() returns boolean values from operations like CREATE TABLE
*
* @return void
**/
function testFetchAllBooleanReturns() {
$name = $this->db->fullTableName('test_query');
$query = "CREATE TABLE {$name} (name varchar(10));";
$result = $this->db->query($query);
$this->assertTrue($result, 'Query did not return a boolean. %s');
$query = "DROP TABLE {$name};";
$result = $this->db->fetchAll($query);
$this->assertTrue($result, 'Query did not return a boolean. %s');
}
/**
* test ShowQuery generation of regular and error messages
*

View file

@ -4805,6 +4805,10 @@ class MultibyteTest extends CakeTestCase {
* @return void
*/
function testUsingMbStrrpos() {
$skip = extension_loaded('mbstring') && version_compare(PHP_VERSION, '5.2.0', '<');
if ($this->skipIf($skip, '%s PHP version does not support $offset parameter in mb_strrpos().')) {
return;
}
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'F';
$result = mb_strrpos($string, $find);

View file

@ -71,6 +71,11 @@ class StringTest extends CakeTestCase {
* @return void
*/
function testInsert() {
$string = 'some string';
$expected = 'some string';
$result = String::insert($string, array());
$this->assertEqual($result, $expected);
$string = '2 + 2 = :sum. Cake is :adjective.';
$expected = '2 + 2 = 4. Cake is yummy.';
$result = String::insert($string, array('sum' => '4', 'adjective' => 'yummy'));

View file

@ -1641,6 +1641,10 @@ class ValidationTest extends CakeTestCase {
* @return void
*/
function testEmailDeep() {
$found = gethostbynamel('example.abcd');
if ($this->skipIf($found, 'Your DNS service responds for non-existant domains, skipping deep email checks. %s')) {
return;
}
$this->assertTrue(Validation::email('abc.efg@cakephp.org', true));
$this->assertFalse(Validation::email('abc.efg@caphpkeinvalid.com', true));
$this->assertFalse(Validation::email('abc@example.abcd', true));

View file

@ -165,6 +165,12 @@ class AjaxHelperTest extends CakeTestCase {
$view =& new View(new AjaxTestController());
ClassRegistry::addObject('view', $view);
ClassRegistry::addObject('PostAjaxTest', new PostAjaxTest());
$this->Ajax->Form->params = array(
'plugin' => null,
'action' => 'view',
'controller' => 'users'
);
}
/**
* tearDown method

File diff suppressed because it is too large Load diff

View file

@ -235,7 +235,7 @@ class JavascriptTest extends CakeTestCase {
* @return void
*/
function testFilteringAndTimestamping() {
if($this->skipIf(!is_writable(JS), "%s JavaScript directory not writable, skipping JS asset timestamp tests.")) {
if ($this->skipIf(!is_writable(JS), 'JavaScript directory not writable, skipping JS asset timestamp tests. %s')) {
return;
}

View file

@ -77,25 +77,24 @@ class TextHelperTest extends CakeTestCase {
$text9 = 'НОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
$this->assertIdentical($this->Text->truncate($text1, 15), 'The quick br...');
$this->assertIdentical($this->Text->truncate($text1, 15, '...', false), 'The quick...');
$this->assertIdentical($this->Text->truncate($text1, 15, array('exact' => false)), 'The quick...');
$this->assertIdentical($this->Text->truncate($text1, 100), 'The quick brown fox jumps over the lazy dog');
$this->assertIdentical($this->Text->truncate($text2, 10, '...'), 'Heiz&ou...');
$this->assertIdentical($this->Text->truncate($text2, 10, '...', false), '...');
$this->assertIdentical($this->Text->truncate($text2, 10), 'Heiz&ou...');
$this->assertIdentical($this->Text->truncate($text2, 10, array('exact' => false)), '...');
$this->assertIdentical($this->Text->truncate($text3, 20), '<b>&copy; 2005-20...');
$this->assertIdentical($this->Text->truncate($text4, 15), '<img src="my...');
$this->assertIdentical($this->Text->truncate($text5, 6, ''), '0<b>1<');
$this->assertIdentical($this->Text->truncate($text1, 15, array('ending' => '...', 'exact' => true, 'considerHtml' => true)), 'The quick br...');
$this->assertIdentical($this->Text->truncate($text1, 15, '...', true, true), 'The quick br...');
$this->assertIdentical($this->Text->truncate($text1, 15, '...', false, true), 'The quick...');
$this->assertIdentical($this->Text->truncate($text2, 10, '...', true, true), 'Heiz&ouml;lr...');
$this->assertIdentical($this->Text->truncate($text2, 10, '...', false, true), '...');
$this->assertIdentical($this->Text->truncate($text3, 20, '...', true, true), '<b>&copy; 2005-2007, Cake...</b>');
$this->assertIdentical($this->Text->truncate($text4, 15, '...', true, true), '<img src="mypic.jpg"> This image ...');
$this->assertIdentical($this->Text->truncate($text4, 45, '...', true, true), '<img src="mypic.jpg"> This image tag is not XHTML conform!<br><hr/><b>But t...</b>');
$this->assertIdentical($this->Text->truncate($text4, 90, '...', true, true), '<img src="mypic.jpg"> This image tag is not XHTML conform!<br><hr/><b>But the following image tag should be conform <img src="mypic.jpg" alt="Me, myself and I" /></b><br />Grea...');
$this->assertIdentical($this->Text->truncate($text5, 6, '', true, true), '0<b>1<i>2<span class="myclass">3</span>4<u>5</u></i></b>');
$this->assertIdentical($this->Text->truncate($text5, 20, '', true, true), $text5);
$this->assertIdentical($this->Text->truncate($text6, 57, '...', false, true), "<p><strong>Extra dates have been announced for this year's...</strong></p>");
$this->assertIdentical($this->Text->truncate($text5, 6, array('ending' => '')), '0<b>1<');
$this->assertIdentical($this->Text->truncate($text1, 15, array('html' => true)), 'The quick br...');
$this->assertIdentical($this->Text->truncate($text1, 15, array('exact' => false, 'html' => true)), 'The quick...');
$this->assertIdentical($this->Text->truncate($text2, 10, array('html' => true)), 'Heiz&ouml;lr...');
$this->assertIdentical($this->Text->truncate($text2, 10, array('exact' => false, 'html' => true)), '...');
$this->assertIdentical($this->Text->truncate($text3, 20, array('html' => true)), '<b>&copy; 2005-2007, Cake...</b>');
$this->assertIdentical($this->Text->truncate($text4, 15, array('html' => true)), '<img src="mypic.jpg"> This image ...');
$this->assertIdentical($this->Text->truncate($text4, 45, array('html' => true)), '<img src="mypic.jpg"> This image tag is not XHTML conform!<br><hr/><b>But t...</b>');
$this->assertIdentical($this->Text->truncate($text4, 90, array('html' => true)), '<img src="mypic.jpg"> This image tag is not XHTML conform!<br><hr/><b>But the following image tag should be conform <img src="mypic.jpg" alt="Me, myself and I" /></b><br />Grea...');
$this->assertIdentical($this->Text->truncate($text5, 6, array('ending' => '', 'html' => true)), '0<b>1<i>2<span class="myclass">3</span>4<u>5</u></i></b>');
$this->assertIdentical($this->Text->truncate($text5, 20, array('ending' => '', 'html' => true)), $text5);
$this->assertIdentical($this->Text->truncate($text6, 57, array('exact' => false, 'html' => true)), "<p><strong>Extra dates have been announced for this year's...</strong></p>");
$this->assertIdentical($this->Text->truncate($text7, 255), $text7);
$this->assertIdentical($this->Text->truncate($text7, 15), 'El moño está...');
$this->assertIdentical($this->Text->truncate($text8, 15), 'Vive la R'.chr(195).chr(169).'pu...');
@ -111,46 +110,47 @@ class TextHelperTest extends CakeTestCase {
function testHighlight() {
$text = 'This is a test text';
$phrases = array('This', 'text');
$result = $this->Text->highlight($text, $phrases, '<b>\1</b>');
$result = $this->Text->highlight($text, $phrases, array('format' => '<b>\1</b>'));
$expected = '<b>This</b> is a test <b>text</b>';
$this->assertEqual($expected, $result);
$text = 'This is a test text';
$phrases = null;
$result = $this->Text->highlight($text, $phrases, '<b>\1</b>');
$result = $this->Text->highlight($text, $phrases, array('format' => '<b>\1</b>'));
$this->assertEqual($result, $text);
$text = 'Ich saß in einem Café am Übergang';
$expected = 'Ich <b>saß</b> in einem <b>Café</b> am <b>Übergang</b>';
$phrases = array('saß', 'café', 'übergang');
$result = $this->Text->highlight($text, $phrases, '<b>\1</b>');
$result = $this->Text->highlight($text, $phrases, array('format' => '<b>\1</b>'));
$this->assertEqual($result, $expected);
}
/**
* testHighlightConsiderHtml method
* testHighlightHtml method
*
* @access public
* @return void
*/
function testHighlightConsiderHtml() {
function testHighlightHtml() {
$text1 = '<p>strongbow isn&rsquo;t real cider</p>';
$text2 = '<p>strongbow <strong>isn&rsquo;t</strong> real cider</p>';
$text3 = '<img src="what-a-strong-mouse.png" alt="What a strong mouse!" />';
$text4 = 'What a strong mouse: <img src="what-a-strong-mouse.png" alt="What a strong mouse!" />';
$options = array('format' => '<b>\1</b>', 'html' => true);
$expected = '<p><b>strong</b>bow isn&rsquo;t real cider</p>';
$this->assertEqual($this->Text->highlight($text1, 'strong', '<b>\1</b>', true), $expected);
$this->assertEqual($this->Text->highlight($text1, 'strong', $options), $expected);
$expected = '<p><b>strong</b>bow <strong>isn&rsquo;t</strong> real cider</p>';
$this->assertEqual($this->Text->highlight($text2, 'strong', '<b>\1</b>', true), $expected);
$this->assertEqual($this->Text->highlight($text2, 'strong', $options), $expected);
$this->assertEqual($this->Text->highlight($text3, 'strong', '<b>\1</b>', true), $text3);
$this->assertEqual($this->Text->highlight($text3, 'strong', $options), $text3);
$this->assertEqual($this->Text->highlight($text3, array('strong', 'what'), '<b>\1</b>', true), $text3);
$this->assertEqual($this->Text->highlight($text3, array('strong', 'what'), $options), $text3);
$expected = '<b>What</b> a <b>strong</b> mouse: <img src="what-a-strong-mouse.png" alt="What a strong mouse!" />';
$this->assertEqual($this->Text->highlight($text4, array('strong', 'what'), '<b>\1</b>', true), $expected);
$this->assertEqual($this->Text->highlight($text4, array('strong', 'what'), $options), $expected);
}
/**
@ -162,7 +162,7 @@ class TextHelperTest extends CakeTestCase {
function testHighlightMulti() {
$text = 'This is a test text';
$phrases = array('This', 'text');
$result = $this->Text->highlight($text, $phrases, array('<b>\1</b>', '<em>\1</em>'));
$result = $this->Text->highlight($text, $phrases, array('format' => array('<b>\1</b>', '<em>\1</em>')));
$expected = '<b>This</b> is a test <em>text</em>';
$this->assertEqual($expected, $result);
@ -286,10 +286,10 @@ class TextHelperTest extends CakeTestCase {
$text = 'This is a Test text';
$expected = 'This is a <b>Test</b> text';
$result = $this->Text->highlight($text, 'test', '<b>\1</b>');
$result = $this->Text->highlight($text, 'test', array('format' => '<b>\1</b>'));
$this->assertEqual($expected, $result);
$result = $this->Text->highlight($text, array('test'), '<b>\1</b>');
$result = $this->Text->highlight($text, array('test'), array('format' => '<b>\1</b>'));
$this->assertEqual($expected, $result);
}

View file

@ -488,57 +488,19 @@ class TimeHelperTest extends CakeTestCase {
* @return void
*/
function testIsThisWeek() {
switch (date('D')) {
case 'Mon' :
for ($i = 0; $i < 6; $i++) {
$this->assertTrue($this->Time->isThisWeek("+$i days"));
}
$this->assertFalse($this->Time->isThisWeek("+7 days"));
$this->assertFalse($this->Time->isThisWeek("-1 days"));
break;
case 'Tue' :
for ($i = -1; $i < 5; $i++) {
$this->assertTrue($this->Time->isThisWeek("+$i days"));
}
$this->assertFalse($this->Time->isThisWeek("+6 days"));
$this->assertFalse($this->Time->isThisWeek("-2 days"));
break;
case 'Wed' :
for ($i = -2; $i < 5; $i++) {
$this->assertTrue($this->Time->isThisWeek("+$i days"));
}
$this->assertFalse($this->Time->isThisWeek("+5 days"));
$this->assertFalse($this->Time->isThisWeek("-3 days"));
break;
case 'Thu' :
for ($i = -3; $i < 4; $i++) {
$this->assertTrue($this->Time->isThisWeek("+$i days"));
}
$this->assertFalse($this->Time->isThisWeek("+4 days"));
$this->assertFalse($this->Time->isThisWeek("-4 days"));
break;
case 'Fri' :
for ($i = -4; $i < 3; $i++) {
$this->assertTrue($this->Time->isThisWeek("+$i days"));
}
$this->assertFalse($this->Time->isThisWeek("+3 days"));
$this->assertFalse($this->Time->isThisWeek("-5 days"));
break;
case 'Sat' :
for ($i = -5; $i < 2; $i++) {
$this->assertTrue($this->Time->isThisWeek("+$i days"));
}
$this->assertFalse($this->Time->isThisWeek("+2 days"));
$this->assertFalse($this->Time->isThisWeek("-6 days"));
break;
case 'Sun' :
for ($i = -6; $i < 1; $i++) {
$this->assertTrue($this->Time->isThisWeek("+$i days"));
}
$this->assertFalse($this->Time->isThisWeek("+1 days"));
$this->assertFalse($this->Time->isThisWeek("-7 days"));
break;
// A map of days which goes from -1 day of week to +1 day of week
$map = array(
'Mon' => array(-1, 7), 'Tue' => array(-2, 6), 'Wed' => array(-3, 5),
'Thu' => array(-4, 4), 'Fri' => array(-5, 3), 'Sat' => array(-6, 2),
'Sun' => array(-7, 1)
);
$days = $map[date('D')];
for ($day = $days[0] + 1; $day < $days[1]; $day++) {
$this->assertTrue($this->Time->isThisWeek(($day > 0 ? '+' : '') . $day . ' days'));
}
$this->assertFalse($this->Time->isThisWeek($days[0] . ' days'));
$this->assertFalse($this->Time->isThisWeek('+' . $days[1] . ' days'));
}
/**
@ -660,6 +622,11 @@ class TimeHelperTest extends CakeTestCase {
* @return void
*/
function testUserOffset() {
if ($this->skipIf(!class_exists('DateTimeZone'), '%s DateTimeZone class not available.')) {
return;
}
$timezoneServer = new DateTimeZone(date_default_timezone_get());
$timeServer = new DateTime('now', $timezoneServer);
$yourTimezone = $timezoneServer->getOffset($timeServer) / HOUR;

View file

@ -46,7 +46,24 @@ class ConsoleGroupTest extends TestSuite {
* @return void
*/
function ConsoleGroupTest() {
TestManager::addTestCasesFromDirectory($this, CORE_TEST_CASES . DS . 'console');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'console' . DS . 'cake');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'console' . DS . 'libs' . DS . 'acl');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'console' . DS . 'libs' . DS . 'api');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'console' . DS . 'libs' . DS . 'bake');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'console' . DS . 'libs' . DS . 'schema');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'console' . DS . 'libs' . DS . 'shell');
$path = CORE_TEST_CASES . DS . 'console' . DS . 'libs' . DS . 'tasks' . DS;
TestManager::addTestFile($this, $path . 'controller');
TestManager::addTestFile($this, $path . 'model');
TestManager::addTestFile($this, $path . 'view');
TestManager::addTestFile($this, $path . 'fixture');
TestManager::addTestFile($this, $path . 'test');
TestManager::addTestFile($this, $path . 'db_config');
TestManager::addTestFile($this, $path . 'plugin');
TestManager::addTestFile($this, $path . 'project');
}
}
?>

View file

@ -35,8 +35,7 @@ class ControllerGroupTest extends TestSuite {
* @var string 'All cake/libs/controller/* (Not yet implemented)'
* @access public
*/
var $label = 'All Controllers and Components';
var $label = 'Component, Controllers, Scaffold test cases.';
/**
* LibControllerGroupTest method
*
@ -44,7 +43,11 @@ class ControllerGroupTest extends TestSuite {
* @return void
*/
function ControllerGroupTest() {
TestManager::addTestCasesFromDirectory($this, CORE_TEST_CASES . DS . 'libs' . DS . 'controller');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'controller' . DS . 'controller');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'controller' . DS . 'scaffold');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'controller' . DS . 'pages_controller');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'controller' . DS . 'component');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'controller' . DS . 'controller_merge_vars');
}
}
?>

View file

@ -46,9 +46,9 @@ class LibGroupTest extends TestSuite {
* @return void
*/
function LibGroupTest() {
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'inflector');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'cake_log');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'class_registry');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'inflector');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'overloadable');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'sanitize');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'security');

View file

@ -1,58 +0,0 @@
<?php
/**
* NoDatabaseGroupTest file
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake
* @subpackage cake.tests.groups
* @since CakePHP(tm) v 1.2.0.4206
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
/**
* NoDatabaseGroupTest class
*
* This test group will run all test in the cases/libs directory.
*
* @package cake
* @subpackage cake.tests.groups
*/
class NoDatabaseGroupTest extends TestSuite {
/**
* label property
*
* @var string 'All tests without a database connection'
* @access public
*/
var $label = 'All Libs not requiring a database connection';
/**
* NoDatabaseGroupTest method
*
* @access public
* @return void
*/
function NoDatabaseGroupTest() {
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'dispatcher');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'router');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'inflector');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'validation');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'cake_session');
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'cake_socket');
TestManager::addTestCasesFromDirectory($this, CORE_TEST_CASES . DS . 'libs' . DS . 'view');
}
}
?>

View file

@ -0,0 +1,60 @@
<?php
class CakeTextReporter extends TextReporter {
var $_timeStart = 0;
var $_timeEnd = 0;
var $_timeDuration = 0;
/**
* Signals / Paints the beginning of a TestSuite executing.
* Starts the timer for the TestSuite execution time.
*
* @param
* @return void
**/
function paintGroupStart($test_name, $size) {
if (empty($this->_timeStart)) {
$this->_timeStart = $this->_getTime();
}
parent::paintGroupStart($test_name, $size);
}
/**
* Signals/Paints the end of a TestSuite. All test cases have run
* and timers are stopped.
*
* @return void
**/
function paintGroupEnd($test_name) {
$this->_timeEnd = $this->_getTime();
$this->_timeDuration = $this->_timeEnd - $this->_timeStart;
parent::paintGroupEnd($test_name);
}
/**
* Get the current time in microseconds. Similar to getMicrotime in basics.php
* but in a separate function to reduce dependancies.
*
* @return float Time in microseconds
**/
function _getTime() {
list($usec, $sec) = explode(' ', microtime());
return ((float)$sec + (float)$usec);
}
/**
* Paints the end of the test with a summary of
* the passes and failures.
*
* @param string $test_name Name class of test.
* @access public
*/
function paintFooter($test_name) {
parent::paintFooter($test_name);
echo 'Time taken by tests (in seconds): ' . $this->_timeDuration . "\n";
if (function_exists('memory_get_peak_usage')) {
echo 'Peak memory use: (in bytes): ' . number_format(memory_get_peak_usage()) . "\n";
}
}
}
?>

View file

@ -790,4 +790,4 @@ class CodeCoverageManager {
return false;
}
}
?>
?>

View file

@ -637,7 +637,8 @@ if (function_exists('caketestsgetreporter')) {
$Reporter =& new CakeHtmlReporter();
break;
default:
$Reporter =& new TextReporter();
require_once CAKE_TESTS_LIB . 'cake_text_reporter.php';
$Reporter =& new CakeTextReporter();
break;
}
}