Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
],
"require": {
"php": ">=5.6.0",
"php": ">=7.1.0",
"ext-json": "*",
"ext-openssl": "*"
},
Expand All @@ -33,7 +33,7 @@
"sort-packages": true,
"optimize-autoloader": true,
"platform": {
"php": "5.6.0"
"php": "7.1.0"
}
}
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 3 additions & 22 deletions tests/Unit/ApiCustomersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

use PHPUnit\Framework\TestCase;
use RetargetingSDK\Api\Customers;
use RetargetingSDK\Helpers\DecryptionHelper;
use RetargetingSDK\Helpers\EncryptionHelper;

/**
* Class ApiCustomersTest
Expand All @@ -22,6 +20,9 @@ class ApiCustomersTest extends TestCase
{
const TOKEN = "df2ce5cba06265db9bffeb6caf8d9fcf46a5a1712f774bca67535a82bdcf1955";

/**
* @var array
*/
protected $customer = [
'firstName' => 'John',
'lastName' => 'Doe',
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/BrandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand All @@ -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));
}
}
2 changes: 1 addition & 1 deletion tests/Unit/CategoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 3 additions & 1 deletion tests/Unit/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
10 changes: 7 additions & 3 deletions tests/Unit/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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" => []
]);
]]);
}

/**
Expand Down Expand Up @@ -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);
}
}

115 changes: 115 additions & 0 deletions tests/Unit/RecommendationEngineTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php
/**
* Created by PhpStorm.
* User: andreicotaga
* Date: 2019-05-29
* Time: 11:06
*/

namespace Tests\Unit;

use PHPUnit\Framework\TestCase;
use RetargetingSDK\RecommendationEngine;

/**
* Class RecommendationEngineTest
* @package Tests\Unit
* @property RecommendationEngine engine
*/
class RecommendationEngineTest extends TestCase
{
public function setUp(): void
{
$this->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(), '<div id="retargeting-recommeng-home-page"></div>');
}

/**
* 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(), '<div id="retargeting-recommeng-category-page"></div>');
}

/**
* 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(), '<div id="retargeting-recommeng-product-page"></div>');
}

/**
* 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(), '<div id="retargeting-recommeng-checkout-page"></div>');
}

/**
* 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(), '<div id="retargeting-recommeng-thank-you-page"></div>');
}

/**
* 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(), '<div id="retargeting-recommeng-out-of-stock-page"></div>');
}

/**
* 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(), '<div id="retargeting-recommeng-search-page"></div>');
}

/**
* 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(), '<div id="retargeting-recommeng-not-found-page"></div>');
}

/**
* Test if generate tags returns string format data
*/
public function test_if_generate_tags_returns_string()
{
$this->engine->markSearchPage();

$this->assertIsString($this->engine->generateTags());
}
}
102 changes: 102 additions & 0 deletions tests/Unit/VariationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
/**
* Created by PhpStorm.
* User: andreicotaga
* Date: 2019-05-29
* Time: 10:39
*/

namespace Tests\Unit;

use PHPUnit\Framework\TestCase;
use RetargetingSDK\Variation;

/**
* Class VariationTest
* @package Tests\Unit
* @property Variation variation
*/
class VariationTest extends TestCase
{
public function setUp(): void
{
$this->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));
}
}