Test-WWW-Mechanize-PSGI-0.35/0000755000175000017500000000000011321120340014062 5ustar acmeacmeTest-WWW-Mechanize-PSGI-0.35/META.yml0000644000175000017500000000122511321120340015333 0ustar acmeacme--- #YAML:1.0 name: Test-WWW-Mechanize-PSGI version: 0.35 abstract: Test PSGI programs using WWW::Mechanize author: - Leon Brocard license: perl distribution_type: module configure_requires: ExtUtils::MakeMaker: 0 build_requires: ExtUtils::MakeMaker: 0 requires: HTTP::Message::PSGI: 0 Test::More: 0 Test::WWW::Mechanize: 0 Try::Tiny: 0 no_index: directory: - t - inc generated_by: ExtUtils::MakeMaker version 6.55_02 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 Test-WWW-Mechanize-PSGI-0.35/README0000644000175000017500000003020711311645507014764 0ustar acmeacmeNAME Test::WWW::Mechanize::PSGI - Test PSGI programs using WWW::Mechanize SYNOPSIS # We're in a t/*.t test script... use Test::WWW::Mechanize::PSGI; my $mech = Test::WWW::Mechanize::PSGI->new( app => sub { my $env = shift; return [ 200, [ 'Content-Type' => 'text/html' ], [ 'HiHello World' ] ]; }, ); $mech->get_ok('/'); is( $mech->ct, 'text/html', 'Is text/html' ); $mech->title_is('Hi'); $mech->content_contains('Hello World'); # ... and all other Test::WWW::Mechanize methods DESCRIPTION PSGI is a specification to decouple web server environments from web application framework code. Test::WWW::Mechanize is a subclass of WWW::Mechanize that incorporates features for web application testing. The Test::WWW::Mechanize::PSGI module meshes the two to allow easy testing of PSGI applications. Testing web applications has always been a bit tricky, normally requiring starting a web server for your application and making real HTTP requests to it. This module allows you to test PSGI web applications but does not require a server or issue HTTP requests. Instead, it passes the HTTP request object directly to PSGI. Thus you do not need to use a real hostname: "http://localhost/" will do. However, this is optional. The following two lines of code do exactly the same thing: $mech->get_ok('/action'); $mech->get_ok('http://localhost/action'); This makes testing fast and easy. Test::WWW::Mechanize provides functions for common web testing scenarios. For example: $mech->get_ok( $page ); $mech->title_is( "Invoice Status", "Make sure we're on the invoice page" ); $mech->content_contains( "Andy Lester", "My name somewhere" ); $mech->content_like( qr/(cpan|perl)\.org/, "Link to perl.org or CPAN" ); An alternative to this module is Plack::Test. CONSTRUCTOR new Behaves like, and calls, WWW::Mechanize's "new" method. You should pass in your application: my $mech = Test::WWW::Mechanize::PSGI->new( app => sub { my $env = shift; return [ 200, [ 'Content-Type' => 'text/plain' ], ['Hello World'] ],; }, ); METHODS: HTTP VERBS $mech->get_ok($url, [ \%LWP_options ,] $desc) A wrapper around WWW::Mechanize's get(), with similar options, except the second argument needs to be a hash reference, not a hash. Like well-behaved "*_ok()" functions, it returns true if the test passed, or false if not. A default description of "GET $url" is used if none if provided. $mech->head_ok($url, [ \%LWP_options ,] $desc) A wrapper around WWW::Mechanize's head(), with similar options, except the second argument needs to be a hash reference, not a hash. Like well-behaved "*_ok()" functions, it returns true if the test passed, or false if not. A default description of "HEAD $url" is used if none if provided. $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 "*_ok()" functions, it returns true if the test passed, or false if not. A default description of "POST to $url" is used if none if provided. $mech->put_ok( $url, [ \%LWP_options ,] $desc ) A wrapper around WWW::Mechanize's put(), with similar options, except the second argument needs to be a hash reference, not a hash. Like well-behaved "*_ok()" functions, it returns true if the test passed, or false if not. A default description of "PUT to $url" is used if none if provided. $mech->submit_form_ok( \%parms [, $desc] ) Makes a "submit_form()" call and executes tests on the results. The form must be found, and then submitted successfully. Otherwise, this test fails. *%parms* is a hashref containing the parms to pass to "submit_form()". Note that the parms to "submit_form()" are a hash whereas the parms to this function are a hashref. You have to call this function like: $agent->submit_form_ok( {n=>3}, "looking for 3rd link" ); As with other test functions, $desc is optional. If it is supplied then it will display when running the test harness in verbose mode. Returns true value if the specified link was found and followed successfully. The HTTP::Response object returned by submit_form() is not available. $mech->follow_link_ok( \%parms [, $desc] ) Makes a "follow_link()" call and executes tests on the results. The link must be found, and then followed successfully. Otherwise, this test fails. *%parms* is a hashref containing the parms to pass to "follow_link()". Note that the parms to "follow_link()" are a hash whereas the parms to this function are a hashref. You have to call this function like: $mech->follow_link_ok( {n=>3}, "looking for 3rd link" ); As with other test functions, $desc is optional. If it is supplied then it will display when running the test harness in verbose mode. Returns a true value if the specified link was found and followed successfully. The HTTP::Response object returned by follow_link() is not available. click_ok( $button[, $desc] ) Clicks the button named by $button. An optional $desc can be given for the test. METHODS: CONTENT CHECKING $mech->html_lint_ok( [$desc] ) Checks the validity of the HTML on the current page. If the page is not HTML, then it fails. The URI is automatically appended to the *$desc*. Note that HTML::Lint must be installed for this to work. Otherwise, it will blow up. $mech->title_is( $str [, $desc ] ) Tells if the title of the page is the given string. $mech->title_is( "Invoice Summary" ); $mech->title_like( $regex [, $desc ] ) Tells if the title of the page matches the given regex. $mech->title_like( qr/Invoices for (.+)/ $mech->title_unlike( $regex [, $desc ] ) Tells if the title of the page matches the given regex. $mech->title_unlike( qr/Invoices for (.+)/ $mech->base_is( $str [, $desc ] ) Tells if the base of the page is the given string. $mech->base_is( "http://example.com/" ); $mech->base_like( $regex [, $desc ] ) Tells if the base of the page matches the given regex. $mech->base_like( qr{http://example.com/index.php?PHPSESSID=(.+)}); $mech->base_unlike( $regex [, $desc ] ) Tells if the base of the page matches the given regex. $mech->base_unlike( qr{http://example.com/index.php?PHPSESSID=(.+)}); $mech->content_is( $str [, $desc ] ) Tells if the content of the page matches the given string $mech->content_contains( $str [, $desc ] ) Tells if the content of the page contains *$str*. $mech->content_lacks( $str [, $desc ] ) Tells if the content of the page lacks *$str*. $mech->content_like( $regex [, $desc ] ) Tells if the content of the page matches *$regex*. $mech->content_unlike( $regex [, $desc ] ) Tells if the content of the page does NOT match *$regex*. $mech->has_tag( $tag, $text [, $desc ] ) Tells if the page has a $tag tag with the given content in its text. $mech->has_tag_like( $tag, $regex [, $desc ] ) Tells if the page has a $tag tag with the given content in its text. $mech->followable_links() Returns a list of links that Mech can follow. This is only http and https links. $mech->page_links_ok( [ $desc ] ) Follow all links on the current page and test for HTTP status 200 $mech->page_links_ok('Check all links'); $mech->page_links_content_like( $regex [, $desc ] ) Follow all links on the current page and test their contents for *$regex*. $mech->page_links_content_like( qr/foo/, 'Check all links contain "foo"' ); $mech->links_ok( $links [, $desc ] ) Follow specified links on the current page and test for HTTP status 200. The links may be specified as a reference to an array containing WWW::Mechanize::Link objects, an array of URLs, or a scalar URL name. my @links = $mech->find_all_links( url_regex => qr/cnn\.com$/ ); $mech->links_ok( \@links, 'Check all links for cnn.com' ); my @links = qw( index.html search.html about.html ); $mech->links_ok( \@links, 'Check main links' ); $mech->links_ok( 'index.html', 'Check link to index' ); $mech->link_status_is( $links, $status [, $desc ] ) Follow specified links on the current page and test for HTTP status passed. The links may be specified as a reference to an array containing WWW::Mechanize::Link objects, an array of URLs, or a scalar URL name. my @links = $mech->followable_links(); $mech->link_status_is( \@links, 403, 'Check all links are restricted' ); $mech->link_status_isnt( $links, $status [, $desc ] ) Follow specified links on the current page and test for HTTP status passed. The links may be specified as a reference to an array containing WWW::Mechanize::Link objects, an array of URLs, or a scalar URL name. my @links = $mech->followable_links(); $mech->link_status_isnt( \@links, 404, 'Check all links are not 404' ); $mech->link_content_like( $links, $regex [, $desc ] ) Follow specified links on the current page and test the resulting content of each against *$regex*. The links may be specified as a reference to an array containing WWW::Mechanize::Link objects, an array of URLs, or a scalar URL name. my @links = $mech->followable_links(); $mech->link_content_like( \@links, qr/Restricted/, 'Check all links are restricted' ); $mech->link_content_unlike( $links, $regex [, $desc ] ) Follow specified links on the current page and test that the resulting content of each does not match *$regex*. The links may be specified as a reference to an array containing WWW::Mechanize::Link objects, an array of URLs, or a scalar URL name. my @links = $mech->followable_links(); $mech->link_content_unlike( \@links, qr/Restricted/, 'No restricted links' ); $mech->stuff_inputs( [\%options] ) Finds all free-text input fields (text, textarea, and password) in the current form and fills them to their maximum length in hopes of finding application code that can't handle it. Fields with no maximum length and all textarea fields are set to 66000 bytes, which will often be enough to overflow the data's eventual recepticle. There is no return value. If there is no current form then nothing is done. The hashref $options can contain the following keys: * ignore hash value is arrayref of field names to not touch, e.g.: $mech->stuff_inputs( { ignore => [qw( specialfield1 specialfield2 )], } ); * fill hash value is default string to use when stuffing fields. Copies of the string are repeated up to the max length of each field. E.g.: $mech->stuff_inputs( { fill => '@' # stuff all fields with something easy to recognize } ); * specs hash value is arrayref of hashrefs with which you can pass detailed instructions about how to stuff a given field. E.g.: $mech->stuff_inputs( { specs=>{ # Some fields are datatype-constrained. It's most common to # want the field stuffed with valid data. widget_quantity => { fill=>'9' }, notes => { maxlength=>2000 }, } } ); The specs allowed are *fill* (use this fill for the field rather than the default) and *maxlength* (use this as the field's maxlength instead of any maxlength specified in the HTML). AUTHOR Leon Brocard . COPYRIGHT Copyright (C) 2009, Leon Brocard LICENSE This module is free software; you can redistribute it or modify it under the same terms as Perl itself. Test-WWW-Mechanize-PSGI-0.35/Makefile.PL0000644000175000017500000000077611311632155016061 0ustar acmeacme#!perl use strict; use warnings; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Test::WWW::Mechanize::PSGI', VERSION_FROM => 'lib/Test/WWW/Mechanize/PSGI.pm', ABSTRACT => 'Test PSGI programs using WWW::Mechanize', AUTHOR => 'Leon Brocard ', LICENSE => 'perl', PREREQ_PM => { 'HTTP::Message::PSGI' => '0', 'Test::More' => '0', 'Test::WWW::Mechanize' => '0', 'Try::Tiny' => '0', } ); Test-WWW-Mechanize-PSGI-0.35/lib/0000755000175000017500000000000011321120340014630 5ustar acmeacmeTest-WWW-Mechanize-PSGI-0.35/lib/Test/0000755000175000017500000000000011321120340015547 5ustar acmeacmeTest-WWW-Mechanize-PSGI-0.35/lib/Test/WWW/0000755000175000017500000000000011321120340016233 5ustar acmeacmeTest-WWW-Mechanize-PSGI-0.35/lib/Test/WWW/Mechanize/0000755000175000017500000000000011321120312020135 5ustar acmeacmeTest-WWW-Mechanize-PSGI-0.35/lib/Test/WWW/Mechanize/PSGI.pm0000644000175000017500000003167111321120312021245 0ustar acmeacmepackage Test::WWW::Mechanize::PSGI; use strict; use warnings; use Carp; use HTTP::Message::PSGI; use Test::WWW::Mechanize; use Try::Tiny; use base 'Test::WWW::Mechanize'; our $VERSION = '0.35'; my $Test = Test::Builder->new(); sub new { my $class = shift; my %args = @_; # Dont let LWP complain about options for our attributes my $app = $args{app}; delete $args{app}; confess('Missing argument app') unless $app; confess('Argument app should be a code reference') unless ref($app) && ref($app) eq 'CODE'; my $self = $class->SUPER::new(%args); $self->{app} = $app; return $self; } sub simple_request { my ( $self, $request ) = @_; my $uri = $request->uri; $uri->scheme('http') unless defined $uri->scheme; $uri->host('localhost') unless defined $uri->host; my $env = $self->prepare_request($request)->to_psgi; my $response; try { $response = HTTP::Response->from_psgi( $self->{app}->($env) ); } catch { $Test->diag("PSGI error: $_"); $response = HTTP::Response->new(500); $response->content($_); $response->content_type(''); }; $response->request($request); $self->run_handlers( "response_done", $response ); return $response; } 1; __END__ =head1 NAME Test::WWW::Mechanize::PSGI - Test PSGI programs using WWW::Mechanize =head1 SYNOPSIS # We're in a t/*.t test script... use Test::WWW::Mechanize::PSGI; my $mech = Test::WWW::Mechanize::PSGI->new( app => sub { my $env = shift; return [ 200, [ 'Content-Type' => 'text/html' ], [ 'HiHello World' ] ]; }, ); $mech->get_ok('/'); is( $mech->ct, 'text/html', 'Is text/html' ); $mech->title_is('Hi'); $mech->content_contains('Hello World'); # ... and all other Test::WWW::Mechanize methods =head1 DESCRIPTION L is a specification to decouple web server environments from web application framework code. L is a subclass of L that incorporates features for web application testing. The L module meshes the two to allow easy testing of L applications. Testing web applications has always been a bit tricky, normally requiring starting a web server for your application and making real HTTP requests to it. This module allows you to test L web applications but does not require a server or issue HTTP requests. Instead, it passes the HTTP request object directly to L. Thus you do not need to use a real hostname: "http://localhost/" will do. However, this is optional. The following two lines of code do exactly the same thing: $mech->get_ok('/action'); $mech->get_ok('http://localhost/action'); This makes testing fast and easy. L provides functions for common web testing scenarios. For example: $mech->get_ok( $page ); $mech->title_is( "Invoice Status", "Make sure we're on the invoice page" ); $mech->content_contains( "Andy Lester", "My name somewhere" ); $mech->content_like( qr/(cpan|perl)\.org/, "Link to perl.org or CPAN" ); An alternative to this module is L. =head1 CONSTRUCTOR =head2 new Behaves like, and calls, L's C method. You should pass in your application: my $mech = Test::WWW::Mechanize::PSGI->new( app => sub { my $env = shift; return [ 200, [ 'Content-Type' => 'text/plain' ], ['Hello World'] ],; }, ); =head1 METHODS: HTTP VERBS =head2 $mech->get_ok($url, [ \%LWP_options ,] $desc) A wrapper around WWW::Mechanize's get(), 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. A default description of "GET $url" is used if none if provided. =head2 $mech->head_ok($url, [ \%LWP_options ,] $desc) A wrapper around WWW::Mechanize's head(), 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. A default description of "HEAD $url" is used if none if provided. =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. A default description of "POST to $url" is used if none if provided. =head2 $mech->put_ok( $url, [ \%LWP_options ,] $desc ) A wrapper around WWW::Mechanize's put(), 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. A default description of "PUT to $url" is used if none if provided. =head2 $mech->submit_form_ok( \%parms [, $desc] ) Makes a C call and executes tests on the results. The form must be found, and then submitted successfully. Otherwise, this test fails. I<%parms> is a hashref containing the parms to pass to C. Note that the parms to C are a hash whereas the parms to this function are a hashref. You have to call this function like: $agent->submit_form_ok( {n=>3}, "looking for 3rd link" ); As with other test functions, C<$desc> is optional. If it is supplied then it will display when running the test harness in verbose mode. Returns true value if the specified link was found and followed successfully. The L object returned by submit_form() is not available. =head2 $mech->follow_link_ok( \%parms [, $desc] ) Makes a C call and executes tests on the results. The link must be found, and then followed successfully. Otherwise, this test fails. I<%parms> is a hashref containing the parms to pass to C. Note that the parms to C are a hash whereas the parms to this function are a hashref. You have to call this function like: $mech->follow_link_ok( {n=>3}, "looking for 3rd link" ); As with other test functions, C<$desc> is optional. If it is supplied then it will display when running the test harness in verbose mode. Returns a true value if the specified link was found and followed successfully. The L object returned by follow_link() is not available. =head2 click_ok( $button[, $desc] ) Clicks the button named by C<$button>. An optional C<$desc> can be given for the test. =head1 METHODS: CONTENT CHECKING =head2 $mech->html_lint_ok( [$desc] ) Checks the validity of the HTML on the current page. If the page is not HTML, then it fails. The URI is automatically appended to the I<$desc>. Note that HTML::Lint must be installed for this to work. Otherwise, it will blow up. =head2 $mech->title_is( $str [, $desc ] ) Tells if the title of the page is the given string. $mech->title_is( "Invoice Summary" ); =head2 $mech->title_like( $regex [, $desc ] ) Tells if the title of the page matches the given regex. $mech->title_like( qr/Invoices for (.+)/ =head2 $mech->title_unlike( $regex [, $desc ] ) Tells if the title of the page matches the given regex. $mech->title_unlike( qr/Invoices for (.+)/ =head2 $mech->base_is( $str [, $desc ] ) Tells if the base of the page is the given string. $mech->base_is( "http://example.com/" ); =head2 $mech->base_like( $regex [, $desc ] ) Tells if the base of the page matches the given regex. $mech->base_like( qr{http://example.com/index.php?PHPSESSID=(.+)}); =head2 $mech->base_unlike( $regex [, $desc ] ) Tells if the base of the page matches the given regex. $mech->base_unlike( qr{http://example.com/index.php?PHPSESSID=(.+)}); =head2 $mech->content_is( $str [, $desc ] ) Tells if the content of the page matches the given string =head2 $mech->content_contains( $str [, $desc ] ) Tells if the content of the page contains I<$str>. =head2 $mech->content_lacks( $str [, $desc ] ) Tells if the content of the page lacks I<$str>. =head2 $mech->content_like( $regex [, $desc ] ) Tells if the content of the page matches I<$regex>. =head2 $mech->content_unlike( $regex [, $desc ] ) Tells if the content of the page does NOT match I<$regex>. =head2 $mech->has_tag( $tag, $text [, $desc ] ) Tells if the page has a C<$tag> tag with the given content in its text. =head2 $mech->has_tag_like( $tag, $regex [, $desc ] ) Tells if the page has a C<$tag> tag with the given content in its text. =head2 $mech->followable_links() Returns a list of links that Mech can follow. This is only http and https links. =head2 $mech->page_links_ok( [ $desc ] ) Follow all links on the current page and test for HTTP status 200 $mech->page_links_ok('Check all links'); =head2 $mech->page_links_content_like( $regex [, $desc ] ) Follow all links on the current page and test their contents for I<$regex>. $mech->page_links_content_like( qr/foo/, 'Check all links contain "foo"' ); =head2 $mech->links_ok( $links [, $desc ] ) Follow specified links on the current page and test for HTTP status 200. The links may be specified as a reference to an array containing L objects, an array of URLs, or a scalar URL name. my @links = $mech->find_all_links( url_regex => qr/cnn\.com$/ ); $mech->links_ok( \@links, 'Check all links for cnn.com' ); my @links = qw( index.html search.html about.html ); $mech->links_ok( \@links, 'Check main links' ); $mech->links_ok( 'index.html', 'Check link to index' ); =head2 $mech->link_status_is( $links, $status [, $desc ] ) Follow specified links on the current page and test for HTTP status passed. The links may be specified as a reference to an array containing L objects, an array of URLs, or a scalar URL name. my @links = $mech->followable_links(); $mech->link_status_is( \@links, 403, 'Check all links are restricted' ); =head2 $mech->link_status_isnt( $links, $status [, $desc ] ) Follow specified links on the current page and test for HTTP status passed. The links may be specified as a reference to an array containing L objects, an array of URLs, or a scalar URL name. my @links = $mech->followable_links(); $mech->link_status_isnt( \@links, 404, 'Check all links are not 404' ); =head2 $mech->link_content_like( $links, $regex [, $desc ] ) Follow specified links on the current page and test the resulting content of each against I<$regex>. The links may be specified as a reference to an array containing L objects, an array of URLs, or a scalar URL name. my @links = $mech->followable_links(); $mech->link_content_like( \@links, qr/Restricted/, 'Check all links are restricted' ); =head2 $mech->link_content_unlike( $links, $regex [, $desc ] ) Follow specified links on the current page and test that the resulting content of each does not match I<$regex>. The links may be specified as a reference to an array containing L objects, an array of URLs, or a scalar URL name. my @links = $mech->followable_links(); $mech->link_content_unlike( \@links, qr/Restricted/, 'No restricted links' ); =head2 $mech->stuff_inputs( [\%options] ) Finds all free-text input fields (text, textarea, and password) in the current form and fills them to their maximum length in hopes of finding application code that can't handle it. Fields with no maximum length and all textarea fields are set to 66000 bytes, which will often be enough to overflow the data's eventual recepticle. There is no return value. If there is no current form then nothing is done. The hashref $options can contain the following keys: =over =item * ignore hash value is arrayref of field names to not touch, e.g.: $mech->stuff_inputs( { ignore => [qw( specialfield1 specialfield2 )], } ); =item * fill hash value is default string to use when stuffing fields. Copies of the string are repeated up to the max length of each field. E.g.: $mech->stuff_inputs( { fill => '@' # stuff all fields with something easy to recognize } ); =item * specs hash value is arrayref of hashrefs with which you can pass detailed instructions about how to stuff a given field. E.g.: $mech->stuff_inputs( { specs=>{ # Some fields are datatype-constrained. It's most common to # want the field stuffed with valid data. widget_quantity => { fill=>'9' }, notes => { maxlength=>2000 }, } } ); The specs allowed are I (use this fill for the field rather than the default) and I (use this as the field's maxlength instead of any maxlength specified in the HTML). =back =head1 AUTHOR Leon Brocard . =head1 COPYRIGHT Copyright (C) 2009, Leon Brocard =head1 LICENSE This module is free software; you can redistribute it or modify it under the same terms as Perl itself. Test-WWW-Mechanize-PSGI-0.35/CHANGES0000644000175000017500000000122311321120307015056 0ustar acmeacmeRevision history for Perl module Test::WWW::Mechanize::PSGI: 0.35 Wed Jan 6 14:39:59 GMT 2010 - override simple_request rather than _make_request, so mechanize still handles redirect and other high level stuff for us (patch by clkao) - use prepare_request so default_headers are added properly. this also makes the request_prepare and response_done hooks called, so cookies jars are handled without the current hack (patch by clkao) 0.34 Sun Jan 3 12:02:29 GMT 2010 - update the README to reflect the name - fix handling of cookies, patch by tokuhirom 0.33 Tue Dec 15 07:12:18 GMT 2009 - inital release Test-WWW-Mechanize-PSGI-0.35/t/0000755000175000017500000000000011311627276014350 5ustar acmeacmeTest-WWW-Mechanize-PSGI-0.35/t/pod.t0000644000175000017500000000022011311627276015311 0ustar acmeacme#!perl -T use Test::More; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD: $@" if $@; all_pod_files_ok(); Test-WWW-Mechanize-PSGI-0.35/t/cookie.t0000644000175000017500000000177411320103431015775 0ustar acmeacme#!perl use strict; use warnings; use Test::More tests => 4; use Test::WWW::Mechanize::PSGI; use CGI::Cookie; my $hello = Test::WWW::Mechanize::PSGI->new( app => do { my $cookie_store = {}; my $sid = 123456; sub { my $env = shift; my %cookies = CGI::Cookie->parse( $env->{HTTP_COOKIE} || '' ); if ( my $cookie = $cookies{sid} ) { my $content = $cookie_store->{ $cookies{sid}->value }; return [ 200, [ 'Set-Cookie' => "sid=$sid; path=/" ], [$content] ], ; } else { $cookie_store->{$sid} = "OK"; return [ 200, [ 'Set-Cookie' => "sid=$sid; path=/" ], ['Hello World'] ], ; } } }, ); $hello->get_ok('/'); $hello->content_is('Hello World'); $hello->get_ok('/'); $hello->content_is('OK'); Test-WWW-Mechanize-PSGI-0.35/t/simple.t0000644000175000017500000000215111321120264016007 0ustar acmeacme#!perl use strict; use warnings; use Test::More tests => 10; use Test::WWW::Mechanize::PSGI; my $hello = Test::WWW::Mechanize::PSGI->new( app => sub { my $env = shift; return [ 200, [ 'Content-Type' => 'text/plain' ], ['Hello World'] ],; }, ); isa_ok( $hello, 'Test::WWW::Mechanize::PSGI' ); $hello->get_ok('/'); is( $hello->ct, 'text/plain', 'Is text/plain' ); $hello->content_contains('Hello World'); my $html = Test::WWW::Mechanize::PSGI->new( app => sub { my $env = shift; return [ 200, [ 'Content-Type' => 'text/html' ], [ 'HiHello World' ] ]; }, ); isa_ok( $html, 'Test::WWW::Mechanize::PSGI' ); $html->get_ok('/'); is( $html->ct, 'text/html', 'Is text/html' ); $html->title_is('Hi'); $html->content_contains('Hello World'); my $die = Test::WWW::Mechanize::PSGI->new( app => sub { my $env = shift; die "Throwing an exception from app handler. Server shouldn't crash."; }, ); isa_ok( $die, 'Test::WWW::Mechanize::PSGI' ); $die->get; Test-WWW-Mechanize-PSGI-0.35/MANIFEST0000644000175000017500000000030611321120340015212 0ustar acmeacmeCHANGES lib/Test/WWW/Mechanize/PSGI.pm Makefile.PL MANIFEST This list of files README t/cookie.t t/pod.t t/simple.t META.yml Module meta-data (added by MakeMaker)