Skip to content
Permalink
Browse files

fixes view vars being set

  • Loading branch information...
leighmackay committed Jul 10, 2015
1 parent bd66f5d commit 14da30b71c650187cd8c4583fdf3e7d7f485551b
Showing with 26 additions and 7 deletions.
  1. +3 −1 src/View/ViewVarsTrait.php
  2. +23 −6 tests/TestCase/View/ViewVarsTraitTest.php
@@ -42,6 +42,7 @@ trait ViewVarsTrait
public function getView($viewClass = null)
{
if ($viewClass === null && $this->View) {
$this->View->viewVars = $this->viewVars;
return $this->View;
}
@@ -65,6 +66,7 @@ public function getView($viewClass = null)
}
if ($this->View && $this->View instanceof $className) {
$this->View->viewVars = $this->viewVars;
return $this->View;
}
@@ -93,7 +95,7 @@ public function createView($viewClass = null)
}
$viewOptions = [];
foreach ($this->_validViewOptions as $option) {
foreach ($this->viewOptions() as $option) {
if (property_exists($this, $option)) {
$viewOptions[$option] = $this->{$option};
}
@@ -13,6 +13,7 @@
*/
namespace Cake\Test\TestCase\View;
use Cake\Controller\Controller;
use Cake\TestSuite\TestCase;
use Cake\View\ViewVarsTrait;
@@ -32,7 +33,7 @@ public function setUp()
{
parent::setUp();
$this->subject = $this->getObjectForTrait('Cake\View\ViewVarsTrait');
$this->subject = new Controller;
}
/**
@@ -100,7 +101,7 @@ public function testAddOneViewOption()
$option = 'newOption';
$this->subject->viewOptions($option);
$this->assertContains($option, $this->subject->_validViewOptions);
$this->assertContains($option, $this->subject->viewOptions());
}
/**
@@ -110,7 +111,7 @@ public function testAddOneViewOption()
*/
public function testAddTwoViewOption()
{
$this->subject->_validViewOptions = ['oldOption'];
$this->subject->viewOptions(['oldOption'], false);
$option = ['newOption', 'anotherOption'];
$result = $this->subject->viewOptions($option);
$expects = ['oldOption', 'newOption', 'anotherOption'];
@@ -126,7 +127,7 @@ public function testAddTwoViewOption()
*/
public function testReadingViewOptions()
{
$expected = $this->subject->_validViewOptions = ['one', 'two', 'three'];
$expected = $this->subject->viewOptions(['one', 'two', 'three'], false);
$result = $this->subject->viewOptions();
$this->assertEquals($expected, $result);
@@ -139,7 +140,7 @@ public function testReadingViewOptions()
*/
public function testMergeFalseViewOptions()
{
$this->subject->_validViewOptions = ['one', 'two', 'three'];
$this->subject->viewOptions(['one', 'two', 'three'], false);
$expected = ['four', 'five', 'six'];
$result = $this->subject->viewOptions($expected, false);
@@ -153,12 +154,28 @@ public function testMergeFalseViewOptions()
*/
public function testUndefinedValidViewOptions()
{
$result = $this->subject->viewOptions();
$result = $this->subject->viewOptions([], false);
$this->assertTrue(is_array($result));
$this->assertTrue(empty($result));
}
/**
* test that getView() updates viewVars of View instance on each call.
*
* @return void
*/
public function testUptoDateViewVars()
{
$expected = ['one' => 'one'];
$this->subject->set($expected);
$this->assertEquals($expected, $this->subject->getView()->viewVars);
$expected = ['one' => 'one', 'two' => 'two'];
$this->subject->set($expected);
$this->assertEquals($expected, $this->subject->getView()->viewVars);
}
/**
* test getView() throws exception if view class cannot be found
*

0 comments on commit 14da30b

Please sign in to comment.
You can’t perform that action at this time.