Skip to content

Commit 519081f

Browse files
authored
Merge pull request #5332 from magento-tsg/2.3-develop-pr104
[TSG] Fixes for 2.3 (pr104) (2.3-develop)
2 parents be805ec + 2beb45b commit 519081f

File tree

32 files changed

+1437
-578
lines changed

32 files changed

+1437
-578
lines changed

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

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ public function getChartUrl($directUrl = true)
190190
$params = [
191191
'cht' => 'lc',
192192
'chls' => '7',
193-
'chf' => 'bg,s,f4f4f4|c,lg,90,ffffff,0.1,ededed,0',
194-
'chm' => 'B,f4d4b2,0,0,0',
193+
'chf' => 'bg,s,f4f4f4|c,lg,90,ffffff,0.1,ededed,0',
194+
'chm' => 'B,f4d4b2,0,0,0',
195195
'chco' => 'db4814',
196196
'chxs' => '0,0,11|1,0,11',
197197
'chma' => '15,15,15,15'
@@ -237,7 +237,7 @@ public function getChartUrl($directUrl = true)
237237
case '1y':
238238
case '2y':
239239
$d = $dateStart->format('Y-m');
240-
$dateStart->modify('+1 month');
240+
$dateStart->modify('first day of next month');
241241
break;
242242
default:
243243
$d = $dateStart->format('Y-m-d H:00');
@@ -300,20 +300,23 @@ public function getChartUrl($directUrl = true)
300300
$minvalue = min($localminvalue);
301301

302302
// default values
303-
$yLabels = [];
304303
$miny = 0;
305304
$maxy = 0;
306305
$yorigin = 0;
306+
$xAxis = 'x';
307+
$xAxisIndex = 0;
308+
$yAxisIndex = 1;
307309

308310
if ($minvalue >= 0 && $maxvalue >= 0) {
309311
if ($maxvalue > 10) {
310-
$p = pow(10, $this->_getPow((int) $maxvalue));
312+
$p = pow(10, $this->_getPow((int)$maxvalue));
311313
$maxy = ceil($maxvalue / $p) * $p;
312-
$yLabels = range($miny, $maxy, $p);
314+
$yRange = "$yAxisIndex,$miny,$maxy,$p";
313315
} else {
314316
$maxy = ceil($maxvalue + 1);
315-
$yLabels = range($miny, $maxy, 1);
317+
$yRange = "$yAxisIndex,$miny,$maxy,1";
316318
}
319+
$params['chxr'] = $yRange;
317320
$yorigin = 0;
318321
}
319322

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

342345
$params['chd'] .= $buffer;
343346

344-
$valueBuffer = [];
345-
346347
if (count($this->_axisLabels) > 0) {
347348
$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);
349+
$this->formatAxisLabelDate($xAxis, (string)$timezoneLocal);
350+
$customAxisLabels = $xAxisIndex . ":|" . implode('|', $this->_axisLabels[$xAxis]);
351+
$params['chxl'] = $customAxisLabels . $dataSetdelimiter;
360352
}
361353

362354
// chart size
@@ -368,7 +360,7 @@ public function getChartUrl($directUrl = true)
368360
foreach ($params as $name => $value) {
369361
$p[] = $name . '=' . urlencode($value);
370362
}
371-
return (string) self::API_URL . '?' . implode('&', $p);
363+
return (string)self::API_URL . '?' . implode('&', $p);
372364
}
373365
$gaData = urlencode(base64_encode(json_encode($params)));
374366
$gaHash = $this->_dashboardData->getChartDataHash($gaData);
@@ -392,7 +384,7 @@ private function formatAxisLabelDate($idx, $timezoneLocal)
392384
switch ($this->getDataHelper()->getParam('period')) {
393385
case '24h':
394386
$this->_axisLabels[$idx][$_index] = $this->_localeDate->formatDateTime(
395-
$period->setTime((int) $period->format('H'), 0, 0),
387+
$period->setTime((int)$period->format('H'), 0, 0),
396388
\IntlDateFormatter::NONE,
397389
\IntlDateFormatter::SHORT
398390
);

app/code/Magento/Catalog/Model/Layout/DepersonalizePlugin.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,55 @@
55
* Copyright © Magento, Inc. All rights reserved.
66
* See COPYING.txt for license details.
77
*/
8+
declare(strict_types=1);
9+
810
namespace Magento\Catalog\Model\Layout;
911

12+
use Magento\Catalog\Model\Session as CatalogSession;
13+
use Magento\Framework\View\LayoutInterface;
1014
use Magento\PageCache\Model\DepersonalizeChecker;
1115

1216
/**
13-
* Class DepersonalizePlugin
17+
* Depersonalize customer data.
18+
*
19+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1420
*/
1521
class DepersonalizePlugin
1622
{
1723
/**
1824
* @var DepersonalizeChecker
1925
*/
20-
protected $depersonalizeChecker;
26+
private $depersonalizeChecker;
2127

2228
/**
2329
* Catalog session
2430
*
25-
* @var \Magento\Catalog\Model\Session
31+
* @var CatalogSession
2632
*/
27-
protected $catalogSession;
33+
private $catalogSession;
2834

2935
/**
3036
* @param DepersonalizeChecker $depersonalizeChecker
31-
* @param \Magento\Catalog\Model\Session $catalogSession
37+
* @param CatalogSession $catalogSession
3238
*/
3339
public function __construct(
3440
DepersonalizeChecker $depersonalizeChecker,
35-
\Magento\Catalog\Model\Session $catalogSession
41+
CatalogSession $catalogSession
3642
) {
37-
$this->catalogSession = $catalogSession;
3843
$this->depersonalizeChecker = $depersonalizeChecker;
44+
$this->catalogSession = $catalogSession;
3945
}
4046

4147
/**
42-
* After generate Xml
48+
* Change sensitive customer data if the depersonalization is needed.
4349
*
44-
* @param \Magento\Framework\View\LayoutInterface $subject
45-
* @param \Magento\Framework\View\LayoutInterface $result
46-
* @return \Magento\Framework\View\LayoutInterface
50+
* @param LayoutInterface $subject
51+
* @return void
4752
*/
48-
public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
53+
public function afterGenerateElements(LayoutInterface $subject)
4954
{
5055
if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) {
5156
$this->catalogSession->clearStorage();
5257
}
53-
return $result;
5458
}
5559
}

app/code/Magento/Catalog/Test/Unit/Model/Layout/DepersonalizePluginTest.php

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

78
namespace Magento\Catalog\Test\Unit\Model\Layout;
89

9-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
use Magento\Catalog\Model\Layout\DepersonalizePlugin;
11+
use Magento\Catalog\Model\Session as CatalogSession;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
13+
use Magento\Framework\View\LayoutInterface;
14+
use Magento\PageCache\Model\DepersonalizeChecker;
15+
use PHPUnit\Framework\TestCase;
1016

11-
class DepersonalizePluginTest extends \PHPUnit\Framework\TestCase
17+
/**
18+
* Tests Magento\Catalog\Model\Layout\DepersonalizePlugin.
19+
*/
20+
class DepersonalizePluginTest extends TestCase
1221
{
1322
/**
14-
* @var \Magento\Catalog\Model\Layout\DepersonalizePlugin
23+
* @var DepersonalizePlugin
1524
*/
16-
protected $plugin;
25+
private $plugin;
1726

1827
/**
19-
* @var \Magento\Catalog\Model\Session|\PHPUnit_Framework_MockObject_MockObject
28+
* @var CatalogSession|\PHPUnit_Framework_MockObject_MockObject
2029
*/
21-
protected $catalogSessionMock;
30+
private $catalogSessionMock;
2231

2332
/**
24-
* @var \Magento\PageCache\Model\DepersonalizeChecker|\PHPUnit_Framework_MockObject_MockObject
33+
* @var DepersonalizeChecker|\PHPUnit_Framework_MockObject_MockObject
2534
*/
26-
protected $depersonalizeCheckerMock;
35+
private $depersonalizeCheckerMock;
2736

2837
/**
29-
* @var \Magento\Framework\View\Layout|\PHPUnit_Framework_MockObject_MockObject
38+
* @var LayoutInterface|\PHPUnit\Framework\MockObject\MockObject
3039
*/
31-
protected $resultLayout;
40+
private $layoutMock;
3241

42+
/**
43+
* @inheritdoc
44+
*/
3345
protected function setUp()
3446
{
35-
$this->layoutMock = $this->createMock(\Magento\Framework\View\Layout::class);
36-
$this->catalogSessionMock = $this->createPartialMock(\Magento\Catalog\Model\Session::class, ['clearStorage']);
37-
$this->resultLayout = $this->createMock(\Magento\Framework\View\Layout::class);
38-
$this->depersonalizeCheckerMock = $this->createMock(\Magento\PageCache\Model\DepersonalizeChecker::class);
39-
40-
$this->plugin = (new ObjectManager($this))->getObject(
41-
\Magento\Catalog\Model\Layout\DepersonalizePlugin::class,
42-
['catalogSession' => $this->catalogSessionMock, 'depersonalizeChecker' => $this->depersonalizeCheckerMock]
47+
$this->layoutMock = $this->getMockForAbstractClass(LayoutInterface::class);
48+
$this->catalogSessionMock = $this->createPartialMock(CatalogSession::class, ['clearStorage']);
49+
$this->depersonalizeCheckerMock = $this->createMock(DepersonalizeChecker::class);
50+
51+
$this->plugin = (new ObjectManagerHelper($this))->getObject(
52+
DepersonalizePlugin::class,
53+
[
54+
'catalogSession' => $this->catalogSessionMock,
55+
'depersonalizeChecker' => $this->depersonalizeCheckerMock,
56+
]
4357
);
4458
}
4559

46-
public function testAfterGenerateXml()
60+
/**
61+
* Tests afterGenerateElements method when depersonalization is needed.
62+
*
63+
* @return void
64+
*/
65+
public function testAfterGenerateElements(): void
4766
{
4867
$this->catalogSessionMock->expects($this->once())->method('clearStorage');
4968
$this->depersonalizeCheckerMock->expects($this->once())->method('checkIfDepersonalize')->willReturn(true);
50-
$actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $this->resultLayout);
51-
$this->assertEquals($this->resultLayout, $actualResult);
69+
$this->assertEmpty($this->plugin->afterGenerateElements($this->layoutMock));
5270
}
5371

54-
public function testAfterGenerateXmlNoDepersonalize()
72+
/**
73+
* Tests afterGenerateElements method when depersonalization is not needed.
74+
*
75+
* @return void
76+
*/
77+
public function testAfterGenerateElementsNoDepersonalize(): void
5578
{
5679
$this->catalogSessionMock->expects($this->never())->method('clearStorage');
5780
$this->depersonalizeCheckerMock->expects($this->once())->method('checkIfDepersonalize')->willReturn(false);
58-
$actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $this->resultLayout);
59-
$this->assertEquals($this->resultLayout, $actualResult);
81+
$this->assertEmpty($this->plugin->afterGenerateElements($this->layoutMock));
6082
}
6183
}

app/code/Magento/Checkout/Model/Layout/DepersonalizePlugin.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,54 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Checkout\Model\Layout;
79

10+
use Magento\Checkout\Model\Session as CheckoutSession;
11+
use Magento\Framework\View\LayoutInterface;
812
use Magento\PageCache\Model\DepersonalizeChecker;
913

1014
/**
11-
* Class DepersonalizePlugin
15+
* Depersonalize customer data.
16+
*
17+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1218
*/
1319
class DepersonalizePlugin
1420
{
1521
/**
1622
* @var DepersonalizeChecker
1723
*/
18-
protected $depersonalizeChecker;
24+
private $depersonalizeChecker;
1925

2026
/**
21-
* @var \Magento\Checkout\Model\Session
27+
* @var CheckoutSession
2228
*/
23-
protected $checkoutSession;
29+
private $checkoutSession;
2430

2531
/**
2632
* @param DepersonalizeChecker $depersonalizeChecker
27-
* @param \Magento\Checkout\Model\Session $checkoutSession
33+
* @param CheckoutSession $checkoutSession
2834
* @codeCoverageIgnore
2935
*/
3036
public function __construct(
3137
DepersonalizeChecker $depersonalizeChecker,
32-
\Magento\Checkout\Model\Session $checkoutSession
38+
CheckoutSession $checkoutSession
3339
) {
34-
$this->checkoutSession = $checkoutSession;
3540
$this->depersonalizeChecker = $depersonalizeChecker;
41+
$this->checkoutSession = $checkoutSession;
3642
}
3743

3844
/**
39-
* After generate Xml
45+
* Change sensitive customer data if the depersonalization is needed.
4046
*
41-
* @param \Magento\Framework\View\LayoutInterface $subject
42-
* @param \Magento\Framework\View\LayoutInterface $result
43-
* @return \Magento\Framework\View\LayoutInterface
47+
* @param LayoutInterface $subject
48+
* @return void
4449
*/
45-
public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
50+
public function afterGenerateElements(LayoutInterface $subject)
4651
{
4752
if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) {
4853
$this->checkoutSession->clearStorage();
4954
}
50-
return $result;
5155
}
5256
}

0 commit comments

Comments
 (0)