@@ -324,17 +324,43 @@ public function testUpload()
324
324
unlink (BASE_PATH .'/tmp/misc/test.txt ' );
325
325
326
326
$ this ->assertTrue (file_exists ($ assetstoreFile ), 'File was not written to the assetstore ' );
327
- $ this ->assertEquals (filesize ($ assetstoreFile ), $ length , 'Assetstore file is the wrong length: ' . filesize ( $ assetstoreFile ) );
327
+ $ this ->assertEquals (filesize ($ assetstoreFile ), $ length , 'Assetstore file is the wrong length ' );
328
328
$ this ->assertEquals (md5_file ($ assetstoreFile ), $ md5 , 'Assetstore file had incorrect checksum ' );
329
329
330
330
// make sure it was uploaded to the head revision of the item
331
331
$ itemDao = $ this ->Item ->load ($ itemsFile [1 ]->getKey ());
332
332
$ revisions = $ itemDao ->getRevisions ();
333
- $ this ->assertEquals (count ($ revisions ), 1 , 'Too many revisions in the item ' );
333
+ $ this ->assertEquals (count ($ revisions ), 1 , 'Wrong number of revisions in the item ' );
334
334
$ bitstreams = $ revisions [0 ]->getBitstreams ();
335
- $ this ->assertEquals (count ($ bitstreams ), 1 , 'Too many bitstreams in the revision ' );
335
+ $ this ->assertEquals (count ($ bitstreams ), 1 , 'Wrong number of bitstreams in the revision ' );
336
336
$ this ->assertEquals ($ bitstreams [0 ]->name , 'test.txt ' );
337
337
$ this ->assertEquals ($ bitstreams [0 ]->sizebytes , $ length );
338
338
$ this ->assertEquals ($ bitstreams [0 ]->checksum , $ md5 );
339
+
340
+ // Check that a redundant upload yields a blank upload token and a new reference
341
+ $ this ->resetAll ();
342
+ $ this ->params ['token ' ] = $ this ->_loginUsingApiKey ();
343
+ $ this ->params ['method ' ] = 'midas.upload.generatetoken ' ;
344
+ $ this ->params ['filename ' ] = 'test2.txt ' ;
345
+ $ this ->params ['checksum ' ] = $ md5 ;
346
+ $ this ->params ['itemid ' ] = $ itemsFile [1 ]->getKey ();
347
+ $ this ->request ->setMethod ('POST ' );
348
+ $ resp = $ this ->_callJsonApi ();
349
+ $ this ->_assertStatusOk ($ resp );
350
+
351
+ $ token = $ resp ->data ->token ;
352
+ $ this ->assertEquals ($ token , '' , 'Redundant content upload did not return a blank token ' );
353
+
354
+ $ itemDao = $ this ->Item ->load ($ itemsFile [1 ]->getKey ());
355
+ $ revisions = $ itemDao ->getRevisions ();
356
+ $ this ->assertEquals (count ($ revisions ), 1 , 'Wrong number of revisions in the item ' );
357
+ $ bitstreams = $ revisions [0 ]->getBitstreams ();
358
+ $ this ->assertEquals (count ($ bitstreams ), 2 , 'Wrong number of bitstreams in the revision ' );
359
+ $ this ->assertEquals ($ bitstreams [0 ]->name , 'test.txt ' );
360
+ $ this ->assertEquals ($ bitstreams [0 ]->sizebytes , $ length );
361
+ $ this ->assertEquals ($ bitstreams [0 ]->checksum , $ md5 );
362
+ $ this ->assertEquals ($ bitstreams [1 ]->name , 'test2.txt ' );
363
+ $ this ->assertEquals ($ bitstreams [1 ]->sizebytes , $ length );
364
+ $ this ->assertEquals ($ bitstreams [1 ]->checksum , $ md5 );
339
365
}
340
366
}
0 commit comments