5
5
*/
6
6
namespace Magento \SalesRule \Model \ResourceModel \Report \Rule ;
7
7
8
- use Magento \Catalog \Test \Fixture \Product as ProductFixture ;
9
- use Magento \Checkout \Test \Fixture \PlaceOrder as PlaceOrderFixture ;
10
- use Magento \Checkout \Test \Fixture \SetBillingAddress as SetBillingAddressFixture ;
11
- use Magento \Checkout \Test \Fixture \SetDeliveryMethod as SetDeliveryMethodFixture ;
12
- use Magento \Checkout \Test \Fixture \SetPaymentMethod as SetPaymentMethodFixture ;
13
- use Magento \Checkout \Test \Fixture \SetShippingAddress as SetShippingAddressFixture ;
14
- use Magento \Customer \Test \Fixture \Customer ;
15
- use Magento \Framework \ObjectManagerInterface ;
16
- use Magento \Quote \Test \Fixture \ApplyCoupon as ApplyCouponFixture ;
17
- use Magento \Quote \Test \Fixture \AddProductToCart as AddProductToCartFixture ;
18
- use Magento \Quote \Test \Fixture \CustomerCart ;
19
- use Magento \Sales \Model \Order ;
20
- use Magento \Sales \Test \Fixture \Invoice as InvoiceFixture ;
21
- use Magento \Sales \Test \Fixture \Shipment as ShipmentFixture ;
22
- use Magento \SalesRule \Model \ResourceModel \Report \Collection ;
23
- use Magento \SalesRule \Model \ResourceModel \Report \Rule ;
24
- use Magento \SalesRule \Model \Rule as SalesRule ;
25
- use Magento \SalesRule \Test \Fixture \AddressCondition as AddressConditionFixture ;
26
- use Magento \SalesRule \Test \Fixture \Rule as RuleFixture ;
27
- use Magento \Store \Model \ScopeInterface ;
28
- use Magento \Tax \Test \Fixture \TaxRate as TaxRateFixture ;
29
- use Magento \Tax \Test \Fixture \TaxRule as TaxRuleFixture ;
30
- use Magento \TestFramework \Fixture \AppArea ;
31
- use Magento \TestFramework \Fixture \Config as ConfigFixture ;
32
- use Magento \TestFramework \Fixture \DataFixture ;
33
- use Magento \TestFramework \Fixture \DataFixtureStorage ;
34
- use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
35
- use Magento \TestFramework \Helper \Bootstrap ;
36
- use PHPUnit \Framework \TestCase ;
37
-
38
8
/**
39
9
* Createdat test for check report totals calculate
10
+ *
11
+ * @magentoDataFixture Magento/SalesRule/_files/order_with_coupon.php
40
12
*/
41
- class CreatedatTest extends TestCase
13
+ class CreatedatTest extends \ PHPUnit \ Framework \ TestCase
42
14
{
43
15
/**
44
- * @var ObjectManagerInterface
45
- */
46
- private $ objectManager ;
47
-
48
- /**
49
- * @var DataFixtureStorage
50
- */
51
- private $ fixtures ;
52
-
53
- /**
54
- * @var Rule
55
- */
56
- private $ reportResource ;
57
-
58
- /**
59
- * @var Collection
60
- */
61
- private $ reportCollection ;
62
-
63
- /**
64
- * @inheirtDoc
65
- */
66
- protected function setUp (): void
67
- {
68
- $ this ->objectManager = Bootstrap::getObjectManager ();
69
- $ this ->fixtures = $ this ->objectManager ->get (DataFixtureStorageManager::class)->getStorage ();
70
- $ this ->reportResource = $ this ->objectManager ->get (Rule::class);
71
- $ this ->reportCollection = $ this ->objectManager ->get (Collection::class);
72
- }
73
-
74
- /**
75
- * @magentoDataFixture Magento/SalesRule/_files/order_with_coupon.php
76
16
* @dataProvider orderParamsDataProvider()
77
17
* @param $orderParams
78
18
*/
79
19
public function testTotals ($ orderParams )
80
20
{
81
- /** @var Order $order */
82
- $ order = $ this -> objectManager -> create (Order::class);
21
+ /** @var \Magento\Sales\Model\ Order $order */
22
+ $ order = \ Magento \ TestFramework \ Helper \Bootstrap:: getObjectManager ()-> create (\ Magento \ Sales \ Model \ Order::class);
83
23
$ order ->loadByIncrementId ('100000001 ' )
84
24
->setBaseGrandTotal ($ orderParams ['base_subtotal ' ])
85
25
->setSubtotal ($ orderParams ['base_subtotal ' ])
@@ -95,46 +35,50 @@ public function testTotals($orderParams)
95
35
->setCreatedAt ('2014-10-25 10:10:10 ' )
96
36
->save ();
97
37
// refresh report statistics
98
- $ this ->reportResource ->aggregate ();
99
- $ salesRuleReportItem = $ this ->reportCollection ->getFirstItem ();
38
+ /** @var \Magento\SalesRule\Model\ResourceModel\Report\Rule $reportResource */
39
+ $ reportResource = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
40
+ \Magento \SalesRule \Model \ResourceModel \Report \Rule::class
41
+ );
42
+ $ reportResource ->aggregate ();
43
+ /** @var \Magento\SalesRule\Model\ResourceModel\Report\Collection $reportCollection */
44
+ $ reportCollection = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
45
+ \Magento \SalesRule \Model \ResourceModel \Report \Collection::class
46
+ );
47
+ $ salesRuleReportItem = $ reportCollection ->getFirstItem ();
100
48
$ this ->assertEquals ($ this ->getTotalAmount ($ order ), $ salesRuleReportItem ['total_amount ' ]);
101
49
$ this ->assertEquals ($ this ->getTotalAmountActual ($ order ), $ salesRuleReportItem ['total_amount_actual ' ]);
102
50
}
103
51
104
52
/**
105
53
* Repeat sql formula from \Magento\SalesRule\Model\ResourceModel\Report\Rule\Createdat::_aggregateByOrder
106
54
*
107
- * @param Order $order
55
+ * @param \Magento\Sales\Model\ Order $order
108
56
* @return float
109
57
*/
110
- private function getTotalAmount (Order $ order )
58
+ private function getTotalAmount (\ Magento \ Sales \ Model \ Order $ order )
111
59
{
112
60
return (
113
- ($ order ->getBaseSubtotal () - $ order ->getBaseSubtotalCanceled ()
114
- + ($ order ->getBaseShippingAmount () - $ order ->getBaseShippingCanceled ()))
115
- - (abs ((float ) $ order ->getBaseDiscountAmount ()) - abs ((float ) $ order ->getBaseDiscountCanceled ()))
116
- + ($ order ->getBaseTaxAmount () - $ order ->getBaseTaxCanceled ())
117
- + ($ order ->getBaseDiscountTaxCompensationAmount () - $ order ->getBaseDiscountTaxCompensationRefunded ())
118
- - abs ((float ) $ order ->getShippingDiscountTaxCompensationAmount ())
119
- ) * $ order ->getBaseToGlobalRate ();
61
+ ($ order ->getBaseSubtotal () - $ order ->getBaseSubtotalCanceled ()
62
+ + ($ order ->getBaseShippingAmount () - $ order ->getBaseShippingCanceled ()))
63
+ - (abs ((float ) $ order ->getBaseDiscountAmount ()) - abs ((float ) $ order ->getBaseDiscountCanceled ()))
64
+ + ($ order ->getBaseTaxAmount () - $ order ->getBaseTaxCanceled ())
65
+ ) * $ order ->getBaseToGlobalRate ();
120
66
}
121
67
122
68
/**
123
69
* Repeat sql formula from \Magento\SalesRule\Model\ResourceModel\Report\Rule\Createdat::_aggregateByOrder
124
70
*
125
- * @param Order $order
71
+ * @param \Magento\Sales\Model\ Order $order
126
72
* @return float
127
73
*/
128
- private function getTotalAmountActual (Order $ order )
74
+ private function getTotalAmountActual (\ Magento \ Sales \ Model \ Order $ order )
129
75
{
130
76
return (
131
- ($ order ->getBaseSubtotalInvoiced () - $ order ->getSubtotalRefunded ()
132
- + ($ order ->getBaseShippingInvoiced () - $ order ->getBaseShippingRefunded ()))
133
- - abs ((float ) $ order ->getBaseDiscountInvoiced ()) - abs ((float ) $ order ->getBaseDiscountRefunded ())
134
- + $ order ->getBaseTaxInvoiced () - $ order ->getBaseTaxRefunded ()
135
- + ($ order ->getBaseDiscountTaxCompensationInvoiced () - $ order ->getBaseDiscountTaxCompensationRefunded ())
136
- - abs ((float ) $ order ->getBaseShippingDiscountTaxCompensationAmnt ())
137
- ) * $ order ->getBaseToGlobalRate ();
77
+ ($ order ->getBaseSubtotalInvoiced () - $ order ->getSubtotalRefunded ()
78
+ + ($ order ->getBaseShippingInvoiced () - $ order ->getBaseShippingRefunded ()))
79
+ - abs ((float ) $ order ->getBaseDiscountInvoiced ()) - abs ((float ) $ order ->getBaseDiscountRefunded ())
80
+ + $ order ->getBaseTaxInvoiced () - $ order ->getBaseTaxRefunded ()
81
+ ) * $ order ->getBaseToGlobalRate ();
138
82
}
139
83
140
84
/**
@@ -155,127 +99,4 @@ public static function orderParamsDataProvider()
155
99
]
156
100
];
157
101
}
158
-
159
- #[
160
- AppArea('adminhtml ' ),
161
- ConfigFixture('tax/classes/shipping_tax_class ' , 2 , ScopeInterface::SCOPE_STORE ),
162
- ConfigFixture('tax/classes/wrapping_tax_class ' , 0 , ScopeInterface::SCOPE_STORE ),
163
-
164
- ConfigFixture('tax/calculation/algorithm ' , 'TOTAL_BASE_CALCULATION ' , ScopeInterface::SCOPE_STORE ),
165
- ConfigFixture('tax/calculation/based_on ' , 'shipping ' , ScopeInterface::SCOPE_STORE ),
166
- ConfigFixture('tax/calculation/price_includes_tax ' , 1 , ScopeInterface::SCOPE_STORE ),
167
- ConfigFixture('tax/calculation/shipping_includes_tax ' , 1 , ScopeInterface::SCOPE_STORE ),
168
- ConfigFixture('tax/calculation/apply_after_discount ' , 1 , ScopeInterface::SCOPE_STORE ),
169
- ConfigFixture('tax/calculation/discount_tax ' , 1 , ScopeInterface::SCOPE_STORE ),
170
- ConfigFixture('tax/calculation/apply_tax_on ' , 0 , ScopeInterface::SCOPE_STORE ),
171
- ConfigFixture('tax/calculation/cross_border_trade_enabled ' , 1 , ScopeInterface::SCOPE_STORE ),
172
-
173
- ConfigFixture('tax/notification/ignore_discount ' , 0 , ScopeInterface::SCOPE_STORE ),
174
- ConfigFixture('tax/notification/ignore_price_display ' , 0 , ScopeInterface::SCOPE_STORE ),
175
- ConfigFixture('tax/notification/ignore_apply_discount ' , 0 , ScopeInterface::SCOPE_STORE ),
176
-
177
- ConfigFixture('tax/display/type ' , 2 , ScopeInterface::SCOPE_STORE ),
178
- ConfigFixture('tax/display/shipping ' , 2 , ScopeInterface::SCOPE_STORE ),
179
-
180
- ConfigFixture('tax/cart_display/price ' , 2 , ScopeInterface::SCOPE_STORE ),
181
- ConfigFixture('tax/cart_display/subtotal ' , 2 , ScopeInterface::SCOPE_STORE ),
182
- ConfigFixture('tax/cart_display/shipping ' , 2 , ScopeInterface::SCOPE_STORE ),
183
- ConfigFixture('tax/cart_display/full_summary ' , 1 , ScopeInterface::SCOPE_STORE ),
184
- ConfigFixture('tax/cart_display/zero_tax ' , 1 , ScopeInterface::SCOPE_STORE ),
185
-
186
- ConfigFixture('tax/sales_display/price ' , 2 , ScopeInterface::SCOPE_STORE ),
187
- ConfigFixture('tax/sales_display/subtotal ' , 2 , ScopeInterface::SCOPE_STORE ),
188
- ConfigFixture('tax/sales_display/shipping ' , 2 , ScopeInterface::SCOPE_STORE ),
189
- ConfigFixture('tax/sales_display/full_summary ' , 1 , ScopeInterface::SCOPE_STORE ),
190
- ConfigFixture('tax/sales_display/zero_tax ' , 1 , ScopeInterface::SCOPE_STORE ),
191
-
192
- DataFixture(
193
- TaxRateFixture::class,
194
- [
195
- 'code ' => 'US 19% ' ,
196
- 'tax_country_id ' => 'USA ' ,
197
- 'rate ' => 19 ,
198
- ],
199
- 'taxRate '
200
- ),
201
- DataFixture(
202
- TaxRuleFixture::class,
203
- [
204
- 'customer_tax_class_ids ' => [3 ],
205
- 'product_tax_class_ids ' => [2 ],
206
- 'tax_rate_ids ' => ['$taxRate.id$ ' ]
207
- ],
208
- 'taxRule '
209
- ),
210
- DataFixture(
211
- AddressConditionFixture::class,
212
- ['attribute ' => 'base_subtotal_total_incl_tax ' , 'operator ' => '>= ' , 'value ' => 12 ],
213
- 'condition '
214
- ),
215
- DataFixture(
216
- RuleFixture::class,
217
- [
218
- 'website_ids ' => [1 ],
219
- 'customer_group_ids ' => [0 , 1 , 2 , 3 ],
220
- 'coupon_code ' => 'COUPON1 ' ,
221
- 'coupon_type ' => SalesRule::COUPON_TYPE_SPECIFIC ,
222
- 'simple_action ' => SalesRule::BY_PERCENT_ACTION ,
223
- 'uses_per_customer ' => 10 ,
224
- 'discount_amount ' => 10 ,
225
- 'stop_rules_processing ' => true ,
226
- 'conditions ' => ['$condition$ ' ]
227
- ],
228
- 'cartPriceRule '
229
- ),
230
- DataFixture(
231
- Customer::class,
232
- [
233
- 'email ' => 'customer@example.com ' ,
234
- 'password ' => 'password '
235
- ],
236
- 'customer '
237
- ),
238
- DataFixture(ProductFixture::class, ['price ' => 17000 , 'qty ' => 1 , 'special_price ' => 16730 ], as:'product ' ),
239
- DataFixture(CustomerCart::class, ['customer_id ' => '$customer.id$ ' ], as: 'cart ' ),
240
- DataFixture(
241
- AddProductToCartFixture::class,
242
- [
243
- 'cart_id ' => '$cart.id$ ' ,
244
- 'product_id ' => '$product.id$ ' ,
245
- 'qty ' => 1
246
- ]
247
- ),
248
- DataFixture(ApplyCouponFixture::class, ['cart_id ' => '$cart.id$ ' , 'coupon_codes ' => ['COUPON1 ' ]]),
249
- DataFixture(SetBillingAddressFixture::class, ['cart_id ' => '$cart.id$ ' ]),
250
- DataFixture(SetShippingAddressFixture::class, ['cart_id ' => '$cart.id$ ' ]),
251
- DataFixture(SetDeliveryMethodFixture::class, ['cart_id ' => '$cart.id$ ' ]),
252
- DataFixture(SetPaymentMethodFixture::class, ['cart_id ' => '$cart.id$ ' ]),
253
- DataFixture(PlaceOrderFixture::class, ['cart_id ' => '$cart.id$ ' ], 'order ' ),
254
- DataFixture(InvoiceFixture::class, ['order_id ' => '$order.id$ ' ], 'invoice ' ),
255
- DataFixture(ShipmentFixture::class, ['order_id ' => '$order.id$ ' ], 'shipment ' )
256
- ]
257
- public function testCouponsReport (): void
258
- {
259
- $ order = $ this ->fixtures ->get ('order ' );
260
- $ this ->reportResource ->aggregate ();
261
- $ salesRuleReportItem = $ this ->reportCollection ->getFirstItem ();
262
-
263
- $ this ->assertEquals (
264
- round ($ order ->getData ('subtotal_incl_tax ' ), 2 ),
265
- round ($ salesRuleReportItem ['subtotal_amount ' ], 2 )
266
- );
267
- $ this ->assertEquals (
268
- round ($ order ->getData ('base_subtotal_incl_tax ' ), 2 ),
269
- round ($ salesRuleReportItem ['subtotal_amount_actual ' ], 2 )
270
- );
271
-
272
- $ this ->assertEquals (
273
- round ($ this ->getTotalAmount ($ order ), 2 ),
274
- round ($ salesRuleReportItem ['total_amount ' ], 2 )
275
- );
276
- $ this ->assertEquals (
277
- round ($ this ->getTotalAmountActual ($ order ), 2 ),
278
- round ($ salesRuleReportItem ['total_amount_actual ' ], 2 )
279
- );
280
- }
281
102
}
0 commit comments