forked from cloudinary/cloudinary_php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUploaderTest.php
More file actions
56 lines (47 loc) · 3.19 KB
/
Copy pathUploaderTest.php
File metadata and controls
56 lines (47 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
$base = realpath(dirname(__FILE__).'/../');
require_once($base . DIRECTORY_SEPARATOR . 'src/Cloudinary.php');
require_once($base . DIRECTORY_SEPARATOR . 'src/Uploader.php');
class UploaderTest extends PHPUnit_Framework_TestCase {
public function setUp() {
Cloudinary::reset_config();
if (!Cloudinary::config_get("api_secret")) {
$this->markTestSkipped('Please setup environment for Upload test to run');
}
}
public function test_upload() {
$result = CloudinaryUploader::upload("tests/logo.png");
$this->assertEquals($result["width"], 241);
$this->assertEquals($result["height"], 51);
$expected_signature = Cloudinary::api_sign_request(array("public_id"=>$result["public_id"], "version"=>$result["version"]), Cloudinary::config_get("api_secret"));
$this->assertEquals($result["signature"], $expected_signature);
}
public function test_explicit() {
$result = CloudinaryUploader::explicit("cloudinary", array("type"=>"twitter_name", "eager"=>array("crop"=>"scale", "width"=>"2.0")));
$url = cloudinary_url("cloudinary", array("type"=>"twitter_name", "crop"=>"scale", "width"=>"2.0", "format"=>"png", "version"=>$result["version"]));
$this->assertEquals($result["eager"][0]["url"], $url);
}
public function test_eager() {
CloudinaryUploader::upload("tests/logo.png", array("eager"=>array("crop"=>"scale", "width"=>"2.0")));
}
public function test_headers() {
CloudinaryUploader::upload("tests/logo.png", array("headers"=>array("Link: 1")));
CloudinaryUploader::upload("tests/logo.png", array("headers"=>array("Link" => "1")));
}
public function test_text() {
$result = CloudinaryUploader::text("hello world");
$this->assertGreaterThan(1, $result["width"]);
$this->assertGreaterThan(1, $result["height"]);
}
public function test_cl_form_tag() {
Cloudinary::config(array("cloud_name"=>"test123", "secure_distribution" => NULL, "private_cdn" => FALSE, "api_key" => "1234"));
$form = cl_form_tag("http://callback.com", array("public_id"=>"hello", "form"=>array("class"=>"uploader")));
$this->assertRegexp("/<form enctype='multipart\/form-data' action='https:\/\/api.cloudinary.com\/v1_1\/test123\/image\/upload' method='POST' class='uploader'>\n<input name='timestamp' type='hidden' value='\d+'\/>\n<input name='public_id' type='hidden' value='hello'\/>\n<input name='signature' type='hidden' value='[0-9a-f]+'\/>\n<input name='api_key' type='hidden' value='1234'\/>\n<\/form>/", $form);
}
public function test_cl_image_upload_tag() {
Cloudinary::config(array("cloud_name"=>"test123", "secure_distribution" => NULL, "private_cdn" => FALSE, "api_key" => "1234"));
$tag = cl_image_upload_tag("image", array("public_id"=>"hello", "html"=>array("class"=>"uploader")));
$this->assertRegexp("/<input class='uploader cloudinary-fileupload' data-cloudinary-field='image' data-form-data='{\"timestamp\":\d+,\"public_id\":\"hello\",\"signature\":\"[0-9a-f]+\",\"api_key\":\"1234\"}' data-url='https:\/\/api.cloudinary.com\/v1_1\/test123\/auto\/upload' name='file' type='file'\/>/", $tag);
}
}
?>