Skip to content

Commit 98cf302

Browse files
Merge pull request #3981 from magento-tsg/2.3-qwerty-pr46
[TSG] Upporting for 2.3 (pr46) (2.3-qwerty)
2 parents 528f3d3 + 311666c commit 98cf302

File tree

9 files changed

+105
-40
lines changed

9 files changed

+105
-40
lines changed

app/code/Magento/Cms/Test/Unit/Ui/Component/Listing/Column/BlockActionsTest.php

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1515

1616
/**
17-
* BlockActionsTest contains unit tests for \Magento\Cms\Ui\Component\Listing\Column\BlockActions class
17+
* BlockActionsTest contains unit tests for \Magento\Cms\Ui\Component\Listing\Column\BlockActions class.
1818
*/
1919
class BlockActionsTest extends \PHPUnit\Framework\TestCase
2020
{
@@ -33,6 +33,9 @@ class BlockActionsTest extends \PHPUnit\Framework\TestCase
3333
*/
3434
private $urlBuilder;
3535

36+
/**
37+
* @inheritdoc
38+
*/
3639
protected function setUp()
3740
{
3841
$objectManager = new ObjectManager($this);
@@ -42,15 +45,15 @@ protected function setUp()
4245
$processor = $this->getMockBuilder(Processor::class)
4346
->disableOriginalConstructor()
4447
->getMock();
45-
$context->expects(static::never())
48+
$context->expects($this->never())
4649
->method('getProcessor')
4750
->willReturn($processor);
4851

4952
$this->urlBuilder = $this->createMock(UrlInterface::class);
5053

5154
$this->escaper = $this->getMockBuilder(Escaper::class)
5255
->disableOriginalConstructor()
53-
->setMethods(['escapeHtml'])
56+
->setMethods(['escapeHtmlAttr'])
5457
->getMock();
5558

5659
$this->blockActions = $objectManager->getObject(BlockActions::class, [
@@ -62,7 +65,10 @@ protected function setUp()
6265
}
6366

6467
/**
68+
* Unit test for prepareDataSource method.
69+
*
6570
* @covers \Magento\Cms\Ui\Component\Listing\Column\BlockActions::prepareDataSource
71+
* @return void
6672
*/
6773
public function testPrepareDataSource()
6874
{
@@ -73,10 +79,10 @@ public function testPrepareDataSource()
7379
'items' => [
7480
[
7581
'block_id' => $blockId,
76-
'title' => $title
77-
]
78-
]
79-
]
82+
'title' => $title,
83+
],
84+
],
85+
],
8086
];
8187
$name = 'item_name';
8288
$expectedItems = [
@@ -93,34 +99,34 @@ public function testPrepareDataSource()
9399
'label' => __('Delete'),
94100
'confirm' => [
95101
'title' => __('Delete %1', $title),
96-
'message' => __('Are you sure you want to delete a %1 record?', $title)
102+
'message' => __('Are you sure you want to delete a %1 record?', $title),
97103
],
98-
'post' => true
99-
]
104+
'post' => true,
105+
],
100106
],
101-
]
107+
],
102108
];
103109

104-
$this->escaper->expects(static::once())
105-
->method('escapeHtml')
110+
$this->escaper->expects($this->once())
111+
->method('escapeHtmlAttr')
106112
->with($title)
107113
->willReturn($title);
108114

109-
$this->urlBuilder->expects(static::exactly(2))
115+
$this->urlBuilder->expects($this->exactly(2))
110116
->method('getUrl')
111117
->willReturnMap(
112118
[
113119
[
114120
BlockActions::URL_PATH_EDIT,
115121
[
116-
'block_id' => $blockId
122+
'block_id' => $blockId,
117123
],
118124
'test/url/edit',
119125
],
120126
[
121127
BlockActions::URL_PATH_DELETE,
122128
[
123-
'block_id' => $blockId
129+
'block_id' => $blockId,
124130
],
125131
'test/url/delete',
126132
],
@@ -130,6 +136,6 @@ public function testPrepareDataSource()
130136
$this->blockActions->setData('name', $name);
131137

132138
$actual = $this->blockActions->prepareDataSource($items);
133-
static::assertEquals($expectedItems, $actual['data']['items']);
139+
$this->assertEquals($expectedItems, $actual['data']['items']);
134140
}
135141
}

app/code/Magento/Cms/Test/Unit/Ui/Component/Listing/Column/PageActionsTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use Magento\Cms\Ui\Component\Listing\Column\PageActions;
99
use Magento\Framework\Escaper;
1010

11+
/**
12+
* Test for Magento\Cms\Ui\Component\Listing\Column\PageActions class.
13+
*/
1114
class PageActionsTest extends \PHPUnit\Framework\TestCase
1215
{
1316
public function testPrepareItemsByPageId()
@@ -68,12 +71,13 @@ public function testPrepareItemsByPageId()
6871
'label' => __('Delete'),
6972
'confirm' => [
7073
'title' => __('Delete %1', $title),
71-
'message' => __('Are you sure you want to delete a %1 record?', $title)
74+
'message' => __('Are you sure you want to delete a %1 record?', $title),
75+
'__disableTmpl' => true,
7276
],
73-
'post' => true
74-
]
77+
'post' => true,
78+
],
7579
],
76-
]
80+
],
7781
];
7882

7983
$escaper->expects(static::once())

app/code/Magento/Cms/Ui/Component/Listing/Column/BlockActions.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Magento\Framework\Escaper;
1414

1515
/**
16-
* Class BlockActions
16+
* Class to build edit and delete link for each item.
1717
*/
1818
class BlockActions extends Column
1919
{
@@ -35,8 +35,6 @@ class BlockActions extends Column
3535
private $escaper;
3636

3737
/**
38-
* Constructor
39-
*
4038
* @param ContextInterface $context
4139
* @param UiComponentFactory $uiComponentFactory
4240
* @param UrlInterface $urlBuilder
@@ -62,31 +60,31 @@ public function prepareDataSource(array $dataSource)
6260
if (isset($dataSource['data']['items'])) {
6361
foreach ($dataSource['data']['items'] as & $item) {
6462
if (isset($item['block_id'])) {
65-
$title = $this->getEscaper()->escapeHtml($item['title']);
63+
$title = $this->getEscaper()->escapeHtmlAttr($item['title']);
6664
$item[$this->getData('name')] = [
6765
'edit' => [
6866
'href' => $this->urlBuilder->getUrl(
6967
static::URL_PATH_EDIT,
7068
[
71-
'block_id' => $item['block_id']
69+
'block_id' => $item['block_id'],
7270
]
7371
),
74-
'label' => __('Edit')
72+
'label' => __('Edit'),
7573
],
7674
'delete' => [
7775
'href' => $this->urlBuilder->getUrl(
7876
static::URL_PATH_DELETE,
7977
[
80-
'block_id' => $item['block_id']
78+
'block_id' => $item['block_id'],
8179
]
8280
),
8381
'label' => __('Delete'),
8482
'confirm' => [
8583
'title' => __('Delete %1', $title),
86-
'message' => __('Are you sure you want to delete a %1 record?', $title)
84+
'message' => __('Are you sure you want to delete a %1 record?', $title),
8785
],
88-
'post' => true
89-
]
86+
'post' => true,
87+
],
9088
];
9189
}
9290
}

app/code/Magento/Cms/Ui/Component/Listing/Column/PageActions.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ public function prepareDataSource(array $dataSource)
8585
'label' => __('Delete'),
8686
'confirm' => [
8787
'title' => __('Delete %1', $title),
88-
'message' => __('Are you sure you want to delete a %1 record?', $title)
88+
'message' => __('Are you sure you want to delete a %1 record?', $title),
89+
'__disableTmpl' => true,
8990
],
90-
'post' => true
91+
'post' => true,
9192
];
9293
}
9394
if (isset($item['identifier'])) {

app/code/Magento/Sales/Controller/Guest/View.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
use Magento\Sales\Helper\Guest as GuestHelper;
1010
use Magento\Framework\View\Result\PageFactory;
1111
use Magento\Framework\Controller\ResultInterface;
12+
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
1213

13-
class View extends Action\Action
14+
/**
15+
* Guest order view action.
16+
*/
17+
class View extends Action\Action implements HttpPostActionInterface
1418
{
1519
/**
1620
* @var \Magento\Sales\Helper\Guest
@@ -38,7 +42,7 @@ public function __construct(
3842
}
3943

4044
/**
41-
* @return \Magento\Framework\Controller\ResultInterface
45+
* @inheritdoc
4246
*/
4347
public function execute()
4448
{

dev/tests/integration/testsuite/Magento/Sales/Controller/Guest/FormTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function testViewOrderAsGuest()
4040
public function testViewOrderAsLoggedIn()
4141
{
4242
$this->login(1);
43+
$this->getRequest()->setMethod(Request::METHOD_POST);
4344
$this->dispatch('sales/guest/view/');
4445
$this->assertRedirect($this->stringContains('sales/order/history/'));
4546
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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\Sales\Controller\Guest;
9+
10+
use Magento\TestFramework\Request;
11+
use Magento\TestFramework\TestCase\AbstractController;
12+
13+
/**
14+
* Test for \Magento\Sales\Controller\Guest\View class.
15+
*/
16+
class ViewTest extends AbstractController
17+
{
18+
/**
19+
* Check that controller applied only POST requests.
20+
*/
21+
public function testExecuteWithNonPostRequest()
22+
{
23+
$this->getRequest()->setMethod(Request::METHOD_GET);
24+
$this->dispatch('sales/guest/view/');
25+
26+
$this->assert404NotFound();
27+
}
28+
}

lib/internal/Magento/Framework/Escaper.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function escapeHtml($data, $allowedTags = null)
6767
foreach ($data as $item) {
6868
$result[] = $this->escapeHtml($item, $allowedTags);
6969
}
70-
} elseif (strlen($data)) {
70+
} elseif (!empty($data)) {
7171
if (is_array($allowedTags) && !empty($allowedTags)) {
7272
$allowedTags = $this->filterProhibitedTags($allowedTags);
7373
$wrapperElementId = uniqid();
@@ -328,7 +328,8 @@ public function escapeXssInUrl($data)
328328
*/
329329
private function escapeScriptIdentifiers(string $data): string
330330
{
331-
$filteredData = preg_replace(self::$xssFiltrationPattern, ':', $data) ?: '';
331+
$filteredData = preg_replace('/[\x00-\x1F\x7F\xA0]/u', '', $data) ?: '';
332+
$filteredData = preg_replace(self::$xssFiltrationPattern, ':', $filteredData) ?: '';
332333
if (preg_match(self::$xssFiltrationPattern, $filteredData)) {
333334
$filteredData = $this->escapeScriptIdentifiers($filteredData);
334335
}

lib/internal/Magento/Framework/Test/Unit/EscaperTest.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ protected function setUp()
4343
*
4444
* @param int $codepoint Unicode codepoint in hex notation
4545
* @return string UTF-8 literal string
46+
* @throws \Exception
4647
*/
4748
protected function codepointToUtf8($codepoint)
4849
{
@@ -265,15 +266,36 @@ public function escapeHtmlInvalidDataProvider()
265266

266267
/**
267268
* @covers \Magento\Framework\Escaper::escapeUrl
269+
*
270+
* @param string $data
271+
* @param string $expected
272+
* @return void
273+
*
274+
* @dataProvider escapeUrlDataProvider
268275
*/
269-
public function testEscapeUrl()
276+
public function testEscapeUrl(string $data, string $expected): void
270277
{
271-
$data = 'http://example.com/search?term=this+%26+that&view=list';
272-
$expected = 'http://example.com/search?term=this+%26+that&amp;view=list';
273278
$this->assertEquals($expected, $this->escaper->escapeUrl($data));
274279
$this->assertEquals($expected, $this->escaper->escapeUrl($expected));
275280
}
276281

282+
/**
283+
* @return array
284+
*/
285+
public function escapeUrlDataProvider(): array
286+
{
287+
return [
288+
[
289+
'data' => "http://example.com/search?term=this+%26+that&view=list",
290+
'expected' => "http://example.com/search?term=this+%26+that&amp;view=list",
291+
],
292+
[
293+
'data' => "http://exam\r\nple.com/search?term=this+%26+that&view=list",
294+
'expected' => "http://example.com/search?term=this+%26+that&amp;view=list",
295+
],
296+
];
297+
}
298+
277299
/**
278300
* @covers \Magento\Framework\Escaper::escapeJsQuote
279301
*/

0 commit comments

Comments
 (0)