/tests/phpunit/ProductAPIUnitTest.php
PHP | 213 lines | 190 code | 3 blank | 20 comment | 4 complexity | e9b6187cdbbee6a7d837ec74920ef16b MD5 | raw file
- <?php
- /**
- * @author Samigullin Kamil <feedback@kamilsk.com>
- * @link http://www.kamilsk.com/
- */
- namespace Ecwid\tests\phpunit;
- use Ecwid\api\ProductAPI,
- Ecwid\api\BatchBuilder,
- \Exception;
- require 'UnitTest.php';
- /**
- * @package Ecwid.tests.phpunit
- * @since 1.0
- */
- class ProductAPIUnitTest extends UnitTest
- {
- /**
- * Test categories fetching.
- */
- public function testGetCategories()
- {
- $product_api = new ProductAPI();
- $response = $product_api->getCategories();
- $this->assertNotEmpty($response);
- $this->assertTrue(is_string($response));
- $response = $product_api->getCategories(0);
- $this->assertNotEmpty($response);
- $this->assertTrue(is_string($response));
- $response = $product_api->getCategories(1002);
- $this->assertNotEmpty($response);
- $this->assertTrue(is_string($response));
- try {
- $response = $product_api->getCategories('1002');
- var_dump($response);
- } catch (Exception $e) {
- try {
- $response = $product_api->getCategories(-1002);
- var_dump($response);
- } catch (Exception $e) {
- return;
- }
- }
- $this->fail("Exception for ProductAPI::getCategories() wasn't triggered.");
- }
- /**
- * Test category fetching.
- */
- public function testGetCategory()
- {
- $product_api = new ProductAPI();
- $response = $product_api->getCategory(1002);
- $this->assertNotEmpty($response);
- $this->assertTrue(is_string($response));
- try {
- $response = $product_api->getCategory('1002');
- var_dump($response);
- } catch (Exception $e) {
- try {
- $response = $product_api->getCategory(-1002);
- var_dump($response);
- } catch (Exception $e) {
- return;
- }
- }
- $this->fail("Exception for ProductAPI::getCategory() wasn't triggered.");
- }
- /**
- * Test products fetching.
- */
- public function testGetProducts()
- {
- $product_api = new ProductAPI();
- $response = $product_api->getProducts();
- $this->assertNotEmpty($response);
- $this->assertTrue(is_string($response));
- $response = $product_api->getProducts(0);
- $this->assertNotEmpty($response);
- $this->assertTrue(is_string($response));
- $response = $product_api->getProducts(1002);
- $this->assertNotEmpty($response);
- $this->assertTrue(is_string($response));
- try {
- $response = $product_api->getProducts('1002');
- var_dump($response);
- } catch (Exception $e) {
- try {
- $response = $product_api->getProducts(-1002);
- var_dump($response);
- } catch (Exception $e) {
- return;
- }
- }
- $this->fail("Exception for ProductAPI::getProducts() wasn't triggered.");
- }
- /**
- * Test product fetching.
- */
- public function testGetProduct()
- {
- $product_api = new ProductAPI();
- $response = $product_api->getProduct(4006);
- $this->assertNotEmpty($response);
- $this->assertTrue(is_string($response));
- try {
- $response = $product_api->getProduct('4006');
- var_dump($response);
- } catch (Exception $e) {
- try {
- $response = $product_api->getProduct(-4006);
- var_dump($response);
- } catch (Exception $e) {
- return;
- }
- }
- $this->fail("Exception for ProductAPI::getProduct() wasn't triggered.");
- }
- /**
- * Test random products fetching.
- */
- public function testGetRandomProducts()
- {
- $product_api = new ProductAPI();
- $response = $product_api->getRandomProducts(5);
- $this->assertNotEmpty($response);
- $this->assertTrue(is_string($response));
- try {
- $response = $product_api->getRandomProducts('5');
- var_dump($response);
- } catch (Exception $e) {
- try {
- $response = $product_api->getRandomProducts(-5);
- var_dump($response);
- } catch (Exception $e) {
- return;
- }
- }
- $this->fail("Exception for ProductAPI::getRandomProducts() wasn't triggered.");
- }
- /**
- * Test classes fetching.
- */
- public function testGetClasses()
- {
- $product_api = new ProductAPI();
- $response = $product_api->getClasses();
- $this->assertNotEmpty($response);
- $this->assertTrue(is_string($response));
- }
- /**
- * Test class fetching.
- */
- public function testGetClass()
- {
- $product_api = new ProductAPI();
- $response = $product_api->getClass(0);
- $this->assertNotEmpty($response);
- $this->assertTrue(is_string($response));
- try {
- $response = $product_api->getClass('0');
- var_dump($response);
- } catch (Exception $e) {
- return;
- }
- $this->fail("Exception for ProductAPI::getClass() wasn't triggered.");
- }
- /**
- * Test profile fetching.
- */
- public function testGetProfile()
- {
- $product_api = new ProductAPI();
- $response = $product_api->getProfile();
- $this->assertNotEmpty($response);
- $this->assertTrue(is_string($response));
- try {
- $product_api->setStoreId(1002);
- $response = $product_api->getProfile();
- var_dump($response);
- } catch (Exception $e) {
- return;
- }
- $this->fail("Exception for ProductAPI::getProfile() wasn't triggered.");
- }
- /**
- * Test run batch.
- */
- public function testRunBatch()
- {
- $product_api = new ProductAPI();
- $batch = new BatchBuilder($product_api);
- $response = $batch->getCategories('categories')->run();
- $this->assertNotEmpty($response);
- $this->assertTrue(is_string($response));
- $response = $batch->getCategories('categories')->getProducts('products')->run();
- $this->assertNotEmpty($response);
- $this->assertTrue(is_string($response));
- try {
- $response = $batch->run();
- var_dump($response);
- } catch (Exception $e) {
- return;
- }
- $this->fail("Exception for ProductAPI::runBatch() wasn't triggered.");
- }
- }