diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2019-02-22 11:29:22 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2019-02-25 12:29:47 +0000 |
commit | fd5a8de180bd67fef7ce14c476ef0fd94c29ce19 (patch) | |
tree | 5b70ae898cfdce635edc58b7fd8fb05654750939 /t | |
parent | e481c2fd127c46024b1b15587981dca00eada44c (diff) |
Factor out test CSV content function.
Diffstat (limited to 't')
-rw-r--r-- | t/app/controller/dashboard.t | 14 | ||||
-rw-r--r-- | t/cobrand/bathnes.t | 22 | ||||
-rw-r--r-- | t/cobrand/fixmystreet.t | 7 |
3 files changed, 6 insertions, 37 deletions
diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index 37903513c..ff8d1a9d5 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -167,12 +167,7 @@ FixMyStreet::override_config { areas => ",$alt_area_id,2651,", }); $mech->get_ok('/dashboard?export=1'); - 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; - } + my @rows = $mech->content_as_csv; is scalar @rows, 19, '1 (header) + 18 (reports) = 19 lines'; is scalar @{$rows[0]}, 20, '20 columns present'; @@ -209,12 +204,7 @@ FixMyStreet::override_config { subtest 'export updates as csv' => sub { $mech->get_ok('/dashboard?updates=1&export=1'); - 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; - } + my @rows = $mech->content_as_csv; is scalar @rows, 15, '1 (header) + 14 (updates) = 15 lines'; is scalar @{$rows[0]}, 8, '8 columns present'; diff --git a/t/cobrand/bathnes.t b/t/cobrand/bathnes.t index 4db2f058c..6586dcb96 100644 --- a/t/cobrand/bathnes.t +++ b/t/cobrand/bathnes.t @@ -64,12 +64,7 @@ subtest 'extra CSV columns are absent if permission not granted' => sub { $mech->get_ok('/dashboard?export=1'); - 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; - } + my @rows = $mech->content_as_csv; is scalar @rows, 5, '1 (header) + 4 (reports) = 5 lines'; is scalar @{$rows[0]}, 20, '20 columns present'; @@ -125,12 +120,7 @@ subtest 'extra CSV columns are present if permission granted' => sub { $mech->get_ok('/dashboard?export=1'); - 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; - } + my @rows = $mech->content_as_csv; is scalar @rows, 5, '1 (header) + 4 (reports) = 5 lines'; is scalar @{$rows[0]}, 24, '24 columns present'; @@ -194,13 +184,7 @@ subtest 'extra CSV columns are present if permission granted' => sub { $mech->get_ok('/dashboard?export=1&updates=1'); - open $data_handle, '<', \$mech->content; - $csv = Text::CSV->new( { binary => 1 } ); - @rows = (); - while ( my $row = $csv->getline( $data_handle ) ) { - push @rows, $row; - } - + @rows = $mech->content_as_csv; is scalar @rows, 1, '1 (header) + 0 (updates)'; is scalar @{$rows[0]}, 10, '10 columns present'; is_deeply $rows[0], diff --git a/t/cobrand/fixmystreet.t b/t/cobrand/fixmystreet.t index 57ab51198..b47269db4 100644 --- a/t/cobrand/fixmystreet.t +++ b/t/cobrand/fixmystreet.t @@ -59,12 +59,7 @@ FixMyStreet::override_config { }); $mech->get_ok('/reports/Birmingham/summary?csv=1'); - 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; - } + my @rows = $mech->content_as_csv; is scalar @rows, 101, '1 (header) + 100 (reports) = 101 lines'; is scalar @{$rows[0]}, 10, '10 columns present'; |