Added failing tests
Oliver Charles [Sun, 21 Mar 2010 18:18:55 +0000 (18:18 +0000)]
t/todo-forms.t [new file with mode: 0644]
t/todo-repeat.t [new file with mode: 0644]
t/todo-span.t [new file with mode: 0644]

diff --git a/t/todo-forms.t b/t/todo-forms.t
new file mode 100644 (file)
index 0000000..29cb575
--- /dev/null
@@ -0,0 +1,32 @@
+use HTML::Zoom;
+use Test::More;
+
+my $zoom = HTML::Zoom->from_html(<<HTML);
+<form class="myform" action="/somewhere">
+<label />
+<input />
+</form>
+HTML
+
+my @fields = (
+    { id => "foo", label => "foo", name => "foo", type => "text", value => 0 },
+    { id => "bar", label => "bar", name => "bar", type => "radio", value => 1 },
+);
+
+my $h = $zoom->select('.myform')->repeat_content([
+    map { my $field = $_; sub {
+              $_->select('label')
+               ->add_attribute( for => $field->{id} )
+               ->then
+               ->replace_content( $field->{label} )
+               ->select('input')
+               ->add_attribute( name => $field->{name} )
+               ->then
+               ->add_attribute( type => $field->{type} )
+               ->then
+               ->add_attribute( value => $field->{value} )
+           } } @fields
+       ])->to_html;
+
+ok 1;
+done_testing;
diff --git a/t/todo-repeat.t b/t/todo-repeat.t
new file mode 100644 (file)
index 0000000..ca83f5e
--- /dev/null
@@ -0,0 +1,23 @@
+use strict;
+use HTML::Zoom;
+use Test::More;
+
+my $z = HTML::Zoom->from_html(<<HTML);
+<html>
+<body>
+<div id="foo"><p/></div>
+</body>
+</html>
+HTML
+
+my @list = qw(foo bar baz);
+my $iter = sub { shift @list };
+
+$z->select("#foo")->repeat(sub {
+    my $e = $iter->() or return;
+    return sub { $_->select("p")->replace_content($e) };
+})->to_html;
+
+ok 1;
+
+done_testing;
diff --git a/t/todo-span.t b/t/todo-span.t
new file mode 100644 (file)
index 0000000..af164c0
--- /dev/null
@@ -0,0 +1,6 @@
+use HTML::Zoom;
+use Test::More tests => 1;
+
+my $zoom = HTML::Zoom->from_html('<p>Hello my name is <span id="name" /></p>');
+my $html = $zoom->select('#name')->replace_content('Foo foo')->to_html;
+is($html, '<p>Hello my name is <span id="#name">Foo foo</span>');