Skip to content

Commit 6347755

Browse files
committed
Merge remote-tracking branch 'origin/MC-33459' into 2.4-develop-pr23
2 parents 8cea142 + 725af90 commit 6347755

File tree

3 files changed

+113
-53
lines changed

3 files changed

+113
-53
lines changed

dev/tests/integration/testsuite/Magento/Customer/_files/customer_group_rollback.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Framework\Api\SearchCriteriaBuilder;
99
use Magento\Customer\Api\GroupRepositoryInterface;
10+
use Magento\Framework\Registry;
1011
use Magento\TestFramework\Helper\Bootstrap;
1112
use Magento\Framework\ObjectManagerInterface;
1213
use Magento\Framework\Exception\NoSuchEntityException;
@@ -21,10 +22,17 @@
2122
->create();
2223
$groups = $groupRepository->getList($searchCriteria)
2324
->getItems();
25+
26+
/** @var Registry $registry */
27+
$registry = $objectManager->get(Registry::class);
28+
$registry->unregister('isSecureArea');
29+
$registry->register('isSecureArea', true);
2430
foreach ($groups as $group) {
2531
try {
2632
$groupRepository->delete($group);
2733
} catch (NoSuchEntityException $exception) {
2834
//Group already removed
2935
}
3036
}
37+
$registry->unregister('isSecureArea');
38+
$registry->register('isSecureArea', false);

dev/tests/integration/testsuite/Magento/Quote/Model/ShippingMethodManagementTest.php

Lines changed: 85 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
namespace Magento\Quote\Model;
87

98
use Magento\Customer\Api\AddressRepositoryInterface;
@@ -12,26 +11,35 @@
1211
use Magento\Customer\Api\Data\GroupInterface;
1312
use Magento\Customer\Api\GroupRepositoryInterface;
1413
use Magento\Customer\Model\Vat;
14+
use Magento\Customer\Observer\AfterAddressSaveObserver;
1515
use Magento\Framework\Api\SearchCriteriaBuilder;
1616
use Magento\Framework\App\Config\MutableScopeConfigInterface;
17+
use Magento\Framework\DataObject;
18+
use Magento\Framework\Exception\NoSuchEntityException;
1719
use Magento\Framework\ObjectManagerInterface;
1820
use Magento\Quote\Api\CartRepositoryInterface;
21+
use Magento\Quote\Api\Data\AddressInterfaceFactory;
22+
use Magento\Quote\Api\Data\EstimateAddressInterface;
23+
use Magento\Quote\Api\GuestShippingMethodManagementInterface;
1924
use Magento\Quote\Api\ShippingMethodManagementInterface;
25+
use Magento\Quote\Observer\Frontend\Quote\Address\CollectTotalsObserver;
26+
use Magento\Quote\Observer\Frontend\Quote\Address\VatValidator;
2027
use Magento\Store\Model\ScopeInterface;
2128
use Magento\Tax\Api\Data\TaxClassInterface;
2229
use Magento\Tax\Api\TaxClassRepositoryInterface;
2330
use Magento\Tax\Model\ClassModel;
2431
use Magento\Tax\Model\Config as TaxConfig;
2532
use Magento\TestFramework\Helper\Bootstrap;
2633
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
34+
use PHPUnit\Framework\TestCase;
2735

