Procházet zdrojové kódy

Merge pull request #381 from Troglodyne-Internet-Widgets/embed-posts

Embed a post again, by calling posts() with the arguments that it takes
George S. Baugh před 3 dny
rodič
revize
bdf74b3d8d
2 změnil soubory, kde provedl 25 přidání a 1 odebrání
  1. 0 1
      lib/Trog/Renderer/html.pm
  2. 25 0
      t/Trog-Routes-HTML-series-lifecycle.t

+ 0 - 1
lib/Trog/Renderer/html.pm

@@ -28,7 +28,6 @@ sub render (%options) {
                 return Text::Xslate::mark_raw(
                     Trog::Routes::HTML::posts(
                         { route => "/post/$this_id", style => $style },
-                        sub { },
                         1
                     )
                 );

+ 25 - 0
t/Trog-Routes-HTML-series-lifecycle.t

@@ -1114,6 +1114,31 @@ subtest 'blog' => sub {
     unlike( $body, qr/Spec[ ]Payee[ ]Entity/, 'no bleed from the entities series' );
 };
 
+subtest 'a post that embeds another' => sub {
+    my $embedded = find_post('Spec Blog Child') or return fail('the blog child is there to embed');
+    my $host     = save_post(
+        'embedding post',
+        form       => 'blog.tx',
+        title      => 'Spec Embedding Post',
+        data       => "Before the embed. <: embed('$embedded->{id}') :> After the embed.",
+        visibility => 'public',
+        tags       => ['specblog'],
+        to         => '/specblog',
+    ) or return;
+
+    my @warned;
+    local $SIG{__WARN__} = sub { push @warned, @_ };
+    my ( $code, $page, $err ) = render( anon( route => "/posts/$host->{id}", id => $host->{id} ), \&Trog::Routes::HTML::posts );
+    is( $code, 200, 'the post renders' ) or return diag($err);
+
+    my ($data) = $page =~ m{id="postData-\Q$host->{id}\E">(.*?)After[ ]the[ ]embed}s;
+    ok( defined $data, 'with its own body' ) or return;
+    like( $data, qr/Spec[ ]blog[ ]body[ ]text[.]/, 'and the body of the post it embeds, in place' );
+    my $embeds = () = $data =~ m/class="post[ ]embed"/g;
+    is( $embeds,         1, 'in the embed style, and only that one post' );
+    is( scalar(@warned), 0, 'without a warning' ) or diag( explain( \@warned ) );
+};
+
 subtest 'microblog' => sub {
     my $title = 'Spec Microblog Series';
     make_series( qw{microblog specmicroblog microblog.tx}, $title ) or return;