ILIAS  trunk Revision v11.0_alpha-1831-g8615d53dadb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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)
 
 getInitiator (bool $activated, string $content, bool $processor_throws_exception=false, bool $processor_throws_error=false, bool $processor_triggers_error=false)
 
 getHandler (string $base_url, InitiatorInterface $initiator)
 

Detailed Description

Definition at line 36 of file HandlerTest.php.

Member Function Documentation

◆ getHandler()

ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest::getHandler ( string  $base_url,
InitiatorInterface  $initiator 
)
protected

Definition at line 179 of file HandlerTest.php.

References $message, ILIAS\__construct(), and ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest\getURI().

Referenced by ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest\testSendResponseToRequestAvailable(), ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest\testSendResponseToRequestNotAvailable(), ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest\testSendResponseToRequestProcessorThrowsError(), ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest\testSendResponseToRequestProcessorThrowsException(), and ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest\testSendResponseToRequestProcessorTriggersError().

182  : Handler {
183  $base_url = $this->getURI($base_url);
184  return new class ($initiator, $base_url) extends Handler {
185  public array $exposed_logged_errors = [];
186 
187  public function __construct(
188  protected InitiatorInterface $initiator,
189  protected readonly URI $base_url
190  ) {
191  }
192 
193  protected function logError(string $message): void
194  {
195  $this->exposed_logged_errors[] = $message;
196  }
197  };
198  }
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:76
$message
Definition: xapiexit.php:31
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInitiator()

ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest::getInitiator ( bool  $activated,
string  $content,
bool  $processor_throws_exception = false,
bool  $processor_throws_error = false,
bool  $processor_triggers_error = false 
)
protected

PhpExpressionResultUnusedInspection

Definition at line 45 of file HandlerTest.php.

References $message, $url, ILIAS\__construct(), ILIAS\MetaData\OERExposer\OAIPMH\Requests\RequestInterface\baseURL(), null, and ILIAS\Repository\settings().

Referenced by ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest\testSendResponseToRequestAvailable(), ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest\testSendResponseToRequestNotAvailable(), ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest\testSendResponseToRequestProcessorThrowsError(), ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest\testSendResponseToRequestProcessorThrowsException(), and ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest\testSendResponseToRequestProcessorTriggersError().

51  : InitiatorInterface {
52  return new class (
53  $activated,
54  $content,
55  $processor_throws_exception,
56  $processor_throws_error,
57  $processor_triggers_error
58  ) extends NullInitiator {
59  protected HTTPWrapperInterface $wrapper;
60 
61  public function __construct(
62  protected bool $activated,
63  protected string $content,
64  protected bool $processor_throws_exception,
65  protected bool $processor_throws_error,
66  protected bool $processor_triggers_error
67  ) {
68  $this->wrapper = new class () extends NullWrapper {
69  public array $exposed_responses = [];
70 
71  public function sendResponseAndClose(
72  int $status_code,
73  string $message = '',
74  ?\DOMDocument $body = null
75  ): void {
76  $this->exposed_responses[] = [
77  'status' => $status_code,
78  'message' => $message,
79  'body' => $body?->saveXML($body->documentElement)
80  ];
81  }
82  };
83  }
84 
85  public function settings(): SettingsInterface
86  {
87  return new class ($this->activated) extends NullSettings {
88  public function __construct(
89  protected bool $activated
90  ) {
91  }
92 
93  public function isOAIPMHActive(): bool
94  {
95  return $this->activated;
96  }
97  };
98  }
99 
100  public function requestParser(): RequestParserInterface
101  {
102  return new class ($this->content) extends NullParser {
103  public function __construct(protected string $content)
104  {
105  }
106 
107  public function parseFromHTTP(URI $base_url): RequestInterface
108  {
109  return new class ($this->content, $base_url) extends NullRequest {
110  public function __construct(
111  protected string $content,
112  protected URI $base_url
113  ) {
114  }
115 
116  public function baseURL(): URI
117  {
118  return $this->base_url;
119  }
120 
121  public function exposeContent(): string
122  {
123  return $this->content;
124  }
125  };
126  }
127  };
128  }
129 
130  public function requestProcessor(): RequestProcessorInterface
131  {
132  return new class (
133  $this->processor_throws_exception,
134  $this->processor_throws_error,
135  $this->processor_triggers_error
136  ) extends NullRequestProcessor {
137  public function __construct(
138  protected bool $throws_exception,
139  protected bool $throws_error,
140  protected bool $triggers_error
141  ) {
142  }
143 
144  public function getResponseToRequest(RequestInterface $request): \DomDocument
145  {
146  if ($this->throws_exception) {
147  throw new \ilMDOERExposerException('exception message');
148  }
149  if ($this->throws_error) {
150  throw new \Error('thrown error message');
151  }
152  if ($this->triggers_error) {
154  1 / 0;
155  }
156 
157  $url = (string) $request->baseURL();
158  $content = $request->exposeContent();
159  $doc = new \DOMDocument();
160  $doc->appendChild($doc->createElement('content', $url . '~!~' . $content));
161  return $doc;
162  }
163  };
164  }
165 
166  public function httpWrapper(): HTTPWrapperInterface
167  {
168  // must always be the same instance to make the expose work
169  return $this->wrapper;
170  }
171 
172  public function exposeHTTPResponses(): array
173  {
174  return $this->httpWrapper()->exposed_responses;
175  }
176  };
177  }
$url
Definition: shib_logout.php:66
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:76
$message
Definition: xapiexit.php:31
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getURI()

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

Definition at line 38 of file HandlerTest.php.

References $url.

Referenced by ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest\getHandler().

38  : URI
39  {
40  $url = $this->createMock(URI::class);
41  $url->method('__toString')->willReturn($string);
42  return $url;
43  }
$url
Definition: shib_logout.php:66
+ Here is the caller graph for this function:

◆ testSendResponseToRequestAvailable()

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

Definition at line 200 of file HandlerTest.php.

References $handler, ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest\getHandler(), and ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest\getInitiator().

200  : void
201  {
202  $initiator = $this->getInitiator(
203  true,
204  'some content'
205  );
206  $handler = $this->getHandler(
207  'some url',
208  $initiator
209  );
210 
211  $handler->sendResponseToRequest();
212 
213  $this->assertCount(1, $initiator->exposeHTTPResponses());
214  $this->assertEquals(
215  ['status' => 200, 'message' => '', 'body' => '<content>some url~!~some content</content>'],
216  $initiator->exposeHTTPResponses()[0] ?? []
217  );
218  }
getHandler(string $base_url, InitiatorInterface $initiator)
getInitiator(bool $activated, string $content, bool $processor_throws_exception=false, bool $processor_throws_error=false, bool $processor_triggers_error=false)
Definition: HandlerTest.php:45
$handler
Definition: oai.php:30
+ Here is the call graph for this function:

◆ testSendResponseToRequestNotAvailable()

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

Definition at line 220 of file HandlerTest.php.

References $handler, ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest\getHandler(), ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest\getInitiator(), and null.

220  : void
221  {
222  $initiator = $this->getInitiator(
223  false,
224  'some content'
225  );
226  $handler = $this->getHandler(
227  'some url',
228  $initiator
229  );
230 
231  $handler->sendResponseToRequest();
232 
233  $this->assertCount(1, $initiator->exposeHTTPResponses());
234  $this->assertEquals(
235  ['status' => 404, 'message' => '', 'body' => null],
236  $initiator->exposeHTTPResponses()[0] ?? []
237  );
238  }
getHandler(string $base_url, InitiatorInterface $initiator)
getInitiator(bool $activated, string $content, bool $processor_throws_exception=false, bool $processor_throws_error=false, bool $processor_triggers_error=false)
Definition: HandlerTest.php:45
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$handler
Definition: oai.php:30
+ Here is the call graph for this function:

◆ testSendResponseToRequestProcessorThrowsError()

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

Definition at line 267 of file HandlerTest.php.

References $handler, ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest\getHandler(), ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest\getInitiator(), and null.

267  : void
268  {
269  $initiator = $this->getInitiator(
270  true,
271  '',
272  false,
273  true,
274  false
275  );
276  $handler = $this->getHandler(
277  'some url',
278  $initiator
279  );
280 
281  $handler->sendResponseToRequest();
282 
283  $this->assertCount(1, $initiator->exposeHTTPResponses());
284  $this->assertEquals(
285  ['status' => 500, 'message' => 'thrown error message', 'body' => null],
286  $initiator->exposeHTTPResponses()[0] ?? []
287  );
288  $this->assertEquals(
289  ['thrown error message'],
290  $handler->exposed_logged_errors
291  );
292  }
getHandler(string $base_url, InitiatorInterface $initiator)
getInitiator(bool $activated, string $content, bool $processor_throws_exception=false, bool $processor_throws_error=false, bool $processor_triggers_error=false)
Definition: HandlerTest.php:45
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$handler
Definition: oai.php:30
+ Here is the call graph for this function:

◆ testSendResponseToRequestProcessorThrowsException()

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

Definition at line 240 of file HandlerTest.php.

References $handler, ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest\getHandler(), ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest\getInitiator(), and null.

240  : void
241  {
242  $initiator = $this->getInitiator(
243  true,
244  '',
245  true,
246  false,
247  false
248  );
249  $handler = $this->getHandler(
250  'some url',
251  $initiator
252  );
253 
254  $handler->sendResponseToRequest();
255 
256  $this->assertCount(1, $initiator->exposeHTTPResponses());
257  $this->assertEquals(
258  ['status' => 500, 'message' => 'exception message', 'body' => null],
259  $initiator->exposeHTTPResponses()[0] ?? []
260  );
261  $this->assertEquals(
262  ['exception message'],
263  $handler->exposed_logged_errors
264  );
265  }
getHandler(string $base_url, InitiatorInterface $initiator)
getInitiator(bool $activated, string $content, bool $processor_throws_exception=false, bool $processor_throws_error=false, bool $processor_triggers_error=false)
Definition: HandlerTest.php:45
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$handler
Definition: oai.php:30
+ Here is the call graph for this function:

◆ testSendResponseToRequestProcessorTriggersError()

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

Definition at line 294 of file HandlerTest.php.

References $handler, ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest\getHandler(), ILIAS\MetaData\OERExposer\OAIPMH\HandlerTest\getInitiator(), and null.

294  : void
295  {
296  $initiator = $this->getInitiator(
297  true,
298  '',
299  false,
300  false,
301  true
302  );
303  $handler = $this->getHandler(
304  'some url',
305  $initiator
306  );
307 
308  $handler->sendResponseToRequest();
309 
310  $this->assertCount(1, $initiator->exposeHTTPResponses());
311  $this->assertEquals(
312  ['status' => 500, 'message' => 'Division by zero', 'body' => null],
313  $initiator->exposeHTTPResponses()[0] ?? []
314  );
315  $this->assertEquals(
316  ['Division by zero'],
317  $handler->exposed_logged_errors
318  );
319  }
getHandler(string $base_url, InitiatorInterface $initiator)
getInitiator(bool $activated, string $content, bool $processor_throws_exception=false, bool $processor_throws_error=false, bool $processor_triggers_error=false)
Definition: HandlerTest.php:45
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$handler
Definition: oai.php:30
+ Here is the call graph for this function:

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