function testCreateRealItem() { $numeric = new configItem('aReal', REAL); $r = $numeric->setDefaultValue(0); $this->assertFalse(isError($r), 'Unexpected error'); $this->assertEquals(0, $numeric->getCurrentValue(), 'Default value fails.'); $r = $numeric->setValue(1); $this->assertFalse(isError($r), 'Unexpected error'); $this->assertEquals(1, $numeric->getCurrentValue(), 'Wrong value'); $this->assertEquals(1, $numeric->getInitialValue(), 'Wrong initial value'); $r = $numeric->setValue(3.141592); $this->assertFalse(isError($r), 'Unexpected error'); $this->assertEquals(3.141592, $numeric->getCurrentValue(), 'Wrong value 2'); $this->assertEquals(1, $numeric->getInitialValue(), 'Wrong initial value 2'); $r = $numeric->setValue('string'); $this->assertTrue(isError($r), 'Unexpected un-error 1'); $r = $numeric->setValue(false); $this->assertTrue(isError($r), 'Unexpected un-error 2'); $r = $numeric->setValue(1200.0); $this->assertFalse(isError($r), 'Unexpected error 2'); $this->assertEquals(1200.0, $numeric->getCurrentValue()); $r = $numeric->setValue(0.0031); $this->assertFalse(isError($r), 'Unexpected error 3'); $this->assertEquals(0.0031, $numeric->getCurrentValue()); }
/** * Adds a user setting to the configmanager. * A user setting is defined a setting that can be changed * from GET, COOKIE or a default value * * * @public * @return (string) The initial value * @since 0.3 */ function addUserSetting($name, $type, $defaultValue = null) { $fullname = '/user/' . $name; if ($this->existsItem($fullname)) { return new Error('CONFIGURATOR_OPTION_EXISTS', $name); } $setting = new configItem($fullname, $type); $setting->setDefaultValue($defaultValue); if (array_key_exists($name, $_GET)) { $setting->setValue($_GET[$name]); setcookie($name, $_GET[$name]); } elseif (array_key_exists($name, $_COOKIE)) { $setting->setValue($_COOKIE[$name]); } $this->allUserItems['/' . $type . $fullname] = $setting; return $setting->getCurrentValue(); }