Merge remote branch 'upstream/2.0' into 2.0

This commit is contained in:
Jeremy Harris 2011-01-21 15:09:06 -08:00
commit c970770c8d
22 changed files with 230 additions and 34 deletions

View file

@ -79,7 +79,7 @@ if (isset($corePath[0])) {
}
if (Configure::read('debug') < 1) {
die(__('Debug setting does not allow access to this url.', true));
die(__('Debug setting does not allow access to this url.'));
}
require_once CAKE_TESTS_LIB . 'cake_test_suite_dispatcher.php';

View file

@ -104,7 +104,7 @@ class DbConfigTask extends Shell {
}
}
$driver = $this->in('Driver:', array('db2', 'firebird', 'mssql', 'mysql', 'odbc', 'oracle', 'postgres', 'sqlite', 'sybase'), 'mysql');
$driver = $this->in('Driver:', array('mssql', 'mysql', 'oracle', 'postgres', 'sqlite'), 'mysql');
$persistent = $this->in('Persistent Connection?', array('y', 'n'), 'n');
if (strtolower($persistent) == 'n') {

View file

@ -18,11 +18,22 @@
*/
?>
/**
* <?php echo $admin ?>index method
*
* @return void
*/
public function <?php echo $admin ?>index() {
$this-><?php echo $currentModelName ?>->recursive = 0;
$this->set('<?php echo $pluralName ?>', $this->paginate());
}
/**
* <?php echo $admin ?>view method
*
* @param string $id
* @return void
*/
public function <?php echo $admin ?>view($id = null) {
$this-><?php echo $currentModelName; ?>->id = $id;
if (!$this-><?php echo $currentModelName; ?>->exists()) {
@ -32,6 +43,11 @@
}
<?php $compact = array(); ?>
/**
* <?php echo $admin ?>add method
*
* @return void
*/
public function <?php echo $admin ?>add() {
if ($this->request->is('post')) {
$this-><?php echo $currentModelName; ?>->create();
@ -66,6 +82,12 @@
}
<?php $compact = array(); ?>
/**
* <?php echo $admin ?>edit method
*
* @param string $id
* @return void
*/
public function <?php echo $admin; ?>edit($id = null) {
$this-><?php echo $currentModelName; ?>->id = $id;
if (!$this-><?php echo $currentModelName; ?>->exists()) {
@ -104,6 +126,12 @@
?>
}
/**
* <?php echo $admin ?>delete method
*
* @param string $id
* @return void
*/
public function <?php echo $admin; ?>delete($id = null) {
if (!$this->request->is('post')) {
throw new MethodNotAllowedException();

View file

@ -21,14 +21,23 @@
echo "<?php\n";
?>
/**
* <?php echo $controllerName; ?> Controller
*
*/
class <?php echo $controllerName; ?>Controller extends <?php echo $plugin; ?>AppController {
public $name = '<?php echo $controllerName; ?>';
<?php if ($isScaffold): ?>
/**
* Scaffold
*
* @var mixed
*/
public $scaffold;
<?php else: ?>
<?php
if (count($helpers)):
echo "/**\n * Helpers\n *\n * @var array\n */\n";
echo "\tvar \$helpers = array(";
for ($i = 0, $len = count($helpers); $i < $len; $i++):
if ($i != $len - 1):
@ -41,6 +50,7 @@ if (count($helpers)):
endif;
if (count($components)):
echo "/**\n * Components\n *\n * @var array\n */\n";
echo "\tpublic \$components = array(";
for ($i = 0, $len = count($components); $i < $len; $i++):
if ($i != $len - 1):

View file

@ -21,20 +21,44 @@
?>
<?php echo '<?php' . "\n"; ?>
/* <?php echo $model; ?> Fixture generated on: <?php echo date('Y-m-d H:i:s') . " : ". time(); ?> */
/**
* <?php echo $model; ?>Fixture
*
*/
class <?php echo $model; ?>Fixture extends CakeTestFixture {
public $name = '<?php echo $model; ?>';
<?php if ($table): ?>
/**
* Table name
*
* @var string
*/
public $table = '<?php echo $table; ?>';
<?php endif; ?>
<?php if ($import): ?>
/**
* Import
*
* @var array
*/
public $import = <?php echo $import; ?>;
<?php endif; ?>
<?php if ($schema): ?>
/**
* Fields
*
* @var array
*/
public $fields = <?php echo $schema; ?>;
<?php endif;?>
<?php if ($records): ?>
/**
* Records
*
* @var array
*/
public $records = <?php echo $records; ?>;
<?php endif;?>
}

View file

@ -20,23 +20,43 @@
*/
echo "<?php\n"; ?>
/**
* <?php echo $name ?> Model
*
*/
class <?php echo $name ?> extends <?php echo $plugin; ?>AppModel {
public $name = '<?php echo $name; ?>';
<?php if ($useDbConfig != 'default'): ?>
/**
* Use database config
*
* @var string
*/
public $useDbConfig = '<?php echo $useDbConfig; ?>';
<?php endif;?>
<?php if ($useTable && $useTable !== Inflector::tableize($name)):
$table = "'$useTable'";
echo "/**\n * Use table\n *\n * @var mixed False or table name\n */\n";
echo "\tpublic \$useTable = $table;\n";
endif;
if ($primaryKey !== 'id'): ?>
/**
* Primary key field
*
* @var string
*/
public $primaryKey = '<?php echo $primaryKey; ?>';
<?php endif;
if ($displayField): ?>
/**
* Display field
*
* @var string
*/
public $displayField = '<?php echo $displayField; ?>';
<?php endif;
if (!empty($validate)):
echo "/**\n * Validation rules\n *\n * @var array\n */\n";
echo "\tpublic \$validate = array(\n";
foreach ($validate as $field => $validations):
echo "\t\t'$field' => array(\n";
@ -58,6 +78,7 @@ endif;
foreach ($associations as $assoc):
if (!empty($assoc)):
?>
//The Associations below have been created with all possible keys, those that are not needed can be removed
<?php
break;
@ -67,6 +88,7 @@ endforeach;
foreach (array('hasOne', 'belongsTo') as $assocType):
if (!empty($associations[$assocType])):
$typeCount = count($associations[$assocType]);
echo "\n/**\n * $assocType associations\n *\n * @var array\n */";
echo "\n\tpublic \$$assocType = array(";
foreach ($associations[$assocType] as $i => $relation):
$out = "\n\t\t'{$relation['alias']}' => array(\n";
@ -87,6 +109,7 @@ endforeach;
if (!empty($associations['hasMany'])):
$belongsToCount = count($associations['hasMany']);
echo "\n/**\n * hasMany associations\n *\n * @var array\n */";
echo "\n\tpublic \$hasMany = array(";
foreach ($associations['hasMany'] as $i => $relation):
$out = "\n\t\t'{$relation['alias']}' => array(\n";
@ -112,6 +135,7 @@ endif;
if (!empty($associations['hasAndBelongsToMany'])):
$habtmCount = count($associations['hasAndBelongsToMany']);
echo "\n/**\n * hasAndBelongsToMany associations\n *\n * @var array\n */";
echo "\n\tpublic \$hasAndBelongsToMany = array(";
foreach ($associations['hasAndBelongsToMany'] as $i => $relation):
$out = "\n\t\t'{$relation['alias']}' => array(\n";

View file

@ -23,30 +23,75 @@ echo "/* ". $className ." Test cases generated on: " . date('Y-m-d H:i:s') . " :
App::import('<?php echo $type; ?>', '<?php echo $plugin . $className;?>');
<?php if ($mock and strtolower($type) == 'controller'): ?>
/**
* Test<?php echo $fullClassName; ?>
*
*/
class Test<?php echo $fullClassName; ?> extends <?php echo $fullClassName; ?> {
/**
* Auto render
*
* @var boolean
*/
public $autoRender = false;
/**
* Redirect action
*
* @param mixed $url
* @param mixed $status
* @param boolean $exit
* @return void
*/
public function redirect($url, $status = null, $exit = true) {
$this->redirectUrl = $url;
}
}
<?php endif; ?>
/**
* <?php echo $fullClassName; ?> Test Case
*
*/
class <?php echo $fullClassName; ?>TestCase extends CakeTestCase {
<?php if (!empty($fixtures)): ?>
/**
* Fixtures
*
* @var array
*/
public $fixtures = array('<?php echo join("', '", $fixtures); ?>');
<?php endif; ?>
public function startTest() {
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$this-><?php echo $className . ' = ' . $construction; ?>
}
public function endTest() {
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
unset($this-><?php echo $className;?>);
ClassRegistry::flush();
parent::tearDown();
}
<?php foreach ($methods as $method): ?>
/**
* test<?php echo Inflector::classify($method); ?> method
*
* @return void
*/
public function test<?php echo Inflector::classify($method); ?>() {
}

View file

@ -79,7 +79,7 @@ if (isset($corePath[0])) {
}
if (Configure::read('debug') < 1) {
die(__('Debug setting does not allow access to this url.', true));
die(__('Debug setting does not allow access to this url.'));
}
require_once CAKE_TESTS_LIB . 'cake_test_suite_dispatcher.php';

View file

@ -644,15 +644,13 @@ class Controller extends Object {
if ($response === false) {
return;
}
if (is_array($response)) {
foreach ($response as $resp) {
if (is_array($resp) && isset($resp['url'])) {
extract($resp, EXTR_OVERWRITE);
} elseif ($resp !== null) {
$url = $resp;
}
}
extract($this->_parseBeforeRedirect($response, $url, $status, $exit), EXTR_OVERWRITE);
$response = $this->beforeRedirect($url, $status, $exit);
if ($response === false) {
return;
}
extract($this->_parseBeforeRedirect($response, $url, $status, $exit), EXTR_OVERWRITE);
if (function_exists('session_write_close')) {
session_write_close();
@ -679,6 +677,28 @@ class Controller extends Object {
}
}
/**
* Parse beforeRedirect Response
*
* @param mixed $response Response from beforeRedirect callback
* @param mixed $url The same value of beforeRedirect
* @param integer $status The same value of beforeRedirect
* @param boolean $exit The same value of beforeRedirect
* @return array Array with keys url, status and exit
*/
protected function _parseBeforeRedirect($response, $url, $status, $exit) {
if (is_array($response)) {
foreach ($response as $resp) {
if (is_array($resp) && isset($resp['url'])) {
extract($resp, EXTR_OVERWRITE);
} elseif ($resp !== null) {
$url = $resp;
}
}
}
return compact('url', 'status', 'exit');
}
/**
* Convenience and object wrapper method for CakeResponse::header().
*
@ -990,6 +1010,23 @@ class Controller extends Object {
public function beforeRender() {
}
/**
* The beforeRedirect method is invoked when the controller's redirect method is called but before any
* further action. If this method returns false the controller will not continue on to redirect the request.
* The $url, $status and $exit variables have same meaning as for the controller's method. You can also
* return a string which will be interpreted as the url to redirect to or return associative array with
* key 'url' and optionally 'status' and 'exit'.
*
* @param mixed $url A string or array-based URL pointing to another location within the app,
* or an absolute URL
* @param integer $status Optional HTTP status code (eg: 404)
* @param boolean $exit If true, exit() will be called after the redirect
* @return boolean
*/
public function beforeRedirect($url, $status = null, $exit = true) {
return true;
}
/**
* Called after the controller action is run and rendered.
*

View file

@ -1084,11 +1084,14 @@ class Router {
*/
public static function reverse($params) {
if ($params instanceof CakeRequest) {
$url = $params->query;
$params = $params->params;
} else {
$url = $params['url'];
}
$pass = $params['pass'];
$named = $params['named'];
$url = $params['url'];
unset(
$params['pass'], $params['named'], $params['paging'], $params['models'], $params['url'], $url['url'],
$params['autoRender'], $params['bare'], $params['requested'], $params['return']

View file

@ -247,7 +247,7 @@ class Validation {
}
break;
default:
self::$errors[] = __('You must define the $operator parameter for Validation::comparison()', true);
self::$errors[] = __('You must define the $operator parameter for Validation::comparison()');
break;
}
return false;
@ -266,7 +266,7 @@ class Validation {
extract(self::_defaults($check));
}
if ($regex === null) {
self::$errors[] = __('You must define a regular expression for Validation::custom()', true);
self::$errors[] = __('You must define a regular expression for Validation::custom()');
return false;
}
return self::_check($check, $regex);

View file

@ -18,7 +18,7 @@
?>
<h2><?php echo $name; ?></h2>
<p class="error">
<strong><?php echo __('Error', true); ?>: </strong>
<strong><?php echo __('Error'); ?>: </strong>
<?php echo __('An Internal Error Has Occurred.'); ?>
</p>
<?php

View file

@ -35,7 +35,7 @@
<body>
<div id="container">
<div id="header">
<h1><?php echo $this->Html->link(__('CakePHP: the rapid development php framework', true), 'http://cakephp.org'); ?></h1>
<h1><?php echo $this->Html->link(__('CakePHP: the rapid development php framework'), 'http://cakephp.org'); ?></h1>
</div>
<div id="content">

View file

@ -120,7 +120,7 @@ You can also add some CSS styles for your pages at: APP/webroot/css.');
<p>
<?php
echo $this->Html->link(
sprintf('<strong>%s</strong> %s', __('New', true), __('CakePHP 1.3 Docs', true)),
sprintf('<strong>%s</strong> %s', __('New'), __('CakePHP 1.3 Docs')),
'http://book.cakephp.org/view/875/x1-3-Collection',
array('target' => '_blank', 'escape' => false)
);
@ -129,7 +129,7 @@ You can also add some CSS styles for your pages at: APP/webroot/css.');
<p>
<?php
echo $this->Html->link(
__('The 15 min Blog Tutorial', true),
__('The 15 min Blog Tutorial'),
'http://book.cakephp.org/view/1528/Blog',
array('target' => '_blank', 'escape' => false)
);

View file

@ -140,9 +140,9 @@ $otherSingularVar = Inflector::variable($_alias);
}
echo "\t\t\t<td class=\"actions\">\n";
echo "\t\t\t\t" . $this->Html->link(__('View', true), array('controller' => $_details['controller'], 'action' => 'view', ${$otherSingularVar}[$_details['primaryKey']])). "\n";
echo "\t\t\t\t" . $this->Html->link(__('Edit', true), array('controller' => $_details['controller'], 'action' => 'edit', ${$otherSingularVar}[$_details['primaryKey']])). "\n";
echo "\t\t\t\t" . $this->Html->link(__('Delete', true), array('controller' => $_details['controller'], 'action' => 'delete', ${$otherSingularVar}[$_details['primaryKey']]), null, __('Are you sure you want to delete', true).' #' . ${$otherSingularVar}[$_details['primaryKey']] . '?'). "\n";
echo "\t\t\t\t" . $this->Html->link(__('View'), array('controller' => $_details['controller'], 'action' => 'view', ${$otherSingularVar}[$_details['primaryKey']])). "\n";
echo "\t\t\t\t" . $this->Html->link(__('Edit'), array('controller' => $_details['controller'], 'action' => 'edit', ${$otherSingularVar}[$_details['primaryKey']])). "\n";
echo "\t\t\t\t" . $this->Html->link(__('Delete'), array('controller' => $_details['controller'], 'action' => 'delete', ${$otherSingularVar}[$_details['primaryKey']]), null, __('Are you sure you want to delete', true).' #' . ${$otherSingularVar}[$_details['primaryKey']] . '?'). "\n";
echo "\t\t\t</td>\n";
echo "\t\t</tr>\n";
endforeach;

View file

@ -299,7 +299,6 @@ class FixtureTaskTest extends CakeTestCase {
$result = $this->Task->bake('Article', 'comments');
$this->assertPattern('/class ArticleFixture extends CakeTestFixture/', $result);
$this->assertPattern('/public \$name \= \'Article\';/', $result);
$this->assertPattern('/public \$table \= \'comments\';/', $result);
$this->assertPattern('/public \$fields = array\(/', $result);

View file

@ -668,7 +668,6 @@ class ModelTaskTest extends CakeTestCase {
);
$result = $this->Task->bake('BakeArticle', compact('validate'));
$this->assertPattern('/class BakeArticle extends AppModel \{/', $result);
$this->assertPattern('/\$name \= \'BakeArticle\'/', $result);
$this->assertPattern('/\$validate \= array\(/', $result);
$expected = <<< STRINGEND
array(

View file

@ -850,6 +850,23 @@ class ControllerTest extends CakeTestCase {
$Controller->redirect('http://cakephp.org', 301);
}
/**
* test that beforeRedirect callback returnning false in controller
*
* @return void
*/
function testRedirectBeforeRedirectInController() {
$Controller = $this->getMock('Controller', array('_stop', 'beforeRedirect'));
$Controller->response = $this->getMock('CakeResponse', array('header'));
$Controller->Components = $this->getMock('ComponentCollection');
$Controller->expects($this->once())->method('beforeRedirect')
->will($this->returnValue(false));
$Controller->response->expects($this->never())->method('header');
$Controller->expects($this->never())->method('_stop');
$Controller->redirect('http://cakephp.org');
}
/**
* testMergeVars method
*

View file

@ -2309,9 +2309,11 @@ class RouterTest extends CakeTestCase {
'action' => 'view',
'pass' => array(1),
'named' => array(),
'url' => array('url' => 'eng/posts/view/1')
));
$request->query = array('url' => 'eng/posts/view/1', 'test' => 'value');
$result = Router::reverse($request);
$expected = '/eng/posts/view/1?test=value';
$this->assertEquals($expected, $result);
}
/**

View file

@ -50,6 +50,13 @@ class CakeTestFixture {
*
*/
public function __construct() {
if ($this->name === null) {
if (preg_match('/^(.*)Fixture$/', get_class($this), $matches)) {
$this->name = $matches[1];
} else {
$this->name = get_class($this);
}
}
App::import('Model', 'CakeSchema');
$this->Schema = new CakeSchema(array('name' => 'TestSuite', 'connection' => 'test'));
$this->init();

View file

@ -83,12 +83,13 @@ class CakeTestSuite extends PHPUnit_Framework_TestSuite {
if (!$this->_fixtureManager) {
return;
}
$classes = array();
foreach ($this->getIterator() as $test) {
if ($test instanceof CakeTestCase) {
$this->_fixtureManager->fixturize($test);
$test->fixtureManager = $this->_fixtureManager;
}
}
}
/**
* Method that is called after all the tests of this test suite are run.

View file

@ -32,7 +32,7 @@ $this->loadHelper('Html');
<body>
<div id="container">
<div id="header">
<h1><?php echo $this->Html->link(__('CakePHP: the rapid development php framework', true), 'http://cakephp.org');?></h1>
<h1><?php echo $this->Html->link(__('CakePHP: the rapid development php framework'), 'http://cakephp.org');?></h1>
</div>
<div id="content">
@ -41,7 +41,7 @@ $this->loadHelper('Html');
</div>
<div id="footer">
<?php echo $this->Html->link(
$this->Html->image('cake.power.gif', array('alt'=> __("CakePHP: the rapid development php framework", true), 'border'=>"0")),
$this->Html->image('cake.power.gif', array('alt'=> __("CakePHP: the rapid development php framework"), 'border'=>"0")),
'http://www.cakephp.org/',
array('target'=>'_blank'), null, false
);