ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
RequestProcessorListIdentifiersTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 
26 class RequestProcessorListIdentifiersTest extends RequestProcessorTestCase
27 {
28  public function testGetResponseToRequestListIdentifiers(): void
29  {
30  $processor = new RequestProcessor(
31  $this->getWriter(),
32  $this->getSettings('prefix_'),
33  $repo = $this->getRepository(
34  null,
35  3,
36  'id1+2022-11-27',
37  'id2+2022-11-27',
38  'id3+2021-11-13'
39  ),
40  $this->getTokenHandler()
41  );
42 
43  $expected_response = <<<XML
44  <response>
45  <response_info>base url:ListIdentifiers:metadataPrefix=oai_dc</response_info>
46  <header>prefix_id1+2022-11-27:2022-11-27</header>
47  <header>prefix_id2+2022-11-27:2022-11-27</header>
48  <header>prefix_id3+2021-11-13:2021-11-13</header>
49  </response>
50  XML;
51 
52  $response = $processor->getResponseToRequest($this->getRequest(
53  'base url',
54  Verb::LIST_IDENTIFIERS,
55  [Argument::MD_PREFIX->value => 'oai_dc'],
56  ));
57 
58  $this->assertEquals(
59  [['from' => null, 'until' => null, 'limit' => 100, 'offset' => 0]],
60  $repo->exposed_parameters
61  );
62  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
63  }
64 
65  public function testGetResponseToRequestListIdentifiersWithDefaultSet(): void
66  {
67  $processor = new RequestProcessor(
68  $this->getWriter(),
69  $this->getSettings('prefix_'),
70  $repo = $this->getRepository(
71  null,
72  3,
73  'id1+2022-11-27',
74  'id2+2022-11-27',
75  'id3+2021-11-13'
76  ),
77  $this->getTokenHandler()
78  );
79 
80  $expected_response = <<<XML
81  <response>
82  <response_info>base url:ListIdentifiers:metadataPrefix=oai_dc,set=default</response_info>
83  <header>prefix_id1+2022-11-27:2022-11-27</header>
84  <header>prefix_id2+2022-11-27:2022-11-27</header>
85  <header>prefix_id3+2021-11-13:2021-11-13</header>
86  </response>
87  XML;
88 
89  $response = $processor->getResponseToRequest($this->getRequest(
90  'base url',
91  Verb::LIST_IDENTIFIERS,
92  [Argument::MD_PREFIX->value => 'oai_dc', Argument::SET->value => 'default'],
93  ));
94 
95  $this->assertEquals(
96  [['from' => null, 'until' => null, 'limit' => 100, 'offset' => 0]],
97  $repo->exposed_parameters
98  );
99  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
100  }
101 
102  public function testGetResponseToRequestListIdentifiersWithFromDate(): void
103  {
104  $processor = new RequestProcessor(
105  $this->getWriter(),
106  $this->getSettings('prefix_'),
107  $repo = $this->getRepository(
108  null,
109  3,
110  'id1+2022-11-27',
111  'id2+2022-11-27',
112  'id3+2021-11-13'
113  ),
114  $this->getTokenHandler()
115  );
116 
117  $expected_response = <<<XML
118  <response>
119  <response_info>base url:ListIdentifiers:metadataPrefix=oai_dc,from=2019-01-02</response_info>
120  <header>prefix_id1+2022-11-27:2022-11-27</header>
121  <header>prefix_id2+2022-11-27:2022-11-27</header>
122  <header>prefix_id3+2021-11-13:2021-11-13</header>
123  </response>
124  XML;
125 
126  $response = $processor->getResponseToRequest($this->getRequest(
127  'base url',
128  Verb::LIST_IDENTIFIERS,
129  [Argument::MD_PREFIX->value => 'oai_dc', Argument::FROM_DATE->value => '2019-01-02'],
130  ));
131 
132  $this->assertEquals(
133  [['from' => '2019-01-02', 'until' => null, 'limit' => 100, 'offset' => 0]],
134  $repo->exposed_parameters
135  );
136  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
137  }
138 
139  public function testGetResponseToRequestListIdentifiersWithUntilDate(): void
140  {
141  $processor = new RequestProcessor(
142  $this->getWriter(),
143  $this->getSettings('prefix_'),
144  $repo = $this->getRepository(
145  null,
146  3,
147  'id1+2022-11-27',
148  'id2+2022-11-27',
149  'id3+2021-11-13'
150  ),
151  $this->getTokenHandler()
152  );
153 
154  $expected_response = <<<XML
155  <response>
156  <response_info>base url:ListIdentifiers:metadataPrefix=oai_dc,until=2033-11-02</response_info>
157  <header>prefix_id1+2022-11-27:2022-11-27</header>
158  <header>prefix_id2+2022-11-27:2022-11-27</header>
159  <header>prefix_id3+2021-11-13:2021-11-13</header>
160  </response>
161  XML;
162 
163  $response = $processor->getResponseToRequest($this->getRequest(
164  'base url',
165  Verb::LIST_IDENTIFIERS,
166  [Argument::MD_PREFIX->value => 'oai_dc', Argument::UNTIL_DATE->value => '2033-11-02'],
167  ));
168 
169  $this->assertSame(
170  [['from' => null, 'until' => '2033-11-02', 'limit' => 100, 'offset' => 0]],
171  $repo->exposed_parameters
172  );
173  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
174  }
175 
176  public function testGetResponseToRequestListIdentifiersWithBothDates(): void
177  {
178  $processor = new RequestProcessor(
179  $this->getWriter(),
180  $this->getSettings('prefix_'),
181  $repo = $this->getRepository(
182  null,
183  3,
184  'id1+2022-11-27',
185  'id2+2022-11-27',
186  'id3+2021-11-13'
187  ),
188  $this->getTokenHandler()
189  );
190 
191  $expected_response = <<<XML
192  <response>
193  <response_info>base url:ListIdentifiers:metadataPrefix=oai_dc,until=2033-11-02,from=2019-01-02</response_info>
194  <header>prefix_id1+2022-11-27:2022-11-27</header>
195  <header>prefix_id2+2022-11-27:2022-11-27</header>
196  <header>prefix_id3+2021-11-13:2021-11-13</header>
197  </response>
198  XML;
199 
200  $response = $processor->getResponseToRequest($this->getRequest(
201  'base url',
202  Verb::LIST_IDENTIFIERS,
203  [
204  Argument::MD_PREFIX->value => 'oai_dc',
205  Argument::UNTIL_DATE->value => '2033-11-02',
206  Argument::FROM_DATE->value => '2019-01-02'
207  ],
208  ));
209 
210  $this->assertEquals(
211  [['from' => '2019-01-02', 'until' => '2033-11-02', 'limit' => 100, 'offset' => 0]],
212  $repo->exposed_parameters
213  );
214  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
215  }
216 
217  public function testGetResponseToRequestListIdentifiersIncompleteList(): void
218  {
219  $processor = new RequestProcessor(
220  $this->getWriter(),
221  $this->getSettings('prefix_'),
222  $repo = $this->getRepository(
223  null,
224  203,
225  'id1+2022-11-27',
226  'id2+2022-11-27',
227  'id3+2021-11-13'
228  ),
229  $this->getTokenHandler()
230  );
231 
232  $expected_response = <<<XML
233  <response>
234  <response_info>base url:ListIdentifiers:metadataPrefix=oai_dc</response_info>
235  <header>prefix_id1+2022-11-27:2022-11-27</header>
236  <header>prefix_id2+2022-11-27:2022-11-27</header>
237  <header>prefix_id3+2021-11-13:2021-11-13</header>
238  <token>next_offset=100:from=:until=,fullsize=203,cursor=0</token>
239  </response>
240  XML;
241 
242  $response = $processor->getResponseToRequest($this->getRequest(
243  'base url',
244  Verb::LIST_IDENTIFIERS,
245  [Argument::MD_PREFIX->value => 'oai_dc'],
246  ));
247 
248  $this->assertEquals(
249  [['from' => null, 'until' => null, 'limit' => 100, 'offset' => 0]],
250  $repo->exposed_parameters
251  );
252  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
253  }
254 
255  public function testGetResponseToRequestListIdentifiersWithResumptionToken(): void
256  {
257  $original_request = $this->getRequest(
258  'base url',
259  Verb::LIST_IDENTIFIERS,
260  [Argument::RESUMPTION_TOKEN->value => 'next_offset=100:from=:until=2024-07-28'],
261  );
262 
263  $appended_request = $this->getRequest(
264  'base url',
265  Verb::LIST_IDENTIFIERS,
266  [
267  Argument::RESUMPTION_TOKEN->value => 'next_offset=100:from=:until=2024-07-28',
268  Argument::UNTIL_DATE->value => '2024-07-28'
269  ],
270  );
271 
272  $processor = new RequestProcessor(
273  $this->getWriter(),
274  $this->getSettings('prefix_'),
275  $repo = $this->getRepository(
276  null,
277  203,
278  'id1+2022-11-27',
279  'id2+2022-11-27',
280  'id3+2021-11-13'
281  ),
282  $this->getTokenHandler(true, $appended_request)
283  );
284 
285  $expected_response = <<<XML
286  <response>
287  <response_info>base url:ListIdentifiers:resumptionToken=next_offset=100:from=:until=2024-07-28</response_info>
288  <header>prefix_id1+2022-11-27:2022-11-27</header>
289  <header>prefix_id2+2022-11-27:2022-11-27</header>
290  <header>prefix_id3+2021-11-13:2021-11-13</header>
291  <token>next_offset=200:from=:until=2024-07-28,fullsize=203,cursor=100</token>
292  </response>
293  XML;
294 
295  $response = $processor->getResponseToRequest($original_request);
296 
297  $this->assertEquals(
298  [['from' => null, 'until' => '2024-07-28', 'limit' => 100, 'offset' => 100]],
299  $repo->exposed_parameters
300  );
301  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
302  }
303 
304  public function testGetResponseToRequestListIdentifiersWithResumptionTokenContainingFromDate(): void
305  {
306  $original_request = $this->getRequest(
307  'base url',
308  Verb::LIST_IDENTIFIERS,
309  [Argument::RESUMPTION_TOKEN->value => 'next_offset=100:from=1999-01-12:until=2024-07-28'],
310  );
311 
312  $appended_request = $this->getRequest(
313  'base url',
314  Verb::LIST_IDENTIFIERS,
315  [
316  Argument::RESUMPTION_TOKEN->value => 'next_offset=100:from=1999-01-12:until=2024-07-28',
317  Argument::UNTIL_DATE->value => '2024-07-28',
318  Argument::FROM_DATE->value => '1999-01-12'
319  ],
320  );
321 
322  $processor = new RequestProcessor(
323  $this->getWriter(),
324  $this->getSettings('prefix_'),
325  $repo = $this->getRepository(
326  null,
327  203,
328  'id1+2022-11-27',
329  'id2+2022-11-27',
330  'id3+2021-11-13'
331  ),
332  $this->getTokenHandler(true, $appended_request)
333  );
334 
335  $expected_response = <<<XML
336  <response>
337  <response_info>base url:ListIdentifiers:resumptionToken=next_offset=100:from=1999-01-12:until=2024-07-28</response_info>
338  <header>prefix_id1+2022-11-27:2022-11-27</header>
339  <header>prefix_id2+2022-11-27:2022-11-27</header>
340  <header>prefix_id3+2021-11-13:2021-11-13</header>
341  <token>next_offset=200:from=1999-01-12:until=2024-07-28,fullsize=203,cursor=100</token>
342  </response>
343  XML;
344 
345  $response = $processor->getResponseToRequest($original_request);
346 
347  $this->assertEquals(
348  [['from' => '1999-01-12', 'until' => '2024-07-28', 'limit' => 100, 'offset' => 100]],
349  $repo->exposed_parameters
350  );
351  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
352  }
353 
354  public function testGetResponseToRequestListIdentifiersWithResumptionTokenLastIncompleteList(): void
355  {
356  $original_request = $this->getRequest(
357  'base url',
358  Verb::LIST_IDENTIFIERS,
359  [Argument::RESUMPTION_TOKEN->value => 'next_offset=200:from=:until=2024-07-28'],
360  );
361 
362  $appended_request = $this->getRequest(
363  'base url',
364  Verb::LIST_IDENTIFIERS,
365  [
366  Argument::RESUMPTION_TOKEN->value => 'next_offset=200:from=:until=2024-07-28',
367  Argument::UNTIL_DATE->value => '2024-07-28'
368  ],
369  );
370 
371  $processor = new RequestProcessor(
372  $this->getWriter(),
373  $this->getSettings('prefix_'),
374  $repo = $this->getRepository(
375  null,
376  203,
377  'id1+2022-11-27',
378  'id2+2022-11-27',
379  'id3+2021-11-13'
380  ),
381  $this->getTokenHandler(true, $appended_request)
382  );
383 
384  $expected_response = <<<XML
385  <response>
386  <response_info>base url:ListIdentifiers:resumptionToken=next_offset=200:from=:until=2024-07-28</response_info>
387  <header>prefix_id1+2022-11-27:2022-11-27</header>
388  <header>prefix_id2+2022-11-27:2022-11-27</header>
389  <header>prefix_id3+2021-11-13:2021-11-13</header>
390  <token>,fullsize=203,cursor=200</token>
391  </response>
392  XML;
393 
394  $response = $processor->getResponseToRequest($original_request);
395 
396  $this->assertEquals(
397  [['from' => null, 'until' => '2024-07-28', 'limit' => 100, 'offset' => 200]],
398  $repo->exposed_parameters
399  );
400  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
401  }
402 
403  public function testGetResponseToRequestListIdentifiersNoMDFormatError(): void
404  {
405  $processor = new RequestProcessor(
406  $this->getWriter(),
407  $this->getSettings('prefix_'),
408  $repo = $this->getRepository(
409  null,
410  3,
411  'id1+2022-11-27',
412  'id2+2022-11-27',
413  'id3+2021-11-13'
414  ),
415  $this->getTokenHandler()
416  );
417 
418  $expected_response = <<<XML
419  <error_response>
420  <response_info>base url:ListIdentifiers:</response_info>
421  <error>badArgument</error>
422  </error_response>
423  XML;
424 
425  $response = $processor->getResponseToRequest($this->getRequest(
426  'base url',
427  Verb::LIST_IDENTIFIERS,
428  [],
429  false
430  ));
431 
432  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
433  }
434 
435  public function testGetResponseToRequestListIdentifiersAdditionalArgumentError(): void
436  {
437  $processor = new RequestProcessor(
438  $this->getWriter(),
439  $this->getSettings('prefix_'),
440  $repo = $this->getRepository(
441  null,
442  3,
443  'id1+2022-11-27',
444  'id2+2022-11-27',
445  'id3+2021-11-13'
446  ),
447  $this->getTokenHandler()
448  );
449 
450  $expected_response = <<<XML
451  <error_response>
452  <response_info>base url:ListIdentifiers:metadataPrefix=oai_dc,identifier=id</response_info>
453  <error>badArgument</error>
454  </error_response>
455  XML;
456 
457  $response = $processor->getResponseToRequest($this->getRequest(
458  'base url',
459  Verb::LIST_IDENTIFIERS,
460  [Argument::MD_PREFIX->value => 'oai_dc', Argument::IDENTIFIER->value => 'id'],
461  false
462  ));
463 
464  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
465  }
466 
467  public function testGetResponseToRequestListIdentifiersBadResumptionTokenError(): void
468  {
469  $original_request = $this->getRequest(
470  'base url',
471  Verb::LIST_IDENTIFIERS,
472  [Argument::RESUMPTION_TOKEN->value => 'next_offset=100:from=:until=2024-07-28'],
473  );
474 
475  $appended_request = $this->getRequest(
476  'base url',
477  Verb::LIST_IDENTIFIERS,
478  [
479  Argument::RESUMPTION_TOKEN->value => 'next_offset=100:from=:until=2024-07-28',
480  Argument::UNTIL_DATE->value => '2024-07-28'
481  ],
482  );
483 
484  $processor = new RequestProcessor(
485  $this->getWriter(),
486  $this->getSettings('prefix_'),
487  $repo = $this->getRepository(
488  null,
489  203,
490  'id1+2022-11-27',
491  'id2+2022-11-27',
492  'id3+2021-11-13'
493  ),
494  $this->getTokenHandler(false, $appended_request)
495  );
496 
497  $expected_response = <<<XML
498  <error_response>
499  <response_info>base url:ListIdentifiers:resumptionToken=next_offset=100:from=:until=2024-07-28</response_info>
500  <error>badResumptionToken</error>
501  </error_response>
502  XML;
503 
504  $response = $processor->getResponseToRequest($original_request);
505 
506  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
507  }
508 
509  public function testGetResponseToRequestListIdentifiersInvalidFromDateError(): void
510  {
511  $processor = new RequestProcessor(
512  $this->getWriter(),
513  $this->getSettings('prefix_'),
514  $repo = $this->getRepository(
515  null,
516  3,
517  'id1+2022-11-27',
518  'id2+2022-11-27',
519  'id3+2021-11-13'
520  ),
521  $this->getTokenHandler()
522  );
523 
524  $expected_response = <<<XML
525  <error_response>
526  <response_info>base url:ListIdentifiers:metadataPrefix=oai_dc,from=invalid</response_info>
527  <error>badArgument</error>
528  </error_response>
529  XML;
530 
531  $response = $processor->getResponseToRequest($this->getRequest(
532  'base url',
533  Verb::LIST_IDENTIFIERS,
534  [Argument::MD_PREFIX->value => 'oai_dc', Argument::FROM_DATE->value => 'invalid'],
535  ));
536 
537  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
538  }
539 
540  public function testGetResponseToRequestListIdentifiersInvalidUntilDateError(): void
541  {
542  $processor = new RequestProcessor(
543  $this->getWriter(),
544  $this->getSettings('prefix_'),
545  $repo = $this->getRepository(
546  null,
547  3,
548  'id1+2022-11-27',
549  'id2+2022-11-27',
550  'id3+2021-11-13'
551  ),
552  $this->getTokenHandler()
553  );
554 
555  $expected_response = <<<XML
556  <error_response>
557  <response_info>base url:ListIdentifiers:metadataPrefix=oai_dc,until=invalid</response_info>
558  <error>badArgument</error>
559  </error_response>
560  XML;
561 
562  $response = $processor->getResponseToRequest($this->getRequest(
563  'base url',
564  Verb::LIST_IDENTIFIERS,
565  [Argument::MD_PREFIX->value => 'oai_dc', Argument::UNTIL_DATE->value => 'invalid'],
566  ));
567 
568  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
569  }
570 
571  public function testGetResponseToRequestListIdentifiersWrongMDFormatError(): void
572  {
573  $processor = new RequestProcessor(
574  $this->getWriter(),
575  $this->getSettings('prefix_'),
576  $repo = $this->getRepository(
577  null,
578  3,
579  'id1+2022-11-27',
580  'id2+2022-11-27',
581  'id3+2021-11-13'
582  ),
583  $this->getTokenHandler()
584  );
585 
586  $expected_response = <<<XML
587  <error_response>
588  <response_info>base url:ListIdentifiers:metadataPrefix=invalid</response_info>
589  <error>cannotDisseminateFormat</error>
590  </error_response>
591  XML;
592 
593  $response = $processor->getResponseToRequest($this->getRequest(
594  'base url',
595  Verb::LIST_IDENTIFIERS,
596  [Argument::MD_PREFIX->value => 'invalid'],
597  ));
598 
599  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
600  }
601 
602  public function testGetResponseToRequestListIdentifiersNoRecordsFoundError(): void
603  {
604  $processor = new RequestProcessor(
605  $this->getWriter(),
606  $this->getSettings('prefix_'),
607  $repo = $this->getRepository(),
608  $this->getTokenHandler()
609  );
610 
611  $expected_response = <<<XML
612  <error_response>
613  <response_info>base url:ListIdentifiers:metadataPrefix=oai_dc</response_info>
614  <error>noRecordsMatch</error>
615  </error_response>
616  XML;
617 
618  $response = $processor->getResponseToRequest($this->getRequest(
619  'base url',
620  Verb::LIST_IDENTIFIERS,
621  [Argument::MD_PREFIX->value => 'oai_dc'],
622  ));
623 
624  $this->assertEquals(
625  [['from' => null, 'until' => null, 'limit' => 100, 'offset' => 0]],
626  $repo->exposed_parameters
627  );
628  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
629  }
630 
631  public function testGetResponseToRequestListIdentifiersNonDefaultSetError(): void
632  {
633  $processor = new RequestProcessor(
634  $this->getWriter(),
635  $this->getSettings('prefix_'),
636  $repo = $this->getRepository(
637  null,
638  3,
639  'id1+2022-11-27',
640  'id2+2022-11-27',
641  'id3+2021-11-13'
642  ),
643  $this->getTokenHandler()
644  );
645 
646  $expected_response = <<<XML
647  <error_response>
648  <response_info>base url:ListIdentifiers:metadataPrefix=oai_dc,set=set</response_info>
649  <error>noRecordsMatch</error>
650  </error_response>
651  XML;
652 
653  $response = $processor->getResponseToRequest($this->getRequest(
654  'base url',
655  Verb::LIST_IDENTIFIERS,
656  [Argument::MD_PREFIX->value => 'oai_dc', Argument::SET->value => 'set'],
657  ));
658 
659  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
660  }
661 
662  public function testGetResponseToRequestListIdentifiersMultipleErrors(): void
663  {
664  $processor = new RequestProcessor(
665  $this->getWriter(),
666  $this->getSettings('prefix_'),
667  $repo = $this->getRepository(),
668  $this->getTokenHandler()
669  );
670 
671  $expected_response = <<<XML
672  <error_response>
673  <response_info>base url:ListIdentifiers:metadataPrefix=invalid,until=also invalid,from=more invalid,set=set,identifier=id</response_info>
674  <error>badArgument</error>
675  <error>noRecordsMatch</error>
676  <error>cannotDisseminateFormat</error>
677  <error>badArgument</error>
678  <error>badArgument</error>
679  <error>noRecordsMatch</error>
680  </error_response>
681  XML;
682 
683  $response = $processor->getResponseToRequest($this->getRequest(
684  'base url',
685  Verb::LIST_IDENTIFIERS,
686  [
687  Argument::MD_PREFIX->value => 'invalid',
688  Argument::UNTIL_DATE->value => 'also invalid',
689  Argument::FROM_DATE->value => 'more invalid',
690  Argument::SET->value => 'set',
691  Argument::IDENTIFIER->value => 'id'
692  ],
693  false
694  ));
695 
696  $this->assertEquals(
697  [['from' => null, 'until' => null, 'limit' => 100, 'offset' => 0]],
698  $repo->exposed_parameters
699  );
700  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
701  }
702 }
$response
Definition: xapitoken.php:93
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
base()
description: > Example for rendering a bulky button.
Definition: base.php:35
more()
description: > Example for rendring a more glyph.
Definition: more.php:41
header()
expected output: > ILIAS shows the rendered Component.
Definition: header.php:29