Skip to content

Commit b64fa5b

Browse files
🔃 [Magento Community Engineering] Community Contributions - 2.4-develop latest changes
Accepted Community Pull Requests: - #26424: Add to Compare link does not show in mobile view under 640px in blank theme (by @ptylek) - #26313: Issue-25968 - Added additional checking for returning needed variable� (by @AndreyChorniy) - #26402: magento/magento2#: Unit test for \Magento\AdminNotification\Observer\PredispatchAdminActionControllerObserver (by @atwixfirster) - #26365: Add to Compare link not showing in mobile view under 640px (by @tejash-wagento) Fixed GitHub Issues: - #26364: Add to Compare link not showing in mobile view under 640px (reported by @tejash-wagento) has been fixed in #26424 by @ptylek in 2.4-develop branch Related commits: 1. 9ec1d67 - #25968: `getPrice()` returns a string when setting custom price in admin order (reported by @paul-gene) has been fixed in #26313 by @AndreyChorniy in 2.4-develop branch Related commits: 1. 0b7a99d 2. 28e8e5a 3. 71da244 - #26364: Add to Compare link not showing in mobile view under 640px (reported by @tejash-wagento) has been fixed in #26365 by @tejash-wagento in 2.4-develop branch Related commits: 1. f4f61f7
2 parents 1fdd709 + 01e0686 commit b64fa5b

File tree

5 files changed

+169
-13
lines changed

5 files changed

+169
-13
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\AdminNotification\Test\Unit\Observer;
7+
8+
use Magento\AdminNotification\Model\Feed;
9+
use Magento\AdminNotification\Model\FeedFactory;
10+
use Magento\AdminNotification\Observer\PredispatchAdminActionControllerObserver;
11+
use Magento\Backend\Model\Auth\Session;
12+
use Magento\Framework\Event\Observer;
13+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* Test class for \Magento\AdminNotification\Observer\PredispatchAdminActionControllerObserver
19+
*/
20+
class PredispatchAdminActionControllerObserverTest extends TestCase
21+
{
22+
private const STATUS_ADMIN_LOGGED_IN = true;
23+
private const STATUS_ADMIN_IS_NOT_LOGGED = false;
24+
25+
/**
26+
* @var Session|MockObject
27+
*/
28+
private $backendAuthSessionMock;
29+
30+
/**
31+
* @var Feed|MockObject
32+
*/
33+
private $feedMock;
34+
35+
/**
36+
* @var FeedFactory|MockObject
37+
*/
38+
private $feedFactoryMock;
39+
40+
/**
41+
* Object Manager Instance
42+
*
43+
* @var ObjectManager
44+
*/
45+
private $objectManager;
46+
47+
/**
48+
* Testable Object
49+
*
50+
* @var PredispatchAdminActionControllerObserver
51+
*/
52+
private $observer;
53+
54+
/**
55+
* @var Observer|MockObject
56+
*/
57+
private $observerMock;
58+
59+
/**
60+
* @inheritdoc
61+
*/
62+
protected function setUp() : void
63+
{
64+
$this->objectManager = new ObjectManager($this);
65+
$this->observerMock = $this->createMock(Observer::class);
66+
67+
$this->backendAuthSessionMock = $this->getMockBuilder(Session::class)
68+
->disableOriginalConstructor()
69+
->setMethods(['isLoggedIn'])
70+
->getMock();
71+
72+
$this->feedMock = $this->getMockBuilder(Feed::class)
73+
->disableOriginalConstructor()
74+
->setMethods(['checkUpdate'])
75+
->getMock();
76+
77+
$this->feedFactoryMock = $this->getMockBuilder(FeedFactory::class)
78+
->disableOriginalConstructor()
79+
->setMethods(['create'])
80+
->getMock();
81+
82+
$this->observer = $this->objectManager->getObject(
83+
PredispatchAdminActionControllerObserver::class,
84+
[
85+
'_feedFactory' => $this->feedFactoryMock,
86+
'_backendAuthSession' => $this->backendAuthSessionMock,
87+
]
88+
);
89+
}
90+
91+
/**
92+
* Test observer when admin user is logged in
93+
*/
94+
public function testPredispatchObserverWhenAdminLoggedIn()
95+
{
96+
$this->backendAuthSessionMock
97+
->expects($this->once())
98+
->method('isLoggedIn')
99+
->willReturn(self::STATUS_ADMIN_LOGGED_IN);
100+
101+
$this->feedFactoryMock
102+
->expects($this->once())
103+
->method('create')
104+
->willReturn($this->feedMock);
105+
106+
$this->feedMock
107+
->expects($this->once())
108+
->method('checkUpdate')
109+
->willReturn($this->feedMock);
110+
111+
$this->observer->execute($this->observerMock);
112+
}
113+
114+
/**
115+
* Test observer when admin user is not logged in
116+
*/
117+
public function testPredispatchObserverWhenAdminIsNotLoggedIn()
118+
{
119+
$this->backendAuthSessionMock
120+
->expects($this->once())
121+
->method('isLoggedIn')
122+
->willReturn(self::STATUS_ADMIN_IS_NOT_LOGGED);
123+
124+
$this->feedFactoryMock
125+
->expects($this->never())
126+
->method('create');
127+
128+
$this->feedMock
129+
->expects($this->never())
130+
->method('checkUpdate');
131+
132+
$this->observer->execute($this->observerMock);
133+
}
134+
}

