|
11 | 11 |
|
12 | 12 | namespace Piwik\Plugins\ApiReference\tests\Integration; |
13 | 13 |
|
| 14 | +use Piwik\Access; |
14 | 15 | use Piwik\Cache; |
| 16 | +use Piwik\Container\StaticContainer; |
15 | 17 | use Piwik\Menu\MenuAdmin; |
16 | 18 | use Piwik\Plugin\Manager; |
17 | 19 | use Piwik\Tests\Framework\Fixture; |
@@ -50,38 +52,23 @@ public function tearDown(): void |
50 | 52 | parent::tearDown(); |
51 | 53 | } |
52 | 54 |
|
53 | | - public function testConfigureAdminMenuAddsSwaggerItemForViewAccess(): void |
| 55 | + public function testConfigureAdminMenuEditsApiItemUrlForViewAccess(): void |
54 | 56 | { |
55 | | - FakeAccess::clearAccess( |
56 | | - $superUser = false, |
57 | | - $idSitesAdmin = [0], |
58 | | - $idSitesView = [1], |
59 | | - $identity = 'viewAccessUser' |
60 | | - ); |
61 | | - |
62 | | - $items = $this->buildConfiguredMenu()->getMenu(); |
63 | | - |
64 | | - $this->assertArrayHasKey('CorePluginsAdmin_MenuPlatform', $items); |
65 | | - $this->assertArrayHasKey('ApiReference_SwaggerApi', $items['CorePluginsAdmin_MenuPlatform']); |
66 | | - } |
67 | | - |
68 | | - public function testConfigureAdminMenuSkipsSwaggerItemWithoutViewAccess(): void |
69 | | - { |
70 | | - FakeAccess::clearAccess( |
71 | | - $superUser = false, |
72 | | - $idSitesAdmin = [], |
73 | | - $idSitesView = [], |
74 | | - $identity = 'noAccessUser' |
75 | | - ); |
76 | | - |
77 | | - $items = $this->buildConfiguredMenu()->getMenu(); |
78 | | - |
79 | | - if (!isset($items['CorePluginsAdmin_MenuPlatform'])) { |
80 | | - $this->assertArrayNotHasKey('CorePluginsAdmin_MenuPlatform', $items); |
81 | | - return; |
| 57 | + $originalAccess = StaticContainer::getContainer()->get(Access::class); |
| 58 | + StaticContainer::getContainer()->set(Access::class, new FakeAccess(false, [0], [1], 'viewAccessUser')); |
| 59 | + |
| 60 | + try { |
| 61 | + $items = $this->buildConfiguredMenu()->getMenu(); |
| 62 | + |
| 63 | + $this->assertArrayHasKey('CorePluginsAdmin_MenuPlatform', $items); |
| 64 | + $this->assertArrayHasKey('General_API', $items['CorePluginsAdmin_MenuPlatform']); |
| 65 | + $this->assertSame( |
| 66 | + ['action' => 'swagger', 'module' => 'ApiReference'], |
| 67 | + $items['CorePluginsAdmin_MenuPlatform']['General_API']['_url'] |
| 68 | + ); |
| 69 | + } finally { |
| 70 | + StaticContainer::getContainer()->set(Access::class, $originalAccess); |
82 | 71 | } |
83 | | - |
84 | | - $this->assertArrayNotHasKey('ApiReference_SwaggerApi', $items['CorePluginsAdmin_MenuPlatform']); |
85 | 72 | } |
86 | 73 |
|
87 | 74 | private function buildConfiguredMenu(): MenuAdmin |
|
0 commit comments