diff --git a/README.md b/README.md index ae246e7..9ad872d 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ See Exads API's documentation. ## Features -* Follows PSR-0 conventions and coding standard: autoload friendly +* Follows PSR-2 conventions and coding standard: autoload friendly * API entry points implementation state : * Campaign * Collection diff --git a/lib/Exads/Api/AbstractPayment.php b/lib/Exads/Api/AbstractPayment.php index 8e10182..d389be7 100644 --- a/lib/Exads/Api/AbstractPayment.php +++ b/lib/Exads/Api/AbstractPayment.php @@ -3,7 +3,7 @@ namespace Exads\Api; /** - * @link https://api.exads.com/v2/docs/index.html#!/payments + * @link https://api.exoclick.com/v2/docs/index.html#!/47payments */ class AbstractPayment extends AbstractApi { diff --git a/lib/Exads/Api/AbstractStatistics.php b/lib/Exads/Api/AbstractStatistics.php index ecbf865..a2452fd 100644 --- a/lib/Exads/Api/AbstractStatistics.php +++ b/lib/Exads/Api/AbstractStatistics.php @@ -3,7 +3,7 @@ namespace Exads\Api; /** - * @link https://api.exads.com/v2/docs/index.html#!/statistics + * @link https://api.exoclick.com/v2/docs/index.html#!/47statistics */ abstract class AbstractStatistics extends AbstractApi { diff --git a/lib/Exads/Api/Campaign.php b/lib/Exads/Api/Campaign.php index 2fa5f7a..e974708 100644 --- a/lib/Exads/Api/Campaign.php +++ b/lib/Exads/Api/Campaign.php @@ -3,7 +3,7 @@ namespace Exads\Api; /** - * @link https://api.exads.com/v2/docs/index.html#!/campaigns + * @link https://api.exoclick.com/v2/docs/index.html#!/47campaigns */ class Campaign extends AbstractApi { @@ -249,16 +249,21 @@ protected function getPath($endPoint = null, $id = null, $type = null) ); if (null !== $type) { - // add targeted/blocked elements routes $elementTypes = $this->getElementTypes($endPoint); - foreach ($elementTypes as $elementType) { - $pathMapping[$elementType] = '%s/%s/%s/'.$elementType; - if ('countries' === $elementType) { - continue; - } - $pathMapping[$elementType.'_all'] = '%s/%s/%s/'.$elementType.'/all'; + + $realEndPoint = preg_replace('/_(all)$/', '/$1', $endPoint); + + if (in_array($realEndPoint, array('countries/all', 'categories/all'))) { + throw new \InvalidArgumentException("$realEndPoint does not exist"); + } elseif (in_array($realEndPoint, array('countries', 'categories')) && $type == 'blocked') { + throw new \InvalidArgumentException("$realEndPoint does not support type $type"); + } elseif (!in_array($type, array('blocked', 'targeted'))) { + throw new \InvalidArgumentException("Unsupported type $type"); + } else { + return sprintf('%s/%s/%s/'.$realEndPoint, $this->apiGroup, urlencode($id), urlencode($type)); } } + if (!isset($pathMapping[$endPoint])) { throw new \InvalidArgumentException('Non existing path'); } @@ -267,11 +272,7 @@ protected function getPath($endPoint = null, $id = null, $type = null) if (null === $id) { return sprintf($path, $this->apiGroup); } - if (null === $type) { - return sprintf($path, $this->apiGroup, urlencode($id)); - } - - return sprintf($path, $this->apiGroup, urlencode($id), urlencode($type)); + return sprintf($path, $this->apiGroup, urlencode($id)); } /** @@ -283,6 +284,8 @@ protected function getPath($endPoint = null, $id = null, $type = null) */ private function getElementTypes($type) { + $type = preg_replace('/_all$/', '', $type); + $elementTypes = array( 'browsers', 'carriers', @@ -297,14 +300,10 @@ private function getElementTypes($type) ); // validate elementType - $tmp = $elementTypes; - foreach ($tmp as $type) { - $tmp[] = $type.'_all'; - } - if (!in_array($type, $tmp, true)) { + if (!in_array($type, $elementTypes, true)) { throw new \InvalidArgumentException( sprintf( - 'Unknown element type "%s". Availabe types : %s', + 'Unknown element type "%s". Available types : %s', $type, implode(', ', $elementTypes) ) diff --git a/lib/Exads/Api/Collection.php b/lib/Exads/Api/Collection.php index 601f7c5..5f5f625 100644 --- a/lib/Exads/Api/Collection.php +++ b/lib/Exads/Api/Collection.php @@ -3,7 +3,7 @@ namespace Exads\Api; /** - * @link https://api.exads.com/v2/docs/index.html#!/collections + * @link https://api.exoclick.com/v2/docs/index.html#!/47collections */ class Collection extends AbstractApi { diff --git a/lib/Exads/Api/Login.php b/lib/Exads/Api/Login.php index c042ae6..8469db0 100644 --- a/lib/Exads/Api/Login.php +++ b/lib/Exads/Api/Login.php @@ -3,7 +3,7 @@ namespace Exads\Api; /** - * @link https://api.exads.com/v2/docs/index.html#!/login + * @link https://api.exoclick.com/v2/docs/index.html#!/47login */ class Login extends AbstractApi { diff --git a/lib/Exads/Api/Offer.php b/lib/Exads/Api/Offer.php index 955770e..0a4e6f8 100644 --- a/lib/Exads/Api/Offer.php +++ b/lib/Exads/Api/Offer.php @@ -3,7 +3,7 @@ namespace Exads\Api; /** - * @link https://api.exads.com/v2/docs/index.html#!/offers + * @link https://api.exoclick.com/v2/docs/index.html#!/47offers */ class Offer extends AbstractApi { diff --git a/lib/Exads/Api/PaymentAdvertiser.php b/lib/Exads/Api/PaymentAdvertiser.php index 41041ec..5407f58 100644 --- a/lib/Exads/Api/PaymentAdvertiser.php +++ b/lib/Exads/Api/PaymentAdvertiser.php @@ -3,7 +3,7 @@ namespace Exads\Api; /** - * @link https://api.exads.com/v2/docs/index.html#!/payments + * @link https://api.exoclick.com/v2/docs/index.html#!/47payments */ class PaymentAdvertiser extends AbstractPayment { diff --git a/lib/Exads/Api/PaymentPublisher.php b/lib/Exads/Api/PaymentPublisher.php index baf79d1..b5f45fe 100644 --- a/lib/Exads/Api/PaymentPublisher.php +++ b/lib/Exads/Api/PaymentPublisher.php @@ -3,7 +3,7 @@ namespace Exads\Api; /** - * @link https://api.exads.com/v2/docs/index.html#!/payments + * @link https://api.exoclick.com/v2/docs/index.html#!/47payments */ class PaymentPublisher extends AbstractPayment { diff --git a/lib/Exads/Api/Site.php b/lib/Exads/Api/Site.php index dff3a53..ad380e6 100644 --- a/lib/Exads/Api/Site.php +++ b/lib/Exads/Api/Site.php @@ -3,7 +3,7 @@ namespace Exads\Api; /** - * @link https://api.exads.com/v2/docs/index.html#!/sites + * @link https://api.exoclick.com/v2/docs/index.html#!/47sites */ class Site extends AbstractApi { diff --git a/lib/Exads/Api/StatisticsAdvertiser.php b/lib/Exads/Api/StatisticsAdvertiser.php index 4c89233..157b00e 100644 --- a/lib/Exads/Api/StatisticsAdvertiser.php +++ b/lib/Exads/Api/StatisticsAdvertiser.php @@ -3,7 +3,7 @@ namespace Exads\Api; /** - * @link https://api.exads.com/v2/docs/index.html#!/statistics + * @link https://api.exoclick.com/v2/docs/index.html#!/47statistics */ class StatisticsAdvertiser extends AbstractStatistics { diff --git a/lib/Exads/Api/StatisticsPublisher.php b/lib/Exads/Api/StatisticsPublisher.php index 483896d..480e5cc 100644 --- a/lib/Exads/Api/StatisticsPublisher.php +++ b/lib/Exads/Api/StatisticsPublisher.php @@ -3,7 +3,7 @@ namespace Exads\Api; /** - * @link https://api.exads.com/v2/docs/index.html#!/statistics + * @link https://api.exoclick.com/v2/docs/index.html#!/47statistics */ class StatisticsPublisher extends AbstractStatistics { @@ -18,14 +18,4 @@ public function sub(array $params = array()) { return $this->get($this->getPath('sub'), $params); } - - /** - * @param array $params - * - * @return array - */ - public function zone(array $params = array()) - { - return $this->get($this->getPath('zone'), $params); - } } diff --git a/lib/Exads/Api/User.php b/lib/Exads/Api/User.php index 9313de1..ac79128 100644 --- a/lib/Exads/Api/User.php +++ b/lib/Exads/Api/User.php @@ -3,7 +3,7 @@ namespace Exads\Api; /** - * @link https://api.exads.com/v2/docs/index.html#!/user + * @link https://api.exoclick.com/v2/docs/index.html#!/47user */ class User extends AbstractApi { diff --git a/lib/Exads/Api/Zone.php b/lib/Exads/Api/Zone.php index 39dedea..41ced2f 100644 --- a/lib/Exads/Api/Zone.php +++ b/lib/Exads/Api/Zone.php @@ -3,7 +3,7 @@ namespace Exads\Api; /** - * @link https://api.exads.com/v2/docs/index.html#!/zones + * @link https://api.exoclick.com/v2/docs/index.html#!/47zones */ class Zone extends AbstractApi { diff --git a/lib/Exads/Client.php b/lib/Exads/Client.php index d3b5fb6..3a960a6 100644 --- a/lib/Exads/Client.php +++ b/lib/Exads/Client.php @@ -19,6 +19,7 @@ * @property-read Api\StatisticsPublisher $statistics_publisher * @property-read Api\User $user * @property-read Api\Zone $zones + * @property-read Api\Offer $offers */ class Client implements ClientInterface { @@ -101,6 +102,7 @@ class Client implements ClientInterface 'statistics_publisher' => 'StatisticsPublisher', 'user' => 'User', 'zones' => 'Zone', + 'offers' => 'Offer', ); /** @@ -227,7 +229,7 @@ public function decode($json) */ public function post($path, $data = null, $headers = []) { - if ( empty($headers['Content-Type']) || $headers['Content-Type'] == 'application/json' ) { + if (empty($headers['Content-Type']) || $headers['Content-Type'] == 'application/json') { $data = $this->encodeData($data); } @@ -397,11 +399,11 @@ protected function runRequest($path, $method = 'GET', $data = '', $headers = []) 'Content-Type: application/json' ); - if ( ! empty($headers) ) { + if (! empty($headers)) { foreach ($headers as $key => $value) { - $existingKey = $this->array_match(sprintf("%s", $key), $requestHeader); + $existingKey = $this->arrayMatch(sprintf("%s", $key), $requestHeader); $valueStr = sprintf("%s: %s", $key, $value); - if ( $existingKey !== false ) { + if ($existingKey !== false) { $requestHeader[$existingKey] = $valueStr; } else { $requestHeader[] = $valueStr; @@ -427,7 +429,6 @@ protected function runRequest($path, $method = 'GET', $data = '', $headers = []) } break; case 'DELETE': - curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE'); if (isset($data)) { curl_setopt($curl, CURLOPT_POSTFIELDS, $data); @@ -519,17 +520,17 @@ private function parseResponse($rawResponse, $headerSize) * @param $haystack * @return bool|int */ - public function array_match($needle, $haystack) + public function arrayMatch($needle, $haystack) { $i = 0; $n = count($haystack); $key = false; do { - if ( strpos($haystack[$i], $needle) !== false ) { + if (strpos($haystack[$i], $needle) !== false) { $key = $i; } $i ++; - } while ( $key === false && $i < $n ); + } while ($key === false && $i < $n); return $key; } diff --git a/test/Exads/Tests/ClientTest.php b/test/Exads/Tests/ClientTest.php index 0bfc160..53b76e5 100644 --- a/test/Exads/Tests/ClientTest.php +++ b/test/Exads/Tests/ClientTest.php @@ -12,7 +12,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase * @covers \Exads\Client * @test */ - public function should_instanciate_client_class() + public function shouldInstanciateClientClass() { $client = new Client('http://localhost'); $this->assertInstanceOf(ClientInterface::class, $client); @@ -23,7 +23,7 @@ public function should_instanciate_client_class() * @test * @expectedException InvalidArgumentException */ - public function should_not_get_api_instance() + public function shouldNotGetApiInstance() { $client = new Client('http://localhost'); $client->api('do_not_exist'); @@ -33,7 +33,7 @@ public function should_not_get_api_instance() * @covers \Exads\Client * @test */ - public function should_return_api_url() + public function shouldReturnAPIUrl() { $client = new Client('http://localhost'); $this->assertSame('http://localhost', $client->getUrl()); @@ -43,7 +43,7 @@ public function should_return_api_url() * @covers \Exads\Client * @test */ - public function should_find_correct_port() + public function shouldFindCorrectPort() { $client = new Client('http://localhost'); $this->assertSame(80, $client->getPort()); @@ -56,7 +56,7 @@ public function should_find_correct_port() * @covers \Exads\Client * @test */ - public function should_update_port() + public function shouldUpdatePort() { $client = new Client('http://localhost'); $this->assertSame($client, $client->setPort(28080)); @@ -67,7 +67,7 @@ public function should_update_port() * @covers \Exads\Client * @test */ - public function response_should_be_0_by_default() + public function responseShouldBe0ByDefault() { $client = new Client('http://localhost'); $this->assertEquals(0, $client->getResponseCode()); @@ -77,7 +77,7 @@ public function response_should_be_0_by_default() * @covers \Exads\Client * @test */ - public function should_decode_valid_json() + public function shouldDecodeValidJson() { // Test values $inputJson = '{"token":"34fb12b579a9e6bc7a28238db3ff79aed04827ab","type":"Bearer","expires_in":3600}'; @@ -94,7 +94,7 @@ public function should_decode_valid_json() * @covers \Exads\Client * @test */ - public function test_empty_json_decode() + public function testEmptyJsonDecode() { $invalidJson = ''; $expectedError = ''; @@ -107,7 +107,7 @@ public function test_empty_json_decode() * @covers \Exads\Client * @test */ - public function test_malformed_json_should_return_error() + public function testMalformedJsonShouldReturnError() { $invalidJson = '{"token":"34fb12b579a9e6bc7a28238db3ff79aed04827ab","type":"Bearer","expires_in":3600'; $expectedError = 'Syntax error'; diff --git a/test/Exads/Tests/TestClientTest.php b/test/Exads/Tests/TestClientTest.php index 2cee9a8..fbdd011 100644 --- a/test/Exads/Tests/TestClientTest.php +++ b/test/Exads/Tests/TestClientTest.php @@ -12,7 +12,7 @@ class TestClientTest extends \PHPUnit_Framework_TestCase * @test * @expectedException Exception */ - public function test_get_method_not_available() + public function testGetMethodNotAvailable() { $client = new TestClient('http://localhost'); $client->get('does_not_exist'); @@ -23,7 +23,7 @@ public function test_get_method_not_available() * @test * @expectedException Exception */ - public function test_delete_method_not_available() + public function testDeleteMethodNotAvailable() { $client = new TestClient('http://localhost'); $client->delete('does_not_exist'); @@ -34,7 +34,7 @@ public function test_delete_method_not_available() * @test * @expectedException Exception */ - public function test_post_method_not_available() + public function testPostMethodNotAvailable() { $client = new TestClient('http://localhost'); $client->post('does_not_exist', 'POST method not available'); @@ -45,7 +45,7 @@ public function test_post_method_not_available() * @test * @expectedException Exception */ - public function test_put_method_not_available() + public function testPutMethodNotAvailable() { $client = new TestClient('http://localhost'); $client->put('does_not_exist', 'PUT method not available'); diff --git a/test/Exads/Tests/TestUrlClientTest.php b/test/Exads/Tests/TestUrlClientTest.php index 9514f26..5b2c965 100644 --- a/test/Exads/Tests/TestUrlClientTest.php +++ b/test/Exads/Tests/TestUrlClientTest.php @@ -10,7 +10,7 @@ class TestUrlClientTest extends \PHPUnit_Framework_TestCase * @covers \Exads\TestUrlClient * @test */ - public function test_get_returns_path_and_method() + public function testGetReturnsPathAndMethod() { $expectedReturn = array('method' => 'GET', 'path' => '/some/path'); $client = new TestUrlClient('http://localhost'); @@ -21,7 +21,7 @@ public function test_get_returns_path_and_method() * @covers \Exads\TestUrlClient * @test */ - public function test_delete_returns_path_and_method() + public function testDeleteReturnsPathAndMethod() { $expectedReturn = array('method' => 'DELETE', 'path' => '/some/path'); $client = new TestUrlClient('http://localhost'); @@ -32,7 +32,7 @@ public function test_delete_returns_path_and_method() * @covers \Exads\TestUrlClient * @test */ - public function test_post_returns_path_and_method() + public function testPostReturnsPathAndMethod() { $expectedReturn = array('method' => 'POST', 'path' => '/some/path'); $client = new TestUrlClient('http://localhost'); @@ -46,7 +46,7 @@ public function test_post_returns_path_and_method() * @covers \Exads\TestUrlClient * @test */ - public function test_put_returns_path_and_method() + public function testPutReturnsPathAndMethod() { $expectedReturn = array('method' => 'PUT', 'path' => '/some/path'); $client = new TestUrlClient('http://localhost'); diff --git a/test/Exads/Tests/UrlsTest.php b/test/Exads/Tests/UrlsTest.php index f44f412..80f0b3e 100644 --- a/test/Exads/Tests/UrlsTest.php +++ b/test/Exads/Tests/UrlsTest.php @@ -18,7 +18,7 @@ public function setup() * @test * @expectedException \InvalidArgumentException */ - public function test_invalid_api_name() + public function testInvalidApiName() { $this->client->bla; } @@ -26,8 +26,13 @@ public function test_invalid_api_name() /** * @test */ - public function test_campaigns_methods() + public function testCampaignsMethods() { + $create = array('method' => 'POST' , 'path' => 'campaigns' , 'data' => array(1)); + $update = array('method' => 'PUT' , 'path' => 'campaigns/2' , 'data' => array(3)); + $createVariation = array('method' => 'POST' , 'path' => 'campaigns/12/variation' , 'data' => array(21)); + + $res = $this->client->api('campaigns')->all(); $this->assertEquals($res, array('method' => 'GET', 'path' => 'campaigns')); @@ -68,6 +73,16 @@ public function test_campaigns_methods() 'data' => array(1), )); + $res = $this->client->api('campaigns')->create(array(1)); + $this->assertEquals($res, $create); + + $res = $this->client->api('campaigns')->update(2, array(3)); + $this->assertEquals($res, $update); + + $res = $this->client->api('campaigns')->createVariation(12, array(21)); + $this->assertEquals($res, $createVariation); + + $res = $this->client->campaigns->all(); $this->assertEquals($res, array('method' => 'GET', 'path' => 'campaigns')); @@ -104,56 +119,73 @@ public function test_campaigns_methods() 'path' => 'campaigns/restore', 'data' => array(1, 2), )); + + $res = $this->client->campaigns->create(array(1)); + $this->assertEquals($res, $create); + + $res = $this->client->campaigns->update(2, array(3)); + $this->assertEquals($res, $update); + + $res = $this->client->campaigns->createVariation(12, array(21)); + $this->assertEquals($res, $createVariation); } /** * @test * @dataProvider getValidElementTypes */ - public function test_campaigns_methods_with_element_type($elementType) + public function testCampaignsMethodsWithElementTypeTarget($elementType, $targetType, $all) { - $res = $this->client->api('campaigns')->addElement($elementType, 1, 'targeted'); - $this->assertEquals($res, array('method' => 'POST', 'path' => 'campaigns/1/targeted/'.$elementType)); + $res = $this->client->api('campaigns')->addElement($elementType, 1, $targetType); + $this->assertEquals($res, array('method' => 'POST', 'path' => "campaigns/1/$targetType/$elementType")); - $res = $this->client->api('campaigns')->replaceElement($elementType, 2, 'blocked'); - $this->assertEquals($res, array('method' => 'PUT', 'path' => 'campaigns/2/blocked/'.$elementType)); + $res = $this->client->api('campaigns')->replaceElement($elementType, 2, $targetType); + $this->assertEquals($res, array('method' => 'PUT', 'path' => "campaigns/2/$targetType/$elementType")); - $res = $this->client->api('campaigns')->removeElement($elementType, 3, 'targeted'); - $this->assertEquals($res, array('method' => 'DELETE', 'path' => 'campaigns/3/targeted/'.$elementType)); + $res = $this->client->api('campaigns')->removeElement($elementType, 3, $targetType); + $this->assertEquals($res, array('method' => 'DELETE', 'path' => "campaigns/3/$targetType/$elementType")); - if ('countries' !== $elementType) { - $res = $this->client->api('campaigns')->removeAllElements($elementType, 4, 'targeted'); - $this->assertEquals($res, array('method' => 'DELETE', 'path' => 'campaigns/4/targeted/'.$elementType.'/all')); + if ($all) { + $res = $this->client->api('campaigns')->removeAllElements($elementType, 4, $targetType); + $this->assertEquals($res, array('method' => 'DELETE', 'path' => "campaigns/4/$targetType/$elementType/all")); } - $res = $this->client->campaigns->addElement($elementType, 1, 'targeted'); - $this->assertEquals($res, array('method' => 'POST', 'path' => 'campaigns/1/targeted/'.$elementType)); + $res = $this->client->campaigns->addElement($elementType, 1, $targetType); + $this->assertEquals($res, array('method' => 'POST', 'path' => "campaigns/1/$targetType/$elementType")); - $res = $this->client->campaigns->replaceElement($elementType, 2, 'blocked'); - $this->assertEquals($res, array('method' => 'PUT', 'path' => 'campaigns/2/blocked/'.$elementType)); + $res = $this->client->campaigns->replaceElement($elementType, 2, $targetType); + $this->assertEquals($res, array('method' => 'PUT', 'path' => "campaigns/2/$targetType/$elementType")); - $res = $this->client->campaigns->removeElement($elementType, 3, 'targeted'); - $this->assertEquals($res, array('method' => 'DELETE', 'path' => 'campaigns/3/targeted/'.$elementType)); + $res = $this->client->campaigns->removeElement($elementType, 3, $targetType); + $this->assertEquals($res, array('method' => 'DELETE', 'path' => "campaigns/3/$targetType/$elementType")); - if ('countries' !== $elementType) { - $res = $this->client->campaigns->removeAllElements($elementType, 4, 'targeted'); - $this->assertEquals($res, array('method' => 'DELETE', 'path' => 'campaigns/4/targeted/'.$elementType.'/all')); + if ($all) { + $res = $this->client->campaigns->removeAllElements($elementType, 4, $targetType); + $this->assertEquals($res, array('method' => 'DELETE', 'path' => "campaigns/4/$targetType/$elementType/all")); } } public function getValidElementTypes() { return array( - array('browsers'), - array('carriers'), - array('categories'), - array('countries'), - array('devices'), - array('languages'), - array('operating_systems'), - array('sites'), - array('keywords'), - array('ip_ranges'), + array('browsers', 'targeted', true), + array('browsers', 'blocked', true), + array('carriers', 'targeted', true), + array('carriers', 'blocked', true), + array('categories', 'targeted', false), + array('countries', 'targeted', false), + array('devices', 'targeted', true), + array('devices', 'blocked', true), + array('languages', 'targeted', true), + array('languages', 'blocked', true), + array('operating_systems', 'blocked', true), + array('operating_systems', 'targeted', true), + array('sites', 'blocked', true), + array('sites', 'targeted', true), + array('keywords', 'targeted', true), + array('keywords', 'blocked', true), + array('ip_ranges', 'targeted', true), + array('ip_ranges', 'blocked', true), ); } @@ -161,10 +193,17 @@ public function getValidElementTypes() * @test * @expectedException \InvalidArgumentException */ - public function test_campaigns_methods_with_invalid_element_type() + public function testCampaignsMethodsWithInvalidElementType() { $this->client->api('campaigns')->addElement('bla', 1, 'targeted'); + } + /** + * @test + * @expectedException \InvalidArgumentException + */ + public function testCampaignsMethodWithInvalidElmentType2() + { $this->client->campaigns->addElement('bla', 1, 'targeted'); } @@ -172,10 +211,17 @@ public function test_campaigns_methods_with_invalid_element_type() * @test * @expectedException \InvalidArgumentException */ - public function test_campaigns_methods_with_invalid_element_type2() + public function testCampaignsMethodsWithInvalidElementType3() { $this->client->api('campaigns')->replaceElement('bla', 1, 'blocked'); + } + /** + * @test + * @expectedException \InvalidArgumentException + */ + public function testCampaignsMethodsWithInvalidElementType4() + { $this->client->campaigns->replaceElement('bla', 1, 'blocked'); } @@ -183,10 +229,17 @@ public function test_campaigns_methods_with_invalid_element_type2() * @test * @expectedException \InvalidArgumentException */ - public function test_campaigns_methods_with_invalid_element_type3() + public function testCampaignsMethodsWithInvalidElementType5() { $this->client->api('campaigns')->removeElement('bla', 1, 'targeted'); + } + /** + * @test + * @expectedException \InvalidArgumentException + */ + public function testCampaignsMethodWithInvalidElementType6() + { $this->client->campaigns->removeElement('bla', 1, 'targeted'); } @@ -194,17 +247,104 @@ public function test_campaigns_methods_with_invalid_element_type3() * @test * @expectedException \InvalidArgumentException */ - public function test_campaigns_methods_with_invalid_element_type4() + public function testCampaignsMethodsWithInvalidElementType7() { $this->client->api('campaigns')->removeAllElements('bla', 1, 'targeted'); + } + /** + * @test + * @expectedException \InvalidArgumentException + */ + public function testCampaignsMethodsWithInvalidElementType8() + { $this->client->campaigns->removeAllElements('bla', 1, 'targeted'); } + /** + * @test + * @expectedException \InvalidArgumentException + */ + public function testCampaignsMethodsWithInvalidElementType9() + { + $this->client->campaigns->removeElement('sites', 1, 'argeted'); + } + + /** + * @test + * @expectedException \InvalidArgumentException + */ + public function testCampaignsMethodsWithInvalidElementType10() + { + $this->client->campaigns->removeElement('browsers', 1, 'target'); + } + + /** + * @test + * @expectedException \InvalidArgumentException + * @dataProvider getTargetOnlyElements + */ + public function testUnsupportedBlockManipulation($element, $op, $accessVia) + { + $access = $this->getCampaignObjectVia($accessVia); + + if ($op == "add") { + $access->addElement($element, 1, 'blocked'); + } elseif ($op == "remove") { + $access->removeElement($element, 1, 'blocked'); + } elseif ($op == "replace") { + $access->replaceElement($element, 1, 'blocked'); + } + } + + public function getTargetOnlyElements() + { + return array( + array('categories', 'add', 'getter'), + array('categories', 'remove', 'getter'), + array('categories', 'replace', 'getter'), + array('categories', 'add', 'api'), + array('categories', 'remove', 'api'), + array('categories', 'replace', 'api'), + array('countries', 'add', 'getter'), + array('countries', 'remove', 'getter'), + array('countries', 'replace', 'getter'), + array('countries', 'add', 'api'), + array('countries', 'remove', 'api'), + array('countries', 'replace', 'api'), + ); + } + + /** + * @test + * @expectedException \InvalidArgumentException + * @dataProvider getDeleteAllUnsuportedElements + */ + public function testUnsupportedAllManipulation($element, $accessVia, $type) + { + $access = $this->getCampaignObjectVia($accessVia); + $access->removeAllElements($element, 12, $type); + } + + public function getDeleteAllUnsuportedElements() + { + return array( + array('categories', 'getter', 'blocked'), + array('categories', 'getter', 'targeted'), + array('categories', 'api', 'blocked'), + array('categories', 'api', 'targeted'), + array('countries', 'getter', 'blocked'), + array('countries', 'getter', 'targeted'), + array('countries', 'api', 'blocked'), + array('countries', 'api', 'targeted'), + ); + } + + /** * @test */ - public function test_login_methods() + public function testLoginMethods() { $res = $this->client->api('login')->getToken('aaa', 'bbb'); $this->assertEquals($res, array( @@ -238,7 +378,7 @@ public function test_login_methods() /** * @test */ - public function test_collections_methods() + public function testCollectionsMethods() { $res = $this->client->api('collections')->all(); $this->assertEquals($res, array('method' => 'GET', 'path' => 'collections')); @@ -286,7 +426,7 @@ public function test_collections_methods() /** * @test */ - public function test_payments_advertiser_methods() + public function testPaymentsAdvertiserMethods() { $res = $this->client->api('payments_advertiser')->all(); $this->assertEquals($res, array('method' => 'GET', 'path' => 'payments/advertiser')); @@ -298,7 +438,7 @@ public function test_payments_advertiser_methods() /** * @test */ - public function test_payments_publisher_methods() + public function testPaymentsPublisherMethods() { $res = $this->client->api('payments_publisher')->all(); $this->assertEquals($res, array('method' => 'GET', 'path' => 'payments/publisher')); @@ -310,7 +450,7 @@ public function test_payments_publisher_methods() /** * @test */ - public function test_sites_methods() + public function testSitesMethods() { $res = $this->client->api('sites')->all(); $this->assertEquals($res, array('method' => 'GET', 'path' => 'sites')); @@ -322,7 +462,7 @@ public function test_sites_methods() /** * @test */ - public function test_statistics_advertiser_methods() + public function testStatisticsAdvertiserMethods() { $res = $this->client->api('statistics_advertiser')->browser(); $this->assertEquals($res, array('method' => 'GET', 'path' => 'statistics/advertiser/browser')); @@ -360,6 +500,9 @@ public function test_statistics_advertiser_methods() $res = $this->client->api('statistics_advertiser')->variation(); $this->assertEquals($res, array('method' => 'GET', 'path' => 'statistics/advertiser/variation')); + $res = $this->client->api('statistics_advertiser')->zone(); + $this->assertEquals($res, array('method' => 'GET', 'path' => 'statistics/advertiser/zone')); + $res = $this->client->statistics_advertiser->browser(); $this->assertEquals($res, array('method' => 'GET', 'path' => 'statistics/advertiser/browser')); @@ -395,12 +538,15 @@ public function test_statistics_advertiser_methods() $res = $this->client->statistics_advertiser->variation(); $this->assertEquals($res, array('method' => 'GET', 'path' => 'statistics/advertiser/variation')); + + $res = $this->client->statistics_advertiser->zone(); + $this->assertEquals($res, array('method' => 'GET', 'path' => 'statistics/advertiser/zone')); } /** * @test */ - public function test_statistics_publisher_methods() + public function testStatisticsPublisherMethods() { $res = $this->client->api('statistics_publisher')->browser(); $this->assertEquals($res, array('method' => 'GET', 'path' => 'statistics/publisher/browser')); @@ -411,6 +557,9 @@ public function test_statistics_publisher_methods() $res = $this->client->api('statistics_publisher')->category(); $this->assertEquals($res, array('method' => 'GET', 'path' => 'statistics/publisher/category')); + $res = $this->client->api('statistics_publisher')->language(); + $this->assertEquals($res, array('method' => 'GET', 'path' => 'statistics/publisher/language')); + $res = $this->client->api('statistics_publisher')->country(); $this->assertEquals($res, array('method' => 'GET', 'path' => 'statistics/publisher/country')); @@ -475,7 +624,7 @@ public function test_statistics_publisher_methods() /** * @test */ - public function test_user_methods() + public function testUserMethods() { $res = $this->client->api('user')->show(); $this->assertEquals($res, array('method' => 'GET', 'path' => 'user')); @@ -529,7 +678,7 @@ public function test_user_methods() /** * @test */ - public function test_zone_methods() + public function testZoneMethods() { $res = $this->client->api('zones')->all(); $this->assertEquals($res, array('method' => 'GET', 'path' => 'zones')); @@ -538,10 +687,27 @@ public function test_zone_methods() $this->assertEquals($res, array('method' => 'GET', 'path' => 'zones')); } + + /** + * + * @test + */ + public function testOfferMethods() + { + $offer_all = array('method' => 'GET', 'path' => 'offers'); + + + $res = $this->client->api('offers')->all(); + $this->assertEquals($res, $offer_all); + + $res = $this->client->offers->all(); + $this->assertEquals($res, $offer_all); + } + /** * @test */ - public function test_get_parameters_presence() + public function testGetParametersPresence() { $res = $this->client->api('campaigns')->all(array('offset' => 100)); $this->assertEquals($res, array('method' => 'GET', 'path' => 'campaigns?offset=100')); @@ -549,4 +715,16 @@ public function test_get_parameters_presence() $res = $this->client->campaigns->all(array('offset' => 100)); $this->assertEquals($res, array('method' => 'GET', 'path' => 'campaigns?offset=100')); } + + private function getCampaignObjectVia($accessVia) + { + $access = null; + + if ($accessVia == "getter") { + $access = $this->client->campaigns; + } elseif ($accessVia == "api") { + $access = $this->client->api('campaigns'); + } + return $access; + } }