Skip to content

Commit d6b85ed

Browse files
upadate testcases
1 parent 5ac511b commit d6b85ed

File tree

7 files changed

+29
-21
lines changed

7 files changed

+29
-21
lines changed

src/lib/models/assets.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
namespace Contentstack\Stack\Assets;
66

77

8-
use Contentstack\Stack\ContentType\BaseQuery\BaseQuery;
98
use Contentstack\Stack\ContentType\Query\Query;
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";
15+
1416

1517
/*
1618
* Class Assets
@@ -19,8 +21,8 @@ class Assets extends BaseQuery {
1921

2022
var $operation;
2123
var $assetUid = '';
22-
var $stack = '';
23-
var $type = '';
24+
var $stack = '';
25+
var $type = '';
2426

2527

2628

@@ -31,16 +33,18 @@ class Assets extends BaseQuery {
3133
*
3234
* */
3335
public function __construct($asset_uid = '', $stack = '') {
34-
36+
3537
$this->stack = $stack;
3638
if($asset_uid == ''){
3739
$this->type = 'assets';
3840
}else{
3941
$this->type = 'asset';
40-
42+
$this->assetUid = $asset_uid;
43+
parent::__construct($this, $asset_uid);
44+
4145
}
42-
$this->assetUid = $asset_uid;
43-
parent::__construct($this, $assetUid);
46+
47+
4448

4549
}
4650

@@ -62,6 +66,4 @@ public function fetch() {
6266
$this->operation = __FUNCTION__;
6367
return \Contentstack\Utility\request($this, 'asset');
6468
}
65-
66-
6769
}

src/lib/models/base_query.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ abstract class BaseQuery {
1414

1515
public function __construct($data = '', $parent = '') {
1616

17-
if($data->type == 'assets'){
17+
if($data->type === 'assets'){
1818
$this->assets = $data;
1919
$this->queryObject = $parent;
2020
$this->queryObject->_query = array();
2121
$this->subQuery = array();
22-
}else if ($data->type == 'asset'){
22+
23+
}else if ($data->type === 'asset'){
2324

2425
$this->asset = $data;
25-
$this->queryObject = $parent;
26+
$this->queryObject = $data;
2627
$this->queryObject->_query = array();
2728
$this->subQuery = array();
2829

src/lib/models/query.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function __construct($data = '', $type = '') {
3333
* */
3434
public function find() {
3535
$this->operation = __FUNCTION__;
36+
3637
if($this->type == 'assets'){
3738
return Utility\request($this, 'assets');
3839
}else if($this->type == 'contentType'){

src/lib/models/stack.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
use Contentstack\Utility;
55
use Contentstack\Stack\ContentType\ContentType;
66
use Contentstack\Stack\Assets\Assets;
7-
use Contentstack\Stack\Asset\Asset;
7+
//use Contentstack\Stack\Asset\Asset;
88

99
require_once __DIR__."/content_type.php";
1010
require_once __DIR__."/assets.php";
11-
require_once __DIR__."/asset.php";
11+
//require_once __DIR__."/asset.php";
1212
require_once __DIR__."/../../config/index.php";
1313

1414
/*

src/lib/utility.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ function request($queryObject = '', $type = '') {
243243
$server_output = '';
244244
if($queryObject) {
245245
$http = curl_init(URL($queryObject, $type));
246-
// \Contentstack\Utility\debug(URL($queryObject, $type));
246+
247247
// setting the GET request
248248
curl_setopt($http, CURLOPT_HEADER, FALSE);
249249
// setting the GET request
@@ -253,6 +253,7 @@ function request($queryObject = '', $type = '') {
253253
$response = curl_exec($http);
254254
// status code extraction
255255
$httpcode = curl_getinfo($http, CURLINFO_HTTP_CODE);
256+
256257
// close the curl
257258
curl_close ($http);
258259
if($httpcode > 199 && $httpcode < 300) {

test/ContentStackTestCases.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Contentstack\Test\REST;
99

1010
use PHPUnit\Framework\TestCase;
11+
1112
class ContentStackTestCases extends TestCase {
1213
public static $rest;
1314
public static $Stack;
@@ -35,17 +36,18 @@ public function testFind() {
3536
}
3637

3738
public function testAssetsFind() {
38-
$_assets = self::$Stack->Assets()->Query()->toJSON()->find();
39-
$this->assertArrayHasKey(0, $_assets);
40-
// $this->assertTrue((count($_assets[0]) === ENTRY_COUNT));
41-
$this->assertTrue(checkAssetsSorting($_assets[0]));
42-
}
4339

40+
$_assets = self::$Stack->Assets()->Query()->toJSON()->find();
41+
$this->assertArrayHasKey(0, $_assets);
42+
$this->assertTrue(checkAssetsSorting($_assets[0]));
43+
44+
}
4445

4546
public function testAssetFetch() {
4647
$_object = self::$Stack->Assets()->Query()->toJSON()->find();
48+
//\Contentstack\Utility\debug($_object[0][0]['uid']);
4749
$_uid = $_object[0][0]['uid'];
48-
$_asset = self::$Stack->Asset($_uid)->fetch();
50+
$_asset = self::$Stack->Assets($_uid)->fetch();
4951
$this->assertEquals($_asset->get('title'), $_object[0][0]['title']);
5052
}
5153

test/utility.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function checkEntriesSorting($entries = array(), $sortKey = 'updated_at', $order
1717
if (!function_exists('assetsSorting')) {
1818

1919
function checkAssetsSorting($assets = array(), $sortKey = 'updated_at', $order = 'desc') {
20+
2021
$result = true;
2122
for($i = 0;$i < count($assets) - 1; $i++) {
2223
if($order === 'desc')

0 commit comments

Comments
 (0)