1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

More OPML parser tests

This commit is contained in:
J. King 2019-05-02 21:54:49 -04:00
parent 5ba009cfed
commit cdd9f4dfbe
10 changed files with 40 additions and 3 deletions

View file

@ -145,8 +145,8 @@ class OPML {
$err = libxml_get_last_error();
throw new Exception("invalidSyntax", ['line' => $err->line, 'column' => $err->column]);
}
$body = $d->getElementsByTagName("body");
if ($d->documentElement->nodeName !== "opml" || !$body->length || !$body->item(0)->parentNode->isSameNode($d->documentElement)) {
$body = (new \DOMXPath($d))->query("/opml/body");
if ($body->length != 1) {
// not a valid OPML document
throw new Exception("invalidSemantics", ['type' => "OPML"]);
}

View file

@ -114,7 +114,7 @@ OPML_EXPORT_SERIALIZATION;
$this->assertException($exp);
$parser->parse($data, $flat);
} else {
$this->assertSame($exp, $parse->parse($data, $flat));
$this->assertSame($exp, $parser->parse($data, $flat));
}
}
@ -124,6 +124,10 @@ OPML_EXPORT_SERIALIZATION;
["BrokenOPML.1.opml", false, new Exception("invalidSemantics")],
["BrokenOPML.2.opml", false, new Exception("invalidSemantics")],
["BrokenOPML.3.opml", false, new Exception("invalidSemantics")],
["BrokenOPML.4.opml", false, new Exception("invalidSemantics")],
["Empty.1.opml", false, [[], []]],
["Empty.2.opml", false, [[], []]],
["Empty.3.opml", false, [[], []]],
];
}
}

View file

@ -1 +1,2 @@
<html/>
<!-- Not an OPML document -->

View file

@ -1 +1,2 @@
<opml/>
<!-- Not body element -->

View file

@ -3,3 +3,4 @@
<body/>
</head>
</opml>
<!-- No body as child of root -->

View file

@ -0,0 +1,5 @@
<opml>
<body/>
<body/>
</opml>
<!-- Only one body is allowed -->

View file

@ -1 +1,2 @@
<opml>
<!-- Not well-formed XML -->

View file

@ -0,0 +1,4 @@
<opml>
<body/>
</opml>
<!-- Empty body is not an error -->

View file

@ -0,0 +1,9 @@
<opml>
<head>
<body>
<outline text="I should be ignored!"/>
</body>
</head>
<body/>
</opml>
<!-- Only body in root counts -->

View file

@ -0,0 +1,11 @@
<opml>
<body>
<someOtherElement>
<outline text="I should be skipped over!"/>
</someOtherElement>
<body>
<outline text="I should be skipped over, too!"/>
</body>
</body>
</opml>
<!-- The descendents of elements other than <outline> are ignored -->