Index: /branches/release-35/t/41-atom.t
===================================================================
--- /branches/release-35/t/41-atom.t (revision 1098)
+++ /branches/release-35/t/41-atom.t (revision 1946)
@@ -1,13 +1,18 @@
 use strict;
+use lib 't/lib', 'extlib', 'lib', '../lib', '../extlib';
 use POSIX;
 
-use Test::More tests => 11;
+use MT;
+use MT::Atom;
+use XML::LibXML; # this test would not work without it
+use XML::XPath;
+use XML::Atom;
+use XML::Atom::Feed;
+use XML::Atom::Entry;
+
+use Test::More tests => 37;
 
 # To keep away from being under FastCGI
 $ENV{HTTP_HOST} = 'localhost';
-
-use MT::Atom;
-
-use MT;
 
 use vars qw( $DB_DIR $T_CFG );
@@ -15,6 +20,42 @@
 isa_ok($mt, 'MT');
 
-use lib 't/lib', 'extlib', 'lib', '../lib', '../extlib';
 use MT::Test qw(:db :data);
+
+my %test_data;
+$test_data{'/mt-atom.cgi/weblog'} = <<XML1;
+<?xml version="1.0" encoding="utf-8"?>
+    <entry xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
+    <title>Fight the Power</title>
+    <content>Elvis was a hero to most but he never meant shit to me</content>
+    <issued>2004-08-06T00:43:34+01:00</issued>
+    </entry>
+XML1
+$test_data{'/mt-atom.cgi/1.0'} = <<XML2;
+<?xml version="1.0" encoding="utf-8"?>
+<entry xmlns="http://www.w3.org/2005/Atom">
+<title>Fight the Power</title>
+<content type="html">Elvis was a hero to most but he never meant shit to me</content>
+<published>2004-08-06T00:43:34+01:00</published>
+</entry>
+XML2
+
+my %feed_link = (
+    '/mt-atom.cgi/weblog' => sub {
+        my ($resp) = @_;
+        my $feed = XML::Atom::Feed->new(\$resp->content());
+        ok($feed, 'got feed');
+        my ($sfeed) = grep {
+            $_->rel eq 'service.feed'
+        } $feed->links;
+        $sfeed->href;
+    },
+    '/mt-atom.cgi/1.0' => sub {
+        my ($resp) = @_;
+        my $feed = XML::XPath->new(xml => $resp->content());
+        ok($feed, 'got feed');
+        my $col = $feed->getNodeText('/service/workspace[1]/collection/@href');
+        $col;
+    }
+);
 
 my $username = 'Chuck D';
@@ -43,4 +84,5 @@
 my $ua = new LWP::UserAgent::Local({ ScriptAlias => '/' });
 
