Skip to content

Commit 01f7f54

Browse files
updated in testcases folder
1 parent ff63400 commit 01f7f54

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

test/ContentStackTestCases.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
require_once __DIR__ . '/REST.php';
33
require_once __DIR__ . '/constants.php';
44
require_once __DIR__ . '/utility.php';
5+
56
require_once __DIR__ . '/../lib/index.php';
67

78
use Contentstack\Test\REST;
89

910
use PHPUnit\Framework\TestCase;
10-
1111
class ContentStackTestCases extends TestCase {
1212
public static $rest;
1313
public static $Stack;
@@ -34,9 +34,25 @@ public function testFind() {
3434
$this->assertTrue(checkEntriesSorting($_entries[0]));
3535
}
3636

37+
public function testAssetsFind() {
38+
$_assets = self::$Stack->Assets()->QueryAssets()->toJSON()->find();
39+
$this->assertArrayHasKey(0, $_assets);
40+
// $this->assertTrue((count($_assets[0]) === ENTRY_COUNT));
41+
$this->assertTrue(checkAssetsSorting($_assets[0]));
42+
}
43+
44+
45+
public function testAssetFetch() {
46+
$_object = self::$Stack->Assets()->QueryAssets()->toJSON()->find();
47+
$_uid = $_object[0][0]['uid'];
48+
$_asset = self::$Stack->Asset($_uid)->fetch();
49+
//\Contentstack\Utility\debug($_asset);
50+
$this->assertEquals($_asset->getTitle(), $_object[0][0]['title']);
51+
}
52+
3753
public function testFindOne() {
3854
$_entry = self::$Stack->ContentType(CT_ContentType)->Query()->toJSON()->findOne();
39-
// $this->assertObjectHasAttribute('object', $_entry);
55+
// $this->assertObjectHasAttribute('object', $_entry);
4056
$this->assertEquals($_entry['title'], getResultEntries(CT_ContentType, ENTRY_COUNT - 1)['title']);
4157
}
4258

@@ -249,7 +265,7 @@ public function testFindNotExists() {
249265

250266
public function testFindAscending() {
251267
$field = 'created_at';
252-
$entries = self::$Stack->ContentType(CT_ContentType)->Query()->toJSON()->ascending('created_at')->find();
268+
$entries = self::$Stack->ContentType(CT_ContentType)->Query()->toJSON()->ascending($field)->find();
253269
$this->assertArrayHasKey(0, $entries);
254270
$this->assertTrue((count($entries[0]) === ENTRY_COUNT));
255271
$this->assertTrue(checkEntriesSorting($entries[0], $field, 'asc'));

test/utility.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ function checkEntriesSorting($entries = array(), $sortKey = 'updated_at', $order
1414
}
1515
}
1616

17+
if (!function_exists('assetsSorting')) {
18+
19+
function checkAssetsSorting($assets = array(), $sortKey = 'updated_at', $order = 'desc') {
20+
$result = true;
21+
for($i = 0;$i < count($assets) - 1; $i++) {
22+
if($order === 'desc')
23+
$result = $result && ($assets[$i][$sortKey] >= $assets[$i+1][$sortKey]);
24+
else
25+
$result = $result && ($assets[$i][$sortKey] <= $assets[$i+1][$sortKey]);
26+
}
27+
return $result;
28+
}
29+
}
30+
1731
if (!function_exists('sortEntries')) {
1832
function sortEntries($entries = array(), $sortKey = 'updated_at', $order = 'desc') {
1933
\Contentstack\Utility\debug(array_column($entries, $sortKey));

0 commit comments

Comments
 (0)