Skip to content

Commit eddfd51

Browse files
[Magento Community Engineering] Community Contributions - 2.3-develop
- merged latest code from mainline branch
2 parents 5a92658 + 65763df commit eddfd51

File tree

57 files changed

+1912
-78
lines changed

Some content is hidden

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

57 files changed

+1912
-78
lines changed
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
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\AdvancedSearch\Test\Unit\Model\Recommendations;
9+
10+
use Magento\AdvancedSearch\Model\Recommendations\DataProvider;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
13+
use Magento\Catalog\Model\Layer\Resolver;
14+
use Magento\AdvancedSearch\Model\ResourceModel\Recommendations;
15+
use Magento\AdvancedSearch\Model\ResourceModel\RecommendationsFactory;
16+
use Magento\Search\Model\QueryResult;
17+
use Magento\Search\Model\QueryResultFactory;
18+
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
19+
use Magento\Catalog\Model\Layer as SearchLayer;
20+
use Magento\Store\Model\ScopeInterface;
21+
use Magento\Search\Model\QueryInterface;
22+
23+
/**
24+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
25+
*
26+
* Class \Magento\AdvancedSearch\Test\Unit\Model\Recommendations\DataProviderTest
27+
*/
28+
class DataProviderTest extends \PHPUnit\Framework\TestCase
29+
{
30+
/**
31+
* @var DataProvider;
32+
*/
33+
private $model;
34+
35+
/**
36+
* @var ObjectManagerHelper
37+
*/
38+
private $objectManagerHelper;
39+
40+
/**
41+
* @var \PHPUnit_Framework_MockObject_MockObject|ScopeConfigInterface
42+
*/
43+
private $scopeConfigMock;
44+
45+
/**
46+
* @var \PHPUnit_Framework_MockObject_MockObject|Resolver
47+
*/
48+
private $layerResolverMock;
49+
50+
/**
51+
* @var \PHPUnit_Framework_MockObject_MockObject|SearchLayer
52+
*/
53+
private $searchLayerMock;
54+
55+
/**
56+
* @var \PHPUnit_Framework_MockObject_MockObject|RecommendationsFactory
57+
*/
58+
private $recommendationsFactoryMock;
59+
60+
/**
61+
* @var \PHPUnit_Framework_MockObject_MockObject|Recommendations
62+
*/
63+
private $recommendationsMock;
64+
65+
/**
66+
* @var \PHPUnit_Framework_MockObject_MockObject|Resolver
67+
*/
68+
private $queryResultFactory;
69+
70+
/**
71+
* Set up test environment.
72+
*
73+
* @return void
74+
*/
75+
protected function setUp()
76+
{
77+
$this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class);
78+
$this->layerResolverMock = $this->getMockBuilder(Resolver::class)
79+
->disableOriginalConstructor()
80+
->setMethods(['get'])
81+
->getMock();
82+
83+
$this->searchLayerMock = $this->createMock(SearchLayer::class);
84+
85+
$this->layerResolverMock->expects($this->any())
86+
->method('get')
87+
->will($this->returnValue($this->searchLayerMock));
88+
89+
$this->recommendationsFactoryMock = $this->getMockBuilder(RecommendationsFactory::class)
90+
->disableOriginalConstructor()
91+
->setMethods(['create'])
92+
->getMock();
93+
94+
$this->recommendationsMock = $this->createMock(Recommendations::class);
95+
96+
$this->queryResultFactory = $this->getMockBuilder(QueryResultFactory::class)
97+
->disableOriginalConstructor()
98+
->setMethods(['create'])
99+
->getMock();
100+
101+
$this->objectManagerHelper = new ObjectManagerHelper($this);
102+
$this->model = $this->objectManagerHelper->getObject(
103+
DataProvider::class,
104+
[
105+
'scopeConfig' => $this->scopeConfigMock,
106+
'layerResolver' => $this->layerResolverMock,
107+
'recommendationsFactory' => $this->recommendationsFactoryMock,
108+
'queryResultFactory' => $this->queryResultFactory
109+
]
110+
);
111+
}
112+
113+
/**
114+
* Test testGetItems() when Search Recommendations disabled.
115+
*
116+
* @return void
117+
*/
118+
public function testGetItemsWhenDisabledSearchRecommendations()
119+
{
120+
$isEnabledSearchRecommendations = false;
121+
122+
/** @var $queryInterfaceMock QueryInterface */
123+
$queryInterfaceMock = $this->createMock(QueryInterface::class);
124+
125+
$this->scopeConfigMock->expects($this->any())
126+
->method('isSetFlag')
127+
->with('catalog/search/search_recommendations_enabled', ScopeInterface::SCOPE_STORE)
128+
->willReturn($isEnabledSearchRecommendations);
129+
130+
$result = $this->model->getItems($queryInterfaceMock);
131+
$this->assertEquals([], $result);
132+
}
133+
134+
/**
135+
* Test testGetItems() when Search Recommendations enabled.
136+
*
137+
* @return void
138+
*/
139+
public function testGetItemsWhenEnabledSearchRecommendations()
140+
{
141+
$storeId = 1;
142+
$searchRecommendationsCountConfig = 2;
143+
$isEnabledSearchRecommendations = true;
144+
$queryText = 'test';
145+
146+
/** @var $queryInterfaceMock QueryInterface */
147+
$queryInterfaceMock = $this->createMock(QueryInterface::class);
148+
$queryInterfaceMock->expects($this->any())->method('getQueryText')->willReturn($queryText);
149+
150+
$this->scopeConfigMock->expects($this->any())
151+
->method('isSetFlag')
152+
->with('catalog/search/search_recommendations_enabled', ScopeInterface::SCOPE_STORE)
153+
->willReturn($isEnabledSearchRecommendations);
154+
155+
$this->scopeConfigMock->expects($this->any())
156+
->method('getValue')
157+
->with('catalog/search/search_recommendations_count', ScopeInterface::SCOPE_STORE)
158+
->willReturn($searchRecommendationsCountConfig);
159+
160+
$productCollectionMock = $this->createMock(ProductCollection::class);
161+
$productCollectionMock->expects($this->any())->method('getStoreId')->willReturn($storeId);
162+
163+
$this->searchLayerMock->expects($this->any())->method('getProductCollection')
164+
->willReturn($productCollectionMock);
165+
166+
$this->recommendationsFactoryMock->expects($this->any())->method('create')
167+
->willReturn($this->recommendationsMock);
168+
169+
$this->recommendationsMock->expects($this->any())->method('getRecommendationsByQuery')
170+
->with($queryText, ['store_id' => $storeId], $searchRecommendationsCountConfig)
171+
->willReturn(
172+
[
173+
[
174+
'query_text' => 'a',
175+
'num_results' => 3
176+
],
177+
[
178+
'query_text' => 'b',
179+
'num_results' => 2
180+
]
181+
]
182+
);
183+
$queryResultMock = $this->createMock(QueryResult::class);
184+
$this->queryResultFactory->expects($this->any())->method('create')->willReturn($queryResultMock);
185+
186+
$result = $this->model->getItems($queryInterfaceMock);
187+
$this->assertEquals(2, count($result));
188+
}
189+
}

