mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Merge branch '1.3' of code.cakephp.org:cakephp into 1.3
This commit is contained in:
commit
2bf630f209
68 changed files with 1435 additions and 790 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,14 @@ class ExtractTask extends Shell {
|
|||
*/
|
||||
var $__files = array();
|
||||
|
||||
/**
|
||||
* Merge all domains string into the default.pot file
|
||||
*
|
||||
* @var boolean
|
||||
* @access public
|
||||
*/
|
||||
var $__merge = false;
|
||||
|
||||
/**
|
||||
* Current file being processed
|
||||
*
|
||||
|
@ -137,6 +145,14 @@ class ExtractTask extends Shell {
|
|||
}
|
||||
}
|
||||
|
||||
if (isset($this->params['merge'])) {
|
||||
$this->__merge = !(strtolower($this->params['merge']) === 'no');
|
||||
} else {
|
||||
$this->out();
|
||||
$response = $this->in(sprintf(__('Would you like to merge all domains strings into the default.pot file?', true)), array('y', 'n'), 'n');
|
||||
$this->__merge = strtolower($response) === 'y';
|
||||
}
|
||||
|
||||
if (empty($this->__files)) {
|
||||
$this->__searchFiles();
|
||||
}
|
||||
|
@ -176,15 +192,18 @@ class ExtractTask extends Shell {
|
|||
$this->out(__('By default the .pot file(s) will be place in the locale directory of -app', true));
|
||||
$this->out(__('By default -app is ROOT/app', true));
|
||||
$this->hr();
|
||||
$this->out(__('Usage: cake i18n extract [command] [path...]', true));
|
||||
$this->out(__('Usage: cake i18n extract <command> <param1> <param2>...', true));
|
||||
$this->out();
|
||||
$this->out(__('Commands:', true));
|
||||
$this->out(__('Params:', true));
|
||||
$this->out(__(' -app [path...]: directory where your application is located', true));
|
||||
$this->out(__(' -root [path...]: path to install', true));
|
||||
$this->out(__(' -core [path...]: path to cake directory', true));
|
||||
$this->out(__(' -paths [comma separated list of paths, full path is needed]', true));
|
||||
$this->out(__(' -merge [yes|no]: Merge all domains strings into the default.pot file', true));
|
||||
$this->out(__(' -output [path...]: Full path to output directory', true));
|
||||
$this->out(__(' -files: [comma separated list of files, full path to file is needed]', true));
|
||||
$this->out();
|
||||
$this->out(__('Commands:', true));
|
||||
$this->out(__(' cake i18n extract help: Shows this help message.', true));
|
||||
$this->out();
|
||||
}
|
||||
|
@ -322,7 +341,7 @@ class ExtractTask extends Shell {
|
|||
}
|
||||
|
||||
$this->__store($domain, $header, $sentence);
|
||||
if ($domain != 'default') {
|
||||
if ($domain != 'default' && $this->__merge) {
|
||||
$this->__store('default', $header, $sentence);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
<?php echo $xml->header(); ?>
|
||||
<?php echo $content_for_layout; ?>
|
|
@ -55,7 +55,7 @@
|
|||
<?php echo $html->link(
|
||||
$html->image('cake.power.gif', array('alt'=>__("CakePHP: the rapid development php framework", true), 'border'=>"0")),
|
||||
'http://www.cakephp.org/',
|
||||
array('target'=>'_blank', 'escape'=>false), null
|
||||
array('target' => '_blank', 'escape' => false)
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -450,10 +450,10 @@ class AuthComponent extends Object {
|
|||
return false;
|
||||
}
|
||||
$defaults = array(
|
||||
'loginAction' => Router::normalize(array(
|
||||
'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),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -434,10 +434,7 @@ class Scaffold extends Object {
|
|||
/**
|
||||
* When methods are now present in a controller
|
||||
* scaffoldView is used to call default Scaffold methods if:
|
||||
* <code>
|
||||
* var $scaffold;
|
||||
* </code>
|
||||
* is placed in the controller's class definition.
|
||||
* `var $scaffold;` is placed in the controller's class definition.
|
||||
*
|
||||
* @param array $params Parameters for scaffolding
|
||||
* @return mixed A rendered view of scaffold action, or showing the error
|
||||
|
@ -445,43 +442,44 @@ class Scaffold extends Object {
|
|||
*/
|
||||
function __scaffold($params) {
|
||||
$db = &ConnectionManager::getDataSource($this->ScaffoldModel->useDbConfig);
|
||||
$admin = Configure::read('Routing.admin');
|
||||
$prefixes = Configure::read('Routing.prefixes');
|
||||
$scaffoldPrefix = $this->scaffoldActions;
|
||||
|
||||
if (isset($db)) {
|
||||
if (empty($this->scaffoldActions)) {
|
||||
$this->scaffoldActions = array(
|
||||
'index', 'list', 'view', 'add', 'create', 'edit', 'update', 'delete'
|
||||
);
|
||||
} elseif (!empty($admin) && $this->scaffoldActions === $admin) {
|
||||
} elseif (!empty($prefixes) && in_array($scaffoldPrefix, $prefixes)) {
|
||||
$this->scaffoldActions = array(
|
||||
$admin .'_index', $admin .'_list', $admin .'_view', $admin .'_add',
|
||||
$admin .'_create', $admin .'_edit', $admin .'_update', $admin .'_delete'
|
||||
$scaffoldPrefix . '_index',
|
||||
$scaffoldPrefix . '_list',
|
||||
$scaffoldPrefix . '_view',
|
||||
$scaffoldPrefix . '_add',
|
||||
$scaffoldPrefix . '_create',
|
||||
$scaffoldPrefix . '_edit',
|
||||
$scaffoldPrefix . '_update',
|
||||
$scaffoldPrefix . '_delete'
|
||||
);
|
||||
}
|
||||
|
||||
if (in_array($params['action'], $this->scaffoldActions)) {
|
||||
if (!empty($admin)) {
|
||||
$params['action'] = str_replace($admin . '_', '', $params['action']);
|
||||
if (!empty($prefixes)) {
|
||||
$params['action'] = str_replace($scaffoldPrefix . '_', '', $params['action']);
|
||||
}
|
||||
switch ($params['action']) {
|
||||
case 'index':
|
||||
case 'list':
|
||||
$this->__scaffoldIndex($params);
|
||||
break;
|
||||
case 'view':
|
||||
$this->__scaffoldView($params);
|
||||
break;
|
||||
case 'list':
|
||||
$this->__scaffoldIndex($params);
|
||||
break;
|
||||
case 'add':
|
||||
$this->__scaffoldSave($params, 'add');
|
||||
break;
|
||||
case 'edit':
|
||||
$this->__scaffoldSave($params, 'edit');
|
||||
break;
|
||||
case 'create':
|
||||
$this->__scaffoldSave($params, 'add');
|
||||
break;
|
||||
case 'edit':
|
||||
case 'update':
|
||||
$this->__scaffoldSave($params, 'edit');
|
||||
break;
|
||||
|
@ -556,10 +554,15 @@ class ScaffoldView extends ThemeView {
|
|||
$name = $this->action;
|
||||
}
|
||||
$name = Inflector::underscore($name);
|
||||
$admin = Configure::read('Routing.admin');
|
||||
$prefixes = Configure::read('Routing.prefixes');
|
||||
|
||||
if (!empty($admin) && strpos($name, $admin . '_') !== false) {
|
||||
$name = substr($name, strlen($admin) + 1);
|
||||
if (!empty($prefixes)) {
|
||||
foreach ($prefixes as $prefix) {
|
||||
if (strpos($name, $prefix . '_') !== false) {
|
||||
$name = substr($name, strlen($prefix) + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($name === 'add') {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -326,7 +326,7 @@ class Folder extends Object {
|
|||
* @static
|
||||
*/
|
||||
function addPathElement($path, $element) {
|
||||
return Folder::slashTerm($path) . $element;
|
||||
return rtrim($path, DS) . DS . $element;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
*
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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...
|
||||
*
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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,7 +201,6 @@ class CacheHelper extends AppHelper {
|
|||
function __parseOutput($cache) {
|
||||
$count = 0;
|
||||
if (!empty($this->__match)) {
|
||||
|
||||
foreach ($this->__match as $found) {
|
||||
$original = $cache;
|
||||
$length = strlen($found);
|
||||
|
@ -301,5 +299,4 @@ class CacheHelper extends AppHelper {
|
|||
return cache('views' . DS . $cache, $file, $timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -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,8 +772,12 @@ class FormHelper extends AppHelper {
|
|||
|
||||
if ($label !== false) {
|
||||
$labelAttributes = $this->domId(array(), 'for');
|
||||
if (in_array($options['type'], array('date', 'datetime'))) {
|
||||
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,22 +910,24 @@ 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';
|
||||
}
|
||||
if ($options['hiddenField']) {
|
||||
$hiddenOptions = array(
|
||||
'id' => $options['id'] . '_', 'name' => $options['name'],
|
||||
'value' => '0', 'secure' => false
|
||||
|
@ -908,6 +936,8 @@ class FormHelper extends AppHelper {
|
|||
$hiddenOptions['disabled'] = 'disabled';
|
||||
}
|
||||
$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,11 +1020,13 @@ class FormHelper extends AppHelper {
|
|||
}
|
||||
$hidden = null;
|
||||
|
||||
if ($hiddenField) {
|
||||
if (!isset($value) || $value === '') {
|
||||
$hidden = $this->hidden($fieldName, array(
|
||||
'id' => $attributes['id'] . '_', 'value' => '', 'name' => $attributes['name']
|
||||
));
|
||||
}
|
||||
}
|
||||
$out = $hidden . join($inbetween, $out);
|
||||
|
||||
if ($legend) {
|
||||
|
@ -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 {
|
||||
|
|
|
@ -250,10 +250,12 @@ 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 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'.
|
||||
|
|
|
@ -46,43 +46,51 @@ class TextHelper extends AppHelper {
|
|||
* Highlights a given phrase in a text. You can specify any expression in highlighter that
|
||||
* may include the \1 expression to include the $phrase found.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* - 'format' The piece of html with that the phrase will be highlighted
|
||||
* - 'html' If true, will ignore any HTML tags, ensuring that only the correct text is highlighted
|
||||
*
|
||||
* @param string $text Text to search the phrase in
|
||||
* @param string $phrase The phrase that will be searched
|
||||
* @param string $highlighter The piece of html with that the phrase will be highlighted
|
||||
* @param boolean $considerHtml If true, will ignore any HTML tags, ensuring that only the correct text is highlighted
|
||||
* @param array $options An array of html attributes and options.
|
||||
* @return string The highlighted text
|
||||
* @access public
|
||||
*/
|
||||
function highlight($text, $phrase, $highlighter = '<span class="highlight">\1</span>', $considerHtml = false) {
|
||||
function highlight($text, $phrase, $options = array()) {
|
||||
if (empty($phrase)) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
if (is_array($phrase)) {
|
||||
$default = array(
|
||||
'format' => '<span class="highlight">\1</span>',
|
||||
'html' => false
|
||||
);
|
||||
$options = array_merge($default, $options);
|
||||
extract($options);
|
||||
|
||||
if (is_array($phrase)) {
|
||||
$replace = array();
|
||||
$with = array();
|
||||
|
||||
foreach ($phrase as $key => $segment) {
|
||||
$segment = "($segment)";
|
||||
|
||||
if ($considerHtml) {
|
||||
if ($html) {
|
||||
$segment = "(?![^<]+>)$segment(?![^<]+>)";
|
||||
}
|
||||
|
||||
$with[] = (is_array($highlighter)) ? $highlighter[$key] : $highlighter;
|
||||
$with[] = (is_array($format)) ? $format[$key] : $format;
|
||||
$replace[] = "|$segment|iu";
|
||||
}
|
||||
|
||||
return preg_replace($replace, $with, $text);
|
||||
|
||||
} else {
|
||||
$phrase = "($phrase)";
|
||||
if ($considerHtml) {
|
||||
if ($html) {
|
||||
$phrase = "(?![^<]+>)$phrase(?![^<]+>)";
|
||||
}
|
||||
|
||||
return preg_replace("|$phrase|iu", $highlighter, $text);
|
||||
return preg_replace("|$phrase|iu", $format, $text);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,56 +110,55 @@ class TextHelper extends AppHelper {
|
|||
* strings like http:// and ftp://.
|
||||
*
|
||||
* @param string $text Text to add links to
|
||||
* @param array $htmlOptions Array of HTML options.
|
||||
* @param array $options Array of HTML options.
|
||||
* @return string The text with links
|
||||
* @access public
|
||||
*/
|
||||
function autoLinkUrls($text, $htmlOptions = array()) {
|
||||
$options = 'array(';
|
||||
foreach ($htmlOptions as $option => $value) {
|
||||
function autoLinkUrls($text, $options = array()) {
|
||||
$linkOptions = 'array(';
|
||||
foreach ($options as $option => $value) {
|
||||
$value = var_export($value, true);
|
||||
$options .= "'$option' => $value, ";
|
||||
$linkOptions .= "'$option' => $value, ";
|
||||
}
|
||||
$options .= ')';
|
||||
$linkOptions .= ')';
|
||||
|
||||
$text = preg_replace_callback('#(?<!href="|">)((?:http|https|ftp|nntp)://[^ <]+)#i', create_function('$matches',
|
||||
'$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], $matches[0],' . $options . ');'), $text);
|
||||
'$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], $matches[0],' . $linkOptions . ');'), $text);
|
||||
|
||||
return preg_replace_callback('#(?<!href="|">)(?<!http://|https://|ftp://|nntp://)(www\.[^\n\%\ <]+[^<\n\%\,\.\ <])(?<!\))#i',
|
||||
create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "http://" . strtolower($matches[0]),' . $options . ');'), $text);
|
||||
create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "http://" . strtolower($matches[0]),' . $linkOptions . ');'), $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds email links (<a href="mailto:....) to a given text.
|
||||
*
|
||||
* @param string $text Text
|
||||
* @param array $htmlOptions Array of HTML options.
|
||||
* @param array $options Array of HTML options.
|
||||
* @return string The text with links
|
||||
* @access public
|
||||
*/
|
||||
function autoLinkEmails($text, $htmlOptions = array()) {
|
||||
$options = 'array(';
|
||||
|
||||
foreach ($htmlOptions as $option => $value) {
|
||||
function autoLinkEmails($text, $options = array()) {
|
||||
$linkOptions = 'array(';
|
||||
foreach ($options as $option => $value) {
|
||||
$value = var_export($value, true);
|
||||
$options .= "'$option' => $value, ";
|
||||
$linkOptions .= "'$option' => $value, ";
|
||||
}
|
||||
$options .= ')';
|
||||
$linkOptions .= ')';
|
||||
|
||||
return preg_replace_callback('#([_A-Za-z0-9+-]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#',
|
||||
create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "mailto:" . $matches[0],' . $options . ');'), $text);
|
||||
create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "mailto:" . $matches[0],' . $linkOptions . ');'), $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert all links and email adresses to HTML links.
|
||||
*
|
||||
* @param string $text Text
|
||||
* @param array $htmlOptions Array of HTML options.
|
||||
* @param array $options Array of HTML options.
|
||||
* @return string The text with links
|
||||
* @access public
|
||||
*/
|
||||
function autoLink($text, $htmlOptions = array()) {
|
||||
return $this->autoLinkEmails($this->autoLinkUrls($text, $htmlOptions), $htmlOptions);
|
||||
function autoLink($text, $options = array()) {
|
||||
return $this->autoLinkEmails($this->autoLinkUrls($text, $options), $options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -160,24 +167,32 @@ class TextHelper extends AppHelper {
|
|||
* Cuts a string to the length of $length and replaces the last characters
|
||||
* with the ending if the text is longer than length.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* - 'ending' Will be used as Ending and appended to the trimmed string
|
||||
* - 'exact' If false, $text will not be cut mid-word
|
||||
* - 'html' If true, HTML tags would be handled correctly
|
||||
*
|
||||
* @param string $text String to truncate.
|
||||
* @param integer $length Length of returned string, including ellipsis.
|
||||
* @param mixed $ending If string, will be used as Ending and appended to the trimmed string. Can also be an associative array that can contain the last three params of this method.
|
||||
* @param boolean $exact If false, $text will not be cut mid-word
|
||||
* @param boolean $considerHtml If true, HTML tags would be handled correctly
|
||||
* @param array $options An array of html attributes and options.
|
||||
* @return string Trimmed string.
|
||||
*/
|
||||
function truncate($text, $length = 100, $ending = '...', $exact = true, $considerHtml = false) {
|
||||
if (is_array($ending)) {
|
||||
extract($ending);
|
||||
}
|
||||
if ($considerHtml) {
|
||||
function truncate($text, $length = 100, $options = array()) {
|
||||
$default = array(
|
||||
'ending' => '...', 'exact' => true, 'html' => false
|
||||
);
|
||||
$options = array_merge($default, $options);
|
||||
extract($options);
|
||||
|
||||
if ($html) {
|
||||
if (mb_strlen(preg_replace('/<.*?>/', '', $text)) <= $length) {
|
||||
return $text;
|
||||
}
|
||||
$totalLength = mb_strlen($ending);
|
||||
$openTags = array();
|
||||
$truncate = '';
|
||||
|
||||
preg_match_all('/(<\/?([\w+]+)[^>]*>)?([^<>]*)/', $text, $tags, PREG_SET_ORDER);
|
||||
foreach ($tags as $tag) {
|
||||
if (!preg_match('/img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param/s', $tag[2])) {
|
||||
|
@ -217,7 +232,6 @@ class TextHelper extends AppHelper {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (mb_strlen($text) <= $length) {
|
||||
return $text;
|
||||
|
@ -228,7 +242,7 @@ class TextHelper extends AppHelper {
|
|||
if (!$exact) {
|
||||
$spacepos = mb_strrpos($truncate, ' ');
|
||||
if (isset($spacepos)) {
|
||||
if ($considerHtml) {
|
||||
if ($html) {
|
||||
$bits = mb_substr($truncate, $spacepos);
|
||||
preg_match_all('/<\/([a-z]+)>/', $bits, $droppedTags, PREG_SET_ORDER);
|
||||
if (!empty($droppedTags)) {
|
||||
|
@ -242,10 +256,9 @@ class TextHelper extends AppHelper {
|
|||
$truncate = mb_substr($truncate, 0, $spacepos);
|
||||
}
|
||||
}
|
||||
|
||||
$truncate .= $ending;
|
||||
|
||||
if ($considerHtml) {
|
||||
if ($html) {
|
||||
foreach ($openTags as $tag) {
|
||||
$truncate .= '</'.$tag.'>';
|
||||
}
|
||||
|
@ -276,9 +289,9 @@ class TextHelper extends AppHelper {
|
|||
* @return string Modified string
|
||||
* @access public
|
||||
*/
|
||||
function excerpt($text, $phrase, $radius = 100, $ending = "...") {
|
||||
function excerpt($text, $phrase, $radius = 100, $ending = '...') {
|
||||
if (empty($text) or empty($phrase)) {
|
||||
return $this->truncate($text, $radius * 2, $ending);
|
||||
return $this->truncate($text, $radius * 2, array('ending' => $ending));
|
||||
}
|
||||
|
||||
$phraseLen = mb_strlen($phrase);
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
<?php echo $html->link(
|
||||
$html->image('cake.power.gif', array('alt'=> __("CakePHP: the rapid development php framework", true), 'border'=>"0")),
|
||||
'http://www.cakephp.org/',
|
||||
array('target'=>'_blank'), null, false
|
||||
array('target' => '_blank', 'escape' => false)
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
|
|
|
@ -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)',
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* TestTaskTest file
|
||||
* ModelTaskTest file
|
||||
*
|
||||
* Test Case for test generation shell task
|
||||
*
|
||||
|
@ -17,7 +18,7 @@
|
|||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
* @since CakePHP v 1.3
|
||||
* @since CakePHP v 1.2.6
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
App::import('Shell', 'Shell', false);
|
||||
|
@ -37,12 +38,10 @@ require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php';
|
|||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'fixture.php';
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
||||
|
||||
|
||||
Mock::generatePartial(
|
||||
'ShellDispatcher', 'TestModelTaskMockShellDispatcher',
|
||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
||||
);
|
||||
|
||||
Mock::generatePartial(
|
||||
'ModelTask', 'MockModelTask',
|
||||
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest')
|
||||
|
@ -217,9 +216,9 @@ class ModelTaskTest extends CakeTestCase {
|
|||
function testInteractiveFieldValidation() {
|
||||
$this->Task->initValidations();
|
||||
$this->Task->interactive = true;
|
||||
$this->Task->setReturnValueAt(0, 'in', '20');
|
||||
$this->Task->setReturnValueAt(0, 'in', '19');
|
||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
||||
$this->Task->setReturnValueAt(2, 'in', '16');
|
||||
$this->Task->setReturnValueAt(2, 'in', '15');
|
||||
$this->Task->setReturnValueAt(3, 'in', 'n');
|
||||
|
||||
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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')));
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -408,8 +408,6 @@ HEADBLOC;
|
|||
This is the body of the message
|
||||
|
||||
This email was sent using the CakePHP Framework, http://cakephp.org.
|
||||
|
||||
|
||||
TEXTBLOC;
|
||||
|
||||
$html = <<<HTMLBLOC
|
||||
|
@ -425,7 +423,6 @@ TEXTBLOC;
|
|||
<p>This email was sent using the <a href="http://cakephp.org">CakePHP Framework</a></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
HTMLBLOC;
|
||||
|
||||
$this->Controller->EmailTest->sendAs = 'text';
|
||||
|
@ -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';
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -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');
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -315,8 +315,8 @@ class ScaffoldViewTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testGetViewFilename() {
|
||||
$_admin = Configure::read('Routing.admin');
|
||||
Configure::write('Routing.admin', 'admin');
|
||||
$_admin = Configure::read('Routing.prefixes');
|
||||
Configure::write('Routing.prefixes', array('admin'));
|
||||
|
||||
$this->Controller->action = 'index';
|
||||
$ScaffoldView =& new TestScaffoldView($this->Controller);
|
||||
|
@ -385,7 +385,7 @@ class ScaffoldViewTest extends CakeTestCase {
|
|||
. DS .'test_plugin' . DS . 'views' . DS . 'tests' . DS . 'scaffold.edit.ctp';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
Configure::write('Routing.admin', $_admin);
|
||||
Configure::write('Routing.prefixes', $_admin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -499,7 +499,7 @@ class ScaffoldViewTest extends CakeTestCase {
|
|||
new Scaffold($this->Controller, $params);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertPattern('/<form id="ScaffoldMockEditForm" method="post" action="\/scaffold_mock\/edit\/1">/', $result);
|
||||
$this->assertPattern('/<form id="ScaffoldMockEditForm" method="post" action="\/scaffold_mock\/edit\/1"/', $result);
|
||||
$this->assertPattern('/<legend>Edit Scaffold Mock<\/legend>/', $result);
|
||||
|
||||
$this->assertPattern('/input type="hidden" name="data\[ScaffoldMock\]\[id\]" value="1" id="ScaffoldMockId"/', $result);
|
||||
|
@ -509,6 +509,7 @@ class ScaffoldViewTest extends CakeTestCase {
|
|||
$this->assertPattern('/textarea name="data\[ScaffoldMock\]\[body\]" cols="30" rows="6" id="ScaffoldMockBody"/', $result);
|
||||
$this->assertPattern('/<li><a href="\/scaffold_mock\/delete\/1"[^>]*>Delete<\/a>\s*<\/li>/', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Admin Index Scaffolding.
|
||||
*
|
||||
|
@ -516,9 +517,9 @@ class ScaffoldViewTest extends CakeTestCase {
|
|||
* @return void
|
||||
**/
|
||||
function testAdminIndexScaffold() {
|
||||
$_backAdmin = Configure::read('Routing.admin');
|
||||
$_backAdmin = Configure::read('Routing.prefixes');
|
||||
|
||||
Configure::write('Routing.admin', 'admin');
|
||||
Configure::write('Routing.prefixes', array('admin'));
|
||||
$params = array(
|
||||
'plugin' => null,
|
||||
'pass' => array(),
|
||||
|
@ -551,7 +552,7 @@ class ScaffoldViewTest extends CakeTestCase {
|
|||
//TODO: add testing for table generation
|
||||
$this->assertPattern('/<li><a href="\/admin\/scaffold_mock\/add\/">New Scaffold Mock<\/a><\/li>/', $result);
|
||||
|
||||
Configure::write('Routing.admin', $_backAdmin);
|
||||
Configure::write('Routing.prefixes', $_backAdmin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -561,9 +562,9 @@ class ScaffoldViewTest extends CakeTestCase {
|
|||
* @return void
|
||||
**/
|
||||
function testAdminEditScaffold() {
|
||||
$_backAdmin = Configure::read('Routing.admin');
|
||||
$_backAdmin = Configure::read('Routing.prefixes');
|
||||
|
||||
Configure::write('Routing.admin', 'admin');
|
||||
Configure::write('Routing.prefixes', array('admin'));
|
||||
$params = array(
|
||||
'plugin' => null,
|
||||
'pass' => array(),
|
||||
|
@ -594,8 +595,54 @@ class ScaffoldViewTest extends CakeTestCase {
|
|||
$this->assertPattern('#admin/scaffold_mock/edit/1#', $result);
|
||||
$this->assertPattern('#Scaffold Mock#', $result);
|
||||
|
||||
Configure::write('Routing.admin', $_backAdmin);
|
||||
Configure::write('Routing.prefixes', $_backAdmin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Admin Index Scaffolding.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
**/
|
||||
function testMultiplePrefixScaffold() {
|
||||
$_backAdmin = Configure::read('Routing.prefixes');
|
||||
|
||||
Configure::write('Routing.prefixes', array('admin', 'member'));
|
||||
$params = array(
|
||||
'plugin' => null,
|
||||
'pass' => array(),
|
||||
'form' => array(),
|
||||
'named' => array(),
|
||||
'prefix' => 'member',
|
||||
'url' => array('url' =>'member/scaffold_mock'),
|
||||
'controller' => 'scaffold_mock',
|
||||
'action' => 'member_index',
|
||||
'member' => 1,
|
||||
);
|
||||
//reset, and set router.
|
||||
Router::reload();
|
||||
Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/member/scaffold_mock', 'webroot' => '/')));
|
||||
$this->Controller->params = $params;
|
||||
$this->Controller->controller = 'scaffold_mock';
|
||||
$this->Controller->base = '/';
|
||||
$this->Controller->action = 'member_index';
|
||||
$this->Controller->here = '/tests/member/scaffold_mock';
|
||||
$this->Controller->webroot = '/';
|
||||
$this->Controller->scaffold = 'member';
|
||||
$this->Controller->constructClasses();
|
||||
|
||||
ob_start();
|
||||
$Scaffold = new Scaffold($this->Controller, $params);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertPattern('/<h2>Scaffold Mock<\/h2>/', $result);
|
||||
$this->assertPattern('/<table cellpadding="0" cellspacing="0">/', $result);
|
||||
//TODO: add testing for table generation
|
||||
$this->assertPattern('/<li><a href="\/member\/scaffold_mock\/add\/">New Scaffold Mock<\/a><\/li>/', $result);
|
||||
|
||||
Configure::write('Routing.prefixes', $_backAdmin);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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'
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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 |