Skip to content

Commit

Permalink
Add integration test for an empty settings array
Browse files Browse the repository at this point in the history
  • Loading branch information
michalkleiner committed Dec 19, 2024
1 parent 38ba77f commit 3d7c0c6
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions plugins/CorePluginsAdmin/tests/Integration/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ class ApiTest extends IntegrationTestCase
],
];

private $testSystemSettingsEmptyValuePayload = [
'ExampleSettingsPlugin' => [
['name' => 'browsers', 'value' => '__empty__'],
],
];

protected static function beforeTableDataCached()
{
parent::beforeTableDataCached();
Expand Down Expand Up @@ -113,6 +119,26 @@ public function testGetSystemSettingsRedactsPasswordValues()
self::assertTrue(password_verify('newPassword', $pluginSettings->getSetting('password')->getValue()));
}

public function testSetSystemSettingsCorrectlySetsEmptyValue()
{
$pluginSettings = StaticContainer::get(\Piwik\Plugins\ExampleSettingsPlugin\SystemSettings::class);
$settings = $this->getPluginSettings('ExampleSettingsPlugin', 'browsers');
$defaultValue = ['firefox', 'chromium', 'safari'];

self::assertEquals('browsers', $settings['name']);
self::assertEquals($defaultValue, $settings['value']);
self::assertEquals($defaultValue, $pluginSettings->getSetting('browsers')->getValue());

$settingValues = $this->testSystemSettingsEmptyValuePayload;
\Piwik\Plugins\CorePluginsAdmin\API::getInstance()->setSystemSettings($settingValues, self::TEST_PASSWORD);

$newSettings = $this->getPluginSettings('ExampleSettingsPlugin', 'browsers');

self::assertEquals('browsers', $newSettings['name']);
self::assertEquals([], $newSettings['value']);
self::assertEquals([], $pluginSettings->getSetting('browsers')->getValue());
}

private function getPluginSettings(string $pluginName, string $settingName): array
{
$settings = \Piwik\Plugins\CorePluginsAdmin\API::getInstance()->getSystemSettings();
Expand Down

0 comments on commit 3d7c0c6

Please sign in to comment.