Skip to content

Commit edbec3b

Browse files
Updated the test cases and in image_transformation function
1 parent 98de0fa commit edbec3b

8 files changed

Lines changed: 79 additions & 58 deletions

File tree

examples/index.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@
1212
use Contentstack\Contentstack;
1313
include_once "../src/index.php";
1414

15-
$stack = Contentstack::Stack('<<API-KEY>>', '<<ACCESS-TOKEN>>', '<<ENVIRONMENT>>');
15+
$stack = Contentstack::Stack('***REMOVED***', '***REMOVED***', 'development');
1616

1717
try {
1818

19-
//$result = $stack->ContentType('authors')->Query()->toJSON()->includeCount()->find();
19+
$result = $stack->ContentType('authors')->Query()->toJSON()->includeCount()->find();
2020
// $result = $stack->ContentType('authors')->Entry('blte58928ca56939985')->Query()->toJSON()->find();
2121
// \Contentstack\Utility\debug($result);
22+
/* $result = $stack->Assets('blt34440151b4e8fe7c')->fetch();
23+
$data = $result->get('url');
24+
$result = $stack->ImageTrasformation($data, array('height'=> 100, 'weight'=> 100, 'disable' => 'upscale'));*/
25+
\Contentstack\Utility\debug($result);
2226

2327

2428
} catch(Exception $e) {

src/lib/models/assets.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66

77

88
use Contentstack\Stack\ContentType\Query\Query;
9-
use Contentstack\Stack\ContentType\BaseQuery\BaseQuery;
9+
// use Contentstack\Stack\ContentType\BaseQuery\BaseQuery;
1010
use Contentstack\Utility;
1111

1212

1313
require_once __DIR__.'/query.php';
14-
require_once __DIR__."/base_query.php";
14+
// require_once __DIR__."/base_query.php";
1515

1616

1717
/*
1818
* Class Assets
1919
* */
20-
class Assets extends BaseQuery {
20+
class Assets {
2121

2222
var $operation;
2323
var $assetUid = '';
@@ -38,9 +38,7 @@ public function __construct($asset_uid = '', $stack = '') {
3838
$this->type = 'assets';
3939
}else{
4040
$this->type = 'asset';
41-
$this->assetUid = $asset_uid;
42-
parent::__construct($this, $asset_uid);
43-
41+
$this->assetUid = $asset_uid;
4442
}
4543
}
4644

@@ -60,6 +58,6 @@ public function Query() {
6058
* */
6159
public function fetch() {
6260
$this->operation = __FUNCTION__;
63-
return \Contentstack\Utility\request($this, 'asset');
61+
return \Contentstack\Utility\contentstack_request($this, 'asset');
6462
}
6563
}

src/lib/models/base_query.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ public function exists($field_uid = '') {
177177

178178
/*
179179
* includeSchema
180+
* @deprecated since verion 3.3.0
180181
* To include schema along with entries
181182
* @param
182183
* @return Query
@@ -188,6 +189,7 @@ public function includeSchema() {
188189

189190
/*
190191
* includeContentType
192+
* @deprecated since verion 3.3.0
191193
* To include content_type along with entries
192194
* @param
193195
* @return Query

src/lib/models/entry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ public function __construct($entryUid = '', $contentType = '') {
3636
* */
3737
public function fetch() {
3838
$this->operation = __FUNCTION__;
39-
return \Contentstack\Utility\request($this);
39+
return \Contentstack\Utility\contentstack_request($this);
4040
}
4141
}

src/lib/models/query.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@ public function __construct($data = '', $type = '') {
3333
* */
3434
public function find() {
3535
$this->operation = __FUNCTION__;
36-
3736
if($this->type == 'assets'){
38-
return Utility\request($this, 'assets');
37+
return \Contentstack\Utility\contentstack_request($this, 'assets');
3938
}else if($this->type == 'contentType'){
40-
return Utility\request($this);
41-
}
42-
39+
return \Contentstack\Utility\contentstack_request($this);
40+
}
4341
}
4442

4543
/*
@@ -52,7 +50,7 @@ public function findOne() {
5250
if($this->type == 'assets'){
5351
return Utility\request($this, 'assets');
5452
}else if($this->type == 'contentType'){
55-
return Utility\request($this);
53+
return \Contentstack\Utility\contentstack_request($this);
5654
}
5755

5856
}

src/lib/models/stack.php

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ public function __construct($api_key = '', $access_token = '', $environment = ''
4141
* string|contentTypeId - valid content type uid relevant to configured stack
4242
* @return ContentType
4343
* */
44-
public function ContentType($contentTypeId = '') {
45-
44+
public function ContentType($contentTypeId = '') {
4645
return new ContentType($contentTypeId, $this);
4746
}
4847

@@ -58,34 +57,37 @@ public function Assets($assetUid = '') {
5857
}
5958

6059

61-
/*
62-
* ImageTrasformation
63-
* ImageTransformation function
64-
* @param
65-
*
66-
* */
67-
public function ImageTrasformation($url, $array){
68-
69-
$url_query_param = $url;
70-
$i = 0;
71-
$len = count($array);
72-
foreach( $array as $key => $value){
73-
74-
if ($i == 0){
60+
/*
61+
* ImageTrasform
62+
* ImageTransformation function is define for image manipulation with different
63+
* parameters in second parameter in array form
64+
* @param url : Image url on which we want to manipulate.
65+
* @param array : It is an second parameter in which we want to place different different manipulation value in form of array
66+
*
67+
* */
68+
public function ImageTrasformation($url, $array){
69+
if(gettype($array) == 'array'){
70+
$url_query_param = $url;
71+
$i = 0;
72+
$len = count($array);
73+
foreach( $array as $key => $value){
74+
if ($i == 0){
7575
$url_query_param .= "?" .$key . "=" .$value ."&";
76-
}else{
76+
}else{
7777
if($i != $len - 1){
78-
$url_query_param .= $key . "=" .$value ."&";
78+
$url_query_param .= $key . "=" .$value ."&";
7979
}else{
80-
$url_query_param .= $key . "=" .$value;
81-
}
80+
$url_query_param .= $key . "=" .$value;
81+
}
8282
}
83-
$i++;
83+
$i++;
8484
}
85-
return $url_query_param;
85+
return $url_query_param;
86+
}else{
87+
\Contentstack\Utility\debug("Please provide second parameter in Array form");
88+
}
89+
}
8690

87-
88-
}
8991

9092

9193
/*

src/lib/utility.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ function getDomain($query) {
6868
}
6969
}
7070

71-
if(!function_exists('URL')) {
71+
if(!function_exists('contentstack_url')) {
7272
/*
73-
* URL
74-
* URL method to create the url based on the request
73+
* contentstack_url
74+
* contentstack_url method to create the url based on the request
7575
* @param
7676
* @queryObject - Object - Query Object
7777
* @return URL()string
7878
* */
79-
function URL($queryObject = '', $type = '') {
79+
function contentstack_url($queryObject = '', $type = '') {
8080

8181
$URL = '';
8282
switch ($type) {
@@ -229,24 +229,24 @@ function wrapResult($result = '', $queryObject = '') {
229229
}
230230
}
231231

232-
if (!function_exists('request')) {
232+
if (!function_exists('contentstack_request')) {
233233

234234
/*
235-
* request
236-
* request to the API server based on the data
235+
* contentstack_request
236+
* contentstack_request to the API server based on the data
237237
* @param
238238
* @queryObject - Object - Query Object
239239
* @return Result
240240
* */
241241

242-
function request($queryObject = '', $type = '') {
242+
function contentstack_request($queryObject = '', $type = ''){
243243
$server_output = '';
244244
if($queryObject) {
245-
$http = curl_init(URL($queryObject, $type));
245+
$http = curl_init(contentstack_url($queryObject, $type));
246246

247247
// setting the GET request
248248
curl_setopt($http, CURLOPT_HEADER, FALSE);
249-
// setting the GET request
249+
// setting the GET request
250250
curl_setopt($http, CURLOPT_CUSTOMREQUEST, "GET");
251251
// receive server response ...
252252
curl_setopt($http, CURLOPT_RETURNTRANSFER, TRUE);

test/ContentStackTestCases.php

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ public function testFind() {
3636
}
3737

3838
public function testAssetsFind() {
39-
4039
$_assets = self::$Stack->Assets()->Query()->toJSON()->find();
4140
$this->assertArrayHasKey(0, $_assets);
4241
$this->assertTrue(checkAssetsSorting($_assets[0]));
43-
4442
}
4543

4644
public function testAssetsFetch() {
@@ -55,12 +53,31 @@ public function testImageTransformation() {
5553
$_object = self::$Stack->Assets()->Query()->toJSON()->find();
5654
$_uid = $_object[0][0]['uid'];
5755
$_asset = self::$Stack->Assets($_uid)->fetch();
58-
$_imagetransformation = self::$Stack->ImageTrasformation($_asset, array('height'=> 100, 'weight'=> 100, 'disable' => 'upscale'));
59-
$data = parse_url($result, PHP_URL_QUERY);
60-
parse_str($data, $get_array);
61-
$default_array = array('height'=> 100, 'weight'=> 100, 'disable' => 'upscale');
62-
$result=array_diff($get_array, $default_array);
63-
$this->assertEquals($get_array, $default_array);
56+
$_url = $_asset->get('url');
57+
if($_url){
58+
59+
$_resizeimagetransformation = self::$Stack->ImageTrasformation($_url, array('height'=> 100, 'weight'=> 100, 'disable' => 'upscale'));
60+
$_cropimagetransformation = self::$Stack->ImageTrasformation($_url, array('crop'=> 100,200));
61+
$_resizecropimagetransformation = self::$Stack->ImageTrasformation($_url, array('height'=> 100, 'weight'=> 100, 'disable' => 'upscale', 'crop'=> 100,200));
62+
63+
$resize_data = parse_url($_resizeimagetransformation, PHP_URL_QUERY);
64+
$crop_data = parse_url($_cropimagetransformation, PHP_URL_QUERY);
65+
$resizecrop_data = parse_url($_resizecropimagetransformation, PHP_URL_QUERY);
66+
67+
parse_str($resize_data, $get_array_resize);
68+
parse_str($crop_data, $get_array_crop);
69+
parse_str($resizecrop_data, $get_array_resizecrop);
70+
71+
$resize_default_array = array('height'=> 100,'weight'=> 100, 'disable' => 'upscale');
72+
$crop_default_array = array('crop'=> 100,200);
73+
$resizecrop_default_array = array('height'=> 100,'weight'=> 100, 'disable' => 'upscale', 'crop'=> 100,200);
74+
75+
$this->assertEquals($get_array_resize, $resize_default_array);
76+
$this->assertEquals($get_array_crop, $crop_default_array);
77+
$this->assertEquals($get_array_resizecrop, $resizecrop_default_array);
78+
}
79+
80+
6481
}
6582

6683

0 commit comments

Comments
 (0)