2006-04-16 03:00:05 +00:00
|
|
|
<?php
|
|
|
|
|
2006-04-16 03:39:39 +00:00
|
|
|
class Test_PureHTMLDefinition extends UnitTestCase
|
2006-04-16 03:00:05 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
var $def;
|
|
|
|
|
2006-04-16 03:39:39 +00:00
|
|
|
function Test_PureHTMLDefinition() {
|
2006-04-16 03:00:05 +00:00
|
|
|
$this->UnitTestCase();
|
|
|
|
$this->def = new PureHTMLDefinition();
|
|
|
|
$this->def->loadData();
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_removeForeignElements() {
|
|
|
|
|
|
|
|
$inputs = array();
|
|
|
|
$expect = array();
|
|
|
|
|
|
|
|
$inputs[0] = array();
|
|
|
|
$expect[0] = $inputs[0];
|
|
|
|
|
|
|
|
$inputs[1] = array(
|
|
|
|
new MF_Text('This is ')
|
|
|
|
,new MF_StartTag('b', array())
|
|
|
|
,new MF_Text('bold')
|
|
|
|
,new MF_EndTag('b')
|
|
|
|
,new MF_Text(' text')
|
|
|
|
);
|
|
|
|
$expect[1] = $inputs[1];
|
|
|
|
|
2006-04-16 03:33:37 +00:00
|
|
|
$inputs[2] = array(
|
|
|
|
new MF_StartTag('asdf')
|
|
|
|
,new MF_EndTag('asdf')
|
|
|
|
,new MF_StartTag('d', array('href' => 'bang!'))
|
|
|
|
,new MF_EndTag('d')
|
|
|
|
,new MF_StartTag('pooloka')
|
|
|
|
,new MF_StartTag('poolasdf')
|
|
|
|
,new MF_StartTag('ds', array('moogle' => '&'))
|
|
|
|
,new MF_EndTag('asdf')
|
|
|
|
,new MF_EndTag('asdf')
|
|
|
|
);
|
|
|
|
$expect[2] = array(
|
|
|
|
new MF_Text('<asdf>')
|
|
|
|
,new MF_Text('</asdf>')
|
|
|
|
,new MF_Text('<d href="bang!">')
|
|
|
|
,new MF_Text('</d>')
|
|
|
|
,new MF_Text('<pooloka>')
|
|
|
|
,new MF_Text('<poolasdf>')
|
|
|
|
,new MF_Text('<ds moogle="&">')
|
|
|
|
,new MF_Text('</asdf>')
|
|
|
|
,new MF_Text('</asdf>')
|
|
|
|
);
|
|
|
|
|
2006-04-16 03:00:05 +00:00
|
|
|
foreach ($inputs as $i => $input) {
|
|
|
|
$result = $this->def->removeForeignElements($input);
|
2006-04-16 03:48:03 +00:00
|
|
|
$this->assertEqual($expect[$i], $result);
|
|
|
|
paintIf($result, $result != $expect[$i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_makeWellFormed() {
|
|
|
|
|
|
|
|
$inputs = array();
|
|
|
|
$expect = array();
|
|
|
|
|
|
|
|
$inputs[0] = array();
|
|
|
|
$expect[0] = $inputs[0];
|
|
|
|
|
|
|
|
$inputs[1] = array(
|
|
|
|
new MF_Text('This is ')
|
|
|
|
,new MF_StartTag('b')
|
|
|
|
,new MF_Text('bold')
|
|
|
|
,new MF_EndTag('b')
|
|
|
|
,new MF_Text(' text')
|
2006-04-16 16:57:51 +00:00
|
|
|
,new MF_EmptyTag('br')
|
2006-04-16 03:48:03 +00:00
|
|
|
);
|
|
|
|
$expect[1] = $inputs[1];
|
|
|
|
|
|
|
|
$inputs[2] = array(
|
|
|
|
new MF_StartTag('b')
|
|
|
|
,new MF_Text('Unclosed tag, gasp!')
|
|
|
|
);
|
|
|
|
$expect[2] = array(
|
|
|
|
new MF_StartTag('b')
|
|
|
|
,new MF_Text('Unclosed tag, gasp!')
|
|
|
|
,new MF_EndTag('b')
|
|
|
|
);
|
|
|
|
|
|
|
|
$inputs[3] = array(
|
|
|
|
new MF_StartTag('b')
|
|
|
|
,new MF_StartTag('i')
|
|
|
|
,new MF_Text('The b is closed, but the i is not')
|
|
|
|
,new MF_EndTag('b')
|
|
|
|
);
|
|
|
|
$expect[3] = array(
|
|
|
|
new MF_StartTag('b')
|
|
|
|
,new MF_StartTag('i')
|
|
|
|
,new MF_Text('The b is closed, but the i is not')
|
|
|
|
,new MF_EndTag('i')
|
|
|
|
,new MF_EndTag('b')
|
|
|
|
);
|
|
|
|
|
|
|
|
$inputs[4] = array(
|
|
|
|
new MF_Text('Hey, recycle unused end tags!')
|
|
|
|
,new MF_EndTag('b')
|
|
|
|
);
|
|
|
|
$expect[4] = array(
|
|
|
|
new MF_Text('Hey, recycle unused end tags!')
|
|
|
|
,new MF_Text('</b>')
|
|
|
|
);
|
|
|
|
|
2006-04-16 16:57:51 +00:00
|
|
|
$inputs[5] = array(new MF_StartTag('br', array('style' => 'clear:both;')));
|
|
|
|
$expect[5] = array(new MF_EmptyTag('br', array('style' => 'clear:both;')));
|
2006-04-16 04:07:21 +00:00
|
|
|
|
2006-04-16 16:57:51 +00:00
|
|
|
$inputs[6] = array(new MF_EmptyTag('div', array('style' => 'clear:both;')));
|
2006-04-16 04:07:21 +00:00
|
|
|
$expect[6] = array(
|
2006-04-16 16:57:51 +00:00
|
|
|
new MF_StartTag('div', array('style' => 'clear:both;'))
|
2006-04-16 04:07:21 +00:00
|
|
|
,new MF_EndTag('div')
|
|
|
|
);
|
|
|
|
|
2006-04-16 16:57:51 +00:00
|
|
|
// demonstrates start tag precedence
|
|
|
|
|
2006-04-16 03:48:03 +00:00
|
|
|
foreach ($inputs as $i => $input) {
|
2006-04-16 16:50:51 +00:00
|
|
|
$result = $this->def->makeWellFormed($input);
|
2006-04-16 03:48:03 +00:00
|
|
|
$this->assertEqual($expect[$i], $result);
|
2006-04-16 03:00:05 +00:00
|
|
|
paintIf($result, $result != $expect[$i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|