-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControllerTest.php
More file actions
115 lines (92 loc) · 3.06 KB
/
ControllerTest.php
File metadata and controls
115 lines (92 loc) · 3.06 KB
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
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
declare(strict_types=1);
namespace Piwik\Plugins\OpenApiDocs\tests\Integration;
use Piwik\Access;
use Piwik\Container\StaticContainer;
use Piwik\Plugin\Manager;
use Piwik\Plugins\OpenApiDocs\Controller;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\Mock\FakeAccess;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
/**
* @group OpenApiDocs
* @group ControllerTest
* @group Plugins
*/
class ControllerTest extends IntegrationTestCase
{
/**
* @var Controller
*/
private $controller;
/**
* @var array<string, mixed>
*/
private $backupGet;
/**
* @var array<string, mixed>
*/
private $backupRequest;
public function setUp(): void
{
parent::setUp();
$this->backupGet = $_GET;
$this->backupRequest = $_REQUEST;
Fixture::createSuperUser();
if (!Fixture::siteCreated(1)) {
Fixture::createWebsite('2012-01-01 00:00:00');
}
Fixture::resetTranslations();
Fixture::loadAllTranslations();
Manager::getInstance()->loadPlugin('OpenApiDocs');
$_GET = [
'idSite' => 1,
'period' => 'day',
'date' => 'today',
];
$_REQUEST = $_GET;
$this->controller = new Controller();
}
public function tearDown(): void
{
$_GET = $this->backupGet;
$_REQUEST = $this->backupRequest;
Fixture::resetTranslations();
parent::tearDown();
}
public function testSwaggerRendersAdminPageForViewAccess(): void
{
FakeAccess::clearAccess(
$superUser = false,
$idSitesAdmin = [0],
$idSitesView = [1],
$identity = 'viewAccessUser'
);
$html = $this->controller->swagger();
$this->assertNotSame('', $html);
$this->assertStringContainsString('vue-entry="OpenApiDocs.SwaggerPage"', $html);
$this->assertStringContainsString('piwik-url=', $html);
$this->assertStringContainsString('plugins/OpenApiDocs/vue/lib/swagger-ui/swagger-ui.css', $html);
$this->assertStringContainsString('plugins/OpenApiDocs/vue/src/SwaggerPage/swagger-ui-overrides.css', $html);
$this->assertStringContainsString('plugins/OpenApiDocs/vue/lib/swagger-ui/swagger-ui-bundle.js', $html);
$this->assertStringContainsString('Swagger', $html);
}
public function testSwaggerThrowsWhenUserHasNoAccess(): void
{
$originalAccess = StaticContainer::getContainer()->get(Access::class);
StaticContainer::getContainer()->set(Access::class, new FakeAccess(false, [], [], 'noAccess'));
try {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('checkUserHasSomeViewAccess');
$this->controller->swagger();
} finally {
StaticContainer::getContainer()->set(Access::class, $originalAccess);
}
}
}