-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e90743b
commit acbc43a
Showing
7 changed files
with
173 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\WysiwygModule\Service; | ||
|
||
use DOMNode; | ||
use OxidEsales\EshopCommunity\Internal\Framework\Templating\HtmlFilter\HtmlRemoverInterface; | ||
|
||
class HtmlTagRemover implements HtmlRemoverInterface | ||
{ | ||
public function remove(DOMNode $node): void | ||
{ | ||
$parent = $node->parentNode; | ||
while ($node->hasChildNodes()) { | ||
$parent->insertBefore($node->lastChild, $node->nextSibling); | ||
} | ||
$parent->removeChild($node); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\WysiwygModule\Tests\Unit\Service; | ||
|
||
use DOMDocument; | ||
use OxidEsales\WysiwygModule\Service\HtmlTagRemover; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class HtmlTagRemoverTest extends TestCase | ||
{ | ||
#[Test] | ||
#[DataProvider('htmlProvider')] | ||
public function remove(string $node, string $html, string $expectedHtml): void | ||
{ | ||
$doc = new DOMDocument(); | ||
$doc->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); | ||
$node = $doc->getElementsByTagName($node)->item(0); | ||
|
||
$remover = new HtmlTagRemover(); | ||
$remover->remove($node); | ||
|
||
$this->assertEquals($expectedHtml, rtrim($doc->saveHTML())); | ||
} | ||
|
||
public static function htmlProvider(): array | ||
{ | ||
return [ | ||
[ | ||
'node' => 'span', | ||
'html' => '<div><span>content</span></div>', | ||
'expectedHtml' => '<div>content</div>', | ||
], | ||
[ | ||
'node' => 'script', | ||
'html' => '<div><script>//content</script></div>', | ||
'expectedHtml' => '<div>//content</div>', | ||
], | ||
[ | ||
'node' => 'script', | ||
'html' => '<div><script src="app.js"/></div>', | ||
'expectedHtml' => '<div></div>', | ||
], | ||
]; | ||
} | ||
} |