mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Merge branch '1.2' of dev@code.cakephp.org:cakephp into 1.2
This commit is contained in:
commit
86f2008d32
2 changed files with 55 additions and 8 deletions
|
@ -267,11 +267,12 @@ class Scaffold extends Object {
|
|||
}
|
||||
|
||||
if (!$this->ScaffoldModel->exists()) {
|
||||
$message = sprintf(__("Invalid id for %s::edit()", true), Inflector::humanize($this->modelKey));
|
||||
if (isset($this->controller->Session) && $this->controller->Session->valid() != false) {
|
||||
$this->controller->Session->setFlash(sprintf(__("Invalid id for %s::edit()", true), Inflector::humanize($this->modelKey)));
|
||||
$this->controller->Session->setFlash($message);
|
||||
$this->controller->redirect($this->redirect);
|
||||
} else {
|
||||
return $this->controller->flash(sprintf(__("Invalid id for %s::edit()", true), Inflector::humanize($this->modelKey)), $this->redirect);
|
||||
return $this->controller->flash($message, $this->redirect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -283,11 +284,16 @@ class Scaffold extends Object {
|
|||
|
||||
if ($this->ScaffoldModel->save($this->controller->data)) {
|
||||
if ($this->controller->_afterScaffoldSave($action)) {
|
||||
$message = sprintf(__('The %1$s has been %2$s', true),
|
||||
Inflector::humanize($this->modelKey),
|
||||
$success
|
||||
);
|
||||
if (isset($this->controller->Session) && $this->controller->Session->valid() != false) {
|
||||
$this->controller->Session->setFlash(sprintf(__('The %1$s has been %2$s', true), Inflector::humanize($this->modelClass), $success));
|
||||
$this->controller->Session->setFlash($message);
|
||||
$this->controller->redirect($this->redirect);
|
||||
} else {
|
||||
return $this->controller->flash(sprintf(__('The %1$s has been %2$s', true), Inflector::humanize($this->modelClass), $success), $this->redirect);
|
||||
$this->controller->flash($message, $this->redirect);
|
||||
return $this->_output();
|
||||
}
|
||||
} else {
|
||||
return $this->controller->_afterScaffoldSaveError($action);
|
||||
|
@ -336,8 +342,8 @@ class Scaffold extends Object {
|
|||
$this->controller->Session->setFlash(sprintf(__("No id set for %s::delete()", true), Inflector::humanize($this->modelKey)));
|
||||
$this->controller->redirect($this->redirect);
|
||||
} else {
|
||||
return $this->controller->flash(sprintf(__("No id set for %s::delete()", true), Inflector::humanize($this->modelKey)),
|
||||
'/' . Inflector::underscore($this->controller->viewPath));
|
||||
$this->controller->flash(sprintf(__("No id set for %s::delete()", true), Inflector::humanize($this->modelKey)), '/' . Inflector::underscore($this->controller->viewPath));
|
||||
return $this->_output();
|
||||
}
|
||||
|
||||
if ($this->ScaffoldModel->del($id)) {
|
||||
|
@ -345,14 +351,16 @@ class Scaffold extends Object {
|
|||
$this->controller->Session->setFlash(sprintf(__('The %1$s with id: %2$d has been deleted.', true), Inflector::humanize($this->modelClass), $id));
|
||||
$this->controller->redirect($this->redirect);
|
||||
} else {
|
||||
return $this->controller->flash(sprintf(__('The %1$s with id: %2$d has been deleted.', true), Inflector::humanize($this->modelClass), $id), '/' . $this->viewPath);
|
||||
$this->controller->flash(sprintf(__('The %1$s with id: %2$d has been deleted.', true), Inflector::humanize($this->modelClass), $id), '/' . $this->viewPath);
|
||||
return $this->_output();
|
||||
}
|
||||
} else {
|
||||
if (isset($this->controller->Session) && $this->controller->Session->valid() != false) {
|
||||
$this->controller->Session->setFlash(sprintf(__('There was an error deleting the %1$s with id: %2$d', true), Inflector::humanize($this->modelClass), $id));
|
||||
$this->controller->redirect($this->redirect);
|
||||
} else {
|
||||
return $this->controller->flash(sprintf(__('There was an error deleting the %1$s with id: %2$d', true), Inflector::humanize($this->modelClass), $id), '/' . $this->viewPath);
|
||||
$this->controller->flash(sprintf(__('There was an error deleting the %1$s with id: %2$d', true), Inflector::humanize($this->modelClass), $id), '/' . $this->viewPath);
|
||||
return $this->_output();
|
||||
}
|
||||
}
|
||||
} elseif ($this->controller->_scaffoldError('delete') === false) {
|
||||
|
|
|
@ -676,6 +676,45 @@ class ScaffoldTest extends CakeTestCase {
|
|||
$this->assertEqual($result['pluralVar'], 'scaffoldMock');
|
||||
$this->assertEqual($result['scaffoldFields'], array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated'));
|
||||
}
|
||||
/**
|
||||
* test that scaffold outputs flash messages when sessions are unset.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testScaffoldFlashMessages() {
|
||||
$this->Controller->action = 'edit';
|
||||
$this->Controller->here = '/scaffold_mock';
|
||||
$this->Controller->webroot = '/';
|
||||
$params = array(
|
||||
'plugin' => null,
|
||||
'pass' => array(1),
|
||||
'form' => array(),
|
||||
'named' => array(),
|
||||
'url' => array('url' =>'scaffold_mock'),
|
||||
'controller' => 'scaffold_mock',
|
||||
'action' => 'edit',
|
||||
);
|
||||
//set router.
|
||||
Router::reload();
|
||||
Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/scaffold_mock', 'webroot' => '/')));
|
||||
$this->Controller->params = $params;
|
||||
$this->Controller->controller = 'scaffold_mock';
|
||||
$this->Controller->base = '/';
|
||||
$this->Controller->data = array(
|
||||
'ScaffoldMock' => array(
|
||||
'id' => 1,
|
||||
'title' => 'New title',
|
||||
'body' => 'new body'
|
||||
)
|
||||
);
|
||||
$this->Controller->constructClasses();
|
||||
unset($this->Controller->Session);
|
||||
|
||||
ob_start();
|
||||
new Scaffold($this->Controller, $params);
|
||||
$result = ob_get_clean();
|
||||
$this->assertPattern('/Scaffold Mock has been updated/', $result);
|
||||
}
|
||||
/**
|
||||
* test that habtm relationship keys get added to scaffoldFields.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue