Please take a look at this Class and comment on the API
Posted: Wed Jun 01, 2005 3:19 pm
This is basically my testing harness page. I'm starting off to make an HTML parser, sorta like Tidy, but not really (it doesn't try to fix your errors, it just converts <> to <> when it knows something is wrong).
I haven't actually started implementing the class yet, but I've got this test harness which maps out the API of the expected new class. Can you guys comment on it (the API)? And yes, I'm thinking up of more tests to use on the class.
I haven't actually started implementing the class yet, but I've got this test harness which maps out the API of the expected new class. Can you guys comment on it (the API)? And yes, I'm thinking up of more tests to use on the class.
Code: Select all
<?php
require_once ( 'TWP_Parser_HTML.php' );
require_once ( 'PHPUnit.php' );
class TWP_Parser_HTML_Test extends PHPUnit_TestCase
{
var $object;
// constructor of the test suite
function ParagraphTest($name) {
$this->PHPUnit_TestCase($name);
}
function setUp() {
$this->object = new TWP_Parser_HTML;
$this->object->setOption('multiline',false);
$this->object->setOption('strip_invalid', 0);
}
function tearDown() {
unset($object);
}
function testSanitize() {
$input = '<html>';
$this->object->setRaw($var);
$output = $this->object->getClean();
$expected = '<html>';
$this->assertTrue($output === $expected, "\n\tInput: '$input'\n\tOutput: '$output'\n\tExpects: '$expected'\n\t>");
}
function testCloseTags() {
$input = '<b>This is bold text';
$this->object->setRaw($var);
$output = $this->object->getClean();
$expected = '<b>This is bold text</b>';
$this->assertTrue($output === $expected, "\n\tInput: '$input'\n\tOutput: '$output'\n\tExpects: '$expected'\n\t>");
}
function testNesting() {
$input = '</i></b><b><i></b></i><span></i>';
$this->object->setRaw($var);
$output = $this->object->getClean();
$expected = '<i><b><b><i></i></b><i><span><i></span>';
$this->assertTrue($output === $expected, "\n\tInput: '$input'\n\tOutput: '$output'\n\tExpects: '$expected'\n\t>");
}
function testInvalidAttribute() {
$input = '<a href="#" onClick="javascript:alert(\'foo!\');">Ohm</a>';
$this->object->setRaw($var);
$output = $this->object->getClean();
$expected = '<a href="#" onClick="javascript:alert(\'foo!\');">Ohm</a>';
$this->assertTrue($output === $expected, "Scripting onClick\n\tInput: '$input'\n\tOutput: '$output'\n\tExpects: '$expected'\n\t>");
$input = '<div style="position:fixed;">Foobar</div>';
$this->object->setRaw($var);
$output = $this->object->getClean();
$expected = '<div style="position:fixed;">Foobar</div>';
$this->assertTrue($output === $expected, "Layout Breaking position CSS\n\tInput: '$input'\n\tOutput: '$output'\n\tExpects: '$expected'\n\t>");
}
}
$suite = new PHPUnit_TestSuite("TWP_Parser_HTML_Test");
$result = PHPUnit::run($suite);
header('Content-type: text/plain');
echo $result -> toString();
?>