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

First set of OPML parser tests

This commit is contained in:
J. King 2019-05-02 12:52:52 -04:00
parent 6ef13d0880
commit 5ba009cfed
7 changed files with 32 additions and 1 deletions

View file

@ -146,7 +146,7 @@ class OPML {
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 != $d->documentElement) {
if ($d->documentElement->nodeName !== "opml" || !$body->length || !$body->item(0)->parentNode->isSameNode($d->documentElement)) {
// not a valid OPML document
throw new Exception("invalidSemantics", ['type' => "OPML"]);
}

View file

@ -8,6 +8,7 @@ namespace JKingWeb\Arsse;
const NS_BASE = __NAMESPACE__."\\";
define(NS_BASE."BASE", dirname(__DIR__).DIRECTORY_SEPARATOR);
const DOCROOT = BASE."tests".DIRECTORY_SEPARATOR."docroot".DIRECTORY_SEPARATOR;
ini_set("memory_limit", "-1");
error_reporting(\E_ALL);
require_once BASE."vendor".DIRECTORY_SEPARATOR."autoload.php";

View file

@ -9,6 +9,7 @@ namespace JKingWeb\Arsse\TestCase\ImportExport;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Test\Result;
use JKingWeb\Arsse\ImportExport\OPML;
use JKingWeb\Arsse\ImportExport\Exception;
/** @covers \JKingWeb\Arsse\ImportExport\OPML<extended> */
class TestOPML extends \JKingWeb\Arsse\Test\AbstractTest {
@ -104,4 +105,25 @@ OPML_EXPORT_SERIALIZATION;
$this->assertException("doesNotExist", "User");
(new OPML)->export("john.doe@example.com");
}
/** @dataProvider provideParserData */
public function testParseOpmlForImport(string $file, bool $flat, $exp) {
$data = file_get_contents(\JKingWeb\Arsse\DOCROOT."Import/OPML/$file");
$parser = new OPML;
if ($exp instanceof \JKingWeb\Arsse\AbstractException) {
$this->assertException($exp);
$parser->parse($data, $flat);
} else {
$this->assertSame($exp, $parse->parse($data, $flat));
}
}
public function provideParserData() {
return [
["BrokenXML.opml", false, new Exception("invalidSyntax")],
["BrokenOPML.1.opml", false, new Exception("invalidSemantics")],
["BrokenOPML.2.opml", false, new Exception("invalidSemantics")],
["BrokenOPML.3.opml", false, new Exception("invalidSemantics")],
];
}
}

View file

@ -0,0 +1 @@
<html/>

View file

@ -0,0 +1 @@
<opml/>

View file

@ -0,0 +1,5 @@
<opml>
<head>
<body/>
</head>
</opml>

View file

@ -0,0 +1 @@
<opml>