From 4c3c7a1fbfa11f56f1740d5234cebdd677160e3c Mon Sep 17 00:00:00 2001 From: Roger Campanera Date: Sat, 11 Mar 2017 01:04:09 +0000 Subject: [PATCH 1/2] Update deprecated SessionComponent::setFlash() to FlashComponent --- src/Controller/TagsController.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Controller/TagsController.php b/src/Controller/TagsController.php index d67b956..02b2854 100644 --- a/src/Controller/TagsController.php +++ b/src/Controller/TagsController.php @@ -35,7 +35,7 @@ class TagsController extends TagsAppController * @var array */ public $components = array( - 'Session', + 'Flash', 'Paginator' ); @@ -70,7 +70,7 @@ public function view($id = null) try { $this->set('tag', $this->{$this->modelClass}->view($id)); } catch (Exception $e) { - $this->Session->setFlash($e->getMessage()); + $this->Flash->warning($e->getMessage()); $this->redirect('/'); } } @@ -97,7 +97,7 @@ public function admin_view($id) try { $this->set('tag', $this->{$this->modelClass}->view($id)); } catch (Exception $e) { - $this->Session->setFlash($e->getMessage()); + $this->Flash->warning($e->getMessage()); $this->redirect('/'); } } @@ -111,7 +111,7 @@ public function admin_add() { if (!empty($this->request->data)) { if ($this->{$this->modelClass}->add($this->request->data)) { - $this->Session->setFlash(__d('tags', 'The Tags has been saved.')); + $this->Flash->success(__d('tags', 'The Tags has been saved.')); $this->redirect(array('action' => 'index')); } } @@ -128,13 +128,13 @@ public function admin_edit($id = null) try { $result = $this->{$this->modelClass}->edit($id, $this->request->data); if ($result === true) { - $this->Session->setFlash(__d('tags', 'Tag saved.')); + $this->Flash->success(__d('tags', 'Tag saved.')); $this->redirect(array('action' => 'index')); } else { $this->request->data = $result; } } catch (Exception $e) { - $this->Session->setFlash($e->getMessage()); + $this->Flash->warning($e->getMessage()); $this->redirect(array('action' => 'index')); } @@ -152,9 +152,9 @@ public function admin_edit($id = null) public function admin_delete($id = null) { if ($this->{$this->modelClass}->delete($id)) { - $this->Session->setFlash(__d('tags', 'Tag deleted.')); + $this->Flash->success(__d('tags', 'Tag deleted.')); } else { - $this->Session->setFlash(__d('tags', 'Invalid Tag.')); + $this->Flash->warning(__d('tags', 'Invalid Tag.')); } $this->redirect(array('action' => 'index')); } From f7d50bc2170888a10bab9e1f04fae67c3a62ef53 Mon Sep 17 00:00:00 2001 From: Roger Campanera Date: Sat, 11 Mar 2017 01:04:29 +0000 Subject: [PATCH 2/2] Update tests --- tests/TestCase/Controller/TagsControllerTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/TestCase/Controller/TagsControllerTest.php b/tests/TestCase/Controller/TagsControllerTest.php index 51246ac..95662d3 100644 --- a/tests/TestCase/Controller/TagsControllerTest.php +++ b/tests/TestCase/Controller/TagsControllerTest.php @@ -97,7 +97,7 @@ public function setUp() 'named' => array(), 'url' => array()); $this->Tags->constructClasses(); - $this->Tags->Session = $this->getMock('SessionComponent', array(), array(), '', false); + $this->Tags->Flash = $this->getMock('FlashComponent', array(), array(), '', false); } /** @@ -180,13 +180,13 @@ public function testAdminIndex() */ public function testAdminDelete() { - $this->Tags->Session->expects($this->at(0)) - ->method('setFlash') + $this->Tags->Flash->expects($this->at(0)) + ->method('warning') ->with($this->equalTo(__d('tags', 'Invalid Tag.'))) ->will($this->returnValue(true)); - $this->Tags->Session->expects($this->at(1)) - ->method('setFlash') + $this->Tags->Flash->expects($this->at(1)) + ->method('success') ->with($this->equalTo(__d('tags', 'Tag deleted.'))) ->will($this->returnValue(true));