Skip to content

Commit

Permalink
Add tests for missing closure tag, missing open tag, paragraph closur…
Browse files Browse the repository at this point in the history
…e, single tag and insecure tag
  • Loading branch information
g-scalvini committed Sep 28, 2023
1 parent 57c7c00 commit 33f8e84
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/HTML_SafeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,53 @@ public function testSpecialChars()
$this->assertSame($expectedOne, $safe->parse($inputOne));
$this->assertSame($expectedTwo, $safe->parse($inputTwo));
}

public function testMissingClosureTag()
{
$input = '<div><span>my text with missing tag closure</div>';
$expected = '<div><span>my text with missing tag closure</span></div>';

$safe = new HTML_Safe();
$this->assertSame($expected, $safe->parse($input));
}

public function testMissingOpenTag()
{
$input = '<div>my text with missing tag opening</span></div>';
$expected = '<div>my text with missing tag opening</div>';

$safe = new HTML_Safe();
$this->assertSame($expected, $safe->parse($input));
}

public function testParagraphClosure()
{
$input = '<div><h1>my first title</h1><p>my text<h1>my second title</h1></p></div>';
$expected = '<div><h1>my first title</h1><p>my text</p><h1>my second title</h1></div>';

$safe = new HTML_Safe();
$this->assertSame($expected, $safe->parse($input));
}

public function testSingleTags()
{
$inputOne = '<img src="not-exist.jpg" alt="Test image">';
$expectedOne = '<img src="not-exist.jpg" alt="Test image" />';

$inputTwo = '<img src="not-exist.jpg" alt="Test image">TEST</img>';
$expectedTwo = '<img src="not-exist.jpg" alt="Test image" />TEST';

$safe = new HTML_Safe();
$this->assertSame($expectedOne, $safe->parse($inputOne));
$this->assertSame($expectedTwo, $safe->parse($inputTwo));
}

public function testInsecureTags()
{
$input = '<div>Iframe content:<iframe title="Github iframe" width="300" height="200" src="https://github.com"></iframe></div>';
$expected = '<div>Iframe content:</div>';

$safe = new HTML_Safe();
$this->assertSame($expected, $safe->parse($input));
}
}

0 comments on commit 33f8e84

Please sign in to comment.