Skip to content

Commit cab730c

Browse files
authored
Merge pull request #5 from retargeting/development
Development
2 parents e52674b + c3cf5c5 commit cab730c

File tree

10 files changed

+238
-34
lines changed

10 files changed

+238
-34
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
}
1010
],
1111
"require": {
12-
"php": ">=5.6.0",
12+
"php": ">=7.1.0",
1313
"ext-json": "*",
1414
"ext-openssl": "*"
1515
},
@@ -33,7 +33,7 @@
3333
"sort-packages": true,
3434
"optimize-autoloader": true,
3535
"platform": {
36-
"php": "5.6.0"
36+
"php": "7.1.0"
3737
}
3838
}
39-
}
39+
}

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Retargeting SDK is a software development tool for E-Commerce platforms that simplifies the implementation of Retargeting extension.
55

66
## Minimum requirements
7-
The Retargeting SDK requires at least PHP version 5.4.0 and it's also compatible with PHP >= 7.0.0.
7+
The Retargeting SDK requires at least PHP version 7.1.0 or greater.
88

99
## How to install
1010
Clone the repository in your platform root folder.

tests/Unit/ApiCustomersTest.php

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
use PHPUnit\Framework\TestCase;
1212
use RetargetingSDK\Api\Customers;
13-
use RetargetingSDK\Helpers\DecryptionHelper;
14-
use RetargetingSDK\Helpers\EncryptionHelper;
1513

1614
/**
1715
* Class ApiCustomersTest
@@ -22,6 +20,9 @@ class ApiCustomersTest extends TestCase
2220
{
2321
const TOKEN = "df2ce5cba06265db9bffeb6caf8d9fcf46a5a1712f774bca67535a82bdcf1955";
2422

23+
/**
24+
* @var array
25+
*/
2526
protected $customer = [
2627
'firstName' => 'John',
2728
'lastName' => 'Doe',
@@ -72,26 +73,6 @@ public function testIfCustomerHasPageData()
7273
$this->assertNotNull($this->customersInstance->getPrevPage());
7374
}
7475

