Skip to content

Commit

Permalink
Merge pull request #215 from cewi/cake3.6
Browse files Browse the repository at this point in the history
change deprecated methods
  • Loading branch information
ADmad authored Apr 24, 2018
2 parents ca974c5 + fde5ecd commit d9f3692
Show file tree
Hide file tree
Showing 7 changed files with 319 additions and 143 deletions.
6 changes: 3 additions & 3 deletions src/View/Helper/FlashHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ class FlashHelper extends Helper
*/
public function render($key = 'flash', array $options = [])
{
if (!$this->request->session()->check("Flash.$key")) {
if (!$this->request->getSession()->check("Flash.$key")) {
return null;
}

$stack = $this->request->session()->read("Flash.$key");
$stack = $this->request->getSession()->read("Flash.$key");
if (!is_array($stack)) {
throw new \UnexpectedValueException(sprintf(
'Value for flash setting key "%s" must be an array.',
Expand All @@ -60,7 +60,7 @@ public function render($key = 'flash', array $options = [])
foreach ($stack as $message) {
$message = $options + $message;
$message['params'] += $this->_config;
$this->request->session()->delete("Flash.$key");
$this->request->getSession()->delete("Flash.$key");

$element = $message['element'];
if (strpos($element, '.') === false &&
Expand Down
8 changes: 4 additions & 4 deletions src/View/Helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public function control($fieldName, array $options = [])
if (isset($options['multiple']) && $options['multiple'] === 'checkbox') {
$options['type'] = 'multicheckbox';
} else {
if ($options['label'] !== false && strpos($this->templates('label'), 'class=') === false) {
if ($options['label'] !== false && strpos($this->getTemplates('label'), 'class=') === false) {
$options['label'] = $this->injectClasses('col-form-label', (array)$options['label']);
}
}
Expand All @@ -280,7 +280,7 @@ public function control($fieldName, array $options = [])

case 'textarea':
default:
if ($options['label'] !== false && strpos($this->templates('label'), 'class=') === false) {
if ($options['label'] !== false && strpos($this->getTemplates('label'), 'class=') === false) {
$options['label'] = $this->injectClasses('col-form-label', (array)$options['label']);
}
}
Expand Down Expand Up @@ -481,7 +481,7 @@ protected function _formAlignment($options)
$this->_grid = $options['align'];
$options['align'] = 'horizontal';
} elseif ($options['align'] === 'horizontal') {
$this->_grid = $this->config('grid');
$this->_grid = $this->getConfig('grid');
}

if (!in_array($options['align'], ['default', 'horizontal', 'inline'])) {
Expand Down Expand Up @@ -566,6 +566,6 @@ protected function _detectFormAlignment($options)
}
}

return $this->config('align');
return $this->getConfig('align');
}
}
20 changes: 14 additions & 6 deletions tests/TestCase/View/Helper/FlashHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

use BootstrapUI\View\Helper\FlashHelper;
use Cake\Core\Exception\Exception;
use Cake\Network\Request;
use Cake\Network\Session;
use Cake\Http\ServerRequest;
use Cake\TestSuite\TestCase;
use Cake\View\View;

Expand Down Expand Up @@ -34,8 +33,17 @@ public function setUp()
{
parent::setUp();
$this->View = new View();
$session = new Session();
$this->View->request = new Request(['session' => $session]);

// load appropriate session class according to Cake version
if (class_exists('\Cake\Http\Session')) {
// 3.6 and later
$session = new \Cake\Http\Session();
} else {
// before 3.6
$session = new \Cake\Network\Session();
}

$this->View->request = new ServerRequest(['session' => $session]);
$this->Flash = new FlashHelper($this->View);

$session->write([
Expand Down Expand Up @@ -134,13 +142,13 @@ public function testRender()
}

/**
* In CakePHP 3.1 you multple message per key
* In CakePHP 3.1 you multiple message per key
*
* @return void
*/
public function testRenderForMultipleMessages()
{
$this->View->request->session()->write([
$this->View->request->getSession()->write([
'Flash' => [
'flash' => [
[
Expand Down
Loading

0 comments on commit d9f3692

Please sign in to comment.