Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 83f2625

Browse files
committed
ENH: refs #236. Add unit test for redundant content upload
1 parent e66b5a8 commit 83f2625

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

modules/api/controllers/components/ApiComponent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ function uploadGeneratetoken($args)
248248
$bitstream->setPath($existingBitstream->getPath());
249249
$bitstream->setAssetstoreId($existingBitstream->getAssetstoreId());
250250
$bitstream->setMimetype($existingBitstream->getMimetype());
251-
$revisionModel = $modelLoader->loadModel('Revision');
251+
$revisionModel = $modelLoader->loadModel('ItemRevision');
252252
$revisionModel->addBitstream($revision, $bitstream);
253253
return array('token' => '');
254254
}

modules/api/tests/controllers/ApiCallMethodsTest.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,17 +324,43 @@ public function testUpload()
324324
unlink(BASE_PATH.'/tmp/misc/test.txt');
325325

326326
$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');
328328
$this->assertEquals(md5_file($assetstoreFile), $md5, 'Assetstore file had incorrect checksum');
329329

330330
// make sure it was uploaded to the head revision of the item
331331
$itemDao = $this->Item->load($itemsFile[1]->getKey());
332332
$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');
334334
$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');
336336
$this->assertEquals($bitstreams[0]->name, 'test.txt');
337337
$this->assertEquals($bitstreams[0]->sizebytes, $length);
338338
$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);
339365
}
340366
}

0 commit comments

Comments
 (0)