1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2013-2014 eBay Enterprise, Inc. |
4
|
|
|
* |
5
|
|
|
* NOTICE OF LICENSE |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
8
|
|
|
* that is bundled with this package in the file LICENSE.md. |
9
|
|
|
* It is also available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* @copyright Copyright (c) 2013-2014 eBay Enterprise, Inc. (http://www.ebayenterprise.com/) |
13
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
class EbayEnterprise_Inventory_Test_Helper_DataTest extends EbayEnterprise_Eb2cCore_Test_Base |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Scenario: Get all products from a quote item |
20
|
|
|
* Given a quote item |
21
|
|
|
* When getting all products from a quote item. |
22
|
|
|
* Then an array containing all child and parent products is returned. |
23
|
|
|
*/ |
24
|
|
|
public function testGetAllProductsFromItem() |
25
|
|
|
{ |
26
|
|
|
/** @var array */ |
27
|
|
|
$skus = ['abc', '123']; |
28
|
|
|
/** @var Mage_Sales_Model_Quote_Item */ |
29
|
|
|
$item = Mage::getModel('sales/quote_item'); |
30
|
|
|
|
31
|
|
|
/** @var EbayEnterprise_Inventory_Helper_Data */ |
32
|
|
|
$helper = $this->getHelperMock('ebayenterprise_inventory', [ |
33
|
|
|
'getAllItemSkus' |
34
|
|
|
]); |
35
|
|
|
$helper->expects($this->once()) |
36
|
|
|
->method('getAllItemSkus') |
37
|
|
|
->with($this->identicalTo($item)) |
38
|
|
|
->will($this->returnValue($skus)); |
39
|
|
|
|
40
|
|
|
/** @var Mage_Catalog_Model_Resource_Product_Collection */ |
41
|
|
|
$products = $this->getResourceModelMockBuilder('catalog/product_collection') |
42
|
|
|
->disableOriginalConstructor() |
43
|
|
|
->setMethods(['addAttributeToSelect', 'addAttributeToFilter', 'load']) |
44
|
|
|
->getMock(); |
45
|
|
|
$products->expects($this->once()) |
46
|
|
|
->method('addAttributeToSelect') |
47
|
|
|
->with($this->identicalTo(['street_date'])) |
48
|
|
|
->will($this->returnSelf()); |
49
|
|
|
$products->expects($this->once()) |
50
|
|
|
->method('addAttributeToFilter') |
51
|
|
|
->with($this->identicalTo([['attribute' => 'sku', 'in' => $skus]])) |
52
|
|
|
->will($this->returnSelf()); |
53
|
|
|
$products->expects($this->once()) |
54
|
|
|
->method('load') |
55
|
|
|
->will($this->returnSelf()); |
56
|
|
|
$this->replaceByMock('resource_model', 'catalog/product_collection', $products); |
57
|
|
|
|
58
|
|
|
$this->assertSame($products, EcomDev_Utils_Reflection::invokeRestrictedMethod($helper, 'getAllProductsFromItem', [$item])); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Scenario: Get all child products from a quote item |
63
|
|
|
* Given a quote item with child products |
64
|
|
|
* When getting all child products from a quote item with child item. |
65
|
|
|
* Then an array containing all child products is returned. |
66
|
|
|
*/ |
67
|
|
|
public function testGetAllChildSkusFromItem() |
68
|
|
|
{ |
69
|
|
|
/** @var string */ |
70
|
|
|
$childSku = 'ABCD1234'; |
71
|
|
|
/** @var Mage_Catalog_Model_Product */ |
72
|
|
|
$childProduct = Mage::getModel('catalog/product', ['sku' => $childSku]); |
73
|
|
|
/** @var Mage_Sales_Model_Quote_Item */ |
74
|
|
|
$children = Mage::getModel('sales/quote_item', ['product' => $childProduct]); |
75
|
|
|
/** @var Mage_Sales_Model_Quote_Item */ |
76
|
|
|
$item = Mage::getModel('sales/quote_item'); |
77
|
|
|
$item->addChild($children); |
78
|
|
|
/** @var EbayEnterprise_Inventory_Helper_Data */ |
79
|
|
|
$helper = Mage::helper('ebayenterprise_inventory'); |
80
|
|
|
|
81
|
|
|
$this->assertSame([$childSku], EcomDev_Utils_Reflection::invokeRestrictedMethod($helper, 'getAllChildSkusFromItem', [$item])); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Scenario: Get current product and parent product from a quote item |
86
|
|
|
* Given a quote item with parent product |
87
|
|
|
* When getting both current and parent products from a quote item. |
88
|
|
|
* Then an array containing both current and parent products is returned. |
89
|
|
|
*/ |
90
|
|
|
public function testGetAllParentSkuFromItem() |
91
|
|
|
{ |
92
|
|
|
/** @var string */ |
93
|
|
|
$parentASku = 'ABCD1234'; |
94
|
|
|
/** @var string */ |
95
|
|
|
$parentBSku = '1234ABCD'; |
96
|
|
|
/** @var Mage_Catalog_Model_Product */ |
97
|
|
|
$product = Mage::getModel('catalog/product', ['entity_id' => 34, 'sku' => $parentASku]); |
98
|
|
|
/** @var Mage_Catalog_Model_Product */ |
99
|
|
|
$parentProduct = Mage::getModel('catalog/product', ['entity_id' => 55, 'sku' => $parentBSku]); |
100
|
|
|
/** @var Mage_Sales_Model_Quote_Item */ |
101
|
|
|
$parent = Mage::getModel('sales/quote_item', ['product' => $parentProduct]); |
102
|
|
|
/** @var Mage_Sales_Model_Quote_Item */ |
103
|
|
|
$item = Mage::getModel('sales/quote_item', ['product' => $product]); |
104
|
|
|
$item->setParentItem($parent); |
105
|
|
|
/** @var EbayEnterprise_Inventory_Helper_Data */ |
106
|
|
|
$helper = Mage::helper('ebayenterprise_inventory'); |
107
|
|
|
|
108
|
|
|
$this->assertSame([$parentASku, $parentBSku], EcomDev_Utils_Reflection::invokeRestrictedMethod($helper, 'getAllParentSkuFromItem', [$item])); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return array |
|
|
|
|
113
|
|
|
*/ |
114
|
|
|
public function providerGetStreetDateForBackorderableItem() |
115
|
|
|
{ |
116
|
|
|
return [ |
117
|
|
|
[true, '2015-09-15', true], |
118
|
|
|
[true, '2015-09-15', false], |
119
|
|
|
[false, null, false], |
120
|
|
|
]; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Mock ebayenterprise_inventory/data helper class |
125
|
|
|
* @param bool |
126
|
|
|
* @param string |
127
|
|
|
* @param bool |
128
|
|
|
* @param Mage_Sales_Model_Quote_Item |
129
|
|
|
* @param Mage_Catalog_Model_Product[] |
130
|
|
|
* @param Varien_Object | null |
131
|
|
|
* @param array |
132
|
|
|
* @param string |
133
|
|
|
* @param string |
134
|
|
|
* @return Mock_EbayEnterprise_Inventory_Helper_Data |
|
|
|
|
135
|
|
|
*/ |
136
|
|
|
protected function getMockHelperClass($isUseStreetDateAsEddDate, $streetDate, $isDateInFuture, Mage_Sales_Model_Quote_Item $item, Mage_Catalog_Model_Resource_Product_Collection $products, $result, array $data, $fromDate, $toDate) |
137
|
|
|
{ |
138
|
|
|
/** @var array */ |
139
|
|
|
$mockMethods = ['getAllProductsFromItem', 'getStreetDateFromProduct', 'isStreetDateInTheFuture', 'getNewVarienObject', 'getNewDateTime', 'getStreetToDate']; |
140
|
|
|
/** @var EbayEnterprise_Inventory_Helper_Data */ |
141
|
|
|
$helper = $this->getHelperMock('ebayenterprise_inventory/data', $mockMethods, false, [[ |
142
|
|
|
'core_config' => $this->buildCoreConfigRegistry(['isUseStreetDateAsEddDate' => $isUseStreetDateAsEddDate]), |
143
|
|
|
]]); |
144
|
|
|
$a = $isUseStreetDateAsEddDate ? $this->any() : $this->never(); |
145
|
|
|
$b = ($isUseStreetDateAsEddDate && $streetDate) ? $this->any() : $this->never(); |
146
|
|
|
$c = ($isUseStreetDateAsEddDate && $streetDate && $isDateInFuture) ? $this->any() : $this->never(); |
147
|
|
|
$helper->expects($a) |
148
|
|
|
->method('getAllProductsFromItem') |
149
|
|
|
->with($this->identicalTo($item)) |
150
|
|
|
->will($this->returnValue($products)); |
151
|
|
|
$helper->expects($a) |
152
|
|
|
->method('getStreetDateFromProduct') |
153
|
|
|
->with($this->identicalTo($products)) |
154
|
|
|
->will($this->returnValue($streetDate)); |
155
|
|
|
$helper->expects($b) |
156
|
|
|
->method('isStreetDateInTheFuture') |
157
|
|
|
->with($this->identicalTo($streetDate)) |
158
|
|
|
->will($this->returnValue($isDateInFuture)); |
159
|
|
|
$helper->expects($c) |
160
|
|
|
->method('getNewVarienObject') |
161
|
|
|
->with($this->identicalTo($data)) |
162
|
|
|
->will($this->returnValue($result)); |
163
|
|
|
$helper->expects($c) |
164
|
|
|
->method('getNewDateTime') |
165
|
|
|
->with($this->identicalTo($streetDate)) |
166
|
|
|
->will($this->returnValue($fromDate)); |
167
|
|
|
$helper->expects($c) |
168
|
|
|
->method('getStreetToDate') |
169
|
|
|
->with($this->identicalTo($streetDate)) |
170
|
|
|
->will($this->returnValue($toDate)); |
171
|
|
|
return $helper; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Scenario: Get street date for backorderable item in a quote |
176
|
|
|
* Given a quote item with parent and child products |
177
|
|
|
* When getting street date for backorderable item in a quote |
178
|
|
|
* Then a Varien_Object is return containing the from and to date, |
179
|
|
|
* otherwise, null is return. |
180
|
|
|
* |
181
|
|
|
* @param bool |
182
|
|
|
* @param string |
183
|
|
|
* @param bool |
184
|
|
|
* @dataProvider providerGetStreetDateForBackorderableItem |
185
|
|
|
*/ |
186
|
|
|
public function testGetStreetDateForBackorderableItem($isUseStreetDateAsEddDate, $streetDate, $isDateInFuture) |
187
|
|
|
{ |
188
|
|
|
/** @var DateTime */ |
189
|
|
|
$fromDate = new DateTime(); |
190
|
|
|
/** @var DateTime */ |
191
|
|
|
$toDate = new DateTime(); |
192
|
|
|
/** @var array */ |
193
|
|
|
$data = [ |
194
|
|
|
'delivery_window_from_date' => $fromDate, |
195
|
|
|
'delivery_window_to_date' => $toDate, |
196
|
|
|
]; |
197
|
|
|
/** @var Varien_Object */ |
198
|
|
|
$result = ($isUseStreetDateAsEddDate && $streetDate && $isDateInFuture) |
199
|
|
|
? new Varien_Object($data) : null; |
200
|
|
|
/** @var Mage_Catalog_Model_Product */ |
201
|
|
|
$product = Mage::getModel('catalog/product', ['entity_id' => 34]); |
202
|
|
|
/** @var Mage_Catalog_Model_Product */ |
203
|
|
|
$parentProduct = Mage::getModel('catalog/product', ['entity_id' => 55]); |
204
|
|
|
/** @var Mage_Catalog_Model_Resource_Product_Collection */ |
205
|
|
|
$products = Mage::getResourceModel('catalog/product_collection'); |
206
|
|
|
$products->addItem($product); |
207
|
|
|
$products->addItem($parentProduct); |
208
|
|
|
|
209
|
|
|
/** @var Mage_Sales_Model_Quote_Item */ |
210
|
|
|
$parent = Mage::getModel('sales/quote_item', ['product' => $parentProduct]); |
211
|
|
|
/** @var Mage_Sales_Model_Quote_Item */ |
212
|
|
|
$item = Mage::getModel('sales/quote_item', ['product' => $product]); |
213
|
|
|
$item->setParentItem($parent); |
214
|
|
|
/** @var EbayEnterprise_Inventory_Helper_Data */ |
215
|
|
|
$helper = $this->getMockHelperClass($isUseStreetDateAsEddDate, $streetDate, $isDateInFuture, $item, $products, $result, $data, $fromDate, $toDate); |
216
|
|
|
$this->assertSame($result, $helper->getStreetDateForBackorderableItem($item)); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Scenario: Get street date an array of products |
221
|
|
|
* Given an array of products |
222
|
|
|
* When getting street date from products |
223
|
|
|
* Then return a street date or null |
224
|
|
|
*/ |
225
|
|
|
public function testGetStreetDateFromProduct() |
226
|
|
|
{ |
227
|
|
|
/** @var string */ |
228
|
|
|
$streetDate = '2015-09-15'; |
229
|
|
|
/** @var string */ |
230
|
|
|
$sku = 'ABC134'; |
231
|
|
|
/** @var Mage_Catalog_Model_Product */ |
232
|
|
|
$product = Mage::getModel('catalog/product', [ |
233
|
|
|
'street_date' => $streetDate, |
234
|
|
|
'sku' => $sku, |
235
|
|
|
'entity_id' => 6638, |
236
|
|
|
]); |
237
|
|
|
/** @var Mage_Catalog_Model_Resource_Product_Collection */ |
238
|
|
|
$products = Mage::getResourceModel('catalog/product_collection'); |
239
|
|
|
$products->addItem($product); |
240
|
|
|
/** @var EbayEnterprise_Inventory_Helper_Data */ |
241
|
|
|
$helper = Mage::helper('ebayenterprise_inventory/data'); |
242
|
|
|
|
243
|
|
|
$this->assertSame($streetDate, EcomDev_Utils_Reflection::invokeRestrictedMethod($helper, 'getStreetDateFromProduct', [$products])); |
244
|
|
|
} |
245
|
|
|
} |
246
|
|
|
|
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.