mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-31 21:12:41 +00:00
More OPML parser tests
This commit is contained in:
parent
5ba009cfed
commit
cdd9f4dfbe
10 changed files with 40 additions and 3 deletions
|
@ -145,8 +145,8 @@ class OPML {
|
||||||
$err = libxml_get_last_error();
|
$err = libxml_get_last_error();
|
||||||
throw new Exception("invalidSyntax", ['line' => $err->line, 'column' => $err->column]);
|
throw new Exception("invalidSyntax", ['line' => $err->line, 'column' => $err->column]);
|
||||||
}
|
}
|
||||||
$body = $d->getElementsByTagName("body");
|
$body = (new \DOMXPath($d))->query("/opml/body");
|
||||||
if ($d->documentElement->nodeName !== "opml" || !$body->length || !$body->item(0)->parentNode->isSameNode($d->documentElement)) {
|
if ($body->length != 1) {
|
||||||
// not a valid OPML document
|
// not a valid OPML document
|
||||||
throw new Exception("invalidSemantics", ['type' => "OPML"]);
|
throw new Exception("invalidSemantics", ['type' => "OPML"]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ OPML_EXPORT_SERIALIZATION;
|
||||||
$this->assertException($exp);
|
$this->assertException($exp);
|
||||||
$parser->parse($data, $flat);
|
$parser->parse($data, $flat);
|
||||||
} else {
|
} 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.1.opml", false, new Exception("invalidSemantics")],
|
||||||
["BrokenOPML.2.opml", false, new Exception("invalidSemantics")],
|
["BrokenOPML.2.opml", false, new Exception("invalidSemantics")],
|
||||||
["BrokenOPML.3.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, [[], []]],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
<html/>
|
<html/>
|
||||||
|
<!-- Not an OPML document -->
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
<opml/>
|
<opml/>
|
||||||
|
<!-- Not body element -->
|
||||||
|
|
|
@ -3,3 +3,4 @@
|
||||||
<body/>
|
<body/>
|
||||||
</head>
|
</head>
|
||||||
</opml>
|
</opml>
|
||||||
|
<!-- No body as child of root -->
|
||||||
|
|
5
tests/docroot/Import/OPML/BrokenOPML.4.opml
Normal file
5
tests/docroot/Import/OPML/BrokenOPML.4.opml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<opml>
|
||||||
|
<body/>
|
||||||
|
<body/>
|
||||||
|
</opml>
|
||||||
|
<!-- Only one body is allowed -->
|
|
@ -1 +1,2 @@
|
||||||
<opml>
|
<opml>
|
||||||
|
<!-- Not well-formed XML -->
|
||||||
|
|
4
tests/docroot/Import/OPML/Empty.1.opml
Normal file
4
tests/docroot/Import/OPML/Empty.1.opml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<opml>
|
||||||
|
<body/>
|
||||||
|
</opml>
|
||||||
|
<!-- Empty body is not an error -->
|
9
tests/docroot/Import/OPML/Empty.2.opml
Normal file
9
tests/docroot/Import/OPML/Empty.2.opml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<opml>
|
||||||
|
<head>
|
||||||
|
<body>
|
||||||
|
<outline text="I should be ignored!"/>
|
||||||
|
</body>
|
||||||
|
</head>
|
||||||
|
<body/>
|
||||||
|
</opml>
|
||||||
|
<!-- Only body in root counts -->
|
11
tests/docroot/Import/OPML/Empty.3.opml
Normal file
11
tests/docroot/Import/OPML/Empty.3.opml
Normal 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 -->
|
Loading…
Reference in a new issue