Clean up
[catagits/XML-Feed.git] / t / 12-multi-categories-atom.t
index 25b0ff9..29ff648 100644 (file)
@@ -1,6 +1,41 @@
 #!perl -w
 
 use strict;
-use vars qw($type $field);
-$type = "atom";
-require 't/12-multi-categories.base';
+use strict;
+use Test::More tests => 8 * 3;
+use XML::Feed;
+
+foreach my $test (["atom"], ["rss"], ["rss", "subjects"]) {
+
+    my $type  = $test->[0];
+    my $other = ('Atom' ne $type)? "RSS" : "Atom";
+    my $field = $test->[1] || "categories";
+
+    ok(my $feed = XML::Feed->parse("t/samples/${type}-multiple-${field}.xml"), "Parsed $type file with multiple categories");
+    my ($entry) = $feed->entries;
+
+    is_deeply(
+        [$entry->category()],
+        ["foo", "bar", "quux", "simon's tags"],        
+    "Got all categories");
+
+    my $xml = $feed->as_xml;
+    ok($feed = XML::Feed->parse(\$xml), "Reparsed $type from string");
+    is_deeply(
+        [$entry->category()],
+        ["foo", "bar", "quux", "simon's tags"],        
+    "Got all categories again");
+
+    ok($entry->category("quirka fleeg"), "Added a category");
+    is_deeply(
+        [$entry->category()],
+        ["foo", "bar", "quux", "simon's tags", "quirka fleeg"],        
+    "Got new category");
+
+    ok(my $new = $entry->convert($other), "Converted entry to $other");
+    is_deeply(
+        [$new->category()],
+        ["foo", "bar", "quux", "simon's tags", "quirka fleeg"],        
+    "Got converted categories");
+
+}