app/code/Magento/Backend/Test/Mftf/Test/AdminCheckLocaleAndDeveloperConfigInDeveloperModeTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<test name="AdminCheckLocaleAndDeveloperConfigInDeveloperModeTest">
1212
<annotations>
1313
<features value="Backend"/>
14+
<stories value="Menu Navigation"/>
1415
<title value="Check locale dropdown and developer configuration page are available in developer mode"/>
1516
<description value="Check locale dropdown and developer configuration page are available in developer mode"/>
1617
<group value="backend"/>

app/code/Magento/Backend/Test/Mftf/Test/AdminCheckLocaleAndDeveloperConfigInProductionModeTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<test name="AdminCheckLocaleAndDeveloperConfigInProductionModeTest">
1212
<annotations>
1313
<features value="Backend"/>
14+
<stories value="Menu Navigation"/>
1415
<title value="Check locale dropdown and developer configuration page are not available in production mode"/>
1516
<description value="Check locale dropdown and developer configuration page are not available in production mode"/>
1617
<testCaseId value="MC-14106" />

app/code/Magento/Bundle/Test/Mftf/Test/StorefrontCustomerSearchBundleProductsByKeywordsTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<requiredEntity createDataKey="fixedBundleOption"/>
4040
<requiredEntity createDataKey="createSimpleProductTwo"/>
4141
</createData>
42-
<magentoCLI command="indexer:reindex" arguments="cataloginventory_stock catalogsearch_fulltext" stepKey="reindex"/>
42+
<magentoCLI command="indexer:reindex" stepKey="reindex"/>
4343
</before>
4444
<after>
4545
<deleteData createDataKey="createDynamicBundle" stepKey="deleteDynamicBundleProduct"/>
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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\CardinalCommerce\Test\Unit\Model\Response;
9+
10+
use Magento\CardinalCommerce\Model\Response\JwtParser;
11+
use Magento\CardinalCommerce\Model\Config;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
use Magento\CardinalCommerce\Model\JwtManagement;
14+
use Magento\CardinalCommerce\Model\Response\JwtPayloadValidatorInterface;
15+
use Magento\Framework\Exception\LocalizedException;
16+
17+
/**
18+
* Class \Magento\CardinalCommerce\Test\Unit\Model\Response\JwtParserTest
19+
*/
20+
class JwtParserTest extends \PHPUnit\Framework\TestCase
21+
{
22+
/**
23+
* @var ObjectManager
24+
*/
25+
private $objectManager;
26+
27+
/**
28+
* @var JwtParser
29+
*/
30+
private $model;
31+
32+
/**
33+
* @var \PHPUnit_Framework_MockObject_MockObject | Config
34+
*/
35+
private $configMock;
36+
37+
/**
38+
* @var \PHPUnit_Framework_MockObject_MockObject | JwtManagement
39+
*/
40+
private $jwtManagementMock;
41+
42+
/**
43+
* @var \PHPUnit_Framework_MockObject_MockObject | JwtPayloadValidatorInterface
44+
*/
45+
private $jwtPayloadValidatorMock;
46+
47+
/**
48+
* @inheritdoc
49+
*/
50+
protected function setUp()
51+
{
52+
$this->objectManager = new ObjectManager($this);
53+
54+
$this->configMock = $this->getMockBuilder(Config::class)
55+
->setMethods(['getApiKey', 'isDebugModeEnabled'])
56+
->disableOriginalConstructor()
57+
->getMock();
58+
59+
$this->jwtManagementMock = $this->getMockBuilder(JwtManagement::class)
60+
->setMethods(['decode'])
61+
->disableOriginalConstructor()
62+
->getMock();
63+
64+
$this->jwtPayloadValidatorMock = $this->getMockBuilder(JwtPayloadValidatorInterface::class)
65+
->setMethods(['validate'])
66+
->disableOriginalConstructor()
67+
->getMock();
68+
69+
$this->model = $this->objectManager->getObject(
70+
JwtParser::class,
71+
[
72+
'jwtManagement' => $this->jwtManagementMock,
73+
'config' => $this->configMock,
74+
'tokenValidator' => $this->jwtPayloadValidatorMock
75+
]
76+
);
77+
78+
$this->configMock->expects($this->any())
79+
->method('getApiKey')
80+
->willReturn('API Key');
81+
82+
$this->configMock->expects($this->any())
83+
->method('isDebugModeEnabled')
84+
->willReturn(false);
85+
86+
$this->jwtManagementMock->expects($this->any())
87+
->method('decode')
88+
->with('string_to_test', 'API Key')
89+
->willReturn(['mockResult' => 'jwtPayload']);
90+
}
91+
92+
/**
93+
* Tests Jwt Parser execute with the result and no exception.
94+
*/
95+
public function testExecuteWithNoException()
96+
{
97+
/* Validate Success */
98+
$this->jwtPayloadValidatorMock->expects($this->any())
99+
->method('validate')
100+
->with(['mockResult' => 'jwtPayload'])
101+
->willReturn(true);
102+
103+
/* Assert the result of function */
104+
$jwtPayload = $this->model->execute('string_to_test');
105+
$this->assertEquals(
106+
['mockResult' => 'jwtPayload'],
107+
$jwtPayload
108+
);
109+
}
110+
111+
/**
112+
* Tests Jwt Parser execute with exception and no result.
113+
*/
114+
public function testExecuteWithException()
115+
{
116+
/* Validate Fail */
117+
$this->jwtPayloadValidatorMock->expects($this->any())
118+
->method('validate')
119+
->with(['mockResult' => 'jwtPayload'])
120+
->willReturn(false);
121+
122+
$this->expectException(LocalizedException::class);
123+
$this->expectExceptionMessage(
124+
'Authentication Failed. Your card issuer cannot authenticate this card. ' .
125+
'Please select another card or form of payment to complete your purchase.'
126+
);
127+
128+
/* Execute function */
129+
$this->model->execute('string_to_test');
130+
}
131+
}

