Skip to content

Commit e79e0fa

Browse files
#39169: Special Price To Date is wrongly validated on applySpecialPrice
- fixes for static and unit test
1 parent c8c8b35 commit e79e0fa

File tree

2 files changed

+134
-35
lines changed

2 files changed

+134
-35
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* Copyright 2015 Adobe
5+
* All Rights Reserved.
6+
*/
7+
8+
namespace Magento\Framework\Stdlib\Test\Unit\DateTime;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\App\ScopeInterface;
12+
use Magento\Framework\App\ScopeResolverInterface;
13+
use Magento\Framework\Locale\ResolverInterface;
14+
use Magento\Framework\Stdlib\DateTime;
15+
use Magento\Framework\Stdlib\DateTime\Intl\DateFormatterFactory;
16+
use Magento\Framework\Stdlib\DateTime\Timezone;
17+
use PHPUnit\Framework\MockObject\Exception;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use PHPUnit\Framework\TestCase;
20+
21+
/**
22+
* Test for scope date interval functionality @see Timezone
23+
*/
24+
class TimezoneScopeTest extends TestCase
25+
{
26+
/**
27+
* @var string|null
28+
*/
29+
private ?string $defaultTimeZone;
30+
31+
/**
32+
* @var string
33+
*/
34+
private string $scopeType = 'store';
35+
36+
/**
37+
* @var string
38+
*/
39+
private string $defaultTimezonePath = 'default/timezone/path';
40+
41+
/**
42+
* @var ScopeResolverInterface|MockObject
43+
*/
44+
private ScopeResolverInterface|MockObject $scopeResolver;
45+
46+
/**
47+
* @var ScopeConfigInterface|MockObject
48+
*/
49+
private MockObject|ScopeConfigInterface $scopeConfig;
50+
51+
/**
52+
* @var ResolverInterface|MockObject
53+
*/
54+
private ResolverInterface|MockObject $localeResolver;
55+
56+
/**
57+
* @inheritdoc
58+
*/
59+
protected function setUp(): void
60+
{
61+
$this->defaultTimeZone = date_default_timezone_get();
62+
date_default_timezone_set('UTC');
63+
$this->scopeType = 'store';
64+
$this->defaultTimezonePath = 'default/timezone/path';
65+
66+
$this->scopeResolver = $this->getMockBuilder(ScopeResolverInterface::class)
67+
->getMock();
68+
$this->localeResolver = $this->getMockBuilder(ResolverInterface::class)
69+
->getMock();
70+
$this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)
71+
->getMock();
72+
}
73+
74+
/**
75+
* @inheritdoc
76+
*/
77+
protected function tearDown(): void
78+
{
79+
date_default_timezone_set($this->defaultTimeZone);
80+
}
81+
82+
/**
83+
* @return Timezone
84+
* @throws Exception
85+
*/
86+
private function getTimezone(): Timezone
87+
{
88+
return new Timezone(
89+
$this->scopeResolver,
90+
$this->localeResolver,
91+
$this->createMock(DateTime::class),
92+
$this->scopeConfig,
93+
$this->scopeType,
94+
$this->defaultTimezonePath,
95+
new DateFormatterFactory()
96+
);
97+
}
98+
99+
/**
100+
* @return void
101+
* @throws Exception
102+
*/
103+
public function testIsScopeDateInInterval()
104+
{
105+
$scopeMock = $this->createMock(ScopeInterface::class);
106+
$this->scopeResolver->method('getScope')->willReturn($scopeMock);
107+
108+
$result = $this->getTimezone()->isScopeDateInInterval(
109+
null,
110+
'2025-04-01 00:00:00',
111+
'2999-05-01 00:00:00',
112+
);
113+
114+
$this->assertTrue($result);
115+
}
116+
117+
/**
118+
* @return void
119+
* @throws Exception
120+
*/
121+
public function testIsScopeDateInIntervalFalse()
122+
{
123+
$scopeMock = $this->createMock(ScopeInterface::class);
124+
$this->scopeResolver->method('getScope')->willReturn($scopeMock);
125+
126+
$result = $this->getTimezone()->isScopeDateInInterval(
127+
null,
128+
'2025-03-01 00:00:00',
129+
'2025-04-01 00:00:00',
130+
);
131+
132+
$this->assertFalse($result);
133+
}
134+
}

lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/TimezoneTest.php

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -426,41 +426,6 @@ public function testScopeDate($date, string $timezone, string $locale, string $e
426426
$this->assertEquals($timezone, $scopeDate->getTimezone()->getName());
427427
}
428428

429-
/**
430-
* @return void
431-
* @throws \PHPUnit\Framework\MockObject\Exception
432-
*/
433-
public function testIsScopeDateInInterval()
434-
{
435-
$scopeMock = $this->createMock(\Magento\Framework\App\ScopeInterface::class);
436-
$this->scopeResolver->method('getScope')->willReturn($scopeMock);
437-
438-
$result = $this->getTimezone()->isScopeDateInInterval(
439-
null,
440-
'2025-04-01 00:00:00',
441-
'2999-05-01 00:00:00',
442-
);
443-
444-
$this->assertTrue($result);
445-
}
446-
447-
/**
448-
* @return void
449-
* @throws \PHPUnit\Framework\MockObject\Exception
450-
*/
451-
public function testIsScopeDateInIntervalFalse()
452-
{
453-
$scopeMock = $this->createMock(\Magento\Framework\App\ScopeInterface::class);
454-
$this->scopeResolver->method('getScope')->willReturn($scopeMock);
455-
456-
$result = $this->getTimezone()->isScopeDateInInterval(
457-
null,
458-
'2025-03-01 00:00:00',
459-
'2025-04-01 00:00:00',
460-
);
461-
462-
$this->assertFalse($result);
463-
}
464429

465430
/**
466431
* @return array

0 commit comments

Comments
 (0)