version 0.3
This commit is contained in:
5
test/bootstrap.php
Normal file
5
test/bootstrap.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
define('MASHAPE_CLIENT_LIBRAY_PATH', dirname(dirname(__FILE__)) . '/main/mashape');
|
||||
|
||||
?>
|
||||
29
test/mashape/http/HttpClientTest.php
Normal file
29
test/mashape/http/HttpClientTest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
require_once(MASHAPE_CLIENT_LIBRAY_PATH . "/http/HttpClient.php");
|
||||
|
||||
class HttpClientTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
function testDoRequest() {
|
||||
|
||||
try {
|
||||
HttpClient::doRequest("ciao", "http://www.ciao.com", null, null);
|
||||
$this->assertFalse(true);
|
||||
} catch (MashapeClientException $e) {
|
||||
$this->assertEquals(1003, $e->getCode());
|
||||
}
|
||||
|
||||
try {
|
||||
HttpClient::doRequest(HttpMethod::GET, "http://www.google.com", null, null);
|
||||
$this->assertFalse(true);
|
||||
} catch (MashapeClientException $e) {
|
||||
$this->assertEquals(2000, $e->getCode());
|
||||
}
|
||||
|
||||
$response = HttpClient::doRequest(HttpMethod::POST, "https://api.mashape.com/requestToken", null, null);
|
||||
$this->assertEquals(2001, $response->errors[0]->code);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
32
test/mashape/http/TokenUtilTest.php
Normal file
32
test/mashape/http/TokenUtilTest.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
require_once(MASHAPE_CLIENT_LIBRAY_PATH . "/http/TokenUtil.php");
|
||||
|
||||
class TokenUtilTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
function testRequestToken() {
|
||||
try {
|
||||
TokenUtil::requestToken(null);
|
||||
$this->assertFalse(true);
|
||||
} catch (MashapeClientException $e) {
|
||||
$this->assertEquals(2001, $e->getCode());
|
||||
}
|
||||
|
||||
try {
|
||||
TokenUtil::requestToken("");
|
||||
$this->assertFalse(true);
|
||||
} catch (MashapeClientException $e) {
|
||||
$this->assertEquals(2001, $e->getCode());
|
||||
}
|
||||
|
||||
try {
|
||||
TokenUtil::requestToken("bla");
|
||||
$this->assertFalse(true);
|
||||
} catch (MashapeClientException $e) {
|
||||
$this->assertEquals(2001, $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
146
test/mashape/http/UrlUtilsTest.php
Normal file
146
test/mashape/http/UrlUtilsTest.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
require_once(MASHAPE_CLIENT_LIBRAY_PATH . "/http/UrlUtils.php");
|
||||
|
||||
class UrlUtilsTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
function testPrepareRequest() {
|
||||
$url = "http://www.ciao.com";
|
||||
$parameters = null;
|
||||
UrlUtils::prepareRequest($url, $parameters);
|
||||
$this->assertEquals("http://www.ciao.com", $url);
|
||||
$this->assertEquals(array(), $parameters);
|
||||
|
||||
$url = "http://www.ciao.com";
|
||||
$parameters = array();
|
||||
UrlUtils::prepareRequest($url, $parameters);
|
||||
$this->assertEquals("http://www.ciao.com", $url);
|
||||
$this->assertEquals(array(), $parameters);
|
||||
|
||||
$url = "http://www.ciao.com/{id}";
|
||||
$parameters = null;
|
||||
UrlUtils::prepareRequest($url, $parameters);
|
||||
$this->assertEquals("http://www.ciao.com/", $url);
|
||||
$this->assertEquals(array(), $parameters);
|
||||
|
||||
$url = "http://www.ciao.com/{id}?name={name}";
|
||||
$parameters = null;
|
||||
UrlUtils::prepareRequest($url, $parameters);
|
||||
$this->assertEquals("http://www.ciao.com/", $url);
|
||||
$this->assertEquals(array(), $parameters);
|
||||
|
||||
$url = "http://www.ciao.com/{id}?name={name}";
|
||||
$parameters = array("id"=>12);
|
||||
UrlUtils::prepareRequest($url, $parameters);
|
||||
$this->assertEquals("http://www.ciao.com/12", $url);
|
||||
$this->assertEquals(array("id"=>"12"), $parameters);
|
||||
|
||||
$url = "http://www.ciao.com/{id}?name={name}";
|
||||
$parameters = array("id"=>12, "name"=>"tom");
|
||||
UrlUtils::prepareRequest($url, $parameters);
|
||||
$this->assertEquals("http://www.ciao.com/12?name=tom", $url);
|
||||
$this->assertEquals(array("id"=>12, "name"=>"tom"), $parameters);
|
||||
|
||||
$url = "http://www.ciao.com/{id}?name={name}&opt=1";
|
||||
$parameters = array("id"=>12, "name"=>"tom");
|
||||
UrlUtils::prepareRequest($url, $parameters);
|
||||
$this->assertEquals("http://www.ciao.com/12?name=tom&opt=1", $url);
|
||||
$this->assertEquals(array("id"=>12, "name"=>"tom"), $parameters);
|
||||
|
||||
$url = "http://www.ciao.com/{id}?name={name}&opt=1";
|
||||
$parameters = array("id"=>12, "name"=>"tom jerry");
|
||||
UrlUtils::prepareRequest($url, $parameters);
|
||||
$this->assertEquals("http://www.ciao.com/12?name=tom+jerry&opt=1", $url);
|
||||
$this->assertEquals(array("id"=>12, "name"=>"tom jerry"), $parameters);
|
||||
|
||||
$url = "http://www.ciao.com/{id}?name={name}&opt=1&nick={nick}";
|
||||
$parameters = array("id"=>12, "name"=>"tom jerry");
|
||||
UrlUtils::prepareRequest($url, $parameters);
|
||||
$this->assertEquals("http://www.ciao.com/12?name=tom+jerry&opt=1", $url);
|
||||
$this->assertEquals(array("id"=>12, "name"=>"tom jerry"), $parameters);
|
||||
|
||||
$url = "http://www.ciao.com/{id}?name={name}&opt={opt}&nick={nick}";
|
||||
$parameters = array("id"=>12, "name"=>"tom jerry", "nick"=>"sinz");
|
||||
UrlUtils::prepareRequest($url, $parameters);
|
||||
$this->assertEquals("http://www.ciao.com/12?name=tom+jerry&nick=sinz", $url);
|
||||
$this->assertEquals(array("id"=>12, "name"=>"tom jerry", "nick"=>"sinz"), $parameters);
|
||||
|
||||
$url = "http://www.ciao.com/{id}?name={name}&opt={opt}&nick={nick}";
|
||||
$parameters = array("id"=>12, "name"=>"tom jerry", "opt"=>"yes", "nick"=>"sinz");
|
||||
UrlUtils::prepareRequest($url, $parameters);
|
||||
$this->assertEquals("http://www.ciao.com/12?name=tom+jerry&opt=yes&nick=sinz", $url);
|
||||
$this->assertEquals(array("id"=>12, "name"=>"tom jerry", "opt"=>"yes", "nick"=>"sinz"), $parameters);
|
||||
|
||||
$url = "http://www.ciao.com/{id}?name={name}&opt={opt}&nick={nick}";
|
||||
$parameters = array("id"=>12, "opt"=>"yes", "nick"=>"sinz");
|
||||
UrlUtils::prepareRequest($url, $parameters);
|
||||
$this->assertEquals("http://www.ciao.com/12?opt=yes&nick=sinz", $url);
|
||||
$this->assertEquals(array("id"=>12, "opt"=>"yes", "nick"=>"sinz"), $parameters);
|
||||
|
||||
$url = "http://www.ciao.com/{id}?name={name}&opt={opt}&nick={nick}";
|
||||
$parameters = array("id"=>12, "opt"=>"yes");
|
||||
UrlUtils::prepareRequest($url, $parameters);
|
||||
$this->assertEquals("http://www.ciao.com/12?opt=yes", $url);
|
||||
$this->assertEquals(array("id"=>12, "opt"=>"yes"), $parameters);
|
||||
|
||||
$url = "http://www.ciao.com/{id}?name={name}&opt={opt}&nick={nick}";
|
||||
$parameters = array("id"=>12, "nick"=>"sinz");
|
||||
UrlUtils::prepareRequest($url, $parameters);
|
||||
$this->assertEquals("http://www.ciao.com/12?nick=sinz", $url);
|
||||
$this->assertEquals(array("id"=>12, "nick"=>"sinz"), $parameters);
|
||||
|
||||
$url = "http://www.ciao.com/{id}?name={name}&opt={opt}&nick={nick}";
|
||||
$parameters = array("id"=>12);
|
||||
UrlUtils::prepareRequest($url, $parameters);
|
||||
$this->assertEquals("http://www.ciao.com/12", $url);
|
||||
$this->assertEquals(array("id"=>12), $parameters);
|
||||
|
||||
$url = "http://www.ciao.com/{id}?name={name}&opt={opt}&nick={nick}";
|
||||
$parameters = array("id"=>12, "pippo"=>null);
|
||||
UrlUtils::prepareRequest($url, $parameters);
|
||||
$this->assertEquals("http://www.ciao.com/12", $url);
|
||||
$this->assertEquals(array("id"=>12), $parameters);
|
||||
|
||||
$url = "http://www.ciao.com/{id}?name={name}&opt={opt}&nick=some+nick";
|
||||
$parameters = array("id"=>"ciao marco", "name"=>"ciao pippo", "opt"=>"2");
|
||||
UrlUtils::prepareRequest($url, $parameters);
|
||||
$this->assertEquals("http://www.ciao.com/ciao%20marco?name=ciao+pippo&opt=2&nick=some+nick", $url);
|
||||
$this->assertEquals(array("id"=>"ciao marco", "name"=>"ciao pippo", "opt"=>"2"), $parameters);
|
||||
|
||||
$url = "http://www.ciao.com/{id}?name={name}&opt={opt}&nick=some+nick";
|
||||
$parameters = array("id"=>"ciao marco", "name"=>"ciao pippo", "opt"=>"{this is opt}");
|
||||
UrlUtils::prepareRequest($url, $parameters);
|
||||
$this->assertEquals("http://www.ciao.com/ciao%20marco?name=ciao+pippo&opt=%7Bthis+is+opt%7D&nick=some+nick", $url);
|
||||
$this->assertEquals(array("id"=>"ciao marco", "name"=>"ciao pippo", "opt"=>"{this is opt}"), $parameters);
|
||||
}
|
||||
|
||||
function testAddClientParameters() {
|
||||
$url = "http://www.ciao.com";
|
||||
$parameters = array();
|
||||
UrlUtils::addClientParameters($url, $parameters, null);
|
||||
$this->assertEquals("http://www.ciao.com?_token={_token}&_language={_language}&_version={_version}", $url);
|
||||
$this->assertEquals(array("_token"=>null, "_language"=>"PHP", "_version"=>"V03"), $parameters);
|
||||
|
||||
$url = "http://www.ciao.com?name={name}";
|
||||
$parameters = array("name"=>"Marco");
|
||||
UrlUtils::addClientParameters($url, $parameters, null);
|
||||
$this->assertEquals("http://www.ciao.com?name={name}&_token={_token}&_language={_language}&_version={_version}", $url);
|
||||
$this->assertEquals(array("name"=>"Marco", "_token"=>null, "_language"=>"PHP", "_version"=>"V03"), $parameters);
|
||||
|
||||
$url = "http://www.ciao.com?name={name}";
|
||||
$parameters = array("name"=>"Marco");
|
||||
UrlUtils::addClientParameters($url, $parameters, "a-random-token");
|
||||
$this->assertEquals("http://www.ciao.com?name={name}&_token={_token}&_language={_language}&_version={_version}", $url);
|
||||
$this->assertEquals(array("name"=>"Marco", "_token"=>"a-random-token", "_language"=>"PHP", "_version"=>"V03"), $parameters);
|
||||
|
||||
$url = "http://www.ciao.com?name={name}";
|
||||
$parameters = array("name"=>"Marco");
|
||||
UrlUtils::addClientParameters($url, $parameters, "a-random-token");
|
||||
UrlUtils::prepareRequest($url, $parameters);
|
||||
$this->assertEquals("http://www.ciao.com?name=Marco&_token=a-random-token&_language=PHP&_version=V03", $url);
|
||||
$this->assertEquals(array("name"=>"Marco", "_token"=>"a-random-token", "_language"=>"PHP", "_version"=>"V03"), $parameters);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
12
test/phpunit.CI.xml
Normal file
12
test/phpunit.CI.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit
|
||||
bootstrap="./bootstrap.php"
|
||||
colors="false"
|
||||
backupGlobals="false"
|
||||
backupStaticAttributes="false">
|
||||
|
||||
<testsuite name="Mashape Client Test Suite">
|
||||
<directory>./mashape</directory>
|
||||
</testsuite>
|
||||
|
||||
</phpunit>
|
||||
12
test/phpunit.xml
Normal file
12
test/phpunit.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit
|
||||
bootstrap="./bootstrap.php"
|
||||
colors="true"
|
||||
backupGlobals="false"
|
||||
backupStaticAttributes="false">
|
||||
|
||||
<testsuite name="Mashape Client Test Suite">
|
||||
<directory>./mashape</directory>
|
||||
</testsuite>
|
||||
|
||||
</phpunit>
|
||||
Reference in New Issue
Block a user