aboutsummaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php')
-rw-r--r--apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php86
1 files changed, 36 insertions, 50 deletions
diff --git a/apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php b/apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php
index 2d8b79842f2..c027e518a3d 100644
--- a/apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php
+++ b/apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php
@@ -1,66 +1,51 @@
<?php
+
/**
- * @copyright 2016, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Provisioning_API\Tests\Middleware;
use OCA\Provisioning_API\Middleware\Exceptions\NotSubAdminException;
use OCA\Provisioning_API\Middleware\ProvisioningApiMiddleware;
use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http;
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\Utility\IControllerMethodReflector;
use Test\TestCase;
class ProvisioningApiMiddlewareTest extends TestCase {
- /** @var IControllerMethodReflector|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var IControllerMethodReflector|\PHPUnit\Framework\MockObject\MockObject */
private $reflector;
- public function setUp() {
+ protected function setUp(): void {
parent::setUp();
$this->reflector = $this->createMock(IControllerMethodReflector::class);
}
- public function dataAnnotation() {
+ public static function dataAnnotation(): array {
return [
- [false, false, false, false],
- [false, false, true, false],
- [false, true, true, false],
- [ true, false, false, true],
- [ true, false, true, false],
- [ true, true, false, false],
- [ true, true, true, false],
+ [false, false, false, false, false],
+ [false, false, true, false, false],
+ [false, true, true, false, false],
+ [true, false, false, false, true],
+ [true, false, true, false, false],
+ [true, true, false, false, false],
+ [true, true, true, false, false],
+ [false, false, false, true, false],
+ [false, false, true, true, false],
+ [false, true, true, true, false],
+ [true, false, false, true, false],
+ [true, false, true, true, false],
+ [true, true, false, true, false],
+ [true, true, true, true, false],
];
}
- /**
- * @dataProvider dataAnnotation
- *
- * @param bool $subadminRequired
- * @param bool $isAdmin
- * @param bool $isSubAdmin
- * @param bool $shouldThrowException
- */
- public function testBeforeController($subadminRequired, $isAdmin, $isSubAdmin, $shouldThrowException) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataAnnotation')]
+ public function testBeforeController(bool $subadminRequired, bool $isAdmin, bool $isSubAdmin, bool $hasSettingAuthorizationAnnotation, bool $shouldThrowException): void {
$middleware = new ProvisioningApiMiddleware(
$this->reflector,
$isAdmin,
@@ -68,8 +53,15 @@ class ProvisioningApiMiddlewareTest extends TestCase {
);
$this->reflector->method('hasAnnotation')
- ->with('NoSubAdminRequired')
- ->willReturn(!$subadminRequired);
+ ->willReturnCallback(function ($annotation) use ($subadminRequired, $hasSettingAuthorizationAnnotation) {
+ if ($annotation === 'NoSubAdminRequired') {
+ return !$subadminRequired;
+ }
+ if ($annotation === 'AuthorizedAdminSetting') {
+ return $hasSettingAuthorizationAnnotation;
+ }
+ return false;
+ });
try {
$middleware->beforeController(
@@ -82,20 +74,15 @@ class ProvisioningApiMiddlewareTest extends TestCase {
}
}
- public function dataAfterException() {
+ public static function dataAfterException(): array {
return [
[new NotSubAdminException(), false],
[new \Exception('test', 42), true],
];
}
- /**
- * @dataProvider dataAfterException
- *
- * @param \Exception $e
- * @param bool $forwared
- */
- public function testAfterException(\Exception $exception, $forwared) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataAfterException')]
+ public function testAfterException(\Exception $exception, bool $forwared): void {
$middleware = new ProvisioningApiMiddleware(
$this->reflector,
false,
@@ -112,11 +99,10 @@ class ProvisioningApiMiddlewareTest extends TestCase {
} catch (OCSException $e) {
$this->assertFalse($forwared);
$this->assertSame($exception->getMessage(), $e->getMessage());
- $this->assertSame(\OCP\API::RESPOND_UNAUTHORISED, $e->getCode());
+ $this->assertSame(Http::STATUS_FORBIDDEN, $e->getCode());
} catch (\Exception $e) {
$this->assertTrue($forwared);
$this->assertSame($exception, $e);
}
-
}
}