Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ test/EntryTestReport.html
test/Entryreport.html
test/Entriesreport.html
test/ImageTransformreport.html
test/result.json
examples/index.php
.DS_Store
.DS_Store
tmp/
stdout
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"files": ["src/Support/helper.php"]
},
"require-dev": {
"phpunit/phpunit": "^9.0"
"phpunit/phpunit": "^9.0",
"phpunit/php-code-coverage": "^8.0"
},
"require": {
"php" : ">=5.5.0"
Expand Down
25 changes: 25 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit>
<testsuites>
<testsuite name="unit">
<directory>test</directory>
</testsuite>
</testsuites>

<logging>
<log type="coverage-html" target="./tmp/report" lowUpperBound="35"
highLowerBound="70"/>
<log type="coverage-clover" target="./tmp/coverage.xml"/>
<log type="coverage-php" target="./tmp/coverage.serialized"/>
<log type="coverage-text" target="./stdout" showUncoveredFiles="false"/>
<log type="junit" target="./tmp/logfile.xml"/>
<log type="testdox-html" target="./tmp/testdox.html"/>
<log type="testdox-text" target="./tmp/testdox.txt"/>
</logging>

<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
2 changes: 1 addition & 1 deletion src/Support/Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
require_once __DIR__ . "/../lib/models/csexception.php";

use Contentstack\Error\CSException;
use Contentstack\Result;
use Contentstack\Result\Result;

/**
* Utility/Helper where all the helper and utility functions will be available.
Expand Down
2 changes: 1 addition & 1 deletion src/config/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace Contentstack\Config;

// Domain relevant constants
define('HOST', 'api.contentstack.io');
define('HOST', 'cdn.contentstack.io');
define('PROTOCOL', 'https');
define('VERSION', '/v3');
define('PORT', 443);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/models/result.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function toJSON()
public function get($key)
{

return ($key && is_string($key)) ? $this->object[$key] : null;
return ($key && is_string($key)) ? $this->_object[$key] : null;

}
}
16 changes: 8 additions & 8 deletions src/lib/models/stack.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct(
) {

if ($region && $region =="eu" && $region !== "undefined") {
$this->host = $region.'-'.HOST;
$this->host = $region.'-cdn.contentstack.com';
}
$this->header = Utility::validateInput(
'stack', array('api_key' => $api_key,
Expand Down Expand Up @@ -149,7 +149,7 @@ public function ImageTrasform($url, $parameters)
public function getLastActivities()
{
$this->_query = array("only_last_activity" => "true");
return Utility\getLastActivites($this);
return Utility::getLastActivites($this);
}

/**
Expand All @@ -161,7 +161,7 @@ public function getLastActivities()
* */
public function setHost($host = '')
{
Utility\validateInput('host', $host);
Utility::validateInput('host', $host);
$this->host = $host;
return $this;
}
Expand All @@ -183,7 +183,7 @@ public function getHost()
* */
public function setProtocol($protocol = '')
{
Utility\validateInput('protocol', $protocol);
Utility::validateInput('protocol', $protocol);
$this->protocol = $protocol;
return $this;
}
Expand All @@ -205,7 +205,7 @@ public function getProtocol()
* */
public function setPort($port = '')
{
Utility\validateInput('port', $port);
Utility::validateInput('port', $port);
$this->port = $port;
return $this;
}
Expand All @@ -229,7 +229,7 @@ public function getPort()
* */
public function setAPIKEY($api_key = '')
{
Utility\validateInput('api_key', $api_key);
Utility::validateInput('api_key', $api_key);
$this->header['api_key'] = $api_key;
return $this;
}
Expand All @@ -242,7 +242,7 @@ public function setAPIKEY($api_key = '')
* */
public function setDeliveryToken($delivery_token = '')
{
Utility\validateInput('access_token', $delivery_token);
Utility::validateInput('access_token', $delivery_token);
$this->header['access_token'] = $delivery_token;
return $this;
}
Expand All @@ -256,7 +256,7 @@ public function setDeliveryToken($delivery_token = '')
* */
public function setEnvironment($environment = '')
{
Utility\validateInput('environment', $environment);
Utility::validateInput('environment', $environment);
$this->environment = $environment;
return $this;
}
Expand Down
78 changes: 41 additions & 37 deletions test/AssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require_once __DIR__ . '/../src/index.php';
require_once __DIR__ . '/utility.php';
use Contentstack\Test\REST;
use Contentstack\Contentstack;

use PHPUnit\Framework\TestCase;
use Contentstack\Support\Utility;
Expand All @@ -17,14 +18,17 @@ class AssetsTest extends TestCase {
*/
public static function setUpBeforeClass() : void {
self::$rest = new REST();
self::$Stack = Contentstack\Contentstack::Stack(self::$rest->getAPIKEY(), self::$rest->getAccessToken(), self::$rest->getEnvironmentName());
self::$Stack = Contentstack::Stack(self::$rest->getAPIKEY(), self::$rest->getAccessToken(), self::$rest->getEnvironmentName());
if (self::$rest->getHost() !== NULL) {
self::$Stack->setHost(self::$rest->getHost());
}
}
/*
* Tear Down after the test suites executes
*/
public static function tearDownAfterClass() : void{
if(ENV !== 'TEST_LOCAL') {
self::$rest->deleteStack();
// self::$rest->deleteStack();
}
}

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

public function testAssetsFetch() {
$_object = self::$Stack->Assets()->Query()->toJSON()->find();
$_title = $_object[0][0]['title'];
$_uid = $_object[0][0]['uid'];
$_asset = self::$Stack->Assets($_uid)->fetch();
$this->assertEquals($_asset->get('title'), $_object[0][0]['title']);
$this->assertEquals($_asset->get('title'), $_title);
}

public function testAssetsFindSkip() {
Expand Down Expand Up @@ -77,7 +82,6 @@ public function testAssetsFindLimit() {
public function testAssetsAddParam() {
$_assets = self::$Stack->Assets()->Query()->addParam('include_dimension', 'true')->toJSON()->find();
$this->assertTrue(array_key_exists('dimension', $_assets[0][0]));

}


Expand Down Expand Up @@ -161,7 +165,6 @@ public function testAssetsFindDescending() {
public function testAssetsFindLessThan() {
$_set = 7575;
$assets = self::$Stack->Assets()->Query()->toJSON()->lessThan('file_size', $_set)->find();
Utility::debug($assets);
$this->assertArrayHasKey(0, $assets);
if(count($assets[0]) !== 0){
foreach ($assets[0] as $key => $val) {
Expand All @@ -173,7 +176,7 @@ public function testAssetsFindLessThan() {
}

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

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

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

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

public function testAssetsFindLogicalAndRawQuery() {
$_value = 6161;
$_value2 = 15000;
$query1 = self::$Stack->Assets()->Query()->greaterThanEqualTo('file_size', $_value);
$query2 = self::$Stack->Assets()->Query()->lessThanEqualTo('file_size', $_value);
$query2 = self::$Stack->Assets()->Query()->lessThanEqualTo('file_size', $_value2);
$assets = self::$Stack->Assets()->Query()->logicalAND($query1, $query2)->toJSON()->find();
$this->assertArrayHasKey(0, $assets);
$this->assertTrue(checkAssetsSorting($assets[0]));
}

// public function testAssetsFindOnlyDefault() {
// $_assets = self::$Stack->Assets()->Query()->only(array('title', 'updated_at'))->toJSON()->find();
// $_assets_count = self::$Stack->Assets()->Query()->toJSON()->find();
// $this->assertArrayHasKey(0, $_assets);
// $this->assertTrue((count($_assets[0]) === count($_assets_count[0])));
// $this->assertTrue(checkAssetsSorting($_assets[0]));
// $flag = true;
// for($i = 0; $i < count($_assets[0]); $i++) {
// $flag = $flag && (count(array_keys($_assets[0][$i])) === 4 && isset($_assets[0][$i]['updated_at']) && isset($_assets[0][$i]['title']) && isset($_assets[0][$i]['uid']));
// }
// $this->assertTrue($flag);
// }
public function testAssetsFindOnlyDefault() {
$_assets = self::$Stack->Assets()->Query()->only('BASE', array('title', 'updated_at'))->toJSON()->find();
$_assets_count = self::$Stack->Assets()->Query()->toJSON()->find();
$this->assertArrayHasKey(0, $_assets);
$this->assertTrue((count($_assets[0]) === count($_assets_count[0])));
$this->assertTrue(checkAssetsSorting($_assets[0]));
$flag = true;
for($i = 0; $i < count($_assets[0]); $i++) {
$flag = $flag && (count(array_keys($_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']));
}
$this->assertTrue($flag);
}

public function testAssetsFindRegEx() {
$regexp = "[0-9]";
Expand Down Expand Up @@ -348,20 +353,19 @@ public function testAssetsFindExceptBaseDefault() {
$this->assertTrue($flag);
}


// public function testAssetsFindOnlyBaseDefault() {
// $_assets = self::$Stack->Assets()->Query()->only('BASE', array('title', 'updated_at'))->toJSON()->find();
// $this->assertArrayHasKey(0, $_assets);
// $assets = self::$Stack->Assets()->Query()->toJSON()->find();
// $assets_count = count($assets[0]);
// $this->assertTrue((count($_assets[0]) === $assets_count));
// $this->assertTrue(checkAssetsSorting($_assets[0]));
// $flag = true;
// for($i = 0; $i < count($_assets[0]); $i++) {
// $flag = $flag && (count(array_keys($_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']));
// }
// $this->assertTrue($flag);
// }
public function testAssetsFindOnlyBaseDefault() {
$_assets = self::$Stack->Assets()->Query()->only('BASE', array('title', 'updated_at'))->toJSON()->find();
$this->assertArrayHasKey(0, $_assets);
$assets = self::$Stack->Assets()->Query()->toJSON()->find();
$assets_count = count($assets[0]);
$this->assertTrue((count($_assets[0]) === $assets_count));
$this->assertTrue(checkAssetsSorting($_assets[0]));
$flag = true;
for($i = 0; $i < count($_assets[0]); $i++) {
$flag = $flag && (count(array_keys($_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']));
}
$this->assertTrue($flag);
}

public function testAssetsFindExceptDefault() {
$_assets = self::$Stack->Assets()->Query()->except('BASE',array('boolean'))->toJSON()->find();
Expand All @@ -380,9 +384,9 @@ public function testAssetsFindExceptDefault() {
public function testAssetsFindSearch() {
$_assets = self::$Stack->Assets()->Query()->search('image/jpeg')->toJSON()->find();
$this->assertArrayHasKey(0, $_assets);
$assets = self::$Stack->Assets()->Query()->toJSON()->find();
$assets_count = count($assets[0]);
$this->assertTrue((count($_assets[0]) === $assets_count));
// $assets = self::$Stack->Assets()->Query()->toJSON()->find();
// $assets_count = count($assets[0]);
$this->assertTrue((count($_assets[0]) === 2));
$this->assertTrue(checkAssetsSorting($_assets[0]));
$flag = true;
for($i = 0; $i < count($_assets[0]); $i++) {
Expand Down
Loading