diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-07-19 12:14:34 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-07-19 12:14:34 +0400 |
commit | 5d7c6f4a813c6193e0be20ccba99037926846b14 (patch) | |
tree | 029f2afb234e4e10978eae40b0d3e50a83ccf4c2 /plugins/UsersManager/tests | |
parent | 5b2c7914fae33cf46cbe96cedce32c3706468f7a (diff) |
refs #5817 added some tests for user preferences
Diffstat (limited to 'plugins/UsersManager/tests')
-rw-r--r-- | plugins/UsersManager/tests/UserPreferencesTest.php | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/plugins/UsersManager/tests/UserPreferencesTest.php b/plugins/UsersManager/tests/UserPreferencesTest.php new file mode 100644 index 0000000000..515df79dd8 --- /dev/null +++ b/plugins/UsersManager/tests/UserPreferencesTest.php @@ -0,0 +1,115 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Plugins\UsersManager\tests; +use Piwik\Piwik; +use Piwik\Plugins\UsersManager\UserPreferences; +use Piwik\Plugins\UsersManager\API as APIUsersManager; +use FakeAccess; +use Piwik\Access; +use Piwik\Tests\Fixture; + +/** + * @group UsersManager + * @group UserPreferencesTest + * @group Database + */ +class UserPreferencesTest extends \DatabaseTestCase +{ + /** + * @var UserPreferences + */ + private $userPreferences; + + public function setUp() + { + parent::setUp(); + + $this->userPreferences = new UserPreferences(); + + $this->setSuperUser(); + } + + public function test_getDefaultReport_ShouldReturnFalseByDefault() + { + $this->assertEquals(false, $this->userPreferences->getDefaultReport()); + } + + public function test_getDefaultReport_ShouldReturnTheRawValueIfNotNumeric() + { + $this->setDefaultReport('MultiSites'); + $this->assertEquals('MultiSites', $this->userPreferences->getDefaultReport()); + } + + public function test_getDefaultReport_ShouldNotReturnSiteIdIfNoPermissionForSite() + { + $this->createSite(); + $this->setDefaultReport(1); + $this->setAnonymous(); + $this->assertEquals(false, $this->userPreferences->getDefaultReport()); + } + + public function test_getDefaultReport_ShouldReturnSiteIdIfPermissionForSite() + { + $this->createSite(); + $this->setDefaultReport(1); + $this->assertEquals(1, $this->userPreferences->getDefaultReport()); + } + + public function test_getDefaultWebsiteId_ShouldReturnFalseByDefault() + { + $this->assertEquals(false, $this->userPreferences->getDefaultWebsiteId()); + } + + public function test_getDefaultWebsiteId_ShouldReturnASiteIfOneExistsAndHasAccess() + { + $this->createSite(); + $this->assertEquals(1, $this->userPreferences->getDefaultWebsiteId()); + } + + public function test_getDefaultWebsiteId_ShouldReturnFalseIfASiteExistsButHasNoAccess() + { + $this->createSite(); + $this->setAnonymous(); + $this->assertEquals(false, $this->userPreferences->getDefaultWebsiteId()); + } + + public function test_getDefaultWebsiteId_ShouldReturnASiteEvenIfMultiSitesIsDefaultReport() + { + $this->setDefaultReport('MultiSites'); + $this->createSite(); + $this->assertEquals(1, $this->userPreferences->getDefaultWebsiteId()); + } + + private function setSuperUser() + { + $pseudoMockAccess = new FakeAccess(); + FakeAccess::$superUser = true; + Access::setSingletonInstance($pseudoMockAccess); + } + + private function setAnonymous() + { + $pseudoMockAccess = new FakeAccess(); + FakeAccess::$superUser = false; + Access::setSingletonInstance($pseudoMockAccess); + } + + private function createSite() + { + Fixture::createWebsite('2013-01-23 01:23:45'); + } + + private function setDefaultReport($defaultReport) + { + APIUsersManager::getInstance()->setUserPreference(Piwik::getCurrentUserLogin(), + APIUsersManager::PREFERENCE_DEFAULT_REPORT, + $defaultReport); + } + +} |