forked from cloudinary/cloudinary_php
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHelpersTest.php
More file actions
106 lines (81 loc) · 3.09 KB
/
Copy pathHelpersTest.php
File metadata and controls
106 lines (81 loc) · 3.09 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
namespace Cloudinary;
use Cloudinary;
use PHPUnit\Framework\TestCase;
/**
* Class HelpersTest
* @package Cloudinary
*/
class HelpersTest extends TestCase
{
protected static $helpers_test_id;
protected static $mocked_response = '{"breakpoints":[50,500,1000]}';
protected static $mocked_breakpoints = [50, 500, 1000];
protected static $expected_transformation = "c_scale,w_auto:breakpoints_50_1000_20_20:json";
protected static $crop_transformation = ['crop' => 'crop', 'width' => 100];
protected static $crop_transformation_str = 'c_crop,w_100';
public static function setUpBeforeClass()
{
\Cloudinary::reset_config();
if (!Cloudinary::config_get("api_secret")) {
self::markTestSkipped('Please setup environment for Helpers test to run');
}
self::$helpers_test_id = "helpers_test_" . UNIQUE_TEST_ID;
Uploader::upload(TEST_IMG, ["public_id" => self::$helpers_test_id, "tags" => array(TEST_TAG, UNIQUE_TEST_TAG)]);
}
public static function tearDownAfterClass()
{
if (!Cloudinary::config_get("api_secret")) {
self::fail("You need to configure the cloudinary api for the tests to work.");
}
$api = new Cloudinary\Api();
try {
$api->delete_resources([self::$helpers_test_id]);
} catch (\Exception $e) {
}
}
public function setUp()
{
Curl::$instance = new Curl();
}
/**
* Should retrieve responsive breakpoints from cloudinary resource (mocked)
*
* @throws \Cloudinary\Error
*/
public function test_fetch_breakpoints()
{
Curl::mockRequest($this, self::$mocked_response);
$actual_breakpoints = fetch_breakpoints(self::$helpers_test_id);
$this->assertEquals(self::$mocked_breakpoints, $actual_breakpoints);
$this->assertContains(self::$expected_transformation, Curl::$instance->url_path());
}
/**
* Should retrieve responsive breakpoints from cloudinary resource with custom transformation (mocked)
*
* @throws \Cloudinary\Error
*/
public function test_fetch_breakpoints_with_transformation()
{
Curl::mockRequest($this, self::$mocked_response);
$srcset = ["transformation" => self::$crop_transformation];
$actual_breakpoints = fetch_breakpoints(self::$helpers_test_id, $srcset);
$this->assertEquals(self::$mocked_breakpoints, $actual_breakpoints);
$this->assertContains(
self::$crop_transformation_str . '/' .self::$expected_transformation,
Curl::$instance->url_path()
);
}
/**
* Should retrieve responsive breakpoints from cloudinary resource (real request)
*
* @throws \Cloudinary\Error
*/
public function test_fetch_breakpoints_real()
{
$actual_breakpoints = fetch_breakpoints(self::$helpers_test_id);
$this->assertContains(self::$expected_transformation, Curl::$instance->url_path());
$this->assertTrue(is_array($actual_breakpoints));
$this->assertGreaterThan(0, count($actual_breakpoints));
}
}