aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/TestMech.pm
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 /perllib/FixMyStreet/TestMech.pm
parentbef1a31660bd3fccdda72cf2ca670c207a7a54c2 (diff)
move add and delete problem utility functions to test mech
add in non public problem tests for front page
Diffstat (limited to 'perllib/FixMyStreet/TestMech.pm')
-rw-r--r--perllib/FixMyStreet/TestMech.pm56
1 files changed, 56 insertions, 0 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;