Skip to content

Commit 2e20a73

Browse files
committed
Merge branch 'MC-40149' into 2.4-develop-sidecar-pr10
2 parents d5f313c + 0b0a732 commit 2e20a73

File tree

7 files changed

+187
-10
lines changed

7 files changed

+187
-10
lines changed

app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Magento\Bundle\Model\Product\Type;
1212
use Magento\Bundle\Model\ResourceModel\BundleFactory;
1313
use Magento\Bundle\Model\ResourceModel\Option\Collection;
14-
use Magento\CatalogRule\Model\ResourceModel\Product\CollectionProcessor;
1514
use Magento\Bundle\Model\ResourceModel\Selection\Collection as SelectionCollection;
1615
use Magento\Bundle\Model\ResourceModel\Selection\CollectionFactory;
1716
use Magento\Bundle\Model\Selection;
@@ -28,6 +27,7 @@
2827
use Magento\CatalogInventory\Api\StockStateInterface;
2928
use Magento\CatalogInventory\Model\StockRegistry;
3029
use Magento\CatalogInventory\Model\StockState;
30+
use Magento\CatalogRule\Model\ResourceModel\Product\CollectionProcessor;
3131
use Magento\Framework\DataObject;
3232
use Magento\Framework\EntityManager\EntityMetadataInterface;
3333
use Magento\Framework\EntityManager\MetadataPool;
@@ -1548,6 +1548,10 @@ public function testPrepareForCartAdvancedSpecifyProductOptions()
15481548
->disableOriginalConstructor()
15491549
->getMock();
15501550

1551+
$buyRequest->method('getOptions')
1552+
->willReturn([333 => ['type' => 'image/jpeg']]);
1553+
$option->method('getId')
1554+
->willReturn(333);
15511555
$this->parentClass($group, $option, $buyRequest, $product);
15521556

15531557
$product->expects($this->any())
@@ -1556,6 +1560,8 @@ public function testPrepareForCartAdvancedSpecifyProductOptions()
15561560
$buyRequest->expects($this->once())
15571561
->method('getBundleOption')
15581562
->willReturn([0, '', 'str']);
1563+
$group->expects($this->once())
1564+
->method('validateUserValue');
15591565

15601566
$result = $this->model->prepareForCartAdvanced($buyRequest, $product);
15611567
$this->assertEquals('Please specify product option(s).', $result);

app/code/Magento/Catalog/Model/Product/Type/AbstractType.php

Lines changed: 5 additions & 2 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-
declare(strict_types=1);
76

87
namespace Magento\Catalog\Model\Product\Type;
98

