1
0
mirror of synced 2024-11-21 21:06:07 +03:00

update tests

This commit is contained in:
Alex Lushpai 2016-07-22 01:01:47 +03:00
parent ddf46fd73d
commit acf29c8c1b
14 changed files with 473 additions and 198 deletions

View File

@ -9,9 +9,11 @@ php:
- '5.4' - '5.4'
- '5.5' - '5.5'
- '5.6' - '5.6'
- '7.0'
before_script: before_script:
- flags="--prefer-dist --no-dev" - flags="--prefer-dist --no-dev"
- composer install $flags - composer install $flags
- wget -c https://db.tt/uMin8U9t
script: phpunit script: phpunit

View File

@ -13,7 +13,8 @@
], ],
"require": { "require": {
"php": ">=5.3.0", "php": ">=5.3.0",
"ext-curl": "*" "ext-curl": "*",
"phpunit/phpunit": "~5.4.7"
}, },
"support": { "support": {
"email": "support@retailcrm.pro" "email": "support@retailcrm.pro"

View File

@ -1437,27 +1437,46 @@ class ApiClient
} }
return $this->client->makeRequest( return $this->client->makeRequest(
"/telephony/settings/$code", "/telephony/setting/$code",
Client::METHOD_GET Client::METHOD_GET
); );
} }
/** /**
* Edit telephony settings * Edit telephony settings
* *
* @param string $code symbolic code * @param string $code symbolic code
* @param string $clientId client id * @param string $clientId client id
* @param boolean $active telephony activity * @param boolean $active telephony activity
* @param mixed $makeCallUrl service init url
* @param mixed $name service name * @param mixed $name service name
* @param mixed $makeCallUrl service init url
* @param mixed $image service logo url(svg file) * @param mixed $image service logo url(svg file)
* *
* @throws \InvalidArgumentException * @param array $additionalCodes
* @throws \RetailCrm\Exception\CurlException * @param array $externalPhones
* @throws \RetailCrm\Exception\InvalidJsonException * @param bool $allowEdit
* @param bool $inputEventSupported
* @param bool $outputEventSupported
* @param bool $hangupEventSupported
* @param bool $changeUserStatusUrl
* *
* @return ApiResponse * @return ApiResponse
*/ */
public function telephonySettingsEdit($code, $clientId, $active = false, $makeCallUrl = false, $name = false, $image = false) public function telephonySettingsEdit(
$code,
$clientId,
$active = false,
$name = false,
$makeCallUrl = false,
$image = false,
$additionalCodes = array(),
$externalPhones = array(),
$allowEdit = false,
$inputEventSupported = false,
$outputEventSupported = false,
$hangupEventSupported = false,
$changeUserStatusUrl = false
)
{ {
if (!isset($code)) { if (!isset($code)) {
throw new \InvalidArgumentException('Code must be set'); throw new \InvalidArgumentException('Code must be set');
@ -1481,64 +1500,101 @@ class ApiClient
throw new \InvalidArgumentException('name must be set'); throw new \InvalidArgumentException('name must be set');
} }
if (isset($makeCallUrl)) {
$parameters['makeCallUrl'] = $makeCallUrl;
}
if (isset($name)) { if (isset($name)) {
$parameters['name'] = $name; $parameters['name'] = $name;
} }
if (isset($makeCallUrl)) {
$parameters['makeCallUrl'] = $makeCallUrl;
}
if (isset($image)) { if (isset($image)) {
$parameters['image'] = $image; $parameters['image'] = $image;
} }
if (isset($additionalCodes)) {
$parameters['additionalCodes'] = $additionalCodes;
}
if (isset($externalPhones)) {
$parameters['externalPhones'] = $externalPhones;
}
if (isset($allowEdit)) {
$parameters['allowEdit'] = $allowEdit;
}
if (isset($inputEventSupported)) {
$parameters['inputEventSupported'] = $inputEventSupported;
}
if (isset($outputEventSupported)) {
$parameters['outputEventSupported'] = $outputEventSupported;
}
if (isset($hangupEventSupported)) {
$parameters['hangupEventSupported'] = $hangupEventSupported;
}
if (isset($changeUserStatusUrl)) {
$parameters['changeUserStatusUrl'] = $changeUserStatusUrl;
}
return $this->client->makeRequest( return $this->client->makeRequest(
"/telephony/setting/$code/edit", "/telephony/setting/$code/edit",
Client::METHOD_POST, Client::METHOD_POST,
$parameters array('configuration' => json_encode($parameters))
); );
} }
/** /**
* Call event * Call event
* *
* @param string $phone phone number * @param string $phone phone number
* @param string $type call type * @param string $type call type
* @param string $code additional phone code * @param array $codes
* @param string $status call status * @param string $hangupStatus
* * @param string $externalPhone
* @throws \InvalidArgumentException * @param array $webAnalyticsData
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
* *
* @return ApiResponse * @return ApiResponse
* @internal param string $code additional phone code
* @internal param string $status call status
*
*/ */
public function telephonyCallEvent($phone, $type, $code, $status) public function telephonyCallEvent(
$phone,
$type,
$codes,
$hangupStatus,
$externalPhone = null,
$webAnalyticsData = array()
)
{ {
if (!isset($phone)) { if (!isset($phone)) {
throw new \InvalidArgumentException('Phone number must be set'); throw new \InvalidArgumentException('Phone number must be set');
} }
$parameters['phone'] = $phone;
if (!isset($type)) { if (!isset($type)) {
throw new \InvalidArgumentException('Type must be set (in|out|hangup)'); throw new \InvalidArgumentException('Type must be set (in|out|hangup)');
} }
$parameters['type'] = $type; if (empty($codes)) {
throw new \InvalidArgumentException('Codes array must be set');
if (!isset($code)) {
throw new \InvalidArgumentException('Code must be set');
} }
$parameters['code'] = $code; $parameters['phone'] = $phone;
$parameters['hangupStatus'] = $status; $parameters['type'] = $type;
$parameters['codes'] = $codes;
$parameters['hangupStatus'] = $hangupStatus;
$parameters['callExternalId'] = $externalPhone;
$parameters['webAnalyticsData'] = $webAnalyticsData;
return $this->client->makeRequest( return $this->client->makeRequest(
'/telephony/call/event', '/telephony/call/event',
Client::METHOD_POST, Client::METHOD_POST,
$parameters array('event' => json_encode($parameters))
); );
} }

