2014-11-06 13:48:07 +03:00
|
|
|
<?php
|
|
|
|
|
2016-07-22 01:01:47 +03:00
|
|
|
/**
|
|
|
|
* 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
|
2017-06-12 23:58:56 +03:00
|
|
|
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
2016-07-22 01:01:47 +03:00
|
|
|
*/
|
|
|
|
|
2014-11-06 13:48:07 +03:00
|
|
|
namespace RetailCrm\Tests;
|
|
|
|
|
|
|
|
use RetailCrm\Test\TestCase;
|
2017-06-12 23:58:56 +03:00
|
|
|
use function var_dump;
|
2014-11-06 13:48:07 +03:00
|
|
|
|
2016-07-22 01:01:47 +03:00
|
|
|
/**
|
|
|
|
* Class ApiClientCustomersTest
|
|
|
|
*
|
|
|
|
* @category RetailCrm
|
|
|
|
* @package RetailCrm
|
|
|
|
* @author RetailCrm <integration@retailcrm.ru>
|
|
|
|
* @license https://opensource.org/licenses/MIT MIT License
|
2017-06-12 23:58:56 +03:00
|
|
|
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
2016-07-22 01:01:47 +03:00
|
|
|
*/
|
2014-11-06 13:48:07 +03:00
|
|
|
class ApiClientCustomersTest extends TestCase
|
|
|
|
{
|
|
|
|
const FIRST_NAME = 'Иннокентий';
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group customers
|
2014-11-06 13:48:07 +03:00
|
|
|
*/
|
|
|
|
public function testCustomersCreate()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
|
|
|
$externalId = 'c-create-' . time();
|
|
|
|
|
2023-06-21 12:57:37 +03:00
|
|
|
$response = $client->request->customersCreate(array(
|
2014-11-06 13:48:07 +03:00
|
|
|
'firstName' => self::FIRST_NAME,
|
|
|
|
'externalId' => $externalId,
|
|
|
|
));
|
2017-06-12 23:58:56 +03:00
|
|
|
|
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertEquals(201, $response->getStatusCode());
|
|
|
|
static::assertTrue(is_int($response['id']));
|
2014-11-06 13:48:07 +03:00
|
|
|
|
|
|
|
return array(
|
2017-06-12 23:58:56 +03:00
|
|
|
'id' => $response['id'],
|
2014-11-06 13:48:07 +03:00
|
|
|
'externalId' => $externalId,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group customers
|
2014-11-06 13:48:07 +03:00
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
2017-06-12 23:58:56 +03:00
|
|
|
public function testCreateExceptionEmpty()
|
2014-11-06 13:48:07 +03:00
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
2023-06-21 12:57:37 +03:00
|
|
|
$client->request->customersCreate(array());
|
2014-11-06 13:48:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-06-12 23:58:56 +03:00
|
|
|
* @group customers
|
2014-11-06 13:48:07 +03:00
|
|
|
* @depends testCustomersCreate
|
2017-06-12 23:58:56 +03:00
|
|
|
*
|
|
|
|
* @param array $ids
|
|
|
|
*
|
|
|
|
* @return array
|
2014-11-06 13:48:07 +03:00
|
|
|
*/
|
|
|
|
public function testCustomersGet(array $ids)
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
2023-06-21 12:57:37 +03:00
|
|
|
$response = $client->request->customersGet(678678678);
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertEquals(404, $response->getStatusCode());
|
|
|
|
static::assertFalse($response->isSuccessful());
|
2014-11-06 13:48:07 +03:00
|
|
|
|
2023-06-21 12:57:37 +03:00
|
|
|
$response = $client->request->customersGet($ids['id'], 'id');
|
2017-06-12 23:58:56 +03:00
|
|
|
$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']);
|
2014-11-06 13:48:07 +03:00
|
|
|
|
2023-06-21 12:57:37 +03:00
|
|
|
$response = $client->request->customersGet($ids['externalId'], 'externalId');
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertEquals($customerById['id'], $response['customer']['id']);
|
2014-11-06 13:48:07 +03:00
|
|
|
|
|
|
|
return $ids;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group customers
|
2014-11-06 13:48:07 +03:00
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testCustomersGetException()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
2023-06-21 12:57:37 +03:00
|
|
|
$client->request->customersGet(678678678, 'asdf');
|
2014-11-06 13:48:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-06-12 23:58:56 +03:00
|
|
|
* @group customers
|
2014-11-06 13:48:07 +03:00
|
|
|
* @depends testCustomersGet
|
2017-06-12 23:58:56 +03:00
|
|
|
*
|
|
|
|
* @param array $ids
|
2014-11-06 13:48:07 +03:00
|
|
|
*/
|
|
|
|
public function testCustomersEdit(array $ids)
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
2023-06-21 12:57:37 +03:00
|
|
|
$response = $client->request->customersEdit(
|
2014-11-06 13:48:07 +03:00
|
|
|
array(
|
|
|
|
'id' => 22342134,
|
|
|
|
'lastName' => '12345',
|
|
|
|
),
|
|
|
|
'id'
|
|
|
|
);
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertEquals(404, $response->getStatusCode());
|
2014-11-06 13:48:07 +03:00
|
|
|
|
2023-06-21 12:57:37 +03:00
|
|
|
$response = $client->request->customersEdit(array(
|
2014-11-06 13:48:07 +03:00
|
|
|
'externalId' => $ids['externalId'],
|
|
|
|
'lastName' => '12345',
|
|
|
|
));
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertEquals(200, $response->getStatusCode());
|
|
|
|
static::assertTrue($response->isSuccessful());
|
2014-11-06 13:48:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group customers
|
2014-11-06 13:48:07 +03:00
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testCustomersEditExceptionEmpty()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
2023-06-21 12:57:37 +03:00
|
|
|
$client->request->customersEdit(array(), 'asdf');
|
2014-11-06 13:48:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group customers
|
2014-11-06 13:48:07 +03:00
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testCustomersEditException()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
2023-06-21 12:57:37 +03:00
|
|
|
$client->request->customersEdit(array('id' => 678678678), 'asdf');
|
2014-11-06 13:48:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group customers
|
2014-11-06 13:48:07 +03:00
|
|
|
*/
|
|
|
|
public function testCustomersList()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
2023-06-21 12:57:37 +03:00
|
|
|
$response = $client->request->customersList();
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertTrue($response->isSuccessful());
|
|
|
|
static::assertTrue(isset($response['customers']));
|
2014-11-06 13:48:07 +03:00
|
|
|
|
2023-06-21 12:57:37 +03:00
|
|
|
$response = $client->request->customersList(array(), 1, 300);
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertFalse(
|
2014-11-06 13:48:07 +03:00
|
|
|
$response->isSuccessful(),
|
|
|
|
'Pagination error'
|
|
|
|
);
|
|
|
|
|
2023-06-21 12:57:37 +03:00
|
|
|
$response = $client->request->customersList(array('maxOrdersCount' => 10), 1);
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertTrue(
|
2014-11-06 13:48:07 +03:00
|
|
|
$response->isSuccessful(),
|
|
|
|
'API returns customers list'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group customers
|
2014-11-06 13:48:07 +03:00
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testCustomersFixExternalIdsException()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
2023-06-21 12:57:37 +03:00
|
|
|
$client->request->customersFixExternalIds(array());
|
2014-11-06 13:48:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group customers
|
2014-11-06 13:48:07 +03:00
|
|
|
*/
|
|
|
|
public function testCustomersFixExternalIds()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
2023-06-21 12:57:37 +03:00
|
|
|
$response = $client->request->ordersCreate(array(
|
2014-11-06 13:48:07 +03:00
|
|
|
'firstName' => 'Aaa111',
|
|
|
|
));
|
2017-06-12 23:58:56 +03:00
|
|
|
|
|
|
|
static::assertTrue(
|
2014-11-06 13:48:07 +03:00
|
|
|
$response->isSuccessful(),
|
|
|
|
'Order created'
|
|
|
|
);
|
|
|
|
|
2023-06-21 12:57:37 +03:00
|
|
|
$response = $client->request->ordersGet($response['id'], 'id');
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertTrue(
|
2014-11-06 13:48:07 +03:00
|
|
|
$response->isSuccessful(),
|
|
|
|
'Order fetched'
|
|
|
|
);
|
|
|
|
|
2017-06-12 23:58:56 +03:00
|
|
|
$id = $response['order']['customer']['id'];
|
2014-11-06 13:48:07 +03:00
|
|
|
$externalId = 'asdf' . time();
|
|
|
|
|
2023-06-21 12:57:37 +03:00
|
|
|
$response = $client->request->customersFixExternalIds(array(
|
2014-11-06 13:48:07 +03:00
|
|
|
array('id' => $id, 'externalId' => $externalId)
|
|
|
|
));
|
|
|
|
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertTrue(
|
2014-11-06 13:48:07 +03:00
|
|
|
$response->isSuccessful(),
|
|
|
|
'Fixed customer ids'
|
|
|
|
);
|
|
|
|
|
2023-06-21 12:57:37 +03:00
|
|
|
$response = $client->request->customersGet($externalId);
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertTrue(
|
2014-11-06 13:48:07 +03:00
|
|
|
$response->isSuccessful(),
|
|
|
|
'Got customer'
|
|
|
|
);
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertEquals(
|
2014-11-06 13:48:07 +03:00
|
|
|
$id,
|
2017-06-12 23:58:56 +03:00
|
|
|
$response['customer']['id'],
|
2014-11-06 13:48:07 +03:00
|
|
|
'Fixing of customer ids were right'
|
|
|
|
);
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertEquals(
|
2014-11-06 13:48:07 +03:00
|
|
|
$externalId,
|
2017-06-12 23:58:56 +03:00
|
|
|
$response['customer']['externalId'],
|
2014-11-06 13:48:07 +03:00
|
|
|
'Fixing of customer ids were right'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group customers
|
2014-11-06 13:48:07 +03:00
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testCustomersUploadExceptionEmpty()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
2023-06-21 12:57:37 +03:00
|
|
|
$client->request->customersUpload(array());
|
2014-11-06 13:48:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group customers
|
2014-11-06 13:48:07 +03:00
|
|
|
*/
|
|
|
|
public function testCustomersUpload()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
|
|
|
$externalIdA = 'upload-a-' . time();
|
|
|
|
$externalIdB = 'upload-b-' . time();
|
|
|
|
|
2023-06-21 12:57:37 +03:00
|
|
|
$response = $client->request->customersUpload(array(
|
2014-11-06 13:48:07 +03:00
|
|
|
array(
|
|
|
|
'externalId' => $externalIdA,
|
|
|
|
'firstName' => 'Aaa',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'externalId' => $externalIdB,
|
|
|
|
'lastName' => 'Bbb',
|
|
|
|
),
|
|
|
|
));
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertTrue(
|
2014-11-06 13:48:07 +03:00
|
|
|
$response->isSuccessful(),
|
|
|
|
'Got customer'
|
|
|
|
);
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertEquals(
|
2014-11-06 13:48:07 +03:00
|
|
|
$externalIdA,
|
2017-06-12 23:58:56 +03:00
|
|
|
$response['uploadedCustomers'][0]['externalId']
|
2014-11-06 13:48:07 +03:00
|
|
|
);
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertEquals(
|
2014-11-06 13:48:07 +03:00
|
|
|
$externalIdB,
|
2017-06-12 23:58:56 +03:00
|
|
|
$response['uploadedCustomers'][1]['externalId']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group customers
|
|
|
|
*/
|
|
|
|
public function testCustomersCombine()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
2023-06-21 12:57:37 +03:00
|
|
|
$responseCreateFirst = $client->request->customersCreate(array(
|
2017-06-12 23:58:56 +03:00
|
|
|
'firstName' => 'Aaa111',
|
|
|
|
'externalId' => 'AA-' . time(),
|
|
|
|
'phones' => array(
|
|
|
|
array(
|
|
|
|
'number' => '+79999999990'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
static::assertTrue(
|
|
|
|
$responseCreateFirst->isSuccessful(),
|
|
|
|
'Got customer'
|
|
|
|
);
|
|
|
|
|
2023-06-21 12:57:37 +03:00
|
|
|
$responseCreateSecond = $client->request->customersCreate(array(
|
2017-06-12 23:58:56 +03:00
|
|
|
'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']);
|
|
|
|
|
2023-06-21 12:57:37 +03:00
|
|
|
$response = $client->request->customersCombine($customers, $resultCustomer);
|
2017-06-12 23:58:56 +03:00
|
|
|
|
|
|
|
static::assertTrue(
|
|
|
|
$response->isSuccessful(),
|
|
|
|
'Customers combined'
|
2014-11-06 13:48:07 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|