@@ -605,7 +604,11 @@ protected function _prepareOptions(\Magento\Framework\DataObject $buyRequest, $p
605604
if ($product->getSkipCheckRequiredOption() !== true) {
606605
$group->validateUserValue($optionsFromRequest);
607606
} elseif ($optionsFromRequest !== null && isset($optionsFromRequest[$option->getId()])) {
608-
$transport->options[$option->getId()] = $optionsFromRequest[$option->getId()];
607+
if (is_array($optionsFromRequest[$option->getId()])) {
608+
$group->validateUserValue($optionsFromRequest);
609+
} else {
610+
$transport->options[$option->getId()] = $optionsFromRequest[$option->getId()];
611+
}
609612
}
610613

611614
} catch (LocalizedException $e) {

app/code/Magento/Sales/Model/RtlTextHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function reverseRtlText(string $string): string
4848

4949
for ($i = 0; $i < $splitTextAmount; $i++) {
5050
if ($this->isRtlText($splitText[$i])) {
51-
for ($j = $i + 1; $j < $splitTextAmount; $j++) {
51+
for ($j = $i; $j < $splitTextAmount; $j++) {
5252
$tmp = $this->isRtlText($splitText[$j])
5353
? $this->stringUtils->strrev($splitText[$j]) : $splitText[$j];
5454
$splitText[$j] = $this->isRtlText($splitText[$i])

app/code/Magento/Sales/Test/Unit/Model/RtlTextHandlerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public function provideRtlTexts(): array
6262
['Herr Prof. Dr. Gerald Schüler B.A.', false],//German
6363
['نديم مقداد نعمان القحطاني', true],//Arabic
6464
['شهاب الفرحان', true],//Arabic
65+
['مرحبا ماجنت اثنان', true],//Arabic
6566
['צבר קרליבך', true],//Hebrew
6667
['גורי מייזליש', true],//Hebrew
6768
['اتابک بهشتی', true],//Persian

app/code/Magento/Sales/Test/Unit/Ui/Component/Listing/Column/PriceTest.php

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
use PHPUnit\Framework\MockObject\MockObject;
1818
use PHPUnit\Framework\TestCase;
1919

20+
/**
21+
* Contains tests for Price class
22+
*/
2023
class PriceTest extends TestCase
2124
{
2225
/**
@@ -34,6 +37,9 @@ class PriceTest extends TestCase
3437
*/
3538
private $storeManagerMock;
3639

40+
/**
41+
* @inheritDoc
42+
*/
3743
protected function setUp(): void
3844
{
3945
$objectManager = new ObjectManager($this);
@@ -57,12 +63,20 @@ protected function setUp(): void
5763
}
5864

5965
/**
60-
* @param $hasCurrency
61-
* @param $dataSource
62-
* @param $currencyCode
66+
* Test for prepareDataSource method
67+
*
68+
* @param bool $hasCurrency
69+
* @param array $dataSource
70+
* @param string $currencyCode
71+
* @param int|null $expectedStoreId
6372
* @dataProvider testPrepareDataSourceDataProvider
6473
*/
65-
public function testPrepareDataSource($hasCurrency, $dataSource, $currencyCode)
74+
public function testPrepareDataSource(
75+
bool $hasCurrency,
76+
array $dataSource,
77+
string $currencyCode,
78+
?int $expectedStoreId = null
79+
): void
6680
{
6781
$itemName = 'itemName';
6882
$oldItemValue = 'oldItemValue';
@@ -79,6 +93,7 @@ public function testPrepareDataSource($hasCurrency, $dataSource, $currencyCode)
7993
->willReturn($currencyCode);
8094
$this->storeManagerMock->expects($hasCurrency ? $this->never() : $this->once())
8195
->method('getStore')
96+
->with($expectedStoreId)
8297
->willReturn($store);
8398
$store->expects($hasCurrency ? $this->never() : $this->once())
8499
->method('getBaseCurrency')
@@ -98,7 +113,12 @@ public function testPrepareDataSource($hasCurrency, $dataSource, $currencyCode)
98113
$this->assertEquals($newItemValue, $dataSource['data']['items'][0][$itemName]);
99114
}
100115

101-
public function testPrepareDataSourceDataProvider()
116+
/**
117+
* Provider for testPrepareDataSource
118+
*
119+
* @return array
120+
*/
121+
public function testPrepareDataSourceDataProvider(): array
102122
{
103123
$dataSource1 = [
104124
'data' => [
@@ -119,9 +139,31 @@ public function testPrepareDataSourceDataProvider()
119139
]
120140
]
121141
];
142+
$dataSource3 = [
143+
'data' => [
144+
'items' => [
145+
[
146+
'itemName' => 'oldItemValue',
147+
'store_id' => '2'
148+
]
149+
]
150+
]
151+
];
152+
$dataSource4 = [
153+
'data' => [
154+
'items' => [
155+
[
156+
'itemName' => 'oldItemValue',
157+
'store_id' => 'abc'
158+
]
159+
]
160+
]
161+
];
122162
return [
123163
[true, $dataSource1, 'US'],
124164
[false, $dataSource2, 'SAR'],
165+
[false, $dataSource3, 'SAR', 2],
166+
[false, $dataSource4, 'SAR'],
125167
];
126168
}
127169
}

app/code/Magento/Sales/Ui/Component/Listing/Column/Price.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\App\ObjectManager;
1111
use Magento\Framework\View\Element\UiComponent\ContextInterface;
1212
use Magento\Framework\View\Element\UiComponentFactory;
13+
use Magento\Store\Model\Store;
1314
use Magento\Store\Model\StoreManagerInterface;
1415
use Magento\Ui\Component\Listing\Columns\Column;
1516
use Magento\Framework\Pricing\PriceCurrencyInterface;
@@ -77,8 +78,10 @@ public function prepareDataSource(array $dataSource)
7778
foreach ($dataSource['data']['items'] as & $item) {
7879
$currencyCode = isset($item['base_currency_code']) ? $item['base_currency_code'] : null;
7980
if (!$currencyCode) {
81+
$storeId = isset($item['store_id']) && (int)$item['store_id'] !== 0 ? $item['store_id'] :
82+
$this->context->getFilterParam('store_id', Store::DEFAULT_STORE_ID);
8083
$store = $this->storeManager->getStore(
81-
$this->context->getFilterParam('store_id', \Magento\Store\Model\Store::DEFAULT_STORE_ID)
84+
$storeId
8285
);
8386
$currencyCode = $store->getBaseCurrency()->getCurrencyCode();
8487
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Controller\Adminhtml\Product;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\Framework\App\Request\Http as HttpRequest;
13+
use Magento\Framework\Exception\NoSuchEntityException;
14+
use Magento\Framework\Message\MessageInterface;
15+
use Magento\TestFramework\TestCase\AbstractBackendController;
16+
17+
/**
18+
* Test class for Product duplicate action
19+
*
20+
* @magentoAppArea adminhtml
21+
* @see \Magento\Catalog\Controller\Adminhtml\Product\Duplicate
22+
*/
23+
class DuplicateTest extends AbstractBackendController
24+
{
25+
/**
26+
* @var ProductRepositoryInterface
27+
*/
28+
private $productRepository;
29+
30+
/**
31+
* @var string
32+
*/
33+
private $duplicatedProductSku;
34+
35+
/**
36+
* @var array
37+
*/
38+
private $dataKeys = ['name', 'description', 'short_description', 'price', 'weight', 'attribute_set_id'];
39+
40+
/**
41+
* @inheritdoc
42+
*/
43+
protected function setUp(): void
44+
{
45+
parent::setUp();
46+
47+
$this->productRepository = $this->_objectManager->get(ProductRepositoryInterface::class);
48+
$this->productRepository->cleanCache();
49+
}
50+
51+
/**
52+
* @inheritdoc
53+
*/
54+
protected function tearDown(): void
55+
{
56+
try {
57+
$this->productRepository->deleteById($this->duplicatedProductSku);
58+
} catch (NoSuchEntityException $e) {
59+
// product already deleted
60+
}
61+
62+
parent::tearDown();
63+
}
64+
65+
/**
66+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
67+
*
68+
* @return void
69+
*/
70+
public function testDuplicateAction(): void
71+
{
72+
$product = $this->productRepository->get('simple');
73+
$this->getRequest()->setMethod(HttpRequest::METHOD_GET);
74+
$this->getRequest()->setParams(
75+
[
76+
'id' => $product->getId(),
77+
'attribute_set_id' => $product->getAttributeSetId(),
78+
]
79+
);
80+
$this->dispatch('backend/catalog/product/duplicate');
81+
$this->assertSessionMessages(
82+
$this->containsEqual((string)__('You duplicated the product.')),
83+
MessageInterface::TYPE_SUCCESS
84+
);
85+
$this->assertRedirect($this->stringContains('catalog/product/edit/'));
86+
$productId = $this->getIdFromRedirectedUrl();
87+
$this->assertNotEmpty($productId, 'Id not found');
88+
$duplicatedProduct = $this->productRepository->getById((int)$productId);
89+
$this->duplicatedProductSku = $duplicatedProduct->getSku();
90+
$this->assertProductDuplicated($product, $duplicatedProduct);
91+
}
92+
93+
/**
94+
* Get id value from redirected url
95+
*
96+
* @return string
97+
*/
98+
private function getIdFromRedirectedUrl(): string
99+
{
100+
$url = $this->getResponse()
101+
->getHeader('Location')
102+
->getFieldValue();
103+
$pattern = '!/id/(.*?)/!';
104+
$result = preg_match($pattern, $url, $matches);
105+
106+
return $result ? $matches[1] : '';
107+
}
108+
109+
/**
110+
* Checks that duplicate product was created from the first product
111+
*
112+
* @param ProductInterface $product
113+
* @param ProductInterface $duplicatedProduct
114+
* @return void
115+
*/
116+
private function assertProductDuplicated(ProductInterface $product, ProductInterface $duplicatedProduct): void
117+
{
118+
foreach ($this->dataKeys as $key) {
119+
$this->assertEquals($product->getData($key), $duplicatedProduct->getData($key));
120+
}
121+
}
122+
}

0 commit comments

Comments
 (0)