File size: 4,013 Bytes
968114b | 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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | <?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\AnonymousPiwikUsageMeasurement\tests\Integration\Tracker;
use Piwik\Db;
use Piwik\Plugins\AnonymousPiwikUsageMeasurement\Tracker\CustomVariables;
use Piwik\Plugins\SegmentEditor\API as SegmentApi;
use Piwik\Plugins\UsersManager\API as UsersApi;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\Mock\FakeAccess;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
/**
* @group AnonymousPiwikUsageMeasurement
* @group CustomVariables
* @group CustomVariablesTest
* @group Plugins
*/
class CustomVariablesTest extends IntegrationTestCase
{
private $idSite = 1;
/**
* @var CustomVariables
*/
private $customVars;
public function setUp(): void
{
parent::setUp();
if (!Fixture::siteCreated($this->idSite)) {
Fixture::createWebsite('2014-01-01 00:00:00');
}
$this->customVars = new CustomVariables();
}
public function test_getClientVisitCustomVariables_shouldReturnAccessInformation_IfUser()
{
FakeAccess::clearAccess($superUser = false, $idSitesAdmin = array($this->idSite));
$access = $this->makeAccessCustomVar('user');
$this->assertSame(array($access), $this->customVars->getClientVisitCustomVariables());
}
public function test_getClientVisitCustomVariables_shouldReturnAccessInformation_IfAnonymous()
{
FakeAccess::clearAccess($superUser = false, array(), array(), $login = 'anonymous');
$access = $this->makeAccessCustomVar('anonymous');
$this->assertSame(array($access), $this->customVars->getClientVisitCustomVariables());
}
public function test_getClientVisitCustomVariables_shouldReturnAccessInformation_IfSuperuser()
{
FakeAccess::clearAccess($superUser = true);
$access = $this->makeAccessCustomVar('superuser');
$this->assertSame(array($access), $this->customVars->getClientVisitCustomVariables());
}
public function test_getServerVisitCustomVariables_shouldReturnSystemReport()
{
FakeAccess::clearAccess($superUser = true);
for ($i = 1; $i < 15; $i++) {
if (!Fixture::siteCreated($i)) {
Fixture::createWebsite('2014-01-01 00:00:00');
}
}
for ($i = 1; $i < 9; $i++) {
UsersApi::getInstance()->addUser($login = 'test' . $i, 'password0815', "lorem$i@piwik.org");
}
for ($i = 1; $i < 5; $i++) {
SegmentApi::getInstance()->add('Segment' . $i, 'pageUrl%3D@inde');
}
$customVars = array(
array(
'id' => 1,
'name' => 'Matomo Version',
'value' => '2.14.3',
),
array(
'id' => 2,
'name' => 'PHP Version',
'value' => '5.5.27',
),
array(
'id' => 3,
'name' => 'Num Users',
'value' => 8,
),
array(
'id' => 4,
'name' => 'Num Websites',
'value' => 14,
),
array(
'id' => 5,
'name' => 'Num Segments',
'value' => 4,
),
array(
'id' => 6,
'name' => 'MySQL Version',
'value' => Db::get()->getServerVersion(),
),
);
$this->assertSame($customVars, $this->customVars->getServerVisitCustomVariables());
}
private function makeAccessCustomVar($permission)
{
return array(
'id' => 1,
'name' => 'Access',
'value' => $permission,
);
}
public function provideContainerConfig()
{
return array(
'Piwik\Access' => new FakeAccess()
);
}
}
|