|
| 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 | +} |
0 commit comments