Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 101 |
|
0.00% |
0 / 23 |
CRAP | |
0.00% |
0 / 1 |
FakeOverdriveConnector | |
0.00% |
0 / 101 |
|
0.00% |
0 / 23 |
702 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getUser | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAccess | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getAvailability | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAvailabilityBulk | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
20 | |||
getCollectionToken | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
doOverdriveCheckout | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
placeOverDriveHold | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
updateOverDriveHold | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
suspendHold | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
editSuspendedHold | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
deleteHoldSuspension | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
cancelHold | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
returnResource | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAuthHeader | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
getPermanentLinks | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getMagazineIssues | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
getMetadata | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getMetadataForTitles | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCheckout | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getHold | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCheckouts | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
getHolds | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * FakeOverdriveConnector |
5 | * |
6 | * Class responsible for simulating the Overdrive API for test purposes. |
7 | * |
8 | * PHP version 8 |
9 | * |
10 | * Copyright (C) Villanova University 2023. |
11 | * |
12 | * This program is free software; you can redistribute it and/or modify |
13 | * it under the terms of the GNU General Public License version 2, |
14 | * as published by the Free Software Foundation. |
15 | * |
16 | * This program is distributed in the hope that it will be useful, |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 | * GNU General Public License for more details. |
20 | * |
21 | * You should have received a copy of the GNU General Public License |
22 | * along with this program; if not, write to the Free Software |
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
24 | * USA |
25 | * |
26 | * @category VuFind |
27 | * @package DigitalContent |
28 | * @author Demian Katz <demian.katz@villanova.edu> |
29 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public |
30 | * License |
31 | * @link https://vufind.org/wiki/development Wiki |
32 | */ |
33 | |
34 | namespace VuFind\DigitalContent; |
35 | |
36 | use Laminas\Config\Config; |
37 | |
38 | /** |
39 | * FakeOverdriveConnector |
40 | * |
41 | * Class responsible for simulating the Overdrive API for test purposes. |
42 | * |
43 | * @category VuFind |
44 | * @package DigitalContent |
45 | * @author Demian Katz <demian.katz@villanova.edu> |
46 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public |
47 | * License |
48 | * @link https://vufind.org/wiki/development Wiki |
49 | */ |
50 | class FakeOverdriveConnector extends OverdriveConnector |
51 | { |
52 | /** |
53 | * Constructor |
54 | * |
55 | * @param Config $mainConfig VuFind main conf |
56 | * @param Config $recordConfig Record-specific conf file |
57 | */ |
58 | public function __construct( |
59 | Config $mainConfig, |
60 | Config $recordConfig |
61 | ) { |
62 | $this->mainConfig = $mainConfig; |
63 | $this->recordConfig = $recordConfig; |
64 | } |
65 | |
66 | /** |
67 | * Get (Logged-in) User |
68 | * |
69 | * Returns the currently logged in user or false if the user is not |
70 | * |
71 | * @return array|boolean an array of user info from the ILSAuthenticator |
72 | * or false if user is not logged in. |
73 | */ |
74 | public function getUser() |
75 | { |
76 | return []; |
77 | } |
78 | |
79 | /** |
80 | * Get Overdrive Access |
81 | * |
82 | * Whether the patron has access to overdrive actions (hold, |
83 | * checkout etc.). |
84 | * This is stored and retrieved from the session. |
85 | * |
86 | * @param bool $refresh Force a check instead of checking cache |
87 | * |
88 | * @return object |
89 | */ |
90 | public function getAccess($refresh = false) |
91 | { |
92 | return (object)[ |
93 | 'status' => true, |
94 | ]; |
95 | } |
96 | |
97 | /** |
98 | * Get Availability |
99 | * |
100 | * Retrieves the availability for a single resource from Overdrive API |
101 | * with information like copiesOwned, copiesAvailable, numberOfHolds et. |
102 | * |
103 | * @param string $overDriveId The Overdrive ID (reserve ID) of the eResource |
104 | * |
105 | * @return object Standard object with availability info |
106 | * |
107 | * @link https://developer.overdrive.com/apis/library-availability-new |
108 | */ |
109 | public function getAvailability($overDriveId) |
110 | { |
111 | return new \stdClass(); |
112 | } |
113 | |
114 | /** |
115 | * Get Availability (in) Bulk |
116 | * |
117 | * Gets availability for up to 25 titles at once. This is used by the |
118 | * the ajax availability system |
119 | * |
120 | * @param array $overDriveIds The Overdrive ID (reserve IDs) of the |
121 | * eResources |
122 | * |
123 | * @return object|bool see getAvailability |
124 | */ |
125 | public function getAvailabilityBulk($overDriveIds = []) |
126 | { |
127 | $data = []; |
128 | $statuses = ['od_code_resource_not_found', 'od_code_login_for_avail']; |
129 | foreach ($overDriveIds as $i => $id) { |
130 | $code = $statuses[$i] ?? ''; |
131 | if (empty($code)) { |
132 | $total = rand(1, 3); |
133 | $avail = rand(0, $total); |
134 | $holds = $avail === 0 ? rand(1, 100) : 0; |
135 | $data[$id] = (object)[ |
136 | 'code' => '', |
137 | 'copiesOwned' => $total, |
138 | 'copiesAvailable' => $avail, |
139 | 'numberOfHolds' => $holds, |
140 | ]; |
141 | } else { |
142 | $data[$id] = (object)compact('code'); |
143 | } |
144 | } |
145 | return (object)[ |
146 | 'status' => true, |
147 | 'data' => $data, |
148 | ]; |
149 | } |
150 | |
151 | /** |
152 | * Get Collection Token |
153 | * |
154 | * Gets the collection token for the Overdrive collection. The collection |
155 | * token doesn't change much but according to |
156 | * the OD API docs it could change and should be retrieved each session. |
157 | * Also, the collection token depends on the user if the user is in a |
158 | * consortium. If consortium support is turned on then the user collection |
159 | * token will override the library collection token. |
160 | * The token itself is returned but it's also saved in the session and |
161 | * automatically returned. |
162 | * |
163 | * @return object|bool A collection token for the library's collection. |
164 | */ |
165 | public function getCollectionToken() |
166 | { |
167 | return false; |
168 | } |
169 | |
170 | /** |
171 | * Overdrive Checkout |
172 | * Processes a request to checkout a title from Overdrive |
173 | * |
174 | * @param string $overDriveId The overdrive id for the title |
175 | * |
176 | * @return object $result Results of the call. |
177 | */ |
178 | public function doOverdriveCheckout($overDriveId) |
179 | { |
180 | return null; |
181 | } |
182 | |
183 | /** |
184 | * Places a hold on an item within OverDrive |
185 | * |
186 | * @param string $overDriveId The overdrive id for the title |
187 | * @param string $email The email overdrive should use for notif |
188 | * |
189 | * @return \stdClass Object with result |
190 | */ |
191 | public function placeOverDriveHold($overDriveId, $email) |
192 | { |
193 | return new \stdClass(); |
194 | } |
195 | |
196 | /** |
197 | * Updates the email address for a hold on an item within OverDrive |
198 | * |
199 | * @param string $overDriveId The overdrive id for the title |
200 | * @param string $email The email overdrive should use for notif |
201 | * |
202 | * @return \stdClass Object with result |
203 | */ |
204 | public function updateOverDriveHold($overDriveId, $email) |
205 | { |
206 | return (object)[ |
207 | 'status' => true, |
208 | 'msg' => '', |
209 | 'data' => false, |
210 | 'code' => 0, |
211 | ]; |
212 | } |
213 | |
214 | /** |
215 | * Suspend Hold |
216 | * Suspend an existing Overdrive Hold |
217 | * |
218 | * @param string $overDriveId The overdrive id for the title |
219 | * @param string $email The email overdrive should use for notif |
220 | * @param string $suspensionType indefinite or limited |
221 | * @param int $numberOfDays number of days to suspend the hold |
222 | * |
223 | * @return \stdClass Object with result |
224 | */ |
225 | public function suspendHold($overDriveId, $email, $suspensionType = 'indefinite', $numberOfDays = 7) |
226 | { |
227 | return (object)[ |
228 | 'status' => true, |
229 | 'msg' => '', |
230 | 'data' => false, |
231 | 'code' => 0, |
232 | ]; |
233 | } |
234 | |
235 | /** |
236 | * Edit Suspended Hold |
237 | * Change the redelivery date on an already suspended hold |
238 | * |
239 | * @param string $overDriveId The overdrive id for the title |
240 | * @param string $email The email overdrive should use for notif |
241 | * @param string $suspensionType indefinite or limited |
242 | * @param int $numberOfDays number of days to suspend the hold |
243 | * |
244 | * @return \stdClass Object with result |
245 | */ |
246 | public function editSuspendedHold($overDriveId, $email, $suspensionType = 'indefinite', $numberOfDays = 7) |
247 | { |
248 | return (object)[ |
249 | 'status' => true, |
250 | 'msg' => '', |
251 | 'data' => false, |
252 | 'code' => 0, |
253 | ]; |
254 | } |
255 | |
256 | /** |
257 | * Delete Suspended Hold |
258 | * Removes the suspension from a hold |
259 | * |
260 | * @param string $overDriveId The overdrive id for the title |
261 | * |
262 | * @return \stdClass Object with result |
263 | */ |
264 | public function deleteHoldSuspension($overDriveId) |
265 | { |
266 | return (object)[ |
267 | 'status' => true, |
268 | 'msg' => '', |
269 | 'data' => false, |
270 | 'code' => 0, |
271 | ]; |
272 | } |
273 | |
274 | /** |
275 | * Cancel Hold |
276 | * Cancel and existing Overdrive Hold |
277 | * |
278 | * @param string $overDriveId The overdrive id for the title |
279 | * |
280 | * @return \stdClass Object with result |
281 | */ |
282 | public function cancelHold($overDriveId) |
283 | { |
284 | return new \stdClass(); |
285 | } |
286 | |
287 | /** |
288 | * Return Resource |
289 | * Return a title early. |
290 | * |
291 | * @param string $resourceID Overdrive ID of the resource |
292 | * |
293 | * @return object|bool Object with result |
294 | */ |
295 | public function returnResource($resourceID) |
296 | { |
297 | return new \stdClass(); |
298 | } |
299 | |
300 | /** |
301 | * Retrieves the auth header needed to get the Download HTML snippet |
302 | * |
303 | * @return object Object containing the auth header in the data property |
304 | */ |
305 | public function getAuthHeader() |
306 | { |
307 | return (object)[ |
308 | 'status' => true, |
309 | 'msg' => '', |
310 | 'data' => false, |
311 | 'code' => 0, |
312 | ]; |
313 | } |
314 | |
315 | /** |
316 | * Returns permanant links for Ovedrive resources |
317 | * |
318 | * @param array $overDriveIds An array of overdrive IDs we need links for |
319 | * |
320 | * @return array<string> |
321 | */ |
322 | public function getPermanentLinks($overDriveIds = []) |
323 | { |
324 | return []; |
325 | } |
326 | |
327 | /** |
328 | * Returns all the issues for an overdrive magazine title |
329 | * |
330 | * @param string $overDriveId Overdrive Identifier for magazine title |
331 | * @param bool $checkouts Whether to add checkout information to each issue |
332 | * @param int $limit maximum number of issues to retrieve (default 100) |
333 | * @param int $offset page of results (default 0) |
334 | * |
335 | * @return object results of metadata fetch |
336 | */ |
337 | public function getMagazineIssues($overDriveId = false, $checkouts = false, $limit = 100, $offset = 0) |
338 | { |
339 | return (object)[ |
340 | 'status' => true, |
341 | 'msg' => '', |
342 | 'data' => false, |
343 | 'code' => 0, |
344 | ]; |
345 | } |
346 | |
347 | /** |
348 | * Returns a hash of metadata keyed on overdrive reserveID |
349 | * |
350 | * @param array $overDriveIds Set of Overdrive IDs |
351 | * |
352 | * @return array results of metadata fetch |
353 | */ |
354 | public function getMetadata($overDriveIds = []) |
355 | { |
356 | return []; |
357 | } |
358 | |
359 | /** |
360 | * For array of titles passed in this will return the same array |
361 | * with metadata attached to the records with the property name of 'metadata' |
362 | * |
363 | * @param array $overDriveTitles Assoc array of objects with OD IDs as keys (generally what |
364 | * you get from getCheckouts and getHolds) |
365 | * |
366 | * @return array initial array with results of metadata attached as "metadata" property |
367 | */ |
368 | public function getMetadataForTitles($overDriveTitles = []) |
369 | { |
370 | return []; |
371 | } |
372 | |
373 | /** |
374 | * Get Overdrive Checkout |
375 | * |
376 | * Get the overdrive checkout object for an overdrive title |
377 | * for the current user |
378 | * |
379 | * @param string $overDriveId Overdrive resource id |
380 | * @param bool $refresh Whether or not to ignore cache and get latest |
381 | * |
382 | * @return object|false PHP object that represents the checkout or false |
383 | * the checkout is not in the current list of checkouts for the current |
384 | * user. |
385 | */ |
386 | public function getCheckout($overDriveId, $refresh = true) |
387 | { |
388 | return false; |
389 | } |
390 | |
391 | /** |
392 | * Get Overdrive Hold |
393 | * |
394 | * Get the overdrive hold object for an overdrive title |
395 | * for the current user |
396 | * |
397 | * @param string $overDriveId Overdrive resource id |
398 | * @param bool $refresh Whether or not to ignore cache and get latest |
399 | * |
400 | * @return object|false PHP object that represents the checkout or false |
401 | * the checkout is not in the current list of checkouts for the current |
402 | * user. |
403 | */ |
404 | public function getHold($overDriveId, $refresh = true) |
405 | { |
406 | return false; |
407 | } |
408 | |
409 | /** |
410 | * Get Overdrive Checkouts (or a user) |
411 | * |
412 | * @param bool $refresh Whether or not to ignore cache and get latest |
413 | * |
414 | * @return object Results of the call |
415 | */ |
416 | public function getCheckouts($refresh = true) |
417 | { |
418 | return (object)[ |
419 | 'status' => true, |
420 | 'data' => [ |
421 | (object)[ |
422 | 'reserveId' => 'overdrive1', |
423 | 'expires' => date('Y-m-d'), |
424 | 'isReturnable' => true, |
425 | ], |
426 | ], |
427 | ]; |
428 | } |
429 | |
430 | /** |
431 | * Get Overdrive Holds (or a user) |
432 | * |
433 | * @param bool $refresh Whether or not to ignore cache and get latest |
434 | * |
435 | * @return \stdClass Results of the call |
436 | */ |
437 | public function getHolds($refresh = true) |
438 | { |
439 | return (object)[ |
440 | 'status' => true, |
441 | 'data' => [ |
442 | (object)[ |
443 | 'reserveId' => 'overdrive2', |
444 | 'holdPlacedDate' => date('Y-m-d'), |
445 | 'holdListPosition' => 6, |
446 | 'numberOfHolds' => 23, |
447 | 'emailAddress' => 'foo@example.com', |
448 | ], |
449 | (object)[ |
450 | 'reserveId' => 'overdrive3', |
451 | 'holdPlacedDate' => date('Y-m-d'), |
452 | 'holdListPosition' => 1, |
453 | 'numberOfHolds' => 1, |
454 | 'emailAddress' => 'foo@example.com', |
455 | ], |
456 | ], |
457 | ]; |
458 | } |
459 | } |