Skip to content

Commit 3b5091f

Browse files
committed
Merge remote-tracking branch 'origin/AC-14829' into cia-2.4.9-alpha2-develop-bugfix-07022025
2 parents 873775b + 5826dec commit 3b5091f

File tree

4 files changed

+183
-118
lines changed

4 files changed

+183
-118
lines changed

app/code/Magento/Newsletter/Block/Adminhtml/Template/Preview.php

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2013 Adobe
4+
* All Rights Reserved.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Newsletter\Block\Adminhtml\Template;
79

10+
use Magento\Backend\Block\Template\Context;
11+
use Magento\Backend\Block\Widget;
12+
use Magento\Framework\App\ObjectManager;
13+
use Magento\Framework\Filter\Input\MaliciousCode;
14+
use Magento\Framework\Profiler;
15+
use Magento\Newsletter\Model\TemplateFactory;
16+
use Magento\Newsletter\Model\Template;
17+
use Magento\Newsletter\Model\SubscriberFactory;
18+
819
/**
920
* Newsletter template preview block
1021
*
1122
* @api
1223
* @since 100.0.2
1324
*/
14-
class Preview extends \Magento\Backend\Block\Widget
25+
class Preview extends Widget
1526
{
1627
/**
1728
* Name for profiler
@@ -21,30 +32,39 @@ class Preview extends \Magento\Backend\Block\Widget
2132
protected $profilerName = "newsletter_template_proccessing";
2233

2334
/**
24-
* @var \Magento\Newsletter\Model\TemplateFactory
35+
* @var TemplateFactory
2536
*/
2637
protected $_templateFactory;
2738

2839
/**
29-
* @var \Magento\Newsletter\Model\SubscriberFactory
40+
* @var SubscriberFactory
3041
*/
3142
protected $_subscriberFactory;
3243

3344
/**
34-
* @param \Magento\Backend\Block\Template\Context $context
35-
* @param \Magento\Newsletter\Model\TemplateFactory $templateFactory
36-
* @param \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory
45+
* @var MaliciousCode
46+
*/
47+
protected $maliciousCode;
48+
49+
/**
50+
* @param Context $context
51+
* @param TemplateFactory $templateFactory
52+
* @param SubscriberFactory $subscriberFactory
3753
* @param array $data
54+
* @param ?MaliciousCode $maliciousCode
3855
*/
3956
public function __construct(
40-
\Magento\Backend\Block\Template\Context $context,
41-
\Magento\Newsletter\Model\TemplateFactory $templateFactory,
42-
\Magento\Newsletter\Model\SubscriberFactory $subscriberFactory,
43-
array $data = []
57+
Context $context,
58+
TemplateFactory $templateFactory,
59+
SubscriberFactory $subscriberFactory,
60+
array $data = [],
61+
?MaliciousCode $maliciousCode = null
4462
) {
4563
$this->_templateFactory = $templateFactory;
4664
$this->_subscriberFactory = $subscriberFactory;
4765
parent::__construct($context, $data);
66+
$this->maliciousCode = $maliciousCode ?:
67+
ObjectManager::getInstance()->get(MaliciousCode::class);
4868
}
4969

5070
/**
@@ -61,13 +81,12 @@ protected function _toHtml()
6181
$this->loadTemplate($template, $id);
6282
} else {
6383
$previewData = $this->getPreviewData();
64-
6584
$template->setTemplateType($previewData['type']);
6685
$template->setTemplateText($previewData['text']);
6786
$template->setTemplateStyles($previewData['styles']);
6887
}
6988

70-
\Magento\Framework\Profiler::start($this->profilerName);
89+
Profiler::start($this->profilerName);
7190
$vars = [];
7291

7392
$vars['subscriber'] = $this->_subscriberFactory->create();
@@ -77,20 +96,19 @@ protected function _toHtml()
7796
$vars['subscriber_data']['unsubscription_link'] = $vars['subscriber'] ?
7897
$vars['subscriber']->getUnsubscriptionLink() :
7998
null;
80-
8199
$template->emulateDesign($this->getStoreId());
82100
$templateProcessed = $this->_appState->emulateAreaCode(
83-
\Magento\Newsletter\Model\Template::DEFAULT_DESIGN_AREA,
101+
Template::DEFAULT_DESIGN_AREA,
84102
[$template, 'getProcessedTemplate'],
85103
[$vars]
86104
);
87105
$template->revertDesign();
88-
106+
$templateProcessed = $this->maliciousCode->filter($templateProcessed);
89107
if ($template->isPlain()) {
90108
$templateProcessed = "<pre>" . $this->escapeHtml($templateProcessed) . "</pre>";
91109
}
92110

93-
\Magento\Framework\Profiler::stop($this->profilerName);
111+
Profiler::stop($this->profilerName);
94112

95113
return $templateProcessed;
96114
}
@@ -147,11 +165,11 @@ protected function getStoreId()
147165
/**
148166
* Return template
149167
*
150-
* @param \Magento\Newsletter\Model\Template $template
168+
* @param Template $template
151169
* @param string $id
152170
* @return $this
153171
*/
154-
protected function loadTemplate(\Magento\Newsletter\Model\Template $template, $id)
172+
protected function loadTemplate(Template $template, $id)
155173
{
156174
$template->load($id);
157175
return $this;

app/code/Magento/Newsletter/Test/Unit/Block/Adminhtml/Queue/PreviewTest.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -15,6 +15,7 @@
1515
use Magento\Framework\App\State;
1616
use Magento\Framework\Escaper;
1717
use Magento\Framework\Event\ManagerInterface;
18+
use Magento\Framework\Filter\Input\MaliciousCode;
1819
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1920
use Magento\Newsletter\Block\Adminhtml\Queue\Preview as QueuePreview;
2021
use Magento\Newsletter\Model\Queue;
@@ -69,6 +70,11 @@ class PreviewTest extends TestCase
6970
*/
7071
private $preview;
7172

73+
/**
74+
* @var MaliciousCode|MockObject
75+
*/
76+
protected $maliciousCode;
77+
7278
protected function setUp(): void
7379
{
7480
$context = $this->createMock(Context::class);
@@ -147,21 +153,23 @@ protected function setUp(): void
147153
$queueFactory->expects($this->any())
148154
->method('create')
149155
->willReturn($this->queueMock);
150-
156+
$this->maliciousCode = $this->createPartialMock(MaliciousCode::class, ['filter']);
151157
$this->objectManager = new ObjectManager($this);
152158

153159
$escaper = $this->objectManager->getObject(Escaper::class);
154160
$context->expects($this->once())
155161
->method('getEscaper')
156162
->willReturn($escaper);
157163

164+
$this->objectManager->prepareObjectManager();
158165
$this->preview = $this->objectManager->getObject(
159166
QueuePreview::class,
160167
[
161168
'context' => $context,
162169
'templateFactory' => $templateFactory,
163170
'subscriberFactory' => $subscriberFactory,
164171
'queueFactory' => $queueFactory,
172+
'maliciousCode' => $this->maliciousCode,
165173
]
166174
);
167175
}
@@ -173,6 +181,9 @@ public function testToHtmlEmpty()
173181
$this->storeManagerMock->expects($this->once())
174182
->method('getDefaultStoreView')
175183
->willReturn($store);
184+
$this->maliciousCode->expects($this->once())
185+
->method('filter')
186+
->willReturn('');
176187
$result = $this->preview->toHtml();
177188
$this->assertEquals('', $result);
178189
}
@@ -210,7 +221,10 @@ public function testToHtmlWithId()
210221
$this->storeManagerMock->expects($this->once())
211222
->method('getStores')
212223
->willReturn([0 => $store]);
224+
$this->maliciousCode->expects($this->once())
225+
->method('filter')
226+
->willReturn($newsletterText);
213227
$result = $this->preview->toHtml();
214-
$this->assertEquals('<pre></pre>', $result);
228+
$this->assertEquals('<pre>'. $newsletterText .'</pre>', $result);
215229
}
216230
}

0 commit comments

Comments
 (0)