mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Merge branch '1.3' into 1.3-misc
This commit is contained in:
commit
3b95b4c95d
13 changed files with 624 additions and 221 deletions
|
@ -27,6 +27,7 @@
|
|||
if (!defined('E_DEPRECATED')) {
|
||||
define('E_DEPRECATED', 8192);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shell dispatcher
|
||||
*
|
||||
|
@ -402,6 +403,7 @@ class ShellDispatcher {
|
|||
$this->stderr($title . "\n" . $message . "\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get shell to use, either plugin shell or application shell
|
||||
*
|
||||
|
@ -606,28 +608,58 @@ class ShellDispatcher {
|
|||
$this->stdout("Example: -app relative/path/to/myapp or -app /absolute/path/to/myapp");
|
||||
|
||||
$this->stdout("\nAvailable Shells:");
|
||||
$_shells = array();
|
||||
$shellList = array();
|
||||
foreach ($this->shellPaths as $path) {
|
||||
if (is_dir($path)) {
|
||||
$shells = App::objects('file', $path);
|
||||
$path = str_replace(CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS, 'CORE' . DS, $path);
|
||||
$path = str_replace(APP, 'APP' . DS, $path);
|
||||
$path = str_replace(ROOT, 'ROOT', $path);
|
||||
$path = rtrim($path, DS);
|
||||
$this->stdout("\n " . $path . ":");
|
||||
if (empty($shells)) {
|
||||
$this->stdout("\t - none");
|
||||
} else {
|
||||
sort($shells);
|
||||
foreach ($shells as $shell) {
|
||||
|
||||
if ($shell !== 'shell.php') {
|
||||
$this->stdout("\t " . str_replace('.php', '', $shell));
|
||||
}
|
||||
}
|
||||
if (!is_dir($path)) {
|
||||
continue;
|
||||
}
|
||||
$shells = App::objects('file', $path);
|
||||
if (empty($shells)) {
|
||||
continue;
|
||||
}
|
||||
if (preg_match('@plugins[\\\/]([^\\\/]*)@', $path, $matches)) {
|
||||
$type = Inflector::camelize($matches[1]);
|
||||
} elseif (preg_match('@([^\\\/]*)[\\\/]vendors[\\\/]@', $path, $matches)) {
|
||||
$type = $matches[1];
|
||||
} elseif (strpos($path, CAKE_CORE_INCLUDE_PATH . DS . 'cake') === 0) {
|
||||
$type = 'CORE';
|
||||
} else {
|
||||
$type = 'app';
|
||||
}
|
||||
foreach ($shells as $shell) {
|
||||
if ($shell !== 'shell.php') {
|
||||
$shell = str_replace('.php', '', $shell);
|
||||
$shellList[$shell][$type] = $type;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($shellList) {
|
||||
ksort($shellList);
|
||||
if (DS === '/') {
|
||||
$width = exec('tput cols') - 2;
|
||||
}
|
||||
if (empty($width)) {
|
||||
$width = 80;
|
||||
}
|
||||
$columns = max(1, floor($width / 30));
|
||||
$rows = ceil(count($shellList) / $columns);
|
||||
|
||||
foreach($shellList as $shell => $types) {
|
||||
sort($types);
|
||||
$shellList[$shell] = str_pad($shell . ' [' . implode ($types, ', ') . ']', $width / $columns);
|
||||
}
|
||||
$out = array_chunk($shellList, $rows);
|
||||
for($i = 0; $i < $rows; $i++) {
|
||||
$row = '';
|
||||
for($j = 0; $j < $columns; $j++) {
|
||||
if (!isset($out[$j][$i])) {
|
||||
continue;
|
||||
}
|
||||
$row .= $out[$j][$i];
|
||||
}
|
||||
$this->stdout(" " . $row);
|
||||
}
|
||||
}
|
||||
$this->stdout("\nTo run a command, type 'cake shell_name [args]'");
|
||||
$this->stdout("To get help on a specific command, type 'cake shell_name help'");
|
||||
}
|
||||
|
|
|
@ -1,28 +1,21 @@
|
|||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
|
||||
/**
|
||||
* Short description for file.
|
||||
*
|
||||
* Long description for file
|
||||
* Acl Shell provides Acl access in the CLI environment
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
|
||||
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs
|
||||
* @since CakePHP(tm) v 1.2.0.5012
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
App::import('Component', 'Acl');
|
||||
|
@ -58,7 +51,7 @@ class AclShell extends Shell {
|
|||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $dataSource = 'default';
|
||||
var $connection = 'default';
|
||||
|
||||
/**
|
||||
* Contains tasks to load and instantiate
|
||||
|
@ -74,10 +67,8 @@ class AclShell extends Shell {
|
|||
* @access public
|
||||
*/
|
||||
function startup() {
|
||||
$this->dataSource = 'default';
|
||||
|
||||
if (isset($this->params['datasource'])) {
|
||||
$this->dataSource = $this->params['datasource'];
|
||||
if (isset($this->params['connection'])) {
|
||||
$this->connection = $this->params['connection'];
|
||||
}
|
||||
|
||||
if (!in_array(Configure::read('Acl.classname'), array('DbAcl', 'DB_ACL'))) {
|
||||
|
@ -220,13 +211,40 @@ class AclShell extends Shell {
|
|||
$this->_checkArgs(2, 'getPath');
|
||||
$this->checkNodeType();
|
||||
extract($this->__dataVars());
|
||||
$id = ife(is_numeric($this->args[1]), intval($this->args[1]), $this->args[1]);
|
||||
$identifier = $this->parseIdentifier($this->args[1]);
|
||||
|
||||
$id = $this->_getNodeId($class, $identifier);
|
||||
$nodes = $this->Acl->{$class}->getPath($id);
|
||||
|
||||
if (empty($nodes)) {
|
||||
$this->error(sprintf(__("Supplied Node '%s' not found", true), $this->args[1]), __("No tree returned.", true));
|
||||
$this->error(
|
||||
sprintf(__("Supplied Node '%s' not found", true), $this->args[1]),
|
||||
__("No tree returned.", true)
|
||||
);
|
||||
}
|
||||
$this->out(__('Path:', true));
|
||||
$this->hr();
|
||||
for ($i = 0; $i < count($nodes); $i++) {
|
||||
$this->out(str_repeat(' ', $i) . "[" . $nodes[$i][$class]['id'] . "]" . $nodes[$i][$class]['alias'] . "\n");
|
||||
$this->_outputNode($class, $nodes[$i], $i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a single node, Either using the alias or Model.key
|
||||
*
|
||||
* @param string $class Class name that is being used.
|
||||
* @param array $node Array of node information.
|
||||
* @param integer $indent indent level.
|
||||
* @return void
|
||||
* @access protected
|
||||
**/
|
||||
function _outputNode($class, $node, $indent) {
|
||||
$indent = str_repeat(' ', $indent);
|
||||
$data = $node[$class];
|
||||
if ($data['alias']) {
|
||||
$this->out($indent . "[" . $data['id'] . "] " . $data['alias']);
|
||||
} else {
|
||||
$this->out($indent . "[" . $data['id'] . "] " . $data['model'] . '.' . $data['foreign_key']);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -303,13 +321,25 @@ class AclShell extends Shell {
|
|||
$this->_checkArgs(1, 'view');
|
||||
$this->checkNodeType();
|
||||
extract($this->__dataVars());
|
||||
if (isset($this->args[1]) && !is_null($this->args[1])) {
|
||||
$key = ife(is_numeric($this->args[1]), $secondary_id, 'alias');
|
||||
$conditions = array($class . '.' . $key => $this->args[1]);
|
||||
|
||||
if (isset($this->args[1])) {
|
||||
$identity = $this->parseIdentifier($this->args[1]);
|
||||
|
||||
$topNode = $this->Acl->{$class}->find('first', array(
|
||||
'conditions' => array($class . '.id' => $this->_getNodeId($class, $identity))
|
||||
));
|
||||
|
||||
$nodes = $this->Acl->{$class}->find('all', array(
|
||||
'conditions' => array(
|
||||
$class . '.lft >=' => $topNode[$class]['lft'],
|
||||
$class . '.lft <=' => $topNode[$class]['rght']
|
||||
),
|
||||
'order' => $class . '.lft ASC'
|
||||
));
|
||||
} else {
|
||||
$conditions = null;
|
||||
$nodes = $this->Acl->{$class}->find('all', array('order' => $class . '.lft ASC'));
|
||||
}
|
||||
$nodes = $this->Acl->{$class}->find('all', array('conditions' => $conditions, 'order' => 'lft ASC'));
|
||||
|
||||
if (empty($nodes)) {
|
||||
if (isset($this->args[1])) {
|
||||
$this->error(sprintf(__("%s not found", true), $this->args[1]), __("No tree returned.", true));
|
||||
|
@ -319,8 +349,10 @@ class AclShell extends Shell {
|
|||
}
|
||||
$this->out($class . " tree:");
|
||||
$this->hr();
|
||||
|
||||
$stack = array();
|
||||
$last = null;
|
||||
|
||||
foreach ($nodes as $n) {
|
||||
$stack[] = $n;
|
||||
if (!empty($last)) {
|
||||
|
@ -334,14 +366,10 @@ class AclShell extends Shell {
|
|||
}
|
||||
}
|
||||
}
|
||||
$last = $n[$class]['rght'];
|
||||
$count = count($stack);
|
||||
$indent = str_repeat(' ', $count);
|
||||
if ($n[$class]['alias']) {
|
||||
$this->out($indent . "[" . $n[$class]['id'] . "]" . $n[$class]['alias']."\n");
|
||||
} else {
|
||||
$this->out($indent . "[" . $n[$class]['id'] . "]" . $n[$class]['model'] . '.' . $n[$class]['foreign_key'] . "\n");
|
||||
}
|
||||
$last = $n[$class]['rght'];
|
||||
$count = count($stack);
|
||||
|
||||
$this->_outputNode($class, $n, $count);
|
||||
}
|
||||
$this->hr();
|
||||
}
|
||||
|
@ -388,7 +416,7 @@ class AclShell extends Shell {
|
|||
"\t" . __("For more detailed parameter usage info,", true) . "\n" .
|
||||
"\t" . __("see help for the 'create' command.", true),
|
||||
|
||||
'setparent' => "setParent aro|aco <node> <parent>\n" .
|
||||
'setparent' => "setParent aro|aco <node> <parent node>\n" .
|
||||
"\t" . __("Moves the ACL object specified by <node> beneath", true) . "\n" .
|
||||
"\t" . __("the parent ACL object specified by <parent>.", true) . "\n" .
|
||||
"\t" . __("For more detailed parameter usage info,", true) . "\n" .
|
||||
|
@ -401,26 +429,26 @@ class AclShell extends Shell {
|
|||
"\t" . __("For more detailed parameter usage info,", true) . "\n" .
|
||||
"\t" . __("see help for the 'create' command.", true),
|
||||
|
||||
'check' => "check <aro_id> <aco_id> [<aco_action>] " . __("or", true) . " all\n" .
|
||||
'check' => "check <node> <node> [<aco_action>] " . __("or", true) . " all\n" .
|
||||
"\t" . __("Use this command to check ACL permissions.", true) . "\n" .
|
||||
"\t" . __("For more detailed parameter usage info,", true) . "\n" .
|
||||
"\t" . __("see help for the 'create' command.", true),
|
||||
|
||||
'grant' => "grant <aro_id> <aco_id> [<aco_action>] " . __("or", true) . " all\n" .
|
||||
'grant' => "grant <node> <node> [<aco_action>] " . __("or", true) . " all\n" .
|
||||
"\t" . __("Use this command to grant ACL permissions. Once executed, the ARO", true) . "\n" .
|
||||
"\t" . __("specified (and its children, if any) will have ALLOW access to the", true) . "\n" .
|
||||
"\t" . __("specified ACO action (and the ACO's children, if any).", true) . "\n" .
|
||||
"\t" . __("For more detailed parameter usage info,", true) . "\n" .
|
||||
"\t" . __("see help for the 'create' command.", true),
|
||||
|
||||
'deny' => "deny <aro_id> <aco_id> [<aco_action>]" . __("or", true) . " all\n" .
|
||||
'deny' => "deny <node> <node> [<aco_action>]" . __("or", true) . " all\n" .
|
||||
"\t" . __("Use this command to deny ACL permissions. Once executed, the ARO", true) . "\n" .
|
||||
"\t" . __("specified (and its children, if any) will have DENY access to the", true) . "\n" .
|
||||
"\t" . __("specified ACO action (and the ACO's children, if any).", true) . "\n" .
|
||||
"\t" . __("For more detailed parameter usage info,", true) . "\n" .
|
||||
"\t" . __("see help for the 'create' command.", true),
|
||||
|
||||
'inherit' => "inherit <aro_id> <aco_id> [<aco_action>]" . __("or", true) . " all\n" .
|
||||
'inherit' => "inherit <node> <node> [<aco_action>]" . __("or", true) . " all\n" .
|
||||
"\t" . __("Use this command to force a child ARO object to inherit its", true) . "\n" .
|
||||
"\t" . __("permissions settings from its parent.", true) . "\n" .
|
||||
"\t" . __("For more detailed parameter usage info,", true) . "\n" .
|
||||
|
@ -428,7 +456,8 @@ class AclShell extends Shell {
|
|||
|
||||
'view' => "view aro|aco [<node>]\n" .
|
||||
"\t" . __("The view command will return the ARO or ACO tree.", true) . "\n" .
|
||||
"\t" . __("The optional id/alias parameter allows you to return\n\tonly a portion of the requested tree.", true) . "\n" .
|
||||
"\t" . __("The optional node parameter allows you to return", true) . "\n" .
|
||||
"\t" . __("only a portion of the requested tree.", true) . "\n" .
|
||||
"\t" . __("For more detailed parameter usage info,", true) . "\n" .
|
||||
"\t" . __("see help for the 'create' command.", true),
|
||||
|
||||
|
@ -461,7 +490,7 @@ class AclShell extends Shell {
|
|||
return false;
|
||||
}
|
||||
if ($this->args[0] != 'aco' && $this->args[0] != 'aro') {
|
||||
$this->error(sprintf(__("Missing/Unknown node type: '%s'", true), $this->args[1]), __('Please specify which ACL object type you wish to create.', true));
|
||||
$this->error(sprintf(__("Missing/Unknown node type: '%s'", true), $this->args[0]), __('Please specify which ACL object type you wish to create. Either "aro" or "aco"', true));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -530,23 +559,15 @@ class AclShell extends Shell {
|
|||
* @access private
|
||||
*/
|
||||
function __getParams() {
|
||||
$aro = ife(is_numeric($this->args[0]), intval($this->args[0]), $this->args[0]);
|
||||
$aco = ife(is_numeric($this->args[1]), intval($this->args[1]), $this->args[1]);
|
||||
$aro = is_numeric($this->args[0]) ? intval($this->args[0]) : $this->args[0];
|
||||
$aco = is_numeric($this->args[1]) ? intval($this->args[1]) : $this->args[1];
|
||||
|
||||
if (is_string($aro) && preg_match('/^([\w]+)\.(.*)$/', $aro, $matches)) {
|
||||
$aro = array(
|
||||
'model' => $matches[1],
|
||||
'foreign_key' => $matches[2],
|
||||
);
|
||||
if (is_string($aro)) {
|
||||
$aro = $this->parseIdentifier($aro);
|
||||
}
|
||||
|
||||
if (is_string($aco) && preg_match('/^([\w]+)\.(.*)$/', $aco, $matches)) {
|
||||
$aco = array(
|
||||
'model' => $matches[1],
|
||||
'foreign_key' => $matches[2],
|
||||
);
|
||||
if (is_string($aco)) {
|
||||
$aco = $this->parseIdentifier($aco);
|
||||
}
|
||||
|
||||
$action = null;
|
||||
if (isset($this->args[2])) {
|
||||
$action = $this->args[2];
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
|
||||
/**
|
||||
* Command-line database management utility to automate programmer chores.
|
||||
*
|
||||
|
@ -26,7 +24,7 @@
|
|||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
App::import('File');
|
||||
App::import('Core', 'File', false);
|
||||
App::import('Model', 'CakeSchema', false);
|
||||
|
||||
/**
|
||||
|
@ -124,7 +122,7 @@ class SchemaShell extends Shell {
|
|||
* @access public
|
||||
*/
|
||||
function generate() {
|
||||
$this->out('Generating Schema...');
|
||||
$this->out(__('Generating Schema...', true));
|
||||
$options = array();
|
||||
if (isset($this->params['f'])) {
|
||||
$options = array('models' => false);
|
||||
|
@ -139,7 +137,7 @@ class SchemaShell extends Shell {
|
|||
$snapshot = true;
|
||||
$result = $this->in("Schema file exists.\n [O]verwrite\n [S]napshot\n [Q]uit\nWould you like to do?", array('o', 's', 'q'), 's');
|
||||
if ($result === 'q') {
|
||||
$this->_stop();
|
||||
return $this->_stop();
|
||||
}
|
||||
if ($result === 'o') {
|
||||
$snapshot = false;
|
||||
|
@ -234,7 +232,7 @@ class SchemaShell extends Shell {
|
|||
*/
|
||||
function run() {
|
||||
if (!isset($this->args[0])) {
|
||||
$this->err('command not found');
|
||||
$this->err(__('Command not found', true));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
|
@ -281,8 +279,8 @@ class SchemaShell extends Shell {
|
|||
$this->__update($Schema, $table);
|
||||
break;
|
||||
default:
|
||||
$this->err(__('command not found', true));
|
||||
$this->_stop();
|
||||
$this->err(__('Command not found', true));
|
||||
$this->_stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -315,7 +313,7 @@ class SchemaShell extends Shell {
|
|||
$this->out(array_keys($drop));
|
||||
|
||||
if ('y' == $this->in(__('Are you sure you want to drop the table(s)?', true), array('y', 'n'), 'n')) {
|
||||
$this->out('Dropping table(s).');
|
||||
$this->out(__('Dropping table(s).', true));
|
||||
$this->__run($drop, 'drop', $Schema);
|
||||
}
|
||||
|
||||
|
@ -323,7 +321,7 @@ class SchemaShell extends Shell {
|
|||
$this->out(array_keys($create));
|
||||
|
||||
if ('y' == $this->in(__('Are you sure you want to create the table(s)?', true), array('y', 'n'), 'y')) {
|
||||
$this->out('Creating table(s).');
|
||||
$this->out(__('Creating table(s).', true));
|
||||
$this->__run($create, 'create', $Schema);
|
||||
}
|
||||
|
||||
|
@ -339,7 +337,7 @@ class SchemaShell extends Shell {
|
|||
function __update($Schema, $table = null) {
|
||||
$db =& ConnectionManager::getDataSource($this->Schema->connection);
|
||||
|
||||
$this->out('Comparing Database to Schema...');
|
||||
$this->out(__('Comparing Database to Schema...', true));
|
||||
$Old = $this->Schema->read();
|
||||
$compare = $this->Schema->compare($Old, $Schema);
|
||||
|
||||
|
@ -417,7 +415,8 @@ class SchemaShell extends Shell {
|
|||
* @access public
|
||||
*/
|
||||
function help() {
|
||||
$this->out("The Schema Shell generates a schema object from \n\t\tthe database and updates the database from the schema.");
|
||||
$this->out("The Schema Shell generates a schema object from");
|
||||
$this->out("the database and updates the database from the schema.");
|
||||
$this->hr();
|
||||
$this->out("Usage: cake schema <command> <arg1> <arg2>...");
|
||||
$this->hr();
|
||||
|
|
|
@ -280,13 +280,13 @@ class ExtractTask extends Shell{
|
|||
}
|
||||
}
|
||||
unset($allTokens);
|
||||
$this->basic();
|
||||
$this->basic('__c');
|
||||
$this->extended();
|
||||
$this->extended('__dc', 2);
|
||||
$this->extended('__n', 0, true);
|
||||
$this->extended('__dn', 2, true);
|
||||
$this->extended('__dcn', 4, true);
|
||||
$this->__parse('__', array('singular'));
|
||||
$this->__parse('__n', array('singular', 'plural'));
|
||||
$this->__parse('__d', array('domain', 'singular'));
|
||||
$this->__parse('__c', array('singular'));
|
||||
$this->__parse('__dc', array('domain', 'singular'));
|
||||
$this->__parse('__dn', array('domain', 'singular', 'plural'));
|
||||
$this->__parse('__dcn', array('domain', 'singular', 'plural'));
|
||||
}
|
||||
$this->__buildFiles();
|
||||
$this->__writeFiles();
|
||||
|
@ -294,50 +294,13 @@ class ExtractTask extends Shell{
|
|||
}
|
||||
|
||||
/**
|
||||
* Will parse __(), __c() functions
|
||||
* Parse tokens
|
||||
*
|
||||
* @param string $functionName Function name that indicates translatable string (e.g: '__')
|
||||
* @param array $map Array containing what variables it will find (e.g: domain, singular, plural)
|
||||
* @access public
|
||||
*/
|
||||
function basic($functionName = '__') {
|
||||
$count = 0;
|
||||
$tokenCount = count($this->__tokens);
|
||||
|
||||
while (($tokenCount - $count) > 3) {
|
||||
list($countToken, $parenthesis, $middle, $right) = array($this->__tokens[$count], $this->__tokens[$count + 1], $this->__tokens[$count + 2], $this->__tokens[$count + 3]);
|
||||
if (!is_array($countToken)) {
|
||||
$count++;
|
||||
continue;
|
||||
}
|
||||
|
||||
list($type, $string, $line) = $countToken;
|
||||
if (($type == T_STRING) && ($string == $functionName) && ($parenthesis == '(')) {
|
||||
|
||||
if (in_array($right, array(')', ','))
|
||||
&& (is_array($middle) && ($middle[0] == T_CONSTANT_ENCAPSED_STRING))) {
|
||||
|
||||
if ($this->__oneFile === true) {
|
||||
$this->__strings[$this->__formatString($middle[1])][$this->__file][] = $line;
|
||||
} else {
|
||||
$this->__strings[$this->__file][$this->__formatString($middle[1])][] = $line;
|
||||
}
|
||||
} else {
|
||||
$this->__markerError($this->__file, $line, $functionName, $count);
|
||||
}
|
||||
}
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Will parse __d(), __dc(), __n(), __dn(), __dcn()
|
||||
*
|
||||
* @param string $functionName Function name that indicates translatable string (e.g: '__')
|
||||
* @param integer $shift Number of parameters to shift to find translateable string
|
||||
* @param boolean $plural Set to true if function supports plural format, false otherwise
|
||||
* @access public
|
||||
*/
|
||||
function extended($functionName = '__d', $shift = 0, $plural = false) {
|
||||
function __parse($functionName, $map) {
|
||||
$count = 0;
|
||||
$tokenCount = count($this->__tokens);
|
||||
|
||||
|
@ -362,50 +325,28 @@ class ExtractTask extends Shell{
|
|||
$position++;
|
||||
}
|
||||
|
||||
if ($plural) {
|
||||
$end = $position + $shift + 7;
|
||||
|
||||
if ($this->__tokens[$position + $shift + 5] === ')') {
|
||||
$end = $position + $shift + 5;
|
||||
$mapCount = count($map);
|
||||
$strings = array();
|
||||
while (count($strings) < $mapCount && ($this->__tokens[$position] == ',' || $this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING)) {
|
||||
if ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) {
|
||||
$strings[] = $this->__tokens[$position][1];
|
||||
}
|
||||
|
||||
if (empty($shift)) {
|
||||
list($singular, $firstComma, $plural, $seoncdComma, $endParenthesis) = array($this->__tokens[$position], $this->__tokens[$position + 1], $this->__tokens[$position + 2], $this->__tokens[$position + 3], $this->__tokens[$end]);
|
||||
$condition = ($seoncdComma == ',');
|
||||
} else {
|
||||
list($domain, $firstComma, $singular, $seoncdComma, $plural, $comma3, $endParenthesis) = array($this->__tokens[$position], $this->__tokens[$position + 1], $this->__tokens[$position + 2], $this->__tokens[$position + 3], $this->__tokens[$position + 4], $this->__tokens[$position + 5], $this->__tokens[$end]);
|
||||
$condition = ($comma3 == ',');
|
||||
}
|
||||
$condition = $condition &&
|
||||
(is_array($singular) && ($singular[0] == T_CONSTANT_ENCAPSED_STRING)) &&
|
||||
(is_array($plural) && ($plural[0] == T_CONSTANT_ENCAPSED_STRING));
|
||||
} else {
|
||||
if ($this->__tokens[$position + $shift + 5] === ')') {
|
||||
$comma = $this->__tokens[$position + $shift + 3];
|
||||
$end = $position + $shift + 5;
|
||||
} else {
|
||||
$comma = null;
|
||||
$end = $position + $shift + 3;
|
||||
}
|
||||
|
||||
list($domain, $firstComma, $text, $seoncdComma, $endParenthesis) = array($this->__tokens[$position], $this->__tokens[$position + 1], $this->__tokens[$position + 2], $comma, $this->__tokens[$end]);
|
||||
$condition = ($seoncdComma == ',' || $seoncdComma === null) &&
|
||||
(is_array($domain) && ($domain[0] == T_CONSTANT_ENCAPSED_STRING)) &&
|
||||
(is_array($text) && ($text[0] == T_CONSTANT_ENCAPSED_STRING));
|
||||
$position++;
|
||||
}
|
||||
|
||||
if (($endParenthesis == ')') && $condition) {
|
||||
if ($mapCount == count($strings)) {
|
||||
extract(array_combine($map, $strings));
|
||||
if ($this->__oneFile === true) {
|
||||
if ($plural) {
|
||||
$this->__strings[$this->__formatString($singular[1]) . "\0" . $this->__formatString($plural[1])][$this->__file][] = $line;
|
||||
if (isset($plural)) {
|
||||
$this->__strings[$this->__formatString($singular) . "\0" . $this->__formatString($plural)][$this->__file][] = $line;
|
||||
} else {
|
||||
$this->__strings[$this->__formatString($text[1])][$this->__file][] = $line;
|
||||
$this->__strings[$this->__formatString($singular)][$this->__file][] = $line;
|
||||
}
|
||||
} else {
|
||||
if ($plural) {
|
||||
$this->__strings[$this->__file][$this->__formatString($singular[1]) . "\0" . $this->__formatString($plural[1])][] = $line;
|
||||
$this->__strings[$this->__file][$this->__formatString($singular) . "\0" . $this->__formatString($plural)][] = $line;
|
||||
} else {
|
||||
$this->__strings[$this->__file][$this->__formatString($text[1])][] = $line;
|
||||
$this->__strings[$this->__file][$this->__formatString($singular)][] = $line;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -36,8 +36,8 @@ if (!class_exists('ShellDispatcher')) {
|
|||
ob_end_clean();
|
||||
}
|
||||
|
||||
|
||||
require_once CONSOLE_LIBS . 'shell.php';
|
||||
|
||||
/**
|
||||
* TestShellDispatcher class
|
||||
*
|
||||
|
@ -85,6 +85,7 @@ class TestShellDispatcher extends ShellDispatcher {
|
|||
* @access public
|
||||
*/
|
||||
var $TestShell;
|
||||
|
||||
/**
|
||||
* _initEnvironment method
|
||||
*
|
||||
|
@ -138,6 +139,7 @@ class TestShellDispatcher extends ShellDispatcher {
|
|||
$this->stopped = 'Stopped with status: ' . $status;
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* getShell
|
||||
*
|
||||
|
@ -148,6 +150,7 @@ class TestShellDispatcher extends ShellDispatcher {
|
|||
function getShell($plugin = null) {
|
||||
return $this->_getShell($plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* _getShell
|
||||
*
|
||||
|
@ -439,7 +442,6 @@ class ShellDispatcherTest extends CakeTestCase {
|
|||
$Dispatcher->parseParams($params);
|
||||
$this->assertEqual($expected, $Dispatcher->params);
|
||||
|
||||
|
||||
$params = array(
|
||||
'cake.php',
|
||||
'-working',
|
||||
|
@ -510,6 +512,7 @@ class ShellDispatcherTest extends CakeTestCase {
|
|||
$result = $Dispatcher->getShell('test_plugin');
|
||||
$this->assertIsA($result, 'ExampleShell');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify correct dispatch of Shell subclasses with a main method
|
||||
*
|
||||
|
@ -600,6 +603,7 @@ class ShellDispatcherTest extends CakeTestCase {
|
|||
$result = $Dispatcher->dispatch();
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify correct dispatch of Shell subclasses without a main method
|
||||
*
|
||||
|
@ -671,6 +675,7 @@ class ShellDispatcherTest extends CakeTestCase {
|
|||
$result = $Dispatcher->dispatch();
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify correct dispatch of custom classes with a main method
|
||||
*
|
||||
|
@ -750,6 +755,7 @@ class ShellDispatcherTest extends CakeTestCase {
|
|||
$result = $Dispatcher->dispatch();
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify correct dispatch of custom classes without a main method
|
||||
*
|
||||
|
@ -819,6 +825,7 @@ class ShellDispatcherTest extends CakeTestCase {
|
|||
$result = $Dispatcher->dispatch();
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that a task is called instead of the shell if the first arg equals
|
||||
* the name of the task
|
||||
|
@ -867,6 +874,7 @@ class ShellDispatcherTest extends CakeTestCase {
|
|||
$result = $Dispatcher->dispatch();
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify shifting of arguments
|
||||
*
|
||||
|
@ -906,39 +914,34 @@ class ShellDispatcherTest extends CakeTestCase {
|
|||
function testHelpCommand() {
|
||||
$Dispatcher =& new TestShellDispatcher();
|
||||
|
||||
$expected = "/ CORE(\\\|\/)tests(\\\|\/)test_app(\\\|\/)plugins(\\\|\/)test_plugin(\\\|\/)vendors(\\\|\/)shells:";
|
||||
$expected .= "\n\t example";
|
||||
$expected .= "\n/";
|
||||
$expected = "/example \[.*TestPlugin, TestPluginTwo.*\]/";
|
||||
$this->assertPattern($expected, $Dispatcher->stdout);
|
||||
|
||||
$expected = "/ CORE(\\\|\/)tests(\\\|\/)test_app(\\\|\/)plugins(\\\|\/)test_plugin_two(\\\|\/)vendors(\\\|\/)shells:";
|
||||
$expected .= "\n\t example";
|
||||
$expected .= "\n\t welcome";
|
||||
$expected .= "\n/";
|
||||
$expected = "/welcome \[.*TestPluginTwo.*\]/";
|
||||
$this->assertPattern($expected, $Dispatcher->stdout);
|
||||
|
||||
$expected = "/ APP(\\\|\/)vendors(\\\|\/)shells:";
|
||||
$expected .= "\n/";
|
||||
$expected = "/acl \[.*CORE.*\]/";
|
||||
$this->assertPattern($expected, $Dispatcher->stdout);
|
||||
|
||||
$expected = "/ ROOT(\\\|\/)vendors(\\\|\/)shells:";
|
||||
$expected .= "\n/";
|
||||
$expected = "/api \[.*CORE.*\]/";
|
||||
$this->assertPattern($expected, $Dispatcher->stdout);
|
||||
|
||||
$expected = "/ CORE(\\\|\/)console(\\\|\/)libs:";
|
||||
$expected .= "\n\t acl";
|
||||
$expected .= "\n\t api";
|
||||
$expected .= "\n\t bake";
|
||||
$expected .= "\n\t console";
|
||||
$expected .= "\n\t i18n";
|
||||
$expected .= "\n\t schema";
|
||||
$expected .= "\n\t testsuite";
|
||||
$expected .= "\n/";
|
||||
$expected = "/bake \[.*CORE.*\]/";
|
||||
$this->assertPattern($expected, $Dispatcher->stdout);
|
||||
|
||||
$expected = "/ CORE(\\\|\/)tests(\\\|\/)test_app(\\\|\/)vendors(\\\|\/)shells:";
|
||||
$expected .= "\n\t sample";
|
||||
$expected .= "\n/";
|
||||
$expected = "/console \[.*CORE.*\]/";
|
||||
$this->assertPattern($expected, $Dispatcher->stdout);
|
||||
|
||||
$expected = "/i18n \[.*CORE.*\]/";
|
||||
$this->assertPattern($expected, $Dispatcher->stdout);
|
||||
|
||||
$expected = "/schema \[.*CORE.*\]/";
|
||||
$this->assertPattern($expected, $Dispatcher->stdout);
|
||||
|
||||
$expected = "/testsuite \[.*CORE.*\]/";
|
||||
$this->assertPattern($expected, $Dispatcher->stdout);
|
||||
|
||||
$expected = "/sample \[.*test_app.*\]/";
|
||||
$this->assertPattern($expected, $Dispatcher->stdout);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,21 @@
|
|||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
|
||||
/**
|
||||
* AclShell Test file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework (http://www.cakephp.org)
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* Copyright 2006-2009, Cake Software Foundation, Inc.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @copyright Copyright 2006-2009, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
* @since CakePHP v 1.2.0.7726
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
App::import('Shell', 'Shell', false);
|
||||
|
@ -127,12 +122,27 @@ class AclShellTest extends CakeTestCase {
|
|||
$this->Task->args[0] = 'aro';
|
||||
|
||||
$this->Task->expectAt(0, 'out', array('Aro tree:'));
|
||||
$this->Task->expectAt(1, 'out', array(new PatternExpectation('/\[1\]ROOT/')));
|
||||
$this->Task->expectAt(3, 'out', array(new PatternExpectation('/\[3\]Gandalf/')));
|
||||
$this->Task->expectAt(5, 'out', array(new PatternExpectation('/\[5\]MyModel.2/')));
|
||||
$this->Task->expectAt(1, 'out', array(new PatternExpectation('/\[1\] ROOT/')));
|
||||
$this->Task->expectAt(3, 'out', array(new PatternExpectation('/\[3\] Gandalf/')));
|
||||
$this->Task->expectAt(5, 'out', array(new PatternExpectation('/\[5\] MyModel.2/')));
|
||||
|
||||
$this->Task->view();
|
||||
}
|
||||
|
||||
/**
|
||||
* test view with an argument
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testViewWithArgument() {
|
||||
$this->Task->args = array('aro', 'admins');
|
||||
$this->Task->expectAt(0, 'out', array('Aro tree:'));
|
||||
$this->Task->expectAt(1, 'out', array(' [2] admins'));
|
||||
$this->Task->expectAt(2, 'out', array(' [3] Gandalf'));
|
||||
$this->Task->expectAt(3, 'out', array(' [4] Elrond'));
|
||||
$this->Task->view();
|
||||
}
|
||||
|
||||
/**
|
||||
* test the method that splits model.foreign key. and that it returns an array.
|
||||
*
|
||||
|
@ -217,5 +227,91 @@ class AclShellTest extends CakeTestCase {
|
|||
$result = $Aro->read(null, 4);
|
||||
$this->assertEqual($result['Aro']['parent_id'], null);
|
||||
}
|
||||
|
||||
/**
|
||||
* test grant
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testGrant() {
|
||||
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create');
|
||||
$this->Task->expectAt(0, 'out', array(new PatternExpectation('/Permission granted/'), true));
|
||||
$this->Task->grant();
|
||||
|
||||
$node = $this->Task->Acl->Aro->read(null, 4);
|
||||
$this->assertFalse(empty($node['Aco'][0]));
|
||||
$this->assertEqual($node['Aco'][0]['Permission']['_create'], 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* test deny
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testDeny() {
|
||||
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create');
|
||||
$this->Task->expectAt(0, 'out', array(new PatternExpectation('/Permission denied/'), true));
|
||||
$this->Task->deny();
|
||||
|
||||
$node = $this->Task->Acl->Aro->read(null, 4);
|
||||
$this->assertFalse(empty($node['Aco'][0]));
|
||||
$this->assertEqual($node['Aco'][0]['Permission']['_create'], -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* test checking allowed and denied perms
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testCheck() {
|
||||
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', '*');
|
||||
$this->Task->expectAt(0, 'out', array(new PatternExpectation('/not allowed/'), true));
|
||||
$this->Task->check();
|
||||
|
||||
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create');
|
||||
$this->Task->expectAt(1, 'out', array(new PatternExpectation('/Permission granted/'), true));
|
||||
$this->Task->grant();
|
||||
|
||||
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create');
|
||||
$this->Task->expectAt(2, 'out', array(new PatternExpectation('/is allowed/'), true));
|
||||
$this->Task->check();
|
||||
|
||||
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', '*');
|
||||
$this->Task->expectAt(3, 'out', array(new PatternExpectation('/not allowed/'), true));
|
||||
$this->Task->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* test inherit and that it 0's the permission fields.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testInherit() {
|
||||
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create');
|
||||
$this->Task->expectAt(0, 'out', array(new PatternExpectation('/Permission granted/'), true));
|
||||
$this->Task->grant();
|
||||
|
||||
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'all');
|
||||
$this->Task->expectAt(1, 'out', array(new PatternExpectation('/permission inherited/i'), true));
|
||||
$this->Task->inherit();
|
||||
|
||||
$node = $this->Task->Acl->Aro->read(null, 4);
|
||||
$this->assertFalse(empty($node['Aco'][0]));
|
||||
$this->assertEqual($node['Aco'][0]['Permission']['_create'], 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* test getting the path for an aro/aco
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testGetPath() {
|
||||
$this->Task->args = array('aro', 'AuthUser.2');
|
||||
$this->Task->expectAt(1, 'out', array('[1] ROOT'));
|
||||
$this->Task->expectAt(2, 'out', array(' [2] admins'));
|
||||
$this->Task->expectAt(3, 'out', array(' [4] Elrond'));
|
||||
$this->Task->getPath();
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
283
cake/tests/cases/console/libs/schema.test.php
Normal file
283
cake/tests/cases/console/libs/schema.test.php
Normal file
|
@ -0,0 +1,283 @@
|
|||
<?php
|
||||
/**
|
||||
* SchemaShellTest Test file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework (http://www.cakephp.org)
|
||||
* Copyright 2006-2009, Cake Software Foundation, Inc.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2009, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.Shells
|
||||
* @since CakePHP v 1.3
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
App::import('Shell', 'Shell', false);
|
||||
App::import('Model', 'CakeSchema', false);
|
||||
|
||||
if (!defined('DISABLE_AUTO_DISPATCH')) {
|
||||
define('DISABLE_AUTO_DISPATCH', true);
|
||||
}
|
||||
|
||||
if (!class_exists('ShellDispatcher')) {
|
||||
ob_start();
|
||||
$argv = false;
|
||||
require CAKE . 'console' . DS . 'cake.php';
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
if (!class_exists('SchemaShell')) {
|
||||
require CAKE . 'console' . DS . 'libs' . DS . 'schema.php';
|
||||
}
|
||||
|
||||
Mock::generatePartial(
|
||||
'ShellDispatcher', 'TestSchemaShellMockShellDispatcher',
|
||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
||||
);
|
||||
Mock::generatePartial(
|
||||
'SchemaShell', 'MockSchemaShell',
|
||||
array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop')
|
||||
);
|
||||
|
||||
Mock::generate('CakeSchema', 'MockSchemaCakeSchema');
|
||||
|
||||
/**
|
||||
* SchemaShellTest class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.Shells
|
||||
*/
|
||||
class SchemaShellTest extends CakeTestCase {
|
||||
|
||||
var $fixtures = array('core.article', 'core.user');
|
||||
/**
|
||||
* startTest method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function startTest() {
|
||||
$this->Dispatcher =& new TestSchemaShellMockShellDispatcher();
|
||||
$this->Shell =& new MockSchemaShell($this->Dispatcher);
|
||||
$this->Shell->Dispatch =& $this->Dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* endTest method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function endTest() {
|
||||
ClassRegistry::flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* test startup method
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testStartup() {
|
||||
$this->Shell->startup();
|
||||
$this->assertTrue(isset($this->Shell->Schema));
|
||||
$this->assertTrue(is_a($this->Shell->Schema, 'CakeSchema'));
|
||||
$this->assertEqual($this->Shell->Schema->name, 'App');
|
||||
$this->assertEqual($this->Shell->Schema->file, 'schema.php');
|
||||
|
||||
unset($this->Shell->Schema);
|
||||
$this->Shell->params = array(
|
||||
'name' => 'TestSchema'
|
||||
);
|
||||
$this->Shell->startup();
|
||||
$this->assertEqual($this->Shell->Schema->name, 'TestSchema');
|
||||
$this->assertEqual($this->Shell->Schema->file, 'test_schema.php');
|
||||
$this->assertEqual($this->Shell->Schema->connection, 'default');
|
||||
$this->assertEqual($this->Shell->Schema->path, APP . 'config' . DS . 'schema');
|
||||
|
||||
unset($this->Shell->Schema);
|
||||
$this->Shell->params = array(
|
||||
'file' => 'other_file.php',
|
||||
'connection' => 'test_suite',
|
||||
'path' => '/test/path'
|
||||
);
|
||||
$this->Shell->startup();
|
||||
$this->assertEqual($this->Shell->Schema->name, 'App');
|
||||
$this->assertEqual($this->Shell->Schema->file, 'other_file.php');
|
||||
$this->assertEqual($this->Shell->Schema->connection, 'test_suite');
|
||||
$this->assertEqual($this->Shell->Schema->path, '/test/path');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test View - and that it dumps the schema file to stdout
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testView() {
|
||||
$this->Shell->startup();
|
||||
$this->Shell->Schema->path = APP . 'config' . DS . 'schema';
|
||||
$this->Shell->params['file'] = 'i18n.php';
|
||||
$this->Shell->expectOnce('_stop');
|
||||
$this->Shell->expectOnce('out');
|
||||
$this->Shell->expectAt(0, 'out', array(new PatternExpectation('/class i18nSchema extends CakeSchema/')));
|
||||
$this->Shell->view();
|
||||
}
|
||||
|
||||
/**
|
||||
* test dumping a schema file.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testDump() {
|
||||
$this->Shell->params = array('name' => 'i18n');
|
||||
$this->Shell->startup();
|
||||
$this->Shell->Schema->path = APP . 'config' . DS . 'schema';
|
||||
$this->Shell->expectAt(0, 'out', array(new PatternExpectation('/create table `i18n`/i')));
|
||||
$this->Shell->dump();
|
||||
}
|
||||
|
||||
/**
|
||||
* test dump() with sql file generation
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testDumpWithFileWriting() {
|
||||
$file =& new File(APP . 'config' . DS . 'schema' . DS . 'i18n.php');
|
||||
$contents = $file->read();
|
||||
$file =& new File(TMP . 'tests' . DS . 'i18n.php');
|
||||
$file->write($contents);
|
||||
|
||||
$this->Shell->params = array('name' => 'i18n');
|
||||
$this->Shell->args = array('write');
|
||||
$this->Shell->startup();
|
||||
$this->Shell->Schema->path = TMP . 'tests';
|
||||
$this->Shell->dump();
|
||||
|
||||
$sql =& new File(TMP . 'tests' . DS . 'i18n.sql');
|
||||
$contents = $sql->read();
|
||||
$this->assertPattern('/DROP TABLE/', $contents);
|
||||
$this->assertPattern('/CREATE TABLE `i18n`/', $contents);
|
||||
$this->assertPattern('/id/', $contents);
|
||||
$this->assertPattern('/model/', $contents);
|
||||
$this->assertPattern('/field/', $contents);
|
||||
$this->assertPattern('/locale/', $contents);
|
||||
$this->assertPattern('/foreign_key/', $contents);
|
||||
$this->assertPattern('/content/', $contents);
|
||||
|
||||
$sql->delete();
|
||||
$file->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* test generate with snapshot generation
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testGenerateSnaphot() {
|
||||
$this->Shell->path = TMP;
|
||||
$this->Shell->params['file'] = 'schema.php';
|
||||
$this->Shell->args = array('snapshot');
|
||||
$this->Shell->Schema =& new MockSchemaCakeSchema();
|
||||
$this->Shell->Schema->setReturnValue('read', array('schema data'));
|
||||
$this->Shell->Schema->setReturnValue('write', true);
|
||||
|
||||
$this->Shell->Schema->expectOnce('read');
|
||||
$this->Shell->Schema->expectOnce('write', array(array('schema data', 'file' => 'schema_1.php')));
|
||||
|
||||
$this->Shell->generate();
|
||||
}
|
||||
|
||||
/**
|
||||
* test generate without a snapshot.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testGenerateNoOverwrite() {
|
||||
touch(TMP . 'schema.php');
|
||||
$this->Shell->params['file'] = 'schema.php';
|
||||
$this->Shell->args = array();
|
||||
|
||||
$this->Shell->setReturnValue('in', 'q');
|
||||
$this->Shell->Schema =& new MockSchemaCakeSchema();
|
||||
$this->Shell->Schema->path = TMP;
|
||||
$this->Shell->Schema->expectNever('read');
|
||||
|
||||
$result = $this->Shell->generate();
|
||||
unlink(TMP . 'schema.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* test generate with overwriting of the schema files.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testGenerateOverwrite() {
|
||||
touch(TMP . 'schema.php');
|
||||
$this->Shell->params['file'] = 'schema.php';
|
||||
$this->Shell->args = array();
|
||||
|
||||
$this->Shell->setReturnValue('in', 'o');
|
||||
$this->Shell->expectAt(1, 'out', array(new PatternExpectation('/Schema file:\s[a-z\.]+\sgenerated/')));
|
||||
$this->Shell->Schema =& new MockSchemaCakeSchema();
|
||||
$this->Shell->Schema->path = TMP;
|
||||
$this->Shell->Schema->setReturnValue('read', array('schema data'));
|
||||
$this->Shell->Schema->setReturnValue('write', true);
|
||||
|
||||
$this->Shell->Schema->expectOnce('read');
|
||||
$this->Shell->Schema->expectOnce('write', array(array('schema data', 'file' => 'schema.php')));
|
||||
|
||||
$this->Shell->generate();
|
||||
unlink(TMP . 'schema.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test schema run create with no table args.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testRunCreateNoArgs() {
|
||||
$this->Shell->params = array(
|
||||
'connection' => 'test_suite',
|
||||
'name' => 'i18n',
|
||||
'path' => APP . 'config' . DS . 'schema'
|
||||
);
|
||||
$this->Shell->args = array('create');
|
||||
$this->Shell->startup();
|
||||
$this->Shell->setReturnValue('in', 'y');
|
||||
$this->Shell->run();
|
||||
|
||||
$db =& ConnectionManager::getDataSource('test_suite');
|
||||
$sources = $db->listSources();
|
||||
$this->assertTrue(in_array('i18n', $sources));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test schema run create with no table args.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testRunCreateWithTableArgs() {
|
||||
$this->Shell->params = array(
|
||||
'connection' => 'test_suite',
|
||||
'name' => 'DbAcl',
|
||||
'path' => APP . 'config' . DS . 'schema'
|
||||
);
|
||||
$this->Shell->args = array('create', 'acos');
|
||||
$this->Shell->startup();
|
||||
$this->Shell->setReturnValue('in', 'y');
|
||||
$this->Shell->run();
|
||||
|
||||
$db =& ConnectionManager::getDataSource('test_suite');
|
||||
$sources = $db->listSources();
|
||||
$this->assertTrue(in_array('acos', $sources));
|
||||
$this->assertFalse(in_array('aros', $sources));
|
||||
$this->assertFalse(in_array('aros_acos', $sources));
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -85,7 +85,7 @@ class DbConfigTaskTest extends CakeTestCase {
|
|||
$this->Task->Dispatch =& $this->Dispatcher;
|
||||
$this->Task->Dispatch->shellPaths = App::path('shells');
|
||||
|
||||
$this->Task->params['working'] = rtrim(APP, '/');
|
||||
$this->Task->params['working'] = rtrim(APP, DS);
|
||||
$this->Task->databaseClassName = 'TEST_DATABASE_CONFIG';
|
||||
}
|
||||
|
||||
|
|
|
@ -107,6 +107,7 @@ class ExtractTaskTest extends CakeTestCase {
|
|||
$pattern = '/"Plural-Forms\: nplurals\=INTEGER; plural\=EXPRESSION;/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
|
||||
// home.ctp
|
||||
$pattern = '/msgid "Your tmp directory is writable."\nmsgstr ""\n/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
$pattern = '/msgid "Your tmp directory is NOT writable."\nmsgstr ""\n/';
|
||||
|
@ -134,6 +135,17 @@ class ExtractTaskTest extends CakeTestCase {
|
|||
$pattern .= 'edit: %s.*You can also add some CSS styles for your pages at: %s"\nmsgstr ""/s';
|
||||
$this->assertPattern($pattern, $result);
|
||||
|
||||
// extract.ctp
|
||||
$pattern = '/msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
$pattern = '/msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
|
||||
$pattern = '/msgid "You have %d new message \(domain\)."\nmsgid_plural "You have %d new messages \(domain\)."/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
$pattern = '/msgid "You deleted %d message \(domain\)."\nmsgid_plural "You deleted %d messages \(domain\)."/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
|
||||
$Folder = new Folder($path);
|
||||
$Folder->delete();
|
||||
}
|
||||
|
|
|
@ -96,10 +96,10 @@ class FixtureTaskTest extends CakeTestCase {
|
|||
* @return void
|
||||
**/
|
||||
function testConstruct() {
|
||||
$this->Dispatch->params['working'] = '/my/path';
|
||||
$this->Dispatch->params['working'] = DS . 'my' . DS . 'path';
|
||||
$Task =& new FixtureTask($this->Dispatch);
|
||||
|
||||
$expected = '/my/path/tests/fixtures/';
|
||||
$expected = DS . 'my' . DS . 'path' . DS . 'tests' . DS . 'fixtures' . DS;
|
||||
$this->assertEqual($Task->path, $expected);
|
||||
}
|
||||
|
||||
|
|
|
@ -254,8 +254,11 @@ class ViewTest extends CakeTestCase {
|
|||
function startTest() {
|
||||
App::build(array(
|
||||
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
|
||||
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
|
||||
));
|
||||
'views' => array(
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS,
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS
|
||||
)
|
||||
), true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -303,8 +306,10 @@ class ViewTest extends CakeTestCase {
|
|||
$this->Controller->action = 'index';
|
||||
|
||||
$View = new TestView($this->Controller);
|
||||
Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));
|
||||
Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS));
|
||||
App::build(array(
|
||||
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
|
||||
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
|
||||
));
|
||||
|
||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS .'test_plugin' . DS . 'views' . DS .'tests' . DS .'index.ctp';
|
||||
$result = $View->getViewFileName('index');
|
||||
|
|
30
cake/tests/fixtures/aco_fixture.php
vendored
30
cake/tests/fixtures/aco_fixture.php
vendored
|
@ -49,13 +49,13 @@ class AcoFixture extends CakeTestFixture {
|
|||
* @access public
|
||||
*/
|
||||
var $fields = array(
|
||||
'id' => array('type' => 'integer', 'key' => 'primary'),
|
||||
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
|
||||
'model' => array('type' => 'string', 'default' => ''),
|
||||
'id' => array('type' => 'integer', 'key' => 'primary'),
|
||||
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
|
||||
'model' => array('type' => 'string', 'default' => ''),
|
||||
'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true),
|
||||
'alias' => array('type' => 'string', 'default' => ''),
|
||||
'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),
|
||||
'rght' => array('type' => 'integer', 'length' => 10, 'null' => true)
|
||||
'alias' => array('type' => 'string', 'default' => ''),
|
||||
'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),
|
||||
'rght' => array('type' => 'integer', 'length' => 10, 'null' => true)
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -65,15 +65,15 @@ class AcoFixture extends CakeTestFixture {
|
|||
* @access public
|
||||
*/
|
||||
var $records = array(
|
||||
array('parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'ROOT', 'lft' => 1, 'rght' => 18),
|
||||
array('parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Controller1', 'lft' => 2, 'rght' => 9),
|
||||
array('parent_id' => 2, 'model' => null, 'foreign_key' => null, 'alias' => 'action1', 'lft' => 3, 'rght' => 6),
|
||||
array('parent_id' => 3, 'model' => null, 'foreign_key' => null, 'alias' => 'record1', 'lft' => 4, 'rght' => 5),
|
||||
array('parent_id' => 2, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 7, 'rght' => 8),
|
||||
array('parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Controller2', 'lft' => 10, 'rght' => 17),
|
||||
array('parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action1', 'lft' => 11, 'rght' => 14),
|
||||
array('parent_id' => 7, 'model' => null, 'foreign_key' => null, 'alias' => 'record1', 'lft' => 12, 'rght' => 13),
|
||||
array('parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 15, 'rght' => 16),
|
||||
array('parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'ROOT', 'lft' => 1, 'rght' => 18),
|
||||
array('parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Controller1', 'lft' => 2, 'rght' => 9),
|
||||
array('parent_id' => 2, 'model' => null, 'foreign_key' => null, 'alias' => 'action1', 'lft' => 3, 'rght' => 6),
|
||||
array('parent_id' => 3, 'model' => null, 'foreign_key' => null, 'alias' => 'record1', 'lft' => 4, 'rght' => 5),
|
||||
array('parent_id' => 2, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 7, 'rght' => 8),
|
||||
array('parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Controller2','lft' => 10, 'rght' => 17),
|
||||
array('parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action1', 'lft' => 11, 'rght' => 14),
|
||||
array('parent_id' => 7, 'model' => null, 'foreign_key' => null, 'alias' => 'record1', 'lft' => 12, 'rght' => 13),
|
||||
array('parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 15, 'rght' => 16),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
11
cake/tests/test_app/views/pages/extract.ctp
Normal file
11
cake/tests/test_app/views/pages/extract.ctp
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
$count = 10;
|
||||
$message = array('count' => 10);
|
||||
|
||||
// Plural
|
||||
__n('You have %d new message.', 'You have %d new messages.', $count);
|
||||
__n('You deleted %d message.', 'You deleted %d messages.', $messages['count']);
|
||||
|
||||
// Domain Plural
|
||||
__dn('domain', 'You have %d new message (domain).', 'You have %d new messages (domain).', '10');
|
||||
__dn('domain', 'You deleted %d message (domain).', 'You deleted %d messages (domain).', $messages['count']);
|
Loading…
Add table
Reference in a new issue