Changeset 1946
- Timestamp:
- 04/17/08 02:37:16 (15 months ago)
- Files:
-
- 1 modified
-
branches/release-35/t/41-atom.t (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/release-35/t/41-atom.t
r1098 r1946 1 1 use strict; 2 use lib 't/lib', 'extlib', 'lib', '../lib', '../extlib'; 2 3 use POSIX; 3 4 4 use Test::More tests => 11; 5 use MT; 6 use MT::Atom; 7 use XML::LibXML; # this test would not work without it 8 use XML::XPath; 9 use XML::Atom; 10 use XML::Atom::Feed; 11 use XML::Atom::Entry; 12 13 use Test::More tests => 37; 5 14 6 15 # To keep away from being under FastCGI 7 16 $ENV{HTTP_HOST} = 'localhost'; 8 9 use MT::Atom;10 11 use MT;12 17 13 18 use vars qw( $DB_DIR $T_CFG ); … … 15 20 isa_ok($mt, 'MT'); 16 21 17 use lib 't/lib', 'extlib', 'lib', '../lib', '../extlib';18 22 use MT::Test qw(:db :data); 23 24 my %test_data; 25 $test_data{'/mt-atom.cgi/weblog'} = <<XML1; 26 <?xml version="1.0" encoding="utf-8"?> 27 <entry xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/"> 28 <title>Fight the Power</title> 29 <content>Elvis was a hero to most but he never meant shit to me</content> 30 <issued>2004-08-06T00:43:34+01:00</issued> 31 </entry> 32 XML1 33 $test_data{'/mt-atom.cgi/1.0'} = <<XML2; 34 <?xml version="1.0" encoding="utf-8"?> 35 <entry xmlns="http://www.w3.org/2005/Atom"> 36 <title>Fight the Power</title> 37 <content type="html">Elvis was a hero to most but he never meant shit to me</content> 38 <published>2004-08-06T00:43:34+01:00</published> 39 </entry> 40 XML2 41 42 my %feed_link = ( 43 '/mt-atom.cgi/weblog' => sub { 44 my ($resp) = @_; 45 my $feed = XML::Atom::Feed->new(\$resp->content()); 46 ok($feed, 'got feed'); 47 my ($sfeed) = grep { 48 $_->rel eq 'service.feed' 49 } $feed->links; 50 $sfeed->href; 51 }, 52 '/mt-atom.cgi/1.0' => sub { 53 my ($resp) = @_; 54 my $feed = XML::XPath->new(xml => $resp->content()); 55 ok($feed, 'got feed'); 56 my $col = $feed->getNodeText('/service/workspace[1]/collection/@href'); 57 $col; 58 } 59 ); 19 60 20 61 my $username = 'Chuck D'; … … 43 84 my $ua = new LWP::UserAgent::Local({ ScriptAlias => '/' }); 44 85 86 foreach my $base_uri ( qw{/mt-atom.cgi/weblog /mt-atom.cgi/1.0 } ) { 45 87 { 46 88 # # # # First try a req with baloney auth, make sure it fails … … 50 92 51 93 my $uri = new URI(); 52 $uri->path( '/mt-atom.cgi/weblog/blog_id=1');94 $uri->path($base_uri . '/blog_id=1'); 53 95 my $req = new HTTP::Request(GET => $uri); 54 96 $req->header(Authentication => 'Atom'); … … 62 104 } 63 105 106 # test blog lists 107 { 108 my $wsse_header = make_wsse($chuck_token); 109 my $uri = new URI; 110 $uri->path($base_uri); 111 my $req = new HTTP::Request(GET => $uri); 112 $req->header('Authorization' => 'Atom'); 113 $req->header('X-WSSE' => $wsse_header); 114 115 print "# X-WSSE: $wsse_header\n"; 116 117 my $resp = $ua->request($req); 118 if (ok($resp->is_success)) { 119 my $blog_feed_url = $feed_link{$base_uri}->($resp); 120 my $uri = new URI($blog_feed_url); 121 is($uri->path, $base_uri . '/blog_id=1', 'blog feed url is correct'); 122 } 123 else { 124 die 'failed to retrieve blog feed'; 125 } 126 } 127 128 # test blog feed 129 { 130 my $wsse_header = make_wsse($chuck_token); 131 my $uri = new URI; 132 $uri->path($base_uri . "/blog_id=1"); 133 my $req = new HTTP::Request(GET => $uri); 134 $req->header('Authorization' => 'Atom'); 135 $req->header('X-WSSE' => $wsse_header); 136 137 print "# X-WSSE: $wsse_header\n"; 138 139 my $resp = $ua->request($req); 140 if (ok($resp->is_success)) { 141 my $feed = XML::Atom::Feed->new(\$resp->content()); 142 ok($feed, 'got feed'); 143 is($feed->title, 'none'); 144 my ($alternate) = grep { 145 $_->rel eq 'alternate' && $_->type eq 'text/html' 146 } $feed->links; 147 is($alternate->href, 'http://narnia.na/nana/', 'blog url is correct'); 148 my $entry_count = MT::Entry->count( 149 { blog_id => 1 }, 150 { limit => 21 }, 151 ); 152 my @entries = $feed->entries; 153 is($entry_count, scalar(@entries), 'number of entries is correct'); 154 } 155 else { 156 die 'failed to retrieve blog feed'; 157 } 158 } 64 159 65 160 my $entry_id; … … 78 173 79 174 my $uri = new URI; 80 $uri->path( '/mt-atom.cgi/weblog/blog_id=1');175 $uri->path($base_uri . '/blog_id=1'); 81 176 my $req = new HTTP::Request(POST => $uri); 82 177 … … 110 205 111 206 $uri = new URI; 112 $uri->path( '/mt-atom.cgi/weblog/blog_id=1');207 $uri->path($base_uri . '/blog_id=1'); 113 208 $req = new HTTP::Request(POST => $uri); 114 209 … … 116 211 print "# sending: ", $req->header('X-Atom-Authorization'); 117 212 118 $req->content(<<XML); 119 <?xml version="1.0" encoding="utf-8"?> 120 <entry xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/"> 121 <title>Fight the Power</title> 122 <content>Elvis was a hero to most but he never meant shit to me</content> 123 </entry> 124 XML 213 $req->content($test_data{$base_uri}); 125 214 126 215 $resp = $ua->simple_request($req); … … 170 259 171 260 my $uri = new URI; 172 $uri->path( '/mt-atom.cgi/weblog/blog_id=1');261 $uri->path($base_uri . '/blog_id=1'); 173 262 my $req = new HTTP::Request(POST => $uri); 174 263 $req->header('Authorization' => 'Atom'); … … 177 266 . "Created=\"$timestamp\""); 178 267 179 $req->content(<<XML); 180 <?xml version="1.0" encoding="utf-8"?> 181 <entry xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/"> 182 <title>Fight the Power</title> 183 <content>Elvis was a hero to most but he never meant shit to me</content> 184 <issued>2004-08-06T00:43:34+01:00</issued> 185 </entry> 186 XML 268 $req->content($test_data{$base_uri}); 187 269 188 270 my $resp = $ua->simple_request($req); … … 209 291 210 292 ok($entry_id); 211 require XML::Atom;212 293 my $atom_obj = XML::Atom::Entry->new(\$resp->content()); 213 294 require Date::Parse; … … 220 301 my $wsse_header = make_wsse($chuck_token); 221 302 my $uri = new URI; 222 $uri->path( "/mt-atom.cgi/weblog/blog_id=1/entry_id=$entry_id");303 $uri->path($base_uri . "/blog_id=1/entry_id=$entry_id"); 223 304 my $req = new HTTP::Request(GET => $uri); 224 305 $req->header('Authorization' => 'Atom'); 225 306 $req->header('X-WSSE' => $wsse_header); 226 307 227 print "# X-WSS SE: $wsse_header\n";308 print "# X-WSSE: $wsse_header\n"; 228 309 229 310 my $resp = $ua->request($req); 230 311 231 require XML::LibXML;232 312 my $atom_entry = XML::Atom::Entry->new(Stream => \$resp->content()); 233 313 … … 239 319 $wsse_header = make_wsse($chuck_token); 240 320 $uri = new URI; 241 $uri->path( "/mt-atom.cgi/weblog/blog_id=1/entry_id=$entry_id");321 $uri->path($base_uri . "/blog_id=1/entry_id=$entry_id"); 242 322 $req = new HTTP::Request(PUT => $uri); 243 323 $req->header('Authorization' => 'Atom'); … … 260 340 } 261 341 342 } #end foreach 343 344 262 345 END { 263 346 #my $melody = MT::Author->load({ name => $username });
