-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6840 from magento-tsg/2.4-develop-pr145
[Arrows] Fixes for 2.4 (pr145) (2.4-develop)
- Loading branch information
Showing
6 changed files
with
116 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
use Magento\Catalog\Model\ResourceModel\Product as ProductResource; | ||
use Magento\Framework\Webapi\Rest\Request; | ||
use Magento\Integration\Api\CustomerTokenServiceInterface; | ||
use Magento\Quote\Model\Quote; | ||
use Magento\Quote\Model\QuoteIdMask; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\ObjectManager; | ||
use Magento\TestFramework\TestCase\WebapiAbstract; | ||
|
@@ -29,6 +31,11 @@ class CartAddingItemsTest extends WebapiAbstract | |
*/ | ||
private $productResource; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $createdQuotes = []; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
|
@@ -38,6 +45,71 @@ protected function setUp(): void | |
$this->productResource = $this->objectManager->get(ProductResource::class); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
/** @var Quote $quote */ | ||
$quote = $this->objectManager->create(Quote::class); | ||
foreach ($this->createdQuotes as $quoteId) { | ||
$quote->load($quoteId); | ||
$quote->delete(); | ||
} | ||
} | ||
|
||
/** | ||
* Test qty for cart after adding grouped product qty specified only for goruped product. | ||
* | ||
* @magentoApiDataFixture Magento/GroupedProduct/_files/product_grouped_with_simple.php | ||
* @magentoApiDataFixture Magento/Customer/_files/customer_one_address.php | ||
* @return void | ||
*/ | ||
public function testAddToCartGroupedWithParentQuantity(): void | ||
{ | ||
$this->_markTestAsRestOnly(); | ||
|
||
// Get customer ID token | ||
/** @var CustomerTokenServiceInterface $customerTokenService */ | ||
$customerTokenService = $this->objectManager->create(CustomerTokenServiceInterface::class); | ||
$token = $customerTokenService->createCustomerAccessToken( | ||
'[email protected]', | ||
'password' | ||
); | ||
|
||
// Creating empty cart for registered customer. | ||
$serviceInfo = [ | ||
'rest' => [ | ||
'resourcePath' => '/V1/carts/mine', | ||
'httpMethod' => Request::HTTP_METHOD_POST, | ||
'token' => $token | ||
] | ||
]; | ||
|
||
$quoteId = $this->_webApiCall($serviceInfo, ['customerId' => 999]); // customerId 999 will get overridden | ||
$this->assertGreaterThan(0, $quoteId); | ||
|
||
/** @var CartRepositoryInterface $cartRepository */ | ||
$cartRepository = $this->objectManager->get(CartRepositoryInterface::class); | ||
$quote = $cartRepository->get($quoteId); | ||
|
||
$quoteItems = $quote->getItemsCollection(); | ||
foreach ($quoteItems as $item) { | ||
$quote->removeItem($item->getId())->save(); | ||
} | ||
|
||
$requestData = [ | ||
'cartItem' => [ | ||
'quote_id' => $quoteId, | ||
'sku' => 'grouped', | ||
'qty' => 7 | ||
] | ||
]; | ||
$this->_webApiCall($this->getServiceInfoAddToCart($token), $requestData); | ||
|
||
foreach ($quote->getAllItems() as $item) { | ||
$this->assertEquals(7, $item->getQty()); | ||
} | ||
$this->createdQuotes[] = $quoteId; | ||
} | ||
|
||
/** | ||
* Test price for cart after adding product to. | ||
* | ||
|
@@ -94,10 +166,11 @@ public function testPriceForCreatingQuoteFromEmptyCart() | |
$paymentInfo = $this->_webApiCall($serviceInfoForGettingPaymentInfo); | ||
$this->assertEquals($paymentInfo['totals']['grand_total'], 10); | ||
|
||
/** @var \Magento\Quote\Model\Quote $quote */ | ||
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class); | ||
$quote->load($quoteId); | ||
$quote->delete(); | ||
$this->createdQuotes[] = $quoteId; | ||
// /** @var \Magento\Quote\Model\Quote $quote */ | ||
// $quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class); | ||
// $quote->load($quoteId); | ||
// $quote->delete(); | ||
} | ||
|
||
/** | ||
|
@@ -163,6 +236,7 @@ public function testAddToCartGroupedCustomQuantity(): void | |
foreach ($quote->getAllItems() as $item) { | ||
$this->assertEquals($qtyData[$item->getProductId()], $item->getQty()); | ||
} | ||
$this->createdQuotes[] = $quoteId; | ||
} | ||
|
||
/** | ||
|
@@ -210,6 +284,8 @@ public function testAddToCartGroupedCustomQuantityNotAllParamsSpecified(): void | |
] | ||
]; | ||
|
||
$this->createdQuotes[] = $quoteId; | ||
|
||
$this->expectException(\Exception::class); | ||
$this->expectExceptionMessage('Please specify id and qty for grouped options.'); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,17 +18,22 @@ | |
$registry->register('isSecureArea', true); | ||
/** @var CustomerRepositoryInterface $customerRepo */ | ||
$customerRepo = $objectManager->get(CustomerRepositoryInterface::class); | ||
try { | ||
$customer = $customerRepo->get('[email protected]'); | ||
/** @var AddressRepositoryInterface $addressRepo */ | ||
$addressRepo = $objectManager->get(AddressRepositoryInterface::class); | ||
foreach ($customer->getAddresses() as $address) { | ||
$addressRepo->delete($address); | ||
$customersEmails = [ | ||
'[email protected]', | ||
'[email protected]', | ||
]; | ||
$addressRepo = $objectManager->get(AddressRepositoryInterface::class); | ||
foreach ($customersEmails as $customerEmail) { | ||
try { | ||
$customer = $customerRepo->get($customerEmail); | ||
foreach ($customer->getAddresses() as $address) { | ||
$addressRepo->delete($address); | ||
} | ||
$customerRepo->delete($customer); | ||
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock | ||
} catch (NoSuchEntityException $exception) { | ||
//Already deleted | ||
} | ||
$customerRepo->delete($customer); | ||
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock | ||
} catch (NoSuchEntityException $exception) { | ||
//Already deleted | ||
} | ||
$registry->unregister('isSecureArea'); | ||
$registry->register('isSecureArea', false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters