Update of /cvsroot/http-webtest/HTTP-WebTest-Recorder/t
In directory sc8-pr-cvs1:/tmp/cvs-serv29594/t
Modified Files:
03-actions.t 02-controller.t
Log Message:
Updated to pass tests for refactored API
Index: 03-actions.t
===================================================================
RCS file: /cvsroot/http-webtest/HTTP-WebTest-Recorder/t/03-actions.t,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** 03-actions.t 5 Apr 2003 09:59:01 -0000 1.6
--- 03-actions.t 22 Apr 2003 21:44:26 -0000 1.7
***************
*** 6,11 ****
use HTTP::Status;
! use Test::More tests => 53;
! use Test::Exception;
# get test template files directory included in search path
--- 6,10 ----
use HTTP::Status;
! use Test::More tests => 46;
# get test template files directory included in search path
***************
*** 23,37 ****
$CONTROLLER->recorder($RECORDER);
! # test default_action()
{
! is_deeply([default_action($CONTROLLER)],
! [controller => $CONTROLLER],
! 'Test template_data()');
}
# test list_action()
{
! my %data = list_action($CONTROLLER);
! is($data{tests}, $RECORDER->tests,
'Check if "tests" variable is defined');
}
--- 22,47 ----
$CONTROLLER->recorder($RECORDER);
! # test HTTP::WebTest::Recorder::Actions::create_template()
{
! my $template = HTTP::WebTest::Recorder::Actions::create_template();
! isa_ok($template, 'Template');
!
! my $output = '';
! ok($template->process('testme', { var => 1 }, \$output),
! 'Try to process test template: ' . ($template->error || '') );
! like($output, qr/This is a test file/, 'Check output');
! like($output, qr/VAR = 1/, 'Check output');
!
! $output = '';
! ok($template->process('testme', { var => 'xxx' }, \$output),
! 'Try to process test template: ' . ($template->error || '') );
! like($output, qr/VAR = xxx/, 'Check output');
}
# test list_action()
{
! $CONTROLLER->heap({});
! list_action($CONTROLLER);
! is($CONTROLLER->heap->{tests}, $RECORDER->tests,
'Check if "tests" variable is defined');
}
***************
*** 56,75 ****
{
$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');
}
--- 66,87 ----
{
$CONTROLLER->cgi(CGI->new({num => 0}));
! $CONTROLLER->heap({});
! request_action($CONTROLLER);
! is_deeply($CONTROLLER->heap,
! { test => $RECORDER->tests->[0],
num => 0 },
'Test if test and test num are returned');
$CONTROLLER->cgi(CGI->new({num => 1}));
! $CONTROLLER->heap({});
! request_action($CONTROLLER);
! is_deeply($CONTROLLER->heap,
! { test => $RECORDER->tests->[1],
num => 1 },
'Test if test and test num are returned');
$CONTROLLER->cgi(CGI->new({num => 2}));
! request_action($CONTROLLER);
! is($CONTROLLER->heap->{tests}, undef,
'Check if "test" variable is not defined');
}
***************
*** 101,106 ****
# test wtscript_action()
{
! my %data = wtscript_action($CONTROLLER);
! is($data{wtscript}, <<'WTSCRIPT',
test_name = N/A
url = http://example.com/doc1.html
--- 113,118 ----
# test wtscript_action()
{
! wtscript_action($CONTROLLER);
! is($CONTROLLER->heap->{wtscript}, <<'WTSCRIPT',
test_name = N/A
url = http://example.com/doc1.html
***************
*** 134,141 ****
{
$CONTROLLER->cgi(CGI->new({ enable => 1 }));
! dies_ok { enable_action($CONTROLLER) } 'Expect redirect';
! isa_ok($@, 'HTTP::WebTest::Recorder::Exception::Redirect',
! 'Verify exception class');
! is($@->url, 'list', 'Test url property of exception');
ok($CONTROLLER->recorder->is_recording, 'Recording');
}
--- 146,153 ----
{
$CONTROLLER->cgi(CGI->new({ enable => 1 }));
! $CONTROLLER->heap->{response} = HTTP::Response->new(RC_OK);
! enable_action($CONTROLLER);
! is($CONTROLLER->heap->{response}->code, RC_FOUND);
! is($CONTROLLER->heap->{response}->header('Location'), 'list');
ok($CONTROLLER->recorder->is_recording, 'Recording');
}
***************
*** 144,151 ****
{
$CONTROLLER->cgi(CGI->new({ enable => 0 }));
! dies_ok { enable_action($CONTROLLER) } 'Expect redirect';
! isa_ok($@, 'HTTP::WebTest::Recorder::Exception::Redirect',
! 'Verify exception class');
! is($@->url, 'list', 'Test url property of exception');
ok(not($CONTROLLER->recorder->is_recording), 'Not recording');
}
--- 156,162 ----
{
$CONTROLLER->cgi(CGI->new({ enable => 0 }));
! enable_action($CONTROLLER);
! is($CONTROLLER->heap->{response}->code, RC_FOUND);
! is($CONTROLLER->heap->{response}->header('Location'), 'list');
ok(not($CONTROLLER->recorder->is_recording), 'Not recording');
}
***************
*** 154,161 ****
{
$CONTROLLER->cgi(CGI->new({ enable => 1 }));
! dies_ok { enable_action($CONTROLLER) } 'Expect redirect';
! isa_ok($@, 'HTTP::WebTest::Recorder::Exception::Redirect',
! 'Verify exception class');
! is($@->url, 'list', 'Test url property of exception');
ok($CONTROLLER->recorder->is_recording, 'Recording');
}
--- 165,171 ----
{
$CONTROLLER->cgi(CGI->new({ enable => 1 }));
! enable_action($CONTROLLER);
! is($CONTROLLER->heap->{response}->code, RC_FOUND);
! is($CONTROLLER->heap->{response}->header('Location'), 'list');
ok($CONTROLLER->recorder->is_recording, 'Recording');
}
***************
*** 164,189 ****
{
$CONTROLLER->cgi(CGI->new({num => 0, view => 'raw'}));
! 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, view => 'raw'}));
! 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');
$CONTROLLER->cgi(CGI->new({num => 0, view => 'text'}));
! my %data = response_content_action($CONTROLLER);
! is($data{content}, $RECORDER->tests->[0]->response->content,
"Test if action doesn't die and returns response content");
}
--- 174,195 ----
{
$CONTROLLER->cgi(CGI->new({num => 0, view => 'raw'}));
! response_content_action($CONTROLLER);
! is($CONTROLLER->heap->{response}->content,
! $RECORDER->tests->[0]->response->content,
! 'Test content of response');
! is($CONTROLLER->heap->{response}->header('Content-Type'), 'text/xml',
! 'Test content-type if header is set correctly');
$CONTROLLER->cgi(CGI->new({num => 2, view => 'raw'}));
! response_content_action($CONTROLLER);
! is($CONTROLLER->heap->{response}->content,
! $RECORDER->tests->[2]->response->content,
! 'Test content of response');
! is($CONTROLLER->heap->{response}->header('Content-Type'), 'text/plain',
! 'Test content-type if header is set correctly');
$CONTROLLER->cgi(CGI->new({num => 0, view => 'text'}));
! response_content_action($CONTROLLER);
! is($CONTROLLER->heap->{content}, $RECORDER->tests->[0]->response->content,
"Test if action doesn't die and returns response content");
}
***************
*** 192,206 ****
{
$CONTROLLER->cgi(CGI->new({num => 2}));
! dies_ok { delete_action($CONTROLLER) } 'Expect redirect';
! isa_ok($@, 'HTTP::WebTest::Recorder::Exception::Redirect',
! 'Verify exception class');
! is($@->url, 'list', 'Test url property of exception');
is(@{$RECORDER->tests}, 2, 'Check number of tests');
$CONTROLLER->cgi(CGI->new({num => 0}));
! dies_ok { delete_action($CONTROLLER) } 'Expect redirect';
! isa_ok($@, 'HTTP::WebTest::Recorder::Exception::Redirect',
! 'Verify exception class');
! is($@->url, 'list', 'Test url property of exception');
is(@{$RECORDER->tests}, 1, 'Check number of tests');
--- 198,210 ----
{
$CONTROLLER->cgi(CGI->new({num => 2}));
! delete_action($CONTROLLER);
! is($CONTROLLER->heap->{response}->code, RC_FOUND);
! is($CONTROLLER->heap->{response}->header('Location'), 'list');
is(@{$RECORDER->tests}, 2, 'Check number of tests');
$CONTROLLER->cgi(CGI->new({num => 0}));
! delete_action($CONTROLLER);
! is($CONTROLLER->heap->{response}->code, RC_FOUND);
! is($CONTROLLER->heap->{response}->header('Location'), 'list');
is(@{$RECORDER->tests}, 1, 'Check number of tests');
***************
*** 216,223 ****
field => 'Content-Type',
value => 'text'}));
! dies_ok { filter_action($CONTROLLER) } 'Expect redirect';
! isa_ok($@, 'HTTP::WebTest::Recorder::Exception::Redirect',
! 'Verify exception class');
! is($@->url, 'list', 'Test url property of exception');
is($RECORDER->filter->{header}{'Content-Type'}, 'text',
'Test if Content-Type header filter is set');
--- 220,226 ----
field => 'Content-Type',
value => 'text'}));
! filter_action($CONTROLLER);
! is($CONTROLLER->heap->{response}->code, RC_FOUND);
! is($CONTROLLER->heap->{response}->header('Location'), 'list');
is($RECORDER->filter->{header}{'Content-Type'}, 'text',
'Test if Content-Type header filter is set');
***************
*** 226,233 ****
field => 'Content-Type',
value => ''}));
! dies_ok { filter_action($CONTROLLER) } 'Expect redirect';
! isa_ok($@, 'HTTP::WebTest::Recorder::Exception::Redirect',
! 'Verify exception class');
! is($@->url, 'list', 'Test url property of exception');
ok(not(exists $RECORDER->filter->{header}{'Content-Type'}),
'Test if Content-Type header filter is removed');
--- 229,235 ----
field => 'Content-Type',
value => ''}));
! filter_action($CONTROLLER);
! is($CONTROLLER->heap->{response}->code, RC_FOUND);
! is($CONTROLLER->heap->{response}->header('Location'), 'list');
ok(not(exists $RECORDER->filter->{header}{'Content-Type'}),
'Test if Content-Type header filter is removed');
***************
*** 236,244 ****
field => 'Location',
value => '.'}));
! dies_ok { filter_action($CONTROLLER) } 'Expect redirect';
! isa_ok($@, 'HTTP::WebTest::Recorder::Exception::Redirect',
! 'Verify exception class');
! is($@->url, 'list', 'Test url property of exception');
is($RECORDER->filter->{header}{Location}, '.',
'Test if Location header filter is set');
}
--- 238,246 ----
field => 'Location',
value => '.'}));
! filter_action($CONTROLLER);
! is($CONTROLLER->heap->{response}->code, RC_FOUND);
! is($CONTROLLER->heap->{response}->header('Location'), 'list');
is($RECORDER->filter->{header}{Location}, '.',
'Test if Location header filter is set');
}
+
Index: 02-controller.t
===================================================================
RCS file: /cvsroot/http-webtest/HTTP-WebTest-Recorder/t/02-controller.t,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** 02-controller.t 2 Feb 2003 00:02:43 -0000 1.5
--- 02-controller.t 22 Apr 2003 21:44:26 -0000 1.6
***************
*** 6,11 ****
use HTTP::Status;
! use Test::More tests => 41;
! use Test::Exception;
# get test template files directory included in search path
--- 6,10 ----
use HTTP::Status;
! use Test::More tests => 29;
# get test template files directory included in search path
***************
*** 18,39 ****
isa_ok($CONTROLLER, 'HTTP::WebTest::Recorder::Controller');
- # try to get template toolkit object and process one of recorder's
- # templates through it
- {
- my $template = $CONTROLLER->template;
- isa_ok($template, 'Template');
-
- my $output = '';
- ok($template->process('testme', { var => 1 }, \$output),
- 'Try to process test template: ' . ($template->error || '') );
- like($output, qr/This is a test file/, 'Check output');
- like($output, qr/VAR = 1/, 'Check output');
-
- $output = '';
- ok($template->process('testme', { var => 'xxx' }, \$output),
- 'Try to process test template: ' . ($template->error || '') );
- like($output, qr/VAR = xxx/, 'Check output');
- }
-
# try to get CGI object
{
--- 17,20 ----
***************
*** 104,111 ****
# test redirect()
{
! dies_ok { $CONTROLLER->redirect('xxx') } 'Expecting redirect exception';
! isa_ok($@, 'HTTP::WebTest::Recorder::Exception::Redirect',
! 'Verify exception class');
! is($@->url, 'xxx', 'Test url property of exception');
}
--- 85,99 ----
# test redirect()
{
! $CONTROLLER->redirect('xxx');
! is($CONTROLLER->heap->{response}->code, RC_FOUND,
! 'Expect redirect status code');
! is($CONTROLLER->heap->{response}->header('Location'), 'xxx',
! 'Verify location header');
!
! $CONTROLLER->redirect('yyy');
! is($CONTROLLER->heap->{response}->code, RC_FOUND,
! 'Expect redirect status code');
! is($CONTROLLER->heap->{response}->header('Location'), 'yyy',
! 'Verify location header');
}
***************
*** 117,121 ****
return $controller->redirect('xxx');
};
! local %HTTP::WebTest::Recorder::Controller::DISPATCH =
( redirect => $test_redirect );
--- 105,110 ----
return $controller->redirect('xxx');
};
! local %HTTP::WebTest::Recorder::Controller::DISPATCH;
! %HTTP::WebTest::Recorder::Controller::DISPATCH =
( redirect => $test_redirect );
***************
*** 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');
}
--- 115,117 ----
|