32
32
use Magento \TestFramework \Helper \Bootstrap ;
33
33
use Magento \TestFramework \Quote \Model \GetQuoteByReservedOrderId ;
34
34
use PHPUnit \Framework \TestCase ;
35
-
35
+ use Magento \ Quote \ Api \ CouponManagementInterface ;
36
36
/**
37
37
* Test for shipping methods management
38
38
*
@@ -77,21 +77,22 @@ public function testRateAppliedToShipping(): void
77
77
}
78
78
79
79
/**
80
+ * Test table rate amount for the cart that contains some items with free shipping applied.
81
+ *
80
82
* @magentoConfigFixture current_store carriers/tablerate/active 1
81
83
* @magentoConfigFixture current_store carriers/flatrate/active 0
82
84
* @magentoConfigFixture current_store carriers/freeshipping/active 0
83
- * @magentoConfigFixture current_store carriers/tablerate/condition_name package_qty
84
- * @magentoDataFixture Magento/SalesRule/_files/cart_rule_free_shipping_by_cart.php
85
- * @magentoDataFixture Magento/Sales/_files/quote.php
86
- * @magentoDataFixture Magento/OfflineShipping/_files/tablerates.php
85
+ * @magentoConfigFixture current_store carriers/tablerate/condition_name package_value_with_discount
86
+ * @magentoDataFixture Magento/Catalog/_files/categories.php
87
+ * @magentoDataFixture Magento/SalesRule/_files/cart_rule_free_shipping_by_category.php
88
+ * @magentoDataFixture Magento/Sales/_files/quote_with_multiple_products.php
89
+ * @magentoDataFixture Magento/OfflineShipping/_files/tablerates_price.php
87
90
* @return void
88
91
*/
89
- public function testTableRateFreeShipping ()
92
+ public function testTableRateWithCartRuleForFreeShipping ()
90
93
{
91
94
$ objectManager = Bootstrap::getObjectManager ();
92
- /** @var Quote $quote */
93
- $ quote = $ objectManager ->get (Quote::class);
94
- $ quote ->load ('test01 ' , 'reserved_order_id ' );
95
+ $ quote = $ this ->getQuote ('tableRate ' );
95
96
$ cartId = $ quote ->getId ();
96
97
if (!$ cartId ) {
97
98
$ this ->fail ('quote fixture failed ' );
@@ -103,44 +104,40 @@ public function testTableRateFreeShipping()
103
104
$ quoteIdMask ->load ($ cartId , 'quote_id ' );
104
105
//Use masked cart Id
105
106
$ cartId = $ quoteIdMask ->getMaskedId ();
106
- $ data = [
107
- 'data ' => [
108
- 'country_id ' => "US " ,
109
- 'postcode ' => null ,
110
- 'region ' => null ,
111
- 'region_id ' => null
112
- ]
113
- ];
114
- /** @var EstimateAddressInterface $address */
115
- $ address = $ objectManager ->create (EstimateAddressInterface::class, $ data );
107
+ $ addressFactory = $ this ->objectManager ->get (AddressInterfaceFactory::class);
108
+ /** @var \Magento\Quote\Api\Data\AddressInterface $address */
109
+ $ address = $ addressFactory ->create ();
110
+ $ address ->setCountryId ('US ' );
116
111
/** @var GuestShippingMethodManagementInterface $shippingEstimation */
117
112
$ shippingEstimation = $ objectManager ->get (GuestShippingMethodManagementInterface::class);
118
- $ result = $ shippingEstimation ->estimateByAddress ($ cartId , $ address );
119
- $ this ->assertNotEmpty ($ result );
113
+ $ result = $ shippingEstimation ->estimateByExtendedAddress ($ cartId , $ address );
114
+ $ this ->assertCount (1 , $ result );
115
+ $ rate = reset ($ result );
120
116
$ expectedResult = [
121
- 'method_code ' => 'bestway ' ,
122
- 'amount ' => 0
117
+ 'method_code ' => 'bestway ' ,
118
+ 'amount ' => 10
123
119
];
124
- foreach ($ result as $ rate ) {
125
- $ this ->assertEquals ($ expectedResult ['amount ' ], $ rate ->getAmount ());
126
- $ this ->assertEquals ($ expectedResult ['method_code ' ], $ rate ->getMethodCode ());
127
- }
120
+ $ this ->assertEquals ($ expectedResult ['method_code ' ], $ rate ->getMethodCode ());
121
+ $ this ->assertEquals ($ expectedResult ['amount ' ], $ rate ->getAmount ());
128
122
}
129
123
130
124
/**
131
- * Test table rate amount for the cart that contains some items with free shipping applied.
125
+ * Test table rate with zero amount is available for the cart when discount coupon cart price rule to all items
126
+ * and freeshipping cart price rule is applied when order subtotal is greater than specified amount.
132
127
*
133
128
* @magentoConfigFixture current_store carriers/tablerate/active 1
134
129
* @magentoConfigFixture current_store carriers/flatrate/active 0
135
130
* @magentoConfigFixture current_store carriers/freeshipping/active 0
136
- * @magentoConfigFixture current_store carriers/tablerate/condition_name package_value_with_discount
131
+ * @magentoConfigFixture default_store carriers/tablerate/condition_name package_value_with_discount
137
132
* @magentoDataFixture Magento/Catalog/_files/categories.php
138
- * @magentoDataFixture Magento/SalesRule/_files/cart_rule_free_shipping_by_category.php
133
+ * @magentoDataFixture Magento/SalesRule/_files/cart_rule_free_shipping_subtotal_equals_more_than_30.php
134
+ * @magentoDataFixture Magento/SalesRule/_files/cart_rule_20_percent_off_with_coupon_no_condition.php
139
135
* @magentoDataFixture Magento/Sales/_files/quote_with_multiple_products.php
140
136
* @magentoDataFixture Magento/OfflineShipping/_files/tablerates_price.php
137
+ *
141
138
* @return void
142
139
*/
143
- public function testTableRateWithCartRuleForFreeShipping ()
140
+ public function testTableRateWithZeroPriceShownWhenDiscountCouponAndFreeShippingCartRuleApplied ()
144
141
{
145
142
$ objectManager = Bootstrap::getObjectManager ();
146
143
$ quote = $ this ->getQuote ('tableRate ' );
@@ -159,14 +156,18 @@ public function testTableRateWithCartRuleForFreeShipping()
159
156
/** @var \Magento\Quote\Api\Data\AddressInterface $address */
160
157
$ address = $ addressFactory ->create ();
161
158
$ address ->setCountryId ('US ' );
159
+ /** @var CouponManagementInterface $couponManagement */
160
+ $ couponManagement = Bootstrap::getObjectManager ()->get (CouponManagementInterface::class);
161
+ $ couponManagement ->set ($ quote ->getId (), '123 ' );
162
162
/** @var GuestShippingMethodManagementInterface $shippingEstimation */
163
163
$ shippingEstimation = $ objectManager ->get (GuestShippingMethodManagementInterface::class);
164
164
$ result = $ shippingEstimation ->estimateByExtendedAddress ($ cartId , $ address );
165
165
$ this ->assertCount (1 , $ result );
166
166
$ rate = reset ($ result );
167
+
167
168
$ expectedResult = [
168
- 'method_code ' => 'bestway ' ,
169
- 'amount ' => 10
169
+ 'method_code ' => 'bestway ' ,
170
+ 'amount ' => 0
170
171
];
171
172
$ this ->assertEquals ($ expectedResult ['method_code ' ], $ rate ->getMethodCode ());
172
173
$ this ->assertEquals ($ expectedResult ['amount ' ], $ rate ->getAmount ());
0 commit comments