Skip to content

Commit

Permalink
Merge pull request #9 from g-scalvini/improve-test
Browse files Browse the repository at this point in the history
Drop support PHP before 5.3.3 and improve tests
  • Loading branch information
bolknote authored Sep 28, 2023
2 parents b9e62d3 + 33f8e84 commit e62eb4d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"source": "https://github.com/pear/HTML_Safe"
},
"require": {
"php": ">=5.2",
"php": ">=5.3.3",
"pear/pear_exception": "*",
"pear/xml_htmlsax3": "*"
},
Expand Down
2 changes: 1 addition & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<dependencies>
<required>
<php>
<min>5.2</min>
<min>5.3.3</min>
</php>
<pearinstaller>
<min>1.6</min>
Expand Down
56 changes: 55 additions & 1 deletion tests/HTML_SafeTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?php

require_once 'PHPUnit/Framework/TestCase.php';
// Include PHPUnit using composer
if (is_readable('vendor/autoload.php')) {
require_once 'vendor/autoload.php';
} else {
require_once 'PHPUnit/Framework/TestCase.php';
}
require_once 'HTML/Safe.php';

use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -29,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 e62eb4d

Please sign in to comment.