Skip to content

Commit

Permalink
fix magic __isset()
Browse files Browse the repository at this point in the history
  • Loading branch information
ceeram authored and markstory committed Jan 14, 2012
1 parent b14072a commit 7badb1d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
16 changes: 15 additions & 1 deletion lib/Cake/Test/Case/View/ViewTest.php
Expand Up @@ -677,7 +677,7 @@ public function testHelperCallbackTriggering() {
$this->attributeEqualTo('_subject', $View)
)
);

$View->Helpers->expects($this->at(4))->method('trigger')
->with(
$this->logicalAnd(
Expand Down Expand Up @@ -1246,6 +1246,20 @@ public function testPropertySetting() {
$this->assertFalse(isset($this->View->pageTitle));
$this->View->pageTitle = 'test';
$this->assertTrue(isset($this->View->pageTitle));
$this->assertTrue(!empty($this->View->pageTitle));
$this->assertEquals('test', $this->View->pageTitle);
}

/**
* Test that setting arbitrary properties still works.
*
* @return void
*/
public function testPropertySettingMagicGet() {
$this->assertFalse(isset($this->View->action));
$this->View->request->params['action'] = 'login';
$this->assertEquals('login', $this->View->action);
$this->assertTrue(isset($this->View->action));
$this->assertTrue(!empty($this->View->action));
}
}
11 changes: 9 additions & 2 deletions lib/Cake/View/View.php
Expand Up @@ -762,7 +762,7 @@ public function __get($name) {
case 'data':
return $this->request->{$name};
case 'action':
return isset($this->request->params['action']) ? $this->request->params['action'] : '';
return $this->request->params['action'];
case 'params':
return $this->request;
case 'output':
Expand Down Expand Up @@ -796,7 +796,14 @@ public function __set($name, $value) {
* @return boolean
*/
public function __isset($name) {
return isset($this->{$name});
if (isset($this->{$name})) {
return true;
}
$magicGet = array('base', 'here', 'webroot', 'data', 'action', 'params', 'output');
if (in_array($name, $magicGet)) {
return $this->__get($name) !== null;
}
return false;
}

/**
Expand Down

0 comments on commit 7badb1d

Please sign in to comment.