Browse Source

Initial entry tests

master
J. King 4 years ago
parent
commit
183788a216
  1. 8
      lib/Parser/Construct.php
  2. 2
      lib/Parser/XML/Feed.php
  3. 42
      tests/cases/XML/entry-atom.yaml

8
lib/Parser/Construct.php

@ -97,9 +97,9 @@ trait Construct {
return null;
}
protected function empty($o): bool {
return !array_filter((array) $o, function($v) {
return !is_null($v) && (!$v instanceof Collection || sizeof($v) > 0);
});
protected function empty($o, array $ignore = []): bool {
return !array_filter((array) $o, function($v, $k) use($ignore) {
return !in_array($k, $ignore) && !is_null($v) && (!$v instanceof Collection || sizeof($v) > 0);
}, \ARRAY_FILTER_USE_BOTH);
}
}

2
lib/Parser/XML/Feed.php

@ -223,7 +223,7 @@ class Feed extends Construct implements \MensBeam\Lax\Parser\Feed {
$out = [];
foreach ($this->xpath->query("atom:entry|rss2:item|rss0:item|rss1:item|/rdf:RDF/rss0:item|/rdf:RDF/rss1:item", $this->subject) as $node) {
$entry = (new EntryParser($node, $this->xpath, $feed))->parse();
if (!$this->empty($entry)) {
if (!$this->empty($entry, ["lang"])) {
$out[] = $entry;
}
}

42
tests/cases/XML/entry-atom.yaml

@ -0,0 +1,42 @@
Empty entry:
input: >
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<entry>Bogus text</entry>
</feed>
output:
format: atom
version: '1.0'
lang: en
Entry identifier:
input: >
<feed xmlns="http://www.w3.org/2005/Atom">
<entry>
<id>ook</id>
</entry>
</feed>
output:
format: atom
version: '1.0'
entries:
- id: 'ook'
Entry language:
input: >
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<entry xml:lang="fr">
<id>ook</id>
</entry>
<entry>
<id>eek</id>
</entry>
</feed>
output:
format: atom
version: '1.0'
lang: en
entries:
- id: 'ook'
lang: fr
- id: eek
lang: en
Loading…
Cancel
Save