Skip to content

Commit

Permalink
add tests for tick() with no value
Browse files Browse the repository at this point in the history
  • Loading branch information
simbabque committed Jul 4, 2022
1 parent 032dd6e commit efb47de
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Revision history for WWW::Mechanize

{{$NEXT}}
[FIXED]
- tick() can now handle checkboxes without a value (GH#331) (Jordan M Adler
and Julien Fiegehenn)

[DOCUMENTATION]
- Explain that file URIs need url encoding (GH#329) (Julien Fiegehenn and
Expand Down
5 changes: 5 additions & 0 deletions lib/WWW/Mechanize.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,11 @@ as the third optional argument will cause the checkbox to be unticked.
The third value does not need to be set if you wish to merely tick the
box.
$mech->tick('extra', 'cheese');
$mech->tick('extra', 'mushrooms');
$mech->tick('no_value', ''); # <input type="checkbox" name="no_value">
=cut

sub tick {
Expand Down
5 changes: 4 additions & 1 deletion t/tick.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

<input type="checkbox" name="foo" value="hello" /> Hello<br />
<input type="checkbox" name="foo" value="bye" /> Bye<br />
<input type="checkbox" name="foo" value="arse" /> Arse<br />
<input type="checkbox" name="foo" value="parse" /> Parse<br />
<input type="checkbox" name="foo" value="wibble" /> Wibble<br />
<input type="checkbox" name="foo" value="foo" /> Foo<br />
<label>
<input type="checkbox" name="no_value" /> I have no value
</label>

<input type="Submit" name="submit" value="Submit" label="Submit" />
</form>
Expand Down
6 changes: 4 additions & 2 deletions t/tick.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ $mech->tick('foo','hello');
$mech->tick('foo','bye');
$mech->untick('foo','hello');

$mech->tick('no_value', '');

my $form = $mech->form_number(1);
isa_ok( $form, 'HTML::Form' );

my $reqstring = $form->click->as_string;

my $wanted = <<'EOT';
POST http://localhost/
Content-Length: 21
Content-Length: 31
Content-Type: application/x-www-form-urlencoded
foo=bye&submit=Submit
foo=bye&no_value=&submit=Submit
EOT

is( $reqstring, $wanted, 'Proper posting' );
Expand Down

0 comments on commit efb47de

Please sign in to comment.