Skip to content

Commit 57f82b8

Browse files
committed
Merge remote-tracking branch 'origin/2.3-qwerty' into 2.3-qwerty-pr49
2 parents b302b6d + 1106fbd commit 57f82b8

File tree

23 files changed

+466
-156
lines changed

23 files changed

+466
-156
lines changed

app/code/Magento/Captcha/Model/DefaultModel.php

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Captcha\Model;
79

810
use Magento\Captcha\Helper\Data;
11+
use Magento\Framework\Math\Random;
912

1013
/**
1114
* Implementation of \Zend\Captcha\Image
1215
*
16+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
17+
*
1318
* @api
1419
* @since 100.0.2
1520
*/
@@ -83,24 +88,32 @@ class DefaultModel extends \Zend\Captcha\Image implements \Magento\Captcha\Model
8388
*/
8489
private $words;
8590

91+
/**
92+
* @var Random
93+
*/
94+
private $randomMath;
95+
8696
/**
8797
* @param \Magento\Framework\Session\SessionManagerInterface $session
8898
* @param \Magento\Captcha\Helper\Data $captchaData
8999
* @param ResourceModel\LogFactory $resLogFactory
90100
* @param string $formId
101+
* @param Random $randomMath
91102
* @throws \Zend\Captcha\Exception\ExtensionNotLoadedException
92103
*/
93104
public function __construct(
94105
\Magento\Framework\Session\SessionManagerInterface $session,
95106
\Magento\Captcha\Helper\Data $captchaData,
96107
\Magento\Captcha\Model\ResourceModel\LogFactory $resLogFactory,
97-
$formId
108+
$formId,
109+
Random $randomMath = null
98110
) {
99111
parent::__construct();
100112
$this->session = $session;
101113
$this->captchaData = $captchaData;
102114
$this->resLogFactory = $resLogFactory;
103115
$this->formId = $formId;
116+
$this->randomMath = $randomMath ?? \Magento\Framework\App\ObjectManager::getInstance()->get(Random::class);
104117
}
105118

106119
/**
@@ -382,23 +395,9 @@ public function setShowCaptchaInSession($value = true)
382395
*/
383396
protected function generateWord()
384397
{
385-
$word = '';
386-
$symbols = $this->getSymbols();
398+
$symbols = (string)$this->captchaData->getConfig('symbols');
387399
$wordLen = $this->getWordLen();
388-
for ($i = 0; $i < $wordLen; $i++) {
389-
$word .= $symbols[array_rand($symbols)];
390-
}
391-
return $word;
392-
}
393-
394-
/**
395-
* Get symbols array to use for word generation
396-
*
397-
* @return array
398-
*/
399-
private function getSymbols()
400-
{
401-
return str_split((string)$this->captchaData->getConfig('symbols'));
400+
return $this->randomMath->getRandomString($wordLen, $symbols);
402401
}
403402

404403
/**
@@ -562,7 +561,7 @@ protected function randomSize()
562561
*/
563562
protected function gc()
564563
{
565-
//do nothing
564+
return; // required for static testing to pass
566565
}
567566

568567
/**

app/code/Magento/Captcha/Test/Unit/Model/DefaultTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Captcha\Test\Unit\Model;
79

10+
use Magento\Framework\Math\Random;
11+
812
/**
913
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1014
*/
@@ -375,4 +379,38 @@ public function isShownToLoggedInUserDataProvider()
375379
[false, 'user_forgotpassword']
376380
];
377381
}
382+
383+
/**
384+
* @param string $string
385+
* @dataProvider generateWordProvider
386+
* @throws \ReflectionException
387+
*/
388+
public function testGenerateWord($string)
389+
{
390+
$randomMock = $this->createMock(Random::class);
391+
$randomMock->expects($this->once())
392+
->method('getRandomString')
393+
->will($this->returnValue($string));
394+
$captcha = new \Magento\Captcha\Model\DefaultModel(
395+
$this->session,
396+
$this->_getHelperStub(),
397+
$this->_resLogFactory,
398+
'user_create',
399+
$randomMock
400+
);
401+
$method = new \ReflectionMethod($captcha, 'generateWord');
402+
$method->setAccessible(true);
403+
$this->assertEquals($string, $method->invoke($captcha));
404+
}
405+
/**
406+
* @return array
407+
*/
408+
public function generateWordProvider()
409+
{
410+
return [
411+
['ABC123'],
412+
['1234567890'],
413+
['The quick brown fox jumps over the lazy dog.']
414+
];
415+
}
378416
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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\Model\Product;
9+
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Store\Model\StoreManagerInterface;
12+
13+
/**
14+
* Class to check that product is saleable.
15+
*/
16+
class SalabilityChecker
17+
{
18+
/**
19+
* @var ProductRepositoryInterface
20+
*/
21+
private $productRepository;
22+
23+
/**
24+
* @var StoreManagerInterface
25+
*/
26+
private $storeManager;
27+
28+
/**
29+
* @param ProductRepositoryInterface $productRepository
30+
* @param StoreManagerInterface $storeManager
31+
*/
32+
public function __construct(
33+
ProductRepositoryInterface $productRepository,
34+
StoreManagerInterface $storeManager
35+
) {
36+
$this->productRepository = $productRepository;
37+
$this->storeManager = $storeManager;
38+
}
39+
40+
/**
41+
* Check if product is salable.
42+
*
43+
* @param int|string $productId
44+
* @param int|null $storeId
45+
* @return bool
46+
*/
47+
public function isSalable($productId, $storeId = null): bool
48+
{
49+
if ($storeId === null) {
50+
$storeId = $this->storeManager->getStore()->getId();
51+
}
52+
/** @var \Magento\Catalog\Model\Product $product */
53+
$product = $this->productRepository->getById($productId, false, $storeId);
54+
55+
return $product->isSalable();
56+
}
57+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
<testCaseId value="MAGETWO-98644"/>
1818
<useCaseId value="MAGETWO-98522"/>
1919
<group value="Catalog"/>
20+
<skip>
21+
<issueId value="MC-15930"/>
22+
</skip>
2023
</annotations>
2124
<before>
2225
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ protected function getCategoriesTree($filter = null)
362362

363363
$categoryById[$category->getId()]['is_active'] = $category->getIsActive();
364364
$categoryById[$category->getId()]['label'] = $category->getName();
365+
$categoryById[$category->getId()]['__disableTmpl'] = true;
365366
$categoryById[$category->getParentId()]['optgroup'][] = &$categoryById[$category->getId()];
366367
}
367368

app/code/Magento/CatalogImportExport/Test/Mftf/Test/AdminExportBundleProductTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<testCaseId value="MC-14008"/>
1919
<group value="catalog_import_export"/>
2020
<group value="mtf_migrated"/>
21+
<skip>
22+
<issueId value="MC-15934"/>
23+
</skip>
2124
</annotations>
2225
<before>
2326
<!--Create bundle product with dynamic price with two simple products -->

app/code/Magento/CatalogImportExport/Test/Mftf/Test/AdminExportSimpleProductWithCustomAttributeTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<testCaseId value="MC-14007"/>
1919
<group value="catalog_import_export"/>
2020
<group value="mtf_migrated"/>
21+
<skip>
22+
<issueId value="MC-15934"/>
23+
</skip>
2124
</annotations>
2225
<before>
2326
<!-- Create simple product with custom attribute set -->

0 commit comments

Comments
 (0)