Skip to content

Commit 0743d57

Browse files
committed
remove unused translations and added controller test
1 parent 017109d commit 0743d57

3 files changed

Lines changed: 108 additions & 8 deletions

File tree

OpenApiDocs.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ public function getClientSideTranslationKeys(&$translationKeys): void
4848
$translationKeys[] = 'OpenApiDocs_ReportingApiReference';
4949
$translationKeys[] = 'OpenApiDocs_ReportingApiSummary';
5050
$translationKeys[] = 'OpenApiDocs_Swagger';
51-
$translationKeys[] = 'OpenApiDocs_SwaggerPageDescription';
52-
$translationKeys[] = 'OpenApiDocs_SwaggerPageLoading';
5351
$translationKeys[] = 'OpenApiDocs_SwaggerPagePluginEmpty';
54-
$translationKeys[] = 'OpenApiDocs_SwaggerPagePluginPlaceholder';
55-
$translationKeys[] = 'OpenApiDocs_SwaggerPagePlaceholder';
5652
$translationKeys[] = 'OpenApiDocs_SwaggerPageRequestFailed';
5753
$translationKeys[] = 'OpenApiDocs_SwaggerPageSpecLoadFailed';
5854
$translationKeys[] = 'OpenApiDocs_SwaggerPageSearchNoResults';

lang/en.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
"ReportingApiReference": "Reporting API Reference",
55
"ReportingApiSummary": "All the data in Matomo is available through simple APIs.",
66
"Swagger": "Swagger",
7-
"SwaggerPageDescription": "Preview and test the Matomo OpenAPI documentation from this admin page.",
8-
"SwaggerPageLoading": "Loading configured plugins...",
97
"SwaggerPagePluginEmpty": "No plugins are configured in the OpenApiDocs whitelist.",
10-
"SwaggerPagePluginPlaceholder": "Swagger UI for %s will appear here.",
11-
"SwaggerPagePlaceholder": "Swagger UI boilerplate is loaded. The interactive API documentation will be added here next.",
128
"SwaggerPageRequestFailed": "The plugin whitelist could not be loaded.",
139
"SwaggerPageSpecLoadFailed": "The OpenAPI spec could not be loaded for this plugin.",
1410
"SwaggerPageSearchNoResults": "No plugins match your search.",
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?php
2+
3+
/**
4+
* Matomo - free/libre analytics platform
5+
*
6+
* @link https://matomo.org
7+
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace Piwik\Plugins\OpenApiDocs\tests\Integration;
13+
14+
use Piwik\Access;
15+
use Piwik\Container\StaticContainer;
16+
use Piwik\Plugin\Manager;
17+
use Piwik\Plugins\OpenApiDocs\Controller;
18+
use Piwik\Tests\Framework\Fixture;
19+
use Piwik\Tests\Framework\Mock\FakeAccess;
20+
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
21+
22+
/**
23+
* @group OpenApiDocs
24+
* @group ControllerTest
25+
* @group Plugins
26+
*/
27+
class ControllerTest extends IntegrationTestCase
28+
{
29+
private Controller $controller;
30+
31+
/**
32+
* @var array<string, mixed>
33+
*/
34+
private array $backupGet;
35+
36+
/**
37+
* @var array<string, mixed>
38+
*/
39+
private array $backupRequest;
40+
41+
public function setUp(): void
42+
{
43+
parent::setUp();
44+
45+
$this->backupGet = $_GET;
46+
$this->backupRequest = $_REQUEST;
47+
48+
Fixture::createSuperUser();
49+
if (!Fixture::siteCreated(1)) {
50+
Fixture::createWebsite('2012-01-01 00:00:00');
51+
}
52+
53+
Fixture::resetTranslations();
54+
Fixture::loadAllTranslations();
55+
56+
Manager::getInstance()->loadPlugin('OpenApiDocs');
57+
58+
$_GET = [
59+
'idSite' => 1,
60+
'period' => 'day',
61+
'date' => 'today',
62+
];
63+
$_REQUEST = $_GET;
64+
65+
$this->controller = new Controller();
66+
}
67+
68+
public function tearDown(): void
69+
{
70+
$_GET = $this->backupGet;
71+
$_REQUEST = $this->backupRequest;
72+
73+
Fixture::resetTranslations();
74+
75+
parent::tearDown();
76+
}
77+
78+
public function testSwaggerRendersAdminPageForSuperUser(): void
79+
{
80+
FakeAccess::clearAccess(
81+
$superUser = true,
82+
$idSitesAdmin = [1],
83+
$idSitesView = [1],
84+
$identity = 'superUserLogin'
85+
);
86+
87+
$html = $this->controller->swagger();
88+
89+
$this->assertNotSame('', $html);
90+
$this->assertStringContainsString('vue-entry="OpenApiDocs.SwaggerPage"', $html);
91+
$this->assertStringContainsString('Swagger', $html);
92+
}
93+
94+
public function testSwaggerThrowsWhenUserIsNotSuperUser(): void
95+
{
96+
$originalAccess = StaticContainer::getContainer()->get(Access::class);
97+
StaticContainer::getContainer()->set(Access::class, new FakeAccess(false, [], [1], 'viewUser'));
98+
99+
try {
100+
$this->expectException(\Exception::class);
101+
$this->expectExceptionMessage('checkUserHasSuperUserAccess');
102+
103+
$this->controller->swagger();
104+
} finally {
105+
StaticContainer::getContainer()->set(Access::class, $originalAccess);
106+
}
107+
}
108+
}

0 commit comments

Comments
 (0)