+foreach my $base_uri ( qw{/mt-atom.cgi/weblog /mt-atom.cgi/1.0 } ) {
 {
 # # # # First try a req with baloney auth, make sure it fails
@@ -50,5 +92,5 @@
 
     my $uri = new URI();
-    $uri->path('/mt-atom.cgi/weblog/blog_id=1');
+    $uri->path($base_uri . '/blog_id=1');
     my $req = new HTTP::Request(GET => $uri);
     $req->header(Authentication => 'Atom');
@@ -62,4 +104,57 @@
 }
 
+# test blog lists
+{
+    my $wsse_header = make_wsse($chuck_token);
+    my $uri = new URI;
+    $uri->path($base_uri);
+    my $req = new HTTP::Request(GET => $uri);
+    $req->header('Authorization' => 'Atom');
+    $req->header('X-WSSE' => $wsse_header);
+
+    print "# X-WSSE: $wsse_header\n";
+
+    my $resp = $ua->request($req);
+    if (ok($resp->is_success)) {
+        my $blog_feed_url = $feed_link{$base_uri}->($resp);
+        my $uri = new URI($blog_feed_url);
+        is($uri->path, $base_uri . '/blog_id=1', 'blog feed url is correct');
+    }
+    else {
+        die 'failed to retrieve blog feed';
+    }
+}
+
+# test blog feed
+{
+    my $wsse_header = make_wsse($chuck_token);
+    my $uri = new URI;
+    $uri->path($base_uri . "/blog_id=1");
+    my $req = new HTTP::Request(GET => $uri);
+    $req->header('Authorization' => 'Atom');
+    $req->header('X-WSSE' => $wsse_header);
+
+    print "# X-WSSE: $wsse_header\n";
+
+    my $resp = $ua->request($req);
+    if (ok($resp->is_success)) {
+        my $feed = XML::Atom::Feed->new(\$resp->content());
+        ok($feed, 'got feed');
+        is($feed->title, 'none');
+        my ($alternate) = grep {
+            $_->rel eq 'alternate' && $_->type eq 'text/html'
+        } $feed->links;
+        is($alternate->href, 'http://narnia.na/nana/', 'blog url is correct');
+        my $entry_count = MT::Entry->count(
+            { blog_id => 1 },
+            { limit => 21 },
+        );
+        my @entries = $feed->entries;
+        is($entry_count, scalar(@entries), 'number of entries is correct');
+    }
+    else {
+        die 'failed to retrieve blog feed';
+    }
+}
 
 my $entry_id;
@@ -78,5 +173,5 @@
 
     my $uri = new URI;
-    $uri->path('/mt-atom.cgi/weblog/blog_id=1');
+    $uri->path($base_uri . '/blog_id=1');
     my $req = new HTTP::Request(POST => $uri);
 
@@ -110,5 +205,5 @@
 
     $uri = new URI;
-    $uri->path('/mt-atom.cgi/weblog/blog_id=1');
+    $uri->path($base_uri . '/blog_id=1');
     $req = new HTTP::Request(POST => $uri);
 
@@ -116,11 +211,5 @@
     print "# sending: ", $req->header('X-Atom-Authorization');
 
-    $req->content(<<XML);
-<?xml version="1.0" encoding="utf-8"?>
-    <entry xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
-    <title>Fight the Power</title>
-    <content>Elvis was a hero to most but he never meant shit to me</content>
-    </entry>
-XML
+    $req->content($test_data{$base_uri});
 
     $resp = $ua->simple_request($req);
@@ -170,5 +259,5 @@
 
     my $uri = new URI;
-    $uri->path('/mt-atom.cgi/weblog/blog_id=1');
+    $uri->path($base_uri . '/blog_id=1');
     my $req = new HTTP::Request(POST => $uri);
     $req->header('Authorization' => 'Atom');
@@ -177,12 +266,5 @@
 		 . "Created=\"$timestamp\"");
 
-    $req->content(<<XML);
-<?xml version="1.0" encoding="utf-8"?>
-    <entry xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
-    <title>Fight the Power</title>
-    <content>Elvis was a hero to most but he never meant shit to me</content>
-    <issued>2004-08-06T00:43:34+01:00</issued>
-    </entry>
-XML
+    $req->content($test_data{$base_uri});
 
     my $resp = $ua->simple_request($req);
@@ -209,5 +291,4 @@
 
     ok($entry_id);
-    require XML::Atom;
     my $atom_obj = XML::Atom::Entry->new(\$resp->content());
     require Date::Parse;
@@ -220,14 +301,13 @@
     my $wsse_header = make_wsse($chuck_token);
     my $uri = new URI;
-    $uri->path("/mt-atom.cgi/weblog/blog_id=1/entry_id=$entry_id");
+    $uri->path($base_uri . "/blog_id=1/entry_id=$entry_id");
     my $req = new HTTP::Request(GET => $uri);
     $req->header('Authorization' => 'Atom');
     $req->header('X-WSSE' => $wsse_header);
 
-    print "# X-WSSSE: $wsse_header\n";
+    print "# X-WSSE: $wsse_header\n";
 
     my $resp = $ua->request($req);
 
-    require XML::LibXML;
     my $atom_entry = XML::Atom::Entry->new(Stream => \$resp->content());
 
@@ -239,5 +319,5 @@
     $wsse_header = make_wsse($chuck_token);
     $uri = new URI;
-    $uri->path("/mt-atom.cgi/weblog/blog_id=1/entry_id=$entry_id");
+    $uri->path($base_uri . "/blog_id=1/entry_id=$entry_id");
     $req = new HTTP::Request(PUT => $uri);
     $req->header('Authorization' => 'Atom');
@@ -260,4 +340,7 @@
 }
 
+} #end foreach
+
+
 END {
     #my $melody = MT::Author->load({ name => $username });
