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
|
public function load(string $xml): bool
|
||||||
{
|
{
|
||||||
$scheduleXML = simplexml_load_string($xml);
|
$scheduleXML = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOWARNING | LIBXML_NOERROR);
|
||||||
|
|
||||||
if (!$scheduleXML) {
|
if (!$scheduleXML) {
|
||||||
return false;
|
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
|
public function testLoad(): void
|
||||||
{
|
{
|
||||||
libxml_use_internal_errors(true);
|
|
||||||
|
|
||||||
$parser = new XmlParser();
|
$parser = new XmlParser();
|
||||||
|
|
||||||
// Invalid XML
|
// Invalid XML
|
||||||
$this->assertFalse($parser->load('foo'));
|
$this->assertFalse($parser->load('foo'));
|
||||||
|
// Invalid schedule
|
||||||
|
$this->assertFalse($parser->load(file_get_contents(__DIR__ . '/Assets/schedule-invalid.html')));
|
||||||
|
|
||||||
// Minimal import
|
// Minimal import
|
||||||
$this->assertTrue($parser->load(file_get_contents(__DIR__ . '/Assets/schedule-minimal.xml')));
|
$this->assertTrue($parser->load(file_get_contents(__DIR__ . '/Assets/schedule-minimal.xml')));
|
||||||
// Basic import
|
// Basic import
|
||||||
|
|
Loading…
Reference in New Issue