PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/phpunit/ProductAPIUnitTest.php

https://github.com/octolab/Ecwid
PHP | 213 lines | 190 code | 3 blank | 20 comment | 4 complexity | e9b6187cdbbee6a7d837ec74920ef16b MD5 | raw file
  1. <?php
  2. /**
  3. * @author Samigullin Kamil <feedback@kamilsk.com>
  4. * @link http://www.kamilsk.com/
  5. */
  6. namespace Ecwid\tests\phpunit;
  7. use Ecwid\api\ProductAPI,
  8. Ecwid\api\BatchBuilder,
  9. \Exception;
  10. require 'UnitTest.php';
  11. /**
  12. * @package Ecwid.tests.phpunit
  13. * @since 1.0
  14. */
  15. class ProductAPIUnitTest extends UnitTest
  16. {
  17. /**
  18. * Test categories fetching.
  19. */
  20. public function testGetCategories()
  21. {
  22. $product_api = new ProductAPI();
  23. $response = $product_api->getCategories();
  24. $this->assertNotEmpty($response);
  25. $this->assertTrue(is_string($response));
  26. $response = $product_api->getCategories(0);
  27. $this->assertNotEmpty($response);
  28. $this->assertTrue(is_string($response));
  29. $response = $product_api->getCategories(1002);
  30. $this->assertNotEmpty($response);
  31. $this->assertTrue(is_string($response));
  32. try {
  33. $response = $product_api->getCategories('1002');
  34. var_dump($response);
  35. } catch (Exception $e) {
  36. try {
  37. $response = $product_api->getCategories(-1002);
  38. var_dump($response);
  39. } catch (Exception $e) {
  40. return;
  41. }
  42. }
  43. $this->fail("Exception for ProductAPI::getCategories() wasn't triggered.");
  44. }
  45. /**
  46. * Test category fetching.
  47. */
  48. public function testGetCategory()
  49. {
  50. $product_api = new ProductAPI();
  51. $response = $product_api->getCategory(1002);
  52. $this->assertNotEmpty($response);
  53. $this->assertTrue(is_string($response));
  54. try {
  55. $response = $product_api->getCategory('1002');
  56. var_dump($response);
  57. } catch (Exception $e) {
  58. try {
  59. $response = $product_api->getCategory(-1002);
  60. var_dump($response);
  61. } catch (Exception $e) {
  62. return;
  63. }
  64. }
  65. $this->fail("Exception for ProductAPI::getCategory() wasn't triggered.");
  66. }
  67. /**
  68. * Test products fetching.
  69. */
  70. public function testGetProducts()
  71. {
  72. $product_api = new ProductAPI();
  73. $response = $product_api->getProducts();
  74. $this->assertNotEmpty($response);
  75. $this->assertTrue(is_string($response));
  76. $response = $product_api->getProducts(0);
  77. $this->assertNotEmpty($response);
  78. $this->assertTrue(is_string($response));
  79. $response = $product_api->getProducts(1002);
  80. $this->assertNotEmpty($response);
  81. $this->assertTrue(is_string($response));
  82. try {
  83. $response = $product_api->getProducts('1002');
  84. var_dump($response);
  85. } catch (Exception $e) {
  86. try {
  87. $response = $product_api->getProducts(-1002);
  88. var_dump($response);
  89. } catch (Exception $e) {
  90. return;
  91. }
  92. }
  93. $this->fail("Exception for ProductAPI::getProducts() wasn't triggered.");
  94. }
  95. /**
  96. * Test product fetching.
  97. */
  98. public function testGetProduct()
  99. {
  100. $product_api = new ProductAPI();
  101. $response = $product_api->getProduct(4006);
  102. $this->assertNotEmpty($response);
  103. $this->assertTrue(is_string($response));
  104. try {
  105. $response = $product_api->getProduct('4006');
  106. var_dump($response);
  107. } catch (Exception $e) {
  108. try {
  109. $response = $product_api->getProduct(-4006);
  110. var_dump($response);
  111. } catch (Exception $e) {
  112. return;
  113. }
  114. }
  115. $this->fail("Exception for ProductAPI::getProduct() wasn't triggered.");
  116. }
  117. /**
  118. * Test random products fetching.
  119. */
  120. public function testGetRandomProducts()
  121. {
  122. $product_api = new ProductAPI();
  123. $response = $product_api->getRandomProducts(5);
  124. $this->assertNotEmpty($response);
  125. $this->assertTrue(is_string($response));
  126. try {
  127. $response = $product_api->getRandomProducts('5');
  128. var_dump($response);
  129. } catch (Exception $e) {
  130. try {
  131. $response = $product_api->getRandomProducts(-5);
  132. var_dump($response);
  133. } catch (Exception $e) {
  134. return;
  135. }
  136. }
  137. $this->fail("Exception for ProductAPI::getRandomProducts() wasn't triggered.");
  138. }
  139. /**
  140. * Test classes fetching.
  141. */
  142. public function testGetClasses()
  143. {
  144. $product_api = new ProductAPI();
  145. $response = $product_api->getClasses();
  146. $this->assertNotEmpty($response);
  147. $this->assertTrue(is_string($response));
  148. }
  149. /**
  150. * Test class fetching.
  151. */
  152. public function testGetClass()
  153. {
  154. $product_api = new ProductAPI();
  155. $response = $product_api->getClass(0);
  156. $this->assertNotEmpty($response);
  157. $this->assertTrue(is_string($response));
  158. try {
  159. $response = $product_api->getClass('0');
  160. var_dump($response);
  161. } catch (Exception $e) {
  162. return;
  163. }
  164. $this->fail("Exception for ProductAPI::getClass() wasn't triggered.");
  165. }
  166. /**
  167. * Test profile fetching.
  168. */
  169. public function testGetProfile()
  170. {
  171. $product_api = new ProductAPI();
  172. $response = $product_api->getProfile();
  173. $this->assertNotEmpty($response);
  174. $this->assertTrue(is_string($response));
  175. try {
  176. $product_api->setStoreId(1002);
  177. $response = $product_api->getProfile();
  178. var_dump($response);
  179. } catch (Exception $e) {
  180. return;
  181. }
  182. $this->fail("Exception for ProductAPI::getProfile() wasn't triggered.");
  183. }
  184. /**
  185. * Test run batch.
  186. */
  187. public function testRunBatch()
  188. {
  189. $product_api = new ProductAPI();
  190. $batch = new BatchBuilder($product_api);
  191. $response = $batch->getCategories('categories')->run();
  192. $this->assertNotEmpty($response);
  193. $this->assertTrue(is_string($response));
  194. $response = $batch->getCategories('categories')->getProducts('products')->run();
  195. $this->assertNotEmpty($response);
  196. $this->assertTrue(is_string($response));
  197. try {
  198. $response = $batch->run();
  199. var_dump($response);
  200. } catch (Exception $e) {
  201. return;
  202. }
  203. $this->fail("Exception for ProductAPI::runBatch() wasn't triggered.");
  204. }
  205. }