-
Notifications
You must be signed in to change notification settings - Fork 9.4k
#40235 - Conditionally process collectTotal for CartItemPrices GraphQl based on params in the request #40289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
senthilengg
wants to merge
21
commits into
magento:2.4-develop
Choose a base branch
from
senthilengg:FixFor-40235
base: 2.4-develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+245
−12
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
fddd1b6
#40235 - Conditionally process collectTotal only if the value of requ…
b352228
#40235 - Adding the missed Discount
ae4d79f
Merge branch '2.4-develop' into FixFor-40235
senthilengg 8e7681a
Merge branch '2.4-develop' into FixFor-40235
senthilengg a15df22
#40235 - Fixed Test Failures & added unit test
f4f87f8
#40235 - Removed Bundle product dependency
1d3f9ef
#40235 - Fixed Static Test Failures
0b047b9
Merge branch '2.4-develop' into FixFor-40235
senthilengg 099bb97
Merge branch '2.4-develop' into FixFor-40235
senthilengg b216034
Merge branch '2.4-develop' into FixFor-40235
senthilengg 18095f9
Merge branch '2.4-develop' into FixFor-40235
senthilengg 86092fa
Merge branch '2.4-develop' into FixFor-40235
senthilengg 50e9916
Merge branch '2.4-develop' into FixFor-40235
senthilengg ae280b8
Merge branch '2.4-develop' into FixFor-40235
senthilengg ad6f4d6
Merge branch '2.4-develop' into FixFor-40235
senthilengg b7d0fcc
Merge branch '2.4-develop' into FixFor-40235
senthilengg 3757e5a
Merge branch '2.4-develop' into FixFor-40235
senthilengg 988ae59
Merge branch '2.4-develop' into FixFor-40235
senthilengg 45a4894
Merge branch '2.4-develop' into FixFor-40235
engcom-Hotel 459592d
#40235 - Addressing review comments
4fbf031
Merge branch '2.4-develop' into FixFor-40235
senthilengg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
215 changes: 215 additions & 0 deletions
215
app/code/Magento/QuoteGraphQl/Test/Unit/Model/Resolver/CartItemPricesTest.php
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,215 @@ | ||
| <?php | ||
| /** | ||
| * Copyright 2024 Adobe | ||
| * All Rights Reserved. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Magento\QuoteGraphQl\Test\Unit\Model\Resolver; | ||
|
|
||
| use Magento\Framework\Exception\LocalizedException; | ||
| use Magento\Framework\GraphQl\Config\Element\Field; | ||
| use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
| use Magento\GraphQl\Model\Query\Context; | ||
| use Magento\Quote\Model\Quote; | ||
| use Magento\Quote\Model\Quote\Item; | ||
| use Magento\QuoteGraphQl\Model\Cart\TotalsCollector; | ||
| use Magento\QuoteGraphQl\Model\Resolver\CartItemPrices; | ||
| use Magento\QuoteGraphQl\Model\GetDiscounts; | ||
| use Magento\Framework\Pricing\PriceCurrencyInterface; | ||
| use Magento\QuoteGraphQl\Model\GetOptionsRegularPrice; | ||
| use Magento\Framework\Api\ExtensionAttributesInterface; | ||
| use Magento\Catalog\Model\Product; | ||
| use PHPUnit\Framework\TestCase; | ||
| use PHPUnit\Framework\MockObject\MockObject; | ||
|
|
||
| /** | ||
| * @see CartItemPrices | ||
| * @SuppressWarnings(PHPMD.CouplingBetweenObjects) | ||
| */ | ||
| class CartItemPricesTest extends TestCase | ||
| { | ||
| /** | ||
| * @var CartItemPrices | ||
| */ | ||
| private CartItemPrices $cartItemPrices; | ||
|
|
||
| /** | ||
| * @var TotalsCollector|MockObject | ||
| */ | ||
| private TotalsCollector $totalsCollectorMock; | ||
|
|
||
| /** | ||
| * @var GetDiscounts |MockObject | ||
| */ | ||
| private GetDiscounts $getDiscountsMock; | ||
|
|
||
| /** | ||
| * @var PriceCurrencyInterface |MockObject | ||
| */ | ||
| private PriceCurrencyInterface $priceCurrencyMock; | ||
|
|
||
| /** | ||
| * @var GetOptionsRegularPrice |MockObject | ||
| */ | ||
| private GetOptionsRegularPrice $getOptionsRegularPriceMock; | ||
|
|
||
| /** | ||
| * @var Field|MockObject | ||
| */ | ||
| private Field $fieldMock; | ||
|
|
||
| /** | ||
| * @var ResolveInfo|MockObject | ||
| */ | ||
| private ResolveInfo $resolveInfoMock; | ||
|
|
||
| /** | ||
| * @var Context|MockObject | ||
| */ | ||
| private Context $contextMock; | ||
|
|
||
| /** | ||
| * @var Quote|MockObject | ||
| */ | ||
| private Quote $quoteMock; | ||
|
|
||
| /** | ||
| * @var Item|MockObject | ||
| */ | ||
| private Item $itemMock; | ||
|
|
||
| /** | ||
| * @var Product|MockObject | ||
| */ | ||
| private Product $productMock; | ||
|
|
||
| /** | ||
| * @var ExtensionAttributesInterface|MockObject | ||
| */ | ||
| private ExtensionAttributesInterface $itemExtensionMock; | ||
|
|
||
| /** | ||
| * @var array | ||
| */ | ||
| private array $valueMock = []; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| $this->totalsCollectorMock = $this->createMock(TotalsCollector::class); | ||
| $this->getDiscountsMock = $this->createMock(GetDiscounts::class); | ||
| $this->priceCurrencyMock = $this->createMock(PriceCurrencyInterface::class); | ||
| $this->getOptionsRegularPriceMock = $this->createMock(GetOptionsRegularPrice::class); | ||
| $this->productMock = $this->getMockBuilder(Product::class) | ||
| ->disableOriginalConstructor() | ||
| ->onlyMethods(['getCustomOption']) | ||
| ->getMock(); | ||
| $this->fieldMock = $this->createMock(Field::class); | ||
| $this->resolveInfoMock = $this->createMock(ResolveInfo::class); | ||
| $this->contextMock = $this->createMock(Context::class); | ||
| $this->quoteMock = $this->getMockBuilder(Quote::class) | ||
| ->disableOriginalConstructor() | ||
| ->addMethods(['getQuoteCurrencyCode']) | ||
| ->getMock(); | ||
| $this->itemMock = $this->getMockBuilder(Item::class) | ||
| ->addMethods([ | ||
| 'getPriceInclTax', 'getRowTotal', | ||
| 'getRowTotalInclTax', 'getDiscountAmount' | ||
| ]) | ||
| ->onlyMethods([ | ||
| 'getCalculationPrice', 'getQuote', 'getExtensionAttributes', | ||
| 'getProduct', 'getOriginalPrice' | ||
| ]) | ||
| ->disableOriginalConstructor() | ||
| ->getMock(); | ||
| $this->itemExtensionMock = $this->getMockBuilder( | ||
| ExtensionAttributesInterface::class | ||
| )->addMethods(['getDiscounts'])->getMockForAbstractClass(); | ||
|
|
||
| $this->cartItemPrices = new CartItemPrices( | ||
| $this->totalsCollectorMock, | ||
| $this->getDiscountsMock, | ||
| $this->priceCurrencyMock, | ||
| $this->getOptionsRegularPriceMock | ||
| ); | ||
| } | ||
|
|
||
| public function testResolve(): void | ||
| { | ||
| $this->valueMock = ['model' => $this->itemMock]; | ||
|
|
||
| $this->resolveInfoMock->expects($this->once()) | ||
| ->method('getFieldSelection') | ||
| ->with(1) | ||
| ->willReturn([]); | ||
|
|
||
| $this->itemMock | ||
| ->expects($this->exactly(2)) | ||
| ->method('getQuote') | ||
| ->willReturn($this->quoteMock); | ||
|
|
||
| $this->quoteMock | ||
| ->expects($this->once()) | ||
| ->method('getQuoteCurrencyCode') | ||
| ->willReturn('USD'); | ||
|
|
||
| $this->itemMock | ||
| ->expects($this->once()) | ||
| ->method('getDiscountAmount'); | ||
|
|
||
| $this->itemMock | ||
| ->expects($this->once()) | ||
| ->method('getCalculationPrice'); | ||
|
|
||
| $this->itemMock | ||
| ->expects($this->once()) | ||
| ->method('getPriceInclTax'); | ||
|
|
||
| $this->itemMock | ||
| ->expects($this->any()) | ||
| ->method('getOriginalPrice') | ||
| ->willReturn(0); | ||
|
|
||
| $this->itemMock | ||
| ->expects($this->once()) | ||
| ->method('getRowTotal'); | ||
|
|
||
| $this->itemMock | ||
| ->expects($this->once()) | ||
| ->method('getRowTotalInclTax'); | ||
|
|
||
| $this->itemMock | ||
| ->expects($this->once()) | ||
| ->method('getExtensionAttributes') | ||
| ->willReturn($this->itemExtensionMock); | ||
|
|
||
| $this->itemMock | ||
| ->expects($this->any()) | ||
| ->method('getProduct') | ||
| ->willReturn($this->productMock); | ||
|
|
||
| $this->productMock | ||
| ->expects($this->exactly(2)) | ||
| ->method('getCustomOption') | ||
| ->willReturn(null); | ||
|
|
||
| $this->itemExtensionMock | ||
| ->expects($this->once()) | ||
| ->method('getDiscounts') | ||
| ->willReturn([]); | ||
|
|
||
| $this->getDiscountsMock | ||
| ->expects($this->once()) | ||
| ->method('execute') | ||
| ->with($this->quoteMock, []); | ||
|
|
||
| $this->cartItemPrices->resolve($this->fieldMock, $this->contextMock, $this->resolveInfoMock, $this->valueMock); | ||
| } | ||
|
|
||
| public function testResolveWithoutModelInValueParameter(): void | ||
| { | ||
| $this->expectException(LocalizedException::class); | ||
| $this->expectExceptionMessage('"model" value should be specified'); | ||
| $this->cartItemPrices->resolve($this->fieldMock, $this->contextMock, $this->resolveInfoMock, $this->valueMock); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.