Add helper to check if settings exists in DB
MAILPOET-5549
This commit is contained in:
committed by
Aschepikov
parent
d81f303d45
commit
281c75c67c
@@ -124,6 +124,17 @@ class SettingsController {
|
|||||||
unset($this->settings[$key]);
|
unset($this->settings[$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if a value is stored in the database for the given key
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function hasSavedValue(string $key): bool {
|
||||||
|
return $this->get($key, 'unset') !== 'unset';
|
||||||
|
}
|
||||||
|
|
||||||
private function ensureLoaded() {
|
private function ensureLoaded() {
|
||||||
if ($this->loaded) {
|
if ($this->loaded) {
|
||||||
return;
|
return;
|
||||||
|
@@ -120,6 +120,13 @@ class SettingsControllerTest extends \MailPoetTest {
|
|||||||
$this->assertEquals(true, true);
|
$this->assertEquals(true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItCanCheckIfSavedValueExists(): void {
|
||||||
|
$this->assertFalse($this->controller->hasSavedValue('test_key'));
|
||||||
|
$this->createOrUpdateSetting('test_key', 'some value');
|
||||||
|
$this->controller->resetCache(); // force reload from database
|
||||||
|
$this->assertTrue($this->controller->hasSavedValue('test_key'));
|
||||||
|
}
|
||||||
|
|
||||||
private function createOrUpdateSetting($name, $value) {
|
private function createOrUpdateSetting($name, $value) {
|
||||||
$tableName = $this->entityManager->getClassMetadata(SettingEntity::class)->getTableName();
|
$tableName = $this->entityManager->getClassMetadata(SettingEntity::class)->getTableName();
|
||||||
$this->connection->executeStatement("
|
$this->connection->executeStatement("
|
||||||
|
Reference in New Issue
Block a user