Skip to content

Commit 47a1ac1

Browse files
committed
Merge remote-tracking branch 'origin/2.3.3-develop' into MC-19075
2 parents c5574b8 + d525030 commit 47a1ac1

File tree

8 files changed

+125
-19
lines changed

8 files changed

+125
-19
lines changed

app/code/Magento/Catalog/Controller/Product/Compare/Add.php

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,72 @@
66
*/
77
namespace Magento\Catalog\Controller\Product\Compare;
88

9-
use Magento\Catalog\Model\Product\Attribute\Source\Status;
9+
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
use Magento\Catalog\ViewModel\Product\Checker\AddToCompareAvailability;
1011
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
12+
use Magento\Framework\Data\Form\FormKey\Validator;
1113
use Magento\Framework\Exception\NoSuchEntityException;
14+
use Magento\Framework\View\Result\PageFactory;
1215

1316
/**
1417
* Add item to compare list action.
18+
*
19+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1520
*/
1621
class Add extends \Magento\Catalog\Controller\Product\Compare implements HttpPostActionInterface
1722
{
23+
/**
24+
* @var AddToCompareAvailability
25+
*/
26+
private $compareAvailability;
27+
28+
/**
29+
* @param \Magento\Framework\App\Action\Context $context
30+
* @param \Magento\Catalog\Model\Product\Compare\ItemFactory $compareItemFactory
31+
* @param \Magento\Catalog\Model\ResourceModel\Product\Compare\Item\CollectionFactory $itemCollectionFactory
32+
* @param \Magento\Customer\Model\Session $customerSession
33+
* @param \Magento\Customer\Model\Visitor $customerVisitor
34+
* @param \Magento\Catalog\Model\Product\Compare\ListCompare $catalogProductCompareList
35+
* @param \Magento\Catalog\Model\Session $catalogSession
36+
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
37+
* @param Validator $formKeyValidator
38+
* @param PageFactory $resultPageFactory
39+
* @param ProductRepositoryInterface $productRepository
40+
* @param AddToCompareAvailability|null $compareAvailability
41+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
42+
*/
43+
public function __construct(
44+
\Magento\Framework\App\Action\Context $context,
45+
\Magento\Catalog\Model\Product\Compare\ItemFactory $compareItemFactory,
46+
\Magento\Catalog\Model\ResourceModel\Product\Compare\Item\CollectionFactory $itemCollectionFactory,
47+
\Magento\Customer\Model\Session $customerSession,
48+
\Magento\Customer\Model\Visitor $customerVisitor,
49+
\Magento\Catalog\Model\Product\Compare\ListCompare $catalogProductCompareList,
50+
\Magento\Catalog\Model\Session $catalogSession,
51+
\Magento\Store\Model\StoreManagerInterface $storeManager,
52+
Validator $formKeyValidator,
53+
PageFactory $resultPageFactory,
54+
ProductRepositoryInterface $productRepository,
55+
AddToCompareAvailability $compareAvailability = null
56+
) {
57+
parent::__construct(
58+
$context,
59+
$compareItemFactory,
60+
$itemCollectionFactory,
61+
$customerSession,
62+
$customerVisitor,
63+
$catalogProductCompareList,
64+
$catalogSession,
65+
$storeManager,
66+
$formKeyValidator,
67+
$resultPageFactory,
68+
$productRepository
69+
);
70+
71+
$this->compareAvailability = $compareAvailability
72+
?: $this->_objectManager->get(AddToCompareAvailability::class);
73+
}
74+
1875
/**
1976
* Add item to compare list.
2077
*
@@ -37,7 +94,7 @@ public function execute()
3794
$product = null;
3895
}
3996

40-
if ($product && (int)$product->getStatus() !== Status::STATUS_DISABLED) {
97+
if ($product && $this->compareAvailability->isAvailableForCompare($product)) {
4198
$this->_catalogProductCompareList->addProduct($product);
4299
$productName = $this->_objectManager->get(
43100
\Magento\Framework\Escaper::class

app/code/Magento/Catalog/Controller/Product/Compare/Remove.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
namespace Magento\Catalog\Controller\Product\Compare;
88

9+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
910
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
1011
use Magento\Framework\Exception\NoSuchEntityException;
1112

@@ -17,12 +18,13 @@ class Remove extends \Magento\Catalog\Controller\Product\Compare implements Http
1718
/**
1819
* Remove item from compare list.
1920
*
21+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
2022
* @return \Magento\Framework\Controller\ResultInterface
2123
*/
2224
public function execute()
2325
{
2426
$productId = (int)$this->getRequest()->getParam('product');
25-
if ($productId) {
27+
if ($this->_formKeyValidator->validate($this->getRequest()) && $productId) {
2628
$storeId = $this->_storeManager->getStore()->getId();
2729
try {
2830
/** @var \Magento\Catalog\Model\Product $product */
@@ -31,7 +33,7 @@ public function execute()
3133
$product = null;
3234
}
3335

34-
if ($product && $product->isSalable()) {
36+
if ($product && (int)$product->getStatus() !== Status::STATUS_DISABLED) {
3537
/** @var $item \Magento\Catalog\Model\Product\Compare\Item */
3638
$item = $this->_compareItemFactory->create();
3739
if ($this->_customerSession->isLoggedIn()) {

app/code/Magento/Catalog/Test/Mftf/Test/AddOutOfStockProductToCompareListTest.xml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,43 @@
1818
<testCaseId value="MAGETWO-98644"/>
1919
<useCaseId value="MAGETWO-98522"/>
2020
<group value="Catalog"/>
21-
<skip>
22-
<issueId value="MC-15930"/>
23-
</skip>
2421
</annotations>
2522
<before>
2623
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
27-
<magentoCLI command="config:set cataloginventory/options/show_out_of_stock 0" stepKey="displayOutOfStockNo"/>
24+
<magentoCLI command="config:set {{CatalogInventoryOptionsShowOutOfStockDisable.path}} {{CatalogInventoryOptionsShowOutOfStockDisable.value}}" stepKey="setConfigShowOutOfStockFalse"/>
2825
<magentoCLI command="cache:flush" stepKey="flushCache"/>
2926
<createData entity="SimpleSubCategory" stepKey="category"/>
3027
<createData entity="SimpleProduct4" stepKey="product">
3128
<requiredEntity createDataKey="category"/>
3229
</createData>
3330
</before>
3431
<after>
35-
<magentoCLI command="config:set cataloginventory/options/show_out_of_stock 0" stepKey="displayOutOfStockNo2"/>
32+
<magentoCLI command="config:set {{CatalogInventoryOptionsShowOutOfStockDisable.path}} {{CatalogInventoryOptionsShowOutOfStockDisable.value}}" stepKey="setConfigShowOutOfStockFalse"/>
3633
<magentoCLI command="cache:flush" stepKey="flushCache"/>
3734
<deleteData createDataKey="product" stepKey="deleteProduct"/>
3835
<deleteData createDataKey="category" stepKey="deleteCategory"/>
3936
<actionGroup ref="logout" stepKey="logout"/>
4037
</after>
4138
<!--Open product page-->
4239
<comment userInput="Open product page" stepKey="openProdPage"/>
43-
<amOnPage url="{{StorefrontProductPage.url($$product.name$$)}}" stepKey="goToSimpleProductPage"/>
40+
<amOnPage url="{{StorefrontProductPage.url($$product.custom_attributes[url_key]$$)}}" stepKey="goToSimpleProductPage"/>
4441
<waitForPageLoad stepKey="waitForSimpleProductPage"/>
4542
<!--'Add to compare' link is not available-->
4643
<comment userInput="'Add to compare' link is not available" stepKey="addToCompareLinkAvailability"/>
4744
<dontSeeElement selector="{{StorefrontProductInfoMainSection.productAddToCompare}}" stepKey="dontSeeAddToCompareLink"/>
4845
<!--Turn on 'out on stock' config-->
4946
<comment userInput="Turn on 'out of stock' config" stepKey="onOutOfStockConfig"/>
50-
<magentoCLI command="config:set cataloginventory/options/show_out_of_stock 1" stepKey="displayOutOfStockYes"/>
47+
<magentoCLI command="config:set {{CatalogInventoryOptionsShowOutOfStockEnable.path}} {{CatalogInventoryOptionsShowOutOfStockEnable.value}}" stepKey="setConfigShowOutOfStockTrue"/>
5148
<!--Clear cache and reindex-->
5249
<comment userInput="Clear cache and reindex" stepKey="cleanCache"/>
5350
<magentoCLI command="indexer:reindex" stepKey="reindex"/>
5451
<magentoCLI command="cache:flush" stepKey="flushCache"/>
5552
<!--Open product page-->
5653
<comment userInput="Open product page" stepKey="openProductPage"/>
57-
<amOnPage url="{{StorefrontProductPage.url($$product.name$$)}}" stepKey="goToSimpleProductPage2"/>
54+
<amOnPage url="{{StorefrontProductPage.url($$product.custom_attributes[url_key]$$)}}" stepKey="goToSimpleProductPage2"/>
5855
<waitForPageLoad stepKey="waitForSimpleProductPage2"/>
5956
<!--Click on 'Add to Compare' link-->
57+
<waitForElementVisible selector="{{StorefrontProductInfoMainSection.productAddToCompare}}" stepKey="seeAddToCompareLink"/>
6058
<comment userInput="Click on 'Add to Compare' link" stepKey="clickOnAddToCompareLink"/>
6159
<click selector="{{StorefrontProductInfoMainSection.productAddToCompare}}" stepKey="clickOnAddToCompare"/>
6260
<waitForPageLoad stepKey="waitForProdAddToCmpList"/>

app/code/Magento/Catalog/ViewModel/Product/Checker/AddToCompareAvailability.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\View\Element\Block\ArgumentInterface;
1111
use Magento\Catalog\Api\Data\ProductInterface;
1212
use Magento\CatalogInventory\Api\StockConfigurationInterface;
13+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
1314

1415
/**
1516
* Check is available add to compare.
@@ -37,7 +38,11 @@ public function __construct(StockConfigurationInterface $stockConfiguration)
3738
*/
3839
public function isAvailableForCompare(ProductInterface $product): bool
3940
{
40-
return $this->isInStock($product) || $this->stockConfiguration->isShowOutOfStock();
41+
if ((int)$product->getStatus() !== Status::STATUS_DISABLED) {
42+
return $this->isInStock($product) || $this->stockConfiguration->isShowOutOfStock();
43+
}
44+
45+
return false;
4146
}
4247

4348
/**
@@ -53,6 +58,6 @@ private function isInStock(ProductInterface $product): bool
5358
return $product->isSalable();
5459
}
5560

56-
return isset($quantityAndStockStatus['is_in_stock']) && $quantityAndStockStatus['is_in_stock'];
61+
return $quantityAndStockStatus['is_in_stock'] ?? false;
5762
}
5863
}

app/code/Magento/Checkout/Test/Mftf/Test/StorefrontOnePageCheckoutJsValidationTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<test name="StorefrontOnePageCheckoutJsValidationTest">
1212
<annotations>
1313
<features value="Checkout"/>
14+
<stories value="Checkout"/>
1415
<title value="Js validation error messages must be absent for required fields after checkout start."/>
1516
<description value="Js validation error messages must be absent for required fields after checkout start."/>
1617
<severity value="MAJOR" />

dev/tests/integration/testsuite/Magento/SendFriend/Controller/SendmailTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ class SendmailTest extends AbstractController
2424
/**
2525
* Share the product to friend as logged in customer
2626
*
27+
* @magentoAppArea frontend
2728
* @magentoDbIsolation enabled
2829
* @magentoAppIsolation enabled
29-
* @magentoConfigFixture default/sendfriend/email/allow_guest 0
30-
* @magentoConfigFixture default/sendfriend/email/enabled 1
30+
* @magentoConfigFixture default_store sendfriend/email/allow_guest 0
31+
* @magentoConfigFixture default_store sendfriend/email/enabled 1
3132
* @magentoDataFixture Magento/Customer/_files/customer.php
3233
* @magentoDataFixture Magento/Catalog/_files/products.php
3334
*/

lib/internal/Magento/Framework/Escaper.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class Escaper
2828
*/
2929
private $logger;
3030

31+
/**
32+
* @var \Magento\Framework\Translate\InlineInterface
33+
*/
34+
private $translateInline;
35+
3136
/**
3237
* @var string[]
3338
*/
@@ -335,8 +340,11 @@ public function escapeJsQuote($data, $quote = '\'')
335340
*/
336341
public function escapeXssInUrl($data)
337342
{
343+
$data = html_entity_decode((string)$data);
344+
$this->getTranslateInline()->processResponseBody($data);
345+
338346
return htmlspecialchars(
339-
$this->escapeScriptIdentifiers(html_entity_decode((string)$data)),
347+
$this->escapeScriptIdentifiers($data),
340348
$this->htmlSpecialCharsFlag | ENT_HTML5 | ENT_HTML401,
341349
'UTF-8',
342350
false
@@ -430,4 +438,19 @@ private function filterProhibitedTags(array $allowedTags): array
430438

431439
return $allowedTags;
432440
}
441+
442+
/**
443+
* Resolve inline translator.
444+
*
445+
* @return \Magento\Framework\Translate\InlineInterface
446+
*/
447+
private function getTranslateInline()
448+
{
449+
if ($this->translateInline === null) {
450+
$this->translateInline = \Magento\Framework\App\ObjectManager::getInstance()
451+
->get(\Magento\Framework\Translate\InlineInterface::class);
452+
}
453+
454+
return $this->translateInline;
455+
}
433456
}

lib/internal/Magento/Framework/Test/Unit/EscaperTest.php

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

88
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
99
use Magento\Framework\Escaper;
10+
use Magento\Framework\Translate\Inline;
1011

1112
/**
1213
* \Magento\Framework\Escaper test case
@@ -16,26 +17,40 @@ class EscaperTest extends \PHPUnit\Framework\TestCase
1617
/**
1718
* @var \Magento\Framework\Escaper
1819
*/
19-
protected $escaper = null;
20+
protected $escaper;
2021

2122
/**
2223
* @var \Magento\Framework\ZendEscaper
2324
*/
2425
private $zendEscaper;
2526

27+
/**
28+
* @var Inline
29+
*/
30+
private $translateInline;
31+
2632
/**
2733
* @var \Psr\Log\LoggerInterface
2834
*/
2935
private $loggerMock;
3036

37+
/**
38+
* @inheritdoc
39+
*/
3140
protected function setUp()
3241
{
42+
$objectManagerHelper = new ObjectManager($this);
3343
$this->escaper = new Escaper();
3444
$this->zendEscaper = new \Magento\Framework\ZendEscaper();
45+
$this->translateInline = $objectManagerHelper->getObject(Inline::class);
3546
$this->loggerMock = $this->getMockForAbstractClass(\Psr\Log\LoggerInterface::class);
36-
$objectManagerHelper = new ObjectManager($this);
3747
$objectManagerHelper->setBackwardCompatibleProperty($this->escaper, 'escaper', $this->zendEscaper);
3848
$objectManagerHelper->setBackwardCompatibleProperty($this->escaper, 'logger', $this->loggerMock);
49+
$objectManagerHelper->setBackwardCompatibleProperty(
50+
$this->escaper,
51+
'translateInline',
52+
$this->translateInline
53+
);
3954
}
4055

4156
/**
@@ -394,6 +409,10 @@ public function escapeDataProvider()
394409
'http://test.com/?redirect=\x64\x61\x74\x61\x3a\x74\x65\x78\x74x2cCPHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg',
395410
'http://test.com/?redirect=:\x74\x65\x78\x74x2cCPHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg',
396411
],
412+
[
413+
'http://test.com/?{{{test}}{{test_translated}}{{tes_origin}}{{theme}}}',
414+
'http://test.com/?test',
415+
],
397416
];
398417
}
399418
}

0 commit comments

Comments
 (0)