View File

@ -12,6 +12,7 @@
<php> <php>
<server name="CRM_URL" value="https://demo.retailcrm.ru" /> <server name="CRM_URL" value="https://demo.retailcrm.ru" />
<server name="CRM_API_KEY" value="nSBFWecViONG5c96wUQQgZzHkilTnaa6" /> <server name="CRM_API_KEY" value="nSBFWecViONG5c96wUQQgZzHkilTnaa6" />
<server name="CRM_USER_ID" value="1" />
</php> </php>
<testsuites> <testsuites>

View File

@ -1,15 +1,36 @@
<?php <?php
/**
* PHP version 5.3
*
* API client customers test class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/
namespace RetailCrm\Tests; namespace RetailCrm\Tests;
use RetailCrm\Test\TestCase; use RetailCrm\Test\TestCase;
/**
* Class ApiClientCustomersTest
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/
class ApiClientCustomersTest extends TestCase class ApiClientCustomersTest extends TestCase
{ {
const FIRST_NAME = 'Иннокентий'; const FIRST_NAME = 'Иннокентий';
/** /**
* @group integration * @group customers
*/ */
public function testCustomersCreate() public function testCustomersCreate()
{ {
@ -32,7 +53,7 @@ class ApiClientCustomersTest extends TestCase
} }
/** /**
* @group unit * @group customers
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testCustomersCreateExceptionEmpty() public function testCustomersCreateExceptionEmpty()
@ -43,7 +64,7 @@ class ApiClientCustomersTest extends TestCase
} }
/** /**
* @group integration * @group customers
* @depends testCustomersCreate * @depends testCustomersCreate
*/ */
public function testCustomersGet(array $ids) public function testCustomersGet(array $ids)
@ -53,13 +74,13 @@ class ApiClientCustomersTest extends TestCase
$response = $client->customersGet(678678678); $response = $client->customersGet(678678678);
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(404, $response->getStatusCode()); $this->assertEquals(404, $response->getStatusCode());
$this->assertFalse($response->success); $this->assertFalse($response->isSuccessful());
$response = $client->customersGet($ids['id'], 'id'); $response = $client->customersGet($ids['id'], 'id');
$customerById = $response->customer; $customerById = $response->customer;
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->success); $this->assertTrue($response->isSuccessful());
$this->assertEquals(self::FIRST_NAME, $response->customer['firstName']); $this->assertEquals(self::FIRST_NAME, $response->customer['firstName']);
$response = $client->customersGet($ids['externalId'], 'externalId'); $response = $client->customersGet($ids['externalId'], 'externalId');
@ -69,7 +90,7 @@ class ApiClientCustomersTest extends TestCase
} }
/** /**
* @group unit * @group customers
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testCustomersGetException() public function testCustomersGetException()
@ -80,7 +101,7 @@ class ApiClientCustomersTest extends TestCase
} }
/** /**
* @group integration * @group customers
* @depends testCustomersGet * @depends testCustomersGet
*/ */
public function testCustomersEdit(array $ids) public function testCustomersEdit(array $ids)
@ -103,19 +124,11 @@ class ApiClientCustomersTest extends TestCase
)); ));
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->success); $this->assertTrue($response->isSuccessful());
$response = $client->customersEdit(array(
'externalId' => 'c-edit-' . time(),
'lastName' => '12345',
));
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(201, $response->getStatusCode());
$this->assertTrue($response->success);
} }
/** /**
* @group unit * @group customers
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testCustomersEditExceptionEmpty() public function testCustomersEditExceptionEmpty()
@ -126,7 +139,7 @@ class ApiClientCustomersTest extends TestCase
} }
/** /**
* @group unit * @group customers
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testCustomersEditException() public function testCustomersEditException()
@ -137,7 +150,7 @@ class ApiClientCustomersTest extends TestCase
} }
/** /**
* @group integration * @group customers
*/ */
public function testCustomersList() public function testCustomersList()
{ {
@ -164,7 +177,7 @@ class ApiClientCustomersTest extends TestCase
} }
/** /**
* @group unit * @group customers
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testCustomersFixExternalIdsException() public function testCustomersFixExternalIdsException()
@ -175,7 +188,7 @@ class ApiClientCustomersTest extends TestCase
} }
/** /**
* @group integration * @group customers
*/ */
public function testCustomersFixExternalIds() public function testCustomersFixExternalIds()
{ {
@ -225,7 +238,7 @@ class ApiClientCustomersTest extends TestCase
} }
/** /**
* @group unit * @group customers
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testCustomersUploadExceptionEmpty() public function testCustomersUploadExceptionEmpty()
@ -236,7 +249,7 @@ class ApiClientCustomersTest extends TestCase
} }
/** /**
* @group integration * @group customers
*/ */
public function testCustomersUpload() public function testCustomersUpload()
{ {

View File

@ -1,15 +1,36 @@
<?php <?php
/**
* PHP version 5.3
*
* API client orders test class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/
namespace RetailCrm\Tests; namespace RetailCrm\Tests;
use RetailCrm\Test\TestCase; use RetailCrm\Test\TestCase;
/**
* Class ApiClientOrdersTest
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/
class ApiClientOrdersTest extends TestCase class ApiClientOrdersTest extends TestCase
{ {
const FIRST_NAME = 'Иннокентий'; const FIRST_NAME = 'Иннокентий';
/** /**
* @group integration * @group orders
*/ */
public function testOrdersCreate() public function testOrdersCreate()
{ {
@ -32,7 +53,7 @@ class ApiClientOrdersTest extends TestCase
} }
/** /**
* @group unit * @group orders
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testOrdersCreateExceptionEmpty() public function testOrdersCreateExceptionEmpty()
@ -43,7 +64,7 @@ class ApiClientOrdersTest extends TestCase
} }
/** /**
* @group integration * @group orders
* @depends testOrdersCreate * @depends testOrdersCreate
*/ */
public function testOrdersStatuses(array $ids) public function testOrdersStatuses(array $ids)
@ -53,19 +74,19 @@ class ApiClientOrdersTest extends TestCase
$response = $client->ordersStatuses(); $response = $client->ordersStatuses();
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(400, $response->getStatusCode()); $this->assertEquals(400, $response->getStatusCode());
$this->assertFalse($response->success); $this->assertFalse($response->isSuccessful());
$response = $client->ordersStatuses(array(), array('asdf')); $response = $client->ordersStatuses(array(), array('asdf'));
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->success); $this->assertTrue($response->isSuccessful());
$orders = $response->orders; $orders = $response->orders;
$this->assertEquals(0, sizeof($orders)); $this->assertEquals(0, sizeof($orders));
$response = $client->ordersStatuses(array(), array($ids['externalId'])); $response = $client->ordersStatuses(array(), array($ids['externalId']));
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->success); $this->assertTrue($response->isSuccessful());
$orders = $response->orders; $orders = $response->orders;
$this->assertEquals(1, sizeof($orders)); $this->assertEquals(1, sizeof($orders));
$this->assertEquals('new', $orders[0]['status']); $this->assertEquals('new', $orders[0]['status']);
@ -73,20 +94,20 @@ class ApiClientOrdersTest extends TestCase
$response = $client->ordersStatuses(array($ids['id']), array($ids['externalId'])); $response = $client->ordersStatuses(array($ids['id']), array($ids['externalId']));
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->success); $this->assertTrue($response->isSuccessful());
$orders = $response->orders; $orders = $response->orders;
$this->assertEquals(1, sizeof($orders)); $this->assertEquals(1, sizeof($orders));
$response = $client->ordersStatuses(array($ids['id'])); $response = $client->ordersStatuses(array($ids['id']));
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->success); $this->assertTrue($response->isSuccessful());
$orders = $response->orders; $orders = $response->orders;
$this->assertEquals(1, sizeof($orders)); $this->assertEquals(1, sizeof($orders));
} }
/** /**
* @group integration * @group orders
* @depends testOrdersCreate * @depends testOrdersCreate
*/ */
public function testOrdersGet(array $ids) public function testOrdersGet(array $ids)
@ -96,13 +117,13 @@ class ApiClientOrdersTest extends TestCase
$response = $client->ordersGet(678678678); $response = $client->ordersGet(678678678);
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(404, $response->getStatusCode()); $this->assertEquals(404, $response->getStatusCode());
$this->assertFalse($response->success); $this->assertFalse($response->isSuccessful());
$response = $client->ordersGet($ids['id'], 'id'); $response = $client->ordersGet($ids['id'], 'id');
$orderById = $response->order; $orderById = $response->order;
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->success); $this->assertTrue($response->isSuccessful());
$this->assertEquals(self::FIRST_NAME, $response->order['firstName']); $this->assertEquals(self::FIRST_NAME, $response->order['firstName']);
$response = $client->ordersGet($ids['externalId'], 'externalId'); $response = $client->ordersGet($ids['externalId'], 'externalId');
@ -112,7 +133,7 @@ class ApiClientOrdersTest extends TestCase
} }
/** /**
* @group unit * @group orders
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testOrdersGetException() public function testOrdersGetException()
@ -123,7 +144,7 @@ class ApiClientOrdersTest extends TestCase
} }
/** /**
* @group integration * @group orders
* @depends testOrdersGet * @depends testOrdersGet
*/ */
public function testOrdersEdit(array $ids) public function testOrdersEdit(array $ids)
@ -146,19 +167,11 @@ class ApiClientOrdersTest extends TestCase
)); ));
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->success); $this->assertTrue($response->isSuccessful());
$response = $client->ordersEdit(array(
'externalId' => time(),
'lastName' => '12345',
));
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(201, $response->getStatusCode());
$this->assertTrue($response->success);
} }
/** /**
* @group unit * @group orders
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testOrdersEditExceptionEmpty() public function testOrdersEditExceptionEmpty()
@ -169,7 +182,7 @@ class ApiClientOrdersTest extends TestCase
} }
/** /**
* @group unit * @group orders
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testOrdersEditException() public function testOrdersEditException()
@ -180,7 +193,7 @@ class ApiClientOrdersTest extends TestCase
} }
/** /**
* @group integration * @group orders
*/ */
public function testOrdersHistory() public function testOrdersHistory()
{ {
@ -189,19 +202,11 @@ class ApiClientOrdersTest extends TestCase
$response = $client->ordersHistory(); $response = $client->ordersHistory();
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->success); $this->assertTrue($response->isSuccessful());
$this->assertTrue(
isset($response['orders']),
'API returns orders history'
);
$this->assertTrue(
isset($response['generatedAt']),
'API returns generatedAt in orders history'
);
} }
/** /**
* @group integration * @group orders
*/ */
public function testOrdersList() public function testOrdersList()
{ {
@ -221,14 +226,10 @@ class ApiClientOrdersTest extends TestCase
$response = $client->ordersList(array('paymentStatus' => 'paid'), 1); $response = $client->ordersList(array('paymentStatus' => 'paid'), 1);
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertTrue(
$response->isSuccessful(),
'API returns orders list'
);
} }
/** /**
* @group unit * @group orders
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testOrdersFixExternalIdsException() public function testOrdersFixExternalIdsException()
@ -239,7 +240,7 @@ class ApiClientOrdersTest extends TestCase
} }
/** /**
* @group integration * @group orders
] */ ] */
public function testOrdersFixExternalIds() public function testOrdersFixExternalIds()
{ {
@ -283,7 +284,7 @@ class ApiClientOrdersTest extends TestCase
} }
/** /**
* @group unit * @group orders
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testOrdersUploadExceptionEmpty() public function testOrdersUploadExceptionEmpty()
@ -294,7 +295,7 @@ class ApiClientOrdersTest extends TestCase
} }
/** /**
* @group integration * @group orders
*/ */
public function testOrdersUpload() public function testOrdersUpload()
{ {

View File

@ -9,7 +9,7 @@
* @package RetailCrm * @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru> * @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License * @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/ */
namespace RetailCrm\Tests; namespace RetailCrm\Tests;
@ -23,29 +23,14 @@ use RetailCrm\Test\TestCase;
* @package RetailCrm * @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru> * @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License * @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/ */
class ApiClientPacksTest extends TestCase class ApiClientPacksTest extends TestCase
{ {
private $_packId;
/**
* ApiClientPacksTest constructor.
*
* @param null|string $name name
* @param array $data data
* @param string $dataName dataName
*/
public function __construct($name = null, array $data = array(), $dataName = '')
{
parent::__construct($name, $data, $dataName);
$this->_packId = __DIR__ . '/../../../pack.tmp';
}
/** /**
* Test packs history * Test packs history
* *
* @group integration * @group packs
* @return void * @return void
*/ */
public function testOrdersPacksHistory() public function testOrdersPacksHistory()
@ -66,33 +51,10 @@ class ApiClientPacksTest extends TestCase
); );
} }
/**
* Test packs create
*
* @group integration
* @return void
*/
public function testOrdersPacksCreate()
{
$client = static::getApiClient();
$pack = array(
'itemId' => $_SERVER['CRM_PACK_ITEM'],
'quantity' => $_SERVER['CRM_PACK_QUANTITY'],
'store' => $_SERVER['CRM_STORE']
);
$response = $client->ordersPacksCreate($pack);
file_put_contents($this->_packId, $response["id"]);
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(201, $response->getStatusCode());
$this->assertTrue($response->success);
}
/** /**
* Test packs failed create * Test packs failed create
* *
* @group integration * @group packs
* @return void * @return void
*/ */
public function testOrdersPacksCreateFailed() public function testOrdersPacksCreateFailed()
@ -100,7 +62,7 @@ class ApiClientPacksTest extends TestCase
$client = static::getApiClient(); $client = static::getApiClient();
$pack = array( $pack = array(
'itemId' => 12, 'itemId' => 12,
'store' => $_SERVER['CRM_STORE'], 'store' => 'test',
'quantity' => 2 'quantity' => 2
); );
@ -109,39 +71,4 @@ class ApiClientPacksTest extends TestCase
$this->assertEquals(400, $response->getStatusCode()); $this->assertEquals(400, $response->getStatusCode());
$this->assertFalse($response->success); $this->assertFalse($response->success);
} }
/**
* Test packs get
*
* @group integration
* @return void
*/
public function testOrdersPacksGet()
{
$client = static::getApiClient();
$packId = file_get_contents($this->_packId);
$response = $client->ordersPacksGet($packId);
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->success);
}
/**
* Test packs delete
*
* @group integration
* @return void
*/
public function testOrdersPacksDelete()
{
$client = static::getApiClient();
$packId = file_get_contents($this->_packId);
$response = $client->ordersPacksDelete($packId);
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->success);
unlink($this->_packId);
}
} }

