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/app') 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 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/app') 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/app') 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/app') 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 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/app') 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/app') 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/app') 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 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 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 't/app') 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 ( { -- 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/app') 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/app') 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/app') 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 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/app') 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