Make base work
Simon Wistow [Thu, 23 Oct 2008 22:43:52 +0000 (22:43 +0000)]
lib/XML/Feed/RSS.pm
t/11-xml-base-atom.t
t/11-xml-base-rss.t

index 9286d21..8c5b80b 100644 (file)
@@ -211,11 +211,17 @@ sub content {
         my $c = ref($_[0]) eq 'XML::Feed::Content' ? $_[0]->body : $_[0];
         $item->{content}{encoded} = $c;
     } else {
+        my $description = $item->{description};
+        my $base;
+        if ('HASH' eq ref($description)) {
+            $base = $description->{'xml:base'};
+            $description = $description->{content};
+        }
         my $body =
             $item->{content}{encoded} ||
             $item->{'http://www.w3.org/1999/xhtml'}{body} ||
-            $item->{description};
-        XML::Feed::Content->wrap({ type => 'text/html', body => $body });
+            $description;
+        XML::Feed::Content->wrap({ type => 'text/html', body => $body, base => $base });
     }
 }
 
index 0340d0e..6f4757e 100644 (file)
@@ -1,13 +1,32 @@
 # $Id: $
 
 use strict;
-use Test::More tests => 3;
+use Test::More tests => 13;
 use XML::Feed;
 
 
 my $feed    = XML::Feed->parse('t/samples/base_atom.xml');
 my ($entry) = $feed->entries;
 my $content = $entry->content;
-is($feed->base,    "http://example.org/",                     "Got feed base");
-is($entry->base,   "http://example.org/archives/",            "Got entry base");
-is($content->base, "http://example.org/archives/000001.html", "Got content base");
+is($feed->base,    "http://example.org/",                         "Got feed base");
+is($entry->base,   "http://example.org/archives/",                "Got entry base");
+is($content->base, "http://example.org/archives/000001.html",     "Got content base");
+
+my $xml = $feed->as_xml;
+my $new;
+ok($new =  XML::Feed->parse(\$xml),                               "Parsed old feed");
+my ($new_entry)  = $new->entries;
+my $new_content  = $entry->content;
+is($new->base,         "http://example.org/",                     "Got feed base");
+is($new_entry->base,   "http://example.org/archives/",            "Got entry base");
+is($new_content->base, "http://example.org/archives/000001.html", "Got content base");
+
+
+ok($feed->base("http://foo.com/"),                                "Set feed base");
+ok($entry->base("http://foo.com/archives/"),                      "Set entry base");
+ok($content->base("http://foo.com/archives/000001.html"),         "Set content base");
+
+is($feed->base,    "http://foo.com/",                             "Got feed base");
+is($entry->base,   "http://foo.com/archives/",                    "Got entry base");
+is($content->base, "http://foo.com/archives/000001.html",         "Got content base");
+
index 2cba3ca..6efcdcb 100644 (file)
@@ -1,14 +1,33 @@
 # $Id: $
 
 use strict;
-#use Test::More tests => 3;
-use Test::More skip_all => "xml:base support not available in XML::RSS yet";
+use Test::More tests => 13;
 use XML::Feed;
 
 
 my $feed    = XML::Feed->parse('t/samples/base_rss.xml');
 my ($entry) = $feed->entries;
 my $content = $entry->content;
-is($feed->base,    "http://example.org/",                     "Got feed base");
-is($entry->base,   "http://example.org/archives/",            "Got entry base");
-is($content->base, "http://example.org/archives/000001.html", "Got content base");
+is($feed->base,    "http://example.org/",                         "Got feed base");
+is($entry->base,   "http://example.org/archives/",                "Got entry base");
+is($content->base, "http://example.org/archives/000001.html",     "Got content base");
+
+my $xml = $feed->as_xml;
+my $new;
+ok($new =  XML::Feed->parse(\$xml),                               "Parsed old feed");
+my ($new_entry)  = $new->entries;
+my $new_content  = $entry->content;
+is($new->base,         "http://example.org/",                     "Got feed base");
+is($new_entry->base,   "http://example.org/archives/",            "Got entry base");
+is($new_content->base, "http://example.org/archives/000001.html", "Got content base");
+
+
+ok($feed->base("http://foo.com/"),                                "Set feed base");
+ok($entry->base("http://foo.com/archives/"),                      "Set entry base");
+ok($content->base("http://foo.com/archives/000001.html"),         "Set content base");
+
+is($feed->base,    "http://foo.com/",                             "Got feed base");
+is($entry->base,   "http://foo.com/archives/",                    "Got entry base");
+is($content->base, "http://foo.com/archives/000001.html",         "Got content base");
+
+