1
0
mirror of synced 2024-11-22 21:36:06 +03:00
api-client-php/tests/RetailCrm/Tests/ApiClientPacksTest.php

147 lines
4.0 KiB
PHP
Raw Normal View History

2016-01-09 15:24:12 +03:00
<?php
2016-04-14 23:11:51 +03:00
/**
* 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/ApiVersion3
*/
2016-01-09 15:24:12 +03:00
namespace RetailCrm\Tests;
use RetailCrm\Test\TestCase;
2016-04-14 23:11:51 +03:00
/**
* 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/ApiVersion3
*/
2016-01-09 15:24:12 +03:00
class ApiClientPacksTest extends TestCase
{
2016-04-14 23:11:51 +03:00
private $_packId;
/**
* ApiClientPacksTest constructor.
*
* @param null|string $name name
* @param array $data data
* @param string $dataName dataName
*/
public function __construct($name = null, array $data = array(), $dataName = '')
{
parent::__construct($name, $data, $dataName);
$this->_packId = __DIR__ . '/../../../pack.tmp';
}
2016-01-09 15:24:12 +03:00
/**
2016-04-14 23:11:51 +03:00
* Test packs history
*
* @group integration
* @return void
2016-01-09 15:24:12 +03:00
*/
public function testOrdersPacksHistory()
{
$client = static::getApiClient();
$response = $client->ordersPacksHistory();
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->success);
$this->assertTrue(
isset($response['history']),
'API returns orders assembly history'
);
$this->assertTrue(
isset($response['generatedAt']),
'API returns generatedAt in orders assembly history'
);
}
2016-03-12 01:54:33 +03:00
/**
2016-04-14 23:11:51 +03:00
* Test packs create
*
* @group integration
* @return void
2016-03-12 01:54:33 +03:00
*/
public function testOrdersPacksCreate()
{
$client = static::getApiClient();
$pack = array(
'itemId' => $_SERVER['CRM_PACK_ITEM'],
'quantity' => $_SERVER['CRM_PACK_QUANTITY'],
'store' => $_SERVER['CRM_STORE']
);
$response = $client->ordersPacksCreate($pack);
2016-04-14 23:11:51 +03:00
file_put_contents($this->_packId, $response["id"]);
2016-03-12 01:54:33 +03:00
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(201, $response->getStatusCode());
$this->assertTrue($response->success);
}
/**
2016-04-14 23:11:51 +03:00
* Test packs failed create
*
* @group integration
* @return void
2016-03-12 01:54:33 +03:00
*/
public function testOrdersPacksCreateFailed()
{
$client = static::getApiClient();
$pack = array(
'itemId' => 12,
'store' => $_SERVER['CRM_STORE'],
'quantity' => 2
);
$response = $client->ordersPacksCreate($pack);
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(400, $response->getStatusCode());
$this->assertFalse($response->success);
}
/**
2016-04-14 23:11:51 +03:00
* Test packs get
*
* @group integration
* @return void
2016-03-12 01:54:33 +03:00
*/
public function testOrdersPacksGet()
{
$client = static::getApiClient();
2016-04-14 23:11:51 +03:00
$packId = file_get_contents($this->_packId);
$response = $client->ordersPacksGet($packId);
2016-03-12 01:54:33 +03:00
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->success);
}
/**
2016-04-14 23:11:51 +03:00
* Test packs delete
*
* @group integration
* @return void
2016-03-12 01:54:33 +03:00
*/
public function testOrdersPacksDelete()
{
$client = static::getApiClient();
2016-04-14 23:11:51 +03:00
$packId = file_get_contents($this->_packId);
$response = $client->ordersPacksDelete($packId);
2016-03-12 01:54:33 +03:00
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->success);
2016-04-14 23:11:51 +03:00
unlink($this->_packId);
2016-03-12 01:54:33 +03:00
}
}