tests for issues with void elements.
Simon Elliott [Thu, 9 Jun 2011 14:20:37 +0000 (15:20 +0100)]
t/bugs/form_helpers.t [new file with mode: 0644]

diff --git a/t/bugs/form_helpers.t b/t/bugs/form_helpers.t
new file mode 100644 (file)
index 0000000..5b674c1
--- /dev/null
@@ -0,0 +1,53 @@
+use strictures 1;
+use Test::More;
+
+use HTML::Zoom;
+
+my $tmpl =<<END;
+<body>
+  <form name="main">
+    <label for="input_field">Input</label>
+    <input data-validate="required" type="text" name="input_field" />
+    <label for="input_field2">Input 2</label>
+    <input data-validate="required" value="gorch" type="text" name="input_field2" />
+
+    <label for="input_check">Checkbox</label>
+    <input data-validate="required" value="0" type="checkbox" name="input_check" />
+
+    <label for="select_field">Select</label>
+    <select data-validate="required" name="select_field">
+      <option value="1">foo</option>
+      <option value="2">bar</option>
+      <option value="3" selected="selected">oof</option>
+      <option value="4">rab</option>
+    </select>
+  </form>
+</body>
+END
+
+my $z = HTML::Zoom->from_html($tmpl);
+
+my @fields;
+$z->select('input')->collect({ 
+    into => \@fields,
+    passthrough => 1,
+})->memoize;
+is(scalar @fields,2,"correctly extracted all inputs");
+
+my $expect;
+
+($expect = $tmpl) =~ s#name="input_field" />#name="input_field" /><div>cluck</div>#;
+
+is(
+  $z->select('input[name="input_field"]')
+  ->add_after(\"<div>cluck</div>")
+  ->to_html, $expect,
+"added after void");
+
+($expect = $tmpl) =~ s#Input</label>#Input</label><div>cluck</div>#;
+
+is(
+  $z->select('input[name="input_field"]')
+  ->add_before(\"<div>cluck</div>")
+  ->to_html, $expect,
+"added before void");