Update of /cvsroot/http-webtest/HTTP-WebTest-Recorder/t
In directory sc8-pr-cvs1:/tmp/cvs-serv18476/t
Added Files:
03-actions.t
Removed Files:
03-action.t
Log Message:
Rename package Action to Actions
--- NEW FILE: 03-actions.t ---
#!/usr/bin/perl -w
use strict;
use HTTP::Request::Common;
use HTTP::Status;
use Test::More tests => 23;
use Test::Exception;
# get test template files directory included in search path
use lib 't';
require_ok('HTTP::WebTest::Recorder::Actions');
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::Actions::default_action($CONTROLLER)],
[controller => $CONTROLLER],
'Test template_data()');
}
# test list_action()
{
my %data = HTTP::WebTest::Recorder::Actions::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::Actions::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::Actions::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::Actions::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::Actions::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::Actions::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::Actions::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::Actions::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');
}
--- 03-action.t DELETED ---
|