mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-23 09:02:41 +00:00
Tests and fixed for OPML feed parsing
This commit is contained in:
parent
cdd9f4dfbe
commit
a30114807f
3 changed files with 52 additions and 2 deletions
|
@ -158,7 +158,7 @@ class OPML {
|
||||||
$folderMap[$body] = sizeof($folderMap);
|
$folderMap[$body] = sizeof($folderMap);
|
||||||
// iterate through each node in the body
|
// iterate through each node in the body
|
||||||
$node = $body->firstChild;
|
$node = $body->firstChild;
|
||||||
while ($node && $node != $body) {
|
while ($node && !$node->isSameNode($body)) {
|
||||||
if ($node->nodeType == \XML_ELEMENT_NODE && $node->nodeName === "outline") {
|
if ($node->nodeType == \XML_ELEMENT_NODE && $node->nodeName === "outline") {
|
||||||
// process any nodes which are outlines
|
// process any nodes which are outlines
|
||||||
if ($node->getAttribute("type") === "rss") {
|
if ($node->getAttribute("type") === "rss") {
|
||||||
|
@ -170,7 +170,7 @@ class OPML {
|
||||||
if (strlen($categories)) {
|
if (strlen($categories)) {
|
||||||
// collapse and trim whitespace from category names, if any, splitting along commas
|
// collapse and trim whitespace from category names, if any, splitting along commas
|
||||||
$categories = array_map(function($v) {
|
$categories = array_map(function($v) {
|
||||||
return trim(preg_replace("/\s+/g", " ", $v));
|
return trim(preg_replace("/\s+/", " ", $v));
|
||||||
}, explode(",", $categories));
|
}, explode(",", $categories));
|
||||||
} else {
|
} else {
|
||||||
$categories = [];
|
$categories = [];
|
||||||
|
|
|
@ -128,6 +128,44 @@ OPML_EXPORT_SERIALIZATION;
|
||||||
["Empty.1.opml", false, [[], []]],
|
["Empty.1.opml", false, [[], []]],
|
||||||
["Empty.2.opml", false, [[], []]],
|
["Empty.2.opml", false, [[], []]],
|
||||||
["Empty.3.opml", false, [[], []]],
|
["Empty.3.opml", false, [[], []]],
|
||||||
|
["FeedsOnly.opml", false, [[
|
||||||
|
[
|
||||||
|
'url' => "http://example.com/1",
|
||||||
|
'title' => "Feed 1",
|
||||||
|
'folder' => 0,
|
||||||
|
'tags' => [],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'url' => "http://example.com/2",
|
||||||
|
'title' => "",
|
||||||
|
'folder' => 0,
|
||||||
|
'tags' => [],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'url' => "http://example.com/3",
|
||||||
|
'title' => "",
|
||||||
|
'folder' => 0,
|
||||||
|
'tags' => [],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'url' => "http://example.com/4",
|
||||||
|
'title' => "",
|
||||||
|
'folder' => 0,
|
||||||
|
'tags' => [],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'url' => "",
|
||||||
|
'title' => "",
|
||||||
|
'folder' => 0,
|
||||||
|
'tags' => ["whee"],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'url' => "",
|
||||||
|
'title' => "",
|
||||||
|
'folder' => 0,
|
||||||
|
'tags' => ["whee", "whoo", ""],
|
||||||
|
],
|
||||||
|
], []]],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
tests/docroot/Import/OPML/FeedsOnly.opml
Normal file
12
tests/docroot/Import/OPML/FeedsOnly.opml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<opml>
|
||||||
|
<body>
|
||||||
|
<outline type="rss" xmlUrl="http://example.com/1" text="Feed 1"/>
|
||||||
|
<outline type="rss" xmlUrl="http://example.com/2" text=""/>
|
||||||
|
<outline type="rss" xmlUrl="http://example.com/3"/>
|
||||||
|
<outline type="rss" xmlUrl="http://example.com/4" title="Feed 4"> <!-- Only the "text" attribute is used -->
|
||||||
|
<outline type="rss" xmlUrl="http://example.com/!" title="Not a feed"/> <!-- Any descendants of a feed are skipped -->
|
||||||
|
</outline>
|
||||||
|
<outline type="rss" xmlUrl="" category="whee"/>
|
||||||
|
<outline type="rss" category="whee,whoo,"/>
|
||||||
|
</body>
|
||||||
|
</opml>
|
Loading…
Reference in a new issue