2014-11-06 16:39:55 +03:00
|
|
|
<?php
|
|
|
|
|
2016-07-22 01:01:47 +03:00
|
|
|
/**
|
|
|
|
* PHP version 5.3
|
|
|
|
*
|
|
|
|
* API client references 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 16:39:55 +03:00
|
|
|
namespace RetailCrm\Tests;
|
|
|
|
|
|
|
|
use RetailCrm\Test\TestCase;
|
|
|
|
|
2016-07-22 01:01:47 +03:00
|
|
|
/**
|
|
|
|
* Class ApiClientReferenceTest
|
|
|
|
*
|
|
|
|
* @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 16:39:55 +03:00
|
|
|
class ApiClientReferenceTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group reference
|
2014-11-06 16:39:55 +03:00
|
|
|
* @dataProvider getListDictionaries
|
2015-04-30 17:35:57 +03:00
|
|
|
* @param $name
|
2014-11-06 16:39:55 +03:00
|
|
|
*/
|
|
|
|
public function testList($name)
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
|
|
|
$method = $name . 'List';
|
|
|
|
$response = $client->$method();
|
|
|
|
|
|
|
|
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
$this->assertTrue($response->isSuccessful());
|
|
|
|
$this->assertTrue(isset($response[$name]));
|
|
|
|
$this->assertTrue(is_array($response[$name]));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group reference
|
2014-11-06 16:39:55 +03:00
|
|
|
* @dataProvider getEditDictionaries
|
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testEditingException($name)
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
|
|
|
$method = $name . 'Edit';
|
|
|
|
$response = $client->$method(array());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group reference
|
2014-11-06 16:39:55 +03:00
|
|
|
* @dataProvider getEditDictionaries
|
|
|
|
*/
|
|
|
|
public function testEditing($name)
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
|
|
|
$code = 'dict-' . strtolower($name) . '-' . time();
|
|
|
|
$method = $name . 'Edit';
|
|
|
|
$params = array(
|
|
|
|
'code' => $code,
|
|
|
|
'name' => 'Aaa',
|
|
|
|
);
|
|
|
|
if ($name == 'statuses') {
|
|
|
|
$params['group'] = 'new';
|
|
|
|
}
|
|
|
|
|
|
|
|
$response = $client->$method($params);
|
2016-11-28 14:38:03 +03:00
|
|
|
$this->assertTrue(in_array($response->getStatusCode(), array(200, 201)));
|
2014-11-06 16:39:55 +03:00
|
|
|
|
|
|
|
$response = $client->$method(array(
|
|
|
|
'code' => $code,
|
|
|
|
'name' => 'Bbb',
|
|
|
|
));
|
2016-11-28 14:38:03 +03:00
|
|
|
|
|
|
|
$this->assertTrue(in_array($response->getStatusCode(), array(200, 201)));
|
2014-11-06 16:39:55 +03:00
|
|
|
}
|
|
|
|
|
2014-11-27 11:23:44 +03:00
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group reference
|
2014-11-27 11:23:44 +03:00
|
|
|
* @group site
|
|
|
|
*/
|
|
|
|
public function testSiteEditing()
|
|
|
|
{
|
|
|
|
$name = 'sites';
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
|
|
|
$code = 'dict-' . strtolower($name) . '-' . time();
|
|
|
|
$method = $name . 'Edit';
|
|
|
|
$params = array(
|
|
|
|
'code' => $code,
|
|
|
|
'name' => 'Aaa',
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $client->$method($params);
|
|
|
|
$this->assertEquals(400, $response->getStatusCode());
|
|
|
|
|
|
|
|
if ($code = $client->getSite()) {
|
|
|
|
$method = $name . 'Edit';
|
|
|
|
$params = array(
|
|
|
|
'code' => $code,
|
|
|
|
'name' => 'Aaa' . time(),
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $client->$method($params);
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-06 16:39:55 +03:00
|
|
|
public function getListDictionaries()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('deliveryServices'),
|
|
|
|
array('deliveryTypes'),
|
|
|
|
array('orderMethods'),
|
|
|
|
array('orderTypes'),
|
|
|
|
array('paymentStatuses'),
|
|
|
|
array('paymentTypes'),
|
|
|
|
array('productStatuses'),
|
|
|
|
array('statusGroups'),
|
|
|
|
array('statuses'),
|
2014-11-27 11:23:44 +03:00
|
|
|
array('sites'),
|
2014-11-06 16:39:55 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEditDictionaries()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('deliveryServices'),
|
|
|
|
array('deliveryTypes'),
|
|
|
|
array('orderMethods'),
|
|
|
|
array('orderTypes'),
|
|
|
|
array('paymentStatuses'),
|
|
|
|
array('paymentTypes'),
|
|
|
|
array('productStatuses'),
|
|
|
|
array('statuses'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|