View File

@ -1,13 +1,34 @@
<?php <?php
/**
* PHP version 5.3
*
* API client references test class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/
namespace RetailCrm\Tests; namespace RetailCrm\Tests;
use RetailCrm\Test\TestCase; use RetailCrm\Test\TestCase;
/**
* Class ApiClientReferenceTest
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/
class ApiClientReferenceTest extends TestCase class ApiClientReferenceTest extends TestCase
{ {
/** /**
* @group integration * @group reference
* @dataProvider getListDictionaries * @dataProvider getListDictionaries
* @param $name * @param $name
*/ */
@ -25,7 +46,7 @@ class ApiClientReferenceTest extends TestCase
} }
/** /**
* @group integration * @group reference
* @dataProvider getEditDictionaries * @dataProvider getEditDictionaries
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
@ -38,7 +59,7 @@ class ApiClientReferenceTest extends TestCase
} }
/** /**
* @group integration * @group reference
* @dataProvider getEditDictionaries * @dataProvider getEditDictionaries
*/ */
public function testEditing($name) public function testEditing($name)
@ -69,7 +90,7 @@ class ApiClientReferenceTest extends TestCase
} }
/** /**
* @group integration * @group reference
* @group site * @group site
*/ */
public function testSiteEditing() public function testSiteEditing()

