Browse Source

More OPML parser tests

microsub
J. King 5 years ago
parent
commit
cdd9f4dfbe
  1. 4
      lib/ImportExport/OPML.php
  2. 6
      tests/cases/ImportExport/TestOPML.php
  3. 1
      tests/docroot/Import/OPML/BrokenOPML.1.opml
  4. 1
      tests/docroot/Import/OPML/BrokenOPML.2.opml
  5. 1
      tests/docroot/Import/OPML/BrokenOPML.3.opml
  6. 5
      tests/docroot/Import/OPML/BrokenOPML.4.opml
  7. 1
      tests/docroot/Import/OPML/BrokenXML.opml
  8. 4
      tests/docroot/Import/OPML/Empty.1.opml
  9. 9
      tests/docroot/Import/OPML/Empty.2.opml
  10. 11
      tests/docroot/Import/OPML/Empty.3.opml

4
lib/ImportExport/OPML.php

@ -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"]);
}

6
tests/cases/ImportExport/TestOPML.php

@ -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, [[], []]],
];
}
}

1
tests/docroot/Import/OPML/BrokenOPML.1.opml

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

1
tests/docroot/Import/OPML/BrokenOPML.2.opml

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

1
tests/docroot/Import/OPML/BrokenOPML.3.opml

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

5
tests/docroot/Import/OPML/BrokenOPML.4.opml

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

1
tests/docroot/Import/OPML/BrokenXML.opml

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

4
tests/docroot/Import/OPML/Empty.1.opml

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

9
tests/docroot/Import/OPML/Empty.2.opml

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

@ -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…
Cancel
Save