Skip to content

Commit e529eaf

Browse files
authored
Merge pull request #14 from contentstack/tokenHotfix
Unit Test automation script
2 parents eb682a1 + 4075527 commit e529eaf

File tree

11 files changed

+109
-98
lines changed

11 files changed

+109
-98
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ test/EntryTestReport.html
1010
test/Entryreport.html
1111
test/Entriesreport.html
1212
test/ImageTransformreport.html
13-
test/result.json
1413
examples/index.php
15-
.DS_Store
14+
.DS_Store
15+
tmp/
16+
stdout

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"files": ["src/Support/helper.php"]
2626
},
2727
"require-dev": {
28-
"phpunit/phpunit": "^9.0"
28+
"phpunit/phpunit": "^9.0",
29+
"phpunit/php-code-coverage": "^8.0"
2930
},
3031
"require": {
3132
"php" : ">=5.5.0"

phpunit.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit>
3+
<testsuites>
4+
<testsuite name="unit">
5+
<directory>test</directory>
6+
</testsuite>
7+
</testsuites>
8+
9+
<logging>
10+
<log type="coverage-html" target="./tmp/report" lowUpperBound="35"
11+
highLowerBound="70"/>
12+
<log type="coverage-clover" target="./tmp/coverage.xml"/>
13+
<log type="coverage-php" target="./tmp/coverage.serialized"/>
14+
<log type="coverage-text" target="./stdout" showUncoveredFiles="false"/>
15+
<log type="junit" target="./tmp/logfile.xml"/>
16+
<log type="testdox-html" target="./tmp/testdox.html"/>
17+
<log type="testdox-text" target="./tmp/testdox.txt"/>
18+
</logging>
19+
20+
<filter>
21+
<whitelist addUncoveredFilesFromWhitelist="true">
22+
<directory suffix=".php">src</directory>
23+
</whitelist>
24+
</filter>
25+
</phpunit>

src/Support/Utility.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
require_once __DIR__ . "/../lib/models/csexception.php";
1919

2020
use Contentstack\Error\CSException;
21-
use Contentstack\Result;
21+
use Contentstack\Result\Result;
2222

2323
/**
2424
* Utility/Helper where all the helper and utility functions will be available.

src/config/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
namespace Contentstack\Config;
1616

1717
// Domain relevant constants
18-
define('HOST', 'api.contentstack.io');
18+
define('HOST', 'cdn.contentstack.io');
1919
define('PROTOCOL', 'https');
2020
define('VERSION', '/v3');
2121
define('PORT', 443);

src/lib/models/result.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function toJSON()
6363
public function get($***)
6464
{
6565

66-
return ($*** && is_string($***)) ? $this->object[$***] : null;
66+
return ($*** && is_string($***)) ? $this->_object[$***] : null;
6767

6868
}
6969
}

src/lib/models/stack.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function __construct(
6262
) {
6363

6464
if ($region && $region =="eu" && $region !== "undefined") {
65-
$this->host = $region.'-'.HOST;
65+
$this->host = $region.'-cdn.contentstack.com';
6666
}
6767
$this->header = Utility::validateInput(
6868
'stack', array('api_***' => $api_***,
@@ -149,7 +149,7 @@ public function ImageTrasform($url, $parameters)
149149
public function getLastActivities()
150150
{
151151
$this->_query = array("only_last_activity" => "true");
152-
return Utility\getLastActivites($this);
152+
return Utility::getLastActivites($this);
153153
}
154154

155155
/**
@@ -161,7 +161,7 @@ public function getLastActivities()
161161
* */
162162
public function setHost($host = '')
163163
{
164-
Utility\validateInput('host', $host);
164+
Utility::validateInput('host', $host);
165165
$this->host = $host;
166166
return $this;
167167
}
@@ -183,7 +183,7 @@ public function getHost()
183183
* */
184184
public function setProtocol($protocol = '')
185185
{
186-
Utility\validateInput('protocol', $protocol);
186+
Utility::validateInput('protocol', $protocol);
187187
$this->protocol = $protocol;
188188
return $this;
189189
}
@@ -205,7 +205,7 @@ public function getProtocol()
205205
* */
206206
public function setPort($port = '')
207207
{
208-
Utility\validateInput('port', $port);
208+
Utility::validateInput('port', $port);
209209
$this->port = $port;
210210
return $this;
211211
}
@@ -229,7 +229,7 @@ public function getPort()
229229
* */
230230
public function setAPIKEY($api_*** = '')
231231
{
232-
Utility\validateInput('api_***', $api_***);
232+
Utility::validateInput('api_***', $api_***);
233233
$this->header['api_***'] = $api_***;
234234
return $this;
235235
}
@@ -242,7 +242,7 @@ public function setAPIKEY($api_*** = '')
242242
* */
243243
public function setDeliveryToken($delivery_token = '')
244244
{
245-
Utility\validateInput('access_token', $delivery_token);
245+
Utility::validateInput('access_token', $delivery_token);
246246
$this->header['access_token'] = $delivery_token;
247247
return $this;
248248
}
@@ -256,7 +256,7 @@ public function setDeliveryToken($delivery_token = '')
256256
* */
257257
public function setEnvironment($environment = '')
258258
{
259-
Utility\validateInput('environment', $environment);
259+
Utility::validateInput('environment', $environment);
260260
$this->environment = $environment;
261261
return $this;
262262
}

test/AssetsTest.php

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
require_once __DIR__ . '/../src/index.php';
66
require_once __DIR__ . '/utility.php';
77
use Contentstack\Test\REST;
8+
use Contentstack\Contentstack;
89

910
use PHPUnit\Framework\TestCase;
1011
use Contentstack\Support\Utility;
@@ -17,14 +18,17 @@ class AssetsTest extends TestCase {
1718
*/
1819
public static function setUpBeforeClass() : void {
1920
self::$rest = new REST();
20-
self::$Stack = Contentstack\Contentstack::Stack(self::$rest->getAPIKEY(), self::$rest->getAccessToken(), self::$rest->getEnvironmentName());
21+
self::$Stack = Contentstack::Stack(self::$rest->getAPIKEY(), self::$rest->getAccessToken(), self::$rest->getEnvironmentName());
22+
if (self::$rest->getHost() !== NULL) {
23+
self::$Stack->setHost(self::$rest->getHost());
24+
}
2125
}
2226
/*
2327
* Tear Down after the test suites executes
2428
*/
2529
public static function tearDownAfterClass() : void{
2630
if(ENV !== 'TEST_LOCAL') {
27-
self::$rest->deleteStack();
31+
// self::$rest->deleteStack();
2832
}
2933
}
3034

@@ -36,9 +40,10 @@ public function testAssetsFind() {
3640

3741
public function testAssetsFetch() {
3842
$_object = self::$Stack->Assets()->Query()->toJSON()->find();
43+
$_title = $_object[0][0]['title'];
3944
$_uid = $_object[0][0]['uid'];
4045
$_asset = self::$Stack->Assets($_uid)->fetch();
41-
$this->assertEquals($_asset->get('title'), $_object[0][0]['title']);
46+
$this->assertEquals($_asset->get('title'), $_title);
4247
}
4348

4449
public function testAssetsFindSkip() {
@@ -77,7 +82,6 @@ public function testAssetsFindLimit() {
7782
public function testAssetsAddParam() {
7883
$_assets = self::$Stack->Assets()->Query()->addParam('include_dimension', 'true')->toJSON()->find();
7984
$this->assertTrue(array_***_exists('dimension', $_assets[0][0]));
80-
8185
}
8286

8387

@@ -161,7 +165,6 @@ public function testAssetsFindDescending() {
161165
public function testAssetsFindLessThan() {
162166
$_set = 7575;
163167
$assets = self::$Stack->Assets()->Query()->toJSON()->lessThan('file_size', $_set)->find();
164-
Utility::debug($assets);
165168
$this->assertArrayHasKey(0, $assets);
166169
if(count($assets[0]) !== 0){
167170
foreach ($assets[0] as $*** => $val) {
@@ -173,7 +176,7 @@ public function testAssetsFindLessThan() {
173176
}
174177

175178
public function testAssetsFindLessThanEqualTo() {
176-
$_set = 12;
179+
$_set = 12000;
177180
$assets = self::$Stack->Assets()->Query()->toJSON()->lessThanEqualTo('file_size', $_set)->find();
178181
$this->assertArrayHasKey(0, $assets);
179182
if(count($assets[0]) !== 0) {
@@ -268,9 +271,10 @@ public function testAssetsFindLogicalOrRawQuery() {
268271

269272
public function testAssetsFindLogicalAndQueryObject() {
270273
$_value = 6161;
274+
$_value2 = 15000;
271275
$query1 = self::$Stack->Assets()->Query()->greaterThanEqualTo('file_size', $_value);
272276

273-
$query2 = self::$Stack->Assets()->Query()->lessThanEqualTo('file_size', $_value);
277+
$query2 = self::$Stack->Assets()->Query()->lessThanEqualTo('file_size', $_value2);
274278
$assets = self::$Stack->Assets()->Query()->logicalAND($query1, $query2)->toJSON()->find();
275279

276280
$this->assertArrayHasKey(0, $assets);
@@ -279,25 +283,26 @@ public function testAssetsFindLogicalAndQueryObject() {
279283

280284
public function testAssetsFindLogicalAndRawQuery() {
281285
$_value = 6161;
286+
$_value2 = 15000;
282287
$query1 = self::$Stack->Assets()->Query()->greaterThanEqualTo('file_size', $_value);
283-
$query2 = self::$Stack->Assets()->Query()->lessThanEqualTo('file_size', $_value);
288+
$query2 = self::$Stack->Assets()->Query()->lessThanEqualTo('file_size', $_value2);
284289
$assets = self::$Stack->Assets()->Query()->logicalAND($query1, $query2)->toJSON()->find();
285290
$this->assertArrayHasKey(0, $assets);
286291
$this->assertTrue(checkAssetsSorting($assets[0]));
287292
}
288293

289-
// public function testAssetsFindOnlyDefault() {
290-
// $_assets = self::$Stack->Assets()->Query()->only(array('title', 'updated_at'))->toJSON()->find();
291-
// $_assets_count = self::$Stack->Assets()->Query()->toJSON()->find();
292-
// $this->assertArrayHasKey(0, $_assets);
293-
// $this->assertTrue((count($_assets[0]) === count($_assets_count[0])));
294-
// $this->assertTrue(checkAssetsSorting($_assets[0]));
295-
// $flag = true;
296-
// for($i = 0; $i < count($_assets[0]); $i++) {
297-
// $flag = $flag && (count(array_***s($_assets[0][$i])) === 4 && isset($_assets[0][$i]['updated_at']) && isset($_assets[0][$i]['title']) && isset($_assets[0][$i]['uid']));
298-
// }
299-
// $this->assertTrue($flag);
300-
// }
294+
public function testAssetsFindOnlyDefault() {
295+
$_assets = self::$Stack->Assets()->Query()->only('BASE', array('title', 'updated_at'))->toJSON()->find();
296+
$_assets_count = self::$Stack->Assets()->Query()->toJSON()->find();
297+
$this->assertArrayHasKey(0, $_assets);
298+
$this->assertTrue((count($_assets[0]) === count($_assets_count[0])));
299+
$this->assertTrue(checkAssetsSorting($_assets[0]));
300+
$flag = true;
301+
for($i = 0; $i < count($_assets[0]); $i++) {
302+
$flag = $flag && (count(array_***s($_assets[0][$i])) === 6 && isset($_assets[0][$i]['updated_at']) && isset($_assets[0][$i]['filename']) && isset($_assets[0][$i]['ACL']) && isset($_assets[0][$i]['title']) && isset($_assets[0][$i]['uid']));
303+
}
304+
$this->assertTrue($flag);
305+
}
301306

302307
public function testAssetsFindRegEx() {
303308
$regexp = "[0-9]";
@@ -348,20 +353,19 @@ public function testAssetsFindExceptBaseDefault() {
348353
$this->assertTrue($flag);
349354
}
350355

351-
352-
// public function testAssetsFindOnlyBaseDefault() {
353-
// $_assets = self::$Stack->Assets()->Query()->only('BASE', array('title', 'updated_at'))->toJSON()->find();
354-
// $this->assertArrayHasKey(0, $_assets);
355-
// $assets = self::$Stack->Assets()->Query()->toJSON()->find();
356-
// $assets_count = count($assets[0]);
357-
// $this->assertTrue((count($_assets[0]) === $assets_count));
358-
// $this->assertTrue(checkAssetsSorting($_assets[0]));
359-
// $flag = true;
360-
// for($i = 0; $i < count($_assets[0]); $i++) {
361-
// $flag = $flag && (count(array_***s($_assets[0][$i])) === 4 && isset($_assets[0][$i]['url']) && isset($_assets[0][$i]['updated_at']) && isset($_assets[0][$i]['title']) && isset($_assets[0][$i]['uid']));
362-
// }
363-
// $this->assertTrue($flag);
364-
// }
356+
public function testAssetsFindOnlyBaseDefault() {
357+
$_assets = self::$Stack->Assets()->Query()->only('BASE', array('title', 'updated_at'))->toJSON()->find();
358+
$this->assertArrayHasKey(0, $_assets);
359+
$assets = self::$Stack->Assets()->Query()->toJSON()->find();
360+
$assets_count = count($assets[0]);
361+
$this->assertTrue((count($_assets[0]) === $assets_count));
362+
$this->assertTrue(checkAssetsSorting($_assets[0]));
363+
$flag = true;
364+
for($i = 0; $i < count($_assets[0]); $i++) {
365+
$flag = $flag && (count(array_***s($_assets[0][$i])) === 6 && isset($_assets[0][$i]['updated_at']) && isset($_assets[0][$i]['filename']) && isset($_assets[0][$i]['ACL']) && isset($_assets[0][$i]['title']) && isset($_assets[0][$i]['uid']));
366+
}
367+
$this->assertTrue($flag);
368+
}
365369

366370
public function testAssetsFindExceptDefault() {
367371
$_assets = self::$Stack->Assets()->Query()->except('BASE',array('boolean'))->toJSON()->find();
@@ -380,9 +384,9 @@ public function testAssetsFindExceptDefault() {
380384
public function testAssetsFindSearch() {
381385
$_assets = self::$Stack->Assets()->Query()->search('image/jpeg')->toJSON()->find();
382386
$this->assertArrayHasKey(0, $_assets);
383-
$assets = self::$Stack->Assets()->Query()->toJSON()->find();
384-
$assets_count = count($assets[0]);
385-
$this->assertTrue((count($_assets[0]) === $assets_count));
387+
// $assets = self::$Stack->Assets()->Query()->toJSON()->find();
388+
// $assets_count = count($assets[0]);
389+
$this->assertTrue((count($_assets[0]) === 2));
386390
$this->assertTrue(checkAssetsSorting($_assets[0]));
387391
$flag = true;
388392
for($i = 0; $i < count($_assets[0]); $i++) {

0 commit comments

Comments
 (0)