Skip to content

Commit 9a2dbd6

Browse files
Devagouda PatilDevagouda Patil
authored andcommitted
Merge branch '2.3-develop' into MAGETWO-95773-invoice-refund-api-error
2 parents 63e840c + c49da73 commit 9a2dbd6

File tree

62 files changed

+2152
-268
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2152
-268
lines changed

app/code/Magento/BundleImportExport/Model/Import/Product/Type/Bundle.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
/**
2222
* Class Bundle
23+
*
2324
* @package Magento\BundleImportExport\Model\Import\Product\Type
2425
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
2526
*/
@@ -349,6 +350,8 @@ protected function populateSelectionTemplate($selection, $optionId, $parentId, $
349350
}
350351

351352
/**
353+
* Deprecated method for retrieving mapping between skus and products.
354+
*
352355
* @deprecated Misspelled method
353356
* @see retrieveProductsByCachedSkus
354357
*/
@@ -600,6 +603,7 @@ protected function insertOptions()
600603

601604
/**
602605
* Populate array for insert option values
606+
*
603607
* @param array $optionIds
604608
* @return array
605609
*/
@@ -779,7 +783,7 @@ protected function clear()
779783
*/
780784
private function getStoreIdByCode(string $storeCode): int
781785
{
782-
if (!isset($this->storeIdToCode[$storeCode])) {
786+
if (!isset($this->storeCodeToId[$storeCode])) {
783787
/** @var $store \Magento\Store\Model\Store */
784788
foreach ($this->storeManager->getStores() as $store) {
785789
$this->storeCodeToId[$store->getCode()] = $store->getId();
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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\Captcha\Test\Unit\Observer;
9+
10+
use Magento\Captcha\Helper\Data;
11+
use Magento\Captcha\Model\DefaultModel;
12+
use Magento\Captcha\Observer\CaptchaStringResolver;
13+
use Magento\Captcha\Observer\CheckUserLoginBackendObserver;
14+
use Magento\Framework\App\RequestInterface;
15+
use Magento\Framework\Event;
16+
use Magento\Framework\Event\Observer;
17+
use Magento\Framework\Message\ManagerInterface;
18+
use PHPUnit\Framework\TestCase;
19+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
20+
21+
/**
22+
* Class CheckUserLoginBackendObserverTest
23+
*/
24+
class CheckUserLoginBackendObserverTest extends TestCase
25+
{
26+
/**
27+
* @var CheckUserLoginBackendObserver
28+
*/
29+
private $observer;
30+
31+
/**
32+
* @var ManagerInterface|MockObject
33+
*/
34+
private $messageManagerMock;
35+
36+
/**
37+
* @var CaptchaStringResolver|MockObject
38+
*/
39+
private $captchaStringResolverMock;
40+
41+
/**
42+
* @var RequestInterface|MockObject
43+
*/
44+
private $requestMock;
45+
46+
/**
47+
* @var Data|MockObject
48+
*/
49+
private $helperMock;
50+
51+
/**
52+
* Set Up
53+
*
54+
* @return void
55+
*/
56+
protected function setUp()
57+
{
58+
$this->helperMock = $this->createMock(Data::class);
59+
$this->messageManagerMock = $this->createMock(ManagerInterface::class);
60+
$this->captchaStringResolverMock = $this->createMock(CaptchaStringResolver::class);
61+
$this->requestMock = $this->createMock(RequestInterface::class);
62+
63+
$this->observer = new CheckUserLoginBackendObserver(
64+
$this->helperMock,
65+
$this->captchaStringResolverMock,
66+
$this->requestMock
67+
);
68+
}
69+
70+
/**
71+
* Test check user login in backend with correct captcha
72+
*
73+
* @dataProvider requiredCaptchaDataProvider
74+
* @param bool $isRequired
75+
* @return void
76+
*/
77+
public function testCheckOnBackendLoginWithCorrectCaptcha(bool $isRequired): void
78+
{
79+
$formId = 'backend_login';
80+
$login = 'admin';
81+
$captchaValue = 'captcha-value';
82+
83+
/** @var Observer|MockObject $observerMock */
84+
$observerMock = $this->createPartialMock(Observer::class, ['getEvent']);
85+
$eventMock = $this->createPartialMock(Event::class, ['getUsername']);
86+
$captcha = $this->createMock(DefaultModel::class);
87+
88+
$eventMock->method('getUsername')->willReturn('admin');
89+
$observerMock->method('getEvent')->willReturn($eventMock);
90+
$captcha->method('isRequired')->with($login)->willReturn($isRequired);
91+
$captcha->method('isCorrect')->with($captchaValue)->willReturn(true);
92+
$this->helperMock->method('getCaptcha')->with($formId)->willReturn($captcha);
93+
$this->captchaStringResolverMock->method('resolve')->with($this->requestMock, $formId)
94+
->willReturn($captchaValue);
95+
96+
$this->observer->execute($observerMock);
97+
}
98+
99+
/**
100+
* @return array
101+
*/
102+
public function requiredCaptchaDataProvider(): array
103+
{
104+
return [
105+
[true],
106+
[false]
107+
];
108+
}
109+
110+
/**
111+
* Test check user login in backend with wrong captcha
112+
*
113+
* @return void
114+
* @expectedException \Magento\Framework\Exception\Plugin\AuthenticationException
115+
*/
116+
public function testCheckOnBackendLoginWithWrongCaptcha(): void
117+
{
118+
$formId = 'backend_login';
119+
$login = 'admin';
120+
$captchaValue = 'captcha-value';
121+
122+
/** @var Observer|MockObject $observerMock */
123+
$observerMock = $this->createPartialMock(Observer::class, ['getEvent']);
124+
$eventMock = $this->createPartialMock(Event::class, ['getUsername']);
125+
$captcha = $this->createMock(DefaultModel::class);
126+
127+
$eventMock->method('getUsername')->willReturn($login);
128+
$observerMock->method('getEvent')->willReturn($eventMock);
129+
$captcha->method('isRequired')->with($login)->willReturn(true);
130+
$captcha->method('isCorrect')->with($captchaValue)->willReturn(false);
131+
$this->helperMock->method('getCaptcha')->with($formId)->willReturn($captcha);
132+
$this->captchaStringResolverMock->method('resolve')->with($this->requestMock, $formId)
133+
->willReturn($captchaValue);
134+
135+
$this->observer->execute($observerMock);
136+
}
137+
}

app/code/Magento/Catalog/Helper/Data.php

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

88
use Magento\Catalog\Api\CategoryRepositoryInterface;
99
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
use Magento\Store\Model\ScopeInterface;
1011
use Magento\Customer\Model\Session as CustomerSession;
1112
use Magento\Framework\Exception\NoSuchEntityException;
1213
use Magento\Framework\Pricing\PriceCurrencyInterface;
@@ -273,7 +274,8 @@ public function setStoreId($store)
273274

274275
/**
275276
* Return current category path or get it from current category
276-
* and creating array of categories|product paths for breadcrumbs
277+
*
278+
* Creating array of categories|product paths for breadcrumbs
277279
*
278280
* @return array
279281
*/
@@ -382,6 +384,7 @@ public function getLastViewedUrl()
382384

383385
/**
384386
* Split SKU of an item by dashes and spaces
387+
*
385388
* Words will not be broken, unless this length is greater than $length
386389
*
387390
* @param string $sku
@@ -410,14 +413,15 @@ public function getAttributeHiddenFields()
410413
/**
411414
* Retrieve Catalog Price Scope
412415
*
413-
* @return int
416+
* @return int|null
414417
*/
415-
public function getPriceScope()
418+
public function getPriceScope(): ?int
416419
{
417-
return $this->scopeConfig->getValue(
420+
$priceScope = $this->scopeConfig->getValue(
418421
self::XML_PATH_PRICE_SCOPE,
419-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
422+
ScopeInterface::SCOPE_STORE
420423
);
424+
return isset($priceScope) ? (int)$priceScope : null;
421425
}
422426

423427
/**
@@ -439,7 +443,7 @@ public function isUsingStaticUrlsAllowed()
439443
{
440444
return $this->scopeConfig->isSetFlag(
441445
self::CONFIG_USE_STATIC_URLS,
442-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
446+
ScopeInterface::SCOPE_STORE
443447
);
444448
}
445449

@@ -454,7 +458,7 @@ public function isUrlDirectivesParsingAllowed()
454458
{
455459
return $this->scopeConfig->isSetFlag(
456460
self::CONFIG_PARSE_URL_DIRECTIVES,
457-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
461+
ScopeInterface::SCOPE_STORE,
458462
$this->_storeId
459463
);
460464
}
@@ -472,19 +476,22 @@ public function getPageTemplateProcessor()
472476

473477
/**
474478
* Whether to display items count for each filter option
479+
*
475480
* @param int $storeId Store view ID
476481
* @return bool
477482
*/
478483
public function shouldDisplayProductCountOnLayer($storeId = null)
479484
{
480485
return $this->scopeConfig->isSetFlag(
481486
self::XML_PATH_DISPLAY_PRODUCT_COUNT,
482-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
487+
ScopeInterface::SCOPE_STORE,
483488
$storeId
484489
);
485490
}
486491

487492
/**
493+
* Convert tax address array to address data object with country id and postcode
494+
*
488495
* @param array $taxAddress
489496
* @return \Magento\Customer\Api\Data\AddressInterface|null
490497
*/

app/code/Magento/Catalog/Model/Product/Attribute/Backend/TierPrice/UpdateHandler.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ public function execute($entity, $arguments = [])
8686
__('Tier prices data should be array, but actually other type is received')
8787
);
8888
}
89-
$websiteId = $this->storeManager->getStore($entity->getStoreId())->getWebsiteId();
89+
$websiteId = (int)$this->storeManager->getStore($entity->getStoreId())->getWebsiteId();
9090
$isGlobal = $attribute->isScopeGlobal() || $websiteId === 0;
9191
$identifierField = $this->metadataPoll->getMetadata(ProductInterface::class)->getLinkField();
92-
$productId = (int) $entity->getData($identifierField);
92+
$productId = (int)$entity->getData($identifierField);
9393

9494
// prepare original data to compare
9595
$origPrices = [];
@@ -98,7 +98,7 @@ public function execute($entity, $arguments = [])
9898
$origPrices = $entity->getOrigData($attribute->getName());
9999
}
100100

101-
$old = $this->prepareOriginalDataToCompare($origPrices, $isGlobal);
101+
$old = $this->prepareOldTierPriceToCompare($origPrices);
102102
// prepare data for save
103103
$new = $this->prepareNewDataForSave($priceRows, $isGlobal);
104104

@@ -271,21 +271,18 @@ private function isWebsiteGlobal(int $websiteId): bool
271271
}
272272

273273
/**
274-
* Prepare original data to compare.
274+
* Prepare old data to compare.
275275
*
276276
* @param array|null $origPrices
277-
* @param bool $isGlobal
278277
* @return array
279278
*/
280-
private function prepareOriginalDataToCompare(?array $origPrices, bool $isGlobal = true): array
279+
private function prepareOldTierPriceToCompare(?array $origPrices): array
281280
{
282281
$old = [];
283282
if (is_array($origPrices)) {
284283
foreach ($origPrices as $data) {
285-
if ($isGlobal === $this->isWebsiteGlobal((int)$data['website_id'])) {
286-
$key = $this->getPriceKey($data);
287-
$old[$key] = $data;
288-
}
284+
$key = $this->getPriceKey($data);
285+
$old[$key] = $data;
289286
}
290287
}
291288

app/code/Magento/CatalogGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ interface CustomizableOptionInterface @typeResolver(class: "Magento\\CatalogGrap
358358
title: String @doc(description: "The display name for this option")
359359
required: Boolean @doc(description: "Indicates whether the option is required")
360360
sort_order: Int @doc(description: "The order in which the option is displayed")
361+
option_id: Int @doc(description: "Option ID")
361362
}
362363

363364
interface CustomizableProductInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model\\ProductInterfaceTypeResolverComposite") @doc(description: "CustomizableProductInterface contains information about customizable product options.") {

app/code/Magento/Customer/Controller/Section/Load.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function __construct(
5959
}
6060

6161
/**
62-
* @return \Magento\Framework\Controller\Result\Json
62+
* @inheritdoc
6363
*/
6464
public function execute()
6565
{
@@ -71,11 +71,11 @@ public function execute()
7171
$sectionNames = $this->getRequest()->getParam('sections');
7272
$sectionNames = $sectionNames ? array_unique(\explode(',', $sectionNames)) : null;
7373

74-
$updateSectionId = $this->getRequest()->getParam('update_section_id');
75-
if ('false' === $updateSectionId) {
76-
$updateSectionId = false;
74+
$forceNewSectionTimestamp = $this->getRequest()->getParam('force_new_section_timestamp');
75+
if ('false' === $forceNewSectionTimestamp) {
76+
$forceNewSectionTimestamp = false;
7777
}
78-
$response = $this->sectionPool->getSectionsData($sectionNames, (bool)$updateSectionId);
78+
$response = $this->sectionPool->getSectionsData($sectionNames, (bool)$forceNewSectionTimestamp);
7979
} catch (\Exception $e) {
8080
$resultJson->setStatusHeader(
8181
\Zend\Http\Response::STATUS_CODE_400,

app/code/Magento/Customer/CustomerData/Section/Identifier.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ public function __construct(
4343
/**
4444
* Init mark(identifier) for sections
4545
*
46-
* @param bool $forceUpdate
46+
* @param bool $forceNewTimestamp
4747
* @return int
4848
*/
49-
public function initMark($forceUpdate)
49+
public function initMark($forceNewTimestamp)
5050
{
51-
if ($forceUpdate) {
51+
if ($forceNewTimestamp) {
5252
$this->markId = time();
5353
return $this->markId;
5454
}
@@ -67,19 +67,19 @@ public function initMark($forceUpdate)
6767
* Mark sections with data id
6868
*
6969
* @param array $sectionsData
70-
* @param null $sectionNames
71-
* @param bool $updateIds
70+
* @param array|null $sectionNames
71+
* @param bool $forceNewTimestamp
7272
* @return array
7373
*/
74-
public function markSections(array $sectionsData, $sectionNames = null, $updateIds = false)
74+
public function markSections(array $sectionsData, $sectionNames = null, $forceNewTimestamp = false)
7575
{
7676
if (!$sectionNames) {
7777
$sectionNames = array_keys($sectionsData);
7878
}
79-
$markId = $this->initMark($updateIds);
79+
$markId = $this->initMark($forceNewTimestamp);
8080

8181
foreach ($sectionNames as $name) {
82-
if ($updateIds || !array_key_exists(self::SECTION_KEY, $sectionsData[$name])) {
82+
if ($forceNewTimestamp || !array_key_exists(self::SECTION_KEY, $sectionsData[$name])) {
8383
$sectionsData[$name][self::SECTION_KEY] = $markId;
8484
}
8585
}

app/code/Magento/Customer/CustomerData/SectionPool.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ public function __construct(
5353
}
5454

5555
/**
56-
* {@inheritdoc}
56+
* @inheritdoc
5757
*/
58-
public function getSectionsData(array $sectionNames = null, $updateIds = false)
58+
public function getSectionsData(array $sectionNames = null, $forceNewTimestamp = false)
5959
{
6060
$sectionsData = $sectionNames ? $this->getSectionDataByNames($sectionNames) : $this->getAllSectionData();
61-
$sectionsData = $this->identifier->markSections($sectionsData, $sectionNames, $updateIds);
61+
$sectionsData = $this->identifier->markSections($sectionsData, $sectionNames, $forceNewTimestamp);
6262
return $sectionsData;
6363
}
6464

0 commit comments

Comments
 (0)