Compare commits
17 commits
Author | SHA1 | Date | |
---|---|---|---|
|
1901f1a81d | ||
|
27dab93cf5 | ||
|
b4ec498f32 | ||
|
5b91648590 | ||
e973d605f4 | |||
|
069987b32d | ||
|
a95ec22823 | ||
|
f3db3fdb63 | ||
00ec04ec6a | |||
|
649c1a38ff | ||
|
6927b38336 | ||
|
a2e1eb8dd6 | ||
|
9fc83d3b8f | ||
|
f181c9d063 | ||
|
ec69557ea7 | ||
|
eb69ee503a | ||
|
fdd7c3d4c8 |
20 changed files with 2014 additions and 1 deletions
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
namespace RetailCrm;
|
namespace RetailCrm;
|
||||||
|
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use RetailCrm\Client\ApiVersion3;
|
use RetailCrm\Client\ApiVersion3;
|
||||||
use RetailCrm\Client\ApiVersion4;
|
use RetailCrm\Client\ApiVersion4;
|
||||||
use RetailCrm\Client\ApiVersion5;
|
use RetailCrm\Client\ApiVersion5;
|
||||||
|
@ -67,4 +68,14 @@ class ApiClient
|
||||||
{
|
{
|
||||||
return $this->version;
|
return $this->version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set logger
|
||||||
|
*
|
||||||
|
* @param LoggerInterface|null $logger
|
||||||
|
*/
|
||||||
|
public function setLogger($logger = null)
|
||||||
|
{
|
||||||
|
$this->request->setLogger($logger);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
namespace RetailCrm\Client;
|
namespace RetailCrm\Client;
|
||||||
|
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use RetailCrm\Http\Client;
|
use RetailCrm\Http\Client;
|
||||||
use RetailCrm\Http\RequestOptions;
|
use RetailCrm\Http\RequestOptions;
|
||||||
|
|
||||||
|
@ -142,6 +143,16 @@ abstract class AbstractLoader
|
||||||
return $this->siteCode;
|
return $this->siteCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set logger
|
||||||
|
*
|
||||||
|
* @param LoggerInterface|null $logger
|
||||||
|
*/
|
||||||
|
public function setLogger($logger)
|
||||||
|
{
|
||||||
|
$this->client->setLogger($logger);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getting the list of available api versions
|
* Getting the list of available api versions
|
||||||
*
|
*
|
||||||
|
@ -171,4 +182,19 @@ abstract class AbstractLoader
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getting the system version, public and technical urls
|
||||||
|
*
|
||||||
|
* @return \RetailCrm\Response\ApiResponse
|
||||||
|
*/
|
||||||
|
public function systemInfo()
|
||||||
|
{
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
$this->crmUrl . 'api/system-info',
|
||||||
|
"GET",
|
||||||
|
[],
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ class ApiVersion5 extends AbstractLoader
|
||||||
use V5\Delivery;
|
use V5\Delivery;
|
||||||
use V5\Files;
|
use V5\Files;
|
||||||
use V5\Module;
|
use V5\Module;
|
||||||
|
use V5\Notifications;
|
||||||
use V5\Orders;
|
use V5\Orders;
|
||||||
use V5\Packs;
|
use V5\Packs;
|
||||||
use V5\References;
|
use V5\References;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
namespace RetailCrm\Http;
|
namespace RetailCrm\Http;
|
||||||
|
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use RetailCrm\Exception\CurlException;
|
use RetailCrm\Exception\CurlException;
|
||||||
use RetailCrm\Exception\InvalidJsonException;
|
use RetailCrm\Exception\InvalidJsonException;
|
||||||
use RetailCrm\Exception\LimitException;
|
use RetailCrm\Exception\LimitException;
|
||||||
|
@ -34,6 +35,11 @@ class Client
|
||||||
protected $defaultParameters;
|
protected $defaultParameters;
|
||||||
protected $options;
|
protected $options;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var LoggerInterface|null $logger
|
||||||
|
*/
|
||||||
|
protected $logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client constructor.
|
* Client constructor.
|
||||||
*
|
*
|
||||||
|
@ -116,6 +122,8 @@ class Client
|
||||||
curl_setopt($curlHandler, CURLOPT_HTTPHEADER, $this->options->getHttpHeaders());
|
curl_setopt($curlHandler, CURLOPT_HTTPHEADER, $this->options->getHttpHeaders());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->logRequest($url, $method, $parameters);
|
||||||
|
|
||||||
if (self::METHOD_POST === $method) {
|
if (self::METHOD_POST === $method) {
|
||||||
curl_setopt($curlHandler, CURLOPT_POST, true);
|
curl_setopt($curlHandler, CURLOPT_POST, true);
|
||||||
|
|
||||||
|
@ -128,6 +136,8 @@ class Client
|
||||||
|
|
||||||
list($statusCode, $responseBody) = $this->checkResponse($curlHandler, $method);
|
list($statusCode, $responseBody) = $this->checkResponse($curlHandler, $method);
|
||||||
|
|
||||||
|
$this->logResponse($responseBody, $statusCode);
|
||||||
|
|
||||||
return new ApiResponse($statusCode, $responseBody);
|
return new ApiResponse($statusCode, $responseBody);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,6 +176,16 @@ class Client
|
||||||
$this->options = $options;
|
$this->options = $options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set logger
|
||||||
|
*
|
||||||
|
* @param LoggerInterface|null $logger
|
||||||
|
*/
|
||||||
|
public function setLogger($logger = null)
|
||||||
|
{
|
||||||
|
$this->logger = $logger;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $curlHandler
|
* @param $curlHandler
|
||||||
* @param $method
|
* @param $method
|
||||||
|
@ -200,4 +220,39 @@ class Client
|
||||||
|
|
||||||
return [$statusCode, $responseBody];
|
return [$statusCode, $responseBody];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $url
|
||||||
|
* @param string $method
|
||||||
|
* @param array $params
|
||||||
|
*/
|
||||||
|
private function logRequest($url, $method, $params)
|
||||||
|
{
|
||||||
|
if (null === $this->logger) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$message = 'Send request: ' . $method . ' ' . $url;
|
||||||
|
|
||||||
|
if (!empty($params)) {
|
||||||
|
$message .= ' with params: ' . json_encode($params);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->logger->info($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $responseBody
|
||||||
|
* @param int $statusCode
|
||||||
|
*/
|
||||||
|
private function logResponse($responseBody, $statusCode)
|
||||||
|
{
|
||||||
|
if (null === $this->logger) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$message = 'Response with code ' . $statusCode . ' received with body: ' . $responseBody;
|
||||||
|
|
||||||
|
$this->logger->info($message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,7 +201,7 @@ trait Costs
|
||||||
*/
|
*/
|
||||||
public function costsDeleteById($id)
|
public function costsDeleteById($id)
|
||||||
{
|
{
|
||||||
if (!empty($id)) {
|
if (empty($id)) {
|
||||||
throw new \InvalidArgumentException(
|
throw new \InvalidArgumentException(
|
||||||
'Parameter `id` must contains a data'
|
'Parameter `id` must contains a data'
|
||||||
);
|
);
|
||||||
|
|
|
@ -73,4 +73,38 @@ trait Module
|
||||||
['integrationModule' => json_encode($configuration)]
|
['integrationModule' => json_encode($configuration)]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update scopes
|
||||||
|
*
|
||||||
|
* @param string $code
|
||||||
|
* @param array $requires
|
||||||
|
*
|
||||||
|
* @throws \RetailCrm\Exception\InvalidJsonException
|
||||||
|
* @throws \RetailCrm\Exception\CurlException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
|
*
|
||||||
|
* @return \RetailCrm\Response\ApiResponse
|
||||||
|
*/
|
||||||
|
public function integrationModulesUpdateScopes($code, array $requires)
|
||||||
|
{
|
||||||
|
if (empty($code)) {
|
||||||
|
throw new \InvalidArgumentException(
|
||||||
|
'Parameter `code` must be set'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!count($requires) || empty($requires['scopes'])) {
|
||||||
|
throw new \InvalidArgumentException(
|
||||||
|
'Parameter `requires` must contains a data & configuration `scopes` must be set'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* @noinspection PhpUndefinedMethodInspection */
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
sprintf('/integration-modules/%s/update-scopes', $code),
|
||||||
|
"POST",
|
||||||
|
['requires' => json_encode($requires)]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
47
lib/RetailCrm/Methods/V5/Notifications.php
Normal file
47
lib/RetailCrm/Methods/V5/Notifications.php
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace RetailCrm\Methods\V5;
|
||||||
|
|
||||||
|
use RetailCrm\Response\ApiResponse;
|
||||||
|
|
||||||
|
trait Notifications
|
||||||
|
{
|
||||||
|
protected static $allowedTypes = ['api.info', 'api.error'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ApiResponse
|
||||||
|
*/
|
||||||
|
public function sendNotification(array $notification)
|
||||||
|
{
|
||||||
|
if (empty($notification['type']) || !in_array($notification['type'], self::$allowedTypes, true)) {
|
||||||
|
throw new \InvalidArgumentException(
|
||||||
|
'Parameter `type` must be not empty & must be equal one of these values: api.info|api.error'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($notification['message'])) {
|
||||||
|
throw new \InvalidArgumentException(
|
||||||
|
'Parameter `message` should not be blank'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($notification['userGroups']) && empty($notification['userIds'])) {
|
||||||
|
throw new \InvalidArgumentException(
|
||||||
|
'One of the parameters must be filled: `userGroups` or `userIds`'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($notification['userGroups']) && !empty($notification['userIds'])) {
|
||||||
|
throw new \InvalidArgumentException(
|
||||||
|
'Only one of the two fields must be set: `userIds`, `userGroups`'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @noinspection PhpUndefinedMethodInspection */
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
"/notifications/send",
|
||||||
|
"POST",
|
||||||
|
['notification' => \json_encode($notification, JSON_UNESCAPED_SLASHES)]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
338
tests/RetailCrm/Tests/ApiClientCustomersTest.php
Normal file
338
tests/RetailCrm/Tests/ApiClientCustomersTest.php
Normal file
|
@ -0,0 +1,338 @@
|
||||||
|
<?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/ApiVersion5
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace RetailCrm\Tests;
|
||||||
|
|
||||||
|
use RetailCrm\Test\TestCase;
|
||||||
|
use function var_dump;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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/ApiVersion5
|
||||||
|
*/
|
||||||
|
class ApiClientCustomersTest extends TestCase
|
||||||
|
{
|
||||||
|
const FIRST_NAME = 'Иннокентий';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group customers
|
||||||
|
*/
|
||||||
|
public function testCustomersCreate()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$externalId = 'c-create-' . time();
|
||||||
|
|
||||||
|
$response = $client->customersCreate(array(
|
||||||
|
'firstName' => self::FIRST_NAME,
|
||||||
|
'externalId' => $externalId,
|
||||||
|
));
|
||||||
|
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(201, $response->getStatusCode());
|
||||||
|
static::assertTrue(is_int($response['id']));
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'id' => $response['id'],
|
||||||
|
'externalId' => $externalId,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group customers
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testCreateExceptionEmpty()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
$client->customersCreate(array());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group customers
|
||||||
|
* @depends testCustomersCreate
|
||||||
|
*
|
||||||
|
* @param array $ids
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function testCustomersGet(array $ids)
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->customersGet(678678678);
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(404, $response->getStatusCode());
|
||||||
|
static::assertFalse($response->isSuccessful());
|
||||||
|
|
||||||
|
$response = $client->customersGet($ids['id'], 'id');
|
||||||
|
$customerById = $response['customer'];
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
static::assertEquals(self::FIRST_NAME, $response['customer']['firstName']);
|
||||||
|
|
||||||
|
$response = $client->customersGet($ids['externalId'], 'externalId');
|
||||||
|
static::assertEquals($customerById['id'], $response['customer']['id']);
|
||||||
|
|
||||||
|
return $ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group customers
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testCustomersGetException()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
$client->customersGet(678678678, 'asdf');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group customers
|
||||||
|
* @depends testCustomersGet
|
||||||
|
*
|
||||||
|
* @param array $ids
|
||||||
|
*/
|
||||||
|
public function testCustomersEdit(array $ids)
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->customersEdit(
|
||||||
|
array(
|
||||||
|
'id' => 22342134,
|
||||||
|
'lastName' => '12345',
|
||||||
|
),
|
||||||
|
'id'
|
||||||
|
);
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(404, $response->getStatusCode());
|
||||||
|
|
||||||
|
$response = $client->customersEdit(array(
|
||||||
|
'externalId' => $ids['externalId'],
|
||||||
|
'lastName' => '12345',
|
||||||
|
));
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group customers
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testCustomersEditExceptionEmpty()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
$client->customersEdit(array(), 'asdf');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group customers
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testCustomersEditException()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
$client->customersEdit(array('id' => 678678678), 'asdf');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group customers
|
||||||
|
*/
|
||||||
|
public function testCustomersList()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->customersList();
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
static::assertTrue(isset($response['customers']));
|
||||||
|
|
||||||
|
$response = $client->customersList(array(), 1, 300);
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertFalse(
|
||||||
|
$response->isSuccessful(),
|
||||||
|
'Pagination error'
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $client->customersList(array('maxOrdersCount' => 10), 1);
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertTrue(
|
||||||
|
$response->isSuccessful(),
|
||||||
|
'API returns customers list'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group customers
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testCustomersFixExternalIdsException()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
$client->customersFixExternalIds(array());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group customers
|
||||||
|
*/
|
||||||
|
public function testCustomersFixExternalIds()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->ordersCreate(array(
|
||||||
|
'firstName' => 'Aaa111',
|
||||||
|
));
|
||||||
|
|
||||||
|
static::assertTrue(
|
||||||
|
$response->isSuccessful(),
|
||||||
|
'Order created'
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $client->ordersGet($response['id'], 'id');
|
||||||
|
static::assertTrue(
|
||||||
|
$response->isSuccessful(),
|
||||||
|
'Order fetched'
|
||||||
|
);
|
||||||
|
|
||||||
|
$id = $response['order']['customer']['id'];
|
||||||
|
$externalId = 'asdf' . time();
|
||||||
|
|
||||||
|
$response = $client->customersFixExternalIds(array(
|
||||||
|
array('id' => $id, 'externalId' => $externalId)
|
||||||
|
));
|
||||||
|
|
||||||
|
static::assertTrue(
|
||||||
|
$response->isSuccessful(),
|
||||||
|
'Fixed customer ids'
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $client->customersGet($externalId);
|
||||||
|
static::assertTrue(
|
||||||
|
$response->isSuccessful(),
|
||||||
|
'Got customer'
|
||||||
|
);
|
||||||
|
static::assertEquals(
|
||||||
|
$id,
|
||||||
|
$response['customer']['id'],
|
||||||
|
'Fixing of customer ids were right'
|
||||||
|
);
|
||||||
|
static::assertEquals(
|
||||||
|
$externalId,
|
||||||
|
$response['customer']['externalId'],
|
||||||
|
'Fixing of customer ids were right'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group customers
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testCustomersUploadExceptionEmpty()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
$client->customersUpload(array());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group customers
|
||||||
|
*/
|
||||||
|
public function testCustomersUpload()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$externalIdA = 'upload-a-' . time();
|
||||||
|
$externalIdB = 'upload-b-' . time();
|
||||||
|
|
||||||
|
$response = $client->customersUpload(array(
|
||||||
|
array(
|
||||||
|
'externalId' => $externalIdA,
|
||||||
|
'firstName' => 'Aaa',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'externalId' => $externalIdB,
|
||||||
|
'lastName' => 'Bbb',
|
||||||
|
),
|
||||||
|
));
|
||||||
|
static::assertTrue(
|
||||||
|
$response->isSuccessful(),
|
||||||
|
'Got customer'
|
||||||
|
);
|
||||||
|
static::assertEquals(
|
||||||
|
$externalIdA,
|
||||||
|
$response['uploadedCustomers'][0]['externalId']
|
||||||
|
);
|
||||||
|
static::assertEquals(
|
||||||
|
$externalIdB,
|
||||||
|
$response['uploadedCustomers'][1]['externalId']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group customers
|
||||||
|
*/
|
||||||
|
public function testCustomersCombine()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$responseCreateFirst = $client->customersCreate(array(
|
||||||
|
'firstName' => 'Aaa111',
|
||||||
|
'externalId' => 'AA-' . time(),
|
||||||
|
'phones' => array(
|
||||||
|
array(
|
||||||
|
'number' => '+79999999990'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
static::assertTrue(
|
||||||
|
$responseCreateFirst->isSuccessful(),
|
||||||
|
'Got customer'
|
||||||
|
);
|
||||||
|
|
||||||
|
$responseCreateSecond = $client->customersCreate(array(
|
||||||
|
'firstName' => 'Aaa222',
|
||||||
|
'externalId' => 'BB-' . time(),
|
||||||
|
'phones' => array(
|
||||||
|
array(
|
||||||
|
'number' => '+79999999991'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
static::assertTrue(
|
||||||
|
$responseCreateSecond->isSuccessful(),
|
||||||
|
'Got customer'
|
||||||
|
);
|
||||||
|
|
||||||
|
$customers = array(
|
||||||
|
array('id' => $responseCreateFirst['id'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$resultCustomer = array('id' => $responseCreateSecond['id']);
|
||||||
|
|
||||||
|
$response = $client->customersCombine($customers, $resultCustomer);
|
||||||
|
|
||||||
|
static::assertTrue(
|
||||||
|
$response->isSuccessful(),
|
||||||
|
'Customers combined'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
49
tests/RetailCrm/Tests/ApiClientMarketplaceTest.php
Normal file
49
tests/RetailCrm/Tests/ApiClientMarketplaceTest.php
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHP version 5.3
|
||||||
|
*
|
||||||
|
* API client marketplace 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/ApiVersion5
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace RetailCrm\Tests;
|
||||||
|
|
||||||
|
use RetailCrm\Test\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ApiClientMarketplaceTest
|
||||||
|
*
|
||||||
|
* @package RetailCrm\Tests
|
||||||
|
*/
|
||||||
|
class ApiClientMarketplaceTest extends TestCase
|
||||||
|
{
|
||||||
|
const SNAME = 'Marketplace integration';
|
||||||
|
const SCODE = 'integration';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group marketplace
|
||||||
|
*/
|
||||||
|
public function testConfigurationEdit()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->marketplaceSettingsEdit(
|
||||||
|
array(
|
||||||
|
'name' => self::SNAME,
|
||||||
|
'code' => self::SCODE,
|
||||||
|
'logo' => 'http://download.retailcrm.pro/logos/setup.svg',
|
||||||
|
'active' => 'true'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertTrue(in_array($response->getStatusCode(), array(200, 201)));
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
}
|
||||||
|
}
|
420
tests/RetailCrm/Tests/ApiClientOrdersTest.php
Normal file
420
tests/RetailCrm/Tests/ApiClientOrdersTest.php
Normal file
|
@ -0,0 +1,420 @@
|
||||||
|
<?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/ApiVersion5
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace RetailCrm\Tests;
|
||||||
|
|
||||||
|
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/ApiVersion5
|
||||||
|
*/
|
||||||
|
class ApiClientOrdersTest extends TestCase
|
||||||
|
{
|
||||||
|
const FIRST_NAME = 'Иннокентий';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group orders
|
||||||
|
*/
|
||||||
|
public function testOrdersCreate()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$externalId = 'o-create-' . time();
|
||||||
|
|
||||||
|
$response = $client->ordersCreate(array(
|
||||||
|
'firstName' => self::FIRST_NAME,
|
||||||
|
'externalId' => $externalId,
|
||||||
|
));
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(201, $response->getStatusCode());
|
||||||
|
static::assertTrue(is_int($response['id']));
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'id' => $response['id'],
|
||||||
|
'externalId' => $externalId,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group orders
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testOrdersCreateExceptionEmpty()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
$client->ordersCreate(array());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group orders
|
||||||
|
* @depends testOrdersCreate
|
||||||
|
*
|
||||||
|
* @param array $ids
|
||||||
|
*/
|
||||||
|
public function testOrdersStatuses(array $ids)
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->ordersStatuses();
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(400, $response->getStatusCode());
|
||||||
|
static::assertFalse($response->isSuccessful());
|
||||||
|
|
||||||
|
$response = $client->ordersStatuses(array(), array('asdf'));
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
$orders = $response['orders'];
|
||||||
|
static::assertEquals(0, sizeof($orders));
|
||||||
|
|
||||||
|
$response = $client->ordersStatuses(array(), array($ids['externalId']));
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
$orders = $response['orders'];
|
||||||
|
static::assertEquals(1, sizeof($orders));
|
||||||
|
static::assertEquals('new', $orders[0]['status']);
|
||||||
|
|
||||||
|
$response = $client->ordersStatuses(array($ids['id']), array($ids['externalId']));
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
$orders = $response['orders'];
|
||||||
|
static::assertEquals(1, sizeof($orders));
|
||||||
|
|
||||||
|
$response = $client->ordersStatuses(array($ids['id']));
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
$orders = $response['orders'];
|
||||||
|
static::assertEquals(1, sizeof($orders));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group orders
|
||||||
|
* @depends testOrdersCreate
|
||||||
|
*
|
||||||
|
* @param array $ids
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function testOrdersGet(array $ids)
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->ordersGet(678678678);
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(404, $response->getStatusCode());
|
||||||
|
static::assertFalse($response->isSuccessful());
|
||||||
|
|
||||||
|
$response = $client->ordersGet($ids['id'], 'id');
|
||||||
|
$orderById = $response['order'];
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
static::assertEquals(self::FIRST_NAME, $response['order']['firstName']);
|
||||||
|
|
||||||
|
$response = $client->ordersGet($ids['externalId'], 'externalId');
|
||||||
|
static::assertEquals($orderById['id'], $response['order']['id']);
|
||||||
|
|
||||||
|
return $ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group orders
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testOrdersGetException()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
$client->ordersGet(678678678, 'asdf');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group orders
|
||||||
|
* @depends testOrdersGet
|
||||||
|
*
|
||||||
|
* @param array $ids
|
||||||
|
*/
|
||||||
|
public function testOrdersEdit(array $ids)
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->ordersEdit(
|
||||||
|
array(
|
||||||
|
'id' => 22342134,
|
||||||
|
'lastName' => '12345',
|
||||||
|
),
|
||||||
|
'id'
|
||||||
|
);
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(404, $response->getStatusCode());
|
||||||
|
|
||||||
|
$response = $client->ordersEdit(array(
|
||||||
|
'externalId' => $ids['externalId'],
|
||||||
|
'lastName' => '12345',
|
||||||
|
));
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group orders
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testOrdersEditExceptionEmpty()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
$client->ordersEdit(array(), 'asdf');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group orders
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testOrdersEditException()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
$client->ordersEdit(array('id' => 678678678), 'asdf');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group orders
|
||||||
|
*/
|
||||||
|
public function testOrdersHistory()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->ordersHistory();
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group orders
|
||||||
|
*/
|
||||||
|
public function testOrdersList()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->ordersList();
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
static::assertTrue(isset($response['orders']));
|
||||||
|
|
||||||
|
$response = $client->ordersList(array(), 1, 300);
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertFalse(
|
||||||
|
$response->isSuccessful(),
|
||||||
|
'Pagination error'
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $client->ordersList(array('paymentStatus' => 'paid'), 1);
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group orders
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testOrdersFixExternalIdsException()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
$client->ordersFixExternalIds(array());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group orders
|
||||||
|
*/
|
||||||
|
public function testOrdersFixExternalIds()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->ordersCreate(array(
|
||||||
|
'firstName' => 'Aaa',
|
||||||
|
));
|
||||||
|
static::assertTrue(
|
||||||
|
$response->isSuccessful(),
|
||||||
|
'Order created'
|
||||||
|
);
|
||||||
|
|
||||||
|
$id = $response['id'];
|
||||||
|
$externalId = 'asdf' . time();
|
||||||
|
|
||||||
|
$response = $client->ordersFixExternalIds(array(
|
||||||
|
array('id' => $id, 'externalId' => $externalId)
|
||||||
|
));
|
||||||
|
|
||||||
|
static::assertTrue(
|
||||||
|
$response->isSuccessful(),
|
||||||
|
'Fixed order ids'
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $client->ordersGet($externalId);
|
||||||
|
static::assertTrue(
|
||||||
|
$response->isSuccessful(),
|
||||||
|
'Got order'
|
||||||
|
);
|
||||||
|
static::assertEquals(
|
||||||
|
$id,
|
||||||
|
$response['order']['id'],
|
||||||
|
'Fixing of order ids were right'
|
||||||
|
);
|
||||||
|
static::assertEquals(
|
||||||
|
$externalId,
|
||||||
|
$response['order']['externalId'],
|
||||||
|
'Fixing of order ids were right'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group orders
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testOrdersUploadExceptionEmpty()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
$client->ordersUpload(array());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group orders
|
||||||
|
*/
|
||||||
|
public function testOrdersUpload()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$externalIdA = 'upload-a-' . time();
|
||||||
|
$externalIdB = 'upload-b-' . time();
|
||||||
|
|
||||||
|
$response = $client->ordersUpload(array(
|
||||||
|
array(
|
||||||
|
'externalId' => $externalIdA,
|
||||||
|
'firstName' => 'Aaa',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'externalId' => $externalIdB,
|
||||||
|
'lastName' => 'Bbb',
|
||||||
|
),
|
||||||
|
));
|
||||||
|
static::assertTrue(
|
||||||
|
$response->isSuccessful(),
|
||||||
|
'Got order'
|
||||||
|
);
|
||||||
|
static::assertEquals(
|
||||||
|
$externalIdA,
|
||||||
|
$response['uploadedOrders'][0]['externalId']
|
||||||
|
);
|
||||||
|
static::assertEquals(
|
||||||
|
$externalIdB,
|
||||||
|
$response['uploadedOrders'][1]['externalId']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group orders
|
||||||
|
*/
|
||||||
|
public function testOrdersCombine()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$responseCreateFirst = $client->ordersCreate([
|
||||||
|
'firstName' => 'Aaa111',
|
||||||
|
'externalId' => 'AA-' . time(),
|
||||||
|
'phone' => '+79999999990'
|
||||||
|
]);
|
||||||
|
|
||||||
|
static::assertTrue(
|
||||||
|
$responseCreateFirst->isSuccessful(),
|
||||||
|
'Got order'
|
||||||
|
);
|
||||||
|
|
||||||
|
$responseCreateSecond = $client->ordersCreate([
|
||||||
|
'firstName' => 'Aaa222',
|
||||||
|
'externalId' => 'BB-' . time(),
|
||||||
|
'phone' => '+79999999991'
|
||||||
|
]);
|
||||||
|
|
||||||
|
static::assertTrue(
|
||||||
|
$responseCreateSecond->isSuccessful(),
|
||||||
|
'Got order'
|
||||||
|
);
|
||||||
|
|
||||||
|
$order = ['id' => $responseCreateFirst['id']];
|
||||||
|
$resultOrder = ['id' => $responseCreateSecond['id']];
|
||||||
|
|
||||||
|
$response = $client->ordersCombine($order, $resultOrder, 'ours');
|
||||||
|
|
||||||
|
static::assertTrue(
|
||||||
|
$response->isSuccessful(),
|
||||||
|
'Orders combined'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOrdersPayment()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
$externalId = 'AA-' . time();
|
||||||
|
|
||||||
|
$responseCreateFirst = $client->ordersCreate([
|
||||||
|
'firstName' => 'Aaa111aaA',
|
||||||
|
'phone' => '+79999999990'
|
||||||
|
]);
|
||||||
|
|
||||||
|
static::assertTrue(
|
||||||
|
$responseCreateFirst->isSuccessful(),
|
||||||
|
'Got order'
|
||||||
|
);
|
||||||
|
|
||||||
|
$payment = array(
|
||||||
|
'externalId' => $externalId,
|
||||||
|
'order' => array('id' => $responseCreateFirst['id']),
|
||||||
|
'amount' => 1200,
|
||||||
|
'comment' => 'test payment',
|
||||||
|
'type' => 'cash',
|
||||||
|
'status' => 'paid'
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $client->ordersPaymentCreate($payment);
|
||||||
|
|
||||||
|
static::assertTrue(
|
||||||
|
$response->isSuccessful(),
|
||||||
|
'Got payment'
|
||||||
|
);
|
||||||
|
|
||||||
|
$paymentEdit = array(
|
||||||
|
'id' => $response['id'],
|
||||||
|
'externalId' => $externalId,
|
||||||
|
'amount' => 1500,
|
||||||
|
'comment' => 'test payment!',
|
||||||
|
'type' => 'cash',
|
||||||
|
'status' => 'paid'
|
||||||
|
);
|
||||||
|
|
||||||
|
$responseAgain = $client->ordersPaymentEdit($paymentEdit);
|
||||||
|
|
||||||
|
static::assertTrue(
|
||||||
|
$responseAgain->isSuccessful(),
|
||||||
|
'Got payment'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
74
tests/RetailCrm/Tests/ApiClientPacksTest.php
Normal file
74
tests/RetailCrm/Tests/ApiClientPacksTest.php
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHP version 5.3
|
||||||
|
*
|
||||||
|
* API client packs 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/ApiVersion5
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace RetailCrm\Tests;
|
||||||
|
|
||||||
|
use RetailCrm\Test\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ApiClientPacksTest
|
||||||
|
*
|
||||||
|
* @category RetailCrm
|
||||||
|
* @package RetailCrm
|
||||||
|
* @author RetailCrm <integration@retailcrm.ru>
|
||||||
|
* @license https://opensource.org/licenses/MIT MIT License
|
||||||
|
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
||||||
|
*/
|
||||||
|
class ApiClientPacksTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test packs history
|
||||||
|
*
|
||||||
|
* @group packs
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testPacksHistory()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->ordersPacksHistory();
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->success);
|
||||||
|
static::assertTrue(
|
||||||
|
isset($response['history']),
|
||||||
|
'API returns orders assembly history'
|
||||||
|
);
|
||||||
|
static::assertTrue(
|
||||||
|
isset($response['generatedAt']),
|
||||||
|
'API returns generatedAt in orders assembly history'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test packs failed create
|
||||||
|
*
|
||||||
|
* @group packs
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testPacksCreateFailed()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
$pack = array(
|
||||||
|
'itemId' => 12,
|
||||||
|
'store' => 'test',
|
||||||
|
'quantity' => 2
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $client->ordersPacksCreate($pack);
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(400, $response->getStatusCode());
|
||||||
|
static::assertFalse($response->success);
|
||||||
|
}
|
||||||
|
}
|
134
tests/RetailCrm/Tests/ApiClientPricesTest.php
Normal file
134
tests/RetailCrm/Tests/ApiClientPricesTest.php
Normal file
|
@ -0,0 +1,134 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHP version 5.3
|
||||||
|
*
|
||||||
|
* API client prices 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/ApiVersion5
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace RetailCrm\Tests;
|
||||||
|
|
||||||
|
use RetailCrm\Test\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ApiClientPricesTest
|
||||||
|
*
|
||||||
|
* @category RetailCrm
|
||||||
|
* @package RetailCrm
|
||||||
|
* @author RetailCrm <integration@retailcrm.ru>
|
||||||
|
* @license https://opensource.org/licenses/MIT MIT License
|
||||||
|
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
||||||
|
*/
|
||||||
|
class ApiClientPricesTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ApiClientPricesTest constructor.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->code = 'price-code-a-' . time();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group prices
|
||||||
|
*/
|
||||||
|
public function testUsersGroups()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->usersGroups();
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group prices
|
||||||
|
*/
|
||||||
|
public function testPricesGet()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->pricesTypes();
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group prices
|
||||||
|
*/
|
||||||
|
public function testPricesEdit()
|
||||||
|
{
|
||||||
|
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->pricesEdit(
|
||||||
|
array(
|
||||||
|
'code' => $this->code,
|
||||||
|
'name' => $this->code,
|
||||||
|
'ordering' => 500,
|
||||||
|
'active' => true
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(201, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group prices
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testPricesUploadExceptionEmpty()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
$client->storePricesUpload(array());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group prices
|
||||||
|
*/
|
||||||
|
public function testPricesUpload()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$xmlIdA = 'upload-a-' . time();
|
||||||
|
$xmlIdB = 'upload-b-' . time();
|
||||||
|
|
||||||
|
$response = $client->storePricesUpload(array(
|
||||||
|
array(
|
||||||
|
'xmlId' => $xmlIdA,
|
||||||
|
'prices' => array(
|
||||||
|
array(
|
||||||
|
'code' => $this->code,
|
||||||
|
'price' => 1700
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'xmlId' => $xmlIdB,
|
||||||
|
'prices' => array(
|
||||||
|
array(
|
||||||
|
'code' => $this->code,
|
||||||
|
'price' => 1500
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
}
|
170
tests/RetailCrm/Tests/ApiClientReferenceTest.php
Normal file
170
tests/RetailCrm/Tests/ApiClientReferenceTest.php
Normal file
|
@ -0,0 +1,170 @@
|
||||||
|
<?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/ApiVersion5
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace RetailCrm\Tests;
|
||||||
|
|
||||||
|
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/ApiVersion5
|
||||||
|
*/
|
||||||
|
class ApiClientReferenceTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @group reference
|
||||||
|
* @dataProvider getListDictionaries
|
||||||
|
* @param $name
|
||||||
|
*/
|
||||||
|
public function testList($name)
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$method = $name . 'List';
|
||||||
|
$response = $client->$method();
|
||||||
|
|
||||||
|
/* @var \RetailCrm\Response\ApiResponse $response */
|
||||||
|
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
static::assertTrue(isset($response[$name]));
|
||||||
|
static::assertTrue(is_array($response[$name]));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group reference
|
||||||
|
* @dataProvider getEditDictionaries
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*
|
||||||
|
* @param $name
|
||||||
|
*/
|
||||||
|
public function testEditingException($name)
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$method = $name . 'Edit';
|
||||||
|
$client->$method(array());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group reference
|
||||||
|
* @dataProvider getEditDictionaries
|
||||||
|
*
|
||||||
|
* @param $name
|
||||||
|
*/
|
||||||
|
public function testEditing($name)
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$code = 'dict-' . strtolower($name) . '-' . time();
|
||||||
|
$method = $name . 'Edit';
|
||||||
|
$params = array(
|
||||||
|
'code' => $code,
|
||||||
|
'name' => 'Aaa' . $code,
|
||||||
|
'active' => false
|
||||||
|
);
|
||||||
|
if ($name == 'statuses') {
|
||||||
|
$params['group'] = 'new';
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = $client->$method($params);
|
||||||
|
/* @var \RetailCrm\Response\ApiResponse $response */
|
||||||
|
|
||||||
|
static::assertTrue(in_array($response->getStatusCode(), array(200, 201)));
|
||||||
|
|
||||||
|
$response = $client->$method(array(
|
||||||
|
'code' => $code,
|
||||||
|
'name' => 'Bbb' . $code,
|
||||||
|
'active' => false
|
||||||
|
));
|
||||||
|
|
||||||
|
static::assertTrue(in_array($response->getStatusCode(), array(200, 201)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group reference
|
||||||
|
* @group site
|
||||||
|
*/
|
||||||
|
public function testSiteEditing()
|
||||||
|
{
|
||||||
|
$name = 'sites';
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$code = 'dict-' . strtolower($name) . '-' . time();
|
||||||
|
$method = $name . 'Edit';
|
||||||
|
$params = array(
|
||||||
|
'code' => $code,
|
||||||
|
'name' => 'Aaa',
|
||||||
|
'active' => false
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $client->$method($params);
|
||||||
|
/* @var \RetailCrm\Response\ApiResponse $response */
|
||||||
|
|
||||||
|
static::assertEquals(400, $response->getStatusCode());
|
||||||
|
|
||||||
|
if ($code == $client->getSite()) {
|
||||||
|
$method = $name . 'Edit';
|
||||||
|
$params = array(
|
||||||
|
'code' => $code,
|
||||||
|
'name' => 'Aaa' . time(),
|
||||||
|
'active' => false
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $client->$method($params);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getListDictionaries()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('deliveryServices'),
|
||||||
|
array('deliveryTypes'),
|
||||||
|
array('orderMethods'),
|
||||||
|
array('orderTypes'),
|
||||||
|
array('paymentStatuses'),
|
||||||
|
array('paymentTypes'),
|
||||||
|
array('productStatuses'),
|
||||||
|
array('statusGroups'),
|
||||||
|
array('statuses'),
|
||||||
|
array('sites'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getEditDictionaries()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('deliveryServices'),
|
||||||
|
array('deliveryTypes'),
|
||||||
|
array('orderMethods'),
|
||||||
|
array('orderTypes'),
|
||||||
|
array('paymentStatuses'),
|
||||||
|
array('paymentTypes'),
|
||||||
|
array('productStatuses'),
|
||||||
|
array('statuses'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
159
tests/RetailCrm/Tests/ApiClientStoreTest.php
Normal file
159
tests/RetailCrm/Tests/ApiClientStoreTest.php
Normal file
|
@ -0,0 +1,159 @@
|
||||||
|
<?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/ApiVersion5
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace RetailCrm\Tests;
|
||||||
|
|
||||||
|
use RetailCrm\Test\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ApiClientStoreTest
|
||||||
|
*
|
||||||
|
* @category RetailCrm
|
||||||
|
* @package RetailCrm
|
||||||
|
* @author RetailCrm <integration@retailcrm.ru>
|
||||||
|
* @license https://opensource.org/licenses/MIT MIT License
|
||||||
|
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
||||||
|
*/
|
||||||
|
class ApiClientStoreTest extends TestCase
|
||||||
|
{
|
||||||
|
const SNAME = 'Test Store';
|
||||||
|
const SCODE = 'test-store';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group store
|
||||||
|
*/
|
||||||
|
public function testStoreCreate()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->storesEdit(array('name' => self::SNAME, 'code' => self::SCODE));
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertTrue(in_array($response->getStatusCode(), array(200, 201)));
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group store
|
||||||
|
*/
|
||||||
|
public function testStoreInventories()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->storeInventories();
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
static::assertTrue(
|
||||||
|
isset($response['offers']),
|
||||||
|
'API returns orders assembly history'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group store
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testInventoriesException()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
$client->storeInventoriesUpload(array());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group store
|
||||||
|
*/
|
||||||
|
public function testInventoriesUpload()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->storeInventoriesUpload(array(
|
||||||
|
array(
|
||||||
|
'externalId' => 'pTKIKAeghYzX21HTdzFCe1',
|
||||||
|
'stores' => array(
|
||||||
|
array(
|
||||||
|
'code' => self::SCODE,
|
||||||
|
'available' => 10,
|
||||||
|
'purchasePrice' => 1700
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'externalId' => 'JQIvcrCtiSpOV3AAfMiQB3',
|
||||||
|
'stores' => array(
|
||||||
|
array(
|
||||||
|
'code' => self::SCODE,
|
||||||
|
'available' => 20,
|
||||||
|
'purchasePrice' => 1500
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group integration
|
||||||
|
*/
|
||||||
|
public function testInventoriesFailed()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$externalIdA = 'upload-a-' . time();
|
||||||
|
$externalIdB = 'upload-b-' . time();
|
||||||
|
|
||||||
|
$response = $client->storeInventoriesUpload(array(
|
||||||
|
array(
|
||||||
|
'externalId' => $externalIdA,
|
||||||
|
'available' => 10,
|
||||||
|
'purchasePrice' => 1700
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'externalId' => $externalIdB,
|
||||||
|
'available' => 20,
|
||||||
|
'purchasePrice' => 1500
|
||||||
|
),
|
||||||
|
));
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(400, $response->getStatusCode());
|
||||||
|
static::assertTrue(isset($response['errorMsg']), $response['errorMsg']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group store
|
||||||
|
*/
|
||||||
|
public function testStoreProducts()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->storeProducts();
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group store
|
||||||
|
*/
|
||||||
|
public function testStoreProductsGroups()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->storeProductsGroups();
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
}
|
||||||
|
}
|
84
tests/RetailCrm/Tests/ApiClientTasksTest.php
Normal file
84
tests/RetailCrm/Tests/ApiClientTasksTest.php
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
<?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/ApiVersion5
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace RetailCrm\Tests;
|
||||||
|
|
||||||
|
use RetailCrm\Test\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ApiClientTasksTest
|
||||||
|
*
|
||||||
|
* @category RetailCrm
|
||||||
|
* @package RetailCrm
|
||||||
|
* @author RetailCrm <integration@retailcrm.ru>
|
||||||
|
* @license https://opensource.org/licenses/MIT MIT License
|
||||||
|
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
||||||
|
*/
|
||||||
|
class ApiClientTasksTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @group tasks
|
||||||
|
*/
|
||||||
|
public function testTasksList()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->tasksList();
|
||||||
|
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group tasks
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testTasksCreateExceptionEmpty()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
$client->tasksCreate(array());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTasksCRU()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$task = array(
|
||||||
|
'text' => 'test task',
|
||||||
|
'commentary' => 'test task commentary',
|
||||||
|
'performerId' => $_SERVER['CRM_USER_ID'],
|
||||||
|
'complete' => false
|
||||||
|
);
|
||||||
|
|
||||||
|
$responseCreate = $client->tasksCreate($task);
|
||||||
|
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $responseCreate);
|
||||||
|
static::assertEquals(201, $responseCreate->getStatusCode());
|
||||||
|
|
||||||
|
$uid = $responseCreate['id'];
|
||||||
|
|
||||||
|
$responseRead = $client->tasksGet($uid);
|
||||||
|
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $responseRead);
|
||||||
|
static::assertEquals(200, $responseRead->getStatusCode());
|
||||||
|
|
||||||
|
$task['id'] = $uid;
|
||||||
|
$task['complete'] = true;
|
||||||
|
|
||||||
|
$responseUpdate = $client->tasksEdit($task);
|
||||||
|
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $responseUpdate);
|
||||||
|
static::assertEquals(200, $responseUpdate->getStatusCode());
|
||||||
|
}
|
||||||
|
}
|
159
tests/RetailCrm/Tests/ApiClientTelephonyTest.php
Normal file
159
tests/RetailCrm/Tests/ApiClientTelephonyTest.php
Normal file
|
@ -0,0 +1,159 @@
|
||||||
|
<?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/ApiVersion5
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace RetailCrm\Tests;
|
||||||
|
|
||||||
|
use RetailCrm\Test\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ApiClientTelephonyTest
|
||||||
|
* @category RetailCrm
|
||||||
|
* @package RetailCrm\Tests
|
||||||
|
* @author RetailCrm <integration@retailcrm.ru>
|
||||||
|
* @license https://opensource.org/licenses/MIT MIT License
|
||||||
|
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
||||||
|
*/
|
||||||
|
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 Edit test
|
||||||
|
*
|
||||||
|
* @group telephony
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testTelephonySettingsEdit()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->telephonySettingsEdit(
|
||||||
|
self::TEL_CODE,
|
||||||
|
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'))
|
||||||
|
);
|
||||||
|
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertTrue(in_array($response->getStatusCode(), array(200, 201)));
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Settings Get test
|
||||||
|
*
|
||||||
|
* @group telephony
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testTelephonySettingsGet()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->telephonySettingsGet(self::TEL_CODE);
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event test
|
||||||
|
*
|
||||||
|
* @group telephony
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testTelephonyEvent()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->telephonyCallEvent(
|
||||||
|
'+79999999999',
|
||||||
|
'in',
|
||||||
|
array('101'),
|
||||||
|
'failed',
|
||||||
|
'+74950000000'
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::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' => 'http://download.retailcrm.pro/api-client-files/beep1.mp3'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'date' => '2016-07-22 00:24:00',
|
||||||
|
'type' => 'in',
|
||||||
|
'phone' => '+79999999999',
|
||||||
|
'code' => '101',
|
||||||
|
'result' => 'answered',
|
||||||
|
'externalId' => rand(10, 100),
|
||||||
|
'recordUrl' => 'http://download.retailcrm.pro/api-client-files/beep2.mp3'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manager test
|
||||||
|
*
|
||||||
|
* @group telephony
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testTelephonyManager()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->telephonyCallManager('+79999999999', 1);
|
||||||
|
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
}
|
||||||
|
}
|
68
tests/RetailCrm/Tests/ApiClientUsersTest.php
Normal file
68
tests/RetailCrm/Tests/ApiClientUsersTest.php
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
<?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/ApiVersion5
|
||||||
|
*/
|
||||||
|
|
||||||
|
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/ApiVersion5
|
||||||
|
*/
|
||||||
|
class ApiClientUsersTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @group users
|
||||||
|
*/
|
||||||
|
public function testUsersList()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->usersList();
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertTrue(in_array($response->getStatusCode(), array(200, 201)));
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group users
|
||||||
|
*/
|
||||||
|
public function testUsersGet()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->usersGet($_SERVER["CRM_USER_ID"]);
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertTrue(in_array($response->getStatusCode(), array(200, 201)));
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group users
|
||||||
|
*/
|
||||||
|
public function testUsersStatus()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->usersStatus($_SERVER["CRM_USER_ID"], 'dinner');
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertTrue(in_array($response->getStatusCode(), array(200, 201)));
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
}
|
||||||
|
}
|
|
@ -74,4 +74,22 @@ class CommonMethodsTest extends TestCase
|
||||||
static::assertTrue($response->isSuccessful());
|
static::assertTrue($response->isSuccessful());
|
||||||
static::assertGreaterThan(0, count($response['settings']));
|
static::assertGreaterThan(0, count($response['settings']));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* System info
|
||||||
|
*
|
||||||
|
* @group api_methods
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testSystemInfo()
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$response = $client->request->systemInfo();
|
||||||
|
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
static::assertNotEmpty($response['systemVersion']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace RetailCrm\Tests\Methods\Version5;
|
||||||
|
|
||||||
|
use RetailCrm\Response\ApiResponse;
|
||||||
|
use RetailCrm\Test\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ApiClientModulesTest
|
||||||
|
*
|
||||||
|
* @category RetailCrm
|
||||||
|
* @package RetailCrm
|
||||||
|
*/
|
||||||
|
class ApiClientModuleTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test configuration
|
||||||
|
*
|
||||||
|
* @group module_v5
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testUpdateScopes()
|
||||||
|
{
|
||||||
|
$integrationCode = 'integration_v5';
|
||||||
|
$stub = $this->getMockBuilder(\RetailCrm\Http\Client::class)
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->setMethods(['makeRequest'])
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$requires = [
|
||||||
|
'scopes' => [
|
||||||
|
"integration_read",
|
||||||
|
"integration_write"
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$stub->expects(self::once())
|
||||||
|
->method('makeRequest')
|
||||||
|
->with(
|
||||||
|
sprintf('/integration-modules/%s/update-scopes', $integrationCode),
|
||||||
|
"POST",
|
||||||
|
['requires' => json_encode($requires)]
|
||||||
|
)
|
||||||
|
->willReturn(
|
||||||
|
(new ApiResponse(200, json_encode(['success' => true, 'apiKey' => 'test key'])))
|
||||||
|
->asJsonResponse()
|
||||||
|
)
|
||||||
|
;
|
||||||
|
$client = static::getMockedApiClient($stub);
|
||||||
|
|
||||||
|
/** @var \RetailCrm\Response\ApiResponse $response */
|
||||||
|
$response = $client->request->integrationModulesUpdateScopes($integrationCode, $requires);
|
||||||
|
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals($response->getStatusCode(), 200);
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
static::assertNotEmpty($response['apiKey']);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,106 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace RetailCrm\Tests\Methods\Version5;
|
||||||
|
|
||||||
|
use RetailCrm\Test\TestCase;
|
||||||
|
|
||||||
|
class ApiClientNotificationsTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @dataProvider notificationsProvider
|
||||||
|
*
|
||||||
|
* @group notifications_v5
|
||||||
|
*
|
||||||
|
* @param callable $getNotification
|
||||||
|
* @param string|null $exceptionClass
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testSendNotification(callable $getNotification, $exceptionClass)
|
||||||
|
{
|
||||||
|
$client = static::getApiClient();
|
||||||
|
if (!empty($exceptionClass)) {
|
||||||
|
$this->expectException($exceptionClass);
|
||||||
|
}
|
||||||
|
$response = $client->request->sendNotification($getNotification());
|
||||||
|
if (empty($exceptionClass)) {
|
||||||
|
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array[]
|
||||||
|
*/
|
||||||
|
public function notificationsProvider()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'error_type' => [
|
||||||
|
static function () {
|
||||||
|
$notification = self::getErrorNotification();
|
||||||
|
$notification['type'] = 'another';
|
||||||
|
|
||||||
|
return $notification;
|
||||||
|
},
|
||||||
|
'InvalidArgumentException',
|
||||||
|
],
|
||||||
|
'error_message' => [
|
||||||
|
static function () {
|
||||||
|
$notification = self::getErrorNotification();
|
||||||
|
$notification['message'] = [];
|
||||||
|
|
||||||
|
return $notification;
|
||||||
|
},
|
||||||
|
'InvalidArgumentException',
|
||||||
|
],
|
||||||
|
'error_users_empty' => [
|
||||||
|
static function () {
|
||||||
|
$notification = self::getErrorNotification();
|
||||||
|
$notification['userGroups'] = [];
|
||||||
|
$notification['userIds'] = [];
|
||||||
|
|
||||||
|
return $notification;
|
||||||
|
},
|
||||||
|
'InvalidArgumentException',
|
||||||
|
],
|
||||||
|
'error_users_filled' => [
|
||||||
|
static function () {
|
||||||
|
return self::getErrorNotification();;
|
||||||
|
},
|
||||||
|
'InvalidArgumentException',
|
||||||
|
],
|
||||||
|
'success_group' => [
|
||||||
|
static function () {
|
||||||
|
$notification = self::getErrorNotification();
|
||||||
|
unset($notification['userIds']);
|
||||||
|
|
||||||
|
return $notification;
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
],
|
||||||
|
'success_ids' => [
|
||||||
|
static function () {
|
||||||
|
$notification = self::getErrorNotification();
|
||||||
|
unset($notification['userGroups']);
|
||||||
|
|
||||||
|
return $notification;
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected static function getErrorNotification()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'type' => 'api.error',
|
||||||
|
'userIds' => [1],
|
||||||
|
'userGroups' => ['superadmins'],
|
||||||
|
'message' => '<a href="/admin/integration/moysklad2/edit">[Модуль МойСклад]</a>
|
||||||
|
Возникли проблемы при проверке доступов входа. Введен неверный логин/пароль, проверьте корректность введенных данных.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue