Fixed user settings across sessions
When getting settings from database, running across NULL loads default
setting for given option. Becuase entity unserializer always returned
NULLs instead of FALSEs due to bug in TextHelper, it ended up always
loading default settings (but only after reloading entity, setting it in
the settings page worked correctly until relog).
This fix is closely related to fde6fc2
.
This commit is contained in:
parent
361a221dc0
commit
72fef5686b
3 changed files with 43 additions and 0 deletions
|
@ -46,6 +46,15 @@ class TextHelper
|
|||
|
||||
public static function toBooleanOrNull($x)
|
||||
{
|
||||
if ($x === null)
|
||||
return null;
|
||||
|
||||
if ($x === true)
|
||||
return true;
|
||||
|
||||
if ($x === false)
|
||||
return false;
|
||||
|
||||
switch (strtolower($x))
|
||||
{
|
||||
case '1':
|
||||
|
@ -54,12 +63,14 @@ class TextHelper
|
|||
case 'yes':
|
||||
case 'y':
|
||||
return true;
|
||||
|
||||
case '0':
|
||||
case 'false':
|
||||
case 'off':
|
||||
case 'no':
|
||||
case 'n':
|
||||
return false;
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,27 @@ class EditUserSettingsJobTest extends AbstractTest
|
|||
$this->assert->isTrue($settings->get(UserSettings::SETTING_ENDLESS_SCROLLING));
|
||||
$this->assert->isTrue($settings->get(UserSettings::SETTING_POST_TAG_TITLES));
|
||||
$this->assert->isTrue($settings->get(UserSettings::SETTING_HIDE_DISLIKED_POSTS));
|
||||
|
||||
$user = $this->assert->doesNotThrow(function() use ($user, $expectedSafety)
|
||||
{
|
||||
return Api::run(
|
||||
new EditUserSettingsJob(),
|
||||
[
|
||||
JobArgs::ARG_USER_NAME => $user->getName(),
|
||||
JobArgs::ARG_NEW_SETTINGS =>
|
||||
[
|
||||
UserSettings::SETTING_ENDLESS_SCROLLING => false,
|
||||
UserSettings::SETTING_POST_TAG_TITLES => false,
|
||||
UserSettings::SETTING_HIDE_DISLIKED_POSTS => false,
|
||||
]
|
||||
]);
|
||||
});
|
||||
|
||||
$settings = $user->getSettings();
|
||||
|
||||
$this->assert->isFalse($settings->get(UserSettings::SETTING_ENDLESS_SCROLLING));
|
||||
$this->assert->isFalse($settings->get(UserSettings::SETTING_POST_TAG_TITLES));
|
||||
$this->assert->isFalse($settings->get(UserSettings::SETTING_HIDE_DISLIKED_POSTS));
|
||||
}
|
||||
|
||||
public function testSettingAdditional()
|
||||
|
|
|
@ -51,9 +51,20 @@ class TextHelperTest extends AbstractTest
|
|||
$this->assert->isFalse(TextHelper::toBooleanOrNull('FaLsE'));
|
||||
$this->assert->isFalse(TextHelper::toBooleanOrNull('false'));
|
||||
$this->assert->isFalse(TextHelper::toBooleanOrNull(false));
|
||||
$this->assert->isNotNull(TextHelper::toBooleanOrNull(false));
|
||||
$this->assert->isNull(TextHelper::toBooleanOrNull(2));
|
||||
$this->assert->isNull(TextHelper::toBooleanOrNull('2'));
|
||||
$this->assert->isNull(TextHelper::toBooleanOrNull('rubbish'));
|
||||
$this->assert->isNull(TextHelper::toBooleanOrNull(null));
|
||||
}
|
||||
|
||||
public function testAssert()
|
||||
{
|
||||
$this->assert->isNull(null);
|
||||
$this->assert->isNotNull(false);
|
||||
$this->assert->isFalse(false);
|
||||
$this->assert->areNotEqual(true, '1');
|
||||
$this->assert->isTrue(true);
|
||||
$this->assert->areNotEqual(false, null);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue