Skip to content

Commit

Permalink
Merge pull request #6264 from cakephp/master-deprecate-session-helper
Browse files Browse the repository at this point in the history
Deprecate Session helper.
  • Loading branch information
ADmad committed Apr 7, 2015
2 parents 9c4a4ad + 68ff132 commit c73495d
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 130 deletions.
2 changes: 1 addition & 1 deletion src/Controller/Controller.php
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Error/ExceptionRenderer.php
Expand Up @@ -325,7 +325,7 @@ protected function _outputMessageSafe($template)
$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'));
Expand Down
14 changes: 14 additions & 0 deletions src/View/Helper/SessionHelper.php
Expand Up @@ -16,13 +16,15 @@

use Cake\View\Helper;
use Cake\View\StringTemplateTrait;
use Cake\View\View;

/**
* Session Helper.
*
* 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
{
Expand All @@ -40,6 +42,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.
*
Expand Down
3 changes: 1 addition & 2 deletions tests/TestCase/Controller/ControllerTest.php
Expand Up @@ -70,7 +70,7 @@ class TestController extends ControllerTestAppController
*
* @var array
*/
public $helpers = ['Session'];
public $helpers = ['Html'];

/**
* components property
Expand Down Expand Up @@ -549,7 +549,6 @@ public function testMergeVars()

$expected = [
'Html' => null,
'Session' => null
];
$this->assertEquals($expected, $TestController->helpers);

Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Error/ExceptionRendererTest.php
Expand Up @@ -665,7 +665,7 @@ public function testMissingRenderSafe()
$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);
}

/**
Expand Down
117 changes: 0 additions & 117 deletions tests/TestCase/View/Helper/SessionHelperTest.php

This file was deleted.

10 changes: 4 additions & 6 deletions tests/TestCase/View/ViewTest.php
Expand Up @@ -1169,7 +1169,6 @@ public function testHelperCallbackTriggering()
public function testBeforeLayout()
{
$this->PostsController->helpers = [
'Session',
'TestBeforeAfter' => ['className' => __NAMESPACE__ . '\TestBeforeAfterHelper'],
'Html'
];
Expand All @@ -1186,7 +1185,6 @@ public function testBeforeLayout()
public function testAfterLayout()
{
$this->PostsController->helpers = [
'Session',
'TestBeforeAfter' => ['className' => __NAMESPACE__ . '\TestBeforeAfterHelper'],
'Html'
];
Expand All @@ -1207,15 +1205,15 @@ public function testAfterLayout()
*/
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);
$this->assertEquals('posts index', $result);

$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');
Expand Down Expand Up @@ -1249,7 +1247,7 @@ public function testRender()

$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);

Expand Down Expand Up @@ -1302,7 +1300,7 @@ public function testGetViewFileNameSubdirWithPluginAndViewPath()
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);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_app/TestApp/Controller/PagesController.php
Expand Up @@ -38,7 +38,7 @@ class PagesController extends AppController
*
* @var array
*/
public $helpers = ['Html', 'Session'];
public $helpers = ['Html'];

/**
* Displays a view
Expand Down
Expand Up @@ -8,7 +8,6 @@ class TestAppsErrorController extends ErrorController

public $helpers = [
'Html',
'Session',
'Form',
'Banana',
];
Expand Down

0 comments on commit c73495d

Please sign in to comment.