diff --git a/lib/RetailCrm/ApiClient.php b/lib/RetailCrm/ApiClient.php index 3671e2f..6316363 100644 --- a/lib/RetailCrm/ApiClient.php +++ b/lib/RetailCrm/ApiClient.php @@ -289,6 +289,266 @@ class ApiClient )); } + /** + * Returns deliveryServices list + * + * @return ApiResponse + */ + public function deliveryServicesList() + { + return $this->client->makeRequest('/reference/delivery-services', Client::METHOD_GET); + } + + /** + * Returns deliveryTypes list + * + * @return ApiResponse + */ + public function deliveryTypesList() + { + return $this->client->makeRequest('/reference/delivery-types', Client::METHOD_GET); + } + + /** + * Returns orderMethods list + * + * @return ApiResponse + */ + public function orderMethodsList() + { + return $this->client->makeRequest('/reference/order-methods', Client::METHOD_GET); + } + + /** + * Returns orderTypes list + * + * @return ApiResponse + */ + public function orderTypesList() + { + return $this->client->makeRequest('/reference/order-types', Client::METHOD_GET); + } + + /** + * Returns paymentStatuses list + * + * @return ApiResponse + */ + public function paymentStatusesList() + { + return $this->client->makeRequest('/reference/payment-statuses', Client::METHOD_GET); + } + + /** + * Returns paymentTypes list + * + * @return ApiResponse + */ + public function paymentTypesList() + { + return $this->client->makeRequest('/reference/payment-types', Client::METHOD_GET); + } + + /** + * Returns productStatuses list + * + * @return ApiResponse + */ + public function productStatusesList() + { + return $this->client->makeRequest('/reference/product-statuses', Client::METHOD_GET); + } + + /** + * Returns statusGroups list + * + * @return ApiResponse + */ + public function statusGroupsList() + { + return $this->client->makeRequest('/reference/status-groups', Client::METHOD_GET); + } + + /** + * Returns statuses list + * + * @return ApiResponse + */ + public function statusesList() + { + return $this->client->makeRequest('/reference/statuses', Client::METHOD_GET); + } + + /** + * Edit deliveryService + * + * @return ApiResponse + */ + public function deliveryServicesEdit(array $data) + { + if (!isset($data['code'])) { + throw new \InvalidArgumentException('Data must contain "code" parameter.'); + } + + return $this->client->makeRequest( + '/reference/delivery-services/' . $data['code'] . '/edit', + Client::METHOD_POST, + array( + 'deliveryService' => json_encode($data) + ) + ); + } + + /** + * Edit deliveryType + * + * @return ApiResponse + */ + public function deliveryTypesEdit(array $data) + { + if (!isset($data['code'])) { + throw new \InvalidArgumentException('Data must contain "code" parameter.'); + } + + return $this->client->makeRequest( + '/reference/delivery-types/' . $data['code'] . '/edit', + Client::METHOD_POST, + array( + 'deliveryType' => json_encode($data) + ) + ); + } + + /** + * Edit orderMethod + * + * @return ApiResponse + */ + public function orderMethodsEdit(array $data) + { + if (!isset($data['code'])) { + throw new \InvalidArgumentException('Data must contain "code" parameter.'); + } + + return $this->client->makeRequest( + '/reference/order-methods/' . $data['code'] . '/edit', + Client::METHOD_POST, + array( + 'orderMethod' => json_encode($data) + ) + ); + } + + /** + * Edit orderType + * + * @return ApiResponse + */ + public function orderTypesEdit(array $data) + { + if (!isset($data['code'])) { + throw new \InvalidArgumentException('Data must contain "code" parameter.'); + } + + return $this->client->makeRequest( + '/reference/order-types/' . $data['code'] . '/edit', + Client::METHOD_POST, + array( + 'orderType' => json_encode($data) + ) + ); + } + + /** + * Edit paymentStatus + * + * @return ApiResponse + */ + public function paymentStatusesEdit(array $data) + { + if (!isset($data['code'])) { + throw new \InvalidArgumentException('Data must contain "code" parameter.'); + } + + return $this->client->makeRequest( + '/reference/payment-statuses/' . $data['code'] . '/edit', + Client::METHOD_POST, + array( + 'paymentStatus' => json_encode($data) + ) + ); + } + + /** + * Edit paymentType + * + * @return ApiResponse + */ + public function paymentTypesEdit(array $data) + { + if (!isset($data['code'])) { + throw new \InvalidArgumentException('Data must contain "code" parameter.'); + } + + return $this->client->makeRequest( + '/reference/payment-types/' . $data['code'] . '/edit', + Client::METHOD_POST, + array( + 'paymentType' => json_encode($data) + ) + ); + } + + /** + * Edit productStatus + * + * @return ApiResponse + */ + public function productStatusesEdit(array $data) + { + if (!isset($data['code'])) { + throw new \InvalidArgumentException('Data must contain "code" parameter.'); + } + + return $this->client->makeRequest( + '/reference/product-statuses/' . $data['code'] . '/edit', + Client::METHOD_POST, + array( + 'productStatus' => json_encode($data) + ) + ); + } + + /** + * Edit order status + * + * @return ApiResponse + */ + public function statusesEdit(array $data) + { + if (!isset($data['code'])) { + throw new \InvalidArgumentException('Data must contain "code" parameter.'); + } + + return $this->client->makeRequest( + '/reference/statuses/' . $data['code'] . '/edit', + Client::METHOD_POST, + array( + 'status' => json_encode($data) + ) + ); + } + + /** + * Update CRM basic statistic + * + * @return ApiResponse + */ + public function statisticUpdate() + { + return $this->client->makeRequest('/statistic/update', Client::METHOD_GET); + } + /** * Check ID parameter * diff --git a/tests/RetailCrm/Tests/ApiClientOrdersTest.php b/tests/RetailCrm/Tests/ApiClientOrdersTest.php index 2b50977..315663a 100644 --- a/tests/RetailCrm/Tests/ApiClientOrdersTest.php +++ b/tests/RetailCrm/Tests/ApiClientOrdersTest.php @@ -151,6 +151,10 @@ class ApiClientOrdersTest extends TestCase isset($response['orders']), 'API returns orders history' ); + $this->assertTrue( + isset($response['generatedAt']), + 'API returns generatedAt in orders history' + ); } /** diff --git a/tests/RetailCrm/Tests/ApiClientReferenceTest.php b/tests/RetailCrm/Tests/ApiClientReferenceTest.php new file mode 100644 index 0000000..95d0b72 --- /dev/null +++ b/tests/RetailCrm/Tests/ApiClientReferenceTest.php @@ -0,0 +1,98 @@ +$method(); + + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertTrue($response->isSuccessful()); + $this->assertTrue(isset($response[$name])); + $this->assertTrue(is_array($response[$name])); + } + + /** + * @group integration + * @dataProvider getEditDictionaries + * @expectedException \InvalidArgumentException + */ + public function testEditingException($name) + { + $client = static::getApiClient(); + + $method = $name . 'Edit'; + $response = $client->$method(array()); + } + + /** + * @group integration + * @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); + $this->assertEquals(201, $response->getStatusCode()); + + $response = $client->$method(array( + 'code' => $code, + 'name' => 'Bbb', + )); + if ($response->getStatusCode() > 201) { + print_r($response); + } + $this->assertEquals(200, $response->getStatusCode()); + } + + public function getListDictionaries() + { + return array( + array('deliveryServices'), + array('deliveryTypes'), + array('orderMethods'), + array('orderTypes'), + array('paymentStatuses'), + array('paymentTypes'), + array('productStatuses'), + array('statusGroups'), + array('statuses'), + ); + } + + public function getEditDictionaries() + { + return array( + array('deliveryServices'), + array('deliveryTypes'), + array('orderMethods'), + array('orderTypes'), + array('paymentStatuses'), + array('paymentTypes'), + array('productStatuses'), + array('statuses'), + ); + } +} diff --git a/tests/RetailCrm/Tests/ApiClientTest.php b/tests/RetailCrm/Tests/ApiClientTest.php index fe78cc1..38b535c 100644 --- a/tests/RetailCrm/Tests/ApiClientTest.php +++ b/tests/RetailCrm/Tests/ApiClientTest.php @@ -15,4 +15,15 @@ class ApiClientTest extends TestCase $this->assertInstanceOf('RetailCrm\ApiClient', $client); } + + /** + * @group integration + */ + public function testStatisticUpdate() + { + $client = static::getApiClient(); + + $response = $client->statisticUpdate(); + $this->assertTrue($response->isSuccessful()); + } }