Skip to content

Commit 69f70db

Browse files
[Magento Community Engineering] Community Contributions - 2.4-develop-prs
- merged with '2.4-develop-express-lane-prs' branch
2 parents a763a2e + 866569c commit 69f70db

File tree

7 files changed

+353
-17
lines changed

7 files changed

+353
-17
lines changed

app/code/Magento/Sales/Model/Order/Email/Sender/ShipmentSender.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
use Magento\Framework\DataObject;
1818

1919
/**
20-
* Class ShipmentSender
20+
* Class for shipment email notification sender
2121
*
22+
* @deprecated since this class works only with the concrete model and no data interface
23+
* @see \Magento\Sales\Model\Order\Shipment\Sender\EmailSender
2224
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2325
*/
2426
class ShipmentSender extends Sender

app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/ShipmentSenderTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
use Magento\Sales\Model\Order\Email\Sender\ShipmentSender;
99

1010
/**
11-
* Test for Magento\Sales\Model\Order\Email\Sender\ShipmentSender class.
11+
* Test for Magento\Sales\Model\Order\Email\Sender\ShipmentSender class
12+
*
13+
* @deprecated since ShipmentSender is deprecated
14+
* @see \Magento\Sales\Model\Order\Email\Sender\ShipmentSender
1215
*/
1316
class ShipmentSenderTest extends AbstractSenderTest
1417
{

app/code/Magento/Search/Block/Term.php

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@
99
*/
1010
namespace Magento\Search\Block;
1111

12+
use Magento\Framework\DataObject;
13+
use Magento\Framework\Exception\NoSuchEntityException;
1214
use Magento\Framework\UrlFactory;
1315
use Magento\Framework\UrlInterface;
1416
use Magento\Framework\View\Element\Template;
1517
use Magento\Framework\View\Element\Template\Context;
1618
use Magento\Search\Model\ResourceModel\Query\CollectionFactory;
1719

1820
/**
21+
* Terms and conditions block
22+
*
1923
* @api
2024
* @since 100.0.2
2125
*/
@@ -37,15 +41,11 @@ class Term extends Template
3741
protected $_maxPopularity;
3842

3943
/**
40-
* Url factory
41-
*
4244
* @var UrlFactory
4345
*/
4446
protected $_urlFactory;
4547

4648
/**
47-
* Query collection factory
48-
*
4949
* @var CollectionFactory
5050
*/
5151
protected $_queryCollectionFactory;
@@ -71,17 +71,17 @@ public function __construct(
7171
* Load terms and try to sort it by names
7272
*
7373
* @return $this
74-
* @throws \Magento\Framework\Exception\NoSuchEntityException
74+
* @throws NoSuchEntityException
7575
*/
7676
protected function _loadTerms()
7777
{
7878
if (empty($this->_terms)) {
7979
$this->_terms = [];
80-
$terms = $this->_queryCollectionFactory->create()->setPopularQueryFilter(
81-
$this->_storeManager->getStore()->getId()
82-
)->setPageSize(
83-
100
84-
)->load()->getItems();
80+
$terms = $this->_queryCollectionFactory->create()
81+
->setPopularQueryFilter($this->_storeManager->getStore()->getId())
82+
->setPageSize(100)
83+
->load()
84+
->getItems();
8585

8686
if (count($terms) == 0) {
8787
return $this;
@@ -91,6 +91,7 @@ protected function _loadTerms()
9191
$this->_minPopularity = end($terms)->getPopularity();
9292
$range = $this->_maxPopularity - $this->_minPopularity;
9393
$range = $range == 0 ? 1 : $range;
94+
$termKeys = [];
9495
foreach ($terms as $term) {
9596
if (!$term->getPopularity()) {
9697
continue;
@@ -99,6 +100,7 @@ protected function _loadTerms()
99100
$temp[$term->getQueryText()] = $term;
100101
$termKeys[] = $term->getQueryText();
101102
}
103+
102104
natcasesort($termKeys);
103105

104106
foreach ($termKeys as $termKey) {
@@ -109,8 +111,10 @@ protected function _loadTerms()
109111
}
110112

111113
/**
114+
* Load and return terms
115+
*
112116
* @return array
113-
* @throws \Magento\Framework\Exception\NoSuchEntityException
117+
* @throws NoSuchEntityException
114118
*/
115119
public function getTerms()
116120
{
@@ -119,7 +123,9 @@ public function getTerms()
119123
}
120124

121125
/**
122-
* @param \Magento\Framework\DataObject $obj
126+
* Return search url
127+
*
128+
* @param DataObject $obj
123129
* @return string
124130
*/
125131
public function getSearchUrl($obj)
@@ -135,6 +141,8 @@ public function getSearchUrl($obj)
135141
}
136142

137143
/**
144+
* Return max popularity
145+
*
138146
* @return int
139147
*/
140148
public function getMaxPopularity()
@@ -143,6 +151,8 @@ public function getMaxPopularity()
143151
}
144152

145153
/**
154+
* Return min popularity
155+
*
146156
* @return int
147157
*/
148158
public function getMinPopularity()
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Search\Test\Unit\Block;
7+
8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
9+
use Magento\Framework\Url;
10+
use Magento\Framework\UrlFactory;
11+
use Magento\Framework\View\Element\Template\Context;
12+
use Magento\Search\Block\Term;
13+
use Magento\Search\Model\Query;
14+
use Magento\Search\Model\ResourceModel\Query\Collection;
15+
use Magento\Search\Model\ResourceModel\Query\CollectionFactory;
16+
use Magento\Store\Model\Store;
17+
use Magento\Store\Model\StoreManager;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use PHPUnit\Framework\TestCase;
20+
21+
/**
22+
* Tests for Terms block
23+
*/
24+
class TermsTest extends TestCase
25+
{
26+
/**
27+
* @var Context|MockObject
28+
*/
29+
private $contextMock;
30+
31+
/**
32+
* @var CollectionFactory|MockObject
33+
*/
34+
private $collectionFactoryMock;
35+
36+
/**
37+
* @var UrlFactory|MockObject
38+
*/
39+
private $urlFactoryMock;
40+
41+
/**
42+
* @var Term
43+
*/
44+
private $termsModel;
45+
46+
/**
47+
* @var StoreManager
48+
*/
49+
private $storeManagerMock;
50+
51+
/**
52+
* @inheritdoc
53+
*/
54+
public function setUp()
55+
{
56+
$objectManager = new ObjectManager($this);
57+
58+
$this->contextMock = $this->createMock(Context::class);
59+
$this->collectionFactoryMock = $this->createMock(CollectionFactory::class);
60+
$this->urlFactoryMock = $this->createMock(UrlFactory::class);
61+
$this->storeManagerMock = $this->createMock(StoreManager::class);
62+
63+
$this->contextMock->expects($this->once())
64+
->method('getStoreManager')
65+
->willReturn($this->storeManagerMock);
66+
$this->termsModel = $objectManager->getObject(
67+
Term::class,
68+
[
69+
'context' => $this->contextMock,
70+
'_queryCollectionFactory' => $this->collectionFactoryMock,
71+
'_urlFactory' => $this->urlFactoryMock
72+
]
73+
);
74+
}
75+
76+
/**
77+
* Verify terms
78+
*
79+
* @dataProvider termKeysProvider
80+
* @param string $termKey
81+
* @param bool $popularity
82+
*/
83+
public function testGetTerms(string $termKey, bool $popularity): void
84+
{
85+
$terms = $this->createMock(Collection::class);
86+
$dataObjectMock = $this->getMockBuilder(Query::class)
87+
->disableOriginalConstructor()
88+
->setMethods(['getPopularity', 'getQueryText'])
89+
->getMock();
90+
$storeMock = $this->createMock(Store::class);
91+
92+
$this->storeManagerMock->expects($this->once())
93+
->method('getStore')
94+
->willReturn($storeMock);
95+
$storeMock->expects($this->once())
96+
->method('getId')
97+
->willReturn(1);
98+
99+
$this->collectionFactoryMock->expects($this->once())
100+
->method('create')
101+
->willReturn($terms);
102+
$terms->expects($this->once())
103+
->method('setPopularQueryFilter')
104+
->willReturnSelf();
105+
$terms->expects($this->once())
106+
->method('setPageSize')
107+
->willReturnSelf();
108+
$terms->expects($this->once())
109+
->method('load')
110+
->willReturnSelf();
111+
$terms->expects($this->once())
112+
->method('getItems')
113+
->willReturn([$dataObjectMock]);
114+
$dataObjectMock->expects($this->exactly(!$popularity ? 3 : 4))
115+
->method('getPopularity')
116+
->willReturn($popularity);
117+
$dataObjectMock->expects($this->exactly(!$popularity ? 0 : 2))
118+
->method('getQueryText')
119+
->willReturn($termKey);
120+
121+
$this->assertEquals(!$popularity ? [] : [$termKey => $dataObjectMock], $this->termsModel->getTerms());
122+
}
123+
124+
/**
125+
* Verify get search Url
126+
*
127+
* @return void
128+
*/
129+
public function testGetSearchResult(): void
130+
{
131+
$urlMock = $this->getMockBuilder(Url::class)
132+
->disableOriginalConstructor()
133+
->setMethods(['setQueryParam', 'getUrl'])
134+
->getMock();
135+
136+
$dataObjectMock = $this->getMockBuilder(Query::class)
137+
->disableOriginalConstructor()
138+
->setMethods(['getPopularity', 'getQueryText'])
139+
->getMock();
140+
$this->urlFactoryMock->expects($this->once())
141+
->method('create')
142+
->willReturn($urlMock);
143+
$dataObjectMock->expects($this->once())
144+
->method('getQueryText')
145+
->willReturn('url');
146+
$urlMock->expects($this->once())->method('setQueryParam');
147+
$urlMock->expects($this->once())
148+
->method('getUrl')
149+
->with('catalogsearch/result')
150+
->willReturn('url');
151+
152+
$this->assertEquals('url', $this->termsModel->getSearchUrl($dataObjectMock));
153+
}
154+
155+
/**
156+
* Terms data key provider
157+
*
158+
* @return array
159+
*/
160+
public function termKeysProvider(): array
161+
{
162+
return [
163+
[
164+
'search',
165+
true
166+
],
167+
[
168+
'',
169+
false
170+
]
171+
];
172+
}
173+
}

app/code/Magento/Theme/Controller/Result/AsyncCssPlugin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ function ($matches) use (&$cssMatches) {
5858
}
5959
$media = $media ?? 'all';
6060
$loadCssAsync = sprintf(
61-
'<link rel="preload" as="style" media="%s" .
62-
onload="this.onload=null;this.rel=\'stylesheet\'"' .
63-
'href="%s">',
61+
'<link rel="preload" as="style" media="%s"' .
62+
' onload="this.onload=null;this.rel=\'stylesheet\'"' .
63+
' href="%s" />',
6464
$media,
6565
$href
6666
);

0 commit comments

Comments
 (0)