|
| 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\Framework\View\Test\Unit\Helper\SecureHtmlRenderer; |
| 9 | + |
| 10 | +use Magento\Framework\Escaper; |
| 11 | +use Magento\Framework\View\Helper\SecureHtmlRender\HtmlRenderer; |
| 12 | +use Magento\Framework\View\Helper\SecureHtmlRender\TagData; |
| 13 | +use PHPUnit\Framework\TestCase; |
| 14 | + |
| 15 | +class HtmlRendererTest extends TestCase |
| 16 | +{ |
| 17 | + /** |
| 18 | + * @return void |
| 19 | + */ |
| 20 | + protected function setUp(): void |
| 21 | + { |
| 22 | + $this->escaperMock = $this->createMock(Escaper::class); |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * @covers \Magento\Framework\View\Helper\SecureHtmlRender\HtmlRenderer::renderTag |
| 27 | + */ |
| 28 | + public function testRenderTag() |
| 29 | + { |
| 30 | + $helper = new HtmlRenderer($this->escaperMock); |
| 31 | + |
| 32 | + /** Test void element to have closing tag */ |
| 33 | + $tag = new TagData('hr', [], null, true); |
| 34 | + $this->assertEquals( |
| 35 | + "<hr/>", |
| 36 | + $helper->renderTag($tag) |
| 37 | + ); |
| 38 | + |
| 39 | + /** Test void element to never have content */ |
| 40 | + $tag = new TagData('hr', [], 'content', false); |
| 41 | + $this->assertEquals( |
| 42 | + "<hr/>", |
| 43 | + $helper->renderTag($tag) |
| 44 | + ); |
| 45 | + |
| 46 | + /** Test any non-void element to not have a closing tag and allow content */ |
| 47 | + $tags = new TagData('script', [], 'content', false); |
| 48 | + $this->assertEquals( |
| 49 | + "<script>content</script>", |
| 50 | + $helper->renderTag($tags) |
| 51 | + ); |
| 52 | + } |
| 53 | +} |
0 commit comments