aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2012-09-03 17:24:28 +0100
committerStruan Donald <struan@exo.org.uk>2012-09-03 17:24:28 +0100
commit350d82c314aa46367d0aba2b18e5858c9c46a025 (patch)
treeb1d589b467416fee5327ea0ed75906da49b656d1
parentbef1a31660bd3fccdda72cf2ca670c207a7a54c2 (diff)
move add and delete problem utility functions to test mech
add in non public problem tests for front page
-rw-r--r--perllib/FixMyStreet/TestMech.pm56
-rw-r--r--t/app/controller/index.t14
-rw-r--r--t/app/controller/reports.t63
3 files changed, 74 insertions, 59 deletions
diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm
index 53ec7ad89..dc08f0240 100644
--- a/perllib/FixMyStreet/TestMech.pm
+++ b/perllib/FixMyStreet/TestMech.pm
@@ -518,4 +518,60 @@ sub get_ok_json {
return decode_json( $res->content );
}
+sub delete_problems_for_council {
+ my $mech = shift;
+ my $council = shift;
+
+ my $reports = FixMyStreet::App->model('DB::Problem')->search( { council => $council } );
+ if ( $reports ) {
+ for my $r ( $reports->all ) {
+ $r->comments->delete;
+ }
+ $reports->delete;
+ }
+}
+
+sub create_problems_for_council {
+ my ( $mech, $count, $council, $title, $dt, $user ) = @_;
+
+ $dt = DateTime->now() unless $dt;
+
+ my @problems;
+
+ $user =
+ FixMyStreet::App->model('DB::User')
+ ->find_or_create( { email => 'test@example.com', name => 'Test User' } )
+ unless $user;;
+
+ while ( $count ) {
+ my $problem = FixMyStreet::App->model('DB::Problem')->create( {
+ postcode => 'SW1A 1AA',
+ council => $council,
+ areas => ',105255,11806,11828,2247,2504,',
+ category => 'Other',
+ title => "$title Test $count for $council",
+ detail => "$title Test $count for $council Detail",
+ used_map => 't',
+ name => 'Test User',
+ anonymous => 'f',
+ state => 'confirmed',
+ confirmed => $dt->ymd . ' ' . $dt->hms,
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 't',
+ latitude => '51.5016605453401',
+ longitude => '-0.142497580865087',
+ user_id => $user->id,
+ photo => 1,
+ } );
+
+ push @problems, $problem;
+ $count--;
+ }
+
+ return @problems;
+}
+
1;
diff --git a/t/app/controller/index.t b/t/app/controller/index.t
index bf9124ee0..52e8cbcd9 100644
--- a/t/app/controller/index.t
+++ b/t/app/controller/index.t
@@ -55,4 +55,18 @@ subtest "does pc, (x,y), (e,n) or (lat,lon) go to /around" => sub {
}
};
+$mech->delete_problems_for_council( 2651 );
+
+my @edinburgh_problems = $mech->create_problems_for_council(5, 2651, 'Front page');
+is scalar @edinburgh_problems, 5, 'correct number of edinburgh problems created';
+
+$mech->get_ok('/');
+$mech->content_contains('Front page Test 3 for 2651', 'problem to be marked non public visible');
+
+my $private = $edinburgh_problems[2];
+ok $private->update( { non_public => 1 } ), 'problem marked non public';
+
+$mech->get_ok('/');
+$mech->content_lacks('Front page Test 3 for 2651', 'non public problem is not visible');
+
done_testing();
diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t
index 5fd1a9962..a4dab6597 100644
--- a/t/app/controller/reports.t
+++ b/t/app/controller/reports.t
@@ -8,11 +8,11 @@ use DateTime;
ok( my $mech = FixMyStreet::TestMech->new, 'Created mech object' );
-delete_problems( 2504 );
-delete_problems( 2651 );
+$mech->delete_problems_for_council( 2504 );
+$mech->delete_problems_for_council( 2651 );
-my @westminster_problems = create_problems(5, 2504);
-my @edinburgh_problems = create_problems(3, 2651);
+my @edinburgh_problems = $mech->create_problems_for_council(3, 2651, 'All reports');
+my @westminster_problems = $mech->create_problems_for_council(5, 2504, 'All reports');
is scalar @westminster_problems, 5, 'correct number of westminster problems created';
is scalar @edinburgh_problems, 3, 'correct number of edinburgh problems created';
@@ -71,60 +71,5 @@ SKIP: {
$mech->content_unlike(qr{Oslo">Oslo.*Oslo}s);
}
-sub create_problems {
- my $count = shift;
- my $area_id = shift;
-
- my @problems;
-
- my $dt = DateTime->now;
-
- my $user =
- FixMyStreet::App->model('DB::User')
- ->find_or_create( { email => 'test@example.com', name => 'Test User' } );
-
- while ( $count ) {
- my $problem = FixMyStreet::App->model('DB::Problem')->create( {
- postcode => 'SW1A 1AA',
- council => $area_id,
- areas => ',105255,11806,11828,2247,2504,',
- category => 'Other',
- title => "All reports Test $count for $area_id",
- detail => "All reports Test $count for $area_id Detail",
- used_map => 't',
- name => 'Test User',
- anonymous => 'f',
- state => 'confirmed',
- confirmed => $dt->ymd . ' ' . $dt->hms,
- lang => 'en-gb',
- service => '',
- cobrand => 'default',
- cobrand_data => '',
- send_questionnaire => 't',
- latitude => '51.5016605453401',
- longitude => '-0.142497580865087',
- user_id => $user->id,
- } );
-
- push @problems, $problem;
- $count--;
- }
-
-
- return @problems;
-}
-
-sub delete_problems {
- my $area_id = shift;
-
- my $reports = FixMyStreet::App->model('DB::Problem')->search( { council => $area_id } );
- if ( $reports ) {
- for my $r ( $reports->all ) {
- $r->comments->delete;
- }
- $reports->delete;
- }
-}
-
done_testing();