ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest Class Reference
+ Inheritance diagram for ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest:
+ Collaboration diagram for ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest:

Public Member Functions

 testSendResponseToRequestAvailable ()
 
 testSendResponseToRequestNotAvailable ()
 
 testSendResponseToRequestProcessorThrowsException ()
 
 testSendResponseToRequestProcessorThrowsError ()
 
 testSendResponseToRequestProcessorTriggersError ()
 

Protected Member Functions

 getURI (string $string)
 
 getHTTPWrapper ()
 
 getSettings (bool $activated)
 
 getRequestParser (string $content)
 
 getRequestProcessor (bool $throws_exception=false, bool $throws_error=false, bool $triggers_error=false)
 
 getHandler (string $base_url, SettingsInterface $settings, HTTPWrapperInterface $http_wrapper, RequestParserInterface $request_parser, RequestProcessorInterface $request_processor,)
 

Detailed Description

Definition at line 36 of file HandlerTest.php.

Member Function Documentation

◆ getHandler()

ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest::getHandler ( string  $base_url,
SettingsInterface  $settings,
HTTPWrapperInterface  $http_wrapper,
RequestParserInterface  $request_parser,
RequestProcessorInterface  $request_processor 
)
protected

Definition at line 149 of file HandlerTest.php.

155 : Handler {
156 $base_url = $this->getURI($base_url);
157 return new class (
158 $settings,
159 $http_wrapper,
160 $request_parser,
161 $request_processor,
162 $base_url
163 ) extends Handler {
164 public array $exposed_logged_errors = [];
165
166 public function __construct(
167 protected SettingsInterface $settings,
168 protected HTTPWrapperInterface $http_wrapper,
169 protected RequestParserInterface $request_parser,
170 protected RequestProcessorInterface $request_processor,
171 protected readonly URI $base_url
172 ) {
173 }
174
175 protected function logError(string $message): void
176 {
177 $this->exposed_logged_errors[] = $message;
178 }
179 };
180 }
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76

References ILIAS\GlobalScreen\Provider\__construct().

+ Here is the call graph for this function:

◆ getHTTPWrapper()

ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest::getHTTPWrapper ( )
protected

Definition at line 45 of file HandlerTest.php.

45 : HTTPWrapperInterface
46 {
47 return new class () extends NullWrapper {
48 public array $exposed_responses = [];
49
50 public function sendResponseAndClose(
51 int $status_code,
52 string $message = '',
53 ?\DOMDocument $body = null
54 ): void {
55 $this->exposed_responses[] = [
56 'status' => $status_code,
57 'message' => $message,
58 'body' => $body?->saveXML($body->documentElement)
59 ];
60 }
61 };
62 }

◆ getRequestParser()

ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest::getRequestParser ( string  $content)
protected

Definition at line 79 of file HandlerTest.php.

79 : RequestParserInterface
80 {
81 return new class ($content) extends NullParser {
82 public function __construct(protected string $content)
83 {
84 }
85
86 public function parseFromHTTP(URI $base_url): RequestInterface
87 {
88 return new class ($this->content, $base_url) extends NullRequest {
89 public function __construct(
90 protected string $content,
91 protected URI $base_url
92 ) {
93 }
94
95 public function baseURL(): URI
96 {
97 return $this->base_url;
98 }
99
100 public function exposeContent(): string
101 {
102 return $this->content;
103 }
104 };
105 }
106 };
107 }

References ILIAS\__construct().

+ Here is the call graph for this function:

◆ getRequestProcessor()

ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest::getRequestProcessor ( bool  $throws_exception = false,
bool  $throws_error = false,
bool  $triggers_error = false 
)
protected

@noinspection PhpExpressionResultUnusedInspection

@noinspection PhpDivisionByZeroInspection

Definition at line 109 of file HandlerTest.php.

113 : RequestProcessorInterface {
114 return new class (
115 $throws_exception,
116 $throws_error,
117 $triggers_error
118 ) extends NullRequestProcessor {
119 public function __construct(
120 protected bool $throws_exception,
121 protected bool $throws_error,
122 protected bool $triggers_error
123 ) {
124 }
125
126 public function getResponseToRequest(RequestInterface $request): \DomDocument
127 {
128 if ($this->throws_exception) {
129 throw new \ilMDOERExposerException('exception message');
130 }
131 if ($this->throws_error) {
132 throw new \Error('thrown error message');
133 }
134 if ($this->triggers_error) {
137 1 / 0;
138 }
139
140 $url = (string) $request->baseURL();
141 $content = $request->exposeContent();
142 $doc = new \DOMDocument();
143 $doc->appendChild($doc->createElement('content', $url . '~!~' . $content));
144 return $doc;
145 }
146 };
147 }
$url
Definition: shib_logout.php:70

◆ getSettings()

ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest::getSettings ( bool  $activated)
protected

Definition at line 64 of file HandlerTest.php.

