Update of /cvsroot/http-webtest/HTTP-WebTest-Recorder/t
In directory sc8-pr-cvs1:/tmp/cvs-serv12320/t
Modified Files:
03-actions.t 02-controller.t
Log Message:
Updated
Index: 03-actions.t
===================================================================
RCS file: /cvsroot/http-webtest/HTTP-WebTest-Recorder/t/03-actions.t,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** 03-actions.t 1 Feb 2003 22:40:07 -0000 1.2
--- 03-actions.t 2 Feb 2003 00:02:42 -0000 1.3
***************
*** 6,10 ****
use HTTP::Status;
! use Test::More tests => 23;
use Test::Exception;
--- 6,10 ----
use HTTP::Status;
! use Test::More tests => 31;
use Test::Exception;
***************
*** 56,70 ****
{
$CONTROLLER->cgi(CGI->new({num => 0}));
! my %data = request_action($CONTROLLER);
! is($data{test}, $RECORDER->tests->[0],
! 'Check if "test" variable is defined');
$CONTROLLER->cgi(CGI->new({num => 1}));
! %data = request_action($CONTROLLER);
! is($data{test}, $RECORDER->tests->[1],
! 'Check if "test" variable is defined');
$CONTROLLER->cgi(CGI->new({num => 2}));
! %data = request_action($CONTROLLER);
is($data{test}, undef,
'Check if "test" variable is not defined');
--- 56,74 ----
{
$CONTROLLER->cgi(CGI->new({num => 0}));
! is_deeply({ request_action($CONTROLLER) },
! { controller => $CONTROLLER,
! test => $RECORDER->tests->[0],
! num => 0 },
! 'Test if test and test num are returned');
$CONTROLLER->cgi(CGI->new({num => 1}));
! is_deeply({ request_action($CONTROLLER) },
! { controller => $CONTROLLER,
! test => $RECORDER->tests->[1],
! num => 1 },
! 'Test if test and test num are returned');
$CONTROLLER->cgi(CGI->new({num => 2}));
! my %data = request_action($CONTROLLER);
is($data{test}, undef,
'Check if "test" variable is not defined');
***************
*** 76,79 ****
--- 80,84 ----
my $request = GET 'http://example.com/doc1.html';
my $response = HTTP::Response->new(RC_OK);
+ $response->header('Content-Type' => 'text/xml');
$response->content('DOC #1');
push @{$RECORDER->tests}, $RECORDER->make_test($request, $response);
***************
*** 89,92 ****
--- 94,98 ----
my $request = GET 'http://example.com/doc3.html?a=b&a=c';
my $response = HTTP::Response->new(RC_OK);
+ $response->header('Content-Type' => 'text/plain');
$response->content('DOC #2');
push @{$RECORDER->tests}, $RECORDER->make_test($request, $response);
***************
*** 153,155 ****
--- 159,184 ----
is($@->url, 'list', 'Test url property of exception');
ok($CONTROLLER->recorder->is_recording, 'Recording');
+ }
+
+ # test response_content_action()
+ {
+ $CONTROLLER->cgi(CGI->new({num => 0}));
+ dies_ok { response_content_action($CONTROLLER) } 'Expect raw response';
+ isa_ok($@, 'HTTP::WebTest::Recorder::Exception::RawResponse',
+ 'Verify exception class');
+ is($@->content, $RECORDER->tests->[0]->response->content,
+ 'Test content property of exception');
+ is_deeply($@->headers,
+ [ 'Content-Type' => 'text/xml' ],
+ 'Test headers property of exception');
+
+ $CONTROLLER->cgi(CGI->new({num => 2}));
+ dies_ok { response_content_action($CONTROLLER) } 'Expect raw response';
+ isa_ok($@, 'HTTP::WebTest::Recorder::Exception::RawResponse',
+ 'Verify exception class');
+ is($@->content, $RECORDER->tests->[2]->response->content,
+ 'Test content property of exception');
+ is_deeply($@->headers,
+ [ 'Content-Type' => 'text/plain' ],
+ 'Test headers property of exception');
}
Index: 02-controller.t
===================================================================
RCS file: /cvsroot/http-webtest/HTTP-WebTest-Recorder/t/02-controller.t,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** 02-controller.t 1 Feb 2003 22:25:32 -0000 1.4
--- 02-controller.t 2 Feb 2003 00:02:43 -0000 1.5
***************
*** 6,10 ****
use HTTP::Status;
! use Test::More tests => 34;
use Test::Exception;
--- 6,10 ----
use HTTP::Status;
! use Test::More tests => 41;
use Test::Exception;
***************
*** 119,124 ****
local %HTTP::WebTest::Recorder::Controller::DISPATCH =
( redirect => $test_redirect );
- # just to disable used only once warning
- () = %HTTP::WebTest::Recorder::Controller::DISPATCH;
my $request = GET 'http://localhost/webtest/redirect';
--- 119,122 ----
***************
*** 128,130 ****
--- 126,163 ----
is($response->header('Location'), 'xxx',
'Check if we got correct Location header');
+ }
+
+ # test raw_response()
+ {
+ my $headers = [ 'Content-Type' => 'image/png' ];
+ my $content = "Expect the worst, it's the least you can do.";
+
+ dies_ok { $CONTROLLER->raw_response(headers => $headers,
+ content => $content) }
+ 'Expecting raw response exception';
+ isa_ok($@, 'HTTP::WebTest::Recorder::Exception::RawResponse',
+ 'Verify exception class');
+ is($@->headers, $headers, 'Test headers property of exception');
+ is($@->content, $content, 'Test content property of exception');
+ }
+
+ # try to access page that generates a raw response
+ {
+ my $test_raw_response = sub {
+ my $controller = shift;
+
+ return $controller->raw_response(headers =>
+ [ 'Content-Type', 'text/xml' ],
+ content => 'Bla Bla');
+ };
+ local %HTTP::WebTest::Recorder::Controller::DISPATCH =
+ ( raw_response => $test_raw_response );
+
+ my $request = GET 'http://localhost/webtest/raw_response';
+ my $response = $CONTROLLER->execute(action => 'raw_response',
+ request => $request);
+ is($response->code, RC_OK, 'Expect ok status');
+ is($response->content, 'Bla Bla', 'Verify content in response');
+ is($response->header('Content-Type'), 'text/xml',
+ 'Verify headers in response');
}
|