diff --git a/tests/PHPUnit/Framework/Mock/FakeAccess.php b/tests/PHPUnit/Framework/Mock/FakeAccess.php index 1f3ff2c95da09f87ff8b9b730bc5a8dc443fd3fe..7e67f0114dab3c59b91accbb426461c1e36cb639 100644 --- a/tests/PHPUnit/Framework/Mock/FakeAccess.php +++ b/tests/PHPUnit/Framework/Mock/FakeAccess.php @@ -23,6 +23,14 @@ class FakeAccess public static $identity = 'superUserLogin'; public static $superUserLogin = 'superUserLogin'; + public static function clearAccess() + { + self::$superUser = false; + self::$idSitesAdmin = array(); + self::$idSitesView = array(); + self::$identity = 'superUserLogin'; + } + public function getTokenAuth() { return false; @@ -30,10 +38,7 @@ class FakeAccess public function __construct() { - self::$superUser = false; - self::$idSitesAdmin = array(); - self::$idSitesView = array(); - self::$identity = 'superUserLogin'; + self::clearAccess(); } public static function setIdSitesAdmin($ids) diff --git a/tests/PHPUnit/Integration/Plugin/SettingsTest.php b/tests/PHPUnit/Integration/Plugin/SettingsTest.php index f086b2b3845f9dcc1711e8cdacf74ed746708321..a7e76800914cf14ea2787a1f7e8234e8b206cffb 100644 --- a/tests/PHPUnit/Integration/Plugin/SettingsTest.php +++ b/tests/PHPUnit/Integration/Plugin/SettingsTest.php @@ -299,10 +299,12 @@ class SettingsTest extends IntegrationTestCase /** * @expectedException \Exception - * @expectedExceptionMessage General_ExceptionPrivilege + * @expectedExceptionMessage checkUserHasSuperUserAccess Fake exception */ public function test_removeAllPluginSettings_shouldThrowException_InCaseAnonymousUser() { + $this->setAnonymousUser(); + $this->settings->removeAllPluginSettings(); } diff --git a/tests/PHPUnit/Integration/Settings/IntegrationTestCase.php b/tests/PHPUnit/Integration/Settings/IntegrationTestCase.php index de16fc20f55c0f7aef8f46e49bbadbed7a722f5c..45470ee14c1841a642f4b283a8b87c46f4a81db4 100644 --- a/tests/PHPUnit/Integration/Settings/IntegrationTestCase.php +++ b/tests/PHPUnit/Integration/Settings/IntegrationTestCase.php @@ -93,6 +93,12 @@ class IntegrationTestCase extends \Piwik\Tests\Framework\TestCase\IntegrationTes Access::setSingletonInstance($pseudoMockAccess); } + protected function setAnonymousUser() + { + FakeAccess::clearAccess(); + Access::setSingletonInstance(new FakeAccess()); + } + protected function createSettingsInstance() { return new CorePluginTestSettings('ExampleSettingsPlugin'); diff --git a/tests/PHPUnit/Integration/Settings/SystemSettingTest.php b/tests/PHPUnit/Integration/Settings/SystemSettingTest.php index 79eaf084ab856597e0d58d5cd72762062aa69b8b..ecc694cc883c5deed4e569be145a7333271f514a 100644 --- a/tests/PHPUnit/Integration/Settings/SystemSettingTest.php +++ b/tests/PHPUnit/Integration/Settings/SystemSettingTest.php @@ -46,6 +46,7 @@ class SystemSettingTest extends IntegrationTestCase */ public function test_setSettingValue_shouldThrowException_IfAnonymousIsTryingToSetASettingWhichNeedsSuperUserPermission() { + $this->setAnonymousUser(); $setting = $this->addSystemSetting('mysystem', 'mytitle'); $setting->setValue(2); @@ -91,6 +92,7 @@ class SystemSettingTest extends IntegrationTestCase */ public function test_getSettingValue_shouldThrowException_IfAnonymousTriedToReadValue() { + $this->setAnonymousUser(); $setting = $this->addSystemSetting('myusersetting', 'mytitle'); $setting->getValue(); } @@ -128,6 +130,7 @@ class SystemSettingTest extends IntegrationTestCase */ public function test_removeSettingValue_shouldThrowException_IfAnonymousTriesToRemoveValue() { + $this->setAnonymousUser(); $setting = $this->addSystemSetting('mysystemsetting', 'mytitle'); $setting->removeValue(); } diff --git a/tests/PHPUnit/Integration/Settings/UserSettingTest.php b/tests/PHPUnit/Integration/Settings/UserSettingTest.php index 5d9c089dc249eaa0c516b799351297cc2017a780..fa49d96ab3ed610c84e367c634aba20af751db8b 100644 --- a/tests/PHPUnit/Integration/Settings/UserSettingTest.php +++ b/tests/PHPUnit/Integration/Settings/UserSettingTest.php @@ -64,6 +64,7 @@ class UserSettingTest extends IntegrationTestCase */ public function test_setSettingValue_shouldThrowException_IfAnonymousIsTryingToSetASettingWhichNeedsUserPermission() { + $this->setAnonymousUser(); $setting = $this->addUserSetting('mysystem', 'mytitle'); $setting->setValue(2); @@ -170,6 +171,7 @@ class UserSettingTest extends IntegrationTestCase */ public function test_getSettingValue_shouldThrowException_IfGivenSettingDoesNotExist() { + $this->setAnonymousUser(); $setting = $this->buildUserSetting('myusersetting', 'mytitle'); $setting->getValue(); } @@ -190,6 +192,7 @@ class UserSettingTest extends IntegrationTestCase */ public function test_removeSettingValue_shouldThrowException_IfUserHasNotEnoughUserPermissions() { + $this->setAnonymousUser(); $setting = $this->addUserSetting('myusersetting', 'mytitle'); $setting->removeValue(); }