view release on metacpan or search on metacpan
no warnings 'redefine';
*Catalyst::Test::local_request = sub {
my ( $class, $request ) = @_;
require HTTP::Request::AsCGI;
my $cgi = HTTP::Request::AsCGI->new( $request, %ENV )->setup;
$class->handle_request;
return $cgi->restore->response;
};
# test echo
{
my $content =
RPC::XML::request->new( 'myAPI.echo', 'hello' )->as_string;
my $request = HTTP::Request->new( POST => $entrypoint );
$request->header( 'Content-Length' => length($content) );
$request->header( 'Content-Type' => 'text/xml' );
$request->content($content);
ok( my $response = request($request), 'Request' );
# test add
{
my $content =
RPC::XML::request->new( 'plugin.xmlrpc.add', ( 1, 2 ) )->as_string;
my $request = HTTP::Request->new( POST => $entrypoint );
$request->header( 'Content-Length' => length($content) );
$request->header( 'Content-Type' => 'text/xml' );
$request->content($content);
ok( my $response = request($request), 'Request' );
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Catalyst/Test.pm view on Meta::CPAN
use Catalyst::Test 'TestApp';
my $content = get('index.html'); # Content as string
my $response = request('index.html'); # HTTP::Response object
my($res, $c) = ctx_request('index.html'); # HTTP::Response & context object
use HTTP::Request::Common;
my $response = request POST '/foo', [
bar => 'baz',
something => 'else'
];
lib/Catalyst/Test.pm view on Meta::CPAN
=head1 DESCRIPTION
This module allows you to make requests to a Catalyst application either without
a server, by simulating the environment of an HTTP request using
L<HTTP::Request::AsCGI> or remotely if you define the CATALYST_SERVER
environment variable. This module also adds a few Catalyst-specific
testing methods as displayed in the method section.
The L<get|/"$content = get( ... )"> and L<request|/"$res = request( ... );">
functions take either a URI or an L<HTTP::Request> object.
=head1 INLINE TESTS WILL NO LONGER WORK
While it used to be possible to inline a whole test app into a C<.t> file for
a distribution, this will no longer work.
lib/Catalyst/Test.pm view on Meta::CPAN
header configuration; currently only supports setting 'host' value.
my $res = request('foo/bar?test=1');
my $virtual_res = request('foo/bar?test=1', {host => 'virtualhost.com'});
Alternately, you can pass in an L<HTTP::Request::Common> object to set arbitrary
request headers.
my $res = request(GET '/foo/bar',
X-Foo => 'Bar',
Authorization => 'Bearer JWT_HERE',
lib/Catalyst/Test.pm view on Meta::CPAN
Verify the given URL has a content type of $type and optionally specify a test name.
=head1 SEE ALSO
L<Catalyst>, L<Test::WWW::Mechanize::Catalyst>,
L<Test::WWW::Selenium::Catalyst>, L<Test::More>, L<HTTP::Request::Common>
=head1 AUTHORS
Catalyst Contributors, see Catalyst.pm
view all matches for this distribution
view release on metacpan or search on metacpan
t/another_site_blog.t view on Meta::CPAN
use Test::More tests => 5;
use HTTP::Request;
use HTTP::Request::Common;
use Test::HTML::Form;
use lib qw(t/lib);
use Catalyst::Test qw(TestBlogApp);
my $main_url = '/blog';
my $hr = HTTP::Request->new('GET', $main_url);
$hr->header(Host => 'foo.bar');
my $r=request($hr);
unless(ok($r->is_success, 'got main blog page ok')) {
if($r->code == 500) {
view all matches for this distribution
view release on metacpan or search on metacpan
"requires" : {
"Catalyst" : 0,
"Catalyst::Controller" : 0,
"Catalyst::Test" : 0,
"FindBin" : 0,
"HTTP::Request::Common" : 0,
"Moose" : 0,
"Test::More" : 0
}
}
},
view all matches for this distribution
view release on metacpan or search on metacpan
t/live-test.t view on Meta::CPAN
no warnings 'redefine';
*Catalyst::Test::local_request = sub {
my ( $class, $request ) = @_;
require HTTP::Request::AsCGI;
my $cgi = HTTP::Request::AsCGI->new( $request, %ENV )->setup;
$class->handle_request;
return $cgi->restore->response;
};
t/live-test.t view on Meta::CPAN
# test first available view
{
my $expected = 'View';
my $request =
HTTP::Request->new( GET => 'http://localhost:3000/test_firstview' );
ok( my $response = request($request), 'Request' );
ok( $response->is_success, 'Response Successful 2xx' );
is( $response->header( 'Content-Type' ), 'text/html; charset=utf-8', 'Content Type' );
is( $response->code, 200, 'Response Code' );
t/live-test.t view on Meta::CPAN
# test view
{
my $expected = 'View';
my $request =
HTTP::Request->new( GET => 'http://localhost:3000/test_view' );
ok( my $response = request($request), 'Request' );
ok( $response->is_success, 'Response Successful 2xx' );
is( $response->header( 'Content-Type' ), 'text/html; charset=utf-8', 'Content Type' );
is( $response->code, 200, 'Response Code' );
t/live-test.t view on Meta::CPAN
# test skip view
{
my $expected = 'Skipped View';
my $request =
HTTP::Request->new( GET => 'http://localhost:3000/test_skipview' );
ok( my $response = request($request), 'Request' );
ok( $response->is_success, 'Response Successful 2xx' );
is( $response->header( 'Content-Type' ), 'text/html; charset=utf-8', 'Content Type' );
is( $response->code, 200, 'Response Code' );
view all matches for this distribution
view release on metacpan or search on metacpan
Catalyst::Test: 0
DBI: 0
DBIx::Class::Core: 0
DBIx::Class::Schema: 0
FindBin: 0
HTTP::Request::Common: 0
Moose: 0
Test::More: 0
base: 0
strict: 0
warnings: 0
view all matches for this distribution
view release on metacpan or search on metacpan
abstract: 'methods for your request object to assist in content negotiation'
author:
- 'John Napiorkowski <jjnapiork@cpan.org>'
build_requires:
Catalyst::Test: '0'
HTTP::Request::Common: '0'
Test::Most: '0.34'
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 0
generated_by: 'Dist::Zilla version 5.041, CPAN::Meta::Converter version 2.150005'
view all matches for this distribution
view release on metacpan or search on metacpan
t/01-json_decoder.t view on Meta::CPAN
use strict;
use warnings;
use lib 't/lib';
use Test::More;
use JSON::Any;
use HTTP::Request::Common;
BEGIN {
use_ok 'Catalyst::Test', 'Simple';
}
view all matches for this distribution
view release on metacpan or search on metacpan
"dynamic_config" : 0,
"generated_by" : "Dist::Zilla version 6.030, CPAN::Meta::Converter version 2.150010",
"keywords" : [
"Catalyst",
"Catalyst::Request",
"HTTP::Request"
],
"license" : [
"artistic_2"
],
"meta-spec" : {
},
"requires" : {
"Catalyst" : "5.90090",
"Catalyst::Test" : "0",
"File::Spec" : "0",
"HTTP::Request" : "0",
"HTTP::Request::Common" : "0",
"Module::Metadata" : "0",
"Moose" : "0",
"Plack::Middleware::MethodOverride" : "0",
"Test::More" : "0",
"Test::Most" : "0",
view all matches for this distribution
view release on metacpan or search on metacpan
Catalyst::Plugin::Session::State::Cookie: 0
Catalyst::Plugin::Session::Store::File: 0
Catalyst::View::TT: 0
CatalystX::RoleApplicator: 0
ExtUtils::MakeMaker: 6.42
HTTP::Request::Common: 0
Test::More: 0
configure_requires:
ExtUtils::MakeMaker: 6.42
distribution_type: module
generated_by: 'Module::Install version 0.99'
view all matches for this distribution
view release on metacpan or search on metacpan
- 'Tomas Doran (t0m) C<< <bobtfish@bobtfish.net> >>'
build_requires:
Catalyst::Runtime: 5.80007
CatalystX::RoleApplicator: 0.005
ExtUtils::MakeMaker: 6.42
HTTP::Request::Common: 0
Test::More: 0.88
configure_requires:
ExtUtils::MakeMaker: 6.42
distribution_type: module
generated_by: 'Module::Install version 0.910'
view all matches for this distribution
view release on metacpan or search on metacpan
author:
- 'John Napiorkowski <jjnapiork@cpan.org>'
build_requires:
Catalyst::Test: '0'
Data::Dumper: '0'
HTTP::Request::Common: '0'
Test::Most: '0.34'
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 0
generated_by: 'Dist::Zilla version 5.039, CPAN::Meta::Converter version 2.150005'
view all matches for this distribution
view release on metacpan or search on metacpan
abstract: 'methods for your request object to assist in content negotiation'
author:
- 'John Napiorkowski <jjnapiork@cpan.org>'
build_requires:
Catalyst::Test: '0'
HTTP::Request::Common: '0'
Test::Most: '0.34'
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 0
generated_by: 'Dist::Zilla version 6.024, CPAN::Meta::Converter version 2.150010'
view all matches for this distribution
view release on metacpan or search on metacpan
abstract: 'Enforce structural rules on your body and data parameters'
author:
- 'John Napiorkowski <jjnapiork@cpan.org>'
build_requires:
Catalyst::Test: '0'
HTTP::Request::Common: '0'
Test::Most: '0.34'
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 0
generated_by: 'Dist::Zilla version 6.024, CPAN::Meta::Converter version 2.150010'
view all matches for this distribution
view release on metacpan or search on metacpan
use strict;
use warnings;
use Test::More;
use HTTP::Request::Common;
use FindBin;
use lib "$FindBin::Bin/lib";
use Catalyst::Test 'TestApp';
view all matches for this distribution
view release on metacpan or search on metacpan
"Catalyst" : "5.64",
"Catalyst::Test" : "0",
"File::Spec" : "0",
"FindBin" : "0",
"HTTP::Headers" : "0",
"HTTP::Request" : "0",
"Moose" : "0",
"MooseX::Aliases" : "0",
"Path::Class::Dir" : "0.17",
"Test::More" : "0.88",
"URI" : "0",
view all matches for this distribution
view release on metacpan or search on metacpan
}
},
"test" : {
"requires" : {
"Catalyst::Test" : "0",
"HTTP::Request::Common" : "0",
"Test::Lib" : "0",
"Test::Most" : "0.34"
}
}
},
view all matches for this distribution
view release on metacpan or search on metacpan
}
},
"test" : {
"requires" : {
"Catalyst::Test" : "0",
"HTTP::Request::Common" : "0",
"Test::Lib" : "0",
"Test::Most" : "0.34"
}
}
},
view all matches for this distribution
view release on metacpan or search on metacpan
}
},
"test" : {
"requires" : {
"Catalyst::Test" : "0",
"HTTP::Request::Common" : "0",
"Test::Lib" : "0",
"Test::Most" : "0.34"
}
}
},
view all matches for this distribution
view release on metacpan or search on metacpan
t/01_server.t view on Meta::CPAN
no warnings 'redefine';
if ( $Catalyst::VERSION < 5.89 ) {
*Catalyst::Test::local_request = sub {
my ( $class, $request ) = @_;
require HTTP::Request::AsCGI;
my $cgi = HTTP::Request::AsCGI->new( $request, %ENV )->setup;
$class->handle_request;
return $cgi->restore->response;
};
t/01_server.t view on Meta::CPAN
}
my $entrypoint = "http://localhost/foo";
{
my $request = HTTP::Request->new( GET => $entrypoint );
ok( my $response = request($request), 'Request' );
ok( $response->is_success, 'Response Successful 2xx' );
is( $response->code, 200, 'Response Code' );
is_deeply( [ $response->content_type ], [ 'application/json', 'charset=utf-8' ] );
t/01_server.t view on Meta::CPAN
is_deeply $data->{json_baz}, [ 1, 2, 3 ];
ok ! $data->{foo}, "doesn't return stash that doesn't match json_";
}
{
my $request = HTTP::Request->new( GET => "http://localhost/foo2" );
ok( my $response = request($request), 'Request' );
ok( $response->is_success, 'Response Successful 2xx' );
is( $response->code, 200, 'Response Code' );
is_deeply( [ $response->content_type ], [ 'application/json', 'charset=utf-8' ] );
t/01_server.t view on Meta::CPAN
my $data = from_json($response->content);
is_deeply( $data, [1, 2, 3] );
}
{
my $request = HTTP::Request->new( GET => $entrypoint . "?cb=foobar" );
ok( my $response = request($request), 'Request' );
ok( $response->is_success, 'Response Successful 2xx' );
is( $response->code, 200, 'Response Code' );
is_deeply( [ $response->content_type ], [ 'application/json', 'charset=utf-8' ] );
t/01_server.t view on Meta::CPAN
is_deeply $data->{json_baz}, [ 1, 2, 3 ];
ok ! $data->{foo}, "doesn't return stash that doesn't match json_";
}
{
my $request = HTTP::Request->new( GET => $entrypoint . "?cb=foobar%28" );
ok( my $response = request($request), 'Request' );
like $response->header('X-Error'), qr/Invalid callback parameter/,;
}
{
##
my $request = HTTP::Request->new( GET => "http://localhost/foo3" );
ok( my $response = request($request), 'Request' );
is_deeply( [ $response->content_type ], [ 'application/json', 'charset=utf-8' ] );
ok decode('utf-8', $response->content);
}
{
my $request = HTTP::Request->new( GET => "http://localhost/foo4" );
ok( my $response = request($request), 'Request' );
is_deeply( [ $response->content_type ], [ 'application/json', 'charset=euc-jp' ] );
ok decode('euc-jp', $response->content);
}
{
my $request = HTTP::Request->new( GET => "http://localhost/foo3" );
$request->header("User-Agent", "Safari");
ok( my $response = request($request), 'Request' );
is_deeply( [ $response->content_type ], [ 'application/json', 'charset=utf-8' ] );
my $bom = substr $response->content, 0, 3;
is $bom, "\xEF\xBB\xBF";
}
{
my $request = HTTP::Request->new( GET => "http://localhost/foo3" );
$request->header("User-Agent", "Safari");
ok( my $response = request($request), 'Request' );
is_deeply( [ $response->content_type ], [ 'application/json', 'charset=utf-8' ] );
my $bom = substr $response->content, 0, 3;
is $bom, "\xEF\xBB\xBF";
}
{
my $request = HTTP::Request->new( GET => "http://localhost/foo3" );
$request->header("X-Prototype-Version", "1.5");
ok( my $response = request($request), 'Request' );
ok $response->header('X-JSON');
}
{
my $request = HTTP::Request->new( GET => "http://localhost/foo5" );
$request->header("X-Prototype-Version", "1.5");
ok( my $response = request($request), 'Request' );
ok !$response->header('X-JSON');
}
{
my $request = HTTP::Request->new( GET => "http://localhost/foo6" );
ok( my $response = request($request), 'Request' );
my $data = from_json($response->content);
is $data->{foo}, "fake";
}
{
my $request = HTTP::Request->new( GET => "http://localhost/warnmsg" );
ok( my $response = request($request), 'Request' );
ok( $response->is_success, 'Response Successful 2xx' );
is( $response->code, 200, 'Response Code' );
is_deeply( [ $response->content_type ], [ 'application/json', 'charset=utf-8' ] );
view all matches for this distribution
view release on metacpan or search on metacpan
"Catalyst" : "5.64",
"Catalyst::Test" : "0",
"File::Spec" : "0",
"FindBin" : "0",
"HTTP::Headers" : "0",
"HTTP::Request" : "0",
"JavaScript::Minifier::XS" : "0",
"Moose" : "0",
"MooseX::Aliases" : "0",
"Path::Class::Dir" : "0.17",
"URI" : "0",
view all matches for this distribution
view release on metacpan or search on metacpan
t/01_live.t view on Meta::CPAN
no warnings 'redefine';
*Catalyst::Test::local_request = sub {
my ( $class, $request ) = @_;
require HTTP::Request::AsCGI;
my $cgi = HTTP::Request::AsCGI->new( $request, %ENV )->setup;
$class->handle_request;
return $cgi->restore->response;
};
}
my $entrypoint = "http://localhost/jemplate";
{
my $request = HTTP::Request->new( GET => $entrypoint );
ok( my $response = request($request), 'Request' );
ok( $response->is_success, 'Response Successful 2xx' );
is( $response->code, 200, 'Response Code' );
t/01_live.t view on Meta::CPAN
like $response->content, qr!//line 1 "foo\.tt"!;
like $response->content, qr!//line 1 "bar\.tt"!;
}
{
my $request = HTTP::Request->new( GET => "http://localhost/selected" );
ok( my $response = request($request), 'Request' );
ok( $response->is_success, 'Response Successful 2xx' );
is( $response->code, 200, 'Response Code' );
t/01_live.t view on Meta::CPAN
unlike $response->content, qr!//line 1 "foo\.tt"!;
like $response->content, qr!//line 1 "bar\.tt"!;
}
{
my $request = HTTP::Request->new( GET => "http://localhost/Jemplate.js" );
ok( my $response = request($request), 'Request' );
ok( $response->is_success, 'Response Successful 2xx' );
is( $response->code, 200, 'Response Code' );
view all matches for this distribution
view release on metacpan or search on metacpan
"Encode" : 0,
"English" : 0,
"File::Find" : 0,
"File::Temp" : 0,
"FindBin" : 0,
"HTTP::Request::AsCGI" : 0,
"MRO::Compat" : 0,
"RDF::Simple::Parser" : 0,
"Test::More" : "0.88"
}
}
view all matches for this distribution
view release on metacpan or search on metacpan
inc/Test/WWW/Mechanize/Catalyst.pm view on Meta::CPAN
# are then we'd better cope with it. Let's create a new URI, using
# our request as the base.
my $uri = URI->new_abs( $location, $request->uri )->as_string;
# make a new response, and save the old response in it
$response = $self->_make_request( HTTP::Request->new( GET => $uri ) );
my $end_of_chain = $response;
while ( $end_of_chain->previous ) # keep going till the end
{
$end_of_chain = $end_of_chain->previous;
} # of the chain...
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Catalyst/View/Template/Lace.pm view on Meta::CPAN
sub view_components {
my ($class, $app, $merged_args) = @_;
return +{
catalyst => {
subrequest => Template::Lace::Utils::mk_component {
require HTTP::Request;
require HTTP::Message::PSGI;
my @args = (delete $_{action});
my $method = ((delete $_{method}) || 'GET');
push @args, delete($_{parts}) if $_{parts};
push @args, delete($_{query}) if $_{query};
my $href = $_{model}->uri_for(@args);
my $http_request = HTTP::Request->new($method, $href);
my $psgi_env = HTTP::Message::PSGI::req_to_psgi($http_request);
my $psgi_response = $_{model}->ctx->psgi_app->($psgi_env);
my $http_response = HTTP::Message::PSGI::res_from_psgi($psgi_response);
my $content = $http_response->content;
if($_{at}) {
view all matches for this distribution
view release on metacpan or search on metacpan
t/04-post.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
use Catalyst::Test 'TestApp';
use Data::Dumper;
use HTTP::Request::Common; # reqd for POST requests
eval "use PHP 0.13";
if ($@) {
plan skip_all => "PHP 0.13 needed for testing";
}
view all matches for this distribution
view release on metacpan or search on metacpan
t/01-basic.t view on Meta::CPAN
use strict;
use warnings;
use FindBin '$Bin';
use lib "$Bin/lib";
use Catalyst::Test 'TestApp';
use HTTP::Request::Common;
use Test::More tests => 5;
action_ok('/', 'check if the thing runs at all');
view all matches for this distribution
view release on metacpan or search on metacpan
}
sub cookies {
my $res = shift;
my $request = HTTP::Request->new( GET => 'http://localhost/' );
$res->request($request);
my $jar = HTTP::Cookies->new();
$jar->extract_cookies($res);
view all matches for this distribution
view release on metacpan or search on metacpan
use Test::More tests => 10;
use lib 't/MyCMS/lib';
use Catalyst::Test 'MyCMS';
use HTTP::Request::Common;
my $result;
# create a page
ok( $result = request('/cms/mypage?cxcms=create'), "GET create" );
view all matches for this distribution
view release on metacpan or search on metacpan
t/01-file.t view on Meta::CPAN
use_ok('CatalystX::CRUD::Model::File');
use_ok('CatalystX::CRUD::Object::File');
use Catalyst::Test 'MyApp';
use Data::Dump qw( dump );
use HTTP::Request::Common;
###########################################
# basic sanity check
ok( get('/foo'), "get /foo" );
t/01-file.t view on Meta::CPAN
);
is( $res->code, 302, "new file 302 redirect status" );
# read the file we just created
ok( $res = request( HTTP::Request->new( GET => '/file/testfile/view' ) ),
"GET new file" );
#diag( $res->content );
like( $res->content, qr/content => "hello world"/, "read file" );
t/01-file.t view on Meta::CPAN
ok( $res = request( POST( '/file/testfile2/delete', [] ) ), "rm file2" );
#diag( $res->content );
# confirm it is gone
ok( $res = request( HTTP::Request->new( GET => '/file/testfile/view' ) ),
"confirm we nuked the file" );
#diag( $res->content );
like( $res->content, qr/content => undef/, "file nuked" );
t/01-file.t view on Meta::CPAN
);
# read the file we just created
ok( $res
= request(
HTTP::Request->new( GET => '/fileadapter/testfile/view' ) ),
"GET new file adapter"
);
#diag( $res->content );
t/01-file.t view on Meta::CPAN
#diag( $res->content );
# confirm it is gone
ok( $res
= request(
HTTP::Request->new( GET => '/fileadapter/testfile/view' ) ),
"confirm we nuked the file adapter"
);
#diag( $res->content );
t/01-file.t view on Meta::CPAN
'{ content => "hello world", file => "testfile" }',
"POST new file response adapter"
);
ok( $res = request(
HTTP::Request->new( GET => '/fetchrewrite/id/testfile/view' )
),
"fetch rewrite works"
);
# delete the file
t/01-file.t view on Meta::CPAN
ok( $res = request( POST( '/fetchrewrite/id/testfile/rm', [] ) ),
"rm fetch rewrite" );
# confirm it is gone
ok( $res = request(
HTTP::Request->new( GET => '/fetchrewrite/id/testfile/view' )
),
"confirm we nuked the fetch rewrite file"
);
view all matches for this distribution