Skip to content

Commit b8f2f60

Browse files
SarmisthaSarmistha
authored andcommitted
Merge remote-tracking branch 'adobe-commerce-tier-4/ACP2E-3058' into Tier4-Kings-PR-06-03-2024
2 parents 58d546a + 051987f commit b8f2f60

File tree

2 files changed

+93
-1
lines changed

2 files changed

+93
-1
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
/************************************************************************
3+
*
4+
* Copyright 2024 Adobe
5+
* All Rights Reserved.
6+
*
7+
* NOTICE: All information contained herein is, and remains
8+
* the property of Adobe and its suppliers, if any. The intellectual
9+
* and technical concepts contained herein are proprietary to Adobe
10+
* and its suppliers and are protected by all applicable intellectual
11+
* property laws, including trade secret and copyright laws.
12+
* Dissemination of this information or reproduction of this material
13+
* is strictly forbidden unless prior written permission is obtained
14+
* from Adobe.
15+
* ************************************************************************
16+
*/
17+
declare(strict_types=1);
18+
19+
namespace Magento\Framework\Test\Unit\View\Element;
20+
21+
use Magento\Framework\Filter\FilterManager;
22+
use Magento\Framework\View\Element\Template;
23+
use Magento\Framework\View\Element\Template\Context;
24+
use PHPUnit\Framework\MockObject\MockObject;
25+
use PHPUnit\Framework\TestCase;
26+
27+
class TemplateTest extends TestCase
28+
{
29+
/**
30+
* @var FilterManager|MockObject
31+
*/
32+
private $filterManagerMock;
33+
34+
/**
35+
* @var Context|MockObject
36+
*/
37+
private $contextMock;
38+
39+
/**
40+
* @var Template
41+
*/
42+
private $templateModel;
43+
44+
protected function setUp(): void
45+
{
46+
$this->contextMock = $this->getMockBuilder(Context::class)
47+
->disableOriginalConstructor()
48+
->getMock();
49+
50+
$this->filterManagerMock = $this->getMockBuilder(FilterManager::class)
51+
->disableOriginalConstructor()
52+
->addMethods(['stripTags'])
53+
->getMock();
54+
55+
$this->contextMock->expects($this->once())
56+
->method('getFilterManager')
57+
->willReturn($this->filterManagerMock);
58+
59+
$this->templateModel = new Template($this->contextMock);
60+
}
61+
62+
/**
63+
* Test to verify the stripped output from the HTML input.
64+
*
65+
* @param $input
66+
* @param $output
67+
* @dataProvider tagDataProvider
68+
*/
69+
public function testStripTags($input, $output): void
70+
{
71+
if ($input) {
72+
$this->filterManagerMock->expects($this->once())
73+
->method('stripTags')
74+
->with($input)
75+
->willReturn($output);
76+
}
77+
$this->assertEquals($this->templateModel->stripTags($input), $output);
78+
}
79+
80+
/**
81+
* @return array
82+
*/
83+
public function tagDataProvider(): array
84+
{
85+
return [
86+
['-1', '-1'],
87+
['0', '0'],
88+
['1', '1'],
89+
['Hello <b>world!</b>' , 'Hello world!']
90+
];
91+
}
92+
}

lib/internal/Magento/Framework/View/Element/AbstractBlock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ public function stripTags($data, $allowableTags = null, $allowHtmlEntities = fal
958958
{
959959
$params = ['allowableTags' => $allowableTags, 'escape' => $allowHtmlEntities];
960960

961-
return $data ? $this->filterManager->stripTags($data, $params) : '';
961+
return $data ? $this->filterManager->stripTags($data, $params) : $data;
962962
}
963963

964964
/**

0 commit comments

Comments
 (0)