1
0
mirror of synced 2024-11-25 23:06:07 +03:00
api-client-php/tests/RetailCrm/Tests/ApiClientStoreTest.php

160 lines
4.4 KiB
PHP
Raw Permalink Normal View History

<?php
2016-07-22 01:01:47 +03:00
/**
* 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
2016-07-22 01:01:47 +03:00
*/
namespace RetailCrm\Tests;
use RetailCrm\Test\TestCase;
2016-03-12 01:54:33 +03:00
/**
* Class ApiClientStoreTest
2016-07-22 01:01:47 +03:00
*
* @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
2016-03-12 01:54:33 +03:00
*/
class ApiClientStoreTest extends TestCase
{
2016-07-21 16:37:41 +03:00
const SNAME = 'Test Store';
const SCODE = 'test-store';
/**
2016-07-22 01:01:47 +03:00
* @group store
2016-07-21 16:37:41 +03:00
*/
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());
2016-07-21 16:37:41 +03:00
}
/**
2016-07-22 01:01:47 +03:00
* @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'
);
}
/**
2016-07-22 01:01:47 +03:00
* @group store
* @expectedException \InvalidArgumentException
*/
public function testInventoriesException()
{
$client = static::getApiClient();
2016-03-12 01:54:33 +03:00
$client->storeInventoriesUpload(array());
}
/**
2016-07-22 01:01:47 +03:00
* @group store
*/
public function testInventoriesUpload()
{
$client = static::getApiClient();
$response = $client->storeInventoriesUpload(array(
array(
'externalId' => 'pTKIKAeghYzX21HTdzFCe1',
2016-03-12 01:54:33 +03:00
'stores' => array(
array(
2016-07-21 16:37:41 +03:00
'code' => self::SCODE,
2016-03-12 01:54:33 +03:00
'available' => 10,
'purchasePrice' => 1700
)
)
),
array(
'externalId' => 'JQIvcrCtiSpOV3AAfMiQB3',
2016-03-12 01:54:33 +03:00
'stores' => array(
array(
2016-07-21 16:37:41 +03:00
'code' => self::SCODE,
2016-03-12 01:54:33 +03:00
'available' => 20,
'purchasePrice' => 1500
)
)
),
));
2016-07-21 16:37:41 +03:00
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue($response->isSuccessful());
}
2016-07-21 16:37:41 +03:00
/**
* @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());
}
}