added test for transform_content using repeatables transform_content
Andreas 'ac0v' Specht [Wed, 29 Jun 2011 15:50:55 +0000 (17:50 +0200)]
t/actions.t

index b019db4..8166d8b 100644 (file)
@@ -172,6 +172,36 @@ is(
   'transform_content works for one specific selected element',
   );
 
+$expect = do {
+    # done in a new context to keep test namespace clean
+    my $copy_of_tmpl = $tmpl;
+    my $repeatable = +( $copy_of_tmpl =~ m{(<div\sclass="main".+?</div>)}xms )[0];
+    my $repeated = join q{}, map {
+        # don't modify the original one
+        my $item = $repeatable;
+        $item =~ s{(<span[^>]+>)}{$1$_. }xmsg;
+        $item
+    } 1 .. 2;
+    $copy_of_tmpl =~ s{<div.+?</div>}{$repeated}xms;
+    $copy_of_tmpl;
+};
+
+is(
+  ( run_for {
+      $_->repeat([
+        sub {
+          $_->select('span')->transform_content( sub { "1. $_" } );
+        },
+        sub {
+          $_->select('span')->transform_content( sub { "2. $_" } );
+        },
+      ]);
+    } 'div.main'
+  ),
+  $expect,
+  'check if transform_content works for repeatables',
+  );
+
 ($expect = $tmpl) =~ s/(?=<div)/O HAI/;
 
 my $ohai = [ { type => 'TEXT', raw => 'O HAI' } ];