77 require_once ( 'TestHelper.php ' );
88 use Cloudinary ;
99 use Exception ;
10- use PHPUnit \Framework \TestCase ;
1110
12- class UploaderTest extends TestCase {
13- const LOGO_PNG = "tests/logo.png " ;
14-
15- const TEST_ICO = "tests/favicon.ico " ;
11+ class UploaderTest extends \PHPUnit \Framework \TestCase {
1612
1713 public $ url_prefix ;
1814 public static function setUpBeforeClass () {
@@ -31,25 +27,24 @@ public function tearDown() {
3127 Curl::$ instance = new Curl ();
3228 }
3329
34- public function test_upload () {
35- $ result = Uploader::upload (self ::LOGO_PNG );
36-
37- switch ($ result ["resource_type " ]) {
38- case "image " :
39- // generate image tag
40- break ;
41- case "video " :
42- // generate video tag
43- break ;
44- }
30+ public function test_upload () {
31+ $ result = Uploader::upload ( TEST_IMG );
32+ switch ( $ result ["resource_type " ] ) {
33+ case "image " :
34+ // generate image tag
35+ break ;
36+ case "video " :
37+ // generate video tag
38+ break ;
39+ }
4540
4641 $ this ->assertEquals ($ result ["width " ], 241 );
4742 $ this ->assertEquals ($ result ["height " ], 51 );
4843 $ expected_signature = Cloudinary::api_sign_request (array ("public_id " =>$ result ["public_id " ], "version " =>$ result ["version " ]), Cloudinary::config_get ("api_secret " ));
4944 $ this ->assertEquals ($ result ["signature " ], $ expected_signature );
5045 Curl::mockUpload ($ this );
5146
52- Uploader::upload (self :: LOGO_PNG , array ("ocr " =>"adv_ocr " ));
47+ Uploader::upload (TEST_IMG , array ("ocr " =>"adv_ocr " ));
5348 $ fields = Curl::$ instance ->fields ();
5449 $ this ->assertArraySubset (array ("ocr " =>"adv_ocr " ),$ fields );
5550
@@ -107,21 +102,21 @@ public function test_build_eager() {
107102
108103 public function test_eager () {
109104 Curl::mockUpload ($ this );
110- Uploader::upload (self :: LOGO_PNG , array ("eager " =>array ("crop " =>"scale " , "width " =>"2.0 " )));
105+ Uploader::upload (TEST_IMG , array ("eager " =>array ("crop " =>"scale " , "width " =>"2.0 " )));
111106 $ fields = Curl::$ instance ->fields ();
112107 $ this ->assertArraySubset (array ("eager " => "c_scale,w_2.0 " ),$ fields );
113108 }
114109
115110 public function test_upload_async () {
116111 Curl::mockUpload ($ this );
117- Uploader::upload (self :: LOGO_PNG , array ("transformation " =>array ("crop " =>"scale " , "width " =>"2.0 " ), "async " =>TRUE ));
112+ Uploader::upload (TEST_IMG , array ("transformation " =>array ("crop " =>"scale " , "width " =>"2.0 " ), "async " =>TRUE ));
118113 $ fields = Curl::$ instance ->fields ();
119114 $ this ->assertArraySubset (array ("async " => TRUE ),$ fields );
120115 }
121-
116+
122117 public function test_headers () {
123- Uploader::upload (self :: LOGO_PNG , array ("headers " =>array ("Link: 1 " )));
124- Uploader::upload (self :: LOGO_PNG , array ("headers " =>array ("Link " => "1 " )));
118+ Uploader::upload (TEST_IMG , array ("headers " =>array ("Link: 1 " )));
119+ Uploader::upload (TEST_IMG , array ("headers " =>array ("Link " => "1 " )));
125120 }
126121
127122 public function test_text () {
@@ -132,7 +127,7 @@ public function test_text() {
132127
133128 public function test_tags () {
134129 $ api = new \Cloudinary \Api ();
135- $ result = Uploader::upload (self :: LOGO_PNG );
130+ $ result = Uploader::upload (TEST_IMG );
136131 Curl::mockUpload ($ this );
137132 Uploader::add_tag ("tag1 " , "foobar " );
138133 assertUrl ($ this , "/image/tags " );
@@ -170,16 +165,16 @@ public function test_huge_public_id_list() {
170165 }
171166 public function test_use_filename () {
172167 $ api = new \Cloudinary \Api ();
173- $ result = Uploader::upload (self :: LOGO_PNG , array ("use_filename " =>TRUE ));
168+ $ result = Uploader::upload (TEST_IMG , array ("use_filename " =>TRUE ));
174169 $ this ->assertRegExp ('/logo_[a-zA-Z0-9]{6}/ ' , $ result ["public_id " ]);
175- $ result = Uploader::upload (self :: LOGO_PNG , array ("use_filename " =>TRUE , "unique_filename " =>FALSE ));
170+ $ result = Uploader::upload (TEST_IMG , array ("use_filename " =>TRUE , "unique_filename " =>FALSE ));
176171 $ this ->assertEquals ("logo " , $ result ["public_id " ]);
177172 }
178173
179174 public function test_allowed_formats () {
180175 //should allow whitelisted formats if allowed_formats
181176 $ formats = array ("png " );
182- $ result = Uploader::upload (self :: LOGO_PNG , array ("allowed_formats " => $ formats ));
177+ $ result = Uploader::upload (TEST_IMG , array ("allowed_formats " => $ formats ));
183178 $ this ->assertEquals ($ result ["format " ], "png " );
184179 }
185180
@@ -188,7 +183,7 @@ public function test_allowed_formats_with_illegal_format() {
188183 $ error_found = FALSE ;
189184 $ formats = array ("jpg " );
190185 try {
191- Uploader::upload (self :: LOGO_PNG , array ("allowed_formats " => $ formats ));
186+ Uploader::upload (TEST_IMG , array ("allowed_formats " => $ formats ));
192187 } catch (Exception $ e ) {
193188 $ error_found = TRUE ;
194189 }
@@ -198,14 +193,14 @@ public function test_allowed_formats_with_illegal_format() {
198193 public function test_allowed_formats_with_format () {
199194 //should allow non whitelisted formats if type is specified and convert to that type
200195 $ formats = array ("jpg " );
201- $ result = Uploader::upload (self :: LOGO_PNG , array ("allowed_formats " => $ formats , "format " => "jpg " ));
196+ $ result = Uploader::upload (TEST_IMG , array ("allowed_formats " => $ formats , "format " => "jpg " ));
202197 $ this ->assertEquals ("jpg " , $ result ["format " ]);
203198 }
204199
205200 public function test_face_coordinates () {
206201 //should allow sending face and custom coordinates
207202 $ face_coordinates = array (array (120 , 30 , 109 , 51 ), array (121 , 31 , 110 , 51 ));
208- $ result = Uploader::upload (self :: LOGO_PNG , array ("face_coordinates " => $ face_coordinates , "faces " => TRUE ));
203+ $ result = Uploader::upload (TEST_IMG , array ("face_coordinates " => $ face_coordinates , "faces " => TRUE ));
209204 $ this ->assertEquals ($ face_coordinates , $ result ["faces " ]);
210205
211206 $ different_face_coordinates = array (array (122 , 32 , 111 , 152 ));
@@ -220,7 +215,7 @@ public function test_face_coordinates() {
220215 public function test_context () {
221216 //should allow sending context
222217 $ context = array ("caption " => "cap=caps " , "alt " => "alternative|alt=a " );
223- $ result = Uploader::upload (self :: LOGO_PNG , array ("context " => $ context ));
218+ $ result = Uploader::upload (TEST_IMG , array ("context " => $ context ));
224219
225220 $ api = new \Cloudinary \Api ();
226221 $ info = $ api ->resource ($ result ["public_id " ]);
@@ -232,7 +227,7 @@ public function test_context() {
232227
233228 public function test_context_api () {
234229 $ api = new \Cloudinary \Api ();
235- $ result = Uploader::upload (self :: LOGO_PNG );
230+ $ result = Uploader::upload (TEST_IMG );
236231 Uploader::add_context ('alt=testAlt|custom=testCustom ' , $ result ['public_id ' ]);
237232 // fwrite(STDERR, print_r($result['public_id'], TRUE));
238233 assertUrl ($ this , "/image/context " );
@@ -275,7 +270,7 @@ public function test_cl_image_upload_tag() {
275270
276271 function test_manual_moderation () {
277272 // should support setting manual moderation status
278- $ resource = Uploader::upload (self :: LOGO_PNG , array ("moderation " =>"manual " ));
273+ $ resource = Uploader::upload (TEST_IMG , array ("moderation " =>"manual " ));
279274 $ this ->assertEquals ($ resource ["moderation " ][0 ]["status " ], "pending " );
280275 $ this ->assertEquals ($ resource ["moderation " ][0 ]["kind " ], "manual " );
281276 }
@@ -295,7 +290,7 @@ function test_raw_conversion() {
295290 */
296291 function test_categorization () {
297292 // should support requesting categorization
298- Uploader::upload (self :: LOGO_PNG , array ("categorization " => "illegal " ));
293+ Uploader::upload (TEST_IMG , array ("categorization " => "illegal " ));
299294 }
300295
301296 /**
@@ -304,7 +299,7 @@ function test_categorization() {
304299 */
305300 function test_detection () {
306301 // should support requesting detection
307- Uploader::upload (self :: LOGO_PNG , array ("detection " => "illegal " ));
302+ Uploader::upload (TEST_IMG , array ("detection " => "illegal " ));
308303 }
309304
310305 /**
@@ -313,7 +308,7 @@ function test_detection() {
313308 */
314309 function test_auto_tagging () {
315310 // should support requesting auto_tagging
316- Uploader::upload (self :: LOGO_PNG , array ("auto_tagging " => 0.5 ));
311+ Uploader::upload (TEST_IMG , array ("auto_tagging " => 0.5 ));
317312 }
318313
319314 /**
@@ -322,7 +317,7 @@ function test_auto_tagging() {
322317 */
323318 function test_background_removal () {
324319 // should support requesting background_removal
325- Uploader::upload (self :: LOGO_PNG , array ("background_removal " => "illegal " ));
320+ Uploader::upload (TEST_IMG , array ("background_removal " => "illegal " ));
326321 }
327322
328323 function test_large_upload () {
@@ -357,7 +352,7 @@ function test_upload_preset() {
357352 // should support unsigned uploading using presets
358353 $ api = new \Cloudinary \Api ();
359354 $ preset = $ api ->create_upload_preset (array ("folder " =>"upload_folder " , "unsigned " =>TRUE ));
360- $ result = Uploader::unsigned_upload (self :: LOGO_PNG , $ preset ["name " ]);
355+ $ result = Uploader::unsigned_upload (TEST_IMG , $ preset ["name " ]);
361356 $ this ->assertRegExp ('/^upload_folder\/[a-z0-9]+$/ ' , $ result ["public_id " ]);
362357 $ api ->delete_upload_preset ($ preset ["name " ]);
363358
@@ -375,7 +370,7 @@ function test_upload_timeout()
375370 try {
376371 // Use a lengthy PNG transformation
377372 $ transformation = array ("crop " => "scale " , "width " => "2.0 " , "angle " => 33 );
378- Uploader::upload (self :: LOGO_PNG , array ("eager " =>array ("transformation " =>array ($ transformation , $ transformation ))));
373+ Uploader::upload (TEST_IMG , array ("eager " =>array ("transformation " =>array ($ transformation , $ transformation ))));
379374 } catch ( Exception $ e ) {
380375 // Finally not supported in PHP 5.3
381376 Cloudinary::config (array ( "timeout " , $ timeout ));
@@ -386,7 +381,7 @@ function test_upload_timeout()
386381
387382 function test_upload_responsive_breakpoints ()
388383 {
389- $ response = Uploader::upload (self :: LOGO_PNG , array ("responsive_breakpoints " =>array (array ("create_derived " =>FALSE ))));
384+ $ response = Uploader::upload (TEST_IMG , array ("responsive_breakpoints " =>array (array ("create_derived " =>FALSE ))));
390385 $ this ->assertArrayHasKey ("responsive_breakpoints " , $ response , "Should return responsive_breakpoints information " );
391386 $ this ->assertEquals (2 , count ($ response ["responsive_breakpoints " ][0 ]["breakpoints " ]));
392387 }
0 commit comments