mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Making baked code throw 404 errors when you try to edit, delete, or view records that do not exist. Updated tests.
This commit is contained in:
parent
44c080d5ad
commit
daffe3adb2
2 changed files with 15 additions and 28 deletions
|
@ -25,13 +25,9 @@
|
|||
}
|
||||
|
||||
public function <?php echo $admin ?>view($id = null) {
|
||||
if (!$id) {
|
||||
<?php if ($wannaUseSession): ?>
|
||||
$this->Session->setFlash(__('Invalid <?php echo strtolower($singularHumanName) ?>'));
|
||||
$this->redirect(array('action' => 'index'));
|
||||
<?php else: ?>
|
||||
$this->flash(__('Invalid <?php echo strtolower($singularHumanName); ?>'), array('action' => 'index'));
|
||||
<?php endif; ?>
|
||||
$this-><?php echo $currentModelName; ?>->id = $id;
|
||||
if (!$this-><?php echo $currentModelName; ?>->exists()) {
|
||||
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
|
||||
}
|
||||
$this->set('<?php echo $singularName; ?>', $this-><?php echo $currentModelName; ?>->read(null, $id));
|
||||
}
|
||||
|
@ -72,13 +68,9 @@
|
|||
|
||||
<?php $compact = array(); ?>
|
||||
public function <?php echo $admin; ?>edit($id = null) {
|
||||
if (!$id && empty($this->request->data)) {
|
||||
<?php if ($wannaUseSession): ?>
|
||||
$this->Session->setFlash(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
|
||||
$this->redirect(array('action' => 'index'));
|
||||
<?php else: ?>
|
||||
$this->flash(__('Invalid <?php echo strtolower($singularHumanName); ?>'), array('action' => 'index'));
|
||||
<?php endif; ?>
|
||||
$this-><?php echo $currentModelName; ?>->id = $id;
|
||||
if (!$this-><?php echo $currentModelName; ?>->exists()) {
|
||||
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
|
||||
}
|
||||
if ($this->request->is('post')) {
|
||||
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
|
||||
|
@ -93,8 +85,7 @@
|
|||
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
|
||||
<?php endif; ?>
|
||||
}
|
||||
}
|
||||
if (!$this->request->is('post')) {
|
||||
} else {
|
||||
$this->data = $this-><?php echo $currentModelName; ?>->read(null, $id);
|
||||
}
|
||||
<?php
|
||||
|
@ -118,15 +109,11 @@
|
|||
if (!$this->request->is('post')) {
|
||||
throw new MethodNotAllowedException();
|
||||
}
|
||||
if (!$id) {
|
||||
<?php if ($wannaUseSession): ?>
|
||||
$this->Session->setFlash(__('Invalid id for <?php echo strtolower($singularHumanName); ?>'));
|
||||
$this->redirect(array('action'=>'index'));
|
||||
<?php else: ?>
|
||||
$this->flash(__('Invalid <?php echo strtolower($singularHumanName); ?>'), array('action' => 'index'));
|
||||
<?php endif; ?>
|
||||
$this-><?php echo $currentModelName; ?>->id = $id;
|
||||
if (!$this-><?php echo $currentModelName; ?>->exists()) {
|
||||
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
|
||||
}
|
||||
if ($this-><?php echo $currentModelName; ?>->delete($id)) {
|
||||
if ($this-><?php echo $currentModelName; ?>->delete()) {
|
||||
<?php if ($wannaUseSession): ?>
|
||||
$this->Session->setFlash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted'));
|
||||
$this->redirect(array('action'=>'index'));
|
||||
|
|
|
@ -340,7 +340,7 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
$this->assertContains("\$this->set('bakeArticles', \$this->paginate());", $result);
|
||||
|
||||
$this->assertContains('function view($id = null)', $result);
|
||||
$this->assertContains("\$this->Session->setFlash(__('Invalid bake article'));", $result);
|
||||
$this->assertContains("throw new NotFoundException(__('Invalid bake article'));", $result);
|
||||
$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result);
|
||||
|
||||
$this->assertContains('function add()', $result);
|
||||
|
@ -352,7 +352,7 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
$this->assertContains("\$this->Session->setFlash(__('The bake article could not be saved. Please, try again.'));", $result);
|
||||
|
||||
$this->assertContains('function delete($id = null)', $result);
|
||||
$this->assertContains('if ($this->BakeArticle->delete($id))', $result);
|
||||
$this->assertContains('if ($this->BakeArticle->delete())', $result);
|
||||
$this->assertContains("\$this->Session->setFlash(__('Bake article deleted'));", $result);
|
||||
|
||||
$result = $this->Task->bakeActions('BakeArticles', 'admin_', true);
|
||||
|
@ -382,7 +382,7 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
$this->assertContains("\$this->set('bakeArticles', \$this->paginate());", $result);
|
||||
|
||||
$this->assertContains('function view($id = null)', $result);
|
||||
$this->assertContains("\$this->flash(__('Invalid bake article'), array('action' => 'index'))", $result);
|
||||
$this->assertContains("throw new NotFoundException(__('Invalid bake article'));", $result);
|
||||
$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result);
|
||||
|
||||
$this->assertContains('function add()', $result);
|
||||
|
@ -396,7 +396,7 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
$this->assertContains("\$this->set(compact('bakeTags'))", $result);
|
||||
|
||||
$this->assertContains('function delete($id = null)', $result);
|
||||
$this->assertContains('if ($this->BakeArticle->delete($id))', $result);
|
||||
$this->assertContains('if ($this->BakeArticle->delete())', $result);
|
||||
$this->assertContains("\$this->flash(__('Bake article deleted'), array('action' => 'index'))", $result);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue