setupFile = dirname( __FILE__ ) . '/../PortableInfobox.setup.php';
parent::setUp();
}
/**
* @dataProvider errorHandlingDataProvider
*/
public function testErrorHandling( $markup, $expectedErrors ) {
$parser = $this->getMockBuilder( 'Wikia\PortableInfobox\Parser\XmlParser' )
->setMethods( [ 'logXmlParseError' ] )
->getMock();
$errors = [ ];
try {
$data = $parser->parseXmlString( $markup, $errors );
} catch ( \Wikia\PortableInfobox\Parser\XmlMarkupParseErrorException $e ) {
// parseXmlString should throw an exception, but we want to proceed in order to check parameters
// from logXmlParseError
}
$this->assertEquals( $expectedErrors, array_map(
function ( LibXMLError $error ) {
return [ 'level' => $error->level, 'code' => $error->code, 'msg' => trim( $error->message ) ];
},
$errors
) );
}
public function errorHandlingDataProvider() {
/*
* Error codes are defined on official xml API documentation:
* http://www.xmlsoft.org/html/libxml-xmlerror.html
*/
return [
[
'd',
[
[ 'level' => LIBXML_ERR_FATAL, 'code' => 73, 'msg' => "expected '>'" ],
[ 'level' => LIBXML_ERR_FATAL, 'code' => 76, 'msg' => "Opening and ending tag mismatch: data line 1 and dat" ],
[ 'level' => LIBXML_ERR_FATAL, 'code' => 5, 'msg' => "Extra content at the end of the document" ],
]
],
[
' x ',
[
[ 'level' => LIBXML_ERR_FATAL, 'code' => 5, 'msg' => "Extra content at the end of the document" ],
]
],
[
' > ddd < a >',
[
[ 'level' => LIBXML_ERR_FATAL, 'code' => 68, 'msg' => "StartTag: invalid element name" ],
]
],
[
'',
[
[ 'level' => LIBXML_ERR_FATAL, 'code' => 77, 'msg' => "Premature end of data in tag data line 1" ],
]
],
[
'',
[
[ 'level' => LIBXML_ERR_FATAL, 'code' => 39, 'msg' => "AttValue: \" or ' expected" ],
[ 'level' => LIBXML_ERR_FATAL, 'code' => 65, 'msg' => "attributes construct error" ],
[ 'level' => LIBXML_ERR_FATAL, 'code' => 73, 'msg' => "Couldn't find end of Start Tag data line 1" ],
]
],
[
'',
[
[ 'level' => LIBXML_ERR_FATAL, 'code' => 76, 'msg' => "Opening and ending tag mismatch: data line 1 and infobox" ],
[ 'level' => LIBXML_ERR_FATAL, 'code' => 77, 'msg' => "Premature end of data in tag infobox line 1" ],
]
],
[
' LIBXML_ERR_FATAL, 'code' => 65, 'msg' => "attributes construct error" ],
[ 'level' => LIBXML_ERR_FATAL, 'code' => 73, 'msg' => "Couldn't find end of Start Tag data line 1" ],
[ 'level' => LIBXML_ERR_FATAL, 'code' => 76, 'msg' => "Opening and ending tag mismatch: infobox line 1 and data" ],
[ 'level' => LIBXML_ERR_FATAL, 'code' => 5, 'msg' => "Extra content at the end of the document" ]
]
]
];
}
}