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

137 lines
3.8 KiB
PHP
Raw 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/ApiVersion4
*/
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/ApiVersion4
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));
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertTrue(in_array($response->getStatusCode(), array(200, 201)));
2016-07-22 01:01:47 +03:00
$this->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();
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode());
2016-07-22 01:01:47 +03:00
$this->assertTrue($response->isSuccessful());
$this->assertTrue(
isset($response['offers']),
'API returns orders assembly history'
);
}
/**
2016-07-22 01:01:47 +03:00
* @group store
* @expectedException \InvalidArgumentException
*/
public function testStoreInventoriesUploadExceptionEmpty()
{
$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 testStoreInventoriesUpload()
{
$client = static::getApiClient();
$externalIdA = 'upload-a-' . time();
$externalIdB = 'upload-b-' . time();
$response = $client->storeInventoriesUpload(array(
array(
'externalId' => $externalIdA,
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' => $externalIdB,
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
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertFalse($response->isSuccessful());
}
2016-07-21 16:37:41 +03:00
/**
* @group integration
*/
public function testStoreInventoriesUploadFailed()
{
$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
),
));
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(400, $response->getStatusCode());
$this->assertTrue(isset($response['errorMsg']), $response['errorMsg']);
}
}