prestashop-module/tests/lib/api/RetailcrmExceptionMiddlewareTest.php

79 lines
2.7 KiB
PHP
Raw Normal View History

2021-10-15 11:20:18 +03:00
<?php
class RetailcrmExceptionMiddlewareTest extends RetailcrmTestCase
{
private $api;
2021-11-03 16:19:39 +07:00
protected function setUp()
2021-10-15 11:20:18 +03:00
{
parent::setUp();
$this->api = RetailcrmTools::getApiClient();
}
public function getRequests()
{
return [
[
'method' => 'ordersGet',
'params' => [406, 'idd'],
2021-11-03 16:19:39 +07:00
'errorMsg' => 'Value "idd" for "by" param is not valid. Allowed values are externalId, id.',
2021-10-15 11:20:18 +03:00
],
[
'method' => 'ordersEdit',
'params' => [['id' => 406], 'idd'],
2021-11-03 16:19:39 +07:00
'errorMsg' => 'Value "idd" for "by" param is not valid. Allowed values are externalId, id.',
2021-10-15 11:20:18 +03:00
],
[
'method' => 'ordersEdit',
'params' => [['id' => 406], 'externalId'],
2021-11-03 16:19:39 +07:00
'errorMsg' => 'Order array must contain the "externalId" parameter.',
2021-10-15 11:20:18 +03:00
],
[
'method' => 'ordersFixExternalIds',
'params' => [[]],
2021-11-03 16:19:39 +07:00
'errorMsg' => 'Method parameter must contains at least one IDs pair',
2021-10-15 11:20:18 +03:00
],
[
'method' => 'ordersCreate',
'params' => [[]],
2021-11-03 16:19:39 +07:00
'errorMsg' => 'Parameter `order` must contains a data',
2021-10-15 11:20:18 +03:00
],
[
'method' => 'ordersUpload',
'params' => [[]],
2021-11-03 16:19:39 +07:00
'errorMsg' => 'Parameter `orders` must contains array of the orders',
2021-10-15 11:20:18 +03:00
],
[
'method' => 'ordersPaymentCreate',
'params' => [[]],
2021-11-03 16:19:39 +07:00
'errorMsg' => 'Parameter `payment` must contains a data',
2021-10-15 11:20:18 +03:00
],
[
'method' => 'ordersPaymentEdit',
'params' => [['id' => 406], 'idd'],
2021-11-03 16:19:39 +07:00
'errorMsg' => 'Value "idd" for "by" param is not valid. Allowed values are externalId, id.',
2021-10-15 11:20:18 +03:00
],
[
'method' => 'ordersPaymentEdit',
'params' => [['id' => 406], 'externalId'],
2021-11-03 16:19:39 +07:00
'errorMsg' => 'Order array must contain the "externalId" parameter.',
2021-10-15 11:20:18 +03:00
],
];
}
/**
* @dataProvider getRequests
*/
public function testRequest($method, $params, $errorMsg)
{
/** @var RetailcrmApiResponse $response */
$response = call_user_func_array([$this->api, $method], $params);
$this->assertInstanceOf(RetailcrmApiResponse::class, $response);
$this->assertFalse($response->isSuccessful());
$this->assertStringStartsWith('Internal error: ', $response['errorMsg']);
$this->assertStringEndsWith($errorMsg, $response['errorMsg']);
}
}