Skip to content

Commit fe976d7

Browse files
#39169: Special Price To Date is wrongly validated on applySpecialPrice
- fix unit tests
1 parent 9b27e4d commit fe976d7

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

app/code/Magento/Bundle/Model/Product/Price.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ class Price extends \Magento\Catalog\Model\Product\Type\Price
5252
*/
5353
private $serializer;
5454

55-
56-
/**
57-
* @var SpecialPriceService
58-
*/
59-
protected SpecialPriceService $specialPriceService;
60-
6155
/**
6256
* Constructor
6357
*
@@ -94,8 +88,6 @@ public function __construct(
9488
$this->_catalogData = $catalogData;
9589
$this->serializer = $serializer ?: ObjectManager::getInstance()
9690
->get(\Magento\Framework\Serialize\Serializer\Json::class);
97-
$this->specialPriceService = $specialPriceService ?: ObjectManager::getInstance()
98-
->get(SpecialPriceService::class);
9991
parent::__construct(
10092
$ruleFactory,
10193
$storeManager,
@@ -106,7 +98,8 @@ public function __construct(
10698
$groupManagement,
10799
$tierPriceFactory,
108100
$config,
109-
$tierPriceExtensionFactory
101+
$tierPriceExtensionFactory,
102+
$specialPriceService
110103
);
111104
}
112105

app/code/Magento/Bundle/Test/Unit/Model/Product/PriceTest.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -14,6 +14,7 @@
1414
use Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory;
1515
use Magento\Catalog\Helper\Data;
1616
use Magento\Catalog\Model\Product;
17+
use Magento\Catalog\Service\SpecialPriceService;
1718
use Magento\CatalogRule\Model\ResourceModel\RuleFactory;
1819
use Magento\Customer\Api\GroupManagementInterface;
1920
use Magento\Customer\Model\Session;
@@ -135,6 +136,17 @@ function ($value) {
135136
->onlyMethods(['create'])
136137
->disableOriginalConstructor()
137138
->getMock();
139+
140+
$specialPriceService = $this->getMockBuilder(SpecialPriceService::class)
141+
->disableOriginalConstructor()
142+
->getMock();
143+
144+
$specialPriceService->expects($this->any())
145+
->method('execute')
146+
->willReturnCallback(function($value) {
147+
return $value;
148+
});
149+
138150
$objectManagerHelper = new ObjectManagerHelper($this);
139151
$this->model = $objectManagerHelper->getObject(
140152
Price::class,
@@ -150,7 +162,8 @@ function ($value) {
150162
'config' => $scopeConfig,
151163
'catalogData' => $this->catalogHelperMock,
152164
'serializer' => $this->serializer,
153-
'tierPriceExtensionFactory' => $tierPriceExtensionFactoryMock
165+
'tierPriceExtensionFactory' => $tierPriceExtensionFactoryMock,
166+
'specialPriceService' => $specialPriceService
154167
]
155168
);
156169
}

app/code/Magento/Bundle/Test/Unit/Pricing/Price/SpecialPriceTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Bundle\Pricing\Price\SpecialPrice;
1212
use Magento\Catalog\Model\Product;
1313
use Magento\Catalog\Pricing\Price\RegularPrice;
14+
use Magento\Catalog\Service\SpecialPriceService;
1415
use Magento\Framework\Pricing\Price\PriceInterface;
1516
use Magento\Framework\Pricing\PriceCurrencyInterface;
1617
use Magento\Framework\Pricing\PriceInfo\Base;
@@ -48,6 +49,11 @@ class SpecialPriceTest extends TestCase
4849
*/
4950
protected $priceCurrencyMock;
5051

52+
/**
53+
* @var SpecialPriceService|MockObject
54+
*/
55+
private $specialPriceService;
56+
5157
protected function setUp(): void
5258
{
5359
$this->saleable = $this->getMockBuilder(Product::class)
@@ -63,13 +69,18 @@ protected function setUp(): void
6369

6470
$this->priceCurrencyMock = $this->getMockForAbstractClass(PriceCurrencyInterface::class);
6571

72+
$this->specialPriceService = $this->getMockBuilder(SpecialPriceService::class)
73+
->disableOriginalConstructor()
74+
->getMock();
75+
6676
$objectHelper = new ObjectManager($this);
6777
$this->model = $objectHelper->getObject(
6878
SpecialPrice::class,
6979
[
7080
'saleableItem' => $this->saleable,
7181
'localeDate' => $this->localeDate,
72-
'priceCurrency' => $this->priceCurrencyMock
82+
'priceCurrency' => $this->priceCurrencyMock,
83+
'specialPriceService' => $this->specialPriceService
7384
]
7485
);
7586
}
@@ -103,6 +114,11 @@ public function testGetValue($regularPrice, $specialPrice, $isScopeDateInInterva
103114
->with(WebsiteInterface::ADMIN_CODE, $specialFromDate, $specialToDate)
104115
->willReturn($isScopeDateInInterval);
105116

117+
$this->specialPriceService->expects($this->once())
118+
->method('execute')
119+
->with($specialToDate)
120+
->willReturn($specialToDate);
121+
106122
$this->priceCurrencyMock->expects($this->never())
107123
->method('convertAndRound');
108124

0 commit comments

Comments
 (0)