blob: 34a8aeabbcd6563ef9339c80089d5d5b43e38e77 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
<?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 Piwik\Access;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\Mock\FakeAccess;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
/**
* @group UsersManager
* @group UserPreferencesTest
* @group Plugins
* @group Plugins
*/
class UserPreferencesTest extends IntegrationTestCase
{
/**
* @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);
}
}
|