2017-06-22 00:55:08 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHP version 5.4
|
|
|
|
*
|
|
|
|
* API client store test class
|
|
|
|
*
|
|
|
|
* @category RetailCrm
|
|
|
|
* @package RetailCrm
|
|
|
|
* @author RetailCrm <integration@retailcrm.ru>
|
|
|
|
* @license https://opensource.org/licenses/MIT MIT License
|
2019-08-30 14:10:52 +03:00
|
|
|
* @link https://help.retailcrm.ru/Developers/ApiVersion5
|
2017-06-22 00:55:08 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace RetailCrm\Tests\Methods\Version5;
|
|
|
|
|
|
|
|
use RetailCrm\Test\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ApiClientStoreTest
|
|
|
|
*
|
|
|
|
* @category RetailCrm
|
|
|
|
* @package RetailCrm
|
|
|
|
* @author RetailCrm <integration@retailcrm.ru>
|
|
|
|
* @license https://opensource.org/licenses/MIT MIT License
|
2019-08-30 14:10:52 +03:00
|
|
|
* @link https://help.retailcrm.ru/Developers/ApiVersion5
|
2017-06-22 00:55:08 +03:00
|
|
|
*/
|
|
|
|
class ApiClientStoreTest extends TestCase
|
|
|
|
{
|
|
|
|
const SNAME = 'Test Store V5';
|
|
|
|
const SCODE = 'test-store-v5';
|
|
|
|
|
|
|
|
/**
|
2017-11-17 15:02:54 +03:00
|
|
|
* @group store_v5
|
2017-06-22 00:55:08 +03:00
|
|
|
*/
|
|
|
|
public function testStoreCreate()
|
|
|
|
{
|
2017-06-22 16:42:42 +03:00
|
|
|
|
|
|
|
$client = static::getApiClient();
|
2017-06-22 00:55:08 +03:00
|
|
|
|
|
|
|
$response = $client->request->storesEdit(['name' => self::SNAME, 'code' => self::SCODE]);
|
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
|
|
|
|
static::assertTrue($response->isSuccessful());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-11-17 15:02:54 +03:00
|
|
|
* @group store_v5
|
2017-06-22 00:55:08 +03:00
|
|
|
*/
|
|
|
|
public function testStoreInventories()
|
|
|
|
{
|
2017-06-22 16:42:42 +03:00
|
|
|
|
|
|
|
$client = static::getApiClient();
|
2017-06-22 00:55:08 +03:00
|
|
|
|
|
|
|
$response = $client->request->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'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-11-17 15:02:54 +03:00
|
|
|
* @group store_v5
|
2017-06-22 00:55:08 +03:00
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testInventoriesException()
|
|
|
|
{
|
2017-06-22 16:42:42 +03:00
|
|
|
|
|
|
|
$client = static::getApiClient();
|
2017-06-22 00:55:08 +03:00
|
|
|
$client->request->storeInventoriesUpload([]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-11-17 15:02:54 +03:00
|
|
|
* @group store_v5
|
2017-06-22 00:55:08 +03:00
|
|
|
*/
|
|
|
|
public function testInventoriesUpload()
|
|
|
|
{
|
2017-06-22 16:42:42 +03:00
|
|
|
|
|
|
|
$client = static::getApiClient();
|
2017-06-22 00:55:08 +03:00
|
|
|
|
|
|
|
$response = $client->request->storeInventoriesUpload([
|
|
|
|
[
|
|
|
|
'externalId' => 'pTKIKAeghYzX21HTdzFCe1',
|
|
|
|
'stores' => [
|
|
|
|
[
|
|
|
|
'code' => self::SCODE,
|
|
|
|
'available' => 10,
|
|
|
|
'purchasePrice' => 1700
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'externalId' => 'JQIvcrCtiSpOV3AAfMiQB3',
|
|
|
|
'stores' => [
|
|
|
|
[
|
|
|
|
'code' => self::SCODE,
|
|
|
|
'available' => 20,
|
|
|
|
'purchasePrice' => 1500
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertTrue($response->isSuccessful());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-11-17 15:02:54 +03:00
|
|
|
* @group store_v5
|
2017-06-22 00:55:08 +03:00
|
|
|
*/
|
|
|
|
public function testInventoriesFailed()
|
|
|
|
{
|
2017-06-22 16:42:42 +03:00
|
|
|
|
|
|
|
$client = static::getApiClient();
|
2017-06-22 00:55:08 +03:00
|
|
|
|
|
|
|
$externalIdA = 'upload-a-' . time();
|
|
|
|
$externalIdB = 'upload-b-' . time();
|
|
|
|
|
|
|
|
$response = $client->request->storeInventoriesUpload([
|
|
|
|
[
|
|
|
|
'externalId' => $externalIdA,
|
|
|
|
'available' => 10,
|
|
|
|
'purchasePrice' => 1700
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'externalId' => $externalIdB,
|
|
|
|
'available' => 20,
|
|
|
|
'purchasePrice' => 1500
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertEquals(400, $response->getStatusCode());
|
|
|
|
static::assertTrue(isset($response['errorMsg']), $response['errorMsg']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-11-17 15:02:54 +03:00
|
|
|
* @group store_v5
|
2017-06-22 00:55:08 +03:00
|
|
|
*/
|
|
|
|
public function testStoreProducts()
|
|
|
|
{
|
2017-06-22 16:42:42 +03:00
|
|
|
|
|
|
|
$client = static::getApiClient();
|
2017-06-22 00:55:08 +03:00
|
|
|
|
|
|
|
$response = $client->request->storeProducts();
|
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertEquals(200, $response->getStatusCode());
|
|
|
|
static::assertTrue($response->isSuccessful());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-11-17 15:02:54 +03:00
|
|
|
* @group store_v5
|
2017-06-22 00:55:08 +03:00
|
|
|
*/
|
|
|
|
public function testStoreProductsGroups()
|
|
|
|
{
|
2017-06-22 16:42:42 +03:00
|
|
|
|
|
|
|
$client = static::getApiClient();
|
2017-06-22 00:55:08 +03:00
|
|
|
|
|
|
|
$response = $client->request->storeProductsGroups();
|
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertEquals(200, $response->getStatusCode());
|
|
|
|
static::assertTrue($response->isSuccessful());
|
|
|
|
}
|
2017-11-17 15:02:54 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group store_v5
|
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testStoreSettingsGet()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
$client->request->storeSettingsGet(self::SCODE);
|
|
|
|
}
|
2017-06-22 00:55:08 +03:00
|
|
|
}
|