View File

@ -1,12 +1,29 @@
<?php <?php
/**
* PHP version 5.3
*
* API client store test class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/
namespace RetailCrm\Tests; namespace RetailCrm\Tests;
use RetailCrm\Test\TestCase; use RetailCrm\Test\TestCase;
/** /**
* Class ApiClientStoreTest * Class ApiClientStoreTest
* @package RetailCrm\Tests *
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/ */
class ApiClientStoreTest extends TestCase class ApiClientStoreTest extends TestCase
{ {
@ -14,7 +31,7 @@ class ApiClientStoreTest extends TestCase
const SCODE = 'test-store'; const SCODE = 'test-store';
/** /**
* @group integration * @group store
*/ */
public function testStoreCreate() public function testStoreCreate()
{ {
@ -23,11 +40,11 @@ class ApiClientStoreTest extends TestCase
$response = $client->storesEdit(array('name' => self::SNAME, 'code' => self::SCODE)); $response = $client->storesEdit(array('name' => self::SNAME, 'code' => self::SCODE));
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertTrue(in_array($response->getStatusCode(), array(200, 201))); $this->assertTrue(in_array($response->getStatusCode(), array(200, 201)));
$this->assertTrue($response->success); $this->assertTrue($response->isSuccessful());
} }
/** /**
* @group integration * @group store
*/ */
public function testStoreInventories() public function testStoreInventories()
{ {
@ -36,7 +53,7 @@ class ApiClientStoreTest extends TestCase
$response = $client->storeInventories(); $response = $client->storeInventories();
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->success); $this->assertTrue($response->isSuccessful());
$this->assertTrue( $this->assertTrue(
isset($response['offers']), isset($response['offers']),
'API returns orders assembly history' 'API returns orders assembly history'
@ -44,7 +61,7 @@ class ApiClientStoreTest extends TestCase
} }
/** /**
* @group unit * @group store
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testStoreInventoriesUploadExceptionEmpty() public function testStoreInventoriesUploadExceptionEmpty()
@ -54,7 +71,7 @@ class ApiClientStoreTest extends TestCase
} }
/** /**
* @group integration * @group store
*/ */
public function testStoreInventoriesUpload() public function testStoreInventoriesUpload()
{ {

View File

@ -1,5 +1,17 @@
<?php <?php
/**
* PHP version 5.3
*
* API client telephony test class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/
namespace RetailCrm\Tests; namespace RetailCrm\Tests;
use RetailCrm\Test\TestCase; use RetailCrm\Test\TestCase;
@ -10,33 +22,138 @@ use RetailCrm\Test\TestCase;
* @package RetailCrm\Tests * @package RetailCrm\Tests
* @author RetailCrm <integration@retailcrm.ru> * @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License * @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/ */
class ApiClientTelephonyTest extends TestCase class ApiClientTelephonyTest extends TestCase
{ {
const TEL_CODE = 'telephony-code';
const TEL_CLIENT = '123';
const TEL_IMAGE = 'http://www.mec.ph/horizon/wp-content/uploads/2011/11/telephony.svg';
/** /**
* Settings test * Settings Edit test
* *
* @group integration * @group telephony
* *
* @return void * @return void
*/ */
public function testTelephonySettings() public function testTelephonySettingsEdit()
{ {
$client = static::getApiClient(); $client = static::getApiClient();
$code = 'telphin'; $response = $client->telephonySettingsEdit(
$clientId = '1'; self::TEL_CODE,
$active = true; self::TEL_CLIENT,
true,
'TestTelephony',
false,
self::TEL_IMAGE,
array(array('userId' => $_SERVER['CRM_USER_ID'], 'code' => '101')),
array(array('siteCode' => 'api-client-php', 'externalPhone' => '+74950000000'))
);
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertTrue(in_array($response->getStatusCode(), array(200, 201)));
$this->assertTrue($response->isSuccessful());
}
/**
* Settings Get test
*
* @group telephony
*
* @return void
*/
public function testTelephonySettingsGet()
{
$client = static::getApiClient();
$response = $client->telephonySettingsGet(self::TEL_CODE);
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->isSuccessful());
}
/**
* Event test
*
* @group telephony
*
* @return void
*/
public function testTelephonyEvent()
{
$client = static::getApiClient();
$response = $client->telephonyCallEvent(
'+79999999999',
'in',
array('101'),
'failed',
'+74950000000'
$response = $client->telephonySettings(
$code,
$clientId,
$active
); );
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->success); $this->assertTrue($response->isSuccessful());
}
/**
* Upload test
*
* @group telephony
*
* @return void
*/
public function testTelephonyUpload()
{
$client = static::getApiClient();
$response = $client->telephonyCallsUpload(
array(
array(
'date' => '2016-07-22 00:18:00',
'type' => 'in',
'phone' => '+79999999999',
'code' => '101',
'result' => 'answered',
'externalId' => rand(10,100),
'recordUrl' => 'https://dl.dropboxusercontent.com/u/15492750/dontry2bfunny.mp3'
),
array(
'date' => '2016-07-22 00:24:00',
'type' => 'in',
'phone' => '+79999999999',
'code' => '101',
'result' => 'answered',
'externalId' => rand(10,100),
'recordUrl' => 'https://dl.dropboxusercontent.com/u/15492750/donttytobefunny.mp3'
)
)
);
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->isSuccessful());
}
/**
* Manager test
*
* @group telephony
*
* @return void
*/
public function testTelephonyManager()
{
$client = static::getApiClient();
$response = $client->telephonyCallManager('+79999999999', 1);
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->isSuccessful());
} }
} }

View File

@ -1,9 +1,30 @@
<?php <?php
/**
* PHP version 5.3
*
* API client test class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/
namespace RetailCrm\Tests; namespace RetailCrm\Tests;
use RetailCrm\Test\TestCase; use RetailCrm\Test\TestCase;
/**
* Class ApiClientTest
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/
class ApiClientTest extends TestCase class ApiClientTest extends TestCase
{ {
/** /**

View File

@ -0,0 +1,55 @@
<?php
/**
* PHP version 5.3
*
* API client users test class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/
namespace RetailCrm\Tests;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientUsersTest
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/
class ApiClientUsersTest extends TestCase
{
/**
* @group users
*/
public function testUsersList()
{
$client = static::getApiClient();
$response = $client->usersList();
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertTrue(in_array($response->getStatusCode(), array(200, 201)));
$this->assertTrue($response->isSuccessful());
}
/**
* @group users
*/
public function testUsersGet()
{
$client = static::getApiClient();
$response = $client->usersGet($_SERVER["CRM_USER_ID"]);
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertTrue(in_array($response->getStatusCode(), array(200, 201)));
$this->assertTrue($response->isSuccessful());
}
}

