assertEquals($type, $event['name'], "Event $type for " . print_r($event, TRUE));
if (is_array($expects)) {
$this->assertEquals($expects, $event['data'], "Event $type should equal $expects: " . print_r($event, TRUE));
}
else {
$this->assertEquals($expects, $event['data'][0], "Event $type should equal $expects: " . print_r($event, TRUE));
}
}
/**
* Assert that a given event is 'error'.
*/
public function assertEventError($event) {
$this->assertEquals('error', $event['name'], "Expected error for event: " . print_r($event, TRUE));
}
// ================================================================
// Utility functions.
// ================================================================
public function testParse() {
list($tok, $events) = $this->createTokenizer('');
$tok->parse();
$e1 = $events->get(0);
$this->assertEquals(1, $events->Depth());
$this->assertEquals('eof', $e1['name']);
}
public function testWhitespace() {
$spaces = ' ';
list($tok, $events) = $this->createTokenizer($spaces);
$tok->parse();
$this->assertEquals(2, $events->depth());
$e1 = $events->get(0);
$this->assertEquals('text', $e1['name']);
$this->assertEquals($spaces, $e1['data'][0]);
}
public function testCharacterReference() {
$str = '&';
$events = $this->parse($str);
$this->assertEquals(2, $events->depth());
$e1 = $events->get(0);
$this->assertEquals('&', $e1['data'][0]);
// Test with hex charref
$str = '<';
$events = $this->parse($str);
$e1 = $events->get(0);
$this->assertEquals('<', $e1['data'][0]);
// Test with decimal charref
$str = '&';
$events = $this->parse($str);
$e1 = $events->get(0);
$this->assertEquals('&', $e1['data'][0]);
// Test with stand-alone ampersand
$str = '& ';
$events = $this->parse($str);
$e1 = $events->get(0);
$this->assertEquals('&', $e1['data'][0][0], "Stand-alone &");
// Test with broken charref
$str = '&foo';
$events = $this->parse($str);
$e1 = $events->get(0);
$this->assertEquals('error', $e1['name']);
}
public function testBogusComment() {
$bogus = array(
'+this is a bogus comment. +>',
'',
'',
'',
'',
'',
'',
'',
'parse($str);
$this->assertEventError($events->get(0));
$this->assertEventEquals('comment', $str, $events->get(1));
}
}
public function testEndTag() {
$succeed = array(
'' => 'a',
'' => 'test',
'' => 'test',
'' =>
'thisIsTheTagThatDoesntEndItJustGoesOnAndOnMyFriend',
// See 8.2.4.10, which requires this and does not say error.
'' => 'a $result) {
$events = $this->parse($test);
$this->assertEquals(2, $events->depth());
$this->assertEventEquals('endTag', $result, $events->get(0));
}
// Recoverable failures
$fail = array(
'' => 'a',
'' => 'a',
'' => 'a',
'' => 'a',
' 'a',
);
foreach ($fail as $test => $result) {
$events = $this->parse($test);
$this->assertEquals(3, $events->depth());
// Should have triggered an error.
$this->assertEventError($events->get(0));
// Should have tried to parse anyway.
$this->assertEventEquals('endTag', $result, $events->get(1));
}
// BogoComments
$comments = array(
'>' => '>',
' >' => ' >',
' a>' => ' a>',
);
foreach ($comments as $test => $result) {
$events = $this->parse($test);
$this->assertEquals(3, $events->depth());
// Should have triggered an error.
$this->assertEventError($events->get(0));
// Should have tried to parse anyway.
$this->assertEventEquals('comment', $result, $events->get(1));
}
}
public function testComment() {
$good = array(
'' => 'easy',
'' => ' 1 > 0 ',
'' => ' --$i ',
'' => '--$i',
'' => ' 1 > 0 ',
"" => "\nHello World.\na",
'' => ' ' => '',
'