From 25943aaa61115a5ba573ab48c3dcebf55e9da970 Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Thu, 29 Aug 2013 10:37:26 +0100 Subject: Fix about controller test --- t/app/controller/about.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't') diff --git a/t/app/controller/about.t b/t/app/controller/about.t index 4e49cdac9..ed28eb584 100644 --- a/t/app/controller/about.t +++ b/t/app/controller/about.t @@ -24,7 +24,7 @@ SKIP: { # check that geting the page as EHA in welsh produces a different page ok $mech->host("cy.reportemptyhomes.co.uk"), 'host to cy.reportemptyhomes'; $mech->get_ok('/about'); - $mech->content_like(qr{Amdanom ni ::\s+Adrodd am Eiddo Gwag}); + $mech->content_like(qr{Amdanom ni ::\s+Rhoi gwybod am eiddo gwag}); $mech->content_contains('html lang="cy"'); } -- cgit v1.2.3 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') 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') 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') 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') 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') 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') 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 d97283bf7b22fb00faa4c8b36a6b477192308fdb Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Thu, 5 Sep 2013 10:00:17 +0100 Subject: Use format_datetime for DBIx::Class searches to get rid of warnings when running test suite --- t/app/controller/alert_new.t | 25 ++++++++++++++++--------- t/app/controller/rss.t | 9 ++++++--- 2 files changed, 22 insertions(+), 12 deletions(-) (limited to 't') diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index 43d90c0ba..23240c3b9 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -3,6 +3,7 @@ use warnings; use Test::More; use FixMyStreet::TestMech; +use FixMyStreet::App; my $mech = FixMyStreet::TestMech->new; @@ -362,6 +363,8 @@ subtest "Test normal alert signups and that alerts are sent" => sub { my $dt = DateTime->now()->add( days => 2); + my $dt_parser = FixMyStreet::App->model('DB')->schema->storage->datetime_parser; + my $report_time = '2011-03-01 12:00:00'; my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { postcode => 'EH1 1BB', @@ -374,9 +377,9 @@ subtest "Test normal alert signups and that alerts are sent" => sub { name => $user1->name, anonymous => 0, state => 'fixed - user', - confirmed => $dt, - lastupdate => $dt, - whensent => $dt->clone->add( minutes => 5 ), + confirmed => $dt_parser->format_datetime($dt), + lastupdate => $dt_parser->format_datetime($dt), + whensent => $dt_parser->format_datetime($dt->clone->add( minutes => 5 )), lang => 'en-gb', service => '', cobrand => 'default', @@ -514,6 +517,8 @@ for my $test ( my $alert_user1 = FixMyStreet::App->model('DB::Alert')->create( $alert_params ); ok $alert_user1, "alert created"; + my $dt_parser = FixMyStreet::App->model('DB')->schema->storage->datetime_parser; + my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { postcode => 'EH1 1BB', bodies_str => '2651', @@ -525,9 +530,9 @@ for my $test ( name => $user2->name, anonymous => 0, state => 'confirmed', - confirmed => $r_dt, - lastupdate => $r_dt, - whensent => $r_dt->clone->add( minutes => 5 ), + confirmed => $dt_parser->format_datetime($r_dt), + lastupdate => $dt_parser->format_datetime($r_dt), + whensent => $dt_parser->format_datetime($r_dt->clone->add( minutes => 5 )), lang => 'en-gb', service => '', cobrand => 'default', @@ -573,6 +578,8 @@ subtest 'check new updates alerts for non public reports only go to report owner my $dt = DateTime->now->add( minutes => -30 ); my $r_dt = $dt->clone->add( minutes => 20 ); + my $dt_parser = FixMyStreet::App->model('DB')->schema->storage->datetime_parser; + my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { postcode => 'EH1 1BB', bodies_str => '2651', @@ -584,9 +591,9 @@ subtest 'check new updates alerts for non public reports only go to report owner name => $user2->name, anonymous => 0, state => 'confirmed', - confirmed => $r_dt, - lastupdate => $r_dt, - whensent => $r_dt->clone->add( minutes => 5 ), + confirmed => $dt_parser->format_datetime($r_dt), + lastupdate => $dt_parser->format_datetime($r_dt), + whensent => $dt_parser->format_datetime($r_dt->clone->add( minutes => 5 )), lang => 'en-gb', service => '', cobrand => 'default', diff --git a/t/app/controller/rss.t b/t/app/controller/rss.t index f04a17151..ec6a01b50 100644 --- a/t/app/controller/rss.t +++ b/t/app/controller/rss.t @@ -3,6 +3,7 @@ use warnings; use Test::More; use FixMyStreet::TestMech; +use FixMyStreet::App; my $mech = FixMyStreet::TestMech->new; @@ -15,6 +16,8 @@ my $dt = DateTime->new( my $user1 = FixMyStreet::App->model('DB::User') ->find_or_create( { email => 'reporter-rss@example.com', name => 'Reporter User' } ); +my $dt_parser = FixMyStreet::App->model('DB')->schema->storage->datetime_parser; + my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { postcode => 'eh1 1BB', bodies_str => '2651', @@ -26,9 +29,9 @@ my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { name => $user1->name, anonymous => 0, state => 'confirmed', - confirmed => $dt, - lastupdate => $dt, - whensent => $dt->clone->add( minutes => 5 ), + confirmed => $dt_parser->format_datetime($dt), + lastupdate => $dt_parser->format_datetime($dt), + whensent => $dt_parser->format_datetime($dt->clone->add( minutes => 5 )), lang => 'en-gb', service => '', cobrand => 'default', -- cgit v1.2.3 From b1ee798788efd57755d6325b6b97259248ff258f Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Wed, 4 Sep 2013 17:15:47 +0100 Subject: Remove unneeded test diagnostics --- t/app/model/questionnaire.t | 2 -- 1 file changed, 2 deletions(-) (limited to 't') diff --git a/t/app/model/questionnaire.t b/t/app/model/questionnaire.t index 86af51c42..be5b433c1 100644 --- a/t/app/model/questionnaire.t +++ b/t/app/model/questionnaire.t @@ -32,8 +32,6 @@ my $problem = FixMyStreet::App->model('DB::Problem')->create( } ); -diag $problem->id; - my $mech = FixMyStreet::TestMech->new; for my $test ( -- cgit v1.2.3 From dd68a744200040d0dd2c9f1a58c5bd9826b4ce80 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Thu, 5 Sep 2013 09:53:45 +0100 Subject: Disable info level logging in some tests --- t/app/controller/report_import.t | 5 +++++ t/app/controller/report_new.t | 5 +++++ t/app/controller/report_new_open311.t | 5 +++++ 3 files changed, 15 insertions(+) (limited to 't') diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t index eb686b44e..e25764c4b 100644 --- a/t/app/controller/report_import.t +++ b/t/app/controller/report_import.t @@ -3,6 +3,7 @@ use warnings; use Test::More; use FixMyStreet::TestMech; +use FixMyStreet::App; use Web::Scraper; use Path::Class; @@ -12,6 +13,10 @@ $mech->get_ok('/import'); my $sample_file = file(__FILE__)->parent->file("sample.jpg")->stringify; ok -e $sample_file, "sample file $sample_file exists"; +# disable info logs for this test run +FixMyStreet::App->log->disable('info'); +END { FixMyStreet::App->log->enable('info'); } + # submit an empty report to import - check we get all errors subtest "Test creating bad partial entries" => sub { diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 8e129a41c..d1f246e95 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -5,9 +5,14 @@ use Test::More; use utf8; use FixMyStreet::TestMech; +use FixMyStreet::App; use Web::Scraper; use Path::Class; +# disable info logs for this test run +FixMyStreet::App->log->disable('info'); +END { FixMyStreet::App->log->enable('info'); } + my $mech = FixMyStreet::TestMech->new; $mech->get_ok('/report/new'); diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t index 22d2d1f97..ed26d58d5 100644 --- a/t/app/controller/report_new_open311.t +++ b/t/app/controller/report_new_open311.t @@ -3,8 +3,13 @@ use warnings; use Test::More; use FixMyStreet::TestMech; +use FixMyStreet::App; use Web::Scraper; +# disable info logs for this test run +FixMyStreet::App->log->disable('info'); +END { FixMyStreet::App->log->enable('info'); } + my $mech = FixMyStreet::TestMech->new; my $body = $mech->create_body_ok(2651, 'City of Edinburgh Council'); -- 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') 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 dbd5376d42beb4744e9e9e2a020f878a2821b00b Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 5 Sep 2013 15:43:06 +0100 Subject: Spell out all "marked as %s" strings. As doing interpolation from a database state field is not great for translation. Fixes #391. --- t/app/controller/report_updates.t | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 't') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index c99a54743..3356867bb 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -537,6 +537,7 @@ for my $test ( state => 'internal referral', }, state => 'internal referral', + meta => "an internal referral", }, { desc => 'from authority user marks report as not responsible', @@ -562,7 +563,7 @@ for my $test ( state => 'duplicate', }, state => 'duplicate', - meta => 'duplicate report', + meta => 'a duplicate report', }, { desc => 'from authority user marks report as internal referral', @@ -575,7 +576,7 @@ for my $test ( state => 'internal referral', }, state => 'internal referral', - meta => 'internal referral', + meta => 'an internal referral', }, { desc => 'from authority user marks report sent to two councils as fixed', -- cgit v1.2.3 From d3886845bf52bdb4af465e90a296b91ceb8b6500 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Tue, 10 Sep 2013 14:26:09 +0100 Subject: Add RABX column code and tests --- t/app/model/rabx_column.t | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 t/app/model/rabx_column.t (limited to 't') diff --git a/t/app/model/rabx_column.t b/t/app/model/rabx_column.t new file mode 100644 index 000000000..607d578ce --- /dev/null +++ b/t/app/model/rabx_column.t @@ -0,0 +1,23 @@ +use strict; +use warnings; + +use Test::More; + +use_ok "FixMyStreet::DB::RABXColumn"; + +# Test that the class names are correctly normalised +my @tests = ( + ["FixMyStreet::DB::Result::Token", "Token"], + ["FixMyStreet::App::Model::DB::Token", "Token"], +); + +foreach my $test (@tests) { + my ($input, $expected) = @$test; + is( + FixMyStreet::DB::RABXColumn::_get_class_identifier($input), + $expected, + "$input -> $expected" + ); +} + +done_testing(); -- cgit v1.2.3 From affebc1ce59e850ccc50013bdcccc89c6846c89a Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Tue, 10 Sep 2013 14:26:48 +0100 Subject: Switch Token over to use RABXColumn and test that changes to the col behave as expected --- t/app/model/token.t | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 't') diff --git a/t/app/model/token.t b/t/app/model/token.t index 12945975e..637477fa3 100644 --- a/t/app/model/token.t +++ b/t/app/model/token.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 45; +use Test::More; use FixMyStreet; use FixMyStreet::App; @@ -94,3 +94,47 @@ foreach my $test_data_name ( sort keys %tests ) { undef, "token gone with m::AT"; } + + + +# Test that the inflation and deflation works as expected +{ + my $token = + $token_rs->create( { scope => 'testing', data => {} } ); + END { $token->delete() }; + + # Add in temporary check to test that the data is updated as expected. + is_deeply($token->data, {}, "data is empty"); + + # store something in it + $token->update({ data => { foo => 'bar' } }); + $token->discard_changes(); + is_deeply($token->data, { foo => 'bar' }, "data has content"); + + # change the hash stored + $token->update({ data => { baz => 'bundy' } }); + $token->discard_changes(); + is_deeply($token->data, { baz => 'bundy' }, "data has new content"); + + # change the hashref in place + { + my $data = $token->data; + $data->{baz} = 'new'; + $token->data( $data ); + $token->update(); + $token->discard_changes(); + is_deeply($token->data, { baz => 'new' }, "data has been updated"); + } + + # change the hashref in place + { + my $data = $token->data; + $data->{baz} = 'new'; + $token->update({ data => $data }); + $token->discard_changes(); + is_deeply($token->data, { baz => 'new' }, "data has been updated"); + } + +} + +done_testing(); -- 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') 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') 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') 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/app/controller/report_display.t | 4 ++-- t/cobrand/zurich.t | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 't') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 7904b6736..62a5b3667 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -100,7 +100,7 @@ subtest "Zurich unconfirmeds are 200" => sub { if ( !FixMyStreet::Cobrand->exists('zurich') ) { plan skip_all => 'Skipping Zurich test without Zurich cobrand'; } - $mech->host( 'zurich.fixmystreet.com' ); + $mech->host( 'zurich.example.com' ); ok $report->update( { state => 'unconfirmed' } ), 'unconfirm report'; $mech->get_ok("/report/$report_id"); $mech->content_contains( 'Überprüfung ausstehend' ); @@ -403,7 +403,7 @@ subtest "Zurich banners are displayed correctly" => sub { if ( !FixMyStreet::Cobrand->exists('zurich') ) { plan skip_all => 'Skipping Zurich test without Zurich cobrand'; } - $mech->host( 'zurich.fixmystreet.com' ); + $mech->host( 'zurich.example.com' ); for my $test ( { 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') 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') 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') 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') 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') 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') 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 64f97d4cf9ad64905006e504f3ffb47fb373eca9 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 Sep 2013 15:57:38 +0100 Subject: Test to check reports from abuse users not sent Reports that have been created by a user who is logged in but whose email is in the abuse table should be hidden and not sent by send_reports. --- t/app/model/problem.t | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 't') diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 7daa653fc..5d02aef2b 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -630,6 +630,53 @@ subtest 'check can turn on report sent email alerts' => sub { like $email->body, qr/Your report about/, 'report sent body correct'; }; +subtest 'check reports from abuser not sent' => sub { + $mech->clear_emails_ok; + + FixMyStreet::App->model('DB::Problem')->search( + { + whensent => undef + } + )->update( { whensent => \'ms_current_timestamp()' } ); + + $problem->discard_changes; + $problem->update( { + title => 'Report', + state => 'confirmed', + confirmed => \'ms_current_timestamp()', + whensent => undef, + category => 'potholes', + send_fail_count => 0, + } ); + + FixMyStreet::App->model('DB::Problem')->send_reports(); + + $mech->email_count_is( 1 ); + + $problem->discard_changes(); + ok $problem->whensent, 'Report has been sent'; + + $problem->update( { + state => 'confirmed', + confirmed => \'ms_current_timestamp()', + whensent => undef, + } ); + + my $abuse = FixMyStreet::App->model('DB::Abuse')->create( { email => $problem->user->email } ); + + $mech->clear_emails_ok; + FixMyStreet::App->model('DB::Problem')->send_reports(); + + $mech->email_count_is( 0 ); + + $problem->discard_changes(); + is $problem->state, 'hidden', 'reports from abuse user are hidden automatically'; + is $problem->whensent, undef, 'reports from abuse user are not sent'; + + ok $abuse->delete(), 'user removed from abuse table'; +}; + + $problem->comments->delete; $problem->delete; $mech->delete_user( $user ); -- cgit v1.2.3 From 30bb1746b703a12d7ec3c698eea63ac9e1183037 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 Sep 2013 15:59:27 +0100 Subject: mechanism to stop app store tests being sent In order to allow the iOS app to be tested in the app store we need to allow the user to create a report but we don't want to send it. To allow this hide reports with a specific title during send_reports --- t/app/model/problem.t | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 't') diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 5d02aef2b..c9fa1a6e3 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -630,6 +630,35 @@ subtest 'check can turn on report sent email alerts' => sub { like $email->body, qr/Your report about/, 'report sent body correct'; }; + +subtest 'check iOS app store test reports not sent' => sub { + $mech->clear_emails_ok; + + FixMyStreet::App->model('DB::Problem')->search( + { + whensent => undef + } + )->update( { whensent => \'ms_current_timestamp()' } ); + + $problem->discard_changes; + $problem->update( { + title => 'App store test', + state => 'confirmed', + confirmed => \'ms_current_timestamp()', + whensent => undef, + category => 'potholes', + send_fail_count => 0, + } ); + + FixMyStreet::App->model('DB::Problem')->send_reports(); + + $mech->email_count_is( 0 ); + + $problem->discard_changes(); + is $problem->state, 'hidden', 'iOS test reports are hidden automatically'; + is $problem->whensent, undef, 'iOS test reports are not sent'; +}; + subtest 'check reports from abuser not sent' => sub { $mech->clear_emails_ok; -- cgit v1.2.3 From d0d2c1d1549b4255eb3d852cc5a64319dccebd7e Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 Sep 2013 17:07:08 +0100 Subject: explicitly set bodies_str for abuse and app store tests The first email count test in the abuse subtest was failing on Travis but not on my machine because the sent email alert test was running on my machine, as it has the mock module installed, and this was resetting the bodies_str to one with a confirmed contact. Setting bodies_str on both these tests stops this sort of thing happening again --- t/app/model/problem.t | 2 ++ 1 file changed, 2 insertions(+) (limited to 't') diff --git a/t/app/model/problem.t b/t/app/model/problem.t index c9fa1a6e3..156ad7fbb 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -642,6 +642,7 @@ subtest 'check iOS app store test reports not sent' => sub { $problem->discard_changes; $problem->update( { + bodies_str => 2651, title => 'App store test', state => 'confirmed', confirmed => \'ms_current_timestamp()', @@ -670,6 +671,7 @@ subtest 'check reports from abuser not sent' => sub { $problem->discard_changes; $problem->update( { + bodies_str => 2651, title => 'Report', state => 'confirmed', confirmed => \'ms_current_timestamp()', -- 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') 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') 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') 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') 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 aeba8e0da58b8e04fbbe0e9923fe8c784f3d54e1 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 Sep 2013 18:05:35 +0100 Subject: switch to Sub::Override from Test::MockModule This is for consistency as Sub::Override is used for another test and also so we minimise the number of modules installed just for testing --- t/app/model/problem.t | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 't') diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 156ad7fbb..9138c11a8 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -9,6 +9,7 @@ use FixMyStreet; use FixMyStreet::App; use FixMyStreet::TestMech; use mySociety::Locale; +use Sub::Override; mySociety::Locale::gettext_domain('FixMyStreet'); @@ -583,9 +584,10 @@ foreach my $test ( { } subtest 'check can turn on report sent email alerts' => sub { - eval 'use Test::MockModule; 1' or - plan skip_all => 'Skipping tests that rely on Test::MockModule'; - + my $send_confirmation_mail_override = Sub::Override->new( + "FixMyStreet::Cobrand::Default::report_sent_confirmation_email", + sub { return 1; } + ); $mech->clear_emails_ok; FixMyStreet::App->model('DB::Problem')->search( @@ -606,9 +608,6 @@ subtest 'check can turn on report sent email alerts' => sub { send_fail_count => 0, } ); - my $m = new Test::MockModule( - 'FixMyStreet::Cobrand::FixMyStreet' ); - $m->mock( report_sent_confirmation_email => 1 ); FixMyStreet::App->model('DB::Problem')->send_reports(); $mech->email_count_is( 2 ); @@ -628,6 +627,8 @@ subtest 'check can turn on report sent email alerts' => sub { $email = $emails[1]; like $email->header('Subject'), qr/Problem Report Sent/, 'report sent email title correct'; like $email->body, qr/Your report about/, 'report sent body correct'; + + $send_confirmation_mail_override->restore(); }; -- 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') 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