aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2011-08-22 11:22:33 +0100
committerStruan Donald <struan@exo.org.uk>2011-08-22 11:22:33 +0100
commit44c31ab8efbd97086e17d26c819b1d5b4946ce43 (patch)
tree5a509a5006afd50f4c48f52fdf45ac9ac86ac054 /t
parentf93ff062c986847f97aef76673c2ca7742f1f125 (diff)
parenta9a4fed583d7467c9c1f1fa56d42bcb75b4b488c (diff)
Merge branch 'master' of ssh://git.mysociety.org/data/git/public/fixmystreet into open311-consumer
Conflicts: t/app/model/problem.t templates/web/default/report/new/fill_in_details.html web/css/core.css
Diffstat (limited to 't')
-rw-r--r--t/app/controller/admin.t166
-rw-r--r--t/app/controller/questionnaire.t68
-rw-r--r--t/app/controller/report_display.t97
-rw-r--r--t/app/controller/report_import.t122
-rw-r--r--t/app/controller/report_updates.t234
-rw-r--r--t/app/model/alert_type.t144
-rw-r--r--t/app/model/problem.t88
-rw-r--r--t/app/model/questionnaire.t106
-rw-r--r--t/map/tilma/original.t108
9 files changed, 1069 insertions, 64 deletions
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t
index 160e99785..be3b74cf5 100644
--- a/t/app/controller/admin.t
+++ b/t/app/controller/admin.t
@@ -77,11 +77,13 @@ my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create(
);
subtest 'check summary counts' => sub {
- my $problems = FixMyStreet::App->model('DB::Problem')->search( { state => { -in => [qw/confirmed fixed/] } } );
+ my $problems = FixMyStreet::App->model('DB::Problem')->search( { state => { -in => [qw/confirmed fixed closed investigating planned/, 'in progress', 'fixed - user', 'fixed - council'] } } );
my $problem_count = $problems->count;
$problems->update( { cobrand => '' } );
+ FixMyStreet::App->model('DB::Problem')->search( { council => 2489 } )->update( { council => 1 } );
+
my $q = FixMyStreet::App->model('DB::Questionnaire')->find_or_new( { problem => $report, });
$q->whensent( \'ms_current_timestamp()' );
$q->in_storage ? $q->update : $q->insert;
@@ -130,6 +132,7 @@ subtest 'check summary counts' => sub {
$alert->cobrand('');
$alert->update;
+ FixMyStreet::App->model('DB::Problem')->search( { council => 1 } )->update( { council => 2489 } );
ok $mech->host('fixmystreet.com');
};
@@ -782,6 +785,76 @@ for my $test (
};
}
+for my $test (
+ {
+ desc => 'user is problem owner',
+ problem_user => $user,
+ update_user => $user,
+ update_fixed => 0,
+ update_reopen => 0,
+ update_state => undef,
+ user_council => undef,
+ content => 'user is problem owner',
+ },
+ {
+ desc => 'user is council user',
+ problem_user => $user,
+ update_user => $user2,
+ update_fixed => 0,
+ update_reopen => 0,
+ update_state => undef,
+ user_council => 2504,
+ content => 'user is from same council as problem - 2504',
+ },
+ {
+ desc => 'update changed problem state',
+ problem_user => $user,
+ update_user => $user2,
+ update_fixed => 0,
+ update_reopen => 0,
+ update_state => 'planned',
+ user_council => 2504,
+ content => 'Update changed problem state to planned',
+ },
+ {
+ desc => 'update marked problem as fixed',
+ problem_user => $user,
+ update_user => $user3,
+ update_fixed => 1,
+ update_reopen => 0,
+ update_state => undef,
+ user_council => undef,
+ content => 'Update marked problem as fixed',
+ },
+ {
+ desc => 'update reopened problem',
+ problem_user => $user,
+ update_user => $user,
+ update_fixed => 0,
+ update_reopen => 1,
+ update_state => undef,
+ user_council => undef,
+ content => 'Update reopened problem',
+ },
+) {
+ subtest $test->{desc} => sub {
+ $report->user( $test->{problem_user} );
+ $report->update;
+
+ $update->user( $test->{update_user} );
+ $update->problem_state( $test->{update_state} );
+ $update->mark_fixed( $test->{update_fixed} );
+ $update->mark_open( $test->{update_reopen} );
+ $update->update;
+
+ $test->{update_user}->from_council( $test->{user_council} );
+ $test->{update_user}->update;
+
+ $mech->get_ok('/admin/update_edit/' . $update->id );
+ $mech->content_contains( $test->{content} );
+ };
+}
+
subtest 'editing update email creates new user if required' => sub {
my $user = FixMyStreet::App->model('DB::User')->find(
{ email => 'test4@example.com' }
@@ -944,6 +1017,97 @@ subtest 'show flagged entries' => sub {
$mech->content_contains( $user->email );
};
+subtest 'user search' => sub {
+ $mech->get_ok('/admin/search_users');
+ $mech->get_ok('/admin/search_users?search=' . $user->name);
+
+ $mech->content_contains( $user->name);
+ my $u_id = $user->id;
+ $mech->content_like( qr{user_edit/$u_id">Edit</a>} );
+
+ $mech->get_ok('/admin/search_users?search=' . $user->email);
+
+ $mech->content_like( qr{user_edit/$u_id">Edit</a>} );
+
+ $user->from_council(2509);
+ $user->update;
+ $mech->get_ok('/admin/search_users?search=2509' );
+ $mech->content_contains(2509);
+};
+
+$log_entries = FixMyStreet::App->model('DB::AdminLog')->search(
+ {
+ object_type => 'user',
+ object_id => $user->id
+ },
+ {
+ order_by => { -desc => 'id' },
+ }
+);
+
+is $log_entries->count, 0, 'no admin log entries';
+
+for my $test (
+ {
+ desc => 'edit user name',
+ fields => {
+ name => 'Test User',
+ email => 'test@example.com',
+ council => 2509,
+ },
+ changes => {
+ name => 'Changed User',
+ },
+ log_count => 1,
+ log_entries => [qw/edit/],
+ },
+ {
+ desc => 'edit user email',
+ fields => {
+ name => 'Changed User',
+ email => 'test@example.com',
+ council => 2509,
+ },
+ changes => {
+ email => 'changed@example.com',
+ },
+ log_count => 2,
+ log_entries => [qw/edit edit/],
+ },
+ {
+ desc => 'edit user council',
+ fields => {
+ name => 'Changed User',
+ email => 'changed@example.com',
+ council => 2509,
+ },
+ changes => {
+ council => 2607,
+ },
+ log_count => 3,
+ log_entries => [qw/edit edit edit/],
+ },
+) {
+ subtest $test->{desc} => sub {
+ $mech->get_ok( '/admin/user_edit/' . $user->id );
+
+ my $visible = $mech->visible_form_values;
+ is_deeply $visible, $test->{fields}, 'expected user';
+
+ my $expected = {
+ %{ $test->{fields} },
+ %{ $test->{changes} }
+ };
+
+ $mech->submit_form_ok( { with_fields => $expected } );
+
+ $visible = $mech->visible_form_values;
+ is_deeply $visible, $expected, 'user updated';
+
+ $mech->content_contains( 'Updated!' );
+ };
+}
+
$mech->delete_user( $user );
$mech->delete_user( $user2 );
$mech->delete_user( $user3 );
diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t
index e56734bfc..af3b373ac 100644
--- a/t/app/controller/questionnaire.t
+++ b/t/app/controller/questionnaire.t
@@ -204,7 +204,12 @@ foreach my $test (
}
my $result;
- $result = 'fixed' if $test->{fields}{been_fixed} eq 'Yes';
+ $result = 'fixed - user'
+ if $test->{fields}{been_fixed} eq 'Yes'
+ && $test->{problem_state} ne 'fixed';
+ $result = 'fixed'
+ if $test->{fields}{been_fixed} eq 'Yes'
+ && $test->{problem_state} eq 'fixed';
$result = 'confirmed' if $test->{fields}{been_fixed} eq 'No';
$result = 'unknown' if $test->{fields}{been_fixed} eq 'Unknown';
@@ -214,7 +219,7 @@ foreach my $test (
# Check the right HTML page has been returned
$mech->content_like( qr/<title>[^<]*Questionnaire/m );
$mech->content_contains( 'glad to hear it&rsquo;s been fixed' )
- if $result eq 'fixed';
+ if $result =~ /fixed/;
$mech->content_contains( 'get some more information about the status of your problem' )
if $result eq 'unknown';
$mech->content_contains( "sorry to hear that" )
@@ -235,6 +240,16 @@ foreach my $test (
{ problem_id => $report->id }
);
is $c->text, $test->{fields}{update} || $test->{comment};
+ if ( $result =~ /fixed/ ) {
+ ok $c->mark_fixed, 'comment marked as fixed';
+ ok !$c->mark_open, 'comment not marked as open';
+ } elsif ( $result eq 'confirmed' ) {
+ ok $c->mark_open, 'comment marked as open';
+ ok !$c->mark_fixed, 'comment not marked as fixed';
+ } elsif ( $result eq 'unknown' ) {
+ ok !$c->mark_open, 'comment not marked as open';
+ ok !$c->mark_fixed, 'comment not marked as fixed';
+ }
}
# Reset questionnaire for next test
@@ -250,6 +265,55 @@ foreach my $test (
};
}
+
+for my $test (
+ {
+ state => 'confirmed',
+ fixed => 0
+ },
+ {
+ state => 'planned',
+ fixed => 0
+ },
+ {
+ state => 'in progress',
+ fixed => 0
+ },
+ {
+ state => 'investigating',
+ fixed => 0
+ },
+ {
+ state => 'closed',
+ fixed => 0
+ },
+ {
+ state => 'fixed',
+ fixed => 1
+ },
+ {
+ state => 'fixed - council',
+ fixed => 1
+ },
+ {
+ state => 'fixed - user',
+ fixed => 1
+ },
+) {
+ subtest "correct fixed text for state $test->{state}" => sub {
+ $report->state ( $test->{state} );
+ $report->update;
+
+ $mech->get_ok("/Q/" . $token->token);
+ $mech->title_like( qr/Questionnaire/ );
+ if ( $test->{fixed} ) {
+ $mech->content_contains('An update marked this problem as fixed');
+ } else {
+ $mech->content_lacks('An update marked this problem as fixed');
+ }
+ };
+}
+
# EHA extra checking
ok $mech->host("reportemptyhomes.com"), 'change host to reportemptyhomes';
diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t
index 1f857a387..a70d5b9e9 100644
--- a/t/app/controller/report_display.t
+++ b/t/app/controller/report_display.t
@@ -235,6 +235,54 @@ for my $test (
banner_text => 'This problem has been fixed.',
fixed => 1
},
+ {
+ description => 'user fixed report',
+ date => DateTime->now,
+ state => 'fixed - user',
+ banner_id => 'fixed',
+ banner_text => 'This problem has been fixed.',
+ fixed => 1
+ },
+ {
+ description => 'council fixed report',
+ date => DateTime->now,
+ state => 'fixed - council',
+ banner_id => 'fixed',
+ banner_text => 'This problem has been fixed.',
+ fixed => 1
+ },
+ {
+ description => 'closed report',
+ date => DateTime->now,
+ state => 'closed',
+ banner_id => 'closed',
+ banner_text => 'This problem has been closed.',
+ fixed => 0
+ },
+ {
+ description => 'investigating report',
+ date => DateTime->now,
+ state => 'investigating',
+ banner_id => 'progress',
+ banner_text => 'This problem is in progress.',
+ fixed => 0
+ },
+ {
+ description => 'planned report',
+ date => DateTime->now,
+ state => 'planned',
+ banner_id => 'progress',
+ banner_text => 'This problem is in progress.',
+ fixed => 0
+ },
+ {
+ description => 'in progressreport',
+ date => DateTime->now,
+ state => 'in progress',
+ banner_id => 'progress',
+ banner_text => 'This problem is in progress.',
+ fixed => 0
+ },
) {
subtest "banner for $test->{description}" => sub {
$report->confirmed( $test->{date}->ymd . ' ' . $test->{date}->hms );
@@ -260,6 +308,55 @@ for my $test (
};
}
+for my $test (
+ {
+ desc => 'no state dropdown if user not from authority',
+ from_council => 0,
+ no_state => 1,
+ report_council => '2504',
+ },
+ {
+ desc => 'state dropdown if user from authority',
+ from_council => 2504,
+ no_state => 0,
+ report_council => '2504',
+ },
+ {
+ desc => 'no state dropdown if user not from same council as problem',
+ from_council => 2505,
+ no_state => 1,
+ report_council => '2504',
+ },
+ {
+ desc => 'state dropdown if user from authority and problem sent to multiple councils',
+ from_council => 2504,
+ no_state => 0,
+ report_council => '2504,2506',
+ },
+) {
+ subtest $test->{desc} => sub {
+ $mech->log_in_ok( $user->email );
+ $user->from_council( $test->{from_council} );
+ $user->update;
+
+ $report->discard_changes;
+ $report->council( $test->{report_council} );
+ $report->update;
+
+ $mech->get_ok("/report/$report_id");
+ my $fields = $mech->visible_form_values( 'updateForm' );
+ if ( $test->{no_state} ) {
+ ok !$fields->{state};
+ } else {
+ ok $fields->{state};
+ }
+ };
+}
+
+$report->discard_changes;
+$report->council( 2504 );
+$report->update;
+
# tidy up
$mech->delete_user('test@example.com');
done_testing();
diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t
index 385445565..d6bff240c 100644
--- a/t/app/controller/report_import.t
+++ b/t/app/controller/report_import.t
@@ -264,69 +264,71 @@ subtest "Submit a correct entry (with location)" => sub {
subtest "Submit a correct entry (with location) to cobrand" => sub {
- skip( "Need 'fiksgatami' in ALLOWED_COBRANDS config", 8 )
- unless FixMyStreet::App->config->{ALLOWED_COBRANDS} =~ m{fiksgatami};
- mySociety::MaPit::configure('http://mapit.nuug.no/');
- ok $mech->host("fiksgatami.no"), 'change host to fiksgatami';
+ SKIP: {
+ skip( "Need 'fiksgatami' in ALLOWED_COBRANDS config", 20 )
+ unless FixMyStreet::App->config->{ALLOWED_COBRANDS} =~ m{fiksgatami};
+ mySociety::MaPit::configure('http://mapit.nuug.no/');
+ ok $mech->host("fiksgatami.no"), 'change host to fiksgatami';
- $mech->get_ok('/import');
-
- $mech->submit_form_ok( #
- {
- with_fields => {
- service => 'test-script',
- lat => '59',
- lon => '10',
- name => 'Test User ll',
- email => 'test-ll@example.com',
- subject => 'Test report ll',
- detail => 'This is a test report ll',
- photo => $sample_file,
- }
- },
- "fill in form"
- );
-
- is_deeply( $mech->import_errors, [], "got no errors" );
- is $mech->content, 'SUCCESS', "Got success response";
-
- # check that we have received the email
- $mech->email_count_is(1);
- my $email = $mech->get_email;
- $mech->clear_emails_ok;
-
- my ($token_url) = $email->body =~ m{(http://\S+)};
- ok $token_url, "Found a token url $token_url";
-
- # go to the token url
- $mech->get_ok($token_url);
-
- # check that we are on '/report/new'
- is $mech->uri->path, '/report/new', "sent to /report/new";
-
- # check that fields are prefilled for us
- is_deeply $mech->visible_form_values,
- {
- name => 'Test User ll',
- title => 'Test report ll',
- detail => 'This is a test report ll',
- photo => '',
- phone => '',
- may_show_name => '1',
- },
- "check imported fields are shown";
-
- my $user =
- FixMyStreet::App->model('DB::User')
- ->find( { email => 'test-ll@example.com' } );
- ok $user, "Found a user";
+ $mech->get_ok('/import');
- my $report = $user->problems->first;
- is $report->state, 'partial', 'is still partial';
- is $report->title, 'Test report ll', 'title is correct';
- is $report->lang, 'nb', 'language is correct';
+ $mech->submit_form_ok( #
+ {
+ with_fields => {
+ service => 'test-script',
+ lat => '59',
+ lon => '10',
+ name => 'Test User ll',
+ email => 'test-ll@example.com',
+ subject => 'Test report ll',
+ detail => 'This is a test report ll',
+ photo => $sample_file,
+ }
+ },
+ "fill in form"
+ );
- $mech->delete_user($user);
+ is_deeply( $mech->import_errors, [], "got no errors" );
+ is $mech->content, 'SUCCESS', "Got success response";
+
+ # check that we have received the email
+ $mech->email_count_is(1);
+ my $email = $mech->get_email;
+ $mech->clear_emails_ok;
+
+ my ($token_url) = $email->body =~ m{(http://\S+)};
+ ok $token_url, "Found a token url $token_url";
+
+ # go to the token url
+ $mech->get_ok($token_url);
+
+ # check that we are on '/report/new'
+ is $mech->uri->path, '/report/new', "sent to /report/new";
+
+ # check that fields are prefilled for us
+ is_deeply $mech->visible_form_values,
+ {
+ name => 'Test User ll',
+ title => 'Test report ll',
+ detail => 'This is a test report ll',
+ photo => '',
+ phone => '',
+ may_show_name => '1',
+ },
+ "check imported fields are shown";
+
+ my $user =
+ FixMyStreet::App->model('DB::User')
+ ->find( { email => 'test-ll@example.com' } );
+ ok $user, "Found a user";
+
+ my $report = $user->problems->first;
+ is $report->state, 'partial', 'is still partial';
+ is $report->title, 'Test report ll', 'title is correct';
+ is $report->lang, 'nb', 'language is correct';
+
+ $mech->delete_user($user);
+ }
};
done_testing();
diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t
index 856e7d763..993c6758e 100644
--- a/t/app/controller/report_updates.t
+++ b/t/app/controller/report_updates.t
@@ -404,6 +404,203 @@ for my $test (
};
}
+$report->state('confirmed');
+$report->update;
+
+subtest 'check non authority user cannot change set state' => sub {
+ $mech->log_in_ok( $user->email );
+ $user->from_council( 0 );
+ $user->update;
+
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form_ok( {
+ form_number => 2,
+ fields => {
+ submit_update => 1,
+ id => $report_id,
+ name => $user->name,
+ rznvy => $user->email,
+ may_show_name => 1,
+ add_alert => 0,
+ photo => '',
+ update => 'this is a forbidden update',
+ state => 'fixed - council',
+ },
+ },
+ 'submitted with state',
+ );
+
+ is $mech->uri->path, "/report/update", "at /report/update";
+
+ my $errors = $mech->page_errors;
+ is_deeply $errors, [ 'There was a problem with your update. Please try again.' ], 'error message';
+
+ is $report->state, 'confirmed', 'state unchanged';
+};
+
+for my $state ( qw/unconfirmed hidden partial/ ) {
+ subtest "check that update cannot set state to $state" => sub {
+ $mech->log_in_ok( $user->email );
+ $user->from_council( 2504 );
+ $user->update;
+
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form_ok( {
+ form_number => 2,
+ fields => {
+ submit_update => 1,
+ id => $report_id,
+ name => $user->name,
+ rznvy => $user->email,
+ may_show_name => 1,
+ add_alert => 0,
+ photo => '',
+ update => 'this is a forbidden update',
+ state => $state,
+ },
+ },
+ 'submitted with state',
+ );
+
+ is $mech->uri->path, "/report/update", "at /report/update";
+
+ my $errors = $mech->page_errors;
+ is_deeply $errors, [ 'There was a problem with your update. Please try again.' ], 'error message';
+
+ is $report->state, 'confirmed', 'state unchanged';
+ };
+}
+
+for my $test (
+ {
+ desc => 'from authority user marks report as investigating',
+ fields => {
+ name => $user->name,
+ may_show_name => 1,
+ add_alert => 0,
+ photo => '',
+ update => 'Set state to investigating',
+ state => 'investigating',
+ },
+ state => 'investigating',
+ },
+ {
+ desc => 'from authority user marks report as planned',
+ fields => {
+ name => $user->name,
+ may_show_name => 1,
+ add_alert => 0,
+ photo => '',
+ update => 'Set state to planned',
+ state => 'planned',
+ },
+ state => 'planned',
+ },
+ {
+ desc => 'from authority user marks report as in progress',
+ fields => {
+ name => $user->name,
+ may_show_name => 1,
+ add_alert => 0,
+ photo => '',
+ update => 'Set state to in progress',
+ state => 'in progress',
+ },
+ state => 'in progress',
+ },
+ {
+ desc => 'from authority user marks report as closed',
+ fields => {
+ name => $user->name,
+ may_show_name => 1,
+ add_alert => 0,
+ photo => '',
+ update => 'Set state to closed',
+ state => 'closed',
+ },
+ state => 'closed',
+ },
+ {
+ desc => 'from authority user marks report as fixed',
+ fields => {
+ name => $user->name,
+ may_show_name => 1,
+ add_alert => 0,
+ photo => '',
+ update => 'Set state to fixed',
+ state => 'fixed',
+ },
+ state => 'fixed - council',
+ },
+ {
+ desc => 'from authority user marks report as confirmed',
+ fields => {
+ name => $user->name,
+ may_show_name => 1,
+ add_alert => 0,
+ photo => '',
+ update => 'Set state to confirmed',
+ state => 'confirmed',
+ },
+ state => 'confirmed',
+ },
+ {
+ desc => 'from authority user marks report sent to two councils as fixed',
+ fields => {
+ name => $user->name,
+ may_show_name => 1,
+ add_alert => 0,
+ photo => '',
+ update => 'Set state to fixed',
+ state => 'fixed',
+ },
+ state => 'fixed - council',
+ report_councils => '2504,2505',
+ },
+) {
+ subtest $test->{desc} => sub {
+ $report->comments->delete;
+ if ( $test->{ report_councils } ) {
+ $report->council( $test->{ report_councils } );
+ $report->update;
+ }
+
+ $mech->log_in_ok( $user->email );
+ $user->from_council( 2504 );
+ $user->update;
+
+ $mech->get_ok("/report/$report_id");
+
+ $mech->submit_form_ok(
+ {
+ with_fields => $test->{fields},
+ },
+ 'submit update'
+ );
+
+ $report->discard_changes;
+ my $update = $report->comments->first;
+ ok $update, 'found update';
+ is $update->text, $test->{fields}->{update}, 'update text';
+ is $update->problem_state, $test->{state}, 'problem state set';
+
+ my $update_meta = $mech->extract_update_metas;
+ like $update_meta->[0], qr/marked as $test->{fields}->{state}$/, 'update meta includes state change';
+ like $update_meta->[0], qr{Test User \(Westminster City Council\)}, 'update meta includes council name';
+ $mech->content_contains( 'Test User (<strong>Westminster City Council</strong>)', 'council name in bold');
+
+ $report->discard_changes;
+ is $report->state, $test->{state}, 'state set';
+ };
+}
+
+$user->from_council(0);
+$user->update;
+
+$report->state('confirmed');
+$report->council('2504');
+$report->update;
+
for my $test (
{
desc => 'submit an update for a registered user, signing in with wrong password',
@@ -738,6 +935,34 @@ foreach my $test (
},
changed => { update => 'Update from owner' },
initial_banner => '',
+ initial_state => 'confirmed',
+ alert => 1, # we signed up for alerts before, do not unsign us
+ anonymous => 0,
+ answered => 0,
+ path => '/report/update',
+ content =>
+"Thanks, glad to hear it's been fixed! Could we just ask if you have ever reported a problem to a council before?",
+ },
+ {
+ desc => 'logged in reporter submits update and marks in progress problem fixed',
+ initial_values => {
+ name => 'Test User',
+ may_show_name => 1,
+ add_alert => 1,
+ photo => '',
+ update => '',
+ fixed => undef,
+ },
+ email => 'test@example.com',
+ fields => {
+ submit_update => 1,
+ update => 'update from owner',
+ add_alert => undef,
+ fixed => 1,
+ },
+ changed => { update => 'Update from owner' },
+ initial_banner => ' This problem is in progress. ',
+ initial_state => 'in progress',
alert => 1, # we signed up for alerts before, do not unsign us
anonymous => 0,
answered => 0,
@@ -765,6 +990,7 @@ foreach my $test (
},
changed => { update => 'Update from owner' },
initial_banner => '',
+ initial_state => 'confirmed',
alert => 1, # we signed up for alerts before, do not unsign us
anonymous => 0,
answered => 1,
@@ -783,7 +1009,7 @@ foreach my $test (
ok( $_->delete, 'deleted comment ' . $_->id ) for $report->comments;
$report->discard_changes;
- $report->state('confirmed');
+ $report->state( $test->{initial_state} );
$report->update;
my $questionnaire;
@@ -825,6 +1051,8 @@ foreach my $test (
my $results = { %{ $test->{fields} }, %{ $test->{changed} }, };
+ $report->discard_changes;
+
my $update = $report->comments->first;
ok $update, 'found update';
is $update->text, $results->{update}, 'update text';
@@ -832,6 +1060,8 @@ foreach my $test (
is $update->state, 'confirmed', 'update confirmed';
is $update->anonymous, $test->{anonymous}, 'user anonymous';
+ is $report->state, 'fixed - user', 'report state';
+
SKIP: {
skip( 'not answering questionnaire', 5 ) if $questionnaire;
@@ -851,6 +1081,8 @@ foreach my $test (
ok $questionnaire, 'questionnaire exists';
ok $questionnaire->ever_reported, 'ever reported is yes';
+ is $questionnaire->old_state(), $test->{initial_state}, 'questionnaire old state';
+ is $questionnaire->new_state(), 'fixed - user', 'questionnaire new state';
};
if ($questionnaire) {
diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t
new file mode 100644
index 000000000..c7bfe171c
--- /dev/null
+++ b/t/app/model/alert_type.t
@@ -0,0 +1,144 @@
+use strict;
+use warnings;
+use Test::More;
+use FixMyStreet::TestMech;
+
+mySociety::Locale::gettext_domain( 'FixMyStreet' );
+
+my $mech = FixMyStreet::TestMech->new();
+
+# this is the easiest way to make sure we're not going
+# to get any emails sent by data kicking about in the database
+FixMyStreet::App->model('DB::AlertType')->email_alerts();
+$mech->clear_emails_ok;
+
+my $user =
+ FixMyStreet::App->model('DB::User')
+ ->find_or_create( { email => 'test@example.com', name => 'Test User' } );
+ok $user, "created test user";
+
+my $user2 =
+ FixMyStreet::App->model('DB::User')
+ ->find_or_create( { email => 'commenter@example.com', name => 'Commenter' } );
+ok $user2, "created comment user";
+
+
+my $dt = DateTime->new(
+ year => 2011,
+ month => 04,
+ day => 16,
+ hour => 15,
+ minute => 47,
+ second => 23
+);
+
+my $report = FixMyStreet::App->model('DB::Problem')->find_or_create(
+ {
+ postcode => 'SW1A 1AA',
+ council => '2504',
+ areas => ',105255,11806,11828,2247,2504,',
+ category => 'Other',
+ title => 'Test 2',
+ detail => 'Test 2 Detail',
+ used_map => 't',
+ name => 'Test User',
+ anonymous => 'f',
+ state => 'closed',
+ confirmed => $dt->ymd . ' ' . $dt->hms,
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 't',
+ latitude => '51.5016605453401',
+ longitude => '-0.142497580865087',
+ user_id => $user->id,
+ }
+);
+my $report_id = $report->id;
+ok $report, "created test report - $report_id";
+
+my $comment = FixMyStreet::App->model('DB::Comment')->find_or_create(
+ {
+ problem_id => $report_id,
+ user_id => $user2->id,
+ name => 'Other User',
+ mark_fixed => 'false',
+ text => 'This is some update text',
+ state => 'confirmed',
+ confirmed => $dt->ymd . ' ' . $dt->hms,
+ anonymous => 'f',
+ }
+);
+my $comment2 = FixMyStreet::App->model('DB::Comment')->find_or_create(
+ {
+ problem_id => $report_id,
+ user_id => $user2->id,
+ name => 'Other User',
+ mark_fixed => 'false',
+ text => 'This is other update text',
+ state => 'confirmed',
+ confirmed => $dt->ymd . ' ' . $dt->hms,
+ anonymous => 'f',
+ }
+);
+
+$comment->confirmed( \"ms_current_timestamp() - '3 days'::interval" );
+$comment->update;
+
+my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create(
+ {
+ user => $user,
+ parameter => $report_id,
+ alert_type => 'new_updates',
+ whensubscribed => $dt->ymd . ' ' . $dt->hms,
+ confirmed => 1,
+ }
+);
+
+for my $test (
+ {
+ state => 'closed',
+ msg => 'This report is currently marked as closed',
+ },
+ {
+ state => 'fixed',
+ msg => 'This report is currently marked as fixed',
+ },
+ {
+ state => 'confirmed',
+ msg => 'This report is currently marked as open',
+ },
+) {
+ subtest "correct summary for state of $test->{state}" => sub {
+ $mech->clear_emails_ok;
+
+ my $sent = FixMyStreet::App->model('DB::AlertSent')->search(
+ {
+ alert_id => $alert->id,
+ parameter => $comment->id,
+ }
+ )->delete;
+
+ $report->state( $test->{state} );
+ $report->update;
+
+ FixMyStreet::App->model('DB::AlertType')->email_alerts();
+
+ $mech->email_count_is( 1 );
+ my $email = $mech->get_email;
+ my $msg = $test->{msg};
+ my $body = $email->body;
+
+ like $body, qr/$msg/, 'email says problem is ' . $test->{state};
+ like $body, qr{report/$report_id}, 'contains problem url';
+ like $body, qr/This is some update text/, 'contains update text';
+ unlike $body, qr/This is other update text/, 'does not contains other update text';
+
+ my $comments = $body =~ s/(------)//gs;
+ is $comments, 1, 'only 1 update';
+ };
+}
+
+done_testing();
+
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
index ed5207c2b..ad42c5fdf 100644
--- a/t/app/model/problem.t
+++ b/t/app/model/problem.t
@@ -257,6 +257,94 @@ for my $test (
};
}
+for my $test (
+ {
+ state => 'partial',
+ is_visible => 0,
+ is_fixed => 0,
+ is_open => 0,
+ is_closed => 0,
+ },
+ {
+ state => 'hidden',
+ is_visible => 0,
+ is_fixed => 0,
+ is_open => 0,
+ is_closed => 0,
+ },
+ {
+ state => 'unconfirmed',
+ is_visible => 0,
+ is_fixed => 0,
+ is_open => 0,
+ is_closed => 0,
+ },
+ {
+ state => 'confirmed',
+ is_visible => 1,
+ is_fixed => 0,
+ is_open => 1,
+ is_closed => 0,
+ },
+ {
+ state => 'investigating',
+ is_visible => 1,
+ is_fixed => 0,
+ is_open => 1,
+ is_closed => 0,
+ },
+ {
+ state => 'planned',
+ is_visible => 1,
+ is_fixed => 0,
+ is_open => 1,
+ is_closed => 0,
+ },
+ {
+ state => 'in progress',
+ is_visible => 1,
+ is_fixed => 0,
+ is_open => 1,
+ is_closed => 0,
+ },
+ {
+ state => 'fixed',
+ is_visible => 1,
+ is_fixed => 1,
+ is_open => 0,
+ is_closed => 0,
+ },
+ {
+ state => 'fixed - council',
+ is_visible => 1,
+ is_fixed => 1,
+ is_open => 0,
+ is_closed => 0,
+ },
+ {
+ state => 'fixed - user',
+ is_visible => 1,
+ is_fixed => 1,
+ is_open => 0,
+ is_closed => 0,
+ },
+ {
+ state => 'closed',
+ is_visible => 1,
+ is_fixed => 0,
+ is_open => 0,
+ is_closed => 1,
+ },
+) {
+ subtest $test->{state} . ' is fixed/open/closed/visible' => sub {
+ $problem->state( $test->{state} );
+ is $problem->is_visible, $test->{is_visible}, 'is_visible';
+ is $problem->is_fixed, $test->{is_fixed}, 'is_fixed';
+ is $problem->is_closed, $test->{is_closed}, 'is_closed';
+ is $problem->is_open, $test->{is_open}, 'is_open';
+ };
+}
+
$problem->comments->delete;
$problem->delete;
$user->delete;
diff --git a/t/app/model/questionnaire.t b/t/app/model/questionnaire.t
new file mode 100644
index 000000000..60b52043a
--- /dev/null
+++ b/t/app/model/questionnaire.t
@@ -0,0 +1,106 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+use FixMyStreet;
+use FixMyStreet::TestMech;
+
+my $user = FixMyStreet::App->model('DB::User')->find_or_create( { email => 'test@example.com' } );
+
+my $problem = FixMyStreet::App->model('DB::Problem')->create(
+ {
+ postcode => 'EH99 1SP',
+ latitude => 1,
+ longitude => 1,
+ areas => 1,
+ title => 'to be sent',
+ detail => 'detail',
+ used_map => 1,
+ user_id => 1,
+ name => 'A Name',
+ state => 'confirmed',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ confirmed => \"ms_current_timestamp() - '5 weeks'::interval",
+ whensent => \"ms_current_timestamp() - '5 weeks'::interval",
+ user => $user,
+ anonymous => 0,
+ }
+);
+
+diag $problem->id;
+
+my $mech = FixMyStreet::TestMech->new;
+
+for my $test (
+ {
+ state => 'unconfirmed',
+ send_email => 0,
+ },
+ {
+ state => 'partial',
+ send_email => 0,
+ },
+ {
+ state => 'hidden',
+ send_email => 0,
+ },
+ {
+ state => 'confirmed',
+ send_email => 1,
+ },
+ {
+ state => 'investigating',
+ send_email => 1,
+ },
+ {
+ state => 'planned',
+ send_email => 1,
+ },
+ {
+ state => 'in progress',
+ send_email => 1,
+ },
+ {
+ state => 'fixed',
+ send_email => 1,
+ },
+ {
+ state => 'fixed - council',
+ send_email => 1,
+ },
+ {
+ state => 'fixed - user',
+ send_email => 1,
+ },
+ {
+ state => 'closed',
+ send_email => 1,
+ },
+) {
+ subtest "correct questionnaire behviour for state $test->{state}" => sub {
+ $problem->discard_changes;
+ $problem->state( $test->{state} );
+ $problem->send_questionnaire( 1 );
+ $problem->update;
+
+ $problem->questionnaires->delete;
+
+ $mech->email_count_is(0);
+
+ FixMyStreet::App->model('DB::Questionnaire')
+ ->send_questionnaires( { site => 'fixmystreet' } );
+
+ $mech->email_count_is( $test->{send_email} );
+
+ $mech->clear_emails_ok();
+ }
+}
+
+$mech->delete_user( $user );
+
+done_testing();
diff --git a/t/map/tilma/original.t b/t/map/tilma/original.t
new file mode 100644
index 000000000..3add7719e
--- /dev/null
+++ b/t/map/tilma/original.t
@@ -0,0 +1,108 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More;
+use FixMyStreet::App;
+use FixMyStreet::Map;
+use FixMyStreet::TestMech;
+use DateTime;
+use mySociety::Locale;
+
+my $mech = FixMyStreet::TestMech->new;
+
+mySociety::Locale::gettext_domain('FixMyStreet');
+
+FixMyStreet::Map::set_map_class();
+my $r = Catalyst::Request->new( { base => URI->new('/'), uri => URI->new('http://fixmystreet.com/test'), parameters => { bbox => '-7.6,49.7,-7.5,49.8' } } );
+
+my $c = FixMyStreet::App->new( {
+ request => $r,
+});
+
+$mech->delete_user('test@example.com');
+my $user =
+ FixMyStreet::App->model('DB::User')
+ ->find_or_create( { email => 'test@example.com', name => 'Test User' } );
+ok $user, "created test user";
+
+my $dt = DateTime->now();
+
+
+my $report = FixMyStreet::App->model('DB::Problem')->find_or_create(
+ {
+ postcode => 'SW1A 1AA',
+ council => '2504',
+ areas => ',105255,11806,11828,2247,2504,',
+ category => 'Other',
+ title => 'Test 2',
+ detail => 'Test 2 Detail',
+ used_map => 't',
+ name => 'Test User',
+ anonymous => 'f',
+ state => 'fixed',
+ confirmed => $dt->ymd . ' ' . $dt->hms,
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 't',
+ latitude => '49.7668057243776',
+ longitude => '-7.55715980363992',
+ user_id => $user->id,
+ }
+);
+
+for my $test (
+ {
+ state => 'fixed',
+ colour => 'green',
+ },
+ {
+ state => 'fixed - user',
+ colour => 'green',
+ },
+ {
+ state => 'fixed - council',
+ colour => 'green',
+ },
+ {
+ state => 'confirmed',
+ colour => 'red',
+ },
+ {
+ state => 'investigating',
+ colour => 'red',
+ },
+ {
+ state => 'planned',
+ colour => 'red',
+ },
+ {
+ state => 'in progress',
+ colour => 'red',
+ },
+) {
+ subtest "pin colour for state $test->{state}" => sub {
+ $report->state($test->{state});
+ $report->update;
+
+ my ( $pins, $around_map_list, $nearby, $dist ) =
+ FixMyStreet::Map::map_pins( $c, 0, 0, 0, 0 );
+
+ ok $pins;
+ ok $around_map_list;
+ ok $nearby;
+ ok $dist;
+
+ my $id = $report->id;
+ my $colour = $test->{colour};
+
+ is $pins->[0][2], $colour, 'pin colour';
+ };
+}
+
+$mech->delete_user( $user );
+
+
+done_testing();