Schedule import: Show error message on schedule parsing errors

This commit is contained in:
Igor Scheller 2023-09-17 13:25:11 +02:00 committed by Michael Weimann
parent 87bd4f4fa1
commit ee7d30b339
3 changed files with 14 additions and 4 deletions

View File

@ -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;
}

View File

@ -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>

View File

@ -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