Schedule import: Show error message on schedule parsing errors
This commit is contained in:
parent
87bd4f4fa1
commit
ee7d30b339
|
@ -15,8 +15,7 @@ class XmlParser
|
|||
|
||||
public function load(string $xml): bool
|
||||
{
|
||||
$scheduleXML = simplexml_load_string($xml);
|
||||
|
||||
$scheduleXML = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOWARNING | LIBXML_NOERROR);
|
||||
if (!$scheduleXML) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="">
|
||||
<head>
|
||||
<title>I'm HTML!</title>
|
||||
</head>
|
||||
<body>
|
||||
This is not a schedule<br>
|
||||
and thus must be ignored.
|
||||
</body>
|
||||
</html>
|
|
@ -23,12 +23,13 @@ class XmlParserTest extends TestCase
|
|||
*/
|
||||
public function testLoad(): void
|
||||
{
|
||||
libxml_use_internal_errors(true);
|
||||
|
||||
$parser = new XmlParser();
|
||||
|
||||
// Invalid XML
|
||||
$this->assertFalse($parser->load('foo'));
|
||||
// Invalid schedule
|
||||
$this->assertFalse($parser->load(file_get_contents(__DIR__ . '/Assets/schedule-invalid.html')));
|
||||
|
||||
// Minimal import
|
||||
$this->assertTrue($parser->load(file_get_contents(__DIR__ . '/Assets/schedule-minimal.xml')));
|
||||
// Basic import
|
||||
|
|
Loading…
Reference in New Issue