Update of /cvsroot/http-webtest/HTTP-WebTest-Recorder/t
In directory sc8-pr-cvs1:/tmp/cvs-serv17274/t
Modified Files:
03-action.t 02-controller.t
Removed Files:
07-action-enable.t 06-action-wtscript.t 05-action-request.t
04-action-list.t
Log Message:
Simplify design of actions by merging all action classes in single
action package with procedural style subs
Index: 03-action.t
===================================================================
RCS file: /cvsroot/http-webtest/HTTP-WebTest-Recorder/t/03-action.t,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** 03-action.t 25 Jan 2003 14:54:51 -0000 1.3
--- 03-action.t 1 Feb 2003 22:25:32 -0000 1.4
***************
*** 6,10 ****
use HTTP::Status;
! use Test::More tests => 5;
# get test template files directory included in search path
--- 6,11 ----
use HTTP::Status;
! use Test::More tests => 23;
! use Test::Exception;
# get test template files directory included in search path
***************
*** 13,27 ****
require_ok('HTTP::WebTest::Recorder::Action');
require_ok('HTTP::WebTest::Recorder::Controller');
# test constructors
- my $ACTION = new HTTP::WebTest::Recorder::Action;
- isa_ok($ACTION, 'HTTP::WebTest::Recorder::Action');
my $CONTROLLER = new HTTP::WebTest::Recorder::Controller;
isa_ok($CONTROLLER, 'HTTP::WebTest::Recorder::Controller');
! # test execute()
{
! is_deeply([$ACTION->execute($CONTROLLER)],
! [action => $ACTION, controller => $CONTROLLER],
'Test template_data()');
}
--- 14,158 ----
require_ok('HTTP::WebTest::Recorder::Action');
require_ok('HTTP::WebTest::Recorder::Controller');
+ require_ok('HTTP::WebTest::Recorder');
# test constructors
my $CONTROLLER = new HTTP::WebTest::Recorder::Controller;
isa_ok($CONTROLLER, 'HTTP::WebTest::Recorder::Controller');
+ my $RECORDER = new HTTP::WebTest::Recorder;
+ isa_ok($RECORDER, 'HTTP::WebTest::Recorder');
+ $CONTROLLER->recorder($RECORDER);
! # test default_action()
{
! is_deeply([HTTP::WebTest::Recorder::Action::default_action($CONTROLLER)],
! [controller => $CONTROLLER],
'Test template_data()');
+ }
+
+ # test list_action()
+ {
+ my %data = HTTP::WebTest::Recorder::Action::list_action($CONTROLLER);
+ is($data{tests}, $RECORDER->tests,
+ 'Check if "tests" variable is defined');
+ }
+
+ # init recorder with some data
+ {
+ my $test1 = HTTP::WebTest::Test->new;
+ $test1->request(GET 'http://example.com/doc1.html');
+ $test1->response(HTTP::Response->new(RC_OK));
+ $test1->response->content('DOC #1');
+
+ my $test2 = HTTP::WebTest::Test->new;
+ $test2->request(POST 'http://example.com/doc2.html',
+ [ xx => 'yy', 1 => 2]);
+ $test2->response(HTTP::Response->new(RC_NOT_FOUND));
+ $test2->response->content('Not Found');
+
+ push @{$RECORDER->tests}, $test1, $test2;
+ }
+
+ # test request_action()
+ {
+ $CONTROLLER->cgi(CGI->new({num => 0}));
+ my %data = HTTP::WebTest::Recorder::Action::request_action($CONTROLLER);
+ is($data{test}, $RECORDER->tests->[0],
+ 'Check if "test" variable is defined');
+
+ $CONTROLLER->cgi(CGI->new({num => 1}));
+ %data = HTTP::WebTest::Recorder::Action::request_action($CONTROLLER);
+ is($data{test}, $RECORDER->tests->[1],
+ 'Check if "test" variable is defined');
+
+ $CONTROLLER->cgi(CGI->new({num => 2}));
+ %data = HTTP::WebTest::Recorder::Action::request_action($CONTROLLER);
+ is($data{test}, undef,
+ 'Check if "test" variable is not defined');
+ }
+
+ # reinit recorder with some test data
+ {
+ $RECORDER->tests([]);
+ my $request = GET 'http://example.com/doc1.html';
+ my $response = HTTP::Response->new(RC_OK);
+ $response->content('DOC #1');
+ push @{$RECORDER->tests}, $RECORDER->make_test($request, $response);
+ }
+ {
+ my $request = (POST 'http://example.com/doc2.html',
+ [ xx => 'yy', 1 => 2]);
+ my $response = HTTP::Response->new(RC_NOT_FOUND);
+ $response->content('Not Found');
+ push @{$RECORDER->tests}, $RECORDER->make_test($request, $response);
+ }
+ {
+ my $request = GET 'http://example.com/doc3.html?a=b&a=c';
+ my $response = HTTP::Response->new(RC_OK);
+ $response->content('DOC #2');
+ push @{$RECORDER->tests}, $RECORDER->make_test($request, $response);
+ }
+
+ # test wtscript_action()
+ {
+ my %data = HTTP::WebTest::Recorder::Action::wtscript_action($CONTROLLER);
+ is($data{wtscript}, <<'WTSCRIPT',
+ test_name = N/A
+ url = http://example.com/doc1.html
+ end_test
+
+ test_name = N/A
+ method = POST
+ params = (
+ xx
+ yy
+ 1
+ 2
+ )
+ url = http://example.com/doc2.html
+ end_test
+
+ test_name = N/A
+ params = (
+ a
+ b
+ a
+ c
+ )
+ url = http://example.com/doc3.html
+ end_test
+ WTSCRIPT
+ 'Check if "wtscript" variable is defined');
+ }
+
+ # test with enable_action() if we can turn on recording
+ {
+ $CONTROLLER->cgi(CGI->new({ enable => 1 }));
+ dies_ok { HTTP::WebTest::Recorder::Action::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');
+ }
+
+ # test with enable_action() if we can turn off recording
+ {
+ $CONTROLLER->cgi(CGI->new({ enable => 0 }));
+ dies_ok { HTTP::WebTest::Recorder::Action::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');
+ }
+
+ # test with enable_action() if we can turn on recording once again
+ {
+ $CONTROLLER->cgi(CGI->new({ enable => 1 }));
+ dies_ok { HTTP::WebTest::Recorder::Action::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');
}
Index: 02-controller.t
===================================================================
RCS file: /cvsroot/http-webtest/HTTP-WebTest-Recorder/t/02-controller.t,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** 02-controller.t 25 Jan 2003 14:54:51 -0000 1.3
--- 02-controller.t 1 Feb 2003 22:25:32 -0000 1.4
***************
*** 112,130 ****
# try to access page that generates a redirect
{
local %HTTP::WebTest::Recorder::Controller::DISPATCH =
! ( redirect => 'TestRedirect' );
# just to disable used only once warning
() = %HTTP::WebTest::Recorder::Controller::DISPATCH;
- {
- package TestRedirect;
- use base qw(HTTP::WebTest::Recorder::Action);
-
- sub execute {
- my $self = shift;
- my $controller = shift;
- return $controller->redirect('xxx');
- }
- }
my $request = GET 'http://localhost/webtest/redirect';
my $response = $CONTROLLER->execute(action => 'redirect',
--- 112,125 ----
# try to access page that generates a redirect
{
+ my $test_redirect = sub {
+ my $controller = shift;
+
+ return $controller->redirect('xxx');
+ };
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';
my $response = $CONTROLLER->execute(action => 'redirect',
--- 07-action-enable.t DELETED ---
--- 06-action-wtscript.t DELETED ---
--- 05-action-request.t DELETED ---
--- 04-action-list.t DELETED ---
|