From b1e96e396f27a9636c2a0ee6bc25311ba6175f43 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 30 Aug 2013 20:44:47 +0100 Subject: Update test to match text change in June. Silly me. --- t/cobrand/zurich.t | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 't/cobrand') diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index 5d7ff8672..d61ec2ae0 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -210,7 +210,7 @@ $mech->submit_form_ok( { with_fields => { body_external => 4 } } ); $mech->get_ok( '/report/' . $report->id ); $mech->content_contains('Beantwortet'); $mech->content_contains('Third Test'); -$mech->content_contains('Weitergeleitet an: External Body'); +$mech->content_contains('Wir haben Ihr Anliegen an External Body weitergeleitet'); FixMyStreet::App->model('DB::Problem')->send_reports('zurich'); $email = $mech->get_email; like $email->header('Subject'), qr/Weitergeleitete Meldung/, 'subject looks okay'; @@ -229,7 +229,7 @@ $mech->submit_form_ok( { with_fields => { body_external => 4, third_personal => $mech->get_ok( '/report/' . $report->id ); $mech->content_contains('Beantwortet'); $mech->content_contains('Third Test'); -$mech->content_contains('Weitergeleitet an: External Body'); +$mech->content_contains('Wir haben Ihr Anliegen an External Body weitergeleitet'); FixMyStreet::App->model('DB::Problem')->send_reports('zurich'); $email = $mech->get_email; like $email->header('Subject'), qr/Weitergeleitete Meldung/, 'subject looks okay'; -- cgit v1.2.3 From 4f1d340588ead562a332993d88690518d0ac3886 Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Tue, 3 Sep 2013 16:49:54 +0100 Subject: [Zurich] Add test for superuser body editing --- t/cobrand/zurich.t | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 't/cobrand') diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index d61ec2ae0..87477b9f8 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -237,6 +237,13 @@ like $email->header('To'), qr/external_body\@example.org/, 'to line looks correc like $email->body, qr/External Body/, 'body has right name'; like $email->body, qr/test\@example.com/, 'body does contain email address'; $mech->clear_emails_ok; +$mech->log_out_ok; + +# Test only superuser can edit bodies +$user = $mech->log_in_ok( 'dm1@example.org') ; +$mech->get( '/admin/body/' . $zurich->id ); +is $mech->res->code, 404, "only superuser should be able to edit bodies"; +$mech->log_out_ok; $mech->delete_problems_for_body( 2 ); $mech->delete_user( 'dm1@example.org' ); -- cgit v1.2.3 From 17e8f2fee732202a7412e4d266408ba3e73b16c2 Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Wed, 4 Sep 2013 12:38:55 +0100 Subject: [Zurich] Test for only superusers can add bodies --- t/cobrand/zurich.t | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 't/cobrand') diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index 87477b9f8..97e525981 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -245,6 +245,12 @@ $mech->get( '/admin/body/' . $zurich->id ); is $mech->res->code, 404, "only superuser should be able to edit bodies"; $mech->log_out_ok; +# Test only superuser can add bodies +$user = $mech->log_in_ok( 'dm1@example.org') ; +$mech->get( '/admin/bodies' ); +$mech->content_lacks( '
log_out_ok; + $mech->delete_problems_for_body( 2 ); $mech->delete_user( 'dm1@example.org' ); $mech->delete_user( 'sdm1@example.org' ); -- cgit v1.2.3 From 90a46767b4a3ce828ff74c15a1691502d1514575 Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Wed, 4 Sep 2013 14:31:05 +0100 Subject: [Zurich] Use get_ok for superuser adding bodies test --- t/cobrand/zurich.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/cobrand') diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index 97e525981..8cb3a6c65 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -247,7 +247,7 @@ $mech->log_out_ok; # Test only superuser can add bodies $user = $mech->log_in_ok( 'dm1@example.org') ; -$mech->get( '/admin/bodies' ); +$mech->get_ok( '/admin/bodies' ); $mech->content_lacks( 'log_out_ok; -- cgit v1.2.3 From 82d1ef966c63cd5517d9f5e4b476634c48acdc4d Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Wed, 4 Sep 2013 16:27:13 +0100 Subject: Fix comment in tests --- t/cobrand/zurich.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/cobrand') diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index 8cb3a6c65..721e6517a 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -245,7 +245,7 @@ $mech->get( '/admin/body/' . $zurich->id ); is $mech->res->code, 404, "only superuser should be able to edit bodies"; $mech->log_out_ok; -# Test only superuser can add bodies +# Test only superuser can see "Add body" form $user = $mech->log_in_ok( 'dm1@example.org') ; $mech->get_ok( '/admin/bodies' ); $mech->content_lacks( ' Date: Thu, 5 Sep 2013 11:06:23 +0100 Subject: [Zurich] Fix spacing in tests --- t/cobrand/zurich.t | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 't/cobrand') diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index 721e6517a..ef207421b 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -240,13 +240,13 @@ $mech->clear_emails_ok; $mech->log_out_ok; # Test only superuser can edit bodies -$user = $mech->log_in_ok( 'dm1@example.org') ; +$user = $mech->log_in_ok( 'dm1@example.org' ); $mech->get( '/admin/body/' . $zurich->id ); is $mech->res->code, 404, "only superuser should be able to edit bodies"; $mech->log_out_ok; # Test only superuser can see "Add body" form -$user = $mech->log_in_ok( 'dm1@example.org') ; +$user = $mech->log_in_ok( 'dm1@example.org' ); $mech->get_ok( '/admin/bodies' ); $mech->content_lacks( 'log_out_ok; -- cgit v1.2.3 From 2e925df7a1ffac90bc29ef7fa67dcf6bd1648a9d Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Thu, 5 Sep 2013 13:39:01 +0100 Subject: [Zurich] Add test for missing phone number --- t/cobrand/zurich.t | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 't/cobrand') diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index ef207421b..69cf82db9 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -251,6 +251,13 @@ $mech->get_ok( '/admin/bodies' ); $mech->content_lacks( 'log_out_ok; +# Test phone number is mandatory +$user = $mech->log_in_ok( 'dm1@example.org' ); +$mech->get_ok( '/report/new?latitude=51.500802;longitude=-0.143005' ); +$mech->submit_form( with_fields => { phone => "" } ); +$mech->content_contains( 'Diese Information wird benötigt' ); +$mech->log_out_ok; + $mech->delete_problems_for_body( 2 ); $mech->delete_user( 'dm1@example.org' ); $mech->delete_user( 'sdm1@example.org' ); -- cgit v1.2.3 From e4763fa9b0a2f12c9538b013420f7f29dbb4496a Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Thu, 5 Sep 2013 12:36:03 +0100 Subject: [Zurich] Notes on steps required to get zurich tests to run --- t/cobrand/zurich.t | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 't/cobrand') diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index 721e6517a..9d9ffea7e 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -9,6 +9,24 @@ use Test::More; plan skip_all => 'Skipping Zurich test without Zurich cobrand' unless FixMyStreet::Cobrand->exists('zurich'); +# To run this test ensure that you have the following in general.yml: +# +# BASE_URL: 'http://zurich.127.0.0.1.xip.io' +# +# ALLOWED_COBRANDS: +# - zurich +# +# SEND_REPORTS_ON_STAGING: 1 +# +# Check that you have the required locale installed - the following +# should return a line with de_CH.utf8 in. If not install that locale. +# +# locale -a | grep de_CH +# +# To generate the translations use: +# +# commonlib/bin/gettext-makemo FixMyStreet + use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -44,6 +62,9 @@ my @reports = $mech->create_problems_for_body( 1, 2, 'Test', { my $report = $reports[0]; $mech->get_ok( '/report/' . $report->id ); +#diag "------------------------------\n"; +#diag $mech->content(); +#diag "------------------------------\n"; $mech->content_contains('Überprüfung ausstehend'); # Check logging in to deal with this report -- cgit v1.2.3 From a58b3d800651ea15cfc4b3b0284ea9657e52ea01 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Thu, 5 Sep 2013 12:39:30 +0100 Subject: [Zurich] remove debugging from test --- t/cobrand/zurich.t | 3 --- 1 file changed, 3 deletions(-) (limited to 't/cobrand') diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index 9d9ffea7e..a583a2ec2 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -62,9 +62,6 @@ my @reports = $mech->create_problems_for_body( 1, 2, 'Test', { my $report = $reports[0]; $mech->get_ok( '/report/' . $report->id ); -#diag "------------------------------\n"; -#diag $mech->content(); -#diag "------------------------------\n"; $mech->content_contains('Überprüfung ausstehend'); # Check logging in to deal with this report -- cgit v1.2.3 From c1f3b7df4055fc15df1afefd47482f24c5f9fc04 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Thu, 5 Sep 2013 14:56:35 +0100 Subject: Override the config so that Zurich tests can be run with normal dev config --- t/cobrand/zurich.t | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) (limited to 't/cobrand') diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index a583a2ec2..d45ae1f4d 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -5,6 +5,7 @@ use strict; use warnings; use DateTime; use Test::More; +use Sub::Override; plan skip_all => 'Skipping Zurich test without Zurich cobrand' unless FixMyStreet::Cobrand->exists('zurich'); @@ -16,8 +17,6 @@ plan skip_all => 'Skipping Zurich test without Zurich cobrand' # ALLOWED_COBRANDS: # - zurich # -# SEND_REPORTS_ON_STAGING: 1 -# # Check that you have the required locale installed - the following # should return a line with de_CH.utf8 in. If not install that locale. # @@ -27,6 +26,39 @@ plan skip_all => 'Skipping Zurich test without Zurich cobrand' # # commonlib/bin/gettext-makemo FixMyStreet + +# This is a helper method that will send the reports but with the config +# correctly set - notably SEND_REPORTS_ON_STAGING needs to be true. +sub send_reports_for_zurich { + + # Capture the bits of the original config that the following code will use + my %config = + map {$_ => mySociety::Config::get($_)} + qw(BASE_URL STAGING_SITE CONTACT_EMAIL SEND_REPORTS_ON_STAGING); + + # Change the SEND_REPORTS_ON_STAGING value to true for this test + $config{SEND_REPORTS_ON_STAGING} = 1; + + # Override the get function to return values from our captured config. This + # override will be cleared at the end of this block when the $override guard + # falls out of scope. + my $override_guard = Sub::Override->new( + "mySociety::Config::get", + sub ($;$) { + my ($key, $default) = @_; + exists $config{$key} + ? return $config{$key} + : die "Need to cache config key '$key' here"; + } + ); + + # Actually send the report + FixMyStreet::App->model('DB::Problem')->send_reports('zurich'); + + # tidy up explicitly + $override_guard->restore(); +} + use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -115,7 +147,7 @@ $mech->get_ok( '/report/' . $report->id ); $mech->content_contains('In Bearbeitung'); $mech->content_contains('Test Test'); -FixMyStreet::App->model('DB::Problem')->send_reports('zurich'); +send_reports_for_zurich(); my $email = $mech->get_email; like $email->header('Subject'), qr/Neue Meldung/, 'subject looks okay'; like $email->header('To'), qr/subdivision\@example.org/, 'to line looks correct'; @@ -150,7 +182,7 @@ $mech->get_ok( '/report/' . $report->id ); $mech->content_contains('In Bearbeitung'); $mech->content_contains('Test Test'); -FixMyStreet::App->model('DB::Problem')->send_reports('zurich'); +send_reports_for_zurich(); $email = $mech->get_email; like $email->header('Subject'), qr/Feedback/, 'subject looks okay'; like $email->header('To'), qr/division\@example.org/, 'to line looks correct'; @@ -229,7 +261,7 @@ $mech->get_ok( '/report/' . $report->id ); $mech->content_contains('Beantwortet'); $mech->content_contains('Third Test'); $mech->content_contains('Wir haben Ihr Anliegen an External Body weitergeleitet'); -FixMyStreet::App->model('DB::Problem')->send_reports('zurich'); +send_reports_for_zurich(); $email = $mech->get_email; like $email->header('Subject'), qr/Weitergeleitete Meldung/, 'subject looks okay'; like $email->header('To'), qr/external_body\@example.org/, 'to line looks correct'; @@ -248,7 +280,7 @@ $mech->get_ok( '/report/' . $report->id ); $mech->content_contains('Beantwortet'); $mech->content_contains('Third Test'); $mech->content_contains('Wir haben Ihr Anliegen an External Body weitergeleitet'); -FixMyStreet::App->model('DB::Problem')->send_reports('zurich'); +send_reports_for_zurich(); $email = $mech->get_email; like $email->header('Subject'), qr/Weitergeleitete Meldung/, 'subject looks okay'; like $email->header('To'), qr/external_body\@example.org/, 'to line looks correct'; -- cgit v1.2.3 From 8e7e991b7fa4a99104a5b49244d034c96ce07222 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Thu, 5 Sep 2013 16:20:06 +0100 Subject: Don't use a domain name when testing that the default ALLOWED_COBRANDS will match to the wrong cobrand. --- t/cobrand/zurich.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/cobrand') diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index d45ae1f4d..cb0a312cc 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -63,7 +63,7 @@ use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; # Front page test -ok $mech->host("zurich.fixmystreet.com"), "change host to Zurich"; +ok $mech->host("zurich.example.com"), "change host to Zurich"; $mech->get_ok('/'); $mech->content_like( qr/zurich/i ); -- cgit v1.2.3 From 7f575d1cf3af5673efb6996beafbe91e0e505f72 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Mon, 9 Sep 2013 12:00:48 +0100 Subject: Handle user already existing (as it may in dev) --- t/cobrand/zurich.t | 1 + 1 file changed, 1 insertion(+) (limited to 't/cobrand') diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index cb0a312cc..77a754cd1 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -156,6 +156,7 @@ $mech->clear_emails_ok; $mech->log_out_ok; $user = $mech->log_in_ok( 'sdm1@example.org') ; +$user->update({ from_body => undef }); $mech->get_ok( '/admin' ); is $mech->uri->path, '/my', "got sent to /my"; $user->from_body( 3 ); -- cgit v1.2.3 From bd0e4f640a265eaaab1a90d2a64c1f5db6f81e87 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Mon, 9 Sep 2013 15:45:04 +0100 Subject: [Zurich] Save internal notes as hidden comments, rather than in the extra field --- t/cobrand/zurich.t | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 't/cobrand') diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index 77a754cd1..790a0c3c5 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -132,8 +132,10 @@ $mech->content_contains('photo/' . $report->id . '.jpeg'); # Internal notes $mech->get_ok( '/admin/report_edit/' . $report->id ); -$mech->submit_form_ok( { with_fields => { internal_notes => 'Some internal notes.' } } ); -$mech->content_contains( 'Some internal notes' ); +$mech->submit_form_ok( { with_fields => { new_internal_note => 'Initial internal note.' } } ); +$mech->submit_form_ok( { with_fields => { new_internal_note => 'Another internal note.' } } ); +$mech->content_contains( 'Initial internal note.' ); +$mech->content_contains( 'Another internal note.' ); # Original description $mech->submit_form_ok( { with_fields => { detail => 'Edited details text.' } } ); @@ -170,7 +172,7 @@ $mech->content_contains( DateTime->now->strftime("%d.%m.%Y") ); $mech->content_contains( 'In Bearbeitung' ); $mech->get_ok( '/admin/report_edit/' . $report->id ); -$mech->content_contains( 'Some internal notes' ); +$mech->content_contains( 'Initial internal note' ); $mech->submit_form_ok( { with_fields => { status_update => 'This is an update.' } } ); is $mech->uri->path, '/admin/report_edit/' . $report->id, "still on edit page"; -- cgit v1.2.3 From ca4487b3b161b857ef5412f93ecd60646697ff2d Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Wed, 11 Sep 2013 14:32:17 +0100 Subject: [Zurich] Test deleted bodies can't have problems assigned --- t/cobrand/zurich.t | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 't/cobrand') diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index 721e6517a..be94d4112 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -251,6 +251,20 @@ $mech->get_ok( '/admin/bodies' ); $mech->content_lacks( 'log_out_ok; +# Test problems can't be assigned to deleted bodies +$user = $mech->log_in_ok( 'dm1@example.org' ); +$user->from_body( 1 ); +$user->update; +$report->state( 'confirmed' ); +$report->update; +$mech->get_ok( '/admin/body/' . $external_body->id ); +$mech->submit_form_ok( { with_fields => { deleted => 1 } } ); +$mech->get_ok( '/admin/report_edit/' . $report->id ); +$mech->content_lacks( $external_body->name ); +$user->from_body( 2 ); +$user->update; +$mech->log_out_ok; + $mech->delete_problems_for_body( 2 ); $mech->delete_user( 'dm1@example.org' ); $mech->delete_user( 'sdm1@example.org' ); -- cgit v1.2.3 From b97bfa3f95466c008af8236aca0537d224446c0e Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Wed, 11 Sep 2013 14:59:03 +0100 Subject: [Zurich] Add tests for changing categories in the admin interface --- t/cobrand/zurich.t | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 't/cobrand') diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index 790a0c3c5..cd826a8d3 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -115,6 +115,44 @@ $mech->content_contains( 'report_edit/' . $report->id ); $mech->content_contains( DateTime->now->strftime("%d.%m.%Y") ); $mech->content_contains( 'Erfasst' ); + +subtest "changing of categories" => sub { + # create a few categories (which are actually contacts) + foreach my $name ( qw/Cat1 Cat2/ ) { + FixMyStreet::App->model('DB::Contact')->find_or_create({ + body => $division, + category => $name, + email => "$name\@example.org", + confirmed => 1, + deleted => 0, + editor => "editor", + whenedited => DateTime->now(), + note => "note for $name", + }); + } + + # put report into know category + my $original_category = $report->category; + $report->update({ category => 'Cat1' }); + is( $report->category, "Cat1", "Category set to Cat1" ); + + # get the latest comment + my $comments_rs = $report->comments->search({},{ order_by => { -desc => "created" } }); + my $pre_change_comment = $comments_rs->first; + + # change the category via the web interface + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->submit_form_ok( { with_fields => { category => 'Cat2' } } ); + + # check changes correctly saved + $report->discard_changes(); + is( $report->category, "Cat2", "Category changed to Cat2 as expected" ); + + # restore report to original state. + $report->update({category => $original_category }); +}; + + $mech->get_ok( '/admin/report_edit/' . $report->id ); $mech->content_contains( 'Unbestätigt' ); # Unconfirmed email $mech->submit_form_ok( { with_fields => { state => 'confirmed' } } ); -- cgit v1.2.3 From dec287591b28d4e2eff79f763306168125d6981a Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Wed, 11 Sep 2013 15:24:18 +0100 Subject: [Zurich] create internal note when the category is changed --- t/cobrand/zurich.t | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 't/cobrand') diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index cd826a8d3..a6cf934ef 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -1,5 +1,5 @@ # TODO -# Overdue alerts +# Overdue alerts use strict; use warnings; @@ -131,14 +131,14 @@ subtest "changing of categories" => sub { }); } - # put report into know category + # put report into known category my $original_category = $report->category; $report->update({ category => 'Cat1' }); is( $report->category, "Cat1", "Category set to Cat1" ); # get the latest comment my $comments_rs = $report->comments->search({},{ order_by => { -desc => "created" } }); - my $pre_change_comment = $comments_rs->first; + ok ( !$comments_rs->first, "There are no comments yet" ); # change the category via the web interface $mech->get_ok( '/admin/report_edit/' . $report->id ); @@ -148,6 +148,10 @@ subtest "changing of categories" => sub { $report->discard_changes(); is( $report->category, "Cat2", "Category changed to Cat2 as expected" ); + # Check that a new comment has been created. + my $new_comment = $comments_rs->first(); + is( $new_comment->text, "Weitergeleitet von Cat1 an Cat2", "category change comment created" ); + # restore report to original state. $report->update({category => $original_category }); }; -- cgit v1.2.3 From 1f5c75fde567bccca3d51ad57bc8f01274e8d114 Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Wed, 11 Sep 2013 18:35:21 +0100 Subject: [Zurich] Test rejected email are only sent when requested --- t/cobrand/zurich.t | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 't/cobrand') diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index 721e6517a..875a4262c 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -251,6 +251,22 @@ $mech->get_ok( '/admin/bodies' ); $mech->content_lacks( 'log_out_ok; +# Test hidden report email are only sent when requested +$user = $mech->log_in_ok( 'dm1@example.org') ; +my $extra = $report->extra; +$extra->{email_confirmed} = 1; +$report->extra ( { %$extra } ); +$report->update; +$mech->get_ok( '/admin/report_edit/' . $report->id ); +$mech->submit_form_ok( { with_fields => { state => 'hidden', send_rejected_email => 1 } } ); +$mech->email_count_is(1); +$mech->clear_emails_ok; +$mech->get_ok( '/admin/report_edit/' . $report->id ); +$mech->submit_form_ok( { with_fields => { state => 'hidden', send_rejected_email => undef } } ); +$mech->email_count_is(0); +$mech->clear_emails_ok; +$mech->log_out_ok; + $mech->delete_problems_for_body( 2 ); $mech->delete_user( 'dm1@example.org' ); $mech->delete_user( 'sdm1@example.org' ); -- cgit v1.2.3 From e3de0d9bd0252e45e5c49b49fbbeed6843162196 Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Thu, 12 Sep 2013 16:36:04 +0100 Subject: [Zurich] Try to override config in tests --- t/cobrand/zurich.t | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 't/cobrand') diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index 6039017e9..0975096db 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -348,9 +348,33 @@ $mech->log_out_ok; # Test phone number is mandatory $user = $mech->log_in_ok( 'dm1@example.org' ); -$mech->get_ok( '/report/new?latitude=51.500802;longitude=-0.143005' ); + +# Capture the bits of the original config that the following code will use +my %config = + map {$_ => FixMyStreet->config($_)} + qw(ALLOWED_COBRANDS FMS_DB_NAME MAPIT_ID_WHITELIST STAGING_SITE); + +# Change the MAPIT_TYPES value for this test +$config{MAPIT_TYPES} = [ 'O08' ]; +$config{MAPIT_URL} = 'http://global.mapit.mysociety.org/'; + +# Override the get function to return values from our captured config. This +# override will be cleared at the end of this block when the $override guard +# falls out of scope. +my $override_guard = Sub::Override->new( + "FixMyStreet::config", + sub { + my ($self, $key, $default) = @_; + exists $config{$key} + ? return $config{$key} + : die "Need to cache config key '$key' here"; + } +); + +$mech->get_ok( '/report/new?lat=47.381817&lon=8.529156' ); $mech->submit_form( with_fields => { phone => "" } ); $mech->content_contains( 'Diese Information wird benötigt' ); +$override_guard->restore(); $mech->log_out_ok; # Test problems can't be assigned to deleted bodies -- cgit v1.2.3 From 008754424d027a7cdefa4a2f09c4cb937d972693 Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Thu, 12 Sep 2013 17:05:55 +0100 Subject: [Zurich] Make sure mapit url is set properly --- t/cobrand/zurich.t | 1 + 1 file changed, 1 insertion(+) (limited to 't/cobrand') diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index 0975096db..d7e63c84e 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -357,6 +357,7 @@ my %config = # Change the MAPIT_TYPES value for this test $config{MAPIT_TYPES} = [ 'O08' ]; $config{MAPIT_URL} = 'http://global.mapit.mysociety.org/'; +mySociety::MaPit::configure($config{MAPIT_URL}); # Override the get function to return values from our captured config. This # override will be cleared at the end of this block when the $override guard -- cgit v1.2.3 From 04cfac32dd1914fef76f8c9df272f686f880890c Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Thu, 12 Sep 2013 17:08:46 +0100 Subject: [Zurich] Put the phone number test into a subtest block --- t/cobrand/zurich.t | 59 +++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) (limited to 't/cobrand') diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index d7e63c84e..40baa4f04 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -346,37 +346,38 @@ $mech->get_ok( '/admin/bodies' ); $mech->content_lacks( 'log_out_ok; -# Test phone number is mandatory -$user = $mech->log_in_ok( 'dm1@example.org' ); +subtest "phone number is mandatory" => sub { + # Capture the bits of the original config that the following code will use + my %config = + map {$_ => FixMyStreet->config($_)} + qw(ALLOWED_COBRANDS FMS_DB_NAME MAPIT_ID_WHITELIST STAGING_SITE); -# Capture the bits of the original config that the following code will use -my %config = - map {$_ => FixMyStreet->config($_)} - qw(ALLOWED_COBRANDS FMS_DB_NAME MAPIT_ID_WHITELIST STAGING_SITE); - -# Change the MAPIT_TYPES value for this test -$config{MAPIT_TYPES} = [ 'O08' ]; -$config{MAPIT_URL} = 'http://global.mapit.mysociety.org/'; -mySociety::MaPit::configure($config{MAPIT_URL}); - -# Override the get function to return values from our captured config. This -# override will be cleared at the end of this block when the $override guard -# falls out of scope. -my $override_guard = Sub::Override->new( - "FixMyStreet::config", - sub { - my ($self, $key, $default) = @_; - exists $config{$key} - ? return $config{$key} - : die "Need to cache config key '$key' here"; - } -); + # Change the MAPIT_TYPES and MAPIT_URL values for this test + $config{MAPIT_TYPES} = [ 'O08' ]; + $config{MAPIT_URL} = 'http://global.mapit.mysociety.org/'; + mySociety::MaPit::configure($config{MAPIT_URL}); -$mech->get_ok( '/report/new?lat=47.381817&lon=8.529156' ); -$mech->submit_form( with_fields => { phone => "" } ); -$mech->content_contains( 'Diese Information wird benötigt' ); -$override_guard->restore(); -$mech->log_out_ok; + # Override the get function to return values from our captured config. This + # override will be cleared at the end of this block when the $override guard + # falls out of scope. + my $override_guard = Sub::Override->new( + "FixMyStreet::config", + sub { + my ($self, $key, $default) = @_; + exists $config{$key} + ? return $config{$key} + : die "Need to cache config key '$key' here"; + } + ); + + $user = $mech->log_in_ok( 'dm1@example.org' ); + $mech->get_ok( '/report/new?lat=47.381817&lon=8.529156' ); + $mech->submit_form( with_fields => { phone => "" } ); + $mech->content_contains( 'Diese Information wird benötigt' ); + $mech->log_out_ok; + + $override_guard->restore(); +}; # Test problems can't be assigned to deleted bodies $user = $mech->log_in_ok( 'dm1@example.org' ); -- cgit v1.2.3 From 1aca7d00c5a780824c9e0f1b1615d2fa96fa1506 Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Thu, 12 Sep 2013 17:25:15 +0100 Subject: [Zurich] Use subtest blocks to seperate test cases --- t/cobrand/zurich.t | 83 +++++++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 39 deletions(-) (limited to 't/cobrand') diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index 40baa4f04..fb9b24678 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -334,23 +334,25 @@ like $email->body, qr/test\@example.com/, 'body does contain email address'; $mech->clear_emails_ok; $mech->log_out_ok; -# Test only superuser can edit bodies -$user = $mech->log_in_ok( 'dm1@example.org' ); -$mech->get( '/admin/body/' . $zurich->id ); -is $mech->res->code, 404, "only superuser should be able to edit bodies"; -$mech->log_out_ok; +subtest "only superuser can edit bodies" => sub { + $user = $mech->log_in_ok( 'dm1@example.org' ); + $mech->get( '/admin/body/' . $zurich->id ); + is $mech->res->code, 404, "only superuser should be able to edit bodies"; + $mech->log_out_ok; +}; -# Test only superuser can see "Add body" form -$user = $mech->log_in_ok( 'dm1@example.org' ); -$mech->get_ok( '/admin/bodies' ); -$mech->content_lacks( 'log_out_ok; +subtest "only superuser can see 'Add body' form" => sub { + $user = $mech->log_in_ok( 'dm1@example.org' ); + $mech->get_ok( '/admin/bodies' ); + $mech->content_lacks( 'log_out_ok; +}; subtest "phone number is mandatory" => sub { # Capture the bits of the original config that the following code will use my %config = map {$_ => FixMyStreet->config($_)} - qw(ALLOWED_COBRANDS FMS_DB_NAME MAPIT_ID_WHITELIST STAGING_SITE); + qw(ALLOWED_COBRANDS BASE_URL FMS_DB_NAME MAPIT_ID_WHITELIST STAGING_SITE); # Change the MAPIT_TYPES and MAPIT_URL values for this test $config{MAPIT_TYPES} = [ 'O08' ]; @@ -377,37 +379,40 @@ subtest "phone number is mandatory" => sub { $mech->log_out_ok; $override_guard->restore(); + mySociety::MaPit::configure(); }; -# Test problems can't be assigned to deleted bodies -$user = $mech->log_in_ok( 'dm1@example.org' ); -$user->from_body( 1 ); -$user->update; -$report->state( 'confirmed' ); -$report->update; -$mech->get_ok( '/admin/body/' . $external_body->id ); -$mech->submit_form_ok( { with_fields => { deleted => 1 } } ); -$mech->get_ok( '/admin/report_edit/' . $report->id ); -$mech->content_lacks( $external_body->name ); -$user->from_body( 2 ); -$user->update; -$mech->log_out_ok; +subtest "problems can't be assigned to deleted bodies" => sub { + $user = $mech->log_in_ok( 'dm1@example.org' ); + $user->from_body( 1 ); + $user->update; + $report->state( 'confirmed' ); + $report->update; + $mech->get_ok( '/admin/body/' . $external_body->id ); + $mech->submit_form_ok( { with_fields => { deleted => 1 } } ); + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->content_lacks( $external_body->name ); + $user->from_body( 2 ); + $user->update; + $mech->log_out_ok; +}; -# Test hidden report email are only sent when requested -$user = $mech->log_in_ok( 'dm1@example.org') ; -$extra = $report->extra; -$extra->{email_confirmed} = 1; -$report->extra ( { %$extra } ); -$report->update; -$mech->get_ok( '/admin/report_edit/' . $report->id ); -$mech->submit_form_ok( { with_fields => { state => 'hidden', send_rejected_email => 1 } } ); -$mech->email_count_is(1); -$mech->clear_emails_ok; -$mech->get_ok( '/admin/report_edit/' . $report->id ); -$mech->submit_form_ok( { with_fields => { state => 'hidden', send_rejected_email => undef } } ); -$mech->email_count_is(0); -$mech->clear_emails_ok; -$mech->log_out_ok; +subtest "hidden report email are only sent when requested" => sub { + $user = $mech->log_in_ok( 'dm1@example.org') ; + $extra = $report->extra; + $extra->{email_confirmed} = 1; + $report->extra ( { %$extra } ); + $report->update; + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->submit_form_ok( { with_fields => { state => 'hidden', send_rejected_email => 1 } } ); + $mech->email_count_is(1); + $mech->clear_emails_ok; + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->submit_form_ok( { with_fields => { state => 'hidden', send_rejected_email => undef } } ); + $mech->email_count_is(0); + $mech->clear_emails_ok; + $mech->log_out_ok; +}; $mech->delete_problems_for_body( 2 ); $mech->delete_user( 'dm1@example.org' ); -- cgit v1.2.3 From 94ac7786132a538a5742ba325eb7fe9eff89cfc9 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 13 Sep 2013 10:46:54 +0100 Subject: Have a central config-override function. You only need to pass in the values you wish to be different. --- t/cobrand/fixmybarangay.t | 6 +++- t/cobrand/zurich.t | 74 ++++++++++------------------------------------- 2 files changed, 20 insertions(+), 60 deletions(-) (limited to 't/cobrand') diff --git a/t/cobrand/fixmybarangay.t b/t/cobrand/fixmybarangay.t index c0823eac4..2d9276dc0 100644 --- a/t/cobrand/fixmybarangay.t +++ b/t/cobrand/fixmybarangay.t @@ -80,7 +80,11 @@ $mech->get_ok( '/report/' . $dps_report->id ); $mech->email_count_is(0); -FixMyStreet::App->model('DB::Problem')->send_reports('fixmybarangay'); +FixMyStreet::override_config { + SEND_REPORTS_ON_STAGING => 1, +}, sub { + FixMyStreet::App->model('DB::Problem')->send_reports('fixmybarangay'); +}; # Check BGY one sent by email my $email = $mech->get_email; diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index fb9b24678..0876be582 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -5,7 +5,6 @@ use strict; use warnings; use DateTime; use Test::More; -use Sub::Override; plan skip_all => 'Skipping Zurich test without Zurich cobrand' unless FixMyStreet::Cobrand->exists('zurich'); @@ -26,37 +25,15 @@ plan skip_all => 'Skipping Zurich test without Zurich cobrand' # # commonlib/bin/gettext-makemo FixMyStreet +use FixMyStreet; # This is a helper method that will send the reports but with the config # correctly set - notably SEND_REPORTS_ON_STAGING needs to be true. sub send_reports_for_zurich { - - # Capture the bits of the original config that the following code will use - my %config = - map {$_ => mySociety::Config::get($_)} - qw(BASE_URL STAGING_SITE CONTACT_EMAIL SEND_REPORTS_ON_STAGING); - - # Change the SEND_REPORTS_ON_STAGING value to true for this test - $config{SEND_REPORTS_ON_STAGING} = 1; - - # Override the get function to return values from our captured config. This - # override will be cleared at the end of this block when the $override guard - # falls out of scope. - my $override_guard = Sub::Override->new( - "mySociety::Config::get", - sub ($;$) { - my ($key, $default) = @_; - exists $config{$key} - ? return $config{$key} - : die "Need to cache config key '$key' here"; - } - ); - - # Actually send the report - FixMyStreet::App->model('DB::Problem')->send_reports('zurich'); - - # tidy up explicitly - $override_guard->restore(); + FixMyStreet::override_config { SEND_REPORTS_ON_STAGING => 1 }, sub { + # Actually send the report + FixMyStreet::App->model('DB::Problem')->send_reports('zurich'); + }; } use FixMyStreet::TestMech; @@ -349,37 +326,16 @@ subtest "only superuser can see 'Add body' form" => sub { }; subtest "phone number is mandatory" => sub { - # Capture the bits of the original config that the following code will use - my %config = - map {$_ => FixMyStreet->config($_)} - qw(ALLOWED_COBRANDS BASE_URL FMS_DB_NAME MAPIT_ID_WHITELIST STAGING_SITE); - - # Change the MAPIT_TYPES and MAPIT_URL values for this test - $config{MAPIT_TYPES} = [ 'O08' ]; - $config{MAPIT_URL} = 'http://global.mapit.mysociety.org/'; - mySociety::MaPit::configure($config{MAPIT_URL}); - - # Override the get function to return values from our captured config. This - # override will be cleared at the end of this block when the $override guard - # falls out of scope. - my $override_guard = Sub::Override->new( - "FixMyStreet::config", - sub { - my ($self, $key, $default) = @_; - exists $config{$key} - ? return $config{$key} - : die "Need to cache config key '$key' here"; - } - ); - - $user = $mech->log_in_ok( 'dm1@example.org' ); - $mech->get_ok( '/report/new?lat=47.381817&lon=8.529156' ); - $mech->submit_form( with_fields => { phone => "" } ); - $mech->content_contains( 'Diese Information wird benötigt' ); - $mech->log_out_ok; - - $override_guard->restore(); - mySociety::MaPit::configure(); + FixMyStreet::override_config { + MAPIT_TYPES => [ 'O08' ], + MAPIT_URL => 'http://global.mapit.mysociety.org/', + }, sub { + $user = $mech->log_in_ok( 'dm1@example.org' ); + $mech->get_ok( '/report/new?lat=47.381817&lon=8.529156' ); + $mech->submit_form( with_fields => { phone => "" } ); + $mech->content_contains( 'Diese Information wird benötigt' ); + $mech->log_out_ok; + }; }; subtest "problems can't be assigned to deleted bodies" => sub { -- cgit v1.2.3