Browse Source

Merge pull request #6264 from cakephp/master-deprecate-session-helper

Deprecate Session helper.
ADmad 11 years ago
parent
commit
c73495dce3

+ 1 - 1
src/Controller/Controller.php

@@ -165,7 +165,7 @@ class Controller implements EventListenerInterface
      * Array containing the names of components this controller uses. Component names
      * should not contain the "Component" portion of the class name.
      *
-     * Example: `public $components = ['Session', 'RequestHandler', 'Acl'];`
+     * Example: `public $components = ['RequestHandler', 'Acl'];`
      *
      * @var array
      * @link http://book.cakephp.org/3.0/en/controllers/components.html

+ 1 - 1
src/Error/ExceptionRenderer.php

@@ -325,7 +325,7 @@ class ExceptionRenderer
         $this->controller->subDir = null;
         $this->controller->viewPath = 'Error';
         $this->controller->layout = 'error';
-        $this->controller->helpers = ['Form', 'Html', 'Session'];
+        $this->controller->helpers = ['Form', 'Html'];
 
         $view = $this->controller->createView();
         $this->controller->response->body($view->render($template, 'error'));

+ 14 - 0
src/View/Helper/SessionHelper.php

@@ -16,6 +16,7 @@ namespace Cake\View\Helper;
 
 use Cake\View\Helper;
 use Cake\View\StringTemplateTrait;
+use Cake\View\View;
 
 /**
  * Session Helper.
@@ -23,6 +24,7 @@ use Cake\View\StringTemplateTrait;
  * Session reading from the view.
  *
  * @link http://book.cakephp.org/3.0/en/views/helpers/session.html
+ * @deprecated 3.1.0 Use request->session() instead.
  */
 class SessionHelper extends Helper
 {
@@ -41,6 +43,18 @@ class SessionHelper extends Helper
     ];
 
     /**
+     *  Constructor
+     *
+     * @param \Cake\View\View $View The View this helper is being attached to.
+     * @param array $config Configuration settings for the helper.
+     */
+    public function __construct(View $View, array $config = [])
+    {
+        trigger_error('SessionHelper has been deprecated. Use request->session() instead.', E_USER_DEPRECATED);
+        parent::__construct($View, $config);
+    }
+
+    /**
      * Reads a session value for a key or returns values for all keys.
      *
      * In your view: `$this->Session->read('Controller.sessKey');`

+ 1 - 2
tests/TestCase/Controller/ControllerTest.php

@@ -70,7 +70,7 @@ class TestController extends ControllerTestAppController
      *
      * @var array
      */
-    public $helpers = ['Session'];
+    public $helpers = ['Html'];
 
     /**
      * components property
@@ -549,7 +549,6 @@ class ControllerTest extends TestCase
 
         $expected = [
             'Html' => null,
-            'Session' => null
         ];
         $this->assertEquals($expected, $TestController->helpers);
 

+ 1 - 1
tests/TestCase/Error/ExceptionRendererTest.php

@@ -665,7 +665,7 @@ class ExceptionRendererTest extends TestCase
         $ExceptionRenderer->controller->response = $response;
         $ExceptionRenderer->render();
         sort($ExceptionRenderer->controller->helpers);
-        $this->assertEquals(['Form', 'Html', 'Session'], $ExceptionRenderer->controller->helpers);
+        $this->assertEquals(['Form', 'Html'], $ExceptionRenderer->controller->helpers);
     }
 
     /**

+ 0 - 117
tests/TestCase/View/Helper/SessionHelperTest.php

@@ -1,117 +0,0 @@
-<?php
-/**
- * SessionHelperTest file
- *
- * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
- * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- *
- * Licensed under The MIT License
- * For full copyright and license information, please see the LICENSE.txt
- * Redistributions of files must retain the above copyright notice
- *
- * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
- * @since         1.2.0
- * @license       http://www.opensource.org/licenses/mit-license.php MIT License
- */
-namespace Cake\Test\TestCase\View\Helper;
-
-use Cake\Controller\Controller;
-use Cake\Core\App;
-use Cake\Core\Plugin;
-use Cake\Network\Request;
-use Cake\Network\Session;
-use Cake\TestSuite\TestCase;
-use Cake\View\Helper\SessionHelper;
-use Cake\View\View;
-
-/**
- * SessionHelperTest class
- *
- */
-class SessionHelperTest extends TestCase
-{
-
-    /**
-     * setUp method
-     *
-     * @return void
-     */
-    public function setUp()
-    {
-        parent::setUp();
-        $this->View = new View();
-        $session = new Session();
-        $this->View->request = new Request(['session' => $session]);
-        $this->Session = new SessionHelper($this->View);
-
-        $session->write([
-            'test' => 'info',
-            'Flash' => [
-                'flash' => [
-                    'type' => 'info',
-                    'params' => [],
-                    'message' => 'This is a calling'
-                ],
-                'notification' => [
-                    'type' => 'info',
-                    'params' => [
-                        'title' => 'Notice!',
-                        'name' => 'Alert!',
-                        'element' => 'session_helper'
-                    ],
-                    'message' => 'This is a test of the emergency broadcasting system',
-                ],
-                'classy' => [
-                    'type' => 'success',
-                    'params' => ['class' => 'positive'],
-                    'message' => 'Recorded'
-                ],
-                'incomplete' => [
-                    'message' => 'A thing happened',
-                ]
-            ],
-            'Deeply' => ['nested' => ['key' => 'value']],
-        ]);
-    }
-
-    /**
-     * tearDown method
-     *
-     * @return void
-     */
-    public function tearDown()
-    {
-        $_SESSION = [];
-        unset($this->View, $this->Session);
-        Plugin::unload();
-        parent::tearDown();
-    }
-
-    /**
-     * testRead method
-     *
-     * @return void
-     */
-    public function testRead()
-    {
-        $result = $this->Session->read('Deeply.nested.key');
-        $this->assertEquals('value', $result);
-
-        $result = $this->Session->read('test');
-        $this->assertEquals('info', $result);
-    }
-
-    /**
-     * testCheck method
-     *
-     * @return void
-     */
-    public function testCheck()
-    {
-        $this->assertTrue($this->Session->check('test'));
-        $this->assertTrue($this->Session->check('Flash.flash'));
-        $this->assertFalse($this->Session->check('Does.not.exist'));
-        $this->assertFalse($this->Session->check('Nope'));
-    }
-}

