Skip to content

Commit 24e9f6b

Browse files
committed
Merge branch 'ACP2E-1659' of https://github.com/magento-l3/magento2ce into PR-L3-03132023
2 parents bbe7615 + e3328f7 commit 24e9f6b

File tree

4 files changed

+86
-17
lines changed

4 files changed

+86
-17
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Date.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,25 +109,16 @@ public function getHtml()
109109
' value="' .
110110
$this->localeResolver->getLocale() .
111111
'"/>';
112-
$scriptString = '
113-
require(["jquery", "mage/calendar"], function($){
114-
$("#' .
115-
$htmlId .
116-
'_range").dateRange({
117-
dateFormat: "' .
118-
$format .
119-
'",
120-
buttonText: "' . $this->escapeHtml(__('Date selector')) .
121-
'",
112+
$scriptString = 'require(["jquery", "mage/calendar"], function($){
113+
$("#' . $htmlId . '_range").dateRange({
114+
dateFormat: "' . $format . '",
115+
buttonText: "' . $this->escapeHtml(__('Date selector')) . '",
116+
buttonImage: "' . $this->getViewFileUrl('Magento_Theme::calendar.png') . '",
122117
from: {
123-
id: "' .
124-
$htmlId .
125-
'_from"
118+
id: "' . $htmlId . '_from"
126119
},
127120
to: {
128-
id: "' .
129-
$htmlId .
130-
'_to"
121+
id: "' . $htmlId . '_to"
131122
}
132123
})
133124
});';

app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Datetime.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Datetime extends \Magento\Backend\Block\Widget\Grid\Column\Filter\Date
1717
/**
1818
* full day is 86400, we need 23 hours:59 minutes:59 seconds = 86399
1919
*/
20-
const END_OF_DAY_IN_SECONDS = 86399;
20+
public const END_OF_DAY_IN_SECONDS = 86399;
2121

2222
/**
2323
* @inheritdoc
@@ -123,6 +123,7 @@ public function getHtml()
123123
timeFormat: "' . $timeFormat . '",
124124
showsTime: ' . ($this->getColumn()->getFilterTime() ? 'true' : 'false') . ',
125125
buttonText: "' . $this->escapeHtml(__('Date selector')) . '",
126+
buttonImage: "' . $this->getViewFileUrl('Magento_Theme::calendar.png') . '",
126127
from: {
127128
id: "' . $htmlId . '_from"
128129
},

app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/Column/Filter/DateTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,21 @@
1010
use Magento\Backend\Block\Context;
1111
use Magento\Backend\Block\Widget\Grid\Column;
1212
use Magento\Backend\Block\Widget\Grid\Column\Filter\Date;
13+
use Magento\Framework\App\Request\Http;
1314
use Magento\Framework\Escaper;
1415
use Magento\Framework\Locale\ResolverInterface;
1516
use Magento\Framework\Math\Random;
1617
use Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface;
1718
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1819
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
20+
use Magento\Framework\View\Asset\Repository;
1921
use PHPUnit\Framework\MockObject\MockObject;
2022
use PHPUnit\Framework\TestCase;
2123

2224
/**
2325
* Class DateTest to test Magento\Backend\Block\Widget\Grid\Column\Filter\Date
2426
*
27+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2528
*/
2629
class DateTest extends TestCase
2730
{
@@ -49,6 +52,16 @@ class DateTest extends TestCase
4952
/** @var Context|MockObject */
5053
private $contextMock;
5154

55+
/**
56+
* @var Http|MockObject
57+
*/
58+
private $request;
59+
60+
/**
61+
* @var Repository|MockObject
62+
*/
63+
private $repositoryMock;
64+
5265
protected function setUp(): void
5366
{
5467
$this->mathRandomMock = $this->getMockBuilder(Random::class)
@@ -88,6 +101,23 @@ protected function setUp(): void
88101
$this->contextMock->expects($this->once())->method('getEscaper')->willReturn($this->escaperMock);
89102
$this->contextMock->expects($this->once())->method('getLocaleDate')->willReturn($this->localeDateMock);
90103

104+
$this->request = $this->getMockBuilder(Http::class)
105+
->disableOriginalConstructor()
106+
->getMock();
107+
108+
$this->contextMock->expects($this->once())
109+
->method('getRequest')
110+
->willReturn($this->request);
111+
112+
$this->repositoryMock = $this->getMockBuilder(Repository::class)
113+
->disableOriginalConstructor()
114+
->setMethods(['getUrlWithParams'])
115+
->getMock();
116+
117+
$this->contextMock->expects($this->once())
118+
->method('getAssetRepository')
119+
->willReturn($this->repositoryMock);
120+
91121
$objectManagerHelper = new ObjectManager($this);
92122
$this->model = $objectManagerHelper->getObject(
93123
Date::class,
@@ -116,6 +146,14 @@ public function testGetHtmlSuccessfulTimestamp()
116146
'from' => $yesterday->getTimestamp(),
117147
'to' => $tomorrow->getTimestamp()
118148
];
149+
$params = ['_secure' => false];
150+
$fileId = 'Magento_Theme::calendar.png';
151+
$fileUrl = 'file url';
152+
153+
$this->repositoryMock->expects($this->once())
154+
->method('getUrlWithParams')
155+
->with($fileId, $params)
156+
->willReturn($fileUrl);
119157

120158
$this->mathRandomMock->expects($this->any())->method('getUniqueHash')->willReturn($uniqueHash);
121159
$this->columnMock->expects($this->once())->method('getHtmlId')->willReturn($id);

app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/Column/Filter/DatetimeTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,21 @@
1010
use Magento\Backend\Block\Context;
1111
use Magento\Backend\Block\Widget\Grid\Column;
1212
use Magento\Backend\Block\Widget\Grid\Column\Filter\Datetime;
13+
use Magento\Framework\App\Request\Http;
1314
use Magento\Framework\Escaper;
1415
use Magento\Framework\Locale\ResolverInterface;
1516
use Magento\Framework\Math\Random;
1617
use Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface;
1718
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1819
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
20+
use Magento\Framework\View\Asset\Repository;
1921
use PHPUnit\Framework\MockObject\MockObject;
2022
use PHPUnit\Framework\TestCase;
2123

2224
/**
2325
* Class DateTimeTest to test Magento\Backend\Block\Widget\Grid\Column\Filter\Date
26+
*
27+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2428
*/
2529
class DatetimeTest extends TestCase
2630
{
@@ -48,6 +52,16 @@ class DatetimeTest extends TestCase
4852
/** @var Context|MockObject */
4953
private $contextMock;
5054

55+
/**
56+
* @var Http|MockObject
57+
*/
58+
private $request;
59+
60+
/**
61+
* @var Repository|MockObject
62+
*/
63+
private $repositoryMock;
64+
5165
protected function setUp(): void
5266
{
5367
$this->mathRandomMock = $this->getMockBuilder(Random::class)
@@ -87,6 +101,23 @@ protected function setUp(): void
87101
$this->contextMock->expects($this->once())->method('getEscaper')->willReturn($this->escaperMock);
88102
$this->contextMock->expects($this->once())->method('getLocaleDate')->willReturn($this->localeDateMock);
89103

104+
$this->request = $this->getMockBuilder(Http::class)
105+
->disableOriginalConstructor()
106+
->getMock();
107+
108+
$this->contextMock->expects($this->once())
109+
->method('getRequest')
110+
->willReturn($this->request);
111+
112+
$this->repositoryMock = $this->getMockBuilder(Repository::class)
113+
->disableOriginalConstructor()
114+
->setMethods(['getUrlWithParams'])
115+
->getMock();
116+
117+
$this->contextMock->expects($this->once())
118+
->method('getAssetRepository')
119+
->willReturn($this->repositoryMock);
120+
90121
$objectManagerHelper = new ObjectManager($this);
91122
$this->model = $objectManagerHelper->getObject(
92123
Datetime::class,
@@ -115,6 +146,14 @@ public function testGetHtmlSuccessfulTimestamp()
115146
'from' => $yesterday->getTimestamp(),
116147
'to' => $tomorrow->getTimestamp()
117148
];
149+
$params = ['_secure' => false];
150+
$fileId = 'Magento_Theme::calendar.png';
151+
$fileUrl = 'file url';
152+
153+
$this->repositoryMock->expects($this->once())
154+
->method('getUrlWithParams')
155+
->with($fileId, $params)
156+
->willReturn($fileUrl);
118157

119158
$this->mathRandomMock->expects($this->any())->method('getUniqueHash')->willReturn($uniqueHash);
120159
$this->columnMock->expects($this->once())->method('getHtmlId')->willReturn($id);

0 commit comments

Comments
 (0)