9
9
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10
10
PURPOSE. See the above copyright notices for more information.
11
11
=========================================================================*/
12
- /** test upload controller*/
13
- class UploadControllerTest extends ControllerTestCase
12
+ /**
13
+ * Tests uploading and downloading of files
14
+ */
15
+ class UploadDownloadControllerTest extends ControllerTestCase
14
16
{
15
17
/** init tests*/
16
18
public function setUp ()
17
19
{
18
- $ this ->setupDatabase (array ('default ' ));
19
20
$ this ->_models = array ('User ' , 'Feed ' , 'Assetstore ' , 'Item ' );
20
21
$ this ->_daos = array ('User ' , 'Assetstore ' );
21
22
parent ::setUp ();
22
23
}
23
24
24
- /** testGethttpuploadoffsetAction */
25
+ /** test UploadController::GethttpuploadoffsetAction */
25
26
function testGethttpuploadoffsetAction ()
26
27
{
28
+ $ this ->setupDatabase (array ('default ' ));
27
29
$ identifier = BASE_PATH .'/tmp/misc/httpupload.png ' ;
28
30
if (file_exists ($ identifier ))
29
31
{
30
32
unlink ($ identifier );
31
33
}
32
34
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 ' ;
34
36
$ this ->dispatchUrI ($ page );
35
37
36
38
$ content = $ this ->getBody ();
37
- if (strpos ($ content , " [OK] " ) === false )
39
+ if (strpos ($ content , ' [OK] ' ) === false )
38
40
{
39
41
$ this ->fail ();
40
42
}
41
- if (strpos ($ content , " [ERROR] " ) !== false )
43
+ if (strpos ($ content , ' [ERROR] ' ) !== false )
42
44
{
43
45
$ this ->fail ();
44
46
}
45
47
}
46
48
47
- /** gethttpuploaduniqueidentifierAction*/
49
+ /** test UploadController:: gethttpuploaduniqueidentifierAction*/
48
50
function testGethttpuploaduniqueidentifierAction ()
49
51
{
52
+ $ this ->setupDatabase (array ('default ' ));
50
53
$ identifier = BASE_PATH .'/tmp/misc/httpupload.png ' ;
51
54
if (file_exists ($ identifier ))
52
55
{
53
56
unlink ($ identifier );
54
57
}
55
58
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 ' ;
57
60
$ this ->dispatchUrI ($ page );
58
61
$ content = $ this ->getBody ();
59
- if (strpos ($ content , " [OK] " ) === false )
62
+ if (strpos ($ content , ' [OK] ' ) === false )
60
63
{
61
64
$ this ->fail ();
62
65
}
63
- if (strpos ($ content , " [ERROR] " ) !== false )
66
+ if (strpos ($ content , ' [ERROR] ' ) !== false )
64
67
{
65
68
$ this ->fail ();
66
69
}
67
70
}
68
71
69
- /** processjavaupload*/
72
+ /** test UploadController:: processjavaupload*/
70
73
function testProcessjavauploadAction ()
71
74
{
72
75
$ this ->setupDatabase (array ('default ' ));
@@ -79,15 +82,15 @@ function testProcessjavauploadAction()
79
82
unlink ($ identifier );
80
83
}
81
84
copy ($ fileBase , $ file );
82
- $ ident = fopen ($ identifier , " x+ " );
83
- fwrite ($ ident , " " );
85
+ $ ident = fopen ($ identifier , ' x+ ' );
86
+ fwrite ($ ident , ' ' );
84
87
fclose ($ ident );
85
88
chmod ($ identifier , 0777 );
86
89
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 ;
89
92
90
- $ page = " upload/processjavaupload/? " .$ params ;
93
+ $ page = ' upload/processjavaupload/? ' .$ params ;
91
94
92
95
$ usersFile = $ this ->loadData ('User ' , 'default ' );
93
96
$ userDao = $ this ->User ->load ($ usersFile [0 ]->getKey ());
@@ -101,27 +104,29 @@ function testProcessjavauploadAction()
101
104
$ this ->setupDatabase (array ('default ' ));
102
105
}
103
106
104
- /** simpleuploadAction*/
107
+ /** test UploadController:: simpleuploadAction*/
105
108
function testSimpleuploadAction ()
106
109
{
110
+ $ this ->setupDatabase (array ('default ' ));
107
111
$ this ->dispatchUrI ("/upload/simpleupload " , null , true );
108
112
109
113
$ usersFile = $ this ->loadData ('User ' , 'default ' );
110
114
$ userDao = $ this ->User ->load ($ usersFile [0 ]->getKey ());
111
115
112
116
$ folder = $ userDao ->getPublicFolder ();
113
- $ this ->dispatchUrI (" /upload/simpleupload?parent= " .$ folder ->getKey (), $ userDao , false );
117
+ $ this ->dispatchUrI (' /upload/simpleupload?parent= ' .$ folder ->getKey (), $ userDao , false );
114
118
$ this ->assertContains ('id="destinationId" value=" ' .$ folder ->getKey (), $ this ->getBody ());
115
119
116
120
$ this ->resetAll ();
117
121
$ folder = $ userDao ->getPrivateFolder ();
118
- $ this ->dispatchUrI (" /upload/simpleupload " , $ userDao , false );
122
+ $ this ->dispatchUrI (' /upload/simpleupload ' , $ userDao , false );
119
123
$ this ->assertContains ('id="destinationId" value=" ' .$ folder ->getKey (), $ this ->getBody ());
120
124
}
121
125
122
- /** revision*/
126
+ /** test UploadController:: revision */
123
127
function testRevision ()
124
128
{
129
+ $ this ->setupDatabase (array ('default ' ));
125
130
$ this ->dispatchUrI ("/upload/revision " , null , true );
126
131
127
132
$ usersFile = $ this ->loadData ('User ' , 'default ' );
@@ -133,9 +138,10 @@ function testRevision()
133
138
$ this ->dispatchUrI ("/upload/revision?itemId= " .$ itemDao ->getKey (), $ userDao );
134
139
}
135
140
136
- /** savelink*/
141
+ /** test UploadController:: savelink */
137
142
function testSavelinkAction ()
138
143
{
144
+ $ this ->setupDatabase (array ('default ' ));
139
145
$ this ->dispatchUrI ("/upload/savelink " , null , true );
140
146
141
147
$ usersFile = $ this ->loadData ('User ' , 'default ' );
@@ -149,7 +155,7 @@ function testSavelinkAction()
149
155
$ this ->params ['name ' ] = 'test name link ' ;
150
156
$ this ->params ['url ' ] = 'http://www.kitware.com ' ;
151
157
$ this ->params ['license ' ] = 0 ;
152
- $ this ->dispatchUrI (" /upload/savelink " , $ userDao );
158
+ $ this ->dispatchUrI (' /upload/savelink ' , $ userDao );
153
159
154
160
$ search = $ this ->Item ->getItemsFromSearch ($ this ->params ['name ' ], $ userDao );
155
161
if (empty ($ search ))
@@ -159,8 +165,8 @@ function testSavelinkAction()
159
165
$ this ->setupDatabase (array ('default ' ));
160
166
}
161
167
162
- /** saveuploadedAction*/
163
- function testDaveuploadedAction ()
168
+ /** test UploadController:: saveuploadedAction*/
169
+ function testSaveuploadedAction ()
164
170
{
165
171
$ this ->setupDatabase (array ('default ' ));
166
172
@@ -170,14 +176,31 @@ function testDaveuploadedAction()
170
176
$ this ->params = array ();
171
177
$ this ->params ['parent ' ] = $ userDao ->getPublicFolder ()->getKey ();
172
178
$ this ->params ['license ' ] = 0 ;
173
- $ this ->dispatchUrI (" /upload/saveuploaded " , $ userDao );
179
+ $ this ->dispatchUrI (' /upload/saveuploaded ' , $ userDao );
174
180
175
181
$ search = $ this ->Item ->getItemsFromSearch ('search.png ' , $ userDao );
176
182
if (empty ($ search ))
177
183
{
178
184
$ this ->fail ('Unable to find item ' );
179
185
}
180
- $ this ->setupDatabase (array ('default ' ));
181
186
}
182
187
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
+ }
183
206
}
0 commit comments