+ 4 - 6
tests/TestCase/View/ViewTest.php

@@ -1169,7 +1169,6 @@ class ViewTest extends TestCase
     public function testBeforeLayout()
     {
         $this->PostsController->helpers = [
-            'Session',
             'TestBeforeAfter' => ['className' => __NAMESPACE__ . '\TestBeforeAfterHelper'],
             'Html'
         ];
@@ -1186,7 +1185,6 @@ class ViewTest extends TestCase
     public function testAfterLayout()
     {
         $this->PostsController->helpers = [
-            'Session',
             'TestBeforeAfter' => ['className' => __NAMESPACE__ . '\TestBeforeAfterHelper'],
             'Html'
         ];
@@ -1207,7 +1205,7 @@ class ViewTest extends TestCase
      */
     public function testRenderLoadHelper()
     {
-        $this->PostsController->helpers = ['Session', 'Form', 'Number'];
+        $this->PostsController->helpers = ['Form', 'Number'];
         $View = $this->PostsController->createView('Cake\Test\TestCase\View\TestView');
 
         $result = $View->render('index', false);
@@ -1215,7 +1213,7 @@ class ViewTest extends TestCase
 
         $attached = $View->helpers()->loaded();
         // HtmlHelper is loaded in TestView::initialize()
-        $this->assertEquals(['Html', 'Session', 'Form', 'Number'], $attached);
+        $this->assertEquals(['Html', 'Form', 'Number'], $attached);
 
         $this->PostsController->helpers = ['Html', 'Form', 'Number', 'TestPlugin.PluggedHelper'];
         $View = $this->PostsController->createView('Cake\Test\TestCase\View\TestView');
@@ -1249,7 +1247,7 @@ class ViewTest extends TestCase
 
         $this->assertNull($View->render(false, 'ajax2'));
 
-        $this->PostsController->helpers = ['Session', 'Html'];
+        $this->PostsController->helpers = ['Html'];
         $this->PostsController->request->params['action'] = 'index';
         Configure::write('Cache.check', true);
 
@@ -1302,7 +1300,7 @@ class ViewTest extends TestCase
     public function testViewVarOverwritingLocalHelperVar()
     {
         $Controller = new ViewPostsController();
-        $Controller->helpers = ['Session', 'Html'];
+        $Controller->helpers = ['Html'];
         $Controller->set('html', 'I am some test html');
         $View = $Controller->createView();
         $result = $View->render('helper_overwrite', false);

+ 1 - 1
tests/test_app/TestApp/Controller/PagesController.php

@@ -38,7 +38,7 @@ class PagesController extends AppController
      *
      * @var array
      */
-    public $helpers = ['Html', 'Session'];
+    public $helpers = ['Html'];
 
     /**
      * Displays a view

+ 0 - 1
tests/test_app/TestApp/Controller/TestAppsErrorController.php

@@ -8,7 +8,6 @@ class TestAppsErrorController extends ErrorController
 
     public $helpers = [
         'Html',
-        'Session',
         'Form',
         'Banana',
     ];