/tests/phpunit/ProductAPISecuredUnitTest.php
PHP | 152 lines | 95 code | 5 blank | 52 comment | 4 complexity | 97da9b99e9a54a0cb00e62989d912531 MD5 | raw file
- <?php
- /**
- * @author Samigullin Kamil <feedback@kamilsk.com>
- * @link http://www.kamilsk.com/
- */
- namespace Ecwid\tests\phpunit;
- use Ecwid\api\ProductAPI,
- \Exception;
- require 'UnitTest.php';
- /**
- * @package Ecwid.tests.phpunit
- * @since 1.0
- */
- class ProductAPISecuredUnitTest extends UnitTest
- {
- /**
- * @return array
- * @throws Exception
- */
- public function secured_product_api_provider()
- {
- $config = array(
- 'store_id' => null,
- 'protocol' => 'https',
- 'secure_auth_key' => null,
- );
- if (is_null($config['store_id']) or is_null($config['secure_auth_key'])) {
- throw new Exception('Set your store id and Product API secret key.');
- }
- return array($config);
- }
- /**
- * Test products updating.
- *
- * @dataProvider secured_product_api_provider
- * @param int $store_id
- * @param string $protocol
- * @param string $secure_auth_key
- */
- public function testPutProducts($store_id, $protocol, $secure_auth_key)
- {
- $product_api = new ProductAPI(array(
- 'store_id' => $store_id,
- 'protocol' => $protocol,
- 'secure_auth_key' => $secure_auth_key,
- ));
- $products = $product_api->getProducts();
- $response = $product_api->putProducts($products);
- $this->assertNotEmpty($response);
- $this->assertTrue(is_string($response));
- }
- /**
- * Test product updating.
- *
- * @dataProvider secured_product_api_provider
- * @param int $store_id
- * @param string $protocol
- * @param string $secure_auth_key
- */
- public function testPutProduct($store_id, $protocol, $secure_auth_key)
- {
- $product_api = new ProductAPI(array(
- 'store_id' => $store_id,
- 'protocol' => $protocol,
- 'secure_auth_key' => $secure_auth_key,
- ));
- $products = $product_api->getProducts();
- $products = json_decode($products, true);
- $product = array_pop($products);
- $response = $product_api->putProduct($product['id'], json_encode($product));
- $this->assertNotEmpty($response);
- $this->assertTrue(is_string($response));
- }
- /**
- * Test class creating.
- *
- * @dataProvider secured_product_api_provider
- * @param int $store_id
- * @param string $protocol
- * @param string $secure_auth_key
- */
- public function testPostClass($store_id, $protocol, $secure_auth_key)
- {
- $product_api = new ProductAPI(array(
- 'store_id' => $store_id,
- 'protocol' => $protocol,
- 'secure_auth_key' => $secure_auth_key,
- ));
- $new_class = array('name' => '_test_class');
- $new_class = json_encode($new_class);
- $response = $product_api->postClass($new_class);
- $this->assertNotEmpty($response);
- $this->assertTrue(is_string($response));
- }
- /**
- * Test class updating.
- *
- * @dataProvider secured_product_api_provider
- * @param int $store_id
- * @param string $protocol
- * @param string $secure_auth_key
- */
- public function testPutClass($store_id, $protocol, $secure_auth_key)
- {
- $product_api = new ProductAPI(array(
- 'store_id' => $store_id,
- 'protocol' => $protocol,
- 'secure_auth_key' => $secure_auth_key,
- ));
- $classes = $product_api->getClasses();
- $classes = json_decode($classes, true);
- $class = array_pop($classes);
- $response = $product_api->putClass($class['id'], json_encode($class));
- $this->assertNotEmpty($response);
- $this->assertTrue(is_string($response));
- }
- /**
- * Test class deleting.
- *
- * @dataProvider secured_product_api_provider
- * @param int $store_id
- * @param string $protocol
- * @param string $secure_auth_key
- */
- public function testDeleteClass($store_id, $protocol, $secure_auth_key)
- {
- $product_api = new ProductAPI(array(
- 'store_id' => $store_id,
- 'protocol' => $protocol,
- 'secure_auth_key' => $secure_auth_key,
- ));
- $classes = $product_api->getClasses();
- $classes = json_decode($classes, true);
- foreach ($classes as $class) {
- if (array_key_exists('name', $class) && $class['name'] === '_test_class') {
- $found = $class;
- }
- }
- if (empty($found)) {
- $this->fail('_test_class_not_found');
- return;
- }
- $response = $product_api->deleteClass($found['id']);
- $this->assertNotEmpty($response);
- $this->assertTrue(is_string($response));
- }
- }