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

331 lines
9.4 KiB
PHP
Raw Normal View History

2014-11-06 13:48:07 +03:00
<?php
2016-07-22 01:01:47 +03:00
/**
* PHP version 5.3
*
* API client orders 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
*/
2014-11-06 13:48:07 +03:00
namespace RetailCrm\Tests;
use RetailCrm\Test\TestCase;
2016-07-22 01:01:47 +03:00
/**
* Class ApiClientOrdersTest
*
* @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
*/
2014-11-06 13:48:07 +03:00
class ApiClientOrdersTest extends TestCase
{
const FIRST_NAME = 'Иннокентий';
/**
2016-07-22 01:01:47 +03:00
* @group orders
2014-11-06 13:48:07 +03:00
*/
public function testOrdersCreate()
{
$client = static::getApiClient();
$externalId = 'o-create-' . time();
$response = $client->ordersCreate(array(
'firstName' => self::FIRST_NAME,
'externalId' => $externalId,
));
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(201, $response->getStatusCode());
$this->assertTrue(is_int($response->getId()));
return array(
'id' => $response->getId(),
'externalId' => $externalId,
);
}
/**
2016-07-22 01:01:47 +03:00
* @group orders
2014-11-06 13:48:07 +03:00
* @expectedException \InvalidArgumentException
*/
public function testOrdersCreateExceptionEmpty()
{
$client = static::getApiClient();
$response = $client->ordersCreate(array());
}
2014-11-13 09:37:53 +03:00
/**
2016-07-22 01:01:47 +03:00
* @group orders
2014-11-13 09:37:53 +03:00
* @depends testOrdersCreate
*/
public function testOrdersStatuses(array $ids)
{
$client = static::getApiClient();
$response = $client->ordersStatuses();
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(400, $response->getStatusCode());
2016-07-22 01:01:47 +03:00
$this->assertFalse($response->isSuccessful());
2014-11-13 09:37:53 +03:00
$response = $client->ordersStatuses(array(), array('asdf'));
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode());
2016-07-22 01:01:47 +03:00
$this->assertTrue($response->isSuccessful());
2014-11-13 09:37:53 +03:00
$orders = $response->orders;
$this->assertEquals(0, sizeof($orders));
$response = $client->ordersStatuses(array(), array($ids['externalId']));
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode());
2016-07-22 01:01:47 +03:00
$this->assertTrue($response->isSuccessful());
2014-11-13 09:37:53 +03:00
$orders = $response->orders;
$this->assertEquals(1, sizeof($orders));
$this->assertEquals('new', $orders[0]['status']);
$response = $client->ordersStatuses(array($ids['id']), array($ids['externalId']));
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode());
2016-07-22 01:01:47 +03:00
$this->assertTrue($response->isSuccessful());
2014-11-13 09:37:53 +03:00
$orders = $response->orders;
$this->assertEquals(1, sizeof($orders));
$response = $client->ordersStatuses(array($ids['id']));
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode());
2016-07-22 01:01:47 +03:00
$this->assertTrue($response->isSuccessful());
2014-11-13 09:37:53 +03:00
$orders = $response->orders;
$this->assertEquals(1, sizeof($orders));
}
2014-11-06 13:48:07 +03:00
/**
2016-07-22 01:01:47 +03:00
* @group orders
2014-11-06 13:48:07 +03:00
* @depends testOrdersCreate
*/
public function testOrdersGet(array $ids)
{
$client = static::getApiClient();
$response = $client->ordersGet(678678678);
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(404, $response->getStatusCode());
2016-07-22 01:01:47 +03:00
$this->assertFalse($response->isSuccessful());
2014-11-06 13:48:07 +03:00
$response = $client->ordersGet($ids['id'], 'id');
$orderById = $response->order;
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode());
2016-07-22 01:01:47 +03:00
$this->assertTrue($response->isSuccessful());
2014-11-06 13:48:07 +03:00
$this->assertEquals(self::FIRST_NAME, $response->order['firstName']);
$response = $client->ordersGet($ids['externalId'], 'externalId');
$this->assertEquals($orderById['id'], $response->order['id']);
return $ids;
}
/**
2016-07-22 01:01:47 +03:00
* @group orders
2014-11-06 13:48:07 +03:00
* @expectedException \InvalidArgumentException
*/
public function testOrdersGetException()
{
$client = static::getApiClient();
$response = $client->ordersGet(678678678, 'asdf');
}
/**
2016-07-22 01:01:47 +03:00
* @group orders
2014-11-06 13:48:07 +03:00
* @depends testOrdersGet
*/
public function testOrdersEdit(array $ids)
{
$client = static::getApiClient();
$response = $client->ordersEdit(
array(
'id' => 22342134,
'lastName' => '12345',
),
'id'
);
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(404, $response->getStatusCode());
$response = $client->ordersEdit(array(
'externalId' => $ids['externalId'],
'lastName' => '12345',
));
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode());
2016-07-22 01:01:47 +03:00
$this->assertTrue($response->isSuccessful());
2014-11-06 13:48:07 +03:00
}
/**
2016-07-22 01:01:47 +03:00
* @group orders
2014-11-06 13:48:07 +03:00
* @expectedException \InvalidArgumentException
*/
public function testOrdersEditExceptionEmpty()
{
$client = static::getApiClient();
$response = $client->ordersEdit(array(), 'asdf');
}
/**
2016-07-22 01:01:47 +03:00
* @group orders
2014-11-06 13:48:07 +03:00
* @expectedException \InvalidArgumentException
*/
public function testOrdersEditException()
{
$client = static::getApiClient();
$response = $client->ordersEdit(array('id' => 678678678), 'asdf');
}
/**
2016-07-22 01:01:47 +03:00
* @group orders
2014-11-06 13:48:07 +03:00
*/
public function testOrdersHistory()
{
$client = static::getApiClient();
$response = $client->ordersHistory();
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode());
2016-07-22 01:01:47 +03:00
$this->assertTrue($response->isSuccessful());
2014-11-06 13:48:07 +03:00
}
/**
2016-07-22 01:01:47 +03:00
* @group orders
2014-11-06 13:48:07 +03:00
*/
public function testOrdersList()
{
$client = static::getApiClient();
$response = $client->ordersList();
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertTrue($response->isSuccessful());
$this->assertTrue(isset($response['orders']));
$response = $client->ordersList(array(), 1, 300);
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertFalse(
$response->isSuccessful(),
'Pagination error'
);
$response = $client->ordersList(array('paymentStatus' => 'paid'), 1);
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
}
/**
2016-07-22 01:01:47 +03:00
* @group orders
2014-11-06 13:48:07 +03:00
* @expectedException \InvalidArgumentException
*/
public function testOrdersFixExternalIdsException()
{
$client = static::getApiClient();
$response = $client->ordersFixExternalIds(array());
}
/**
2016-07-22 01:01:47 +03:00
* @group orders
2017-06-12 01:23:48 +03:00
*/
2014-11-06 13:48:07 +03:00
public function testOrdersFixExternalIds()
{
$client = static::getApiClient();
$response = $client->ordersCreate(array(
'firstName' => 'Aaa',
));
$this->assertTrue(
$response->isSuccessful(),
'Order created'
);
$id = $response->id;
$externalId = 'asdf' . time();
$response = $client->ordersFixExternalIds(array(
array('id' => $id, 'externalId' => $externalId)
));
$this->assertTrue(
$response->isSuccessful(),
'Fixed order ids'
);
$response = $client->ordersGet($externalId);
$this->assertTrue(
$response->isSuccessful(),
'Got order'
);
$this->assertEquals(
$id,
$response->order['id'],
'Fixing of order ids were right'
);
$this->assertEquals(
$externalId,
$response->order['externalId'],
'Fixing of order ids were right'
);
}
/**
2016-07-22 01:01:47 +03:00
* @group orders
2014-11-06 13:48:07 +03:00
* @expectedException \InvalidArgumentException
*/
public function testOrdersUploadExceptionEmpty()
{
$client = static::getApiClient();
$response = $client->ordersUpload(array());
}
/**
2016-07-22 01:01:47 +03:00
* @group orders
2014-11-06 13:48:07 +03:00
*/
public function testOrdersUpload()
{
$client = static::getApiClient();
$externalIdA = 'upload-a-' . time();
$externalIdB = 'upload-b-' . time();
$response = $client->ordersUpload(array(
array(
'externalId' => $externalIdA,
'firstName' => 'Aaa',
),
array(
'externalId' => $externalIdB,
'lastName' => 'Bbb',
),
));
$this->assertTrue(
$response->isSuccessful(),
'Got order'
);
$this->assertEquals(
$externalIdA,
$response->uploadedOrders[0]['externalId']
);
$this->assertEquals(
$externalIdB,
$response->uploadedOrders[1]['externalId']
);
}
}