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

Commit 575f703

Browse files
committed
ENH: refs #260. Add a download bitstream test that verifies checksum
1 parent c7ea6ed commit 575f703

File tree

4 files changed

+128
-90
lines changed

4 files changed

+128
-90
lines changed

core/controllers/DownloadController.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DownloadController extends AppController
2929
public function indexAction()
3030
{
3131
set_time_limit(0);
32-
$this->_helper->layout->disableLayout();
32+
$this->disableLayout();
3333
$itemIds = $this->_getParam('items');
3434
$folderIds = $this->_getParam('folders');
3535
if(!isset($itemIds) && !isset($folderIds))
@@ -78,6 +78,7 @@ public function indexAction()
7878
{
7979
continue;
8080
}
81+
8182
$this->Item->incrementDownloadCount($item);
8283
if(isset($tmp[1]))
8384
{
@@ -100,12 +101,19 @@ public function indexAction()
100101

101102
if(empty($folders) && empty($revisions))
102103
{
103-
throw new Zend_Exception("No element");
104+
throw new Zend_Exception('There is nothing to download');
104105
}
105106
if(empty($folders) && count($revisions) == 1)
106107
{
107108
$revision = $revisions[0];
108109
$bitstreams = $revision->getBitstreams();
110+
111+
if($this->_getParam('testingmode') == '1')
112+
{
113+
$bitstreams = array($bitstreams[0]);
114+
$this->view->testingmode = true;
115+
}
116+
109117
if(count($bitstreams) == 0)
110118
{
111119
throw new Zend_Exception("Empty item");

core/tests/controllers/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
add_midas_test( IndexController IndexControllerTest.php )
22
add_midas_test( FeedController FeedControllerTest.php )
33
add_midas_test( UserController UserControllerTest.php )
4-
add_midas_test( UploadController UploadControllerTest.php )
4+
add_midas_test( UploadDownloadController UploadDownloadControllerTest.php )
55

66

77
# Syle

core/tests/controllers/UploadControllerTest.php renamed to core/tests/controllers/UploadDownloadControllerTest.php

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,64 +9,67 @@
99
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
1010
PURPOSE. See the above copyright notices for more information.
1111
=========================================================================*/
12-
/** test upload controller*/
13-
class UploadControllerTest extends ControllerTestCase
12+
/**
13+
* Tests uploading and downloading of files
14+
*/
15+
class UploadDownloadControllerTest extends ControllerTestCase
1416
{
1517
/** init tests*/
1618
public function setUp()
1719
{
18-
$this->setupDatabase(array('default'));
1920
$this->_models = array('User', 'Feed', 'Assetstore', 'Item');
2021
$this->_daos = array('User', 'Assetstore');
2122
parent::setUp();
2223
}
2324

24-
/** testGethttpuploadoffsetAction*/
25+
/** test UploadController::GethttpuploadoffsetAction*/
2526
function testGethttpuploadoffsetAction()
2627
{
28+
$this->setupDatabase(array('default'));
2729
$identifier = BASE_PATH.'/tmp/misc/httpupload.png';
2830
if(file_exists($identifier))
2931
{
3032
unlink($identifier);
3133
}
3234
copy(BASE_PATH.'/tests/testfiles/search.png', $identifier);
33-
$page = "upload/gethttpuploadoffset/?uploadUniqueIdentifier=httpupload.png&testingmode=1";
35+
$page = 'upload/gethttpuploadoffset/?uploadUniqueIdentifier=httpupload.png&testingmode=1';
3436
$this->dispatchUrI($page);
3537

3638
$content = $this->getBody();
37-
if(strpos($content, "[OK]") === false)
39+
if(strpos($content, '[OK]') === false)
3840
{
3941
$this->fail();
4042
}
41-
if(strpos($content, "[ERROR]") !== false)
43+
if(strpos($content, '[ERROR]') !== false)
4244
{
4345
$this->fail();
4446
}
4547
}
4648

47-
/** gethttpuploaduniqueidentifierAction*/
49+
/** test UploadController::gethttpuploaduniqueidentifierAction*/
4850
function testGethttpuploaduniqueidentifierAction()
4951
{
52+
$this->setupDatabase(array('default'));
5053
$identifier = BASE_PATH.'/tmp/misc/httpupload.png';
5154
if(file_exists($identifier))
5255
{
5356
unlink($identifier);
5457
}
5558
copy(BASE_PATH.'/tests/testfiles/search.png', $identifier);
56-
$page = "upload/gethttpuploaduniqueidentifier/?filename=httpupload.png&testingmode=1";
59+
$page = 'upload/gethttpuploaduniqueidentifier/?filename=httpupload.png&testingmode=1';
5760
$this->dispatchUrI($page);
5861
$content = $this->getBody();
59-
if(strpos($content, "[OK]") === false)
62+
if(strpos($content, '[OK]') === false)
6063
{
6164
$this->fail();
6265
}
63-
if(strpos($content, "[ERROR]") !== false)
66+
if(strpos($content, '[ERROR]') !== false)
6467
{
6568
$this->fail();
6669
}
6770
}
6871

69-
/** processjavaupload*/
72+
/** test UploadController::processjavaupload*/
7073
function testProcessjavauploadAction()
7174
{
7275
$this->setupDatabase(array('default'));
@@ -79,15 +82,15 @@ function testProcessjavauploadAction()
7982
unlink($identifier);
8083
}
8184
copy($fileBase, $file);
82-
$ident = fopen($identifier, "x+");
83-
fwrite($ident, " ");
85+
$ident = fopen($identifier, 'x+');
86+
fwrite($ident, ' ');
8487
fclose($ident);
8588
chmod($identifier, 0777);
8689

87-
$params = "testingmode=1&filename=search.png&path=".$file."&length=".filesize($file)."&uploadUniqueIdentifier=".basename($identifier);
88-
$page = $this->webroot."item/process_http_upload/".$this->item."?".$params;
90+
$params = 'testingmode=1&filename=search.png&path='.$file.'&length='.filesize($file).'&uploadUniqueIdentifier='.basename($identifier);
91+
$page = $this->webroot.'item/process_http_upload/'.$this->item.'?'.$params;
8992

90-
$page = "upload/processjavaupload/?".$params;
93+
$page = 'upload/processjavaupload/?'.$params;
9194

9295
$usersFile = $this->loadData('User', 'default');
9396
$userDao = $this->User->load($usersFile[0]->getKey());
@@ -101,27 +104,29 @@ function testProcessjavauploadAction()
101104
$this->setupDatabase(array('default'));
102105
}
103106

104-
/** simpleuploadAction*/
107+
/** test UploadController::simpleuploadAction*/
105108
function testSimpleuploadAction()
106109
{
110+
$this->setupDatabase(array('default'));
107111
$this->dispatchUrI("/upload/simpleupload", null, true);
108112

109113
$usersFile = $this->loadData('User', 'default');
110114
$userDao = $this->User->load($usersFile[0]->getKey());
111115

112116
$folder = $userDao->getPublicFolder();
113-
$this->dispatchUrI("/upload/simpleupload?parent=".$folder->getKey(), $userDao, false);
117+
$this->dispatchUrI('/upload/simpleupload?parent='.$folder->getKey(), $userDao, false);
114118
$this->assertContains('id="destinationId" value="'.$folder->getKey(), $this->getBody());
115119

116120
$this->resetAll();
117121
$folder = $userDao->getPrivateFolder();
118-
$this->dispatchUrI("/upload/simpleupload", $userDao, false);
122+
$this->dispatchUrI('/upload/simpleupload', $userDao, false);
119123
$this->assertContains('id="destinationId" value="'.$folder->getKey(), $this->getBody());
120124
}
121125

122-
/** revision*/
126+
/** test UploadController::revision */
123127
function testRevision()
124128
{
129+
$this->setupDatabase(array('default'));
125130
$this->dispatchUrI("/upload/revision", null, true);
126131

127132
$usersFile = $this->loadData('User', 'default');
@@ -133,9 +138,10 @@ function testRevision()
133138
$this->dispatchUrI("/upload/revision?itemId=".$itemDao->getKey(), $userDao);
134139
}
135140

136-
/** savelink*/
141+
/** test UploadController::savelink */
137142
function testSavelinkAction()
138143
{
144+
$this->setupDatabase(array('default'));
139145
$this->dispatchUrI("/upload/savelink", null, true);
140146

141147
$usersFile = $this->loadData('User', 'default');
@@ -149,7 +155,7 @@ function testSavelinkAction()
149155
$this->params['name'] = 'test name link';
150156
$this->params['url'] = 'http://www.kitware.com';
151157
$this->params['license'] = 0;
152-
$this->dispatchUrI("/upload/savelink", $userDao);
158+
$this->dispatchUrI('/upload/savelink', $userDao);
153159

154160
$search = $this->Item->getItemsFromSearch($this->params['name'], $userDao);
155161
if(empty($search))
@@ -159,8 +165,8 @@ function testSavelinkAction()
159165
$this->setupDatabase(array('default'));
160166
}
161167

162-
/** saveuploadedAction*/
163-
function testDaveuploadedAction()
168+
/** test UploadController::saveuploadedAction*/
169+
function testSaveuploadedAction()
164170
{
165171
$this->setupDatabase(array('default'));
166172

@@ -170,14 +176,31 @@ function testDaveuploadedAction()
170176
$this->params = array();
171177
$this->params['parent'] = $userDao->getPublicFolder()->getKey();
172178
$this->params['license'] = 0;
173-
$this->dispatchUrI("/upload/saveuploaded", $userDao);
179+
$this->dispatchUrI('/upload/saveuploaded', $userDao);
174180

175181
$search = $this->Item->getItemsFromSearch('search.png', $userDao);
176182
if(empty($search))
177183
{
178184
$this->fail('Unable to find item');
179185
}
180-
$this->setupDatabase(array('default'));
181186
}
182187

188+
/**
189+
* Test the download controller in the case of a one-bitstream item
190+
*/
191+
function testDownloadBitstream()
192+
{
193+
$usersFile = $this->loadData('User', 'default');
194+
$userDao = $this->User->load($usersFile[0]->getKey());
195+
$actualMd5 = md5_file(BASE_PATH.'/tmp/misc/httpupload.png');
196+
197+
$search = $this->Item->getItemsFromSearch('search.png', $userDao);
198+
$this->assertTrue(count($search) > 0);
199+
$itemId = $search[0]->item_id;
200+
201+
$this->dispatchUrI('/download?testingmode=1&items='.$itemId, $userDao);
202+
$downloadedMd5 = md5($this->getBody());
203+
204+
$this->assertEquals($actualMd5, $downloadedMd5);
205+
}
183206
}

0 commit comments

Comments
 (0)