mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-18 23:49:55 +00:00
Simplifying message generation.
Fixing inflection of model names. Adding tests for flash page generation. Refs #64
This commit is contained in:
parent
0097e8c14b
commit
f6ce178d85
2 changed files with 49 additions and 13 deletions
|
@ -309,17 +309,13 @@ class Scaffold extends Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->ScaffoldModel->exists()) {
|
if (!$this->ScaffoldModel->exists()) {
|
||||||
|
$message = sprintf(__("Invalid id for %s::edit()", true), Inflector::humanize($this->modelKey));
|
||||||
if ($this->_validSession) {
|
if ($this->_validSession) {
|
||||||
$this->controller->Session->setFlash(sprintf(
|
$this->controller->Session->setFlash($message);
|
||||||
__("Invalid id for %s::edit()", true),
|
|
||||||
Inflector::humanize($this->modelKey)
|
|
||||||
));
|
|
||||||
$this->controller->redirect($this->redirect);
|
$this->controller->redirect($this->redirect);
|
||||||
} else {
|
} else {
|
||||||
return $this->controller->flash(sprintf(
|
$this->controller->flash($message, $this->redirect);
|
||||||
__("Invalid id for %s::edit()", true),
|
$this->_output();
|
||||||
Inflector::humanize($this->modelKey)
|
|
||||||
), $this->redirect);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,14 +327,15 @@ class Scaffold extends Object {
|
||||||
|
|
||||||
if ($this->ScaffoldModel->save($this->controller->data)) {
|
if ($this->ScaffoldModel->save($this->controller->data)) {
|
||||||
if ($this->controller->_afterScaffoldSave($action)) {
|
if ($this->controller->_afterScaffoldSave($action)) {
|
||||||
|
$message = sprintf(__('The %1$s has been %2$s', true),
|
||||||
|
Inflector::humanize($this->modelKey),
|
||||||
|
$success
|
||||||
|
);
|
||||||
if ($this->_validSession) {
|
if ($this->_validSession) {
|
||||||
$this->controller->Session->setFlash(sprintf(
|
$this->controller->Session->setFlash($message);
|
||||||
__('The %1$s has been %2$s', true),
|
|
||||||
Inflector::humanize($this->modelClass), $success
|
|
||||||
));
|
|
||||||
$this->controller->redirect($this->redirect);
|
$this->controller->redirect($this->redirect);
|
||||||
} else {
|
} else {
|
||||||
$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();
|
return $this->_output();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -713,6 +713,45 @@ class ScaffoldTest extends CakeTestCase {
|
||||||
$this->assertEqual($result['scaffoldFields'], array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated'));
|
$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.
|
* test that habtm relationship keys get added to scaffoldFields.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue