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]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
if ($this->loaded) {
|
||||
return;
|
||||
|
@@ -120,6 +120,13 @@ class SettingsControllerTest extends \MailPoetTest {
|
||||
$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) {
|
||||
$tableName = $this->entityManager->getClassMetadata(SettingEntity::class)->getTableName();
|
||||
$this->connection->executeStatement("
|
||||
|
Reference in New Issue
Block a user