')
,new MF_Text('')
,new MF_Text('')
);
foreach ($inputs as $i => $input) {
$result = $this->def->removeForeignElements($input);
$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')
,new MF_EmptyTag('br')
);
$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('')
);
$inputs[5] = array(new MF_StartTag('br', array('style' => 'clear:both;')));
$expect[5] = array(new MF_EmptyTag('br', array('style' => 'clear:both;')));
$inputs[6] = array(new MF_EmptyTag('div', array('style' => 'clear:both;')));
$expect[6] = array(
new MF_StartTag('div', array('style' => 'clear:both;'))
,new MF_EndTag('div')
);
// test automatic paragraph closing
$inputs[7] = array(
new MF_StartTag('p')
,new MF_Text('Paragraph 1')
,new MF_StartTag('p')
,new MF_Text('Paragraph 2')
);
$expect[7] = array(
new MF_StartTag('p')
,new MF_Text('Paragraph 1')
,new MF_EndTag('p')
,new MF_StartTag('p')
,new MF_Text('Paragraph 2')
,new MF_EndTag('p')
);
$inputs[8] = array(
new MF_StartTag('div')
,new MF_StartTag('p')
,new MF_Text('Paragraph 1 in a div')
,new MF_EndTag('div')
);
$expect[8] = array(
new MF_StartTag('div')
,new MF_StartTag('p')
,new MF_Text('Paragraph 1 in a div')
,new MF_EndTag('p')
,new MF_EndTag('div')
);
// automatic list closing
$inputs[9] = array(
new MF_StartTag('ol')
,new MF_StartTag('li')
,new MF_Text('Item 1')
,new MF_StartTag('li')
,new MF_Text('Item 2')
,new MF_EndTag('ol')
);
$expect[9] = array(
new MF_StartTag('ol')
,new MF_StartTag('li')
,new MF_Text('Item 1')
,new MF_EndTag('li')
,new MF_StartTag('li')
,new MF_Text('Item 2')
,new MF_EndTag('li')
,new MF_EndTag('ol')
);
foreach ($inputs as $i => $input) {
$result = $this->def->makeWellFormed($input);
$this->assertEqual($expect[$i], $result);
paintIf($result, $result != $expect[$i]);
}
}
function test_fixNesting() {
$inputs = array();
$expect = array();
// next id = 4
// legal inline nesting
$inputs[0] = array(
new MF_StartTag('b'),
new MF_Text('Bold text'),
new MF_EndTag('b'),
);
$expect[0] = $inputs[0];
// legal inline and block
// as the parent element is considered FLOW
$inputs[1] = array(
new MF_StartTag('a', array('href' => 'http://www.example.com/')),
new MF_Text('Linky'),
new MF_EndTag('a'),
new MF_StartTag('div'),
new MF_Text('Block element'),
new MF_EndTag('div'),
);
$expect[1] = $inputs[1];
// illegal block in inline, element -> text
$inputs[2] = array(
new MF_StartTag('b'),
new MF_StartTag('div'),
new MF_Text('Illegal Div'),
new MF_EndTag('div'),
new MF_EndTag('b'),
);
$expect[2] = array(
new MF_StartTag('b'),
new MF_Text(''),
new MF_Text('Illegal Div'),
new MF_Text('
'),
new MF_EndTag('b'),
);
// illegal in
$inputs[3] = array(
new MF_StartTag('a'),
new MF_EndTag('a')
);
$expect[3] = array(
new MF_StartTag('a'),
new MF_EndTag('a')
);
foreach ($inputs as $i => $input) {
$result = $this->def->fixNesting($input);
$this->assertEqual($expect[$i], $result);
paintIf($result, $result != $expect[$i]);
}
}
}
?>