Open Journal Systems  3.3.0
test-swordappclient.php
1 <?php
2  // Test the V2 PHP client implementation using the Simple SWORD Server (SSS)
3 
4  // The URL of the service document
5  $testurl = "http://localhost/sss/sd-uri";
6 
7  // The user (if required)
8  $testuser = "sword";
9 
10  // The password of the user (if required)
11  $testpw = "sword";
12 
13  // The on-behalf-of user (if required)
14  //$testobo = "user@swordapp.com";
15 
16  // The URL of the example deposit collection
17  $testdepositurl = "http://localhost/sss/col-uri/da9b9feb-4266-446a-8847-46f6c30b2ff0";
18 
19  // The test atom entry to deposit
20  $testatomentry = "test-files/atom_multipart/atom";
21 
22  // The second test atom entry to deposit
23  $testatomentry2 = "test-files/atom_multipart/atom2";
24 
25  // The test atom multipart file to deposit
26  $testmultipart = "test-files/atom_multipart_package";
27 
28  // The second test file to deposit
29  $testmultipart2 = "test-files/atom_multipart_package2";
30 
31  // The test content zip file to deposit
32  $testzipcontentfile = "test-files/atom_multipart_package2.zip";
33 
34  // A plain content file
35  $testextrafile = "test-files/swordlogo.jpg";
36 
37  // The file type of the extra file
38  $testextrafiletype = "image/jpg";
39 
40  // The content type of the test file
41  $testcontenttype = "application/zip";
42 
43  // The packaging format of the test file
44  $testpackaging = "http://purl.org/net/sword/package/SimpleZip";
45 
46  require("../swordappclient.php");
47  $testsac = new SWORDAPPClient();
48 
49  if (false) {
50  print "About to request servicedocument from " . $testurl . "\n";
51  if (empty($testuser)) {
52  print "As: anonymous\n";
53  } else {
54  print "As: " . $testuser . "\n";
55  }
56  $testsdr = $testsac->servicedocument($testurl, $testuser, $testpw, $testobo);
57  print "Received HTTP status code: " . $testsdr->sac_status . " (" . $testsdr->sac_statusmessage . ")\n";
58 
59  if ($testsdr->sac_status == 200) {
60  $testsdr->toString();
61  }
62 
63  print "\n\n";
64  }
65 
66  if (true) {
67  print "About to deposit multipart file (" . $testmultipart . ") to " . $testdepositurl . "\n";
68  if (empty($testuser)) {
69  print "As: anonymous\n";
70  } else {
71  print "As: " . $testuser . "\n";
72  }
73  $testdr = $testsac->depositMultipart($testdepositurl, $testuser, $testpw, $testobo, $testmultipart, $testpackaging, false);
74  print "Received HTTP status code: " . $testdr->sac_status . " (" . $testdr->sac_statusmessage . ")\n";
75 
76  if (($testdr->sac_status >= 200) || ($testdr->sac_status < 300)) {
77  $testdr->toString();
78  }
79 
80  print "\n\n";
81 
82  $edit_iri = $testdr->sac_edit_iri;
83  $cont_iri = $testdr->sac_content_src;
84  $edit_media = $testdr->sac_edit_media_iri;
85  $statement_atom = $testdr->sac_state_iri_atom;
86  $statement_ore = $testdr->sac_state_iri_ore;
87  }
88 
89  if (false) {
90  print "About to request Atom serialisation of the deposit statement from " . $statement_atom . "\n";
91  if (empty($testuser)) {
92  print "As: anonymous\n";
93  } else {
94  print "As: " . $testuser . "\n";
95  }
96  $testatomstatement = $testsac->retrieveAtomStatement($statement_atom, $testuser, $testpw, $testobo);
97 
98  if (($testatomstatement->sac_status >= 200) || ($testatomstatement->sac_status < 300)) {
99  $testatomstatement->toString();
100  }
101 
102  print "\n\n";
103  }
104 
105  if (false) {
106  print "About to request OAI-ORE serialisation of the deposit statement from " . $statement_ore . "\n";
107  if (empty($testuser)) {
108  print "As: anonymous\n";
109  } else {
110  print "As: " . $testuser . "\n";
111  }
112  $testoaiore = $testsac->retrieveOAIOREStatement($statement_ore, $testuser, $testpw, $testobo);
113  echo $testoaiore;
114 
115  print "\n\n";
116  }
117 
118  if (false) {
119  print "About to retrieve content from " . $edit_media . "\n";
120  if (empty($testuser)) {
121  print "As: anonymous\n";
122  } else {
123  print "As: " . $testuser . "\n";
124  }
125  $testresp = $testsac->retrieveContent($edit_media, $testuser, $testpw, $testobo, "http://purl.org/net/sword/package/SimpleZip");
126  // file_put_contents("temp-save.zip", $testresp);
127 
128  print "\n\n";
129  }
130 
131  if (false) {
132  print "About to replace content at " . $edit_media . "\n";
133  if (empty($testuser)) {
134  print "As: anonymous\n";
135  } else {
136  print "As: " . $testuser . "\n";
137  }
138  $status = $testsac->replaceFileContent($edit_media, $testuser, $testpw, $testobo, $testzipcontentfile, $testpackaging, $testcontenttype, false);
139  print "Received HTTP status code: " . $status . "\n";
140  if ($status == 204) {
141  echo "Content replaced\n";
142  }
143 
144  print "\n\n";
145  }
146 
147  if (false) {
148  print "About to replace atom entry (" . $testatomentry2 . ") to " . $edit_iri . "\n";
149  if (empty($testuser)) {
150  print "As: anonymous\n";
151  } else {
152  print "As: " . $testuser . "\n";
153  }
154  $testdr = $testsac->replaceMetadata($edit_iri, $testuser, $testpw, $testobo, $testatomentry2, false);
155  print "Received HTTP status code: " . $testdr->sac_status .
156  " (" . $testdr->sac_statusmessage . ")\n";
157 
158  if (($testdr->sac_status >= 200) || ($testdr->sac_status < 300)) {
159  $testdr->toString();
160  }
161 
162  print "\n\n";
163  }
164 
165  if (false) {
166  print "About to replace multipart atom entry and file (" . $testmultipart2 . ") to " . $edit_iri . "\n";
167  if (empty($testuser)) {
168  print "As: anonymous\n";
169  } else {
170  print "As: " . $testuser . "\n";
171  }
172  $testdr = $testsac->replaceMetadataAndFile($edit_iri, $testuser, $testpw, $testobo, $testmultipart2, $testpackaging, false);
173  print "Received HTTP status code: " . $testdr->sac_status .
174  " (" . $testdr->sac_statusmessage . ")\n";
175 
176  if (($testdr->sac_status >= 200) || ($testdr->sac_status < 300)) {
177  $testdr->toString();
178  }
179 
180  print "\n\n";
181  }
182 
183  if (false) {
184  print "About to add file (" . $testextrafile . ") to " . $edit_media . "\n";
185  if (empty($testuser)) {
186  print "As: anonymous\n";
187  } else {
188  print "As: " . $testuser . "\n";
189  }
190  $testdr = $testsac->addExtraFileToMediaResource($edit_media, $testuser, $testpw, $testobo, $testextrafile, $testextrafiletype, false);
191  print "Received HTTP status code: " . $testdr->sac_status .
192  " (" . $testdr->sac_statusmessage . ")\n";
193 
194  if (($testdr->sac_status >= 200) || ($testdr->sac_status < 300)) {
195  $testdr->toString();
196  }
197 
198  print "\n\n";
199  }
200 
201  if (false) {
202  print "About to add package (" . $testzipcontentfile . ") to " . $edit_iri . "\n";
203  if (empty($testuser)) {
204  print "As: anonymous\n";
205  } else {
206  print "As: " . $testuser . "\n";
207  }
208  $testdr = $testsac->addExtraPackage($edit_iri, $testuser, $testpw, $testobo, $testzipcontentfile, $testpackaging, $testcontenttype, false);
209  print "Received HTTP status code: " . $testdr->sac_status .
210  " (" . $testdr->sac_statusmessage . ")\n";
211 
212  if (($testdr->sac_status >= 200) || ($testdr->sac_status < 300)) {
213  $testdr->toString();
214  }
215 
216  print "\n\n";
217  }
218 
219  if (false) {
220  print "About to add atom entry (" . $testatomentry2 . ") to " . $edit_iri . "\n";
221  if (empty($testuser)) {
222  print "As: anonymous\n";
223  } else {
224  print "As: " . $testuser . "\n";
225  }
226  $testdr = $testsac->addExtraAtomEntry($edit_iri, $testuser, $testpw, $testobo, $testatomentry2, false);
227  print "Received HTTP status code: " . $testdr->sac_status .
228  " (" . $testdr->sac_statusmessage . ")\n";
229 
230  if (($testdr->sac_status >= 200) || ($testdr->sac_status < 300)) {
231  $testdr->toString();
232  }
233 
234  print "\n\n";
235  }
236 
237  if (false) {
238  print "About to add multipart atom entry and file (" . $testmultipart2 . ") to " . $edit_iri . "\n";
239  if (empty($testuser)) {
240  print "As: anonymous\n";
241  } else {
242  print "As: " . $testuser . "\n";
243  }
244  $testdr = $testsac->addExtraMultipartPackage($edit_iri, $testuser, $testpw, $testobo, $testmultipart2, $testpackaging, false);
245  print "Received HTTP status code: " . $testdr->sac_status .
246  " (" . $testdr->sac_statusmessage . ")\n";
247 
248  if (($testdr->sac_status >= 200) || ($testdr->sac_status < 300)) {
249  $testdr->toString();
250  }
251 
252  print "\n\n";
253  }
254 
255 
276  if (false) {
277  print "About to delete container at " . $edit_iri . "\n";
278  if (empty($testuser)) {
279  print "As: anonymous\n";
280  } else {
281  print "As: " . $testuser . "\n";
282  }
283  try {
284  $deleteresponse = $testsac->deleteContainer($edit_iri, $testuser, $testpw, $testobo);
285  print " - Container successfully deleted, HTTP code 204\n";
286  } catch (Exception $e) {
287  echo $e->getMessage();
288  }
289 
290  print "\n\n";
291  }
292 
293  if (false) {
294  print "About to deposit atom entry (" . $testatomentry . ") to " . $testdepositurl . "\n";
295  if (empty($testuser)) {
296  print "As: anonymous\n";
297  } else {
298  print "As: " . $testuser . "\n";
299  }
300  $testdr = $testsac->depositAtomEntry($testdepositurl, $testuser, $testpw, $testobo, $testatomentry, false);
301  print "Received HTTP status code: " . $testdr->sac_status .
302  " (" . $testdr->sac_statusmessage . ")\n";
303 
304  if (($testdr->sac_status >= 200) || ($testdr->sac_status < 300)) {
305  $testdr->toString();
306  }
307 
308  print "\n\n";
309 
310  $edit_iri = $testdr->sac_edit_iri;
311  $cont_iri = $testdr->sac_content_src;
312  $edit_media = $testdr->sac_edit_media_iri;
313  $statement_atom = $testdr->sac_state_iri_atom;
314  $statement_ore = $testdr->sac_state_iri_ore;
315  }
316 
317  if (true) {
318  print "About to retrieve deposit receipt from " . $edit_iri . "\n";
319  if (empty($testuser)) {
320  print "As: anonymous\n";
321  } else {
322  print "As: " . $testuser . "\n";
323  }
324  $testdr = $testsac->retrieveDepositReceipt($edit_iri, $testuser, $testpw, $testobo, "http://purl.org/net/sword/package/SimpleZip");
325  print "Received HTTP status code: " . $testsdr->sac_status . " (" . $testsdr->sac_statusmessage . ")\n";
326  if ($testdr->sac_status == 200) {
327  $testdr->toString();
328  }
329 
330  print "\n\n";
331  }
332 
333 ?>
SWORDAPPClient
Definition: swordappclient.php:12