Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <tsteur@users.noreply.github.com>2016-12-12 03:53:28 +0300
committerGitHub <noreply@github.com>2016-12-12 03:53:28 +0300
commitdb01cbefb5f4dd1092396ee5e3549160149dfc77 (patch)
tree5d52b05d14ee985f4a4bf7344d7b77eaea4c18be
parent9227a3a695aa8db3291e3fd994c9a7733ee643bf (diff)
expose some more settings methods (#10993)
-rw-r--r--core/Settings/Settings.php4
-rw-r--r--core/Settings/Storage/Factory.php8
-rw-r--r--tests/PHPUnit/Framework/Mock/Settings/FakeMeasurableSettings.php4
-rw-r--r--tests/PHPUnit/Framework/Mock/Settings/FakeSystemSettings.php4
-rw-r--r--tests/PHPUnit/Framework/Mock/Settings/FakeUserSettings.php4
-rw-r--r--tests/PHPUnit/Integration/Settings/BaseSettingsTestCase.php38
-rw-r--r--tests/PHPUnit/Integration/Settings/Measurable/MeasurableSettingsTest.php2
-rw-r--r--tests/PHPUnit/Integration/Settings/Storage/FactoryTest.php10
8 files changed, 57 insertions, 17 deletions
diff --git a/core/Settings/Settings.php b/core/Settings/Settings.php
index 8181502c7b..2ceffb7948 100644
--- a/core/Settings/Settings.php
+++ b/core/Settings/Settings.php
@@ -93,13 +93,13 @@ abstract class Settings
}
/**
- * Makes a new plugin setting available.
+ * Adds a new setting to the settings container.
*
* @param Setting $setting
* @throws \Exception If there is a setting with the same name that already exists.
* If the name contains non-alphanumeric characters.
*/
- protected function addSetting(Setting $setting)
+ public function addSetting(Setting $setting)
{
$name = $setting->getName();
diff --git a/core/Settings/Storage/Factory.php b/core/Settings/Storage/Factory.php
index 2ca3deb17c..8336c58f3e 100644
--- a/core/Settings/Storage/Factory.php
+++ b/core/Settings/Storage/Factory.php
@@ -125,7 +125,13 @@ class Factory
return new Storage(new Backend\NullBackend($key));
}
- private function makeStorage(BackendInterface $backend)
+ /**
+ * Makes a new storage object based on a custom backend interface.
+ *
+ * @param BackendInterface $backend
+ * @return Storage
+ */
+ public function makeStorage(BackendInterface $backend)
{
if (SettingsServer::isTrackerApiRequest()) {
$backend = new Backend\Cache($backend);
diff --git a/tests/PHPUnit/Framework/Mock/Settings/FakeMeasurableSettings.php b/tests/PHPUnit/Framework/Mock/Settings/FakeMeasurableSettings.php
index 4fb569b9d8..c11f4e3476 100644
--- a/tests/PHPUnit/Framework/Mock/Settings/FakeMeasurableSettings.php
+++ b/tests/PHPUnit/Framework/Mock/Settings/FakeMeasurableSettings.php
@@ -28,9 +28,5 @@ class FakeMeasurableSettings extends \Piwik\Plugins\ExampleSettingsPlugin\Measur
return parent::makeProperty($name, $defaultValue, $type, $configureCallback);
}
- public function addSetting(Setting $setting)
- {
- parent::addSetting($setting);
- }
}
diff --git a/tests/PHPUnit/Framework/Mock/Settings/FakeSystemSettings.php b/tests/PHPUnit/Framework/Mock/Settings/FakeSystemSettings.php
index 00b9554196..735b3f9dc2 100644
--- a/tests/PHPUnit/Framework/Mock/Settings/FakeSystemSettings.php
+++ b/tests/PHPUnit/Framework/Mock/Settings/FakeSystemSettings.php
@@ -28,9 +28,5 @@ class FakeSystemSettings extends \Piwik\Plugins\ExampleSettingsPlugin\SystemSett
return parent::makeSetting($name, $defaultValue, $type, $configureCallback);
}
- public function addSetting(Setting $setting)
- {
- parent::addSetting($setting);
- }
}
diff --git a/tests/PHPUnit/Framework/Mock/Settings/FakeUserSettings.php b/tests/PHPUnit/Framework/Mock/Settings/FakeUserSettings.php
index 9d4bb5fdb1..fc77c85346 100644
--- a/tests/PHPUnit/Framework/Mock/Settings/FakeUserSettings.php
+++ b/tests/PHPUnit/Framework/Mock/Settings/FakeUserSettings.php
@@ -23,9 +23,5 @@ class FakeUserSettings extends \Piwik\Plugins\ExampleSettingsPlugin\UserSettings
return parent::makeSetting($name, $defaultValue, $type, $configureCallback);
}
- public function addSetting(Setting $setting)
- {
- parent::addSetting($setting);
- }
}
diff --git a/tests/PHPUnit/Integration/Settings/BaseSettingsTestCase.php b/tests/PHPUnit/Integration/Settings/BaseSettingsTestCase.php
index 4a91af3a1c..2d56a0dce7 100644
--- a/tests/PHPUnit/Integration/Settings/BaseSettingsTestCase.php
+++ b/tests/PHPUnit/Integration/Settings/BaseSettingsTestCase.php
@@ -11,6 +11,7 @@ namespace Piwik\Tests\Integration\Settings;
use Piwik\Db;
use Piwik\Piwik;
use Piwik\Settings\FieldConfig;
+use Piwik\Settings\Setting;
/**
* @group PluginSettings
@@ -122,4 +123,41 @@ class BaseSettingsTestCase extends IntegrationTestCase
return $this->settings->makeSetting($name, $default = '', $type, function () {});
}
+ public function test_addSetting_shouldAddNewSetting()
+ {
+ $settingName = 'testSetting';
+ $setting = $this->buildSetting($settingName);
+ $settings = $this->createSettingsInstance();
+
+ $this->assertEmpty($settings->getSetting($settingName));
+
+ $settings->addSetting($setting);
+
+ $this->assertSame($setting, $settings->getSetting($settingName));
+ }
+
+ /**
+ * @expectedException \Exception
+ * @expectedExceptionMessage "testSetting" does already exist
+ */
+ public function test_addSetting_throwsException_IfSameSettingAddedTwice()
+ {
+ $settingName = 'testSetting';
+ $setting = $this->buildSetting($settingName);
+ $settings = $this->createSettingsInstance();
+
+ $settings->addSetting($setting);
+ $settings->addSetting($setting);
+ }
+
+ private function buildSetting($name, $type = null, $default = '')
+ {
+ if (!isset($type)) {
+ $type = FieldConfig::TYPE_STRING;
+ }
+
+ $userSetting = new Setting($name, $default, $type, 'MyPluginName');
+
+ return $userSetting;
+ }
}
diff --git a/tests/PHPUnit/Integration/Settings/Measurable/MeasurableSettingsTest.php b/tests/PHPUnit/Integration/Settings/Measurable/MeasurableSettingsTest.php
index 689bab5d92..026aec7925 100644
--- a/tests/PHPUnit/Integration/Settings/Measurable/MeasurableSettingsTest.php
+++ b/tests/PHPUnit/Integration/Settings/Measurable/MeasurableSettingsTest.php
@@ -12,8 +12,6 @@ use Piwik\Db;
use Piwik\Plugins\WebsiteMeasurable\Type;
use Piwik\Settings\Measurable\MeasurableSetting;
use Piwik\Settings\Measurable\MeasurableSettings;
-use Piwik\Settings\Plugin\UserSetting;
-use Piwik\Settings\Plugin\UserSettings;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\Mock\Settings\FakeMeasurableSettings;
use Piwik\Tests\Integration\Settings\BaseSettingsTestCase;
diff --git a/tests/PHPUnit/Integration/Settings/Storage/FactoryTest.php b/tests/PHPUnit/Integration/Settings/Storage/FactoryTest.php
index fb25bbf13b..82acc03ec3 100644
--- a/tests/PHPUnit/Integration/Settings/Storage/FactoryTest.php
+++ b/tests/PHPUnit/Integration/Settings/Storage/FactoryTest.php
@@ -144,4 +144,14 @@ class FactoryTest extends IntegrationTestCase
$this->assertSame('', $storage->getValue('mytest', $default = '', FieldConfig::TYPE_STRING));
}
+ public function test_makeStorage_returnsStorageWithGivenBackend()
+ {
+ $backend = new NullBackend('test');
+ $storage = $this->factory->makeStorage($backend);
+
+ $this->assertTrue($storage instanceof Storage);
+
+ $this->assertSame($backend, $storage->getBackend());
+ }
+
}