64 : SettingsInterface
65 {
66 return new class ($activated) extends NullSettings {
67 public function __construct(
68 protected bool $activated
69 ) {
70 }
71
72 public function isOAIPMHActive(): bool
73 {
74 return $this->activated;
75 }
76 };
77 }

References ILIAS\__construct().

+ Here is the call graph for this function:

◆ getURI()

ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest::getURI ( string  $string)
protected

Definition at line 38 of file HandlerTest.php.

38 : URI
39 {
40 $url = $this->createMock(URI::class);
41 $url->method('__toString')->willReturn($string);
42 return $url;
43 }

References $url.

◆ testSendResponseToRequestAvailable()

ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest::testSendResponseToRequestAvailable ( )

Definition at line 182 of file HandlerTest.php.

182 : void
183 {
184 $handler = $this->getHandler(
185 'some url',
186 $this->getSettings(true),
187 $wrapper = $this->getHTTPWrapper(),
188 $this->getRequestParser('some content'),
189 $this->getRequestProcessor()
190 );
191
192 $handler->sendResponseToRequest();
193
194 $this->assertCount(1, $wrapper->exposed_responses);
195 $this->assertEquals(
196 ['status' => 200, 'message' => '', 'body' => '<content>some url~!~some content</content>'],
197 $wrapper->exposed_responses[0] ?? []
198 );
199 }
getRequestProcessor(bool $throws_exception=false, bool $throws_error=false, bool $triggers_error=false)
getHandler(string $base_url, SettingsInterface $settings, HTTPWrapperInterface $http_wrapper, RequestParserInterface $request_parser, RequestProcessorInterface $request_processor,)
$handler
Definition: oai.php:31

References $handler.

◆ testSendResponseToRequestNotAvailable()

ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest::testSendResponseToRequestNotAvailable ( )

Definition at line 201 of file HandlerTest.php.

201 : void
202 {
203 $handler = $this->getHandler(
204 'some url',
205 $this->getSettings(false),
206 $wrapper = $this->getHTTPWrapper(),
207 $this->getRequestParser('some content'),
208 $this->getRequestProcessor()
209 );
210
211 $handler->sendResponseToRequest();
212
213 $this->assertCount(1, $wrapper->exposed_responses);
214 $this->assertEquals(
215 ['status' => 404, 'message' => '', 'body' => null],
216 $wrapper->exposed_responses[0] ?? []
217 );
218 }

References $handler.

◆ testSendResponseToRequestProcessorThrowsError()

ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest::testSendResponseToRequestProcessorThrowsError ( )

Definition at line 243 of file HandlerTest.php.

243 : void
244 {
245 $handler = $this->getHandler(
246 'some url',
247 $this->getSettings(true),
248 $wrapper = $this->getHTTPWrapper(),
249 $this->getRequestParser(''),
250 $this->getRequestProcessor(false, true)
251 );
252
253 $handler->sendResponseToRequest();
254
255 $this->assertCount(1, $wrapper->exposed_responses);
256 $this->assertEquals(
257 ['status' => 500, 'message' => 'thrown error message', 'body' => null],
258 $wrapper->exposed_responses[0] ?? []
259 );
260 $this->assertEquals(
261 ['thrown error message'],
262 $handler->exposed_logged_errors
263 );
264 }

References $handler.

◆ testSendResponseToRequestProcessorThrowsException()

ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest::testSendResponseToRequestProcessorThrowsException ( )

Definition at line 220 of file HandlerTest.php.

220 : void
221 {
222 $handler = $this->getHandler(
223 'some url',
224 $this->getSettings(true),
225 $wrapper = $this->getHTTPWrapper(),
226 $this->getRequestParser(''),
227 $this->getRequestProcessor(true)
228 );
229
230 $handler->sendResponseToRequest();
231
232 $this->assertCount(1, $wrapper->exposed_responses);
233 $this->assertEquals(
234 ['status' => 500, 'message' => 'exception message', 'body' => null],
235 $wrapper->exposed_responses[0] ?? []
236 );
237 $this->assertEquals(
238 ['exception message'],
239 $handler->exposed_logged_errors
240 );
241 }

References $handler.

◆ testSendResponseToRequestProcessorTriggersError()

ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest::testSendResponseToRequestProcessorTriggersError ( )

Definition at line 266 of file HandlerTest.php.

266 : void
267 {
268 $handler = $this->getHandler(
269 'some url',
270 $this->getSettings(true),
271 $wrapper = $this->getHTTPWrapper(),
272 $this->getRequestParser(''),
273 $this->getRequestProcessor(false, false, true)
274 );
275
276 $handler->sendResponseToRequest();
277
278 $this->assertCount(1, $wrapper->exposed_responses);
279 $this->assertEquals(
280 ['status' => 500, 'message' => 'Division by zero', 'body' => null],
281 $wrapper->exposed_responses[0] ?? []
282 );
283 $this->assertEquals(
284 ['Division by zero'],
285 $handler->exposed_logged_errors
286 );
287 }

References $handler.


The documentation for this class was generated from the following file: