From 183788a216683147bb78a400c23e1dbc893da2e4 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Sat, 21 Mar 2020 16:54:31 -0400 Subject: [PATCH] Initial entry tests --- lib/Parser/Construct.php | 8 +++---- lib/Parser/XML/Feed.php | 2 +- tests/cases/XML/entry-atom.yaml | 42 +++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 tests/cases/XML/entry-atom.yaml diff --git a/lib/Parser/Construct.php b/lib/Parser/Construct.php index f5c117e..243705d 100644 --- a/lib/Parser/Construct.php +++ b/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); } } diff --git a/lib/Parser/XML/Feed.php b/lib/Parser/XML/Feed.php index dcd2d2e..4cf65c5 100644 --- a/lib/Parser/XML/Feed.php +++ b/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; } } diff --git a/tests/cases/XML/entry-atom.yaml b/tests/cases/XML/entry-atom.yaml new file mode 100644 index 0000000..dd8d2b5 --- /dev/null +++ b/tests/cases/XML/entry-atom.yaml @@ -0,0 +1,42 @@ +Empty entry: + input: > + + Bogus text + + output: + format: atom + version: '1.0' + lang: en + +Entry identifier: + input: > + + + ook + + + output: + format: atom + version: '1.0' + entries: + - id: 'ook' + +Entry language: + input: > + + + ook + + + eek + + + output: + format: atom + version: '1.0' + lang: en + entries: + - id: 'ook' + lang: fr + - id: eek + lang: en