From 0334e84483d2e23866049b5ccf3af419eb45f5d8 Mon Sep 17 00:00:00 2001 From: andreicotaga Date: Wed, 29 May 2019 11:43:13 +0300 Subject: [PATCH 1/4] Test cases --- tests/Unit/ApiCustomersTest.php | 25 +----- tests/Unit/BrandTest.php | 4 +- tests/Unit/CategoryTest.php | 2 +- tests/Unit/EmailTest.php | 2 +- tests/Unit/OrderTest.php | 4 +- tests/Unit/ProductTest.php | 10 ++- tests/Unit/RecommendationEngineTest.php | 115 ++++++++++++++++++++++++ tests/Unit/VariationTest.php | 102 +++++++++++++++++++++ 8 files changed, 234 insertions(+), 30 deletions(-) create mode 100644 tests/Unit/RecommendationEngineTest.php create mode 100644 tests/Unit/VariationTest.php diff --git a/tests/Unit/ApiCustomersTest.php b/tests/Unit/ApiCustomersTest.php index 4a4f504..4c85053 100644 --- a/tests/Unit/ApiCustomersTest.php +++ b/tests/Unit/ApiCustomersTest.php @@ -10,8 +10,6 @@ use PHPUnit\Framework\TestCase; use RetargetingSDK\Api\Customers; -use RetargetingSDK\Helpers\DecryptionHelper; -use RetargetingSDK\Helpers\EncryptionHelper; /** * Class ApiCustomersTest @@ -22,6 +20,9 @@ class ApiCustomersTest extends TestCase { const TOKEN = "df2ce5cba06265db9bffeb6caf8d9fcf46a5a1712f774bca67535a82bdcf1955"; + /** + * @var array + */ protected $customer = [ 'firstName' => 'John', 'lastName' => 'Doe', @@ -72,26 +73,6 @@ public function testIfCustomerHasPageData() $this->assertNotNull($this->customersInstance->getPrevPage()); } - /** - * Test if token is type of hashed - * @throws Exceptions\DecryptException - * @throws Exceptions\RTGException - */ - public function testIfCustomerDataIsHashed() - { - $encryption = new EncryptionHelper(self::TOKEN); - - $data = $encryption->encrypt(json_encode($this->customer, JSON_PRETTY_PRINT)); - - $this->customersInstance->setData($data); - - $decryption = new DecryptionHelper(self::TOKEN); - - $decryptedData = $decryption->decrypt($this->customersInstance->getData()); - - $this->assertEquals(json_decode($decryptedData, JSON_PRETTY_PRINT), $this->customer); - } - /** * Test if customer prepare api information has proper format * @throws \Exception diff --git a/tests/Unit/BrandTest.php b/tests/Unit/BrandTest.php index 6b0d463..676ff7a 100644 --- a/tests/Unit/BrandTest.php +++ b/tests/Unit/BrandTest.php @@ -49,7 +49,7 @@ public function testIfBrandPrepareInformationIsJson() $this->brand->setId(23); $this->brand->setName('Apple'); - $this->assertJson($this->brand->prepareBrandInformation()); + $this->assertJson($this->brand->getData()); } /** @@ -60,6 +60,6 @@ public function testIfBrandHasProperFormat() $this->brand->setId(9000); $this->brand->setName('Adidas'); - $this->assertEquals($this->brand->prepareBrandInformation(), json_encode(['id' => 9000, 'name' => 'Adidas'], JSON_PRETTY_PRINT)); + $this->assertEquals($this->brand->getData(), json_encode(['id' => 9000, 'name' => 'Adidas'], JSON_PRETTY_PRINT)); } } diff --git a/tests/Unit/CategoryTest.php b/tests/Unit/CategoryTest.php index ae0b871..c1b6018 100644 --- a/tests/Unit/CategoryTest.php +++ b/tests/Unit/CategoryTest.php @@ -122,7 +122,7 @@ public function testIfCategoryHasTwoOreMoreCategoryBreadcrumb() */ public function testIfCategoryPrepareDataHasProperFormat() { - $this->assertEquals($this->category->prepareCategoryData(), json_encode([ + $this->assertEquals($this->category->getData(), json_encode([ 'id' => '89', 'name' => 'Shoes', 'url' => 'https://www.example.com/desktops/monitors', diff --git a/tests/Unit/EmailTest.php b/tests/Unit/EmailTest.php index a1c74c7..c7551f9 100644 --- a/tests/Unit/EmailTest.php +++ b/tests/Unit/EmailTest.php @@ -139,7 +139,7 @@ public function test_if_birthday_has_proper_format() */ public function test_if_prepare_email_data_has_proper_format() { - $this->assertEquals($this->email->prepareEmailData(), + $this->assertEquals($this->email->getData(), json_encode([ 'email' => 'john.doe@mail.com', 'name' => 'John Doe', diff --git a/tests/Unit/OrderTest.php b/tests/Unit/OrderTest.php index b2ebc02..ecca6b6 100644 --- a/tests/Unit/OrderTest.php +++ b/tests/Unit/OrderTest.php @@ -174,9 +174,11 @@ public function test_if_order_prepare_information_has_correct_json_format() 'discount' => "20", 'discount_code' => 'RAX204', 'shipping' => 'Sample shipping street', + 'rebates' => 0, + 'fees' => 0, 'total' => 396 ]; - $this->assertEquals($this->order->prepareOrderInformation(), json_encode($order, JSON_PRETTY_PRINT)); + $this->assertEquals($this->order->getData(), json_encode($order, JSON_PRETTY_PRINT)); } } \ No newline at end of file diff --git a/tests/Unit/ProductTest.php b/tests/Unit/ProductTest.php index 27163a0..02f43c2 100644 --- a/tests/Unit/ProductTest.php +++ b/tests/Unit/ProductTest.php @@ -97,6 +97,10 @@ public function test_when_product_price_is_int() $this->assertEquals($this->product->getPrice(), 12); } + /** + * Test if product promo price is greater then product price, then promo price needs to be 0 + * @throws \Exception + */ public function test_when_product_promo_price_is_zero_and_promo_is_greater_than_price() { $this->product->setPrice(20); @@ -144,12 +148,12 @@ public function test_if_product_category_has_correct_format_with_only_one_parent ] ]); - $this->assertEquals($this->product->getCategory(), [ + $this->assertEquals($this->product->getCategory(), [[ "id" => 12, "name" => "Women footwear", "parent" => false, "breadcrumb" => [] - ]); + ]]); } /** @@ -393,7 +397,7 @@ public function test_if_product_prepare_information_return_correct_format_array( ] ], JSON_PRETTY_PRINT); - $this->assertEquals($product->prepareProductInformationToJson(), $result); + $this->assertEquals($product->getData(), $result); } } diff --git a/tests/Unit/RecommendationEngineTest.php b/tests/Unit/RecommendationEngineTest.php new file mode 100644 index 0000000..c2d37e3 --- /dev/null +++ b/tests/Unit/RecommendationEngineTest.php @@ -0,0 +1,115 @@ +engine = new RecommendationEngine(); + } + + /** + * Test if mark home page returns correct div with correct id + */ + public function test_if_mark_home_page_return_correct_value() + { + $this->engine->markHomePage(); + + $this->assertEquals($this->engine->generateTags(), '
'); + } + + /** + * Test if mark category page returns correct div with correct id + */ + public function test_if_mark_category_page_return_correct_value() + { + $this->engine->markCategoryPage(); + + $this->assertEquals($this->engine->generateTags(), '
'); + } + + /** + * Test if mark product page returns correct div with correct id + */ + public function test_if_mark_product_page_return_correct_value() + { + $this->engine->markProductPage(); + + $this->assertEquals($this->engine->generateTags(), '
'); + } + + /** + * Test if mark checkout page returns correct div with correct id + */ + public function test_if_mark_checkout_page_return_correct_value() + { + $this->engine->markCheckoutPage(); + + $this->assertEquals($this->engine->generateTags(), '
'); + } + + /** + * Test if mark thank you page returns correct div with correct id + */ + public function test_if_mark_thankyou_page_return_correct_value() + { + $this->engine->markThankYouPage(); + + $this->assertEquals($this->engine->generateTags(), '
'); + } + + /** + * Test if mark out of stock page returns correct div with correct id + */ + public function test_if_mark_out_of_stock_page_return_correct_value() + { + $this->engine->markOutOfStockPage(); + + $this->assertEquals($this->engine->generateTags(), '
'); + } + + /** + * Test if mark search page returns correct div with correct id + */ + public function test_if_mark_search_page_return_correct_value() + { + $this->engine->markSearchPage(); + + $this->assertEquals($this->engine->generateTags(), '
'); + } + + /** + * Test if mark not found page returns correct div with correct id + */ + public function test_if_mark_notfound_page_return_correct_value() + { + $this->engine->markNotFoundPage(); + + $this->assertEquals($this->engine->generateTags(), '
'); + } + + /** + * Test if generate tags returns string format data + */ + public function test_if_generate_tags_returns_string() + { + $this->engine->markSearchPage(); + + $this->assertIsString($this->engine->generateTags()); + } +} \ No newline at end of file diff --git a/tests/Unit/VariationTest.php b/tests/Unit/VariationTest.php new file mode 100644 index 0000000..bd83bf2 --- /dev/null +++ b/tests/Unit/VariationTest.php @@ -0,0 +1,102 @@ +variation = new Variation(); + + $details = [ + 42 => [ + 'category_name' => 'Size', + 'category' => 'size', + 'value' => 42 + ], + 'B' => [ + 'category_name' => 'Color', + 'category' => 'color', + 'value' => 'Black' + ], + ]; + + $this->variation->setStock(true); + $this->variation->setCode('42-B'); + $this->variation->setDetails($details); + } + + /** + * Test if variation code is not null + */ + public function test_if_variation_has_code() + { + $this->assertNotNull($this->variation->getCode()); + } + + /** + * Test if stock is boolean type of + */ + public function test_if_stock_is_boolean() + { + $this->assertIsBool($this->variation->getStock()); + } + + /** + * Test if details is array type of + */ + public function test_if_details_is_array() + { + $this->assertIsArray($this->variation->getDetails()); + } + + /** + * Test if details is array or not + */ + public function test_if_details_is_not_empty() + { + $this->assertNotEmpty($this->variation->getDetails()); + } + + /** + * Test if get data returns correct format array + */ + public function test_if_get_data_variation_function_return_correct_format_array() + { + $variation = [ + 'code' => $this->variation->getCode(), + 'stock' => $this->variation->getStock(), + 'details' => $this->variation->getDetails() + ]; + + $this->assertEquals($this->variation->getData(false), $variation); + } + + /** + * Test if get data returns correct format json + */ + public function test_if_get_data_variation_function_return_correct_format_json() + { + $variation = [ + 'code' => $this->variation->getCode(), + 'stock' => $this->variation->getStock(), + 'details' => $this->variation->getDetails() + ]; + + $this->assertEquals($this->variation->getData(), json_encode($variation, JSON_PRETTY_PRINT)); + } +} \ No newline at end of file From b492b38694074a1045c4856539d296ea45548d10 Mon Sep 17 00:00:00 2001 From: andreicotaga Date: Wed, 29 May 2019 11:45:18 +0300 Subject: [PATCH 2/4] Test cases --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index adcf21e..86b1ee6 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ } }, "require-dev": { - "phpunit/phpunit": "8.0", + "phpunit/phpunit": "7.*", "mockery/mockery": "^1.0", "fzaninotto/faker": "^1.4" }, From 36c514a989986127862c5d4425928aaa12dc2110 Mon Sep 17 00:00:00 2001 From: andreicotaga Date: Wed, 29 May 2019 11:47:17 +0300 Subject: [PATCH 3/4] Test cases --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 86b1ee6..adcf21e 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ } }, "require-dev": { - "phpunit/phpunit": "7.*", + "phpunit/phpunit": "8.0", "mockery/mockery": "^1.0", "fzaninotto/faker": "^1.4" }, From c3cf5c5d17bc4357ad21e4ca0d0d38aa0366125b Mon Sep 17 00:00:00 2001 From: andreicotaga Date: Wed, 29 May 2019 12:00:25 +0300 Subject: [PATCH 4/4] Test cases --- composer.json | 6 +++--- readme.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index adcf21e..6339b26 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } ], "require": { - "php": ">=5.6.0", + "php": ">=7.1.0", "ext-json": "*", "ext-openssl": "*" }, @@ -33,7 +33,7 @@ "sort-packages": true, "optimize-autoloader": true, "platform": { - "php": "5.6.0" + "php": "7.1.0" } } -} +} \ No newline at end of file diff --git a/readme.md b/readme.md index aa9cdfe..670ef7f 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ Retargeting SDK is a software development tool for E-Commerce platforms that simplifies the implementation of Retargeting extension. ## Minimum requirements -The Retargeting SDK requires at least PHP version 5.4.0 and it's also compatible with PHP >= 7.0.0. +The Retargeting SDK requires at least PHP version 7.1.0 or greater. ## How to install Clone the repository in your platform root folder.