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:
parent
6ef13d0880
commit
5ba009cfed
7 changed files with 32 additions and 1 deletions
|
@ -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"]);
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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")],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
1
tests/docroot/Import/OPML/BrokenOPML.1.opml
Normal file
1
tests/docroot/Import/OPML/BrokenOPML.1.opml
Normal file
|
@ -0,0 +1 @@
|
|||
<html/>
|
1
tests/docroot/Import/OPML/BrokenOPML.2.opml
Normal file
1
tests/docroot/Import/OPML/BrokenOPML.2.opml
Normal file
|
@ -0,0 +1 @@
|
|||
<opml/>
|
5
tests/docroot/Import/OPML/BrokenOPML.3.opml
Normal file
5
tests/docroot/Import/OPML/BrokenOPML.3.opml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<opml>
|
||||
<head>
|
||||
<body/>
|
||||
</head>
|
||||
</opml>
|
1
tests/docroot/Import/OPML/BrokenXML.opml
Normal file
1
tests/docroot/Import/OPML/BrokenXML.opml
Normal file
|
@ -0,0 +1 @@
|
|||
<opml>
|
Loading…
Reference in a new issue