View File

@ -1,11 +1,32 @@
<?php <?php
/**
* PHP version 5.3
*
* API client test class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/
namespace RetailCrm\Tests\Http; namespace RetailCrm\Tests\Http;
use RetailCrm\Test\TestCase; use RetailCrm\Test\TestCase;
use RetailCrm\ApiClient; use RetailCrm\ApiClient;
use RetailCrm\Http\Client; use RetailCrm\Http\Client;
/**
* Class ClientTest
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/
class ClientTest extends TestCase class ClientTest extends TestCase
{ {
/** /**
@ -25,6 +46,7 @@ class ClientTest extends TestCase
public function testHttpRequiring() public function testHttpRequiring()
{ {
$client = new Client('http://demo.retailcrm.ru/api/' . ApiClient::VERSION, array('apiKey' => '123')); $client = new Client('http://demo.retailcrm.ru/api/' . ApiClient::VERSION, array('apiKey' => '123'));
return $client;
} }
/** /**
@ -44,7 +66,7 @@ class ClientTest extends TestCase
public function testMakeRequestWrongUrl() public function testMakeRequestWrongUrl()
{ {
$client = new Client('https://asdf.df', array()); $client = new Client('https://asdf.df', array());
$client->makeRequest('/a', Client::METHOD_GET, array(), 1); $client->makeRequest('/a', Client::METHOD_GET, array());
} }
/** /**

View File

@ -1,10 +1,31 @@
<?php <?php
/**
* PHP version 5.3
*
* API client response test class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/
namespace RetailCrm\Tests\Response; namespace RetailCrm\Tests\Response;
use RetailCrm\Test\TestCase; use RetailCrm\Test\TestCase;
use RetailCrm\Response\ApiResponse; use RetailCrm\Response\ApiResponse;
/**
* Class ApiResponseTest
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/
class ApiResponseTest extends TestCase class ApiResponseTest extends TestCase
{ {
/** /**