app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2520,10 +2520,10 @@ public function getPricesCount()
25202520
/**
25212521
* Add is_saleable attribute to filter
25222522
*
2523-
* @param array|null $condition
2523+
* @param mixed $condition
25242524
* @return $this
25252525
*/
2526-
private function addIsSaleableAttributeToFilter(?array $condition): self
2526+
private function addIsSaleableAttributeToFilter($condition): self
25272527
{
25282528
$columns = $this->getSelect()->getPart(Select::COLUMNS);
25292529
foreach ($columns as $columnEntry) {
@@ -2551,10 +2551,10 @@ private function addIsSaleableAttributeToFilter(?array $condition): self
25512551
* Add tier price attribute to filter
25522552
*
25532553
* @param string $attribute
2554-
* @param array|null $condition
2554+
* @param mixed $condition
25552555
* @return $this
25562556
*/
2557-
private function addTierPriceAttributeToFilter(string $attribute, ?array $condition): self
2557+
private function addTierPriceAttributeToFilter(string $attribute, $condition): self
25582558
{
25592559
$attrCode = $attribute;
25602560
$connection = $this->getConnection();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<test name="DisplayRefreshCacheAfterChangingCategoryPageLayoutTest">
1212
<annotations>
1313
<features value="Catalog"/>
14+
<stories value="Category Layout Change"/>
1415
<title value="'Refresh cache' admin notification is displayed when changing category page layout"/>
1516
<description value="'Refresh cache' message is not displayed when changing category page layout"/>
1617
<severity value="MAJOR"/>

0 commit comments

Comments
 (0)