2836
/**
2937
* Test for shipping methods management
3038
*
3139
* @magentoDbIsolation enabled
3240
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3341
*/
34-
class ShippingMethodManagementTest extends \PHPUnit\Framework\TestCase
42+
class ShippingMethodManagementTest extends TestCase
3543
{
3644
/** @var ObjectManagerInterface $objectManager */
3745
private $objectManager;
@@ -56,14 +64,14 @@ protected function setUp()
5664
* @magentoDataFixture Magento/SalesRule/_files/cart_rule_100_percent_off.php
5765
* @magentoDataFixture Magento/Sales/_files/quote_with_customer.php
5866
* @return void
59-
* @throws \Magento\Framework\Exception\NoSuchEntityException
67+
* @throws NoSuchEntityException
6068
*/
6169
public function testRateAppliedToShipping(): void
6270
{
63-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
71+
$objectManager = Bootstrap::getObjectManager();
6472

65-
/** @var \Magento\Quote\Api\CartRepositoryInterface $quoteRepository */
66-
$quoteRepository = $objectManager->create(\Magento\Quote\Api\CartRepositoryInterface::class);
73+
/** @var CartRepositoryInterface $quoteRepository */
74+
$quoteRepository = $objectManager->create(CartRepositoryInterface::class);
6775
$customerQuote = $quoteRepository->getForCustomer(1);
6876
$this->assertEquals(0, $customerQuote->getBaseGrandTotal());
6977
}
@@ -80,17 +88,17 @@ public function testRateAppliedToShipping(): void
8088
*/
8189
public function testTableRateFreeShipping()
8290
{
83-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
84-
/** @var \Magento\Quote\Model\Quote $quote */
85-
$quote = $objectManager->get(\Magento\Quote\Model\Quote::class);
91+
$objectManager = Bootstrap::getObjectManager();
92+
/** @var Quote $quote */
93+
$quote = $objectManager->get(Quote::class);
8694
$quote->load('test01', 'reserved_order_id');
8795
$cartId = $quote->getId();
8896
if (!$cartId) {
8997
$this->fail('quote fixture failed');
9098
}
91-
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
92-
$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
93-
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
99+
/** @var QuoteIdMask $quoteIdMask */
100+
$quoteIdMask = Bootstrap::getObjectManager()
101+
->create(QuoteIdMaskFactory::class)
94102
->create();
95103
$quoteIdMask->load($cartId, 'quote_id');
96104
//Use masked cart Id
@@ -103,10 +111,10 @@ public function testTableRateFreeShipping()
103111
'region_id' => null
104112
]
105113
];
106-
/** @var \Magento\Quote\Api\Data\EstimateAddressInterface $address */
107-
$address = $objectManager->create(\Magento\Quote\Api\Data\EstimateAddressInterface::class, $data);
108-
/** @var \Magento\Quote\Api\GuestShippingMethodManagementInterface $shippingEstimation */
109-
$shippingEstimation = $objectManager->get(\Magento\Quote\Api\GuestShippingMethodManagementInterface::class);
114+
/** @var EstimateAddressInterface $address */
115+
$address = $objectManager->create(EstimateAddressInterface::class, $data);
116+
/** @var GuestShippingMethodManagementInterface $shippingEstimation */
117+
$shippingEstimation = $objectManager->get(GuestShippingMethodManagementInterface::class);
110118
$result = $shippingEstimation->estimateByAddress($cartId, $address);
111119
$this->assertNotEmpty($result);
112120
$expectedResult = [
@@ -134,25 +142,25 @@ public function testTableRateFreeShipping()
134142
*/
135143
public function testTableRateWithCartRuleForFreeShipping()
136144
{
137-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
145+
$objectManager = Bootstrap::getObjectManager();
138146
$quote = $this->getQuote('tableRate');
139147
$cartId = $quote->getId();
140148
if (!$cartId) {
141149
$this->fail('quote fixture failed');
142150
}
143-
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
144-
$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
145-
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
151+
/** @var QuoteIdMask $quoteIdMask */
152+
$quoteIdMask = Bootstrap::getObjectManager()
153+
->create(QuoteIdMaskFactory::class)
146154
->create();
147155
$quoteIdMask->load($cartId, 'quote_id');
148156
//Use masked cart Id
149157
$cartId = $quoteIdMask->getMaskedId();
150-
$addressFactory = $this->objectManager->get(\Magento\Quote\Api\Data\AddressInterfaceFactory::class);
158+
$addressFactory = $this->objectManager->get(AddressInterfaceFactory::class);
151159
/** @var \Magento\Quote\Api\Data\AddressInterface $address */
152160
$address = $addressFactory->create();
153161
$address->setCountryId('US');
154-
/** @var \Magento\Quote\Api\GuestShippingMethodManagementInterface $shippingEstimation */
155-
$shippingEstimation = $objectManager->get(\Magento\Quote\Api\GuestShippingMethodManagementInterface::class);
162+
/** @var GuestShippingMethodManagementInterface $shippingEstimation */
163+
$shippingEstimation = $objectManager->get(GuestShippingMethodManagementInterface::class);
156164
$result = $shippingEstimation->estimateByExtendedAddress($cartId, $address);
157165
$this->assertCount(1, $result);
158166
$rate = reset($result);
@@ -234,17 +242,17 @@ public function testEstimateByAddress()
234242
*/
235243
private function executeTestFlow($flatRateAmount, $tableRateAmount)
236244
{
237-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
238-
/** @var \Magento\Quote\Model\Quote $quote */
239-
$quote = $objectManager->get(\Magento\Quote\Model\Quote::class);
245+
$objectManager = Bootstrap::getObjectManager();
246+
/** @var Quote $quote */
247+
$quote = $objectManager->get(Quote::class);
240248
$quote->load('test01', 'reserved_order_id');
241249
$cartId = $quote->getId();
242250
if (!$cartId) {
243251
$this->fail('quote fixture failed');
244252
}
245-
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
246-
$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
247-
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
253+
/** @var QuoteIdMask $quoteIdMask */
254+
$quoteIdMask = Bootstrap::getObjectManager()
255+
->create(QuoteIdMaskFactory::class)
248256
->create();
249257
$quoteIdMask->load($cartId, 'quote_id');
250258
//Use masked cart Id
@@ -257,17 +265,17 @@ private function executeTestFlow($flatRateAmount, $tableRateAmount)
257265
'region_id' => null
258266
]
259267
];
260-
/** @var \Magento\Quote\Api\Data\EstimateAddressInterface $address */
261-
$address = $objectManager->create(\Magento\Quote\Api\Data\EstimateAddressInterface::class, $data);
262-
/** @var \Magento\Quote\Api\GuestShippingMethodManagementInterface $shippingEstimation */
263-
$shippingEstimation = $objectManager->get(\Magento\Quote\Api\GuestShippingMethodManagementInterface::class);
268+
/** @var EstimateAddressInterface $address */
269+
$address = $objectManager->create(EstimateAddressInterface::class, $data);
270+
/** @var GuestShippingMethodManagementInterface $shippingEstimation */
271+
$shippingEstimation = $objectManager->get(GuestShippingMethodManagementInterface::class);
264272
$result = $shippingEstimation->estimateByAddress($cartId, $address);
265273
$this->assertNotEmpty($result);
266274
$expectedResult = [
267275
'tablerate' => [
268-
'method_code' => 'bestway',
269-
'amount' => $tableRateAmount
270-
],
276+
'method_code' => 'bestway',
277+
'amount' => $tableRateAmount
278+
],
271279
'flatrate' => [
272280
'method_code' => 'flatrate',
273281
'amount' => $flatRateAmount
@@ -295,17 +303,15 @@ private function executeTestFlow($flatRateAmount, $tableRateAmount)
295303
*/
296304
public function testEstimateByAddressWithInclExclTaxAndVATGroup()
297305
{
298-
$this->markTestSkipped('MC-33463');
299-
300-
/** @var CustomerRepositoryInterface $customerRepository */
301-
$customerRepository = $this->objectManager->get(CustomerRepositoryInterface::class);
302-
$customer = $customerRepository->get('customer@example.com');
303-
304306
/** @var GroupInterface $customerGroup */
305307
$customerGroup = $this->findCustomerGroupByCode('custom_group');
308+
$this->mockCustomerVat((int)$customerGroup->getId());
309+
306310
$customerGroup->setTaxClassId($this->getTaxClass('CustomerTaxClass')->getClassId());
307311
$this->groupRepository->save($customerGroup);
308-
312+
/** @var CustomerRepositoryInterface $customerRepository */
313+
$customerRepository = $this->objectManager->get(CustomerRepositoryInterface::class);
314+
$customer = $customerRepository->get('customer@example.com');
309315
$customer->setGroupId($customerGroup->getId());
310316
$customer->setTaxvat('12');
311317
$customerRepository->save($customer);
@@ -322,11 +328,46 @@ public function testEstimateByAddressWithInclExclTaxAndVATGroup()
322328
$this->assertEquals(5.0, $result[0]->getPriceExclTax());
323329
}
324330

331+
/**
332+
* Create a test double fot customer vat class
333+
*
334+
* @param int $customerGroupId
335+
*/
336+
private function mockCustomerVat(int $customerGroupId): void
337+
{
338+
$gatewayResponse = new DataObject([
339+
'is_valid' => false,
340+
'request_date' => '',
341+
'request_identifier' => '123123123',
342+
'request_success' => false,
343+
'request_message' => __('Error during VAT Number verification.'),
344+
]);
345+
$customerVat = $this->createPartialMock(
346+
Vat::class,
347+
[
348+
'checkVatNumber',
349+
'isCountryInEU',
350+
'getCustomerGroupIdBasedOnVatNumber',
351+
'getMerchantCountryCode',
352+
'getMerchantVatNumber'
353+
]
354+
);
355+
$customerVat->method('checkVatNumber')->willReturn($gatewayResponse);
356+
$customerVat->method('isCountryInEU')->willReturn(true);
357+
$customerVat->method('getMerchantCountryCode')->willReturn('GB');
358+
$customerVat->method('getMerchantVatNumber')->willReturn('11111');
359+
$customerVat->method('getCustomerGroupIdBasedOnVatNumber')->willReturn($customerGroupId);
360+
$this->objectManager->removeSharedInstance(Vat::class);
361+
$this->objectManager->addSharedInstance($customerVat, Vat::class);
362+
363+
// Remove instances where the customer vat object is cached
364+
$this->objectManager->removeSharedInstance(CollectTotalsObserver::class);
365+
}
366+
325367
/**
326368
* Find the group with a given code.
327369
*
328370
* @param string $code
329-
*
330371
* @return GroupInterface
331372
*/
332373
protected function findCustomerGroupByCode(string $code): ?GroupInterface

dev/tests/integration/testsuite/Magento/Tax/_files/tax_classes_de_rollback.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
declare(strict_types=1);
77

88
use Magento\Framework\Api\SearchCriteriaBuilder;
9+
use Magento\Framework\Registry;
10+
use Magento\Tax\Api\TaxClassManagementInterface;
911
use Magento\Tax\Model\ClassModel;
1012
use Magento\TestFramework\Helper\Bootstrap;
1113
use Magento\Framework\ObjectManagerInterface;
@@ -18,37 +20,44 @@
1820

1921
/** @var ObjectManagerInterface $objectManager */
2022
$objectManager = Bootstrap::getObjectManager();
21-
$taxClasses = [
22-
'CustomerTaxClass',
23-
'ProductTaxClass',
24-
];
2523
$taxRuleRepository = $objectManager->get(TaxRuleRepositoryInterface::class);
2624
/** @var SearchCriteriaBuilder $searchBuilder */
2725
$searchBuilder = $objectManager->get(SearchCriteriaBuilder::class);
2826
$searchCriteria = $searchBuilder->addFilter(Rule::KEY_CODE, 'Test Rule')
2927
->create();
3028
$taxRules = $taxRuleRepository->getList($searchCriteria)
3129
->getItems();
30+
31+
/** @var Registry $registry */
32+
$registry = $objectManager->get(Registry::class);
33+
$registry->unregister('isSecureArea');
34+
$registry->register('isSecureArea', true);
3235
foreach ($taxRules as $taxRule) {
3336
try {
3437
$taxRuleRepository->delete($taxRule);
3538
} catch (NoSuchEntityException $exception) {
3639
//Rule already removed
3740
}
3841
}
39-
$searchCriteria = $searchBuilder->addFilter(ClassModel::KEY_NAME, $taxClasses, 'in')
40-
->create();
41-
/** @var TaxClassRepositoryInterface $groupRepository */
42+
43+
/** @var TaxClassRepositoryInterface $taxClassRepository */
4244
$taxClassRepository = $objectManager->get(TaxClassRepositoryInterface::class);
43-
$taxClasses = $taxClassRepository->getList($searchCriteria)
44-
->getItems();
45+
$searchCriteria = $searchBuilder->addFilter(ClassModel::KEY_NAME, 'CustomerTaxClass')
46+
->addFilter(ClassModel::KEY_TYPE, TaxClassManagementInterface::TYPE_CUSTOMER)
47+
->create();
48+
$taxClasses = $taxClassRepository->getList($searchCriteria)->getItems();
49+
$searchCriteria = $searchBuilder->addFilter(ClassModel::KEY_NAME, 'ProductTaxClass')
50+
->addFilter(ClassModel::KEY_TYPE, TaxClassManagementInterface::TYPE_PRODUCT)
51+
->create();
52+
$taxClasses = array_merge($taxClasses, $taxClassRepository->getList($searchCriteria)->getItems());
4553
foreach ($taxClasses as $taxClass) {
4654
try {
4755
$taxClassRepository->delete($taxClass);
4856
} catch (NoSuchEntityException $exception) {
4957
//TaxClass already removed
5058
}
5159
}
60+
5261
$searchCriteria = $searchBuilder->addFilter(Rate::KEY_CODE, 'Denmark')
5362
->create();
5463
/** @var TaxRateRepositoryInterface $groupRepository */
@@ -62,3 +71,5 @@
6271
//TaxRate already removed
6372
}
6473
}
74+
$registry->unregister('isSecureArea');
75+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)