Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Test-WWW-Mechanize CPAN distribution.

Report information
The Basics
Id: 29843
Status: resolved
Priority: 0/
Queue: Test-WWW-Mechanize

People
Owner: Nobody in particular
Requestors: greg.sheard [...] wcn.co.uk
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: New method wrapper
Date: Mon, 08 Oct 2007 17:02:39 +0100
To: bug-Test-WWW-Mechanize [...] rt.cpan.org
From: Greg Sheard <greg.sheard [...] wcn.co.uk>
Inspired by get_ok(), this is its counterpart, post_ok(). Patch attached against 1.14. -- Greg Sheard <greg.sheard@wcn.co.uk> Not speaking for WCN plc in any way. #include "long_disclaimer.h"
--- Mechanize.pm.orig 2007-10-08 16:31:10.000000000 +0100 +++ Mechanize.pm 2007-10-08 16:31:35.000000000 +0100 @@ -124,6 +124,51 @@ return $ok; } +=head2 $mech->post_ok($url, [ \%LWP_options ,] $desc) + +A wrapper around WWW::Mechanize's post(), with similar options, except +the second argument needs to be a hash reference, not a hash. Like +well-behaved C<*_ok()> functions, it returns true if the test passed, +or false if not. + +=cut +sub post_ok { + my $self = shift; + my $url = shift; + + my $desc; + my %opts; + + if ( @_ ) { + my $flex = shift; # The flexible argument + + if ( !defined( $flex ) ) { + $desc = shift; + } + elsif ( ref $flex eq 'HASH' ) { + %opts = %$flex; + $desc = shift; + } + elsif ( ref $flex eq 'ARRAY' ) { + %opts = @$flex; + $desc = shift; + } + else { + $desc = $flex; + } + } # parms left + + $self->post( $url, \%opts ); + my $ok = $self->success; + $Test->ok( $ok, $desc ); + if ( !$ok ) { + $Test->diag( $self->status ); + $Test->diag( $self->response->message ) if $self->response; + } + + return $ok; +} + =head2 $mech->title_is( $str [, $desc ] ) Tells if the title of the page is the given string.
I'm adding this to the next version. Tests would be nice, too. Please don't respond here. This queue is dead, moving over to: http://code.google.com/p/www-mechanize/issues/list