version 1.1, 2010/01/23 07:04:43 |
version 1.4, 2010/02/13 22:15:29 |
|
|
# AUTHOR: Andrew Fresh (AAF), andrew@cpan.org |
# AUTHOR: Andrew Fresh (AAF), andrew@cpan.org |
# COMPANY: Red River Communications |
# COMPANY: Red River Communications |
# CREATED: 01/07/10 19:11 |
# CREATED: 01/07/10 19:11 |
# REVISION: $AFresh1$ |
# REVISION: $AFresh1: response.t,v 1.3 2010/02/13 21:46:13 andrew Exp $ |
#=============================================================================== |
#=============================================================================== |
|
|
use strict; |
use strict; |
use warnings; |
use warnings; |
|
|
use Test::More tests => 49; |
use Test::More tests => 101; |
|
|
my $class; |
my $class; |
|
|
|
|
|
|
my %data = ( |
my %data = ( |
files => ['todo.txt'], |
files => ['todo.txt'], |
list => [ |
list => [ |
{ text => 'uno', md5 => 'XXX md5 of uno XXX' }, |
{ text => 'uno', md5 => 'XXX md5 of uno XXX' }, |
{ text => 'dos', md5 => 'XXX md5 of dos XXX' }, |
{ text => 'dos', md5 => 'XXX md5 of dos XXX' }, |
{ text => 'tre', md5 => 'XXX md5 of tre XXX' }, |
{ text => 'tre', md5 => 'XXX md5 of tre XXX' }, |
], |
], |
entry => { text => 'ety', md5 => 'XXX md5 of ety XXX' }, |
|
|
tags => [ 'delete', 'dos', 'uno' ], |
|
entry => { text => 'ety', md5 => 'XXX md5 of ety XXX' }, |
); |
); |
|
|
my %TESTS = ( |
my %TESTS = ( |
|
|
result => '/^Unable to handle \[render_files\] for format \[\]/', |
result => '/^Unable to handle \[render_files\] for format \[\]/', |
}, |
}, |
text => { |
text => { |
result => undef, |
result => undef, |
data_result => "todo.txt\n" |
data_result => "todo.txt\n", |
|
content_type => 'text/plain', |
}, |
}, |
md5 => { |
md5 => { |
result => |
result => |
'/^Unable to handle \[render_files\] for format \[md5\]/', |
'/^Unable to handle \[render_files\] for format \[md5\]/', |
|
content_type => 'text/plain', |
}, |
}, |
|
json => { |
|
result => '[]', |
|
data_result => '["todo.txt"]', |
|
content_type => 'application/json', |
|
}, |
}, |
}, |
|
|
list => { |
list => { |
|
|
text => { |
text => { |
result => undef, |
result => undef, |
data_result => ( join q{}, map "$_->{text}\n", @{ $data{list} } ), |
data_result => ( join q{}, map "$_->{text}\n", @{ $data{list} } ), |
|
content_type => 'text/plain', |
}, |
}, |
md5 => { |
md5 => { |
result => undef, |
result => undef, |
data_result => ( join q{}, map "MD5 ($_->{text}) = $_->{md5}\n", |
data_result => ( |
@{ $data{list} } ), |
join q{}, |
|
map "MD5 ($_->{text}) = $_->{md5}\n", |
|
@{ $data{list} } |
|
), |
|
content_type => 'text/plain', |
}, |
}, |
|
json => { |
|
result => '[]', |
|
data_result => '[{"text":"uno","md5":"XXX md5 of uno XXX"},{"text":"dos","md5":"XXX md5 of dos XXX"},{"text":"tre","md5":"XXX md5 of tre XXX"}]', |
|
content_type => 'application/json', |
|
}, |
}, |
}, |
|
|
|
tags => { |
|
undef => { |
|
result => '/^Unable to handle \[render_tags\] for format \[\]/', |
|
}, |
|
text => { |
|
result => undef, |
|
data_result => ( join q{}, map "$_\n", @{ $data{tags} } ), |
|
content_type => 'text/plain', |
|
}, |
|
md5 => { |
|
result => undef, |
|
result => '/^Unable to handle \[render_tags\] for format \[md5\]/', |
|
content_type => 'text/plain', |
|
}, |
|
json => { |
|
result => '[]', |
|
data_result => '["delete","dos","uno"]', |
|
content_type => 'application/json', |
|
}, |
|
}, |
|
|
entry => { |
entry => { |
undef => { |
undef => { |
result => '/^Unable to handle \[render_entry\] for format \[\]/', |
result => '/^Unable to handle \[render_entry\] for format \[\]/', |
}, |
}, |
text => { |
text => { |
result => undef, |
result => undef, |
data_result => ( join q{}, map "$_->{text}\n", $data{entry} ), |
data_result => ( join q{}, map "$_->{text}\n", $data{entry} ), |
|
content_type => 'text/plain', |
}, |
}, |
md5 => { |
md5 => { |
result => undef, |
result => undef, |
data_result => ( join q{}, map "MD5 ($_->{text}) = $_->{md5}\n", |
data_result => ( |
$data{entry} ), |
join q{}, map "MD5 ($_->{text}) = $_->{md5}\n", |
|
$data{entry} |
|
), |
|
content_type => 'text/plain', |
}, |
}, |
|
json => { |
|
result => '[]', |
|
data_result => '{"text":"ety","md5":"XXX md5 of ety XXX"}', |
|
content_type => 'application/json', |
|
}, |
}, |
}, |
); |
); |
|
|
|
|
|
|
my $response = new_ok( $class, [$args] ); |
my $response = new_ok( $class, [$args] ); |
|
|
|
if ( exists $test->{content_type} ) { |
|
is( $response->content_type, $test->{content_type}, |
|
'Got content_type - ' . $diag ); |
|
} |
|
|
my $expected = $test->{result}; |
my $expected = $test->{result}; |
if ( $args->{data} && exists $test->{data_result} ) { |
if ( $args->{data} && exists $test->{data_result} ) { |
$expected = $test->{data_result}; |
$expected = $test->{data_result}; |
|
|
my $result; |
my $result; |
eval { $result = $response->render() }; |
eval { $result = $response->render() }; |
if ($@) { |
if ($@) { |
if (index $expected, '/') { |
if ( index $expected, '/' ) { |
$expected = '/^$/'; |
$expected = '/^$/'; |
} |
} |
|
|
|
|
else { |
else { |
is( $result, $expected, 'Got expected result - ' . $diag ); |
is( $result, $expected, 'Got expected result - ' . $diag ); |
} |
} |
|
|
return 1; |
return 1; |
} |
} |