From cd80d501f9eb12d9aca3e65f742041b142ee659f Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Tue, 2 Aug 2016 18:07:31 +1200 Subject: [PATCH] BUG Fix unset config options returning isset() = true Fixes #4791 --- core/Config.php | 11 +++++++++++ tests/core/ConfigTest.php | 19 ++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/core/Config.php b/core/Config.php index 31662b645..a3198714d 100644 --- a/core/Config.php +++ b/core/Config.php @@ -881,6 +881,7 @@ class Config_ForClass { /** * @param string $name + * @return mixed */ public function __get($name) { return Config::inst()->get($this->class, $name); @@ -894,6 +895,16 @@ class Config_ForClass { return Config::inst()->update($this->class, $name, $val); } + /** + * @param string $name + * @return bool + */ + public function __isset($name) + { + $val = $this->__get($name); + return isset($val); + } + /** * @param string $name * @param int $sourceOptions diff --git a/tests/core/ConfigTest.php b/tests/core/ConfigTest.php index bbfe3b1a3..cd3ad70ff 100644 --- a/tests/core/ConfigTest.php +++ b/tests/core/ConfigTest.php @@ -82,15 +82,15 @@ class ConfigTest_TestNest extends Object implements TestOnly { } class ConfigTest extends SapphireTest { - + protected $depSettings = null; - + public function setUp() { parent::setUp(); $this->depSettings = Deprecation::dump_settings(); Deprecation::set_enabled(false); } - + public function tearDown() { Deprecation::restore_settings($this->depSettings); parent::tearDown(); @@ -262,6 +262,19 @@ class ConfigTest extends SapphireTest { $this->assertEquals(Object::static_lookup('ConfigTest_DefinesFooDoesntExtendObject', 'bar'), null); } + public function testForClass() { + $config = ConfigTest_DefinesFoo::config(); + // Set values + $this->assertTrue(isset($config->foo), 'foo is set'); + $this->assertFalse(empty($config->foo), 'foo is not empty'); + $this->assertEquals(1, $config->foo, 'foo is 1'); + + // Unset values + $this->assertFalse(isset($config->bar), 'bar is not set'); + $this->assertTrue(empty($config->bar), 'bar is empty'); + $this->assertEquals(null, $config->bar, 'bar is accessible but empty'); + } + public function testFragmentOrder() { $this->markTestIncomplete(); }