ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
URIBuilderTest.php
Go to the documentation of this file.
1<?php
2
19namespace ILIAS\StaticURL\Tests;
20
21use PHPUnit\Framework\Attributes\DataProvider;
26
27require_once "Base.php";
28
32class URIBuilderTest extends Base
33{
34 public static function getILIAS_HTTP_Paths(): \Iterator
35 {
36 yield ['https://ilias.de/ilias', 'https://ilias.de/ilias'];
37 yield ['https://ilias.de/ilias/', 'https://ilias.de/ilias'];
38 yield ['http://ilias.de/ilias', 'http://ilias.de/ilias'];
39 yield ['https://test9.ilias.de/goto.php', 'https://test9.ilias.de'];
40 yield ['https://test9.ilias.de/goto.php/', 'https://test9.ilias.de'];
41 yield ['https://test9.ilias.de/goto.php/wiki', 'https://test9.ilias.de'];
42 yield ['https://test9.ilias.de/goto.php/wiki/22', 'https://test9.ilias.de'];
43 yield ['http://test9.ilias.de/goto.php', 'http://test9.ilias.de'];
44 yield ['http://test9.ilias.de/go/hello', 'http://test9.ilias.de'];
45 yield ['http://test9.ilias.de/go/hello', 'http://test9.ilias.de'];
46 yield ['http://test9.ilias.de/Customizing/plugins/Services/index.php', 'http://test9.ilias.de'];
47 }
48
49 #[DataProvider('getILIAS_HTTP_Paths')]
50 public function testBaseURI(string $ILIAS_HTTP_PATH, string $expected): void
51 {
52 $uri_builder = new StandardURIBuilder(
53 $this->getConfig($ILIAS_HTTP_PATH)
54 );
55 $this->assertSame($expected, (string) $uri_builder->getBaseURI());
56 }
57
58 public static function getBuilderParts(): \Iterator
59 {
60 yield ['wiki', 42, [], 'https://test9.ilias.de/goto.php/wiki/42'];
61 yield ['file', 42, ['download'], 'https://test9.ilias.de/goto.php/file/42/download'];
62 yield ['dashboard', null, [], 'https://test9.ilias.de/goto.php/dashboard'];
63 }
64
65 #[DataProvider('getBuilderParts')]
66 public function testFullBuilder(string $namespace, ?int $ref_id, array $params, string $expected): void
67 {
68 $uri_builder = new StandardURIBuilder(
69 $this->getConfig('https://test9.ilias.de')
70 );
71 $uri = $uri_builder->build(
73 $ref_id === null ? null : new ReferenceId($ref_id),
75 );
76 $this->assertSame($expected, (string) $uri);
77 }
78
79 private function getConfig(
80 string $ILIAS_HTTP_PATH
81 ): Configuration {
82 return new class ($ILIAS_HTTP_PATH) implements Configuration {
83 public function __construct(
84 private string $ILIAS_HTTP_PATH
85 ) {
86 }
87
88 public function get(Config $config): mixed
89 {
90 return match ($config) {
91 Config::BASE_URL => $this->ILIAS_HTTP_PATH,
92 Config::REWRITE_POSSIBLE => false,
93 Config::SHORTLINK_NAMESPACE => 'shortlink',
94 Config::STATIC_LINK_ENDPOINT => StandardURIBuilder::LONG,
95 Config::ULTRA_SHORT => false,
96 default => null,
97 };
98 }
99
100 };
101 }
102
103}
testBaseURI(string $ILIAS_HTTP_PATH, string $expected)
testFullBuilder(string $namespace, ?int $ref_id, array $params, string $expected)
getConfig(string $ILIAS_HTTP_PATH)
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($err=$client->getError()) $namespace
A configuration for the setup.
Definition: Config.php:27
$ref_id
Definition: ltiauth.php:66
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Base.php:19