app/code/Magento/Sales/Model/Order/Item.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ public function getStatus()
385385
*
386386
* @param string $statusId
387387
* @return \Magento\Framework\Phrase
388+
*
389+
* phpcs:disable Magento2.Functions.StaticFunction
388390
*/
389391
public static function getStatusName($statusId)
390392
{
@@ -422,6 +424,8 @@ public function cancel()
422424
* Retrieve order item statuses array
423425
*
424426
* @return array
427+
*
428+
* phpcs:disable Magento2.Functions.StaticFunction
425429
*/
426430
public static function getStatuses()
427431
{
@@ -1319,7 +1323,13 @@ public function getParentItemId()
13191323
*/
13201324
public function getPrice()
13211325
{
1322-
return $this->getData(OrderItemInterface::PRICE);
1326+
$price = $this->getData(OrderItemInterface::PRICE);
1327+
1328+
if ($price === null) {
1329+
return $price;
1330+
}
1331+
1332+
return (float) $price;
13231333
}
13241334

13251335
/**

app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
namespace Magento\Sales\Test\Unit\Model\Order;
88

99
use Magento\Framework\Serialize\Serializer\Json;
10+
use Magento\Sales\Api\Data\OrderItemInterface;
1011
use Magento\Sales\Model\ResourceModel\OrderFactory;
11-
use \Magento\Sales\Model\Order;
1212

1313
/**
14-
* Class ItemTest
15-
*
16-
* @package Magento\Sales\Model\Order
14+
* Unit test for order item class.
1715
*/
1816
class ItemTest extends \PHPUnit\Framework\TestCase
1917
{
@@ -72,7 +70,7 @@ public function testSetParentItem()
7270
public function testGetPatentItem()
7371
{
7472
$item = $this->objectManager->getObject(\Magento\Sales\Model\Order\Item::class, []);
75-
$this->model->setData(\Magento\Sales\Api\Data\OrderItemInterface::PARENT_ITEM, $item);
73+
$this->model->setData(OrderItemInterface::PARENT_ITEM, $item);
7674
$this->assertEquals($item, $this->model->getParentItem());
7775
}
7876

@@ -184,7 +182,7 @@ public function testGetOriginalPrice()
184182
$this->assertEquals($price, $this->model->getOriginalPrice());
185183

186184
$originalPrice = 5.55;
187-
$this->model->setData(\Magento\Sales\Api\Data\OrderItemInterface::ORIGINAL_PRICE, $originalPrice);
185+
$this->model->setData(OrderItemInterface::ORIGINAL_PRICE, $originalPrice);
188186
$this->assertEquals($originalPrice, $this->model->getOriginalPrice());
189187
}
190188

@@ -348,4 +346,24 @@ public function getItemQtyVariants()
348346
]
349347
];
350348
}
349+
350+
/**
351+
* Test getPrice() method returns float
352+
*/
353+
public function testGetPriceReturnsFloat()
354+
{
355+
$price = 9.99;
356+
$this->model->setPrice($price);
357+
$this->assertEquals($price, $this->model->getPrice());
358+
}
359+
360+
/**
361+
* Test getPrice() method returns null
362+
*/
363+
public function testGetPriceReturnsNull()
364+
{
365+
$nullablePrice = null;
366+
$this->model->setData(OrderItemInterface::PRICE, $nullablePrice);
367+
$this->assertEquals($nullablePrice, $this->model->getPrice());
368+
}
351369
}

app/design/frontend/Magento/blank/Magento_Catalog/web/css/source/_module.less

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,6 @@
543543
}
544544

545545
.compare,
546-
.product-addto-links .action.tocompare,
547546
.product-item-actions .actions-secondary > .action.tocompare,
548547
[class*='block-compare'] {
549548
display: none;

app/design/frontend/Magento/luma/Magento_Catalog/web/css/source/_module.less

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -623,11 +623,6 @@
623623
// _____________________________________________
624624

625625
.media-width(@extremum, @break) when (@extremum = 'max') and (@break = @screen__s) {
626-
.product-social-links {
627-
.action.tocompare {
628-
display: none;
629-
}
630-
}
631626

632627
.product-info-price {
633628
margin: 0 -@indent__s 0;

0 commit comments

Comments
 (0)