diff options
Diffstat (limited to 'tests/lib/UrlGeneratorTest.php')
-rw-r--r-- | tests/lib/UrlGeneratorTest.php | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/tests/lib/UrlGeneratorTest.php b/tests/lib/UrlGeneratorTest.php index ed7b797d809..4320efc4190 100644 --- a/tests/lib/UrlGeneratorTest.php +++ b/tests/lib/UrlGeneratorTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -8,6 +9,7 @@ namespace Test; use OC\Route\Router; +use OC\URLGenerator; use OCP\ICacheFactory; use OCP\IConfig; use OCP\IRequest; @@ -42,7 +44,7 @@ class UrlGeneratorTest extends \Test\TestCase { $this->cacheFactory = $this->createMock(ICacheFactory::class); $this->request = $this->createMock(IRequest::class); $this->router = $this->createMock(Router::class); - $this->urlGenerator = new \OC\URLGenerator( + $this->urlGenerator = new URLGenerator( $this->config, $this->userSession, $this->cacheFactory, @@ -69,8 +71,8 @@ class UrlGeneratorTest extends \Test\TestCase { /** * @small * test linkTo URL construction - * @dataProvider provideDocRootAppUrlParts */ + #[\PHPUnit\Framework\Attributes\DataProvider('provideDocRootAppUrlParts')] public function testLinkToDocRoot($app, $file, $args, $expectedResult): void { \OC::$WEBROOT = ''; $result = $this->urlGenerator->linkTo($app, $file, $args); @@ -80,17 +82,15 @@ class UrlGeneratorTest extends \Test\TestCase { /** * @small * test linkTo URL construction in sub directory - * @dataProvider provideSubDirAppUrlParts */ + #[\PHPUnit\Framework\Attributes\DataProvider('provideSubDirAppUrlParts')] public function testLinkToSubDir($app, $file, $args, $expectedResult): void { \OC::$WEBROOT = '/nextcloud'; $result = $this->urlGenerator->linkTo($app, $file, $args); $this->assertEquals($expectedResult, $result); } - /** - * @dataProvider provideRoutes - */ + #[\PHPUnit\Framework\Attributes\DataProvider('provideRoutes')] public function testLinkToRouteAbsolute($route, $expected): void { $this->mockBaseUrl(); \OC::$WEBROOT = '/nextcloud'; @@ -107,14 +107,14 @@ class UrlGeneratorTest extends \Test\TestCase { $this->assertEquals($expected, $result); } - public static function provideRoutes() { + public static function provideRoutes(): array { return [ ['core.Preview.getPreview', 'http://localhost/nextcloud/index.php/core/preview.png'], ['cloud_federation_api.requesthandlercontroller.addShare', 'http://localhost/nextcloud/index.php/ocm/shares'], ]; } - public static function provideDocRootAppUrlParts() { + public static function provideDocRootAppUrlParts(): array { return [ ['files_external', 'ajax/oauth2.php', [], '/index.php/apps/files_external/ajax/oauth2.php'], ['files_external', 'ajax/oauth2.php', ['trut' => 'trat', 'dut' => 'dat'], '/index.php/apps/files_external/ajax/oauth2.php?trut=trat&dut=dat'], @@ -122,7 +122,7 @@ class UrlGeneratorTest extends \Test\TestCase { ]; } - public static function provideSubDirAppUrlParts() { + public static function provideSubDirAppUrlParts(): array { return [ ['files_external', 'ajax/oauth2.php', [], '/nextcloud/index.php/apps/files_external/ajax/oauth2.php'], ['files_external', 'ajax/oauth2.php', ['trut' => 'trat', 'dut' => 'dat'], '/nextcloud/index.php/apps/files_external/ajax/oauth2.php?trut=trat&dut=dat'], @@ -133,8 +133,8 @@ class UrlGeneratorTest extends \Test\TestCase { /** * @small * test absolute URL construction - * @dataProvider provideDocRootURLs */ + #[\PHPUnit\Framework\Attributes\DataProvider('provideDocRootURLs')] public function testGetAbsoluteURLDocRoot($url, $expectedResult): void { $this->mockBaseUrl(); \OC::$WEBROOT = ''; @@ -145,8 +145,8 @@ class UrlGeneratorTest extends \Test\TestCase { /** * @small * test absolute URL construction - * @dataProvider provideSubDirURLs */ + #[\PHPUnit\Framework\Attributes\DataProvider('provideSubDirURLs')] public function testGetAbsoluteURLSubDir($url, $expectedResult): void { $this->mockBaseUrl(); \OC::$WEBROOT = '/nextcloud'; @@ -154,7 +154,7 @@ class UrlGeneratorTest extends \Test\TestCase { $this->assertEquals($expectedResult, $result); } - public function provideDocRootURLs() { + public static function provideDocRootURLs(): array { return [ ['index.php', 'http://localhost/index.php'], ['/index.php', 'http://localhost/index.php'], @@ -163,7 +163,7 @@ class UrlGeneratorTest extends \Test\TestCase { ]; } - public function provideSubDirURLs() { + public static function provideSubDirURLs(): array { return [ ['', 'http://localhost/nextcloud/'], ['/', 'http://localhost/nextcloud/'], @@ -188,9 +188,7 @@ class UrlGeneratorTest extends \Test\TestCase { $this->assertEquals(\OC::$WEBROOT, $actual); } - /** - * @dataProvider provideOCSRoutes - */ + #[\PHPUnit\Framework\Attributes\DataProvider('provideOCSRoutes')] public function testLinkToOCSRouteAbsolute(string $route, bool $ignoreFrontController, string $expected): void { $this->mockBaseUrl(); \OC::$WEBROOT = '/nextcloud'; @@ -213,7 +211,7 @@ class UrlGeneratorTest extends \Test\TestCase { $this->assertEquals($expected, $result); } - public function provideOCSRoutes(): array { + public static function provideOCSRoutes(): array { return [ ['core.OCS.getCapabilities', false, 'http://localhost/nextcloud/ocs/v2.php/cloud/capabilities'], ['core.OCS.getCapabilities', true, 'http://localhost/nextcloud/ocs/v2.php/cloud/capabilities'], @@ -268,16 +266,14 @@ class UrlGeneratorTest extends \Test\TestCase { $this->assertSame('http://localhost' . \OC::$WEBROOT . '/apps/dashboard/', $this->urlGenerator->linkToDefaultPageUrl()); } - public function imagePathProvider(): array { + public static function imagePathProvider(): array { return [ ['core', 'favicon-mask.svg', \OC::$WEBROOT . '/core/img/favicon-mask.svg'], ['files', 'folder.svg', \OC::$WEBROOT . '/apps/files/img/folder.svg'], ]; } - /** - * @dataProvider imagePathProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('imagePathProvider')] public function testImagePath(string $appName, string $file, string $result): void { $this->assertSame($result, $this->urlGenerator->imagePath($appName, $file)); } |