75-
/**
76-
* Test if token is type of hashed
77-
* @throws Exceptions\DecryptException
78-
* @throws Exceptions\RTGException
79-
*/
80-
public function testIfCustomerDataIsHashed()
81-
{
82-
$encryption = new EncryptionHelper(self::TOKEN);
83-
84-
$data = $encryption->encrypt(json_encode($this->customer, JSON_PRETTY_PRINT));
85-
86-
$this->customersInstance->setData($data);
87-
88-
$decryption = new DecryptionHelper(self::TOKEN);
89-
90-
$decryptedData = $decryption->decrypt($this->customersInstance->getData());
91-
92-
$this->assertEquals(json_decode($decryptedData, JSON_PRETTY_PRINT), $this->customer);
93-
}
94-
9576
/**
9677
* Test if customer prepare api information has proper format
9778
* @throws \Exception

tests/Unit/BrandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function testIfBrandPrepareInformationIsJson()
4949
$this->brand->setId(23);
5050
$this->brand->setName('Apple');
5151

52-
$this->assertJson($this->brand->prepareBrandInformation());
52+
$this->assertJson($this->brand->getData());
5353
}
5454

5555
/**
@@ -60,6 +60,6 @@ public function testIfBrandHasProperFormat()
6060
$this->brand->setId(9000);
6161
$this->brand->setName('Adidas');
6262

63-
$this->assertEquals($this->brand->prepareBrandInformation(), json_encode(['id' => 9000, 'name' => 'Adidas'], JSON_PRETTY_PRINT));
63+
$this->assertEquals($this->brand->getData(), json_encode(['id' => 9000, 'name' => 'Adidas'], JSON_PRETTY_PRINT));
6464
}
6565
}

tests/Unit/CategoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function testIfCategoryHasTwoOreMoreCategoryBreadcrumb()
122122
*/
123123
public function testIfCategoryPrepareDataHasProperFormat()
124124
{
125-
$this->assertEquals($this->category->prepareCategoryData(), json_encode([
125+
$this->assertEquals($this->category->getData(), json_encode([
126126
'id' => '89',
127127
'name' => 'Shoes',
128128
'url' => 'https://www.example.com/desktops/monitors',

tests/Unit/EmailTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function test_if_birthday_has_proper_format()
139139
*/
140140
public function test_if_prepare_email_data_has_proper_format()
141141
{
142-
$this->assertEquals($this->email->prepareEmailData(),
142+
$this->assertEquals($this->email->getData(),
143143
json_encode([
144144
'email' => 'john.doe@mail.com',
145145
'name' => 'John Doe',

tests/Unit/OrderTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,11 @@ public function test_if_order_prepare_information_has_correct_json_format()
174174
'discount' => "20",
175175
'discount_code' => 'RAX204',
176176
'shipping' => 'Sample shipping street',
177+
'rebates' => 0,
178+
'fees' => 0,
177179
'total' => 396
178180
];
179181

180-
$this->assertEquals($this->order->prepareOrderInformation(), json_encode($order, JSON_PRETTY_PRINT));
182+
$this->assertEquals($this->order->getData(), json_encode($order, JSON_PRETTY_PRINT));
181183
}
182184
}

tests/Unit/ProductTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ public function test_when_product_price_is_int()
9797
$this->assertEquals($this->product->getPrice(), 12);
9898
}
9999

100+
/**
101+
* Test if product promo price is greater then product price, then promo price needs to be 0
102+
* @throws \Exception
103+
*/
100104
public function test_when_product_promo_price_is_zero_and_promo_is_greater_than_price()
101105
{
102106
$this->product->setPrice(20);
@@ -144,12 +148,12 @@ public function test_if_product_category_has_correct_format_with_only_one_parent
144148
]
145149
]);
146150

147-
$this->assertEquals($this->product->getCategory(), [
151+
$this->assertEquals($this->product->getCategory(), [[
148152
"id" => 12,
149153
"name" => "Women footwear",
150154
"parent" => false,
151155
"breadcrumb" => []
152-
]);
156+
]]);
153157
}
154158

155159
/**
@@ -393,7 +397,7 @@ public function test_if_product_prepare_information_return_correct_format_array(
393397
]
394398
], JSON_PRETTY_PRINT);
395399

396-
$this->assertEquals($product->prepareProductInformationToJson(), $result);
400+
$this->assertEquals($product->getData(), $result);
397401
}
398402
}
399403

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: andreicotaga
5+
* Date: 2019-05-29
6+
* Time: 11:06
7+
*/
8+
9+
namespace Tests\Unit;
10+
11+
use PHPUnit\Framework\TestCase;
12+
use RetargetingSDK\RecommendationEngine;
13+
14+
/**
15+
* Class RecommendationEngineTest
16+
* @package Tests\Unit
17+
* @property RecommendationEngine engine
18+
*/
19+
class RecommendationEngineTest extends TestCase
20+
{
21+
public function setUp(): void
22+
{
23+
$this->engine = new RecommendationEngine();
24+
}
25+
26+
/**
27+
* Test if mark home page returns correct div with correct id
28+
*/
29+
public function test_if_mark_home_page_return_correct_value()
30+
{
31+
$this->engine->markHomePage();
32+
33+
$this->assertEquals($this->engine->generateTags(), '<div id="retargeting-recommeng-home-page"></div>');
34+
}
35+
36+
/**
37+
* Test if mark category page returns correct div with correct id
38+
*/
39+
public function test_if_mark_category_page_return_correct_value()
40+
{
41+
$this->engine->markCategoryPage();
42+
43+
$this->assertEquals($this->engine->generateTags(), '<div id="retargeting-recommeng-category-page"></div>');
44+
}
45+
46+
/**
47+
* Test if mark product page returns correct div with correct id
48+
*/
49+
public function test_if_mark_product_page_return_correct_value()
50+
{
51+
$this->engine->markProductPage();
52+
53+
$this->assertEquals($this->engine->generateTags(), '<div id="retargeting-recommeng-product-page"></div>');
54+
}
55+
56+
/**
57+
* Test if mark checkout page returns correct div with correct id
58+
*/
59+
public function test_if_mark_checkout_page_return_correct_value()
60+
{
61+
$this->engine->markCheckoutPage();
62+
63+
$this->assertEquals($this->engine->generateTags(), '<div id="retargeting-recommeng-checkout-page"></div>');
64+
}
65+
66+
/**
67+
* Test if mark thank you page returns correct div with correct id
68+
*/
69+
public function test_if_mark_thankyou_page_return_correct_value()
70+
{
71+
$this->engine->markThankYouPage();
72+
73+
$this->assertEquals($this->engine->generateTags(), '<div id="retargeting-recommeng-thank-you-page"></div>');
74+
}
75+
76+
/**
77+
* Test if mark out of stock page returns correct div with correct id
78+
*/
79+
public function test_if_mark_out_of_stock_page_return_correct_value()
80+
{
81+
$this->engine->markOutOfStockPage();
82+
83+
$this->assertEquals($this->engine->generateTags(), '<div id="retargeting-recommeng-out-of-stock-page"></div>');
84+
}
85+
86+
/**
87+
* Test if mark search page returns correct div with correct id
88+
*/
89+
public function test_if_mark_search_page_return_correct_value()
90+
{
91+
$this->engine->markSearchPage();
92+
93+
$this->assertEquals($this->engine->generateTags(), '<div id="retargeting-recommeng-search-page"></div>');
94+
}
95+
96+
/**
97+
* Test if mark not found page returns correct div with correct id
98+
*/
99+
public function test_if_mark_notfound_page_return_correct_value()
100+
{
101+
$this->engine->markNotFoundPage();
102+
103+
$this->assertEquals($this->engine->generateTags(), '<div id="retargeting-recommeng-not-found-page"></div>');
104+
}
105+
106+
/**
107+
* Test if generate tags returns string format data
108+
*/
109+
public function test_if_generate_tags_returns_string()
110+
{
111+
$this->engine->markSearchPage();
112+
113+
$this->assertIsString($this->engine->generateTags());
114+
}
115+
}

tests/Unit/VariationTest.php

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: andreicotaga
5+
* Date: 2019-05-29
6+
* Time: 10:39
7+
*/
8+
9+
namespace Tests\Unit;
10+
11+
use PHPUnit\Framework\TestCase;
12+
use RetargetingSDK\Variation;
13+
14+
/**
15+
* Class VariationTest
16+
* @package Tests\Unit
17+
* @property Variation variation
18+
*/
19+
class VariationTest extends TestCase
20+
{
21+
public function setUp(): void
22+
{
23+
$this->variation = new Variation();
24+
25+
$details = [
26+
42 => [
27+
'category_name' => 'Size',
28+
'category' => 'size',
29+
'value' => 42
30+
],
31+
'B' => [
32+
'category_name' => 'Color',
33+
'category' => 'color',
34+
'value' => 'Black'
35+
],
36+
];
37+
38+
$this->variation->setStock(true);
39+
$this->variation->setCode('42-B');
40+
$this->variation->setDetails($details);
41+
}
42+
43+
/**
44+
* Test if variation code is not null
45+
*/
46+
public function test_if_variation_has_code()
47+
{
48+
$this->assertNotNull($this->variation->getCode());
49+
}
50+
51+
/**
52+
* Test if stock is boolean type of
53+
*/
54+
public function test_if_stock_is_boolean()
55+
{
56+
$this->assertIsBool($this->variation->getStock());
57+
}
58+
59+
/**
60+
* Test if details is array type of
61+
*/
62+
public function test_if_details_is_array()
63+
{
64+
$this->assertIsArray($this->variation->getDetails());
65+
}
66+
67+
/**
68+
* Test if details is array or not
69+
*/
70+
public function test_if_details_is_not_empty()
71+
{
72+
$this->assertNotEmpty($this->variation->getDetails());
73+
}
74+
75+
/**
76+
* Test if get data returns correct format array
77+
*/
78+
public function test_if_get_data_variation_function_return_correct_format_array()
79+
{
80+
$variation = [
81+
'code' => $this->variation->getCode(),
82+
'stock' => $this->variation->getStock(),
83+
'details' => $this->variation->getDetails()
84+
];
85+
86+
$this->assertEquals($this->variation->getData(false), $variation);
87+
}
88+
89+
/**
90+
* Test if get data returns correct format json
91+
*/
92+
public function test_if_get_data_variation_function_return_correct_format_json()
93+
{
94+
$variation = [
95+
'code' => $this->variation->getCode(),
96+
'stock' => $this->variation->getStock(),
97+
'details' => $this->variation->getDetails()
98+
];
99+
100+
$this->assertEquals($this->variation->getData(), json_encode($variation, JSON_PRETTY_PRINT));
101+
}
102+
}

0 commit comments

Comments
 (0)