Permalink
Browse files

Include the related images in Atom entry responses

  • Loading branch information...
1 parent f29c350 commit 6d8709f0da2e1c6e6da91f6cca322c52717370d2 @markpasc markpasc committed Jun 1, 2011
Showing with 22 additions and 2 deletions.
  1. +15 −1 lib/AtomPub/Server/Weblog.pm
  2. +7 −1 t/15-image.t
@@ -43,7 +43,21 @@ sub new_with_entry {
my $mo = AtomPub::Atom::Entry::_create_issued($entry->modified_on, $entry->blog);
$atom->set(NS_APP(), 'edited', $mo);
- $atom;
+ my $objectasset_iter = MT::ObjectAsset->load_iter({
+ blog_id => $entry->blog_id,
+ object_ds => 'entry',
+ object_id => $entry->id,
+ });
+ while (my $objectasset = $objectasset_iter->()) {
+ $atom->add_link({
+ rel => 'related',
+ type => $app->atom_content_type,
+ href => join(q{}, $app->base, $app->uri, '/blog_id=', $entry->blog_id, '/asset_id=',
+ $objectasset->asset_id),
+ });
+ }
+
+ return $atom;
}
sub new_with_asset {
View
@@ -8,7 +8,7 @@ BEGIN {
}
use MT::Test qw( :app :db :data );
-use Test::More tests => 18;
+use Test::More tests => 20;
use AtomPub::Test qw( basic_auth run_app );
use File::Spec;
@@ -116,6 +116,12 @@ EOF
object_ds => 'entry',
});
ok($oa, "Creating a new post that linked to a created asset associated them");
+
+ my @related = $xpath->findnodes('./atom:link[@rel="related"]', $root);
+ is(scalar @related, 1, "Entry has one related link");
+ my ($related) = @related;
+ is($related->getAttribute('href'), 'http://www.example.com/plugins/AtomPub/mt-atom.cgi/1.0/blog_id=1/asset_id=4',
+ "Entry's related link is uploaded image's AtomPub URI");
}

0 comments on commit 6d8709f

Please sign in to comment.