Skip to content

Commit 53fe8ee

Browse files
committed
Merge branch '2.4-develop' of https://github.com/magento/magento2 into escapekey-issue-onprompt-close
2 parents b1ab6a9 + a25c107 commit 53fe8ee

File tree

12 files changed

+448
-166
lines changed

12 files changed

+448
-166
lines changed

app/code/Magento/Backend/Block/Dashboard/Graph.php

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
*/
1515
class Graph extends \Magento\Backend\Block\Dashboard\AbstractDashboard
1616
{
17-
/**
18-
* Api URL
19-
*/
2017
const API_URL = 'https://image-charts.com/chart';
2118

2219
/**
@@ -190,8 +187,8 @@ public function getChartUrl($directUrl = true)
190187
$params = [
191188
'cht' => 'lc',
192189
'chls' => '7',
193-
'chf' => 'bg,s,f4f4f4|c,lg,90,ffffff,0.1,ededed,0',
194-
'chm' => 'B,f4d4b2,0,0,0',
190+
'chf' => 'bg,s,f4f4f4|c,lg,90,ffffff,0.1,ededed,0',
191+
'chm' => 'B,f4d4b2,0,0,0',
195192
'chco' => 'db4814',
196193
'chxs' => '0,0,11|1,0,11',
197194
'chma' => '15,15,15,15'
@@ -237,7 +234,7 @@ public function getChartUrl($directUrl = true)
237234
case '1y':
238235
case '2y':
239236
$d = $dateStart->format('Y-m');
240-
$dateStart->modify('+1 month');
237+
$dateStart->modify('first day of next month');
241238
break;
242239
default:
243240
$d = $dateStart->format('Y-m-d H:00');
@@ -300,20 +297,23 @@ public function getChartUrl($directUrl = true)
300297
$minvalue = min($localminvalue);
301298

302299
// default values
303-
$yLabels = [];
304300
$miny = 0;
305301
$maxy = 0;
306302
$yorigin = 0;
303+
$xAxis = 'x';
304+
$xAxisIndex = 0;
305+
$yAxisIndex = 1;
307306

308307
if ($minvalue >= 0 && $maxvalue >= 0) {
309308
if ($maxvalue > 10) {
310-
$p = pow(10, $this->_getPow((int) $maxvalue));
309+
$p = pow(10, $this->_getPow((int)$maxvalue));
311310
$maxy = ceil($maxvalue / $p) * $p;
312-
$yLabels = range($miny, $maxy, $p);
311+
$yRange = "$yAxisIndex,$miny,$maxy,$p";
313312
} else {
314313
$maxy = ceil($maxvalue + 1);
315-
$yLabels = range($miny, $maxy, 1);
314+
$yRange = "$yAxisIndex,$miny,$maxy,1";
316315
}
316+
$params['chxr'] = $yRange;
317317
$yorigin = 0;
318318
}
319319

@@ -341,22 +341,11 @@ public function getChartUrl($directUrl = true)
341341

342342
$params['chd'] .= $buffer;
343343

344-
$valueBuffer = [];
345-
346344
if (count($this->_axisLabels) > 0) {
347345
$params['chxt'] = implode(',', array_keys($this->_axisLabels));
348-
$indexid = 0;
349-
foreach ($this->_axisLabels as $idx => $labels) {
350-
if ($idx == 'x') {
351-
$this->formatAxisLabelDate((string) $idx, (string) $timezoneLocal);
352-
$tmpstring = implode('|', $this->_axisLabels[$idx]);
353-
$valueBuffer[] = $indexid . ":|" . $tmpstring;
354-
} elseif ($idx == 'y') {
355-
$valueBuffer[] = $indexid . ":|" . implode('|', $yLabels);
356-
}
357-
$indexid++;
358-
}
359-
$params['chxl'] = implode('|', $valueBuffer);
346+
$this->formatAxisLabelDate($xAxis, (string)$timezoneLocal);
347+
$customAxisLabels = $xAxisIndex . ":|" . implode('|', $this->_axisLabels[$xAxis]);
348+
$params['chxl'] = $customAxisLabels . $dataSetdelimiter;
360349
}
361350

362351
// chart size
@@ -368,7 +357,7 @@ public function getChartUrl($directUrl = true)
368357
foreach ($params as $name => $value) {
369358
$p[] = $name . '=' . urlencode($value);
370359
}
371-
return (string) self::API_URL . '?' . implode('&', $p);
360+
return (string)self::API_URL . '?' . implode('&', $p);
372361
}
373362
$gaData = urlencode(base64_encode(json_encode($params)));
374363
$gaHash = $this->_dashboardData->getChartDataHash($gaData);
@@ -392,7 +381,7 @@ private function formatAxisLabelDate($idx, $timezoneLocal)
392381
switch ($this->getDataHelper()->getParam('period')) {
393382
case '24h':
394383
$this->_axisLabels[$idx][$_index] = $this->_localeDate->formatDateTime(
395-
$period->setTime((int) $period->format('H'), 0, 0),
384+
$period->setTime((int)$period->format('H'), 0, 0),
396385
\IntlDateFormatter::NONE,
397386
\IntlDateFormatter::SHORT
398387
);

app/code/Magento/Customer/Model/CustomerRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public function removeByEmail($customerEmail, $websiteId = null)
195195
$websiteId = $this->storeManager->getStore()->getWebsiteId();
196196
}
197197
$emailKey = $this->getEmailKey($customerEmail, $websiteId);
198-
if ($emailKey) {
198+
if (isset($this->customerRegistryByEmail[$emailKey])) {
199199
/** @var Customer $customer */
200200
$customer = $this->customerRegistryByEmail[$emailKey];
201201
unset($this->customerRegistryByEmail[$emailKey]);

app/code/Magento/PageCache/Model/App/Response/HttpPlugin.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace Magento\PageCache\Model\App\Response;
88

9+
use Magento\Framework\App\PageCache\NotCacheableInterface;
10+
use Magento\Framework\App\Response\Http as HttpResponse;
11+
912
/**
1013
* HTTP response plugin for frontend.
1114
*/
@@ -14,14 +17,15 @@ class HttpPlugin
1417
/**
1518
* Set proper value of X-Magento-Vary cookie.
1619
*
17-
* @param \Magento\Framework\App\Response\Http $subject
20+
* @param HttpResponse $subject
1821
* @return void
1922
*/
20-
public function beforeSendResponse(\Magento\Framework\App\Response\Http $subject)
23+
public function beforeSendResponse(HttpResponse $subject)
2124
{
22-
if ($subject instanceof \Magento\Framework\App\PageCache\NotCacheableInterface) {
25+
if ($subject instanceof NotCacheableInterface || $subject->headersSent()) {
2326
return;
2427
}
28+
2529
$subject->sendVary();
2630
}
2731
}

app/code/Magento/PageCache/Test/Unit/Model/App/Response/HttpPluginTest.php

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,63 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\PageCache\Test\Unit\Model\App\Response;
89

10+
use Magento\Framework\App\Response\Http as HttpResponse;
11+
use Magento\MediaStorage\Model\File\Storage\Response as FileResponse;
912
use Magento\PageCache\Model\App\Response\HttpPlugin;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
1015

11-
class HttpPluginTest extends \PHPUnit\Framework\TestCase
16+
/**
17+
* Tests \Magento\PageCache\Model\App\Response\HttpPlugin.
18+
*/
19+
class HttpPluginTest extends TestCase
1220
{
1321
/**
14-
* @param \Magento\Framework\App\Response\FileInterface $responseInstanceClass
22+
* @var HttpPlugin
23+
*/
24+
private $httpPlugin;
25+
26+
/**
27+
* @inheritdoc
28+
*/
29+
protected function setUp()
30+
{
31+
parent::setUp();
32+
$this->httpPlugin = new HttpPlugin();
33+
}
34+
35+
/**
36+
* @param string $responseClass
37+
* @param bool $headersSent
1538
* @param int $sendVaryCalled
39+
* @return void
1640
*
1741
* @dataProvider beforeSendResponseDataProvider
1842
*/
19-
public function testBeforeSendResponse($responseInstanceClass, $sendVaryCalled)
43+
public function testBeforeSendResponse(string $responseClass, bool $headersSent, int $sendVaryCalled): void
2044
{
21-
/** @var \Magento\Framework\App\Response\Http | \PHPUnit_Framework_MockObject_MockObject $responseMock */
22-
$responseMock = $this->createMock($responseInstanceClass);
23-
$responseMock->expects($this->exactly($sendVaryCalled))
24-
->method('sendVary');
25-
$plugin = new HttpPlugin();
26-
$plugin->beforeSendResponse($responseMock);
45+
/** @var HttpResponse|MockObject $responseMock */
46+
$responseMock = $this->createMock($responseClass);
47+
$responseMock->expects($this->any())->method('headersSent')->willReturn($headersSent);
48+
$responseMock->expects($this->exactly($sendVaryCalled))->method('sendVary');
49+
50+
$this->httpPlugin->beforeSendResponse($responseMock);
2751
}
2852

2953
/**
3054
* @return array
3155
*/
32-
public function beforeSendResponseDataProvider()
56+
public function beforeSendResponseDataProvider(): array
3357
{
3458
return [
35-
[\Magento\Framework\App\Response\Http::class, 1],
36-
[\Magento\MediaStorage\Model\File\Storage\Response::class, 0]
59+
'http_response_headers_not_sent' => [HttpResponse::class, false, 1],
60+
'http_response_headers_sent' => [HttpResponse::class, true, 0],
61+
'file_response_headers_not_sent' => [FileResponse::class, false, 0],
62+
'file_response_headers_sent' => [FileResponse::class, true, 0],
3763
];
3864
}
3965
}

app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ public function getDateRange($range, $customStart, $customEnd, $returnObjects =
461461
$startMonth = isset($startMonthDay[0]) ? (int)$startMonthDay[0] : 1;
462462
$startDay = isset($startMonthDay[1]) ? (int)$startMonthDay[1] : 1;
463463
$dateStart->setDate($dateStart->format('Y'), $startMonth, $startDay);
464+
$dateStart->modify('-1 year');
464465
if ($range == '2y') {
465466
$dateStart->modify('-1 year');
466467
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Backend\Block\Dashboard\Tab;
9+
10+
use Magento\Backend\Block\Dashboard\Graph;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\Framework\View\LayoutInterface;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Test for \Magento\Backend\Block\Dashboard\Tab\Orders class.
18+
*
19+
* @magentoAppArea adminhtml
20+
*/
21+
class OrdersTest extends TestCase
22+
{
23+
/**
24+
* @var ObjectManagerInterface
25+
*/
26+
private $objectManager;
27+
28+
/**
29+
* @var LayoutInterface
30+
*/
31+
private $layout;
32+
33+
/**
34+
* @var Graph
35+
*/
36+
private $graphBlock;
37+
38+
/**
39+
* @inheritdoc
40+
*/
41+
protected function setUp()
42+
{
43+
$this->objectManager = Bootstrap::getObjectManager();
44+
$this->layout = $this->objectManager->get(LayoutInterface::class);
45+
$this->graphBlock = $this->layout->createBlock(Graph::class);
46+
}
47+
48+
/**
49+
* @magentoDataFixture Magento/Sales/_files/order_list_with_invoice.php
50+
* @dataProvider chartUrlDataProvider
51+
* @param string $period
52+
* @param string $expectedAxisRange
53+
* @return void
54+
*/
55+
public function testGetChartUrl(string $period, string $expectedAxisRange): void
56+
{
57+
$this->graphBlock->getRequest()->setParams(['period' => $period]);
58+
$ordersBlock = $this->layout->createBlock(Orders::class);
59+
$decodedChartUrl = urldecode($ordersBlock->getChartUrl());
60+
$this->assertEquals($expectedAxisRange, $this->getUrlParamData($decodedChartUrl, 'chxr'));
61+
}
62+
63+
/**
64+
* @return array
65+
*/
66+
public function chartUrlDataProvider(): array
67+
{
68+
return [
69+
'Last 24 Hours' => ['24h', '1,0,2,1'],
70+
'Last 7 Days' => ['7d', '1,0,3,1'],
71+
'Current Month' => ['1m', '1,0,3,1'],
72+
'YTD' => ['1y', '1,0,4,1'],
73+
'2YTD' => ['2y', '1,0,4,1'],
74+
];
75+
}
76+
77+
/**
78+
* @param string $chartUrl
79+
* @param string $paramName
80+
* @return string
81+
*/
82+
private function getUrlParamData(string $chartUrl, string $paramName): string
83+
{
84+
$chartUrlSegments = explode('&', $chartUrl);
85+
foreach ($chartUrlSegments as $chartUrlSegment) {
86+
[$paramKey, $paramValue] = explode('=', $chartUrlSegment);
87+
if ($paramKey === $paramName) {
88+
return $paramValue;
89+
}
90+
}
91+
92+
return '';
93+
}
94+
}

0 commit comments

Comments
 (0)