Skip to content

Commit 2ad76d0

Browse files
committed
ACP2E-3407: Gift Card Product | Cart Merge is merging Gift Cards
1 parent 0c48581 commit 2ad76d0

File tree

1 file changed

+123
-0
lines changed
  • dev/tests/integration/testsuite/Magento/Quote/Model/Quote/Item

1 file changed

+123
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace integration\testsuite\Magento\Quote\Model\Quote\Item;
9+
10+
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\Framework\ObjectManagerInterface;
13+
use Magento\Framework\DataObject;
14+
use Magento\Catalog\Api\ProductRepositoryInterface;
15+
use Magento\Catalog\Api\Data\ProductInterface;
16+
use Magento\Catalog\Api\Data\ProductCustomOptionInterface;
17+
use Magento\Catalog\Model\Product\Option;
18+
use Magento\Quote\Model\Quote;
19+
use Magento\Quote\Model\Quote\Item\Compare;
20+
use Magento\TestFramework\Helper\Bootstrap;
21+
use PHPUnit\Framework\TestCase;
22+
23+
class CompareTest extends TestCase
24+
{
25+
/**
26+
* @var Compare
27+
*/
28+
private $compare;
29+
30+
/**
31+
* @var ObjectManagerInterface
32+
*/
33+
private $objectManager;
34+
35+
/**
36+
* @var ProductRepositoryInterface
37+
*/
38+
private $productRepository;
39+
40+
/**
41+
* @var Quote
42+
*/
43+
private $quote1;
44+
45+
/**
46+
* @var Quote
47+
*/
48+
private $quote2;
49+
50+
/**
51+
* @var Quote
52+
*/
53+
private $quote3;
54+
55+
/**
56+
* @inheritdoc
57+
*/
58+
protected function setUp(): void
59+
{
60+
$this->objectManager = Bootstrap::getObjectManager();
61+
$this->compare = $this->objectManager->create(Compare::class);
62+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
63+
$this->quote1 = $this->objectManager->create(Quote::class);
64+
$this->quote2 = $this->objectManager->create(Quote::class);
65+
$this->quote3 = $this->objectManager->create(Quote::class);
66+
}
67+
68+
/**
69+
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_custom_options.php
70+
* @return void
71+
* @throws NoSuchEntityException
72+
* @throws LocalizedException
73+
*/
74+
public function testCompare(): void
75+
{
76+
$this->quote1->setReservedOrderId('test_order_item_with_custom_options1');
77+
$this->quote2->setReservedOrderId('test_order_item_with_custom_options2');
78+
$this->quote2->setReservedOrderId('test_order_item_with_custom_options3');
79+
80+
$product = $this->productRepository->get('simple_with_custom_options', true, null, true);
81+
82+
$options = $this->selectOptions($product, 'test1');
83+
$requestInfo = new DataObject(['qty' => 1, 'options' => $options]);
84+
$this->quote1->addProduct($product, $requestInfo);
85+
$items1 = $this->quote1->getAllItems();
86+
87+
$options = $this->selectOptions($product, 'test2');
88+
$requestInfo = new DataObject(['qty' => 1, 'options' => $options]);
89+
$this->quote2->addProduct($product, $requestInfo);
90+
$items2 = $this->quote2->getAllItems();
91+
92+
$options = $this->selectOptions($product, 'test1');
93+
$requestInfo = new DataObject(['qty' => 1, 'options' => $options]);
94+
$this->quote3->addProduct($product, $requestInfo);
95+
$items3 = $this->quote3->getAllItems();
96+
97+
$this->assertTrue($this->compare->compare($items1[0], $items1[0]));
98+
$this->assertTrue($this->compare->compare($items2[0], $items2[0]));
99+
$this->assertFalse($this->compare->compare($items1[0], $items2[0]));
100+
$this->assertTrue($this->compare->compare($items1[0], $items3[0]));
101+
}
102+
103+
/**
104+
* Make selection of custom options
105+
*
106+
* @param ProductInterface $product
107+
* @param string $textValue
108+
* @return array
109+
*/
110+
private function selectOptions(ProductInterface $product, string $textValue): array
111+
{
112+
$options = [];
113+
/** @var $option Option */
114+
foreach ($product->getOptions() as $option) {
115+
$value = match ($option->getGroupByType()) {
116+
ProductCustomOptionInterface::OPTION_GROUP_SELECT => key($option->getValues()),
117+
default => $textValue,
118+
};
119+
$options[$option->getId()] = $value;
120+
}
121+
return $options;
122+
}
123+
}

0 commit comments

Comments
 (0)