ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
RequestTranslationTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use PHPUnit\Framework\TestCase;
24use PHPUnit\Framework\Attributes\Test;
25use PHPUnit\Framework\Attributes\Small;
26use Psr\Http\Message\ServerRequestInterface;
27use Psr\Http\Message\UriInterface;
30
31#[Small]
32final class RequestTranslationTest extends TestCase
33{
34 private function buildRequest(string $path, array $query_params = []): ServerRequestInterface
35 {
36 $uri = $this->createStub(UriInterface::class);
37 $uri->method('getPath')->willReturn($path);
38
39 $request = $this->createStub(ServerRequestInterface::class);
40 $request->method('getUri')->willReturn($uri);
41 $request->method('getQueryParams')->willReturn($query_params);
42
43 return $request;
44 }
45
46 private function buildConfig(string $client_id = 'default'): Config
47 {
48 return new class ($client_id) extends Config {
49 public function __construct(private string $client)
50 {
51 }
52 public function getClientId(): string
53 {
54 return $this->client;
55 }
56 };
57 }
58
59 #[Test]
61 {
62 $translation = new RequestTranslation(
63 $this->buildConfig('default'),
64 $this->buildRequest('/webdav.php/default/ref_92/sub/file.txt')
65 );
66
67 $this->assertSame('ref_92/sub/file.txt', $translation->getRequestedPath());
68 }
69
70 #[Test]
72 {
73 $translation = new RequestTranslation(
74 $this->buildConfig('default'),
75 $this->buildRequest('/webdav.php/ref_92/sub/file.txt')
76 );
77
78 $this->assertSame('ref_92/sub/file.txt', $translation->getRequestedPath());
79 }
80
81 #[Test]
83 {
84 $translation = new RequestTranslation(
85 $this->buildConfig('default'),
86 $this->buildRequest('/webdav.php/')
87 );
88
89 $this->assertSame('', $translation->getRequestedPath());
90 }
91
92 #[Test]
94 {
95 // ensure that "ref_92" is never accidentally treated as a client segment
96 $translation = new RequestTranslation(
97 $this->buildConfig('default'),
98 $this->buildRequest('/webdav.php/ref_92')
99 );
100
101 $this->assertSame('ref_92', $translation->getRequestedPath());
102 }
103
104 #[Test]
106 {
107 $translation = new RequestTranslation(
108 $this->buildConfig('default'),
109 $this->buildRequest('/webdav.php/ref_92/folder/file.txt')
110 );
111
112 $this->assertSame(
113 ['ref_92', 'folder', 'file.txt'],
114 $translation->getRequestedPathAsArray()
115 );
116 }
117
118 #[Test]
120 {
121 $translation = new RequestTranslation(
122 $this->buildConfig('default'),
123 $this->buildRequest('/webdav.php/default/ref_92')
124 );
125
126 $this->assertSame('/webdav.php/default/', $translation->getBasePath());
127 }
128
129 #[Test]
131 {
132 $translation = new RequestTranslation(
133 $this->buildConfig('default'),
134 $this->buildRequest('/webdav.php/ref_92')
135 );
136
137 $this->assertSame('/webdav.php/', $translation->getBasePath());
138 }
139
140 #[Test]
142 {
143 $translation = new RequestTranslation(
144 $this->buildConfig(''),
145 $this->buildRequest('/webdav.php/default/ref_92')
146 );
147
148 $this->assertSame('/webdav.php/', $translation->getBasePath());
149 }
150
151 #[Test]
153 {
154 $translation = new RequestTranslation(
155 $this->buildConfig('default'),
156 $this->buildRequest('/webdav.php/ref_92', ['mount-instructions' => ''])
157 );
158
159 $this->assertTrue($translation->showMountPoint());
160 }
161
162 #[Test]
164 {
165 $translation = new RequestTranslation(
166 $this->buildConfig('default'),
167 $this->buildRequest('/webdav.php/ref_92', [])
168 );
169
170 $this->assertFalse($translation->showMountPoint());
171 }
172}
buildRequest(string $path, array $query_params=[])
string $client_id
Definition: class.ilias.php:36
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76
getClientId()
$client
$path
Definition: ltiservices.php:30