diff options
author | Dave Arter <davea@mysociety.org> | 2014-04-30 10:42:33 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2014-04-30 10:46:14 +0100 |
commit | 39d3a68fe3e4bbc34193b2903a3a933d162678fe (patch) | |
tree | 70569ab0d2716526252730375a2b324d7446b99a | |
parent | d75e161c151c4f1e6dced24eae3170e01f9b7ba6 (diff) |
Test dashboard CSV export more thoroughly
Instead of counting the number of lines output by dashboard CSV export,
the content is parsed as CSV and the number of rows present is checked.
Also includes a problem report that's split across multiple lines, testing
the fix for mysociety/FixMyStreet-Commercial#494 introduced in
d75e161c151c4f1e6dced24eae3170e01f9b7ba6.
Closes #780.
-rw-r--r-- | t/app/controller/dashboard.t | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index a87232e9b..4e62028b5 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -609,9 +609,19 @@ FixMyStreet::override_config { } subtest 'export as csv' => sub { + make_problem( { + detail => "this report\nis split across\nseveral lines", + state => "confirmed", + conf_dt => DateTime->now(), + } ); $mech->get_ok('/dashboard?export=1'); - my @lines = split /\n/, $mech->content; - is scalar @lines, 6, '1 (header) + 5 (reports) = 6 lines'; + open my $data_handle, '<', \$mech->content; + my $csv = Text::CSV->new( { binary => 1 } ); + my @rows; + while ( my $row = $csv->getline( $data_handle ) ) { + push @rows, $row; + } + is scalar @rows, 7, '1 (header) + 6 (reports) = 7 lines'; }; }; restore_time; @@ -623,7 +633,7 @@ sub make_problem { title => 'a problem', name => 'a user', anonymous => 1, - detail => 'some detail', + detail => $args->{detail} || 'some detail', state => $args->{state}, confirmed => $args->{conf_dt}, whensent => $args->{conf_dt}, |