diff --git a/cake/console/libs/bake.php b/cake/console/libs/bake.php index f99010c4c..7f1f0ad67 100644 --- a/cake/console/libs/bake.php +++ b/cake/console/libs/bake.php @@ -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; } } diff --git a/cake/console/libs/tasks/extract.php b/cake/console/libs/tasks/extract.php index e5c67d67c..31f0b29c3 100644 --- a/cake/console/libs/tasks/extract.php +++ b/cake/console/libs/tasks/extract.php @@ -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 ...', 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); } } diff --git a/cake/console/libs/tasks/fixture.php b/cake/console/libs/tasks/fixture.php index f91b6d3c4..dc55c8720 100644 --- a/cake/console/libs/tasks/fixture.php +++ b/cake/console/libs/tasks/fixture.php @@ -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(); } diff --git a/cake/console/libs/templates/skel/views/layouts/xml/default.ctp b/cake/console/libs/templates/skel/views/layouts/xml/default.ctp new file mode 100644 index 000000000..566ca2158 --- /dev/null +++ b/cake/console/libs/templates/skel/views/layouts/xml/default.ctp @@ -0,0 +1,2 @@ +header(); ?> + \ No newline at end of file diff --git a/cake/console/templates/skel/views/layouts/default.ctp b/cake/console/templates/skel/views/layouts/default.ctp index 047439e7a..5d61adc1b 100644 --- a/cake/console/templates/skel/views/layouts/default.ctp +++ b/cake/console/templates/skel/views/layouts/default.ctp @@ -55,7 +55,7 @@ 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) ); ?> diff --git a/cake/libs/cake_session.php b/cake/libs/cake_session.php index 71e05a1cb..d118ef431 100644 --- a/cake/libs/cake_session.php +++ b/cake/libs/cake_session.php @@ -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); diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index 40ac1fe3f..d22c9d627 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -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), diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index ebad2baa1..bd7b8e69a 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -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 diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index 3490c7169..234ea3053 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -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: - * - * var $scaffold; - * - * 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') { diff --git a/cake/libs/debugger.php b/cake/libs/debugger.php index 1e4c47ee0..83fb14294 100644 --- a/cake/libs/debugger.php +++ b/cake/libs/debugger.php @@ -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)); } /** diff --git a/cake/libs/folder.php b/cake/libs/folder.php index f36123ec4..69af1434d 100644 --- a/cake/libs/folder.php +++ b/cake/libs/folder.php @@ -326,7 +326,7 @@ class Folder extends Object { * @static */ function addPathElement($path, $element) { - return Folder::slashTerm($path) . $element; + return rtrim($path, DS) . DS . $element; } /** diff --git a/cake/libs/http_socket.php b/cake/libs/http_socket.php index 8367ce6b3..a31b89131 100644 --- a/cake/libs/http_socket.php +++ b/cake/libs/http_socket.php @@ -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; diff --git a/cake/libs/model/behaviors/tree.php b/cake/libs/model/behaviors/tree.php index c1d51bb85..0466ff224 100644 --- a/cake/libs/model/behaviors/tree.php +++ b/cake/libs/model/behaviors/tree.php @@ -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; } diff --git a/cake/libs/model/datasources/datasource.php b/cake/libs/model/datasources/datasource.php index e94fa50a5..4ada77bff 100644 --- a/cake/libs/model/datasources/datasource.php +++ b/cake/libs/model/datasources/datasource.php @@ -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) * diff --git a/cake/libs/model/datasources/dbo/dbo_adodb.php b/cake/libs/model/datasources/dbo/dbo_adodb.php index a43581f8a..8e2931d8e 100644 --- a/cake/libs/model/datasources/dbo/dbo_adodb.php +++ b/cake/libs/model/datasources/dbo/dbo_adodb.php @@ -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. * diff --git a/cake/libs/model/datasources/dbo/dbo_db2.php b/cake/libs/model/datasources/dbo/dbo_db2.php index 873fa8ec0..55b25010e 100644 --- a/cake/libs/model/datasources/dbo/dbo_db2.php +++ b/cake/libs/model/datasources/dbo/dbo_db2.php @@ -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. * diff --git a/cake/libs/model/datasources/dbo/dbo_firebird.php b/cake/libs/model/datasources/dbo/dbo_firebird.php index faab0920d..4243097c8 100644 --- a/cake/libs/model/datasources/dbo/dbo_firebird.php +++ b/cake/libs/model/datasources/dbo/dbo_firebird.php @@ -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. * diff --git a/cake/libs/model/datasources/dbo/dbo_mssql.php b/cake/libs/model/datasources/dbo/dbo_mssql.php index de8db0a60..11c819d52 100644 --- a/cake/libs/model/datasources/dbo/dbo_mssql.php +++ b/cake/libs/model/datasources/dbo/dbo_mssql.php @@ -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. * diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php index 316edcc2c..86de93b10 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysql.php +++ b/cake/libs/model/datasources/dbo/dbo_mysql.php @@ -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. * diff --git a/cake/libs/model/datasources/dbo/dbo_mysqli.php b/cake/libs/model/datasources/dbo/dbo_mysqli.php index ec5f05fb3..6777dbca1 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysqli.php +++ b/cake/libs/model/datasources/dbo/dbo_mysqli.php @@ -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... * diff --git a/cake/libs/model/datasources/dbo/dbo_odbc.php b/cake/libs/model/datasources/dbo/dbo_odbc.php index e24daf7ce..9f73dd140 100644 --- a/cake/libs/model/datasources/dbo/dbo_odbc.php +++ b/cake/libs/model/datasources/dbo/dbo_odbc.php @@ -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. * diff --git a/cake/libs/model/datasources/dbo/dbo_postgres.php b/cake/libs/model/datasources/dbo/dbo_postgres.php index d8787a018..0e6ac7be9 100644 --- a/cake/libs/model/datasources/dbo/dbo_postgres.php +++ b/cake/libs/model/datasources/dbo/dbo_postgres.php @@ -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'; } diff --git a/cake/libs/model/datasources/dbo/dbo_sqlite.php b/cake/libs/model/datasources/dbo/dbo_sqlite.php index aa6311be3..552096bec 100644 --- a/cake/libs/model/datasources/dbo/dbo_sqlite.php +++ b/cake/libs/model/datasources/dbo/dbo_sqlite.php @@ -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); } /** diff --git a/cake/libs/model/datasources/dbo/dbo_sybase.php b/cake/libs/model/datasources/dbo/dbo_sybase.php index db345ea08..7a56220aa 100644 --- a/cake/libs/model/datasources/dbo/dbo_sybase.php +++ b/cake/libs/model/datasources/dbo/dbo_sybase.php @@ -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. * diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 141364da8..46afa587d 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -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; } /** diff --git a/cake/libs/string.php b/cake/libs/string.php index fcfa76d91..15bd9cb6f 100644 --- a/cake/libs/string.php +++ b/cake/libs/string.php @@ -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( diff --git a/cake/libs/validation.php b/cake/libs/validation.php index 59cf68c08..98e7d3c55 100644 --- a/cake/libs/validation.php +++ b/cake/libs/validation.php @@ -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. * diff --git a/cake/libs/view/helpers/cache.php b/cake/libs/view/helpers/cache.php index 1da01dd44..af1af442d 100644 --- a/cake/libs/view/helpers/cache.php +++ b/cake/libs/view/helpers/cache.php @@ -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); } } - ?> \ No newline at end of file diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 88e71791b..d93f9748b 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -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 { diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index 1cc614532..3a71d0a66 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -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'. */ diff --git a/cake/libs/view/helpers/text.php b/cake/libs/view/helpers/text.php index d6f88d4fc..6159c4962 100644 --- a/cake/libs/view/helpers/text.php +++ b/cake/libs/view/helpers/text.php @@ -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 = '\1', $considerHtml = false) { + function highlight($text, $phrase, $options = array()) { if (empty($phrase)) { return $text; } - if (is_array($phrase)) { + $default = array( + 'format' => '\1', + '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('#(?)((?: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('#(?)(?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 ( $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 .= ''; } @@ -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); diff --git a/cake/libs/view/layouts/default.ctp b/cake/libs/view/layouts/default.ctp index 0b326d6c0..93b0e441a 100644 --- a/cake/libs/view/layouts/default.ctp +++ b/cake/libs/view/layouts/default.ctp @@ -55,7 +55,7 @@ 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) ); ?> diff --git a/cake/tests/cases/console/libs/api.test.php b/cake/tests/cases/console/libs/api.test.php index 2ad67d2a0..dc977006f 100644 --- a/cake/tests/cases/console/libs/api.test.php +++ b/cake/tests/cases/console/libs/api.test.php @@ -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)', diff --git a/cake/tests/cases/console/libs/tasks/model.test.php b/cake/tests/cases/console/libs/tasks/model.test.php index d4c84a0eb..431fb4130 100644 --- a/cake/tests/cases/console/libs/tasks/model.test.php +++ b/cake/tests/cases/console/libs/tasks/model.test.php @@ -1,6 +1,7 @@ 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)); diff --git a/cake/tests/cases/libs/cake_test_case.test.php b/cake/tests/cases/libs/cake_test_case.test.php index 90f59686e..e57c19718 100644 --- a/cake/tests/cases/libs/cake_test_case.test.php +++ b/cake/tests/cases/libs/cake_test_case.test.php @@ -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); } diff --git a/cake/tests/cases/libs/code_coverage_manager.test.php b/cake/tests/cases/libs/code_coverage_manager.test.php index 97c22a915..74722ab4d 100644 --- a/cake/tests/cases/libs/code_coverage_manager.test.php +++ b/cake/tests/cases/libs/code_coverage_manager.test.php @@ -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 diff --git a/cake/tests/cases/libs/controller/component.test.php b/cake/tests/cases/libs/controller/component.test.php index 459ead972..067972e85 100644 --- a/cake/tests/cases/libs/controller/component.test.php +++ b/cake/tests/cases/libs/controller/component.test.php @@ -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'))); } + } ?> \ No newline at end of file diff --git a/cake/tests/cases/libs/controller/components/email.test.php b/cake/tests/cases/libs/controller/components/email.test.php index d010c0f08..1560080a1 100644 --- a/cake/tests/cases/libs/controller/components/email.test.php +++ b/cake/tests/cases/libs/controller/components/email.test.php @@ -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 = << - EmailTest + Email Test @@ -425,7 +423,6 @@ TEXTBLOC;

This email was sent using the CakePHP Framework

- HTMLBLOC; $this->Controller->EmailTest->sendAs = 'text'; @@ -452,7 +449,7 @@ HTMLBLOC; - EmailTest + Email Test @@ -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'; diff --git a/cake/tests/cases/libs/controller/components/request_handler.test.php b/cake/tests/cases/libs/controller/components/request_handler.test.php index cc702d48e..f8a971734 100644 --- a/cake/tests/cases/libs/controller/components/request_handler.test.php +++ b/cake/tests/cases/libs/controller/components/request_handler.test.php @@ -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(); } } ?> \ No newline at end of file diff --git a/cake/tests/cases/libs/controller/components/security.test.php b/cake/tests/cases/libs/controller/components/security.test.php index 7b2fc0444..965f2235d 100644 --- a/cake/tests/cases/libs/controller/components/security.test.php +++ b/cake/tests/cases/libs/controller/components/security.test.php @@ -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'); diff --git a/cake/tests/cases/libs/controller/controller.test.php b/cake/tests/cases/libs/controller/controller.test.php index bd1041da9..4c200d1e9 100644 --- a/cake/tests/cases/libs/controller/controller.test.php +++ b/cake/tests/cases/libs/controller/controller.test.php @@ -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(); } /** diff --git a/cake/tests/cases/libs/controller/controller_merge_vars.test.php b/cake/tests/cases/libs/controller/controller_merge_vars.test.php index aec73d884..e7929f4ad 100644 --- a/cake/tests/cases/libs/controller/controller_merge_vars.test.php +++ b/cake/tests/cases/libs/controller/controller_merge_vars.test.php @@ -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 * diff --git a/cake/tests/cases/libs/controller/scaffold.test.php b/cake/tests/cases/libs/controller/scaffold.test.php index 3d6f5f64b..c0a4a0fcd 100644 --- a/cake/tests/cases/libs/controller/scaffold.test.php +++ b/cake/tests/cases/libs/controller/scaffold.test.php @@ -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('/
/', $result); + $this->assertPattern('/assertPattern('/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('/
  • ]*>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('/
  • 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('/

    Scaffold Mock<\/h2>/', $result); + $this->assertPattern('//', $result); + //TODO: add testing for table generation + $this->assertPattern('/
  • New Scaffold Mock<\/a><\/li>/', $result); + + Configure::write('Routing.prefixes', $_backAdmin); + } + } /** diff --git a/cake/tests/cases/libs/debugger.test.php b/cake/tests/cases/libs/debugger.test.php index f9c97e481..9ddcad781 100644 --- a/cake/tests/cases/libs/debugger.test.php +++ b/cake/tests/cases/libs/debugger.test.php @@ -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); diff --git a/cake/tests/cases/libs/folder.test.php b/cake/tests/cases/libs/folder.test.php index b778008cb..97e3ad500 100644 --- a/cake/tests/cases/libs/folder.test.php +++ b/cake/tests/cases/libs/folder.test.php @@ -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 * diff --git a/cake/tests/cases/libs/http_socket.test.php b/cake/tests/cases/libs/http_socket.test.php index 6389823d4..1f58ab99c 100644 --- a/cake/tests/cases/libs/http_socket.test.php +++ b/cake/tests/cases/libs/http_socket.test.php @@ -1026,6 +1026,28 @@ class HttpSocketTest extends CakeTestCase { 'host' => 'www.google.com', 'port' => 8080, )); + + $uri = $this->Socket->parseUri('http://www.cakephp.org/?param1=value1¶m2=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¶m2=value2=value3'); + $this->assertIdentical($uri, array( + 'scheme' => 'http', + 'host' => 'www.cakephp.org', + 'path' => '/', + 'query' => array( + 'param1' => 'value1', + 'param2' => 'value2=value3' + ) + )); } /** diff --git a/cake/tests/cases/libs/i18n.test.php b/cake/tests/cases/libs/i18n.test.php index 3e849e07a..a32d205b3 100644 --- a/cake/tests/cases/libs/i18n.test.php +++ b/cake/tests/cases/libs/i18n.test.php @@ -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; } diff --git a/cake/tests/cases/libs/model/behaviors/tree.test.php b/cake/tests/cases/libs/model/behaviors/tree.test.php index 6376e27a4..95322c314 100644 --- a/cake/tests/cases/libs/model/behaviors/tree.test.php +++ b/cake/tests/cases/libs/model/behaviors/tree.test.php @@ -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 * diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php index 0159480cb..5b96b9790 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php @@ -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:¯Ü‚Héá¶jV∂ÓúÎL≥çÀóËıÎ…>ï≈ vFE%ÒâLFI<†µw˝±≈£7˘ç^H“≤« >Éâ*∑ÇnÖA•Ù|flêèj£:=ÿ6óUàµ5'∂®àA¬ñ∆ˆGE(gt’≈àÚyÁó«7 ‚VìöÇ√˙Ç™ + k”:;kÀAõ{*¡€Î˚˚[;;"; + + $model =& new AppModel(array('name' => 'BinaryTest', 'ds' => 'test_suite')); + $model->save(compact('data')); + + $result = $model->find('first'); + $this->assertEqual($result['BinaryTest']['data'], $data); + } /** * test altering the table settings with schema. diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php index eed93c09a..d9f8c0c62 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php @@ -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. diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php index 936a931e7..e13466ecb 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php @@ -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'); } /** diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_sqlite.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_sqlite.test.php index 75acb73e6..51ede159b 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_sqlite.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_sqlite.test.php @@ -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. * diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index fa98837ae..9e5c08d1f 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -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 * diff --git a/cake/tests/cases/libs/multibyte.test.php b/cake/tests/cases/libs/multibyte.test.php index 44f59d41b..64a75288a 100644 --- a/cake/tests/cases/libs/multibyte.test.php +++ b/cake/tests/cases/libs/multibyte.test.php @@ -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); diff --git a/cake/tests/cases/libs/string.test.php b/cake/tests/cases/libs/string.test.php index 52ac2867c..e17a5b895 100644 --- a/cake/tests/cases/libs/string.test.php +++ b/cake/tests/cases/libs/string.test.php @@ -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')); diff --git a/cake/tests/cases/libs/validation.test.php b/cake/tests/cases/libs/validation.test.php index 278c262dd..07edecf57 100644 --- a/cake/tests/cases/libs/validation.test.php +++ b/cake/tests/cases/libs/validation.test.php @@ -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)); diff --git a/cake/tests/cases/libs/view/helpers/ajax.test.php b/cake/tests/cases/libs/view/helpers/ajax.test.php index 233d1fa00..12cf40c85 100644 --- a/cake/tests/cases/libs/view/helpers/ajax.test.php +++ b/cake/tests/cases/libs/view/helpers/ajax.test.php @@ -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 diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 5c5995631..ecc84393d 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -666,6 +666,7 @@ class FormHelperTest extends CakeTestCase { $this->Form->Html =& new HtmlHelper(); $this->Controller =& new ContactTestController(); $this->View =& new View($this->Controller); + $this->Form->params['action'] = 'add'; ClassRegistry::addObject('view', $view); ClassRegistry::addObject('Contact', new Contact()); @@ -720,12 +721,12 @@ class FormHelperTest extends CakeTestCase { * @access public * @return void */ - function testFormCreateWithSecurity() { + function testCreateWithSecurity() { $this->Form->params['_Token'] = array('key' => 'testKey'); - + $encoding = strtolower(Configure::read('App.encoding')); $result = $this->Form->create('Contact', array('url' => '/contacts/add')); $expected = array( - 'form' => array('method' => 'post', 'action' => '/contacts/add'), + 'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding), 'fieldset' => array('style' => 'display:none;'), array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')), array('input' => array( @@ -733,7 +734,7 @@ class FormHelperTest extends CakeTestCase { )), '/fieldset' ); - $this->assertTags($result, $expected); + $this->assertTags($result, $expected,true); $result = $this->Form->create('Contact', array('url' => '/contacts/add', 'id' => 'MyForm')); $expected['form']['id'] = 'MyForm'; @@ -1077,8 +1078,9 @@ class FormHelperTest extends CakeTestCase { $this->Form->params['_Token']['key'] = 'testKey'; $result = $this->Form->create('Contact', array('url' => '/contacts/add')); + $encoding = strtolower(Configure::read('App.encoding')); $expected = array( - 'form' => array('method' => 'post', 'action' => '/contacts/add'), + 'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding), 'fieldset' => array('style' => 'display:none;'), array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')), array('input' => array( @@ -1274,9 +1276,11 @@ class FormHelperTest extends CakeTestCase { $this->assertFalse($this->UserForm->OpenidUrl->validates()); $result = $this->Form->create('UserForm', array('type' => 'post', 'action' => 'login')); + $encoding = strtolower(Configure::read('App.encoding')); $expected = array( 'form' => array( - 'method' => 'post', 'action' => '/user_forms/login/', 'id' => 'UserFormLoginForm' + 'method' => 'post', 'action' => '/user_forms/login/', 'id' => 'UserFormLoginForm', + 'accept-charset' => $encoding ), 'fieldset' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), @@ -1317,8 +1321,9 @@ class FormHelperTest extends CakeTestCase { $this->assertFalse($this->ValidateUser->ValidateProfile->validates()); $result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add')); + $encoding = strtolower(Configure::read('App.encoding')); $expected = array( - 'form' => array('method' => 'post', 'action' => '/validate_users/add/', 'id'), + 'form' => array('method' => 'post', 'action' => '/validate_users/add/', 'id','accept-charset' => $encoding), 'fieldset' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/fieldset' @@ -1360,8 +1365,9 @@ class FormHelperTest extends CakeTestCase { $this->assertFalse($this->ValidateUser->ValidateProfile->ValidateItem->validates()); $result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add')); + $encoding = strtolower(Configure::read('App.encoding')); $expected = array( - 'form' => array('method' => 'post', 'action' => '/validate_users/add/', 'id'), + 'form' => array('method' => 'post', 'action' => '/validate_users/add/', 'id','accept-charset' => $encoding), 'fieldset' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/fieldset' @@ -1503,14 +1509,14 @@ class FormHelperTest extends CakeTestCase { } /** - * testFormInput method + * testInput method * * Test various incarnations of input(). * * @access public * @return void */ - function testFormInput() { + function testInput() { $result = $this->Form->input('ValidateUser.balance'); $expected = array( 'div' => array('class'), @@ -1585,50 +1591,6 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $result = $this->Form->input('email', array( - 'options' => array('è' => 'Firést', 'é' => 'Secoènd'), 'empty' => true) - ); - $expected = array( - 'div' => array('class' => 'input select'), - 'label' => array('for' => 'email'), - 'Email', - '/label', - array('select' => array('name' => 'data[email]', 'id' => 'email')), - array('option' => array('value' => '')), - '/option', - array('option' => array('value' => 'è')), - 'Firést', - '/option', - array('option' => array('value' => 'é')), - 'Secoènd', - '/option', - '/select', - '/div' - ); - $this->assertTags($result, $expected); - - $result = $this->Form->input('email', array( - 'options' => array('First', 'Second'), 'empty' => true) - ); - $expected = array( - 'div' => array('class' => 'input select'), - 'label' => array('for' => 'email'), - 'Email', - '/label', - array('select' => array('name' => 'data[email]', 'id' => 'email')), - array('option' => array('value' => '')), - '/option', - array('option' => array('value' => '0')), - 'First', - '/option', - array('option' => array('value' => '1')), - 'Second', - '/option', - '/select', - '/div' - ); - $this->assertTags($result, $expected); - $result = $this->Form->input('Contact.email', array( 'type' => 'file', 'class' => 'textbox' )); @@ -1645,84 +1607,6 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24)); - $result = explode(':', $result); - $this->assertPattern('/option value="23"/', $result[0]); - $this->assertNoPattern('/option value="24"/', $result[0]); - - $result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24)); - $result = explode(':', $result); - $this->assertPattern('/option value="23"/', $result[0]); - $this->assertNoPattern('/option value="24"/', $result[0]); - - $result = $this->Form->input('Model.field', array( - 'type' => 'time', 'timeFormat' => 24, 'interval' => 15 - )); - $result = explode(':', $result); - $this->assertNoPattern('##', $result[1]); - $this->assertNoPattern('##', $result[1]); - $this->assertPattern('##', $result[1]); - - $result = $this->Form->input('Model.field', array( - 'type' => 'time', 'timeFormat' => 12, 'interval' => 15 - )); - $result = explode(':', $result); - $this->assertNoPattern('##', $result[1]); - $this->assertNoPattern('##', $result[1]); - $this->assertPattern('##', $result[1]); - - $result = $this->Form->input('prueba', array( - 'type' => 'time', 'timeFormat'=> 24 , 'dateFormat'=>'DMY' , 'minYear' => 2008, - 'maxYear' => date('Y') + 1 ,'interval' => 15 - )); - $result = explode(':', $result); - $this->assertNoPattern('##', $result[1]); - $this->assertNoPattern('##', $result[1]); - $this->assertPattern('##', $result[1]); - $this->assertPattern('##', $result[1]); - - $result = $this->Form->input('prueba', array( - 'type' => 'datetime', 'timeFormat'=> 24 , 'dateFormat'=>'DMY' , 'minYear' => 2008, - 'maxYear' => date('Y') + 1 ,'interval' => 15 - )); - $result = explode(':', $result); - $this->assertNoPattern('##', $result[1]); - $this->assertNoPattern('##', $result[1]); - $this->assertPattern('##', $result[1]); - $this->assertPattern('##', $result[1]); - - //related to ticket #5013 - $result = $this->Form->input('Contact.date', array( - 'type' => 'date', 'class' => 'customClass', 'onChange' => 'function(){}' - )); - $this->assertPattern('/class="customClass"/', $result); - $this->assertPattern('/onChange="function\(\)\{\}"/', $result); - - $result = $this->Form->input('Contact.date', array( - 'type' => 'date', 'id' => 'customId', 'onChange' => 'function(){}' - )); - $this->assertPattern('/id="customIdDay"/', $result); - $this->assertPattern('/id="customIdMonth"/', $result); - $this->assertPattern('/onChange="function\(\)\{\}"/', $result); - - $result = $this->Form->input('Model.field', array( - 'type' => 'datetime', 'timeFormat' => 24, 'id' => 'customID' - )); - $this->assertPattern('/id="customIDDay"/', $result); - $this->assertPattern('/id="customIDHour"/', $result); - $result = explode('assertPattern('/option value="23"/', $result[0]); - $this->assertNoPattern('/option value="24"/', $result[0]); - - $result = $this->Form->input('Model.field', array( - 'type' => 'datetime', 'timeFormat' => 12 - )); - $result = explode('assertPattern('/option value="12"/', $result[0]); - $this->assertNoPattern('/option value="13"/', $result[0]); - $this->Form->data = array('Contact' => array('phone' => 'Hello & World > weird chars')); $result = $this->Form->input('Contact.phone'); $expected = array( @@ -1739,7 +1623,6 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $this->Form->data['Model']['0']['OtherModel']['field'] = 'My value'; $result = $this->Form->input('Model.0.OtherModel.field', array('id' => 'myId')); $expected = array( @@ -1856,6 +1739,207 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); + $this->Form->validationErrors['Model']['field'] = 'minLength'; + $result = $this->Form->input('Model.field', array('error' => array('minLength' => __('Le login doit contenir au moins 2 caractères', true)))); + $expected = array( + 'div' => array('class' => 'input text error'), + 'label' => array('for' => 'ModelField'), + 'Field', + '/label', + 'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField', 'class' => 'form-error'), + array('div' => array('class' => 'error-message')), + 'Le login doit contenir au moins 2 caractères', + '/div', + '/div' + ); + $this->assertTags($result, $expected); + } +/** + * test form->input() with datetime, date and time types + * + * @return void + **/ + function testInputDatetime() { + extract($this->dateRegex); + $result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24)); + $result = explode(':', $result); + $this->assertPattern('/option value="23"/', $result[0]); + $this->assertNoPattern('/option value="24"/', $result[0]); + + $result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24)); + $result = explode(':', $result); + $this->assertPattern('/option value="23"/', $result[0]); + $this->assertNoPattern('/option value="24"/', $result[0]); + + $result = $this->Form->input('Model.field', array( + 'type' => 'time', 'timeFormat' => 24, 'interval' => 15 + )); + $result = explode(':', $result); + $this->assertNoPattern('##', $result[1]); + $this->assertNoPattern('##', $result[1]); + $this->assertPattern('##', $result[1]); + + $result = $this->Form->input('Model.field', array( + 'type' => 'time', 'timeFormat' => 12, 'interval' => 15 + )); + $result = explode(':', $result); + $this->assertNoPattern('##', $result[1]); + $this->assertNoPattern('##', $result[1]); + $this->assertPattern('##', $result[1]); + + $result = $this->Form->input('prueba', array( + 'type' => 'time', 'timeFormat'=> 24 , 'dateFormat'=>'DMY' , 'minYear' => 2008, + 'maxYear' => date('Y') + 1 ,'interval' => 15 + )); + $result = explode(':', $result); + $this->assertNoPattern('##', $result[1]); + $this->assertNoPattern('##', $result[1]); + $this->assertPattern('##', $result[1]); + $this->assertPattern('##', $result[1]); + + $result = $this->Form->input('prueba', array( + 'type' => 'datetime', 'timeFormat'=> 24 , 'dateFormat'=>'DMY' , 'minYear' => 2008, + 'maxYear' => date('Y') + 1 ,'interval' => 15 + )); + $result = explode(':', $result); + $this->assertNoPattern('##', $result[1]); + $this->assertNoPattern('##', $result[1]); + $this->assertPattern('##', $result[1]); + $this->assertPattern('##', $result[1]); + + //related to ticket #5013 + $result = $this->Form->input('Contact.date', array( + 'type' => 'date', 'class' => 'customClass', 'onChange' => 'function(){}' + )); + $this->assertPattern('/class="customClass"/', $result); + $this->assertPattern('/onChange="function\(\)\{\}"/', $result); + + $result = $this->Form->input('Contact.date', array( + 'type' => 'date', 'id' => 'customId', 'onChange' => 'function(){}' + )); + $this->assertPattern('/id="customIdDay"/', $result); + $this->assertPattern('/id="customIdMonth"/', $result); + $this->assertPattern('/onChange="function\(\)\{\}"/', $result); + + $result = $this->Form->input('Model.field', array( + 'type' => 'datetime', 'timeFormat' => 24, 'id' => 'customID' + )); + $this->assertPattern('/id="customIDDay"/', $result); + $this->assertPattern('/id="customIDHour"/', $result); + $result = explode('assertPattern('/option value="23"/', $result[0]); + $this->assertNoPattern('/option value="24"/', $result[0]); + + $result = $this->Form->input('Model.field', array( + 'type' => 'datetime', 'timeFormat' => 12 + )); + $result = explode('assertPattern('/option value="12"/', $result[0]); + $this->assertNoPattern('/option value="13"/', $result[0]); + + $this->Form->data = array('Contact' => array('created' => null)); + $result = $this->Form->input('Contact.created', array('empty' => 'Date Unknown')); + $expected = array( + 'div' => array('class' => 'input date'), + 'label' => array('for' => 'ContactCreatedMonth'), + 'Created', + '/label', + array('select' => array('name' => 'data[Contact][created][month]', 'id' => 'ContactCreatedMonth')), + array('option' => array('value' => '')), 'Date Unknown', '/option', + $monthsRegex, + '/select', '-', + array('select' => array('name' => 'data[Contact][created][day]', 'id' => 'ContactCreatedDay')), + array('option' => array('value' => '')), 'Date Unknown', '/option', + $daysRegex, + '/select', '-', + array('select' => array('name' => 'data[Contact][created][year]', 'id' => 'ContactCreatedYear')), + array('option' => array('value' => '')), 'Date Unknown', '/option', + $yearsRegex, + '/select', + '/div' + ); + $this->assertTags($result, $expected); + + $this->Form->data = array('Contact' => array('created' => null)); + $result = $this->Form->input('Contact.created', array('type' => 'datetime', 'dateFormat' => 'NONE')); + $this->assertPattern('/for\="ContactCreatedHour"/', $result); + + $this->Form->data = array('Contact' => array('created' => null)); + $result = $this->Form->input('Contact.created', array('type' => 'datetime', 'timeFormat' => 'NONE')); + $this->assertPattern('/for\="ContactCreatedMonth"/', $result); + } +/** + * Test generating checkboxes in a loop. + * + * @return void + **/ + function testInputCheckboxesInLoop() { + for ($i = 1; $i < 5; $i++) { + $result = $this->Form->input("Contact.{$i}.email", array('type' => 'checkbox', 'value' => $i)); + $expected = array( + 'div' => array('class' => 'input checkbox'), + 'input' => array('type' => 'hidden', 'name' => "data[Contact][{$i}][email]", 'value' => '0', 'id' => "Contact{$i}Email_"), + array('input' => array('type' => 'checkbox', 'name' => "data[Contact][{$i}][email]", 'value' => $i, 'id' => "Contact{$i}Email")), + 'label' => array('for' => "Contact{$i}Email"), + 'Email', + '/label', + '/div' + ); + $this->assertTags($result, $expected); + } + } +/** + * test form->input() with select type inputs. + * + * @return void + **/ + function testInputSelectType() { + $result = $this->Form->input('email', array( + 'options' => array('è' => 'Firést', 'é' => 'Secoènd'), 'empty' => true) + ); + $expected = array( + 'div' => array('class' => 'input select'), + 'label' => array('for' => 'email'), + 'Email', + '/label', + array('select' => array('name' => 'data[email]', 'id' => 'email')), + array('option' => array('value' => '')), + '/option', + array('option' => array('value' => 'è')), + 'Firést', + '/option', + array('option' => array('value' => 'é')), + 'Secoènd', + '/option', + '/select', + '/div' + ); + $this->assertTags($result, $expected); + + $result = $this->Form->input('email', array( + 'options' => array('First', 'Second'), 'empty' => true) + ); + $expected = array( + 'div' => array('class' => 'input select'), + 'label' => array('for' => 'email'), + 'Email', + '/label', + array('select' => array('name' => 'data[email]', 'id' => 'email')), + array('option' => array('value' => '')), + '/option', + array('option' => array('value' => '0')), + 'First', + '/option', + array('option' => array('value' => '1')), + 'Second', + '/option', + '/select', + '/div' + ); + $this->assertTags($result, $expected); + $this->Form->data = array('Model' => array('user_id' => 'value')); $view =& ClassRegistry::getObject('view'); $view->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); @@ -1927,33 +2011,6 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - extract($this->dateRegex); - - $this->Form->data = array('Contact' => array('created' => null)); - $view =& ClassRegistry::getObject('view'); - $view->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); - $result = $this->Form->input('Contact.created', array('empty' => 'Date Unknown')); - $expected = array( - 'div' => array('class' => 'input date'), - 'label' => array('for' => 'ContactCreatedMonth'), - 'Created', - '/label', - array('select' => array('name' => 'data[Contact][created][month]', 'id' => 'ContactCreatedMonth')), - array('option' => array('value' => '')), 'Date Unknown', '/option', - $monthsRegex, - '/select', '-', - array('select' => array('name' => 'data[Contact][created][day]', 'id' => 'ContactCreatedDay')), - array('option' => array('value' => '')), 'Date Unknown', '/option', - $daysRegex, - '/select', '-', - array('select' => array('name' => 'data[Contact][created][year]', 'id' => 'ContactCreatedYear')), - array('option' => array('value' => '')), 'Date Unknown', '/option', - $yearsRegex, - '/select', - '/div' - ); - $this->assertTags($result, $expected); - $this->Form->data = array('User' => array('User' => array('value'))); $view =& ClassRegistry::getObject('view'); $view->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); @@ -1977,35 +2034,24 @@ class FormHelperTest extends CakeTestCase { '/div' ); $this->assertTags($result, $expected); + } - $this->Form->validationErrors['Model']['field'] = 'minLength'; - $result = $this->Form->input('Model.field', array('error' => array('minLength' => __('Le login doit contenir au moins 2 caractères', true)))); +/** + * test that overriding the magic select type widget is possible + * + * @return void + **/ + function testInputOverridingMagicSelectType() { + $view =& ClassRegistry::getObject('view'); + $view->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); + $result = $this->Form->input('Model.user_id', array('type' => 'text')); $expected = array( - 'div' => array('class' => 'input text error'), - 'label' => array('for' => 'ModelField'), - 'Field', - '/label', - 'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField', 'class' => 'form-error'), - array('div' => array('class' => 'error-message')), - 'Le login doit contenir au moins 2 caractères', - '/div', + 'div' => array('class' => 'input text'), + 'label' => array('for' => 'ModelUserId'), 'User', '/label', + 'input' => array('name' => 'data[Model][user_id]', 'type' => 'text', 'id' => 'ModelUserId', 'value' => ''), '/div' ); $this->assertTags($result, $expected); - - for ($i = 1; $i < 5; $i++) { - $result = $this->Form->input("Contact.{$i}.email", array('type' => 'checkbox', 'value' => $i)); - $expected = array( - 'div' => array('class' => 'input checkbox'), - 'input' => array('type' => 'hidden', 'name' => "data[Contact][{$i}][email]", 'value' => '0', 'id' => "Contact{$i}Email_"), - array('input' => array('type' => 'checkbox', 'name' => "data[Contact][{$i}][email]", 'value' => $i, 'id' => "Contact{$i}Email")), - 'label' => array('for' => "Contact{$i}Email"), - 'Email', - '/label', - '/div' - ); - $this->assertTags($result, $expected); - } } /** @@ -2372,6 +2418,21 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); } +/** + * test error options when using form->input(); + * + * @return void + */ + function testInputErrorEscape() { + $this->Form->create('ValidateProfile'); + $this->Form->validationErrors['ValidateProfile']['city'] = 'required
    '; + $result = $this->Form->input('city',array('error' => array('escape' => true))); + $this->assertPattern('/required<br>/', $result); + + $result = $this->Form->input('city',array('error' => array('escape' => false))); + $this->assertPattern('/required
    /', $result); + } + /** * testPassword method * @@ -2678,6 +2739,38 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); } +/** + * test disabling the hidden input for radio buttons + * + * @return void + **/ + function testRadioHiddenInputDisabling() { + $result = $this->Form->input('Model.1.field', array( + 'type' => 'radio', + 'options' => array('option A'), + 'hiddenField' => false + ) + ); + $expected = array( + 'div' => array('class' => 'input radio'), + 'input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0'), + 'label' => array('for' => 'Model1Field0'), + 'option A', + '/label', + '/div' + ); + $this->assertTags($result, $expected); + + $result = $this->Form->radio('Model.1.field', array('option A'), array('hiddenField' => false)); + $expected = array( + 'input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0'), + 'label' => array('for' => 'Model1Field0'), + 'option A', + '/label' + ); + $this->assertTags($result, $expected); + } + /** * testSelect method * @@ -2760,6 +2853,23 @@ class FormHelperTest extends CakeTestCase { '/select' ); $this->assertTags($result, $expected); + + $this->Form->data = array('Model' => array('contact_id' => 228)); + $result = $this->Form->select( + 'Model.contact_id', + array('228' => '228 value', '228-1' => '228-1 value', '228-2' => '228-2 value'), + null, array('escape' => false, 'empty' => 'pick something') + ); + + $expected = array( + 'select' => array('name' => 'data[Model][contact_id]', 'id' => 'ModelContactId'), + array('option' => array('value' => '')), 'pick something', '/option', + array('option' => array('value' => '228', 'selected' => 'selected')), '228 value', '/option', + array('option' => array('value' => '228-1')), '228-1 value', '/option', + array('option' => array('value' => '228-2')), '228-2 value', '/option', + '/select' + ); + $this->assertTags($result, $expected); } /** @@ -3226,7 +3336,7 @@ class FormHelperTest extends CakeTestCase { $this->Form->validationErrors['Model']['field'] = 1; $this->Form->data['Contact']['published'] = 1; - $result = $this->Form->checkbox('Contact.published', array('id'=>'theID')); + $result = $this->Form->checkbox('Contact.published', array('id' => 'theID')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Contact][published]', 'value' => '0', 'id' => 'theID_'), array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][published]', 'value' => '1', 'id' => 'theID', 'checked' => 'checked')) @@ -3275,7 +3385,7 @@ class FormHelperTest extends CakeTestCase { array('input' => array('type' => 'hidden', 'name' => 'data[Account][show_name]', 'value' => '0', 'id' => 'AccountShowName_', 'disabled' => 'disabled')), array('input' => array('type' => 'checkbox', 'name' => 'data[Account][show_name]', 'value' => '1', 'id' => 'AccountShowName', 'disabled' => 'disabled')) ); - $this->assertTags($result, $expected); + $this->assertTags($result, $expected,true); } /** @@ -3292,6 +3402,31 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); } +/** + * Test that the hidden input for checkboxes can be removed/omitted from the output. + * + * @return void + */ + function testCheckboxHiddenFieldOmission() { + $result = $this->Form->input('UserForm.something', array( + 'type' => 'checkbox', + 'hiddenField' => false + ) + ); + $expected = array( + 'div' => array('class' => 'input checkbox'), + array('input' => array( + 'type' => 'checkbox', 'name' => 'data[UserForm][something]', + 'value' => '1', 'id' => 'UserFormSomething' + )), + 'label' => array('for' => 'UserFormSomething'), + 'Something', + '/label', + '/div' + ); + $this->assertTags($result, $expected); + } + /** * testDateTime method * @@ -4556,14 +4691,6 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $result = $this->Form->submit('Next >', array('escape' => false)); - $expected = array( - 'div' => array('class' => 'submit'), - 'input' => array('type' => 'submit', 'value' => 'Next >'), - '/div' - ); - $this->assertTags($result, $expected); - $result = $this->Form->submit('Reset!', array('type' => 'reset')); $expected = array( 'div' => array('class' => 'submit'), @@ -4571,6 +4698,36 @@ class FormHelperTest extends CakeTestCase { '/div' ); $this->assertTags($result, $expected); + + $before = '--before--'; + $after = '--after--'; + $result = $this->Form->submit('Test', array('before' => $before)); + $expected = array( + 'div' => array('class' => 'submit'), + '--before--', + 'input' => array('type' => 'submit', 'value' => 'Test'), + '/div' + ); + $this->assertTags($result, $expected); + + $result = $this->Form->submit('Test', array('after' => $after)); + $expected = array( + 'div' => array('class' => 'submit'), + 'input' => array('type' => 'submit', 'value' => 'Test'), + '--after--', + '/div' + ); + $this->assertTags($result, $expected); + + $result = $this->Form->submit('Test', array('before' => $before, 'after' => $after)); + $expected = array( + 'div' => array('class' => 'submit'), + '--before--', + 'input' => array('type' => 'submit', 'value' => 'Test'), + '--after--', + '/div' + ); + $this->assertTags($result, $expected); } /** @@ -4610,19 +4767,61 @@ class FormHelperTest extends CakeTestCase { '/div' ); $this->assertTags($result, $expected); + + $after = '--after--'; + $before = '--before--'; + $result = $this->Form->submit('cake.power.gif', array('after' => $after)); + $expected = array( + 'div' => array('class' => 'submit'), + 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'), + '--after--', + '/div' + ); + $this->assertTags($result, $expected); + + $result = $this->Form->submit('cake.power.gif', array('before' => $before)); + $expected = array( + 'div' => array('class' => 'submit'), + '--before--', + 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'), + '/div' + ); + $this->assertTags($result, $expected); + + $result = $this->Form->submit('cake.power.gif', array('before' => $before, 'after' => $after)); + $expected = array( + 'div' => array('class' => 'submit'), + '--before--', + 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'), + '--after--', + '/div' + ); + $this->assertTags($result, $expected); + + $result = $this->Form->submit('Not.an.image', array('before' => $before, 'after' => $after)); + $expected = array( + 'div' => array('class' => 'submit'), + '--before--', + 'input' => array('type' => 'submit', 'value' => 'Not.an.image'), + '--after--', + '/div' + ); + $this->assertTags($result, $expected); } /** - * testFormCreate method + * test the create() method * * @access public * @return void */ - function testFormCreate() { + function testCreate() { $result = $this->Form->create('Contact'); + $encoding = strtolower(Configure::read('App.encoding')); $expected = array( 'form' => array( - 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/' + 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/', + 'accept-charset' => $encoding ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), @@ -4632,20 +4831,49 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->create('Contact', array('type' => 'GET')); $expected = array('form' => array( - 'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add/' + 'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add/', + 'accept-charset' => $encoding )); $this->assertTags($result, $expected); $result = $this->Form->create('Contact', array('type' => 'get')); $expected = array('form' => array( - 'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add/' + 'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add/', + 'accept-charset' => $encoding )); $this->assertTags($result, $expected); $result = $this->Form->create('Contact', array('type' => 'put')); $expected = array( 'form' => array( - 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/' + 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/', + 'accept-charset' => $encoding + ), + 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), + 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'), + '/fieldset' + ); + $this->assertTags($result, $expected); + + $result = $this->Form->create('Contact', array('type' => 'file')); + $expected = array( + 'form' => array( + 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/', + 'accept-charset' => $encoding, 'enctype' => 'multipart/form-data' + ), + 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), + 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), + '/fieldset' + ); + $this->assertTags($result, $expected); + + $this->Form->data['Contact']['id'] = 1; + $this->Form->params['action'] = 'edit'; + $result = $this->Form->create('Contact'); + $expected = array( + 'form' => array( + 'id' => 'ContactEditForm', 'method' => 'post', 'action' => '/contacts/edit/1', + 'accept-charset' => $encoding ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'), @@ -4654,10 +4882,12 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); $this->Form->data['Contact']['id'] = 1; - $result = $this->Form->create('Contact'); + $this->Form->params['action'] = 'edit'; + $result = $this->Form->create('Contact', array('type' => 'file')); $expected = array( 'form' => array( - 'id' => 'ContactEditForm', 'method' => 'post', 'action' => '/contacts/edit/1' + 'id' => 'ContactEditForm', 'method' => 'post', 'action' => '/contacts/edit/1', + 'accept-charset' => $encoding, 'enctype' => 'multipart/form-data' ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'), @@ -4670,7 +4900,7 @@ class FormHelperTest extends CakeTestCase { $expected = array( 'form' => array( 'id' => 'ContactNonStandardPkEditForm', 'method' => 'post', - 'action' => '/contact_non_standard_pks/edit/1' + 'action' => '/contact_non_standard_pks/edit/1','accept-charset' => $encoding ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'), @@ -4680,16 +4910,23 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->create('Contact', array('id' => 'TestId')); $expected = array( - 'form' => array('id' => 'TestId', 'method' => 'post', 'action' => '/contacts/edit/1'), + 'form' => array( + 'id' => 'TestId', 'method' => 'post', 'action' => '/contacts/edit/1', + 'accept-charset' => $encoding + ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'), '/fieldset' ); $this->assertTags($result, $expected); + $this->Form->params['action'] = 'add'; $result = $this->Form->create('User', array('url' => array('action' => 'login'))); $expected = array( - 'form' => array('id' => 'UserAddForm', 'method' => 'post', 'action' => '/users/login/'), + 'form' => array( + 'id' => 'UserAddForm', 'method' => 'post', 'action' => '/users/login/', + 'accept-charset' => $encoding + ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/fieldset' @@ -4699,7 +4936,8 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->create('User', array('action' => 'login')); $expected = array( 'form' => array( - 'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/users/login/' + 'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/users/login/', + 'accept-charset' => $encoding ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), @@ -4709,7 +4947,7 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->create('User', array('url' => '/users/login')); $expected = array( - 'form' => array('method' => 'post', 'action' => '/users/login'), + 'form' => array('method' => 'post', 'action' => '/users/login','accept-charset' => $encoding), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/fieldset' @@ -4721,7 +4959,8 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->create('User', array('action' => 'signup')); $expected = array( 'form' => array( - 'id' => 'UserSignupForm', 'method' => 'post', 'action' => '/users/signup/' + 'id' => 'UserSignupForm', 'method' => 'post', 'action' => '/users/signup/', + 'accept-charset' => $encoding ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), @@ -4755,11 +4994,34 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); } +/** + * test automatic accept-charset overriding + * + * @return void + **/ + function testCreateWithAcceptCharset() { + $result = $this->Form->create('UserForm', array( + 'type' => 'post', 'action' => 'login','encoding' => 'iso-8859-1' + ) + ); + $expected = array( + 'form' => array( + 'method' => 'post', 'action' => '/user_forms/login/', 'id' => 'UserFormLoginForm', + 'accept-charset' => 'iso-8859-1' + ), + 'fieldset' => array('style' => 'display:none;'), + 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), + '/fieldset' + ); + $this->assertTags($result, $expected); + } + /** * Test base form url when url param is passed with multiple parameters (&) * */ - function testFormCreateQuerystringParams() { + function testCreateQuerystringParams() { + $encoding = strtolower(Configure::read('App.encoding')); $result = $this->Form->create('Contact', array( 'type' => 'post', 'escape' => false, @@ -4773,7 +5035,8 @@ class FormHelperTest extends CakeTestCase { 'form' => array( 'id' => 'ContactAddForm', 'method' => 'post', - 'action' => '/controller/action/?param1=value1&param2=value2' + 'action' => '/controller/action/?param1=value1&param2=value2', + 'accept-charset' => $encoding ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), @@ -4783,20 +5046,22 @@ class FormHelperTest extends CakeTestCase { } /** - * testGetFormCreate method + * test creating a get form, and get form inputs. * * @access public * @return void */ function testGetFormCreate() { + $encoding = strtolower(Configure::read('App.encoding')); $result = $this->Form->create('Contact', array('type' => 'get')); $this->assertTags($result, array('form' => array( - 'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add/' + 'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add/', + 'accept-charset' => $encoding ))); $result = $this->Form->text('Contact.name'); $this->assertTags($result, array('input' => array( - 'name' => 'name', 'type' => 'text', 'value' => '', 'id' => 'ContactName' + 'name' => 'name', 'type' => 'text', 'value' => '', 'id' => 'ContactName', ))); $result = $this->Form->password('password'); @@ -4821,12 +5086,12 @@ class FormHelperTest extends CakeTestCase { */ function testEditFormWithData() { $this->Form->data = array('Person' => array( - 'id' => 1, - 'first_name' => 'Nate', - 'last_name' => 'Abele', - 'email' => 'nate@example.com' + 'id' => 1, + 'first_name' => 'Nate', + 'last_name' => 'Abele', + 'email' => 'nate@example.com' )); - $this->Form->params = array('models' => array('Person'), 'controller' => 'people'); + $this->Form->params = array('models' => array('Person'), 'controller' => 'people', 'action' => 'add'); $options = array(1 => 'Nate', 2 => 'Garrett', 3 => 'Larry'); $this->Form->create(); @@ -4836,15 +5101,9 @@ class FormHelperTest extends CakeTestCase { 'select' => array( 'name' => 'data[People][People][]', 'multiple' => 'multiple', 'id' => 'PeoplePeople' ), - array('option' => array('value' => 1)), - 'Nate', - '/option', - array('option' => array('value' => 2)), - 'Garrett', - '/option', - array('option' => array('value' => 3)), - 'Larry', - '/option', + array('option' => array('value' => 1)), 'Nate', '/option', + array('option' => array('value' => 2)), 'Garrett', '/option', + array('option' => array('value' => 3)), 'Larry', '/option', '/select' ); $this->assertTags($result, $expected); @@ -4857,10 +5116,12 @@ class FormHelperTest extends CakeTestCase { * @return void */ function testFormMagicInput() { + $encoding = strtolower(Configure::read('App.encoding')); $result = $this->Form->create('Contact'); $expected = array( 'form' => array( - 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/' + 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/', + 'accept-charset' => $encoding ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), @@ -5083,10 +5344,12 @@ class FormHelperTest extends CakeTestCase { * @return void */ function testForMagicInputNonExistingNorValidated() { + $encoding = strtolower(Configure::read('App.encoding')); $result = $this->Form->create('Contact'); $expected = array( 'form' => array( - 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/' + 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/', + 'accept-charset' => $encoding ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), @@ -5143,10 +5406,12 @@ class FormHelperTest extends CakeTestCase { * @return void */ function testFormMagicInputLabel() { + $encoding = strtolower(Configure::read('App.encoding')); $result = $this->Form->create('Contact'); $expected = array( 'form' => array( - 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/' + 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/', + 'accept-charset' => $encoding ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), @@ -5579,5 +5844,6 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->error('2.city'); $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div')); } + } ?> \ No newline at end of file diff --git a/cake/tests/cases/libs/view/helpers/javascript.test.php b/cake/tests/cases/libs/view/helpers/javascript.test.php index a4587fd96..c0b3a0df9 100644 --- a/cake/tests/cases/libs/view/helpers/javascript.test.php +++ b/cake/tests/cases/libs/view/helpers/javascript.test.php @@ -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; } diff --git a/cake/tests/cases/libs/view/helpers/text.test.php b/cake/tests/cases/libs/view/helpers/text.test.php index 748754073..294c6a17e 100644 --- a/cake/tests/cases/libs/view/helpers/text.test.php +++ b/cake/tests/cases/libs/view/helpers/text.test.php @@ -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), '© 2005-20...'); $this->assertIdentical($this->Text->truncate($text4, 15), ' This image ...'); - $this->assertIdentical($this->Text->truncate($text4, 45, '...', true, true), ' This image tag is not XHTML conform!

    But t...'); - $this->assertIdentical($this->Text->truncate($text4, 90, '...', true, true), ' This image tag is not XHTML conform!

    But the following image tag should be conform Me, myself and I
    Grea...'); - $this->assertIdentical($this->Text->truncate($text5, 6, '', true, true), '012345'); - $this->assertIdentical($this->Text->truncate($text5, 20, '', true, true), $text5); - $this->assertIdentical($this->Text->truncate($text6, 57, '...', false, true), "

    Extra dates have been announced for this year's...

    "); + $this->assertIdentical($this->Text->truncate($text5, 6, array('ending' => '')), '01<'); + $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ölr...'); + $this->assertIdentical($this->Text->truncate($text2, 10, array('exact' => false, 'html' => true)), '...'); + $this->assertIdentical($this->Text->truncate($text3, 20, array('html' => true)), '© 2005-2007, Cake...'); + $this->assertIdentical($this->Text->truncate($text4, 15, array('html' => true)), ' This image ...'); + $this->assertIdentical($this->Text->truncate($text4, 45, array('html' => true)), ' This image tag is not XHTML conform!

    But t...'); + $this->assertIdentical($this->Text->truncate($text4, 90, array('html' => true)), ' This image tag is not XHTML conform!

    But the following image tag should be conform Me, myself and I
    Grea...'); + $this->assertIdentical($this->Text->truncate($text5, 6, array('ending' => '', 'html' => true)), '012345'); + $this->assertIdentical($this->Text->truncate($text5, 20, array('ending' => '', 'html' => true)), $text5); + $this->assertIdentical($this->Text->truncate($text6, 57, array('exact' => false, 'html' => true)), "

    Extra dates have been announced for this year's...

    "); $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, '\1'); + $result = $this->Text->highlight($text, $phrases, array('format' => '\1')); $expected = 'This is a test text'; $this->assertEqual($expected, $result); $text = 'This is a test text'; $phrases = null; - $result = $this->Text->highlight($text, $phrases, '\1'); + $result = $this->Text->highlight($text, $phrases, array('format' => '\1')); $this->assertEqual($result, $text); $text = 'Ich saß in einem Café am Übergang'; $expected = 'Ich saß in einem Café am Übergang'; $phrases = array('saß', 'café', 'übergang'); - $result = $this->Text->highlight($text, $phrases, '\1'); + $result = $this->Text->highlight($text, $phrases, array('format' => '\1')); $this->assertEqual($result, $expected); } /** - * testHighlightConsiderHtml method + * testHighlightHtml method * * @access public * @return void */ - function testHighlightConsiderHtml() { + function testHighlightHtml() { $text1 = '

    strongbow isn’t real cider

    '; $text2 = '

    strongbow isn’t real cider

    '; $text3 = 'What a strong mouse!'; $text4 = 'What a strong mouse: What a strong mouse!'; + $options = array('format' => '\1', 'html' => true); $expected = '

    strongbow isn’t real cider

    '; - $this->assertEqual($this->Text->highlight($text1, 'strong', '\1', true), $expected); + $this->assertEqual($this->Text->highlight($text1, 'strong', $options), $expected); $expected = '

    strongbow isn’t real cider

    '; - $this->assertEqual($this->Text->highlight($text2, 'strong', '\1', true), $expected); + $this->assertEqual($this->Text->highlight($text2, 'strong', $options), $expected); - $this->assertEqual($this->Text->highlight($text3, 'strong', '\1', true), $text3); + $this->assertEqual($this->Text->highlight($text3, 'strong', $options), $text3); - $this->assertEqual($this->Text->highlight($text3, array('strong', 'what'), '\1', true), $text3); + $this->assertEqual($this->Text->highlight($text3, array('strong', 'what'), $options), $text3); $expected = 'What a strong mouse: What a strong mouse!'; - $this->assertEqual($this->Text->highlight($text4, array('strong', 'what'), '\1', 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('\1', '\1')); + $result = $this->Text->highlight($text, $phrases, array('format' => array('\1', '\1'))); $expected = 'This is a test text'; $this->assertEqual($expected, $result); @@ -286,10 +286,10 @@ class TextHelperTest extends CakeTestCase { $text = 'This is a Test text'; $expected = 'This is a Test text'; - $result = $this->Text->highlight($text, 'test', '\1'); + $result = $this->Text->highlight($text, 'test', array('format' => '\1')); $this->assertEqual($expected, $result); - $result = $this->Text->highlight($text, array('test'), '\1'); + $result = $this->Text->highlight($text, array('test'), array('format' => '\1')); $this->assertEqual($expected, $result); } diff --git a/cake/tests/cases/libs/view/helpers/time.test.php b/cake/tests/cases/libs/view/helpers/time.test.php index 5f79549e5..c8d5045c0 100644 --- a/cake/tests/cases/libs/view/helpers/time.test.php +++ b/cake/tests/cases/libs/view/helpers/time.test.php @@ -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; diff --git a/cake/tests/groups/console.group.php b/cake/tests/groups/console.group.php index 491a7d5fd..3008303e2 100644 --- a/cake/tests/groups/console.group.php +++ b/cake/tests/groups/console.group.php @@ -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'); + } } ?> \ No newline at end of file diff --git a/cake/tests/groups/controller.group.php b/cake/tests/groups/controller.group.php index 918ea3fdf..df704a286 100644 --- a/cake/tests/groups/controller.group.php +++ b/cake/tests/groups/controller.group.php @@ -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'); } } ?> \ No newline at end of file diff --git a/cake/tests/groups/lib.group.php b/cake/tests/groups/lib.group.php index 1e2fc11b4..4ca7bb73d 100644 --- a/cake/tests/groups/lib.group.php +++ b/cake/tests/groups/lib.group.php @@ -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'); diff --git a/cake/tests/groups/no_database.group.php b/cake/tests/groups/no_database.group.php deleted file mode 100644 index a8e307cef..000000000 --- a/cake/tests/groups/no_database.group.php +++ /dev/null @@ -1,58 +0,0 @@ - - * 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'); - } -} -?> \ No newline at end of file diff --git a/cake/tests/lib/cake_text_reporter.php b/cake/tests/lib/cake_text_reporter.php new file mode 100644 index 000000000..1d1424641 --- /dev/null +++ b/cake/tests/lib/cake_text_reporter.php @@ -0,0 +1,60 @@ +_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"; + } + } +} +?> \ No newline at end of file diff --git a/cake/tests/lib/code_coverage_manager.php b/cake/tests/lib/code_coverage_manager.php index 3ccee53f9..3bdbb28f4 100644 --- a/cake/tests/lib/code_coverage_manager.php +++ b/cake/tests/lib/code_coverage_manager.php @@ -790,4 +790,4 @@ class CodeCoverageManager { return false; } } -?> \ No newline at end of file +?> diff --git a/cake/tests/lib/test_manager.php b/cake/tests/lib/test_manager.php index 596c8da3a..1e4717bf2 100644 --- a/cake/tests/lib/test_manager.php +++ b/cake/tests/lib/test_manager.php @@ -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; } }