Skip to content

Commit 2506852

Browse files
authored
Merge branch '2.4-develop' into cron-log
2 parents 986eb5b + 015b8dd commit 2506852

File tree

844 files changed

+19257
-16388
lines changed

Some content is hidden

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

844 files changed

+19257
-16388
lines changed

app/code/Magento/AdminAnalytics/Controller/Adminhtml/Config/EnableAdminUsage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private function markUserNotified(): ResultInterface
8989
public function execute()
9090
{
9191
$this->enableAdminUsage();
92-
$this->markUserNotified();
92+
return $this->markUserNotified();
9393
}
9494

9595
/**
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Magento\AdminAnalytics\Test\Unit\Controller\Adminhtml\Config;
10+
11+
use Magento\AdminAnalytics\Controller\Adminhtml\Config\EnableAdminUsage;
12+
use Magento\AdminAnalytics\Model\ResourceModel\Viewer\Logger as NotificationLogger;
13+
use Magento\Config\Model\Config;
14+
use Magento\Config\Model\Config\Factory as ConfigFactory;
15+
use Magento\Framework\App\ProductMetadataInterface;
16+
use Magento\Framework\Controller\Result\Json as JsonResult;
17+
use Magento\Framework\Controller\ResultFactory;
18+
use Magento\Framework\Controller\ResultInterface;
19+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
20+
use PHPUnit\Framework\MockObject\MockObject;
21+
22+
/**
23+
* @covers \Magento\AdminAnalytics\Controller\Adminhtml\Config\EnableAdminUsage
24+
*/
25+
class EnableAdminUsageTest extends \PHPUnit\Framework\TestCase
26+
{
27+
private const STUB_PRODUCT_VERSION = 'Product Version';
28+
29+
/** @var EnableAdminUsage */
30+
private $controller;
31+
32+
/** @var MockObject|Config */
33+
private $configMock;
34+
35+
/** @var MockObject|ProductMetadataInterface */
36+
private $productMetadataMock;
37+
38+
/** @var MockObject|NotificationLogger */
39+
private $notificationLoggerMock;
40+
41+
/** @var MockObject|ResultFactory */
42+
private $resultFactoryMock;
43+
44+
/** @var JsonResult|MockObject */
45+
private $resultMock;
46+
47+
protected function setUp(): void
48+
{
49+
$objectManager = new ObjectManager($this);
50+
51+
$this->configMock = $this->getMockBuilder(Config::class)
52+
->disableOriginalConstructor()
53+
->onlyMethods(['setDataByPath', 'save'])
54+
->getMock();
55+
56+
$configFactory = $this->getMockBuilder(ConfigFactory::class)
57+
->disableOriginalConstructor()
58+
->onlyMethods(['create'])
59+
->getMock();
60+
61+
$configFactory->method('create')
62+
->willReturn($this->configMock);
63+
64+
$this->productMetadataMock = $this->getMockBuilder(ProductMetadataInterface::class)
65+
->onlyMethods(['getVersion'])
66+
->getMockForAbstractClass();
67+
68+
$this->productMetadataMock->method('getVersion')
69+
->willReturn(self::STUB_PRODUCT_VERSION);
70+
71+
$this->notificationLoggerMock = $this->getMockBuilder(NotificationLogger::class)
72+
->disableOriginalConstructor()
73+
->onlyMethods(['log'])
74+
->getMock();
75+
76+
$this->resultFactoryMock = $this->getMockBuilder(ResultFactory::class)
77+
->disableOriginalConstructor()
78+
->onlyMethods(['create'])
79+
->getMock();
80+
81+
$this->resultMock = $this->getMockBuilder(JsonResult::class)
82+
->disableOriginalConstructor()
83+
->onlyMethods(['setData'])
84+
->getMock();
85+
86+
$this->resultFactoryMock->method('create')
87+
->with(ResultFactory::TYPE_JSON)
88+
->willReturn($this->resultMock);
89+
90+
$this->controller = $objectManager->getObject(EnableAdminUsage::class, [
91+
'configFactory' => $configFactory,
92+
'productMetadata' => $this->productMetadataMock,
93+
'notificationLogger' => $this->notificationLoggerMock,
94+
'resultFactory' => $this->resultFactoryMock
95+
]);
96+
}
97+
98+
/**
99+
* If Controller returns `null`, no data is passed to the browser
100+
*/
101+
public function testResponseAfterAdminUsageChange()
102+
{
103+
// Given
104+
$this->resultMock->method('setData')->willReturnSelf();
105+
106+
// When
107+
$response = $this->controller->execute();
108+
109+
// Then
110+
$this->assertInstanceOf(ResultInterface::class, $response);
111+
}
112+
113+
public function testResponseWhenExceptionThrown()
114+
{
115+
$this->markTestSkipped('magento/magento2#31393 Lack of exception handling');
116+
117+
$this->configMock->method('setDataByPath')
118+
->willThrowException(
119+
new \Exception('System Exception')
120+
);
121+
122+
// When
123+
$response = $this->controller->execute();
124+
125+
// Then
126+
$this->assertInstanceOf(ResultInterface::class, $response);
127+
}
128+
}

app/code/Magento/AdminAnalytics/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"sort-packages": true
66
},
77
"require": {
8-
"php": "~8.1.0||~8.2.0",
8+
"php": "~8.1.0||~8.2.0||~8.3.0",
99
"magento/framework": "*",
1010
"magento/module-backend": "*",
1111
"magento/module-config": "*",

app/code/Magento/AdminNotification/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"sort-packages": true
66
},
77
"require": {
8-
"php": "~8.1.0||~8.2.0",
8+
"php": "~8.1.0||~8.2.0||~8.3.0",
99
"lib-libxml": "*",
1010
"magento/framework": "*",
1111
"magento/module-backend": "*",

app/code/Magento/AdvancedPricingImportExport/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"sort-packages": true
66
},
77
"require": {
8-
"php": "~8.1.0||~8.2.0",
8+
"php": "~8.1.0||~8.2.0||~8.3.0",
99
"magento/framework": "*",
1010
"magento/module-catalog": "*",
1111
"magento/module-catalog-import-export": "*",
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
/************************************************************************
3+
*
4+
* Copyright 2023 Adobe
5+
* All Rights Reserved.
6+
*
7+
* NOTICE: All information contained herein is, and remains
8+
* the property of Adobe and its suppliers, if any. The intellectual
9+
* and technical concepts contained herein are proprietary to Adobe
10+
* and its suppliers and are protected by all applicable intellectual
11+
* property laws, including trade secret and copyright laws.
12+
* Dissemination of this information or reproduction of this material
13+
* is strictly forbidden unless prior written permission is obtained
14+
* from Adobe.
15+
* ***********************************************************************
16+
*/
17+
declare(strict_types=1);
18+
19+
namespace Magento\AdvancedSearch\Model\DataProvider;
20+
21+
use Magento\Search\Model\Autocomplete\DataProviderInterface;
22+
use Magento\Search\Model\Autocomplete\ItemFactory;
23+
use Magento\Search\Model\QueryFactory;
24+
use Magento\Framework\App\Config\ScopeConfigInterface as ScopeConfig;
25+
use Magento\AdvancedSearch\Model\SuggestedQueries;
26+
use Magento\CatalogSearch\Model\Autocomplete\DataProvider;
27+
use Magento\AdvancedSearch\Model\SuggestedQueriesInterface;
28+
use Magento\Store\Model\ScopeInterface;
29+
30+
class AutocompleteSuggestions implements DataProviderInterface
31+
{
32+
/**
33+
* @var QueryFactory
34+
*/
35+
private $queryFactory;
36+
37+
/**
38+
* @var ItemFactory
39+
*/
40+
private $itemFactory;
41+
42+
/**
43+
* @var SuggestedQueries
44+
*/
45+
private $suggestedQueries;
46+
47+
/**
48+
* @var DataProvider
49+
*/
50+
private $dataProvider;
51+
52+
/**
53+
* @var ScopeConfig
54+
*/
55+
private $scopeConfig;
56+
57+
/**
58+
* @param QueryFactory $queryFactory
59+
* @param ItemFactory $itemFactory
60+
* @param ScopeConfig $scopeConfig
61+
* @param SuggestedQueries $suggestedQueries
62+
* @param DataProvider $dataProvider
63+
*/
64+
public function __construct(
65+
QueryFactory $queryFactory,
66+
ItemFactory $itemFactory,
67+
ScopeConfig $scopeConfig,
68+
SuggestedQueries $suggestedQueries,
69+
DataProvider $dataProvider
70+
) {
71+
$this->queryFactory = $queryFactory;
72+
$this->itemFactory = $itemFactory;
73+
$this->suggestedQueries = $suggestedQueries;
74+
$this->dataProvider = $dataProvider;
75+
$this->scopeConfig = $scopeConfig;
76+
}
77+
78+
/**
79+
* @inheritdoc
80+
*/
81+
public function getItems()
82+
{
83+
$result = [];
84+
if ($this->scopeConfig->isSetFlag(
85+
SuggestedQueriesInterface::SEARCH_SUGGESTION_ENABLED,
86+
ScopeInterface::SCOPE_STORE
87+
)) {
88+
// populate with search suggestions
89+
$query = $this->queryFactory->get();
90+
$suggestions = $this->suggestedQueries->getItems($query);
91+
foreach ($suggestions as $suggestion) {
92+
$resultItem = $this->itemFactory->create([
93+
'title' => $suggestion->getQueryText(),
94+
'num_results' => $suggestion->getResultsCount(),
95+
]);
96+
$result[] = $resultItem;
97+
}
98+
} else {
99+
// populate with autocomplete
100+
$result = $this->dataProvider->getItems();
101+
}
102+
return $result;
103+
}
104+
}

0 commit comments

Comments
 (0)