aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/AppFramework
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/AppFramework')
-rw-r--r--tests/lib/AppFramework/AppTest.php2
-rw-r--r--tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php2
-rw-r--r--tests/lib/AppFramework/Controller/AuthPublicShareControllerTest.php10
-rw-r--r--tests/lib/AppFramework/Controller/ControllerTest.php2
-rw-r--r--tests/lib/AppFramework/Controller/PublicShareControllerTest.php2
-rw-r--r--tests/lib/AppFramework/Db/EntityTest.php2
-rw-r--r--tests/lib/AppFramework/Db/QBMapperTest.php95
-rw-r--r--tests/lib/AppFramework/DependencyInjection/DIContainerTest.php2
-rw-r--r--tests/lib/AppFramework/Http/DispatcherTest.php40
-rw-r--r--tests/lib/AppFramework/Http/DownloadResponseTest.php2
-rw-r--r--tests/lib/AppFramework/Http/JSONResponseTest.php5
-rw-r--r--tests/lib/AppFramework/Middleware/MiddlewareDispatcherTest.php17
-rw-r--r--tests/lib/AppFramework/Middleware/MiddlewareTest.php7
-rw-r--r--tests/lib/AppFramework/Middleware/NotModifiedMiddlewareTest.php2
-rw-r--r--tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php120
-rw-r--r--tests/lib/AppFramework/Middleware/PublicShare/PublicShareMiddlewareTest.php2
-rw-r--r--tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php41
-rw-r--r--tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php16
-rw-r--r--tests/lib/AppFramework/Middleware/Security/PasswordConfirmationMiddlewareTest.php2
-rw-r--r--tests/lib/AppFramework/Middleware/Security/SameSiteCookieMiddlewareTest.php2
-rw-r--r--tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php20
-rw-r--r--tests/lib/AppFramework/OCS/V2ResponseTest.php2
-rw-r--r--tests/lib/AppFramework/Routing/RouteParserTest.php347
-rw-r--r--tests/lib/AppFramework/Routing/RoutingTest.php476
-rw-r--r--tests/lib/AppFramework/Services/AppConfigTest.php16
-rw-r--r--tests/lib/AppFramework/Utility/SimpleContainerTest.php2
26 files changed, 551 insertions, 685 deletions
diff --git a/tests/lib/AppFramework/AppTest.php b/tests/lib/AppFramework/AppTest.php
index 3c535a4bf7a..87c96fdb9a8 100644
--- a/tests/lib/AppFramework/AppTest.php
+++ b/tests/lib/AppFramework/AppTest.php
@@ -124,7 +124,7 @@ class AppTest extends \Test\TestCase {
App::main($this->controllerName, $this->controllerMethod, $this->container, []);
}
- public function dataNoOutput() {
+ public static function dataNoOutput(): array {
return [
['HTTP/2.0 204 No content'],
['HTTP/2.0 304 Not modified'],
diff --git a/tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php b/tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php
index 1e0b13b5755..6469a01cce3 100644
--- a/tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php
+++ b/tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php
@@ -156,7 +156,7 @@ class RegistrationContextTest extends TestCase {
);
}
- public function dataProvider_TrueFalse() {
+ public static function dataProvider_TrueFalse(): array {
return[
[true],
[false]
diff --git a/tests/lib/AppFramework/Controller/AuthPublicShareControllerTest.php b/tests/lib/AppFramework/Controller/AuthPublicShareControllerTest.php
index d6e0321023e..bcc0daf002f 100644
--- a/tests/lib/AppFramework/Controller/AuthPublicShareControllerTest.php
+++ b/tests/lib/AppFramework/Controller/AuthPublicShareControllerTest.php
@@ -38,7 +38,7 @@ class AuthPublicShareControllerTest extends \Test\TestCase {
$this->request,
$this->session,
$this->urlGenerator
- ])->setMethods([
+ ])->onlyMethods([
'authFailed',
'getPasswordHash',
'isAuthenticated',
@@ -64,7 +64,9 @@ class AuthPublicShareControllerTest extends \Test\TestCase {
$this->controller->setToken('myToken');
$this->session->method('get')
- ->willReturnMap(['public_link_authenticate_redirect', ['foo' => 'bar']]);
+ ->willReturnMap([
+ ['public_link_authenticate_redirect', json_encode(['foo' => 'bar'])],
+ ]);
$this->urlGenerator->method('linkToRoute')
->willReturn('myLink!');
@@ -107,7 +109,9 @@ class AuthPublicShareControllerTest extends \Test\TestCase {
$this->session->expects($this->once())
->method('regenerateId');
$this->session->method('get')
- ->willReturnMap(['public_link_authenticate_redirect', ['foo' => 'bar']]);
+ ->willReturnMap([
+ ['public_link_authenticate_redirect', json_encode(['foo' => 'bar'])],
+ ]);
$tokenSet = false;
$hashSet = false;
diff --git a/tests/lib/AppFramework/Controller/ControllerTest.php b/tests/lib/AppFramework/Controller/ControllerTest.php
index 7c466e3a5b7..aa016872847 100644
--- a/tests/lib/AppFramework/Controller/ControllerTest.php
+++ b/tests/lib/AppFramework/Controller/ControllerTest.php
@@ -66,7 +66,7 @@ class ControllerTest extends \Test\TestCase {
);
$this->app = $this->getMockBuilder(DIContainer::class)
- ->setMethods(['getAppName'])
+ ->onlyMethods(['getAppName'])
->setConstructorArgs(['test'])
->getMock();
$this->app->expects($this->any())
diff --git a/tests/lib/AppFramework/Controller/PublicShareControllerTest.php b/tests/lib/AppFramework/Controller/PublicShareControllerTest.php
index f8430d42ef1..6f0e433f2fb 100644
--- a/tests/lib/AppFramework/Controller/PublicShareControllerTest.php
+++ b/tests/lib/AppFramework/Controller/PublicShareControllerTest.php
@@ -57,7 +57,7 @@ class PublicShareControllerTest extends \Test\TestCase {
$this->assertEquals('test', $controller->getToken());
}
- public function dataIsAuthenticated() {
+ public static function dataIsAuthenticated(): array {
return [
[false, 'token1', 'token1', 'hash1', 'hash1', true],
[false, 'token1', 'token1', 'hash1', 'hash2', true],
diff --git a/tests/lib/AppFramework/Db/EntityTest.php b/tests/lib/AppFramework/Db/EntityTest.php
index 3c844780b07..ccd0ae4bbaf 100644
--- a/tests/lib/AppFramework/Db/EntityTest.php
+++ b/tests/lib/AppFramework/Db/EntityTest.php
@@ -211,7 +211,7 @@ class EntityTest extends \Test\TestCase {
}
- public function dataSetterCasts(): array {
+ public static function dataSetterCasts(): array {
return [
['Id', '3', 3],
['smallInt', '3', 3],
diff --git a/tests/lib/AppFramework/Db/QBMapperTest.php b/tests/lib/AppFramework/Db/QBMapperTest.php
index 3cf32e56f12..c1d8bf07234 100644
--- a/tests/lib/AppFramework/Db/QBMapperTest.php
+++ b/tests/lib/AppFramework/Db/QBMapperTest.php
@@ -99,7 +99,7 @@ class QBMapperTest extends \Test\TestCase {
$this->mapper = new QBTestMapper($this->db);
}
-
+
public function testInsertEntityParameterTypeMapping(): void {
$datetime = new \DateTimeImmutable();
$entity = new QBTestEntity();
@@ -117,31 +117,40 @@ class QBMapperTest extends \Test\TestCase {
$booleanParam = $this->qb->createNamedParameter('boolean_prop', IQueryBuilder::PARAM_BOOL);
$datetimeParam = $this->qb->createNamedParameter('datetime_prop', IQueryBuilder::PARAM_DATETIME_IMMUTABLE);
+ $createNamedParameterCalls = [
+ [123, IQueryBuilder::PARAM_INT, null],
+ [true, IQueryBuilder::PARAM_BOOL, null],
+ ['string', IQueryBuilder::PARAM_STR, null],
+ [456, IQueryBuilder::PARAM_INT, null],
+ [false, IQueryBuilder::PARAM_BOOL, null],
+ [$datetime, IQueryBuilder::PARAM_DATETIME_IMMUTABLE, null],
+ ];
$this->qb->expects($this->exactly(6))
->method('createNamedParameter')
- ->withConsecutive(
- [$this->equalTo(123), $this->equalTo(IQueryBuilder::PARAM_INT)],
- [$this->equalTo(true), $this->equalTo(IQueryBuilder::PARAM_BOOL)],
- [$this->equalTo('string'), $this->equalTo(IQueryBuilder::PARAM_STR)],
- [$this->equalTo(456), $this->equalTo(IQueryBuilder::PARAM_INT)],
- [$this->equalTo(false), $this->equalTo(IQueryBuilder::PARAM_BOOL)],
- [$this->equalTo($datetime), $this->equalTo(IQueryBuilder::PARAM_DATETIME_IMMUTABLE)],
- );
+ ->willReturnCallback(function () use (&$createNamedParameterCalls) {
+ $expected = array_shift($createNamedParameterCalls);
+ $this->assertEquals($expected, func_get_args());
+ });
+
+ $setValueCalls = [
+ ['int_prop', $intParam],
+ ['bool_prop', $boolParam],
+ ['string_prop', $stringParam],
+ ['integer_prop', $integerParam],
+ ['boolean_prop', $booleanParam],
+ ['datetime_prop', $datetimeParam],
+ ];
$this->qb->expects($this->exactly(6))
->method('setValue')
- ->withConsecutive(
- [$this->equalTo('int_prop'), $this->equalTo($intParam)],
- [$this->equalTo('bool_prop'), $this->equalTo($boolParam)],
- [$this->equalTo('string_prop'), $this->equalTo($stringParam)],
- [$this->equalTo('integer_prop'), $this->equalTo($integerParam)],
- [$this->equalTo('boolean_prop'), $this->equalTo($booleanParam)],
- [$this->equalTo('datetime_prop'), $this->equalTo($datetimeParam)],
- );
+ ->willReturnCallback(function () use (&$setValueCalls) {
+ $expected = array_shift($setValueCalls);
+ $this->assertEquals($expected, func_get_args());
+ });
$this->mapper->insert($entity);
}
-
+
public function testUpdateEntityParameterTypeMapping(): void {
$datetime = new \DateTimeImmutable();
$entity = new QBTestEntity();
@@ -163,30 +172,38 @@ class QBMapperTest extends \Test\TestCase {
$jsonParam = $this->qb->createNamedParameter('json_prop', IQueryBuilder::PARAM_JSON);
$datetimeParam = $this->qb->createNamedParameter('datetime_prop', IQueryBuilder::PARAM_DATETIME_IMMUTABLE);
+ $createNamedParameterCalls = [
+ [123, IQueryBuilder::PARAM_INT, null],
+ [true, IQueryBuilder::PARAM_BOOL, null],
+ ['string', IQueryBuilder::PARAM_STR, null],
+ [456, IQueryBuilder::PARAM_INT, null],
+ [false, IQueryBuilder::PARAM_BOOL, null],
+ [['hello' => 'world'], IQueryBuilder::PARAM_JSON, null],
+ [$datetime, IQueryBuilder::PARAM_DATETIME_IMMUTABLE, null],
+ [789, IQueryBuilder::PARAM_INT, null],
+ ];
$this->qb->expects($this->exactly(8))
->method('createNamedParameter')
- ->withConsecutive(
- [$this->equalTo(123), $this->equalTo(IQueryBuilder::PARAM_INT)],
- [$this->equalTo(true), $this->equalTo(IQueryBuilder::PARAM_BOOL)],
- [$this->equalTo('string'), $this->equalTo(IQueryBuilder::PARAM_STR)],
- [$this->equalTo(456), $this->equalTo(IQueryBuilder::PARAM_INT)],
- [$this->equalTo(false), $this->equalTo(IQueryBuilder::PARAM_BOOL)],
- [$this->equalTo(['hello' => 'world']), $this->equalTo(IQueryBuilder::PARAM_JSON)],
- [$this->equalTo($datetime), $this->equalTo(IQueryBuilder::PARAM_DATETIME_IMMUTABLE)],
- [$this->equalTo(789), $this->equalTo(IQueryBuilder::PARAM_INT)],
- );
-
+ ->willReturnCallback(function () use (&$createNamedParameterCalls) {
+ $expected = array_shift($createNamedParameterCalls);
+ $this->assertEquals($expected, func_get_args());
+ });
+
+ $setCalls = [
+ ['int_prop', $intParam],
+ ['bool_prop', $boolParam],
+ ['string_prop', $stringParam],
+ ['integer_prop', $integerParam],
+ ['boolean_prop', $booleanParam],
+ ['json_prop', $datetimeParam],
+ ['datetime_prop', $datetimeParam],
+ ];
$this->qb->expects($this->exactly(7))
->method('set')
- ->withConsecutive(
- [$this->equalTo('int_prop'), $this->equalTo($intParam)],
- [$this->equalTo('bool_prop'), $this->equalTo($boolParam)],
- [$this->equalTo('string_prop'), $this->equalTo($stringParam)],
- [$this->equalTo('integer_prop'), $this->equalTo($integerParam)],
- [$this->equalTo('boolean_prop'), $this->equalTo($booleanParam)],
- [$this->equalTo('json_prop'), $this->equalTo($jsonParam)],
- [$this->equalTo('datetime_prop'), $this->equalTo($datetimeParam)],
- );
+ ->willReturnCallback(function () use (&$setCalls) {
+ $expected = array_shift($setCalls);
+ $this->assertEquals($expected, func_get_args());
+ });
$this->expr->expects($this->once())
->method('eq')
@@ -196,7 +213,7 @@ class QBMapperTest extends \Test\TestCase {
$this->mapper->update($entity);
}
-
+
public function testGetParameterTypeForProperty(): void {
$entity = new QBTestEntity();
diff --git a/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php b/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php
index f3d2cff1ffd..e84b44db9a0 100644
--- a/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php
+++ b/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php
@@ -29,7 +29,7 @@ class DIContainerTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();
$this->container = $this->getMockBuilder(DIContainer::class)
- ->setMethods(['isAdminUser'])
+ ->onlyMethods(['isAdminUser'])
->setConstructorArgs(['name'])
->getMock();
}
diff --git a/tests/lib/AppFramework/Http/DispatcherTest.php b/tests/lib/AppFramework/Http/DispatcherTest.php
index 7415ecd9486..404d3f4c90b 100644
--- a/tests/lib/AppFramework/Http/DispatcherTest.php
+++ b/tests/lib/AppFramework/Http/DispatcherTest.php
@@ -8,6 +8,7 @@
namespace Test\AppFramework\Http;
+use OC\AppFramework\DependencyInjection\DIContainer;
use OC\AppFramework\Http\Dispatcher;
use OC\AppFramework\Http\Request;
use OC\AppFramework\Middleware\MiddlewareDispatcher;
@@ -20,6 +21,7 @@ use OCP\AppFramework\Http\ParameterOutOfRangeException;
use OCP\AppFramework\Http\Response;
use OCP\Diagnostics\IEventLogger;
use OCP\IConfig;
+use OCP\IDBConnection;
use OCP\IRequest;
use OCP\IRequestId;
use PHPUnit\Framework\MockObject\MockObject;
@@ -63,6 +65,10 @@ class TestController extends Controller {
'text' => [$int, $bool, $test, $test2]
]);
}
+
+ public function test(): Response {
+ return new DataResponse();
+ }
}
/**
@@ -104,33 +110,17 @@ class DispatcherTest extends \Test\TestCase {
$this->logger = $this->createMock(LoggerInterface::class);
$this->eventLogger = $this->createMock(IEventLogger::class);
$this->container = $this->createMock(ContainerInterface::class);
- $app = $this->getMockBuilder(
- 'OC\AppFramework\DependencyInjection\DIContainer')
- ->disableOriginalConstructor()
- ->getMock();
- $request = $this->getMockBuilder(
- '\OC\AppFramework\Http\Request')
- ->disableOriginalConstructor()
- ->getMock();
- $this->http = $this->getMockBuilder(
- \OC\AppFramework\Http::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $app = $this->createMock(DIContainer::class);
+ $request = $this->createMock(Request::class);
+ $this->http = $this->createMock(\OC\AppFramework\Http::class);
- $this->middlewareDispatcher = $this->getMockBuilder(
- '\OC\AppFramework\Middleware\MiddlewareDispatcher')
- ->disableOriginalConstructor()
- ->getMock();
- $this->controller = $this->getMockBuilder(
- '\OCP\AppFramework\Controller')
- ->setMethods([$this->controllerMethod])
+ $this->middlewareDispatcher = $this->createMock(MiddlewareDispatcher::class);
+ $this->controller = $this->getMockBuilder(TestController::class)
+ ->onlyMethods([$this->controllerMethod])
->setConstructorArgs([$app, $request])
->getMock();
- $this->request = $this->getMockBuilder(
- '\OC\AppFramework\Http\Request')
- ->disableOriginalConstructor()
- ->getMock();
+ $this->request = $this->createMock(Request::class);
$this->reflector = new ControllerMethodReflector();
@@ -140,7 +130,7 @@ class DispatcherTest extends \Test\TestCase {
$this->reflector,
$this->request,
$this->config,
- \OC::$server->getDatabaseConnection(),
+ \OCP\Server::get(IDBConnection::class),
$this->logger,
$this->eventLogger,
$this->container,
@@ -545,7 +535,7 @@ class DispatcherTest extends \Test\TestCase {
}
- public function rangeDataProvider(): array {
+ public static function rangeDataProvider(): array {
return [
[PHP_INT_MIN, PHP_INT_MAX, 42, false],
[0, 12, -5, true],
diff --git a/tests/lib/AppFramework/Http/DownloadResponseTest.php b/tests/lib/AppFramework/Http/DownloadResponseTest.php
index ee89e8e55d1..cf179ba270b 100644
--- a/tests/lib/AppFramework/Http/DownloadResponseTest.php
+++ b/tests/lib/AppFramework/Http/DownloadResponseTest.php
@@ -37,7 +37,7 @@ class DownloadResponseTest extends \Test\TestCase {
$this->assertEquals('attachment; filename="' . $expected . '"', $headers['Content-Disposition']);
}
- public function filenameEncodingProvider() : array {
+ public static function filenameEncodingProvider() : array {
return [
['TestName.txt', 'TestName.txt'],
['A "Quoted" Filename.txt', 'A \\"Quoted\\" Filename.txt'],
diff --git a/tests/lib/AppFramework/Http/JSONResponseTest.php b/tests/lib/AppFramework/Http/JSONResponseTest.php
index 175ed852c7b..703e6d89dd1 100644
--- a/tests/lib/AppFramework/Http/JSONResponseTest.php
+++ b/tests/lib/AppFramework/Http/JSONResponseTest.php
@@ -46,10 +46,7 @@ class JSONResponseTest extends \Test\TestCase {
$this->assertEquals($expected, $this->json->render());
}
- /**
- * @return array
- */
- public function renderDataProvider() {
+ public static function renderDataProvider(): array {
return [
[
['test' => 'hi'], '{"test":"hi"}',
diff --git a/tests/lib/AppFramework/Middleware/MiddlewareDispatcherTest.php b/tests/lib/AppFramework/Middleware/MiddlewareDispatcherTest.php
index fae5f5d9f1c..a8273be362b 100644
--- a/tests/lib/AppFramework/Middleware/MiddlewareDispatcherTest.php
+++ b/tests/lib/AppFramework/Middleware/MiddlewareDispatcherTest.php
@@ -10,6 +10,7 @@ namespace Test\AppFramework\Middleware;
use OC\AppFramework\Http\Request;
use OC\AppFramework\Middleware\MiddlewareDispatcher;
+use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Middleware;
use OCP\IConfig;
@@ -84,6 +85,10 @@ class TestMiddleware extends Middleware {
}
}
+class TestController extends Controller {
+ public function method(): void {
+ }
+}
class MiddlewareDispatcherTest extends \Test\TestCase {
public $exception;
@@ -110,8 +115,8 @@ class MiddlewareDispatcherTest extends \Test\TestCase {
private function getControllerMock() {
- return $this->getMockBuilder('OCP\AppFramework\Controller')
- ->setMethods(['method'])
+ return $this->getMockBuilder(TestController::class)
+ ->onlyMethods(['method'])
->setConstructorArgs(['app',
new Request(
['method' => 'GET'],
@@ -131,14 +136,14 @@ class MiddlewareDispatcherTest extends \Test\TestCase {
public function testAfterExceptionShouldReturnResponseOfMiddleware(): void {
$response = new Response();
- $m1 = $this->getMockBuilder('\OCP\AppFramework\Middleware')
- ->setMethods(['afterException', 'beforeController'])
+ $m1 = $this->getMockBuilder(\OCP\AppFramework\Middleware::class)
+ ->onlyMethods(['afterException', 'beforeController'])
->getMock();
$m1->expects($this->never())
->method('afterException');
- $m2 = $this->getMockBuilder('OCP\AppFramework\Middleware')
- ->setMethods(['afterException', 'beforeController'])
+ $m2 = $this->getMockBuilder(\OCP\AppFramework\Middleware::class)
+ ->onlyMethods(['afterException', 'beforeController'])
->getMock();
$m2->expects($this->once())
->method('afterException')
diff --git a/tests/lib/AppFramework/Middleware/MiddlewareTest.php b/tests/lib/AppFramework/Middleware/MiddlewareTest.php
index c1e5c44c4db..addd9683122 100644
--- a/tests/lib/AppFramework/Middleware/MiddlewareTest.php
+++ b/tests/lib/AppFramework/Middleware/MiddlewareTest.php
@@ -36,12 +36,9 @@ class MiddlewareTest extends \Test\TestCase {
$this->middleware = new ChildMiddleware();
- $this->api = $this->getMockBuilder(DIContainer::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $this->api = $this->createMock(DIContainer::class);
$this->controller = $this->getMockBuilder(Controller::class)
- ->setMethods([])
->setConstructorArgs([
$this->api,
new Request(
@@ -51,7 +48,7 @@ class MiddlewareTest extends \Test\TestCase {
)
])->getMock();
$this->exception = new \Exception();
- $this->response = $this->getMockBuilder(Response::class)->getMock();
+ $this->response = $this->createMock(Response::class);
}
diff --git a/tests/lib/AppFramework/Middleware/NotModifiedMiddlewareTest.php b/tests/lib/AppFramework/Middleware/NotModifiedMiddlewareTest.php
index 58ae6b13aed..204cc647cad 100644
--- a/tests/lib/AppFramework/Middleware/NotModifiedMiddlewareTest.php
+++ b/tests/lib/AppFramework/Middleware/NotModifiedMiddlewareTest.php
@@ -32,7 +32,7 @@ class NotModifiedMiddlewareTest extends \Test\TestCase {
$this->controller = $this->createMock(Controller::class);
}
- public function dataModified(): array {
+ public static function dataModified(): array {
$now = new \DateTime();
return [
diff --git a/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php b/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php
index 6724f841c5e..62e20a2dcd0 100644
--- a/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php
+++ b/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php
@@ -12,6 +12,7 @@ use OC\AppFramework\OCS\V1Response;
use OC\AppFramework\OCS\V2Response;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\Response;
use OCP\AppFramework\OCS\OCSBadRequestException;
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCS\OCSForbiddenException;
@@ -32,49 +33,37 @@ class OCSMiddlewareTest extends \Test\TestCase {
->getMock();
}
- public function dataAfterException() {
- $OCSController = $this->getMockBuilder(OCSController::class)
- ->disableOriginalConstructor()
- ->getMock();
- $controller = $this->getMockBuilder(Controller::class)
- ->disableOriginalConstructor()
- ->getMock();
-
+ public static function dataAfterException(): array {
return [
- [$OCSController, new \Exception(), true],
- [$OCSController, new OCSException(), false, '', Http::STATUS_INTERNAL_SERVER_ERROR],
- [$OCSController, new OCSException('foo'), false, 'foo', Http::STATUS_INTERNAL_SERVER_ERROR],
- [$OCSController, new OCSException('foo', Http::STATUS_IM_A_TEAPOT), false, 'foo', Http::STATUS_IM_A_TEAPOT],
- [$OCSController, new OCSBadRequestException(), false, '', Http::STATUS_BAD_REQUEST],
- [$OCSController, new OCSBadRequestException('foo'), false, 'foo', Http::STATUS_BAD_REQUEST],
- [$OCSController, new OCSForbiddenException(), false, '', Http::STATUS_FORBIDDEN],
- [$OCSController, new OCSForbiddenException('foo'), false, 'foo', Http::STATUS_FORBIDDEN],
- [$OCSController, new OCSNotFoundException(), false, '', Http::STATUS_NOT_FOUND],
- [$OCSController, new OCSNotFoundException('foo'), false, 'foo', Http::STATUS_NOT_FOUND],
-
- [$controller, new \Exception(), true],
- [$controller, new OCSException(), true],
- [$controller, new OCSException('foo'), true],
- [$controller, new OCSException('foo', Http::STATUS_IM_A_TEAPOT), true],
- [$controller, new OCSBadRequestException(), true],
- [$controller, new OCSBadRequestException('foo'), true],
- [$controller, new OCSForbiddenException(), true],
- [$controller, new OCSForbiddenException('foo'), true],
- [$controller, new OCSNotFoundException(), true],
- [$controller, new OCSNotFoundException('foo'), true],
+ [OCSController::class, new \Exception(), true],
+ [OCSController::class, new OCSException(), false, '', Http::STATUS_INTERNAL_SERVER_ERROR],
+ [OCSController::class, new OCSException('foo'), false, 'foo', Http::STATUS_INTERNAL_SERVER_ERROR],
+ [OCSController::class, new OCSException('foo', Http::STATUS_IM_A_TEAPOT), false, 'foo', Http::STATUS_IM_A_TEAPOT],
+ [OCSController::class, new OCSBadRequestException(), false, '', Http::STATUS_BAD_REQUEST],
+ [OCSController::class, new OCSBadRequestException('foo'), false, 'foo', Http::STATUS_BAD_REQUEST],
+ [OCSController::class, new OCSForbiddenException(), false, '', Http::STATUS_FORBIDDEN],
+ [OCSController::class, new OCSForbiddenException('foo'), false, 'foo', Http::STATUS_FORBIDDEN],
+ [OCSController::class, new OCSNotFoundException(), false, '', Http::STATUS_NOT_FOUND],
+ [OCSController::class, new OCSNotFoundException('foo'), false, 'foo', Http::STATUS_NOT_FOUND],
+
+ [Controller::class, new \Exception(), true],
+ [Controller::class, new OCSException(), true],
+ [Controller::class, new OCSException('foo'), true],
+ [Controller::class, new OCSException('foo', Http::STATUS_IM_A_TEAPOT), true],
+ [Controller::class, new OCSBadRequestException(), true],
+ [Controller::class, new OCSBadRequestException('foo'), true],
+ [Controller::class, new OCSForbiddenException(), true],
+ [Controller::class, new OCSForbiddenException('foo'), true],
+ [Controller::class, new OCSNotFoundException(), true],
+ [Controller::class, new OCSNotFoundException('foo'), true],
];
}
/**
* @dataProvider dataAfterException
- *
- * @param Controller $controller
- * @param \Exception $exception
- * @param bool $forward
- * @param string $message
- * @param int $code
*/
- public function testAfterExceptionOCSv1($controller, $exception, $forward, $message = '', $code = 0): void {
+ public function testAfterExceptionOCSv1(string $controller, \Exception $exception, bool $forward, string $message = '', int $code = 0): void {
+ $controller = $this->createMock($controller);
$this->request
->method('getScriptName')
->willReturn('/ocs/v1.php');
@@ -103,14 +92,9 @@ class OCSMiddlewareTest extends \Test\TestCase {
/**
* @dataProvider dataAfterException
- *
- * @param Controller $controller
- * @param \Exception $exception
- * @param bool $forward
- * @param string $message
- * @param int $code
*/
- public function testAfterExceptionOCSv2($controller, $exception, $forward, $message = '', $code = 0): void {
+ public function testAfterExceptionOCSv2(string $controller, \Exception $exception, bool $forward, string $message = '', int $code = 0): void {
+ $controller = $this->createMock($controller);
$this->request
->method('getScriptName')
->willReturn('/ocs/v2.php');
@@ -137,14 +121,9 @@ class OCSMiddlewareTest extends \Test\TestCase {
/**
* @dataProvider dataAfterException
- *
- * @param Controller $controller
- * @param \Exception $exception
- * @param bool $forward
- * @param string $message
- * @param int $code
*/
- public function testAfterExceptionOCSv2SubFolder($controller, $exception, $forward, $message = '', $code = 0): void {
+ public function testAfterExceptionOCSv2SubFolder(string $controller, \Exception $exception, bool $forward, string $message = '', int $code = 0): void {
+ $controller = $this->createMock($controller);
$this->request
->method('getScriptName')
->willReturn('/mysubfolder/ocs/v2.php');
@@ -152,7 +131,7 @@ class OCSMiddlewareTest extends \Test\TestCase {
$OCSMiddleware->beforeController($controller, 'method');
if ($forward) {
- $this->expectException(get_class($exception));
+ $this->expectException($exception::class);
$this->expectExceptionMessage($exception->getMessage());
}
@@ -169,39 +148,28 @@ class OCSMiddlewareTest extends \Test\TestCase {
$this->assertSame($code, $result->getStatus());
}
- public function dataAfterController() {
- $OCSController = $this->getMockBuilder(OCSController::class)
- ->disableOriginalConstructor()
- ->getMock();
- $controller = $this->getMockBuilder(Controller::class)
- ->disableOriginalConstructor()
- ->getMock();
-
+ public static function dataAfterController(): array {
return [
- [$OCSController, new Http\Response(), false],
- [$OCSController, new Http\JSONResponse(), false],
- [$OCSController, new Http\JSONResponse(['message' => 'foo']), false],
- [$OCSController, new Http\JSONResponse(['message' => 'foo'], Http::STATUS_UNAUTHORIZED), true, OCSController::RESPOND_UNAUTHORISED],
- [$OCSController, new Http\JSONResponse(['message' => 'foo'], Http::STATUS_FORBIDDEN), true],
-
- [$controller, new Http\Response(), false],
- [$controller, new Http\JSONResponse(), false],
- [$controller, new Http\JSONResponse(['message' => 'foo']), false],
- [$controller, new Http\JSONResponse(['message' => 'foo'], Http::STATUS_UNAUTHORIZED), false],
- [$controller, new Http\JSONResponse(['message' => 'foo'], Http::STATUS_FORBIDDEN), false],
+ [OCSController::class, new Response(), false],
+ [OCSController::class, new Http\JSONResponse(), false],
+ [OCSController::class, new Http\JSONResponse(['message' => 'foo']), false],
+ [OCSController::class, new Http\JSONResponse(['message' => 'foo'], Http::STATUS_UNAUTHORIZED), true, OCSController::RESPOND_UNAUTHORISED],
+ [OCSController::class, new Http\JSONResponse(['message' => 'foo'], Http::STATUS_FORBIDDEN), true],
+
+ [Controller::class, new Response(), false],
+ [Controller::class, new Http\JSONResponse(), false],
+ [Controller::class, new Http\JSONResponse(['message' => 'foo']), false],
+ [Controller::class, new Http\JSONResponse(['message' => 'foo'], Http::STATUS_UNAUTHORIZED), false],
+ [Controller::class, new Http\JSONResponse(['message' => 'foo'], Http::STATUS_FORBIDDEN), false],
];
}
/**
* @dataProvider dataAfterController
- *
- * @param Controller $controller
- * @param Http\Response $response
- * @param bool $converted
- * @param int $convertedOCSStatus
*/
- public function testAfterController($controller, $response, $converted, $convertedOCSStatus = 0): void {
+ public function testAfterController(string $controller, Response $response, bool $converted, int $convertedOCSStatus = 0): void {
+ $controller = $this->createMock($controller);
$OCSMiddleware = new OCSMiddleware($this->request);
$newResponse = $OCSMiddleware->afterController($controller, 'foo', $response);
diff --git a/tests/lib/AppFramework/Middleware/PublicShare/PublicShareMiddlewareTest.php b/tests/lib/AppFramework/Middleware/PublicShare/PublicShareMiddlewareTest.php
index 8433aa93f4a..bf0d719f46e 100644
--- a/tests/lib/AppFramework/Middleware/PublicShare/PublicShareMiddlewareTest.php
+++ b/tests/lib/AppFramework/Middleware/PublicShare/PublicShareMiddlewareTest.php
@@ -58,7 +58,7 @@ class PublicShareMiddlewareTest extends \Test\TestCase {
$this->assertTrue(true);
}
- public function dataShareApi() {
+ public static function dataShareApi(): array {
return [
['no', 'no',],
['no', 'yes',],
diff --git a/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php
index a224ebae949..c516c1e6c89 100644
--- a/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php
+++ b/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php
@@ -98,13 +98,19 @@ class BruteForceMiddlewareTest extends TestCase {
->expects($this->once())
->method('getRemoteAddress')
->willReturn('::1');
+
+ $calls = [
+ ['::1', 'first'],
+ ['::1', 'second'],
+ ];
$this->throttler
->expects($this->exactly(2))
->method('sleepDelayOrThrowOnMax')
- ->withConsecutive(
- ['::1', 'first'],
- ['::1', 'second'],
- );
+ ->willReturnCallback(function () use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ return 0;
+ });
$controller = new TestController('test', $this->request);
$this->reflector->reflect($controller, 'multipleAttributes');
@@ -221,20 +227,31 @@ class BruteForceMiddlewareTest extends TestCase {
->expects($this->once())
->method('getRemoteAddress')
->willReturn('::1');
+
+ $sleepCalls = [
+ ['::1', 'first'],
+ ['::1', 'second'],
+ ];
$this->throttler
->expects($this->exactly(2))
->method('sleepDelayOrThrowOnMax')
- ->withConsecutive(
- ['::1', 'first'],
- ['::1', 'second'],
- );
+ ->willReturnCallback(function () use (&$sleepCalls) {
+ $expected = array_shift($sleepCalls);
+ $this->assertEquals($expected, func_get_args());
+ return 0;
+ });
+
+ $attemptCalls = [
+ ['first', '::1', []],
+ ['second', '::1', []],
+ ];
$this->throttler
->expects($this->exactly(2))
->method('registerAttempt')
- ->withConsecutive(
- ['first', '::1'],
- ['second', '::1'],
- );
+ ->willReturnCallback(function () use (&$attemptCalls) {
+ $expected = array_shift($attemptCalls);
+ $this->assertEquals($expected, func_get_args());
+ });
$controller = new TestController('test', $this->request);
$this->reflector->reflect($controller, 'multipleAttributes');
diff --git a/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php
index b703b10c554..f22933a5884 100644
--- a/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php
+++ b/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php
@@ -44,7 +44,7 @@ class CORSMiddlewareTest extends \Test\TestCase {
);
}
- public function dataSetCORSAPIHeader(): array {
+ public static function dataSetCORSAPIHeader(): array {
return [
['testSetCORSAPIHeader'],
['testSetCORSAPIHeaderAttribute'],
@@ -89,7 +89,7 @@ class CORSMiddlewareTest extends \Test\TestCase {
$this->assertFalse(array_key_exists('Access-Control-Allow-Origin', $headers));
}
- public function dataNoOriginHeaderNoCORSHEADER(): array {
+ public static function dataNoOriginHeaderNoCORSHEADER(): array {
return [
['testNoOriginHeaderNoCORSHEADER'],
['testNoOriginHeaderNoCORSHEADERAttribute'],
@@ -113,7 +113,7 @@ class CORSMiddlewareTest extends \Test\TestCase {
$this->assertFalse(array_key_exists('Access-Control-Allow-Origin', $headers));
}
- public function dataCorsIgnoredIfWithCredentialsHeaderPresent(): array {
+ public static function dataCorsIgnoredIfWithCredentialsHeaderPresent(): array {
return [
['testCorsIgnoredIfWithCredentialsHeaderPresent'],
['testCorsAttributeIgnoredIfWithCredentialsHeaderPresent'],
@@ -143,7 +143,7 @@ class CORSMiddlewareTest extends \Test\TestCase {
$middleware->afterController($this->controller, $method, $response);
}
- public function dataNoCORSOnAnonymousPublicPage(): array {
+ public static function dataNoCORSOnAnonymousPublicPage(): array {
return [
['testNoCORSOnAnonymousPublicPage'],
['testNoCORSOnAnonymousPublicPageAttribute'],
@@ -177,7 +177,7 @@ class CORSMiddlewareTest extends \Test\TestCase {
$middleware->beforeController($this->controller, $method);
}
- public function dataCORSShouldNeverAllowCookieAuth(): array {
+ public static function dataCORSShouldNeverAllowCookieAuth(): array {
return [
['testCORSShouldNeverAllowCookieAuth'],
['testCORSShouldNeverAllowCookieAuthAttribute'],
@@ -211,7 +211,7 @@ class CORSMiddlewareTest extends \Test\TestCase {
$middleware->beforeController($this->controller, $method);
}
- public function dataCORSShouldRelogin(): array {
+ public static function dataCORSShouldRelogin(): array {
return [
['testCORSShouldRelogin'],
['testCORSAttributeShouldRelogin'],
@@ -242,7 +242,7 @@ class CORSMiddlewareTest extends \Test\TestCase {
$middleware->beforeController($this->controller, $method);
}
- public function dataCORSShouldFailIfPasswordLoginIsForbidden(): array {
+ public static function dataCORSShouldFailIfPasswordLoginIsForbidden(): array {
return [
['testCORSShouldFailIfPasswordLoginIsForbidden'],
['testCORSAttributeShouldFailIfPasswordLoginIsForbidden'],
@@ -275,7 +275,7 @@ class CORSMiddlewareTest extends \Test\TestCase {
$middleware->beforeController($this->controller, $method);
}
- public function dataCORSShouldNotAllowCookieAuth(): array {
+ public static function dataCORSShouldNotAllowCookieAuth(): array {
return [
['testCORSShouldNotAllowCookieAuth'],
['testCORSAttributeShouldNotAllowCookieAuth'],
diff --git a/tests/lib/AppFramework/Middleware/Security/PasswordConfirmationMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/PasswordConfirmationMiddlewareTest.php
index 3dec030d438..e607b19d1ef 100644
--- a/tests/lib/AppFramework/Middleware/Security/PasswordConfirmationMiddlewareTest.php
+++ b/tests/lib/AppFramework/Middleware/Security/PasswordConfirmationMiddlewareTest.php
@@ -162,7 +162,7 @@ class PasswordConfirmationMiddlewareTest extends TestCase {
- public function dataProvider() {
+ public static function dataProvider(): array {
return [
['foo', 2000, 4000, true],
['foo', 2000, 3000, false],
diff --git a/tests/lib/AppFramework/Middleware/Security/SameSiteCookieMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/SameSiteCookieMiddlewareTest.php
index 0ca4a455cba..44897fa21ef 100644
--- a/tests/lib/AppFramework/Middleware/Security/SameSiteCookieMiddlewareTest.php
+++ b/tests/lib/AppFramework/Middleware/Security/SameSiteCookieMiddlewareTest.php
@@ -103,7 +103,7 @@ class SameSiteCookieMiddlewareTest extends TestCase {
$middleware = $this->getMockBuilder(SameSiteCookieMiddleware::class)
->setConstructorArgs([$this->request, $this->reflector])
- ->setMethods(['setSameSiteCookie'])
+ ->onlyMethods(['setSameSiteCookie'])
->getMock();
$middleware->expects($this->once())
diff --git a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php
index 07e368fd1e6..3b5861cbba9 100644
--- a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php
+++ b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php
@@ -125,7 +125,7 @@ class SecurityMiddlewareTest extends \Test\TestCase {
);
}
- public function dataNoCSRFRequiredPublicPage(): array {
+ public static function dataNoCSRFRequiredPublicPage(): array {
return [
['testAnnotationNoCSRFRequiredPublicPage'],
['testAnnotationNoCSRFRequiredAttributePublicPage'],
@@ -134,21 +134,21 @@ class SecurityMiddlewareTest extends \Test\TestCase {
];
}
- public function dataPublicPage(): array {
+ public static function dataPublicPage(): array {
return [
['testAnnotationPublicPage'],
['testAttributePublicPage'],
];
}
- public function dataNoCSRFRequired(): array {
+ public static function dataNoCSRFRequired(): array {
return [
['testAnnotationNoCSRFRequired'],
['testAttributeNoCSRFRequired'],
];
}
- public function dataPublicPageStrictCookieRequired(): array {
+ public static function dataPublicPageStrictCookieRequired(): array {
return [
['testAnnotationPublicPageStrictCookieRequired'],
['testAnnotationStrictCookieRequiredAttributePublicPage'],
@@ -157,28 +157,28 @@ class SecurityMiddlewareTest extends \Test\TestCase {
];
}
- public function dataNoCSRFRequiredPublicPageStrictCookieRequired(): array {
+ public static function dataNoCSRFRequiredPublicPageStrictCookieRequired(): array {
return [
['testAnnotationNoCSRFRequiredPublicPageStrictCookieRequired'],
['testAttributeNoCSRFRequiredPublicPageStrictCookiesRequired'],
];
}
- public function dataNoAdminRequiredNoCSRFRequired(): array {
+ public static function dataNoAdminRequiredNoCSRFRequired(): array {
return [
['testAnnotationNoAdminRequiredNoCSRFRequired'],
['testAttributeNoAdminRequiredNoCSRFRequired'],
];
}
- public function dataNoAdminRequiredNoCSRFRequiredPublicPage(): array {
+ public static function dataNoAdminRequiredNoCSRFRequiredPublicPage(): array {
return [
['testAnnotationNoAdminRequiredNoCSRFRequiredPublicPage'],
['testAttributeNoAdminRequiredNoCSRFRequiredPublicPage'],
];
}
- public function dataNoCSRFRequiredSubAdminRequired(): array {
+ public static function dataNoCSRFRequiredSubAdminRequired(): array {
return [
['testAnnotationNoCSRFRequiredSubAdminRequired'],
['testAnnotationNoCSRFRequiredAttributeSubAdminRequired'],
@@ -429,7 +429,7 @@ class SecurityMiddlewareTest extends \Test\TestCase {
$this->middleware->beforeController($this->controller, $method);
}
- public function dataCsrfOcsController(): array {
+ public static function dataCsrfOcsController(): array {
return [
[NormalController::class, false, false, true],
[NormalController::class, false, true, true],
@@ -659,7 +659,7 @@ class SecurityMiddlewareTest extends \Test\TestCase {
/**
* @return array
*/
- public function exceptionProvider() {
+ public static function exceptionProvider(): array {
return [
[
new AppNotEnabledException(),
diff --git a/tests/lib/AppFramework/OCS/V2ResponseTest.php b/tests/lib/AppFramework/OCS/V2ResponseTest.php
index 97a227418f3..0037763f163 100644
--- a/tests/lib/AppFramework/OCS/V2ResponseTest.php
+++ b/tests/lib/AppFramework/OCS/V2ResponseTest.php
@@ -23,7 +23,7 @@ class V2ResponseTest extends \Test\TestCase {
$this->assertEquals($expected, $response->getStatus());
}
- public function providesStatusCodes(): array {
+ public static function providesStatusCodes(): array {
return [
[Http::STATUS_OK, 200],
[Http::STATUS_BAD_REQUEST, 104],
diff --git a/tests/lib/AppFramework/Routing/RouteParserTest.php b/tests/lib/AppFramework/Routing/RouteParserTest.php
new file mode 100644
index 00000000000..406c5f1f3a5
--- /dev/null
+++ b/tests/lib/AppFramework/Routing/RouteParserTest.php
@@ -0,0 +1,347 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace Test\AppFramework\Routing;
+
+use OC\AppFramework\Routing\RouteParser;
+use Symfony\Component\Routing\Route as RoutingRoute;
+use Symfony\Component\Routing\RouteCollection;
+
+class RouteParserTest extends \Test\TestCase {
+
+ protected RouteParser $parser;
+
+ protected function setUp(): void {
+ $this->parser = new RouteParser();
+ }
+
+ public function testParseRoutes(): void {
+ $routes = ['routes' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET'],
+ ['name' => 'folders#create', 'url' => '/{folderId}/create', 'verb' => 'POST']
+ ]];
+
+ $collection = $this->parser->parseDefaultRoutes($routes, 'app1');
+ $this->assertArrayHasKey('app1.folders.open', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'FoldersController', 'open', route: $collection->get('app1.folders.open'));
+ $this->assertArrayHasKey('app1.folders.create', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/create', 'POST', 'FoldersController', 'create', route: $collection->get('app1.folders.create'));
+ }
+
+ public function testParseRoutesRootApps(): void {
+ $routes = ['routes' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET'],
+ ['name' => 'folders#create', 'url' => '/{folderId}/create', 'verb' => 'POST']
+ ]];
+
+ $collection = $this->parser->parseDefaultRoutes($routes, 'core');
+ $this->assertArrayHasKey('core.folders.open', $collection->all());
+ $this->assertSimpleRoute('/{folderId}/open', 'GET', 'FoldersController', 'open', app: 'core', route: $collection->get('core.folders.open'));
+ $this->assertArrayHasKey('core.folders.create', $collection->all());
+ $this->assertSimpleRoute('/{folderId}/create', 'POST', 'FoldersController', 'create', app: 'core', route: $collection->get('core.folders.create'));
+ }
+
+ public function testParseRoutesWithResources(): void {
+ $routes = ['routes' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET'],
+ ], 'resources' => [
+ 'names' => ['url' => '/names'],
+ 'folder_names' => ['url' => '/folder/names'],
+ ]];
+
+ $collection = $this->parser->parseDefaultRoutes($routes, 'app1');
+ $this->assertArrayHasKey('app1.folders.open', $collection->all());
+ $this->assertSimpleResource('/apps/app1/folder/names', 'folder_names', 'FolderNamesController', 'app1', $collection);
+ $this->assertSimpleResource('/apps/app1/names', 'names', 'NamesController', 'app1', $collection);
+ }
+
+ public function testParseRoutesWithPostfix(): void {
+ $routes = ['routes' => [
+ ['name' => 'folders#update', 'url' => '/{folderId}/update', 'verb' => 'POST'],
+ ['name' => 'folders#update', 'url' => '/{folderId}/update', 'verb' => 'PUT', 'postfix' => '-edit']
+ ]];
+
+ $collection = $this->parser->parseDefaultRoutes($routes, 'app1');
+ $this->assertArrayHasKey('app1.folders.update', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/update', 'POST', 'FoldersController', 'update', route: $collection->get('app1.folders.update'));
+ $this->assertArrayHasKey('app1.folders.update-edit', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/update', 'PUT', 'FoldersController', 'update', route: $collection->get('app1.folders.update-edit'));
+ }
+
+ public function testParseRoutesKebabCaseAction(): void {
+ $routes = ['routes' => [
+ ['name' => 'folders#open_folder', 'url' => '/{folderId}/open', 'verb' => 'GET']
+ ]];
+
+ $collection = $this->parser->parseDefaultRoutes($routes, 'app1');
+ $this->assertArrayHasKey('app1.folders.open_folder', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'FoldersController', 'openFolder', route: $collection->get('app1.folders.open_folder'));
+ }
+
+ public function testParseRoutesKebabCaseController(): void {
+ $routes = ['routes' => [
+ ['name' => 'my_folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET']
+ ]];
+
+ $collection = $this->parser->parseDefaultRoutes($routes, 'app1');
+ $this->assertArrayHasKey('app1.my_folders.open', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'MyFoldersController', 'open', route: $collection->get('app1.my_folders.open'));
+ }
+
+ public function testParseRoutesLowercaseVerb(): void {
+ $routes = ['routes' => [
+ ['name' => 'folders#delete', 'url' => '/{folderId}/delete', 'verb' => 'delete']
+ ]];
+
+ $collection = $this->parser->parseDefaultRoutes($routes, 'app1');
+ $this->assertArrayHasKey('app1.folders.delete', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/delete', 'DELETE', 'FoldersController', 'delete', route: $collection->get('app1.folders.delete'));
+ }
+
+ public function testParseRoutesMissingVerb(): void {
+ $routes = ['routes' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open']
+ ]];
+
+ $collection = $this->parser->parseDefaultRoutes($routes, 'app1');
+ $this->assertArrayHasKey('app1.folders.open', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'FoldersController', 'open', route: $collection->get('app1.folders.open'));
+ }
+
+ public function testParseRoutesWithRequirements(): void {
+ $routes = ['routes' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET', 'requirements' => ['folderId' => '\d+']]
+ ]];
+
+ $collection = $this->parser->parseDefaultRoutes($routes, 'app1');
+ $this->assertArrayHasKey('app1.folders.open', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'FoldersController', 'open', requirements: ['folderId' => '\d+'], route: $collection->get('app1.folders.open'));
+ }
+
+ public function testParseRoutesWithDefaults(): void {
+ $routes = ['routes' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET', 'defaults' => ['hello' => 'world']]
+ ]];
+
+ $collection = $this->parser->parseDefaultRoutes($routes, 'app1');
+ $this->assertArrayHasKey('app1.folders.open', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'FoldersController', 'open', defaults: ['hello' => 'world'], route: $collection->get('app1.folders.open'));
+ }
+
+ public function testParseRoutesInvalidName(): void {
+ $routes = ['routes' => [
+ ['name' => 'folders', 'url' => '/{folderId}/open', 'verb' => 'GET']
+ ]];
+
+ $this->expectException(\UnexpectedValueException::class);
+ $this->parser->parseDefaultRoutes($routes, 'app1');
+ }
+
+ public function testParseRoutesInvalidName2(): void {
+ $routes = ['routes' => [
+ ['name' => 'folders#open#action', 'url' => '/{folderId}/open', 'verb' => 'GET']
+ ]];
+
+ $this->expectException(\UnexpectedValueException::class);
+ $this->parser->parseDefaultRoutes($routes, 'app1');
+ }
+
+ public function testParseRoutesEmpty(): void {
+ $routes = ['routes' => []];
+
+ $collection = $this->parser->parseDefaultRoutes($routes, 'app1');
+ $this->assertEquals(0, $collection->count());
+ }
+
+ // OCS routes
+
+ public function testParseOcsRoutes(): void {
+ $routes = ['ocs' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET'],
+ ['name' => 'folders#create', 'url' => '/{folderId}/create', 'verb' => 'POST']
+ ]];
+
+ $collection = $this->parser->parseOCSRoutes($routes, 'app1');
+ $this->assertArrayHasKey('ocs.app1.folders.open', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'FoldersController', 'open', route: $collection->get('ocs.app1.folders.open'));
+ $this->assertArrayHasKey('ocs.app1.folders.create', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/create', 'POST', 'FoldersController', 'create', route: $collection->get('ocs.app1.folders.create'));
+ }
+
+ public function testParseOcsRoutesRootApps(): void {
+ $routes = ['ocs' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET'],
+ ['name' => 'folders#create', 'url' => '/{folderId}/create', 'verb' => 'POST']
+ ]];
+
+ $collection = $this->parser->parseOCSRoutes($routes, 'core');
+ $this->assertArrayHasKey('ocs.core.folders.open', $collection->all());
+ $this->assertSimpleRoute('/{folderId}/open', 'GET', 'FoldersController', 'open', app: 'core', route: $collection->get('ocs.core.folders.open'));
+ $this->assertArrayHasKey('ocs.core.folders.create', $collection->all());
+ $this->assertSimpleRoute('/{folderId}/create', 'POST', 'FoldersController', 'create', app: 'core', route: $collection->get('ocs.core.folders.create'));
+ }
+
+ public function testParseOcsRoutesWithPostfix(): void {
+ $routes = ['ocs' => [
+ ['name' => 'folders#update', 'url' => '/{folderId}/update', 'verb' => 'POST'],
+ ['name' => 'folders#update', 'url' => '/{folderId}/update', 'verb' => 'PUT', 'postfix' => '-edit']
+ ]];
+
+ $collection = $this->parser->parseOCSRoutes($routes, 'app1');
+ $this->assertArrayHasKey('ocs.app1.folders.update', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/update', 'POST', 'FoldersController', 'update', route: $collection->get('ocs.app1.folders.update'));
+ $this->assertArrayHasKey('ocs.app1.folders.update-edit', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/update', 'PUT', 'FoldersController', 'update', route: $collection->get('ocs.app1.folders.update-edit'));
+ }
+
+ public function testParseOcsRoutesKebabCaseAction(): void {
+ $routes = ['ocs' => [
+ ['name' => 'folders#open_folder', 'url' => '/{folderId}/open', 'verb' => 'GET']
+ ]];
+
+ $collection = $this->parser->parseOCSRoutes($routes, 'app1');
+ $this->assertArrayHasKey('ocs.app1.folders.open_folder', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'FoldersController', 'openFolder', route: $collection->get('ocs.app1.folders.open_folder'));
+ }
+
+ public function testParseOcsRoutesKebabCaseController(): void {
+ $routes = ['ocs' => [
+ ['name' => 'my_folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET']
+ ]];
+
+ $collection = $this->parser->parseOCSRoutes($routes, 'app1');
+ $this->assertArrayHasKey('ocs.app1.my_folders.open', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'MyFoldersController', 'open', route: $collection->get('ocs.app1.my_folders.open'));
+ }
+
+ public function testParseOcsRoutesLowercaseVerb(): void {
+ $routes = ['ocs' => [
+ ['name' => 'folders#delete', 'url' => '/{folderId}/delete', 'verb' => 'delete']
+ ]];
+
+ $collection = $this->parser->parseOCSRoutes($routes, 'app1');
+ $this->assertArrayHasKey('ocs.app1.folders.delete', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/delete', 'DELETE', 'FoldersController', 'delete', route: $collection->get('ocs.app1.folders.delete'));
+ }
+
+ public function testParseOcsRoutesMissingVerb(): void {
+ $routes = ['ocs' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open']
+ ]];
+
+ $collection = $this->parser->parseOCSRoutes($routes, 'app1');
+ $this->assertArrayHasKey('ocs.app1.folders.open', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'FoldersController', 'open', route: $collection->get('ocs.app1.folders.open'));
+ }
+
+ public function testParseOcsRoutesWithRequirements(): void {
+ $routes = ['ocs' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET', 'requirements' => ['folderId' => '\d+']]
+ ]];
+
+ $collection = $this->parser->parseOCSRoutes($routes, 'app1');
+ $this->assertArrayHasKey('ocs.app1.folders.open', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'FoldersController', 'open', requirements: ['folderId' => '\d+'], route: $collection->get('ocs.app1.folders.open'));
+ }
+
+ public function testParseOcsRoutesWithDefaults(): void {
+ $routes = ['ocs' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET', 'defaults' => ['hello' => 'world']]
+ ]];
+
+ $collection = $this->parser->parseOCSRoutes($routes, 'app1');
+ $this->assertArrayHasKey('ocs.app1.folders.open', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'FoldersController', 'open', defaults: ['hello' => 'world'], route: $collection->get('ocs.app1.folders.open'));
+ }
+
+ public function testParseOcsRoutesInvalidName(): void {
+ $routes = ['ocs' => [
+ ['name' => 'folders', 'url' => '/{folderId}/open', 'verb' => 'GET']
+ ]];
+
+ $this->expectException(\UnexpectedValueException::class);
+ $this->parser->parseOCSRoutes($routes, 'app1');
+ }
+
+ public function testParseOcsRoutesEmpty(): void {
+ $routes = ['ocs' => []];
+
+ $collection = $this->parser->parseOCSRoutes($routes, 'app1');
+ $this->assertEquals(0, $collection->count());
+ }
+
+ public function testParseOcsRoutesWithResources(): void {
+ $routes = ['ocs' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET'],
+ ], 'ocs-resources' => [
+ 'names' => ['url' => '/names', 'root' => '/core/something'],
+ 'folder_names' => ['url' => '/folder/names'],
+ ]];
+
+ $collection = $this->parser->parseOCSRoutes($routes, 'app1');
+ $this->assertArrayHasKey('ocs.app1.folders.open', $collection->all());
+ $this->assertOcsResource('/apps/app1/folder/names', 'folder_names', 'FolderNamesController', 'app1', $collection);
+ $this->assertOcsResource('/core/something/names', 'names', 'NamesController', 'app1', $collection);
+ }
+
+ protected function assertSimpleRoute(
+ string $path,
+ string $method,
+ string $controller,
+ string $action,
+ string $app = 'app1',
+ array $requirements = [],
+ array $defaults = [],
+ ?RoutingRoute $route = null,
+ ): void {
+ self::assertEquals($path, $route->getPath());
+ self::assertEqualsCanonicalizing([$method], $route->getMethods());
+ self::assertEqualsCanonicalizing($requirements, $route->getRequirements());
+ self::assertEquals([...$defaults, 'action' => null, 'caller' => [$app, $controller, $action]], $route->getDefaults());
+ }
+
+ protected function assertSimpleResource(
+ string $path,
+ string $resourceName,
+ string $controller,
+ string $app,
+ RouteCollection $collection,
+ ): void {
+ self::assertArrayHasKey("$app.$resourceName.index", $collection->all());
+ self::assertArrayHasKey("$app.$resourceName.show", $collection->all());
+ self::assertArrayHasKey("$app.$resourceName.create", $collection->all());
+ self::assertArrayHasKey("$app.$resourceName.update", $collection->all());
+ self::assertArrayHasKey("$app.$resourceName.destroy", $collection->all());
+
+ $this->assertSimpleRoute($path, 'GET', $controller, 'index', $app, route: $collection->get("$app.$resourceName.index"));
+ $this->assertSimpleRoute($path, 'POST', $controller, 'create', $app, route: $collection->get("$app.$resourceName.create"));
+ $this->assertSimpleRoute("$path/{id}", 'GET', $controller, 'show', $app, route: $collection->get("$app.$resourceName.show"));
+ $this->assertSimpleRoute("$path/{id}", 'PUT', $controller, 'update', $app, route: $collection->get("$app.$resourceName.update"));
+ $this->assertSimpleRoute("$path/{id}", 'DELETE', $controller, 'destroy', $app, route: $collection->get("$app.$resourceName.destroy"));
+ }
+
+ protected function assertOcsResource(
+ string $path,
+ string $resourceName,
+ string $controller,
+ string $app,
+ RouteCollection $collection,
+ ): void {
+ self::assertArrayHasKey("ocs.$app.$resourceName.index", $collection->all());
+ self::assertArrayHasKey("ocs.$app.$resourceName.show", $collection->all());
+ self::assertArrayHasKey("ocs.$app.$resourceName.create", $collection->all());
+ self::assertArrayHasKey("ocs.$app.$resourceName.update", $collection->all());
+ self::assertArrayHasKey("ocs.$app.$resourceName.destroy", $collection->all());
+
+ $this->assertSimpleRoute($path, 'GET', $controller, 'index', $app, route: $collection->get("ocs.$app.$resourceName.index"));
+ $this->assertSimpleRoute($path, 'POST', $controller, 'create', $app, route: $collection->get("ocs.$app.$resourceName.create"));
+ $this->assertSimpleRoute("$path/{id}", 'GET', $controller, 'show', $app, route: $collection->get("ocs.$app.$resourceName.show"));
+ $this->assertSimpleRoute("$path/{id}", 'PUT', $controller, 'update', $app, route: $collection->get("ocs.$app.$resourceName.update"));
+ $this->assertSimpleRoute("$path/{id}", 'DELETE', $controller, 'destroy', $app, route: $collection->get("ocs.$app.$resourceName.destroy"));
+ }
+}
diff --git a/tests/lib/AppFramework/Routing/RoutingTest.php b/tests/lib/AppFramework/Routing/RoutingTest.php
deleted file mode 100644
index 8522382ddcc..00000000000
--- a/tests/lib/AppFramework/Routing/RoutingTest.php
+++ /dev/null
@@ -1,476 +0,0 @@
-<?php
-/**
- * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
- * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-namespace Test\AppFramework\Routing;
-
-use OC\AppFramework\DependencyInjection\DIContainer;
-use OC\AppFramework\Routing\RouteConfig;
-use OC\Route\Route;
-use OC\Route\Router;
-use OCP\App\IAppManager;
-use OCP\Diagnostics\IEventLogger;
-use OCP\IConfig;
-use OCP\IRequest;
-use OCP\Route\IRouter;
-use PHPUnit\Framework\MockObject\MockObject;
-use Psr\Container\ContainerInterface;
-use Psr\Log\LoggerInterface;
-
-class RoutingTest extends \Test\TestCase {
- public function testSimpleRoute(): void {
- $routes = ['routes' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'GET']
- ]];
-
- $this->assertSimpleRoute($routes, 'folders.open', 'GET', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open');
- }
-
- public function testSimpleRouteWithUnderScoreNames(): void {
- $routes = ['routes' => [
- ['name' => 'admin_folders#open_current', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', 'root' => '']
- ]];
-
- $this->assertSimpleRoute($routes, 'admin_folders.open_current', 'DELETE', '/folders/{folderId}/open', 'AdminFoldersController', 'openCurrent', [], [], '', true);
- }
-
- public function testSimpleOCSRoute(): void {
- $routes = ['ocs' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'GET']
- ]
- ];
-
- $this->assertSimpleOCSRoute($routes, 'folders.open', 'GET', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open');
- }
-
- public function testSimpleRouteWithMissingVerb(): void {
- $routes = ['routes' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open']
- ]];
-
- $this->assertSimpleRoute($routes, 'folders.open', 'GET', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open');
- }
-
- public function testSimpleOCSRouteWithMissingVerb(): void {
- $routes = ['ocs' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open']
- ]
- ];
-
- $this->assertSimpleOCSRoute($routes, 'folders.open', 'GET', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open');
- }
-
- public function testSimpleRouteWithLowercaseVerb(): void {
- $routes = ['routes' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete']
- ]];
-
- $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open');
- }
-
- public function testSimpleOCSRouteWithLowercaseVerb(): void {
- $routes = ['ocs' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete']
- ]
- ];
-
- $this->assertSimpleOCSRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open');
- }
-
- public function testSimpleRouteWithRequirements(): void {
- $routes = ['routes' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', 'requirements' => ['something']]
- ]];
-
- $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', ['something']);
- }
-
- public function testSimpleOCSRouteWithRequirements(): void {
- $routes = ['ocs' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', 'requirements' => ['something']]
- ]
- ];
-
- $this->assertSimpleOCSRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', ['something']);
- }
-
- public function testSimpleRouteWithDefaults(): void {
- $routes = ['routes' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', [], 'defaults' => ['param' => 'foobar']]
- ]];
-
- $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', [], ['param' => 'foobar']);
- }
-
-
- public function testSimpleOCSRouteWithDefaults(): void {
- $routes = ['ocs' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', 'defaults' => ['param' => 'foobar']]
- ]
- ];
-
- $this->assertSimpleOCSRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', [], ['param' => 'foobar']);
- }
-
- public function testSimpleRouteWithPostfix(): void {
- $routes = ['routes' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', 'postfix' => '_something']
- ]];
-
- $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', [], [], '_something');
- }
-
- public function testSimpleOCSRouteWithPostfix(): void {
- $routes = ['ocs' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', 'postfix' => '_something']
- ]
- ];
-
- $this->assertSimpleOCSRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', [], [], '_something');
- }
-
-
- public function testSimpleRouteWithBrokenName(): void {
- $this->expectException(\UnexpectedValueException::class);
-
- $routes = ['routes' => [
- ['name' => 'folders_open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete']
- ]];
-
- /** @var IRouter|MockObject $router */
- $router = $this->getMockBuilder(Router::class)
- ->onlyMethods(['create'])
- ->setConstructorArgs([
- $this->createMock(LoggerInterface::class),
- $this->createMock(IRequest::class),
- $this->createMock(IConfig::class),
- $this->createMock(IEventLogger::class),
- $this->createMock(ContainerInterface::class),
- $this->createMock(IAppManager::class),
- ])
- ->getMock();
-
- // load route configuration
- $container = new DIContainer('app1');
- $config = new RouteConfig($container, $router, $routes);
-
- $config->register();
- }
-
-
- public function testSimpleOCSRouteWithBrokenName(): void {
- $this->expectException(\UnexpectedValueException::class);
-
- $routes = ['ocs' => [
- ['name' => 'folders_open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete']
- ]];
-
- /** @var IRouter|MockObject $router */
- $router = $this->getMockBuilder(Router::class)
- ->onlyMethods(['create'])
- ->setConstructorArgs([
- $this->createMock(LoggerInterface::class),
- $this->createMock(IRequest::class),
- $this->createMock(IConfig::class),
- $this->createMock(IEventLogger::class),
- $this->createMock(ContainerInterface::class),
- $this->createMock(IAppManager::class),
- ])
- ->getMock();
-
- // load route configuration
- $container = new DIContainer('app1');
- $config = new RouteConfig($container, $router, $routes);
-
- $config->register();
- }
-
- public function testSimpleOCSRouteWithUnderScoreNames(): void {
- $routes = ['ocs' => [
- ['name' => 'admin_folders#open_current', 'url' => '/folders/{folderId}/open', 'verb' => 'delete']
- ]];
-
- $this->assertSimpleOCSRoute($routes, 'admin_folders.open_current', 'DELETE', '/apps/app1/folders/{folderId}/open', 'AdminFoldersController', 'openCurrent');
- }
-
- public function testOCSResource(): void {
- $routes = ['ocs-resources' => ['account' => ['url' => '/accounts']]];
-
- $this->assertOCSResource($routes, 'account', '/apps/app1/accounts', 'AccountController', 'id');
- }
-
- public function testOCSResourceWithUnderScoreName(): void {
- $routes = ['ocs-resources' => ['admin_accounts' => ['url' => '/admin/accounts']]];
-
- $this->assertOCSResource($routes, 'admin_accounts', '/apps/app1/admin/accounts', 'AdminAccountsController', 'id');
- }
-
- public function testOCSResourceWithRoot(): void {
- $routes = ['ocs-resources' => ['admin_accounts' => ['url' => '/admin/accounts', 'root' => '/core/endpoint']]];
-
- $this->assertOCSResource($routes, 'admin_accounts', '/core/endpoint/admin/accounts', 'AdminAccountsController', 'id');
- }
-
- public function testResource(): void {
- $routes = ['resources' => ['account' => ['url' => '/accounts']]];
-
- $this->assertResource($routes, 'account', '/apps/app1/accounts', 'AccountController', 'id');
- }
-
- public function testResourceWithUnderScoreName(): void {
- $routes = ['resources' => ['admin_accounts' => ['url' => '/admin/accounts']]];
-
- $this->assertResource($routes, 'admin_accounts', '/apps/app1/admin/accounts', 'AdminAccountsController', 'id');
- }
-
- private function assertSimpleRoute($routes, $name, $verb, $url, $controllerName, $actionName, array $requirements = [], array $defaults = [], $postfix = '', $allowRootUrl = false): void {
- if ($postfix) {
- $name .= $postfix;
- }
-
- // route mocks
- $container = new DIContainer('app1');
- $route = $this->mockRoute($container, $verb, $controllerName, $actionName, $requirements, $defaults);
-
- /** @var IRouter|MockObject $router */
- $router = $this->getMockBuilder(Router::class)
- ->onlyMethods(['create'])
- ->setConstructorArgs([
- $this->createMock(LoggerInterface::class),
- $this->createMock(IRequest::class),
- $this->createMock(IConfig::class),
- $this->createMock(IEventLogger::class),
- $this->createMock(ContainerInterface::class),
- $this->createMock(IAppManager::class),
- ])
- ->getMock();
-
- // we expect create to be called once:
- $router
- ->expects($this->once())
- ->method('create')
- ->with($this->equalTo('app1.' . $name), $this->equalTo($url))
- ->willReturn($route);
-
- // load route configuration
- $config = new RouteConfig($container, $router, $routes);
- if ($allowRootUrl) {
- self::invokePrivate($config, 'rootUrlApps', [['app1']]);
- }
-
- $config->register();
- }
-
- /**
- * @param $routes
- * @param string $name
- * @param string $verb
- * @param string $url
- * @param string $controllerName
- * @param string $actionName
- * @param array $requirements
- * @param array $defaults
- * @param string $postfix
- */
- private function assertSimpleOCSRoute($routes,
- $name,
- $verb,
- $url,
- $controllerName,
- $actionName,
- array $requirements = [],
- array $defaults = [],
- $postfix = '') {
- if ($postfix) {
- $name .= $postfix;
- }
-
- // route mocks
- $container = new DIContainer('app1');
- $route = $this->mockRoute($container, $verb, $controllerName, $actionName, $requirements, $defaults);
-
- /** @var IRouter|MockObject $router */
- $router = $this->getMockBuilder(Router::class)
- ->onlyMethods(['create'])
- ->setConstructorArgs([
- $this->createMock(LoggerInterface::class),
- $this->createMock(IRequest::class),
- $this->createMock(IConfig::class),
- $this->createMock(IEventLogger::class),
- $this->createMock(ContainerInterface::class),
- $this->createMock(IAppManager::class),
- ])
- ->getMock();
-
- // we expect create to be called once:
- $router
- ->expects($this->once())
- ->method('create')
- ->with($this->equalTo('ocs.app1.' . $name), $this->equalTo($url))
- ->willReturn($route);
-
- // load route configuration
- $config = new RouteConfig($container, $router, $routes);
-
- $config->register();
- }
-
- /**
- * @param array $yaml
- * @param string $resourceName
- * @param string $url
- * @param string $controllerName
- * @param string $paramName
- */
- private function assertOCSResource($yaml, $resourceName, $url, $controllerName, $paramName): void {
- /** @var IRouter|MockObject $router */
- $router = $this->getMockBuilder(Router::class)
- ->onlyMethods(['create'])
- ->setConstructorArgs([
- $this->createMock(LoggerInterface::class),
- $this->createMock(IRequest::class),
- $this->createMock(IConfig::class),
- $this->createMock(IEventLogger::class),
- $this->createMock(ContainerInterface::class),
- $this->createMock(IAppManager::class),
- ])
- ->getMock();
-
- // route mocks
- $container = new DIContainer('app1');
- $indexRoute = $this->mockRoute($container, 'GET', $controllerName, 'index');
- $showRoute = $this->mockRoute($container, 'GET', $controllerName, 'show');
- $createRoute = $this->mockRoute($container, 'POST', $controllerName, 'create');
- $updateRoute = $this->mockRoute($container, 'PUT', $controllerName, 'update');
- $destroyRoute = $this->mockRoute($container, 'DELETE', $controllerName, 'destroy');
-
- $urlWithParam = $url . '/{' . $paramName . '}';
-
- // we expect create to be called five times:
- $router
- ->expects($this->exactly(5))
- ->method('create')
- ->withConsecutive(
- [$this->equalTo('ocs.app1.' . $resourceName . '.index'), $this->equalTo($url)],
- [$this->equalTo('ocs.app1.' . $resourceName . '.show'), $this->equalTo($urlWithParam)],
- [$this->equalTo('ocs.app1.' . $resourceName . '.create'), $this->equalTo($url)],
- [$this->equalTo('ocs.app1.' . $resourceName . '.update'), $this->equalTo($urlWithParam)],
- [$this->equalTo('ocs.app1.' . $resourceName . '.destroy'), $this->equalTo($urlWithParam)],
- )->willReturnOnConsecutiveCalls(
- $indexRoute,
- $showRoute,
- $createRoute,
- $updateRoute,
- $destroyRoute,
- );
-
- // load route configuration
- $config = new RouteConfig($container, $router, $yaml);
-
- $config->register();
- }
-
- /**
- * @param string $resourceName
- * @param string $url
- * @param string $controllerName
- * @param string $paramName
- */
- private function assertResource($yaml, $resourceName, $url, $controllerName, $paramName) {
- /** @var IRouter|MockObject $router */
- $router = $this->getMockBuilder(Router::class)
- ->onlyMethods(['create'])
- ->setConstructorArgs([
- $this->createMock(LoggerInterface::class),
- $this->createMock(IRequest::class),
- $this->createMock(IConfig::class),
- $this->createMock(IEventLogger::class),
- $this->createMock(ContainerInterface::class),
- $this->createMock(IAppManager::class),
- ])
- ->getMock();
-
- // route mocks
- $container = new DIContainer('app1');
- $indexRoute = $this->mockRoute($container, 'GET', $controllerName, 'index');
- $showRoute = $this->mockRoute($container, 'GET', $controllerName, 'show');
- $createRoute = $this->mockRoute($container, 'POST', $controllerName, 'create');
- $updateRoute = $this->mockRoute($container, 'PUT', $controllerName, 'update');
- $destroyRoute = $this->mockRoute($container, 'DELETE', $controllerName, 'destroy');
-
- $urlWithParam = $url . '/{' . $paramName . '}';
-
- // we expect create to be called five times:
- $router
- ->expects($this->exactly(5))
- ->method('create')
- ->withConsecutive(
- [$this->equalTo('app1.' . $resourceName . '.index'), $this->equalTo($url)],
- [$this->equalTo('app1.' . $resourceName . '.show'), $this->equalTo($urlWithParam)],
- [$this->equalTo('app1.' . $resourceName . '.create'), $this->equalTo($url)],
- [$this->equalTo('app1.' . $resourceName . '.update'), $this->equalTo($urlWithParam)],
- [$this->equalTo('app1.' . $resourceName . '.destroy'), $this->equalTo($urlWithParam)],
- )->willReturnOnConsecutiveCalls(
- $indexRoute,
- $showRoute,
- $createRoute,
- $updateRoute,
- $destroyRoute,
- );
-
- // load route configuration
- $config = new RouteConfig($container, $router, $yaml);
-
- $config->register();
- }
-
- /**
- * @param DIContainer $container
- * @param string $verb
- * @param string $controllerName
- * @param string $actionName
- * @param array $requirements
- * @param array $defaults
- * @return MockObject
- */
- private function mockRoute(
- DIContainer $container,
- $verb,
- $controllerName,
- $actionName,
- array $requirements = [],
- array $defaults = [],
- ) {
- $route = $this->getMockBuilder(Route::class)
- ->onlyMethods(['method', 'requirements', 'defaults'])
- ->disableOriginalConstructor()
- ->getMock();
- $route
- ->expects($this->once())
- ->method('method')
- ->with($this->equalTo($verb))
- ->willReturn($route);
-
- if (count($requirements) > 0) {
- $route
- ->expects($this->once())
- ->method('requirements')
- ->with($this->equalTo($requirements))
- ->willReturn($route);
- }
-
- $route->expects($this->once())
- ->method('defaults')
- ->with($this->callback(function (array $def) use ($defaults, $controllerName, $actionName) {
- $defaults['caller'] = ['app1', $controllerName, $actionName];
-
- $this->assertEquals($defaults, $def);
- return true;
- }))
- ->willReturn($route);
-
- return $route;
- }
-}
diff --git a/tests/lib/AppFramework/Services/AppConfigTest.php b/tests/lib/AppFramework/Services/AppConfigTest.php
index 46f73a8c088..718817a7636 100644
--- a/tests/lib/AppFramework/Services/AppConfigTest.php
+++ b/tests/lib/AppFramework/Services/AppConfigTest.php
@@ -28,7 +28,7 @@ class AppConfigTest extends TestCase {
parent::setUp();
$this->config = $this->createMock(IConfig::class);
$this->appConfigCore = $this->createMock(AppConfigCore::class);
-
+
$this->appConfig = new AppConfig($this->config, $this->appConfigCore, self::TEST_APPID);
}
@@ -46,7 +46,7 @@ class AppConfigTest extends TestCase {
* @return array
* @see testHasAppKey
*/
- public function providerHasAppKey(): array {
+ public static function providerHasAppKey(): array {
return [
// lazy, expected
[false, true],
@@ -76,7 +76,7 @@ class AppConfigTest extends TestCase {
* @return array
* @see testIsSensitive
*/
- public function providerIsSensitive(): array {
+ public static function providerIsSensitive(): array {
return [
// lazy, expected
[false, true],
@@ -123,7 +123,7 @@ class AppConfigTest extends TestCase {
* @return array
* @see testIsLazy
*/
- public function providerIsLazy(): array {
+ public static function providerIsLazy(): array {
return [
// expected
[true],
@@ -161,7 +161,7 @@ class AppConfigTest extends TestCase {
* @return array
* @see testGetAllAppValues
*/
- public function providerGetAllAppValues(): array {
+ public static function providerGetAllAppValues(): array {
return [
// key, filtered
['', false],
@@ -214,7 +214,7 @@ class AppConfigTest extends TestCase {
* @see testSetAppValueArray
* @see testSetAppValueArrayException
*/
- public function providerSetAppValue(): array {
+ public static function providerSetAppValue(): array {
return [
// lazy, sensitive, expected
[false, false, true],
@@ -340,7 +340,7 @@ class AppConfigTest extends TestCase {
* @return array
* @see testSetAppValueBool
*/
- public function providerSetAppValueBool(): array {
+ public static function providerSetAppValueBool(): array {
return [
// lazy, expected
[false, true],
@@ -456,7 +456,7 @@ class AppConfigTest extends TestCase {
* @see testGetAppValueArray
* @see testGetAppValueArrayException
*/
- public function providerGetAppValue(): array {
+ public static function providerGetAppValue(): array {
return [
// lazy, exist
[false, false],
diff --git a/tests/lib/AppFramework/Utility/SimpleContainerTest.php b/tests/lib/AppFramework/Utility/SimpleContainerTest.php
index d3e9dec18e0..754da8e5fb3 100644
--- a/tests/lib/AppFramework/Utility/SimpleContainerTest.php
+++ b/tests/lib/AppFramework/Utility/SimpleContainerTest.php
@@ -191,7 +191,7 @@ class SimpleContainerTest extends \Test\TestCase {
$this->container->query('test'), $this->container->query('test1'));
}
- public function sanitizeNameProvider() {
+ public static function sanitizeNameProvider(): array {
return [
['ABC\\Foo', 'ABC\\Foo'],
['\\ABC\\Foo', '\\ABC\\Foo'],