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

Commit 2b02f6d

Browse files
committed
ENH: refs #0306. Fix UploadDownload test
1 parent d0d7bb1 commit 2b02f6d

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

core/controllers/UploadController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ function gethttpuploadoffsetAction()
190190

191191
$this->Component->Httpupload->setTmpDirectory($this->getTempDirectory());
192192
$this->Component->Httpupload->setTokenParamName('uploadUniqueIdentifier');
193-
$this->Component->Httpupload->getOffset($params);
193+
$offset = $this->Component->Httpupload->getOffset($params);
194+
echo '[OK]'.$offset['offset'];
194195
} //end gethttpuploadoffset
195196

196197
/**
@@ -208,7 +209,7 @@ function gethttpuploaduniqueidentifierAction()
208209
throw new Zend_Exception('You have to be logged in to do that');
209210
}
210211

211-
if($this->userSession->JavaUpload->parent)
212+
if(!isset($params['testingmode']) && $this->userSession->JavaUpload->parent)
212213
{
213214
$folderId = $this->userSession->JavaUpload->parent;
214215
}
@@ -257,7 +258,7 @@ function processjavauploadAction()
257258
throw new Zend_Exception('User id does not match upload token user id');
258259
}
259260

260-
if($this->userSession->JavaUpload->parent)
261+
if(!isset($params['testingmode']) && $this->userSession->JavaUpload->parent)
261262
{
262263
$expectedParentId = $this->userSession->JavaUpload->parent;
263264
}
@@ -279,7 +280,7 @@ function processjavauploadAction()
279280

280281
if(!empty($data['path']) && file_exists($data['path']) && $data['size'] > 0)
281282
{
282-
if(isset($this->userSession->JavaUpload->parent))
283+
if(!isset($params['testingmode']) && isset($this->userSession->JavaUpload->parent))
283284
{
284285
$parent = $this->userSession->JavaUpload->parent;
285286
}
@@ -310,7 +311,6 @@ function processjavauploadAction()
310311
}
311312
} //end processjavaupload
312313

313-
314314
/** save an uploaded file */
315315
public function saveuploadedAction()
316316
{

core/tests/controllers/UploadDownloadControllerTest.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,22 @@ public function setUp()
2626
function testGethttpuploadoffsetAction()
2727
{
2828
$this->setupDatabase(array('default'));
29-
$identifier = BASE_PATH.'/tmp/misc/httpupload.png';
29+
30+
$usersFile = $this->loadData('User', 'default');
31+
$userDao = $this->User->load($usersFile[0]->getKey());
32+
$dir = BASE_PATH.'/tmp/misc/'.$userDao->getUserId().'/'.$userDao->getPrivatefolderId();
33+
$identifier = $dir.'/httpupload.png';
34+
if(!file_exists($dir))
35+
{
36+
mkdir($dir, 0700, true);
37+
}
3038
if(file_exists($identifier))
3139
{
3240
unlink($identifier);
3341
}
3442
copy(BASE_PATH.'/tests/testfiles/search.png', $identifier);
35-
$page = 'upload/gethttpuploadoffset/?uploadUniqueIdentifier=httpupload.png&testingmode=1';
36-
$this->dispatchUrI($page);
43+
$page = 'upload/gethttpuploadoffset/?uploadUniqueIdentifier='.$userDao->getUserId().'/'.$userDao->getPrivatefolderId().'/httpupload.png&testingmode=1';
44+
$this->dispatchUrI($page, $userDao);
3745

3846
$content = $this->getBody();
3947
if(strpos($content, '[OK]') === false)
@@ -50,14 +58,17 @@ function testGethttpuploadoffsetAction()
5058
function testGethttpuploaduniqueidentifierAction()
5159
{
5260
$this->setupDatabase(array('default'));
61+
62+
$usersFile = $this->loadData('User', 'default');
63+
$userDao = $this->User->load($usersFile[0]->getKey());
5364
$identifier = BASE_PATH.'/tmp/misc/httpupload.png';
5465
if(file_exists($identifier))
5566
{
5667
unlink($identifier);
5768
}
5869
copy(BASE_PATH.'/tests/testfiles/search.png', $identifier);
5970
$page = 'upload/gethttpuploaduniqueidentifier/?filename=httpupload.png&testingmode=1';
60-
$this->dispatchUrI($page);
71+
$this->dispatchUrI($page, $userDao);
6172
$content = $this->getBody();
6273
if(strpos($content, '[OK]') === false)
6374
{
@@ -73,9 +84,14 @@ function testGethttpuploaduniqueidentifierAction()
7384
function testProcessjavauploadAction()
7485
{
7586
$this->setupDatabase(array('default'));
87+
88+
$usersFile = $this->loadData('User', 'default');
89+
$userDao = $this->User->load($usersFile[0]->getKey());
90+
$subdir = $userDao->getUserId().'/'.$userDao->getPrivatefolderId();
91+
$dir = BASE_PATH.'/tmp/misc/'.$subdir;
7692
$fileBase = BASE_PATH.'/tests/testfiles/search.png';
7793
$file = BASE_PATH.'/tmp/misc/testing_file.png';
78-
$identifier = BASE_PATH.'/tmp/misc/httpupload.png';
94+
$identifier = $dir.'/httpupload.png';
7995

8096
if(file_exists($identifier))
8197
{
@@ -87,13 +103,8 @@ function testProcessjavauploadAction()
87103
fclose($ident);
88104
chmod($identifier, 0777);
89105

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;
92-
106+
$params = 'testingmode=1&filename=search.png&localinput='.$file.'&length='.filesize($file).'&uploadUniqueIdentifier='.$subdir.'/httpupload.png';
93107
$page = 'upload/processjavaupload/?'.$params;
94-
95-
$usersFile = $this->loadData('User', 'default');
96-
$userDao = $this->User->load($usersFile[0]->getKey());
97108
$this->dispatchUrI($page, $userDao);
98109

99110
$search = $this->Item->getItemsFromSearch('search.png', $userDao);

0 commit comments

Comments
 (0)