ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
RequestProcessorGetRecordTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 
26 class RequestProcessorGetRecordTest extends RequestProcessorTestCase
27 {
28  public function testGetResponseToRequestGetRecord(): void
29  {
30  $processor = new RequestProcessor(
31  $this->getWriter(),
32  $this->getSettings('prefix_'),
33  $this->getRepository(null, 0, 'id+2022-11-27'),
34  $this->getTokenHandler()
35  );
36 
37  $expected_response = <<<XML
38  <response>
39  <response_info>base url:GetRecord:identifier=prefix_id+2022-11-27,metadataPrefix=oai_dc</response_info>
40  <record>
41  <record_info>prefix_id+2022-11-27:2022-11-27</record_info>
42  <md>md for id+2022-11-27</md>
43  </record>
44  </response>
45  XML;
46 
47  $response = $processor->getResponseToRequest($this->getRequest(
48  'base url',
49  Verb::GET_RECORD,
50  [Argument::IDENTIFIER->value => 'prefix_id+2022-11-27', Argument::MD_PREFIX->value => 'oai_dc']
51  ));
52 
53  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
54  }
55 
56  public function testGetResponseToRequestGetRecordNoMDFormatError(): void
57  {
58  $processor = new RequestProcessor(
59  $this->getWriter(),
60  $this->getSettings('prefix_'),
61  $this->getRepository(null, 0, 'id+2022-11-27'),
62  $this->getTokenHandler()
63  );
64 
65  $expected_response = <<<XML
66  <error_response>
67  <response_info>base url:GetRecord:identifier=prefix_id+2022-11-27</response_info>
68  <error>badArgument</error>
69  </error_response>
70  XML;
71 
72  $response = $processor->getResponseToRequest($this->getRequest(
73  'base url',
74  Verb::GET_RECORD,
75  [Argument::IDENTIFIER->value => 'prefix_id+2022-11-27'],
76  false
77  ));
78 
79  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
80  }
81 
82  public function testGetResponseToRequestGetRecordNoIdentifierError(): void
83  {
84  $processor = new RequestProcessor(
85  $this->getWriter(),
86  $this->getSettings('prefix_'),
87  $this->getRepository(null, 0, 'id+2022-11-27'),
88  $this->getTokenHandler()
89  );
90 
91  $expected_response = <<<XML
92  <error_response>
93  <response_info>base url:GetRecord:metadataPrefix=oai_dc</response_info>
94  <error>badArgument</error>
95  </error_response>
96  XML;
97 
98  $response = $processor->getResponseToRequest($this->getRequest(
99  'base url',
100  Verb::GET_RECORD,
101  [Argument::MD_PREFIX->value => 'oai_dc'],
102  false
103  ));
104 
105  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
106  }
107 
108  public function testGetResponseToRequestGetRecordAdditionalArgumentError(): void
109  {
110  $processor = new RequestProcessor(
111  $this->getWriter(),
112  $this->getSettings('prefix_'),
113  $this->getRepository(null, 0, 'id+2022-11-27'),
114  $this->getTokenHandler()
115  );
116 
117  $expected_response = <<<XML
118  <error_response>
119  <response_info>base url:GetRecord:identifier=prefix_id+2022-11-27,metadataPrefix=oai_dc,from=date</response_info>
120  <error>badArgument</error>
121  </error_response>
122  XML;
123 
124  $response = $processor->getResponseToRequest($this->getRequest(
125  'base url',
126  Verb::GET_RECORD,
127  [Argument::IDENTIFIER->value => 'prefix_id+2022-11-27', Argument::MD_PREFIX->value => 'oai_dc', Argument::FROM_DATE->value => 'date'],
128  false
129  ));
130 
131 
132  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
133  }
134 
135  public function testGetResponseToRequestGetRecordWrongMDFormatError(): void
136  {
137  $processor = new RequestProcessor(
138  $this->getWriter(),
139  $this->getSettings('prefix_'),
140  $this->getRepository(null, 0, 'id+2022-11-27'),
141  $this->getTokenHandler()
142  );
143 
144  $expected_response = <<<XML
145  <error_response>
146  <response_info>base url:GetRecord:identifier=prefix_id+2022-11-27,metadataPrefix=invalid</response_info>
147  <error>cannotDisseminateFormat</error>
148  </error_response>
149  XML;
150 
151  $response = $processor->getResponseToRequest($this->getRequest(
152  'base url',
153  Verb::GET_RECORD,
154  [Argument::IDENTIFIER->value => 'prefix_id+2022-11-27', Argument::MD_PREFIX->value => 'invalid']
155  ));
156 
157  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
158  }
159 
160  public function testGetResponseToRequestGetRecordInvalidIdentifierError(): void
161  {
162  $processor = new RequestProcessor(
163  $this->getWriter(),
164  $this->getSettings('prefix_'),
165  $this->getRepository(null, 0, 'id+2022-11-27'),
166  $this->getTokenHandler()
167  );
168 
169  $expected_response = <<<XML
170  <error_response>
171  <response_info>base url:GetRecord:identifier=invalid_id+2022-11-27,metadataPrefix=oai_dc</response_info>
172  <error>idDoesNotExist</error>
173  </error_response>
174  XML;
175 
176  $response = $processor->getResponseToRequest($this->getRequest(
177  'base url',
178  Verb::GET_RECORD,
179  [Argument::IDENTIFIER->value => 'invalid_id+2022-11-27', Argument::MD_PREFIX->value => 'oai_dc']
180  ));
181 
182  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
183  }
184 
185  public function testGetResponseToRequestGetRecordNotFoundError(): void
186  {
187  $processor = new RequestProcessor(
188  $this->getWriter(),
189  $this->getSettings('prefix_'),
190  $this->getRepository(),
191  $this->getTokenHandler()
192  );
193 
194  $expected_response = <<<XML
195  <error_response>
196  <response_info>base url:GetRecord:identifier=prefix_id+2022-11-27,metadataPrefix=oai_dc</response_info>
197  <error>idDoesNotExist</error>
198  </error_response>
199  XML;
200 
201  $response = $processor->getResponseToRequest($this->getRequest(
202  'base url',
203  Verb::GET_RECORD,
204  [Argument::IDENTIFIER->value => 'prefix_id+2022-11-27', Argument::MD_PREFIX->value => 'oai_dc']
205  ));
206 
207  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
208  }
209 
210  public function testGetResponseToRequestGetRecordMultipleErrors(): void
211  {
212  $processor = new RequestProcessor(
213  $this->getWriter(),
214  $this->getSettings('prefix_'),
215  $this->getRepository(),
216  $this->getTokenHandler()
217  );
218 
219  $expected_response = <<<XML
220  <error_response>
221  <response_info>base url:GetRecord:identifier=prefix_id+2022-11-27,metadataPrefix=invalid,from=date</response_info>
222  <error>badArgument</error>
223  <error>cannotDisseminateFormat</error>
224  <error>idDoesNotExist</error>
225  </error_response>
226  XML;
227 
228  $response = $processor->getResponseToRequest($this->getRequest(
229  'base url',
230  Verb::GET_RECORD,
231  [Argument::IDENTIFIER->value => 'prefix_id+2022-11-27', Argument::MD_PREFIX->value => 'invalid', Argument::FROM_DATE->value => 'date'],
232  false
233  ));
234 
235  $this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
236  }
237 }
$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