aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--db/schema.sql6
-rw-r--r--db/schema_0006-alter_problem_state.sql19
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm37
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm2
-rw-r--r--t/app/controller/report_display.t49
-rw-r--r--t/app/model/problem.t44
-rw-r--r--t/app/model/questionnaire.t106
-rw-r--r--templates/web/default/report/display.html2
8 files changed, 263 insertions, 2 deletions
diff --git a/db/schema.sql b/db/schema.sql
index 9c5b3d8fd..823a60485 100644
--- a/db/schema.sql
+++ b/db/schema.sql
@@ -165,7 +165,13 @@ create table problem (
state text not null check (
state = 'unconfirmed'
or state = 'confirmed'
+ or state = 'investigating'
+ or state = 'planned'
+ or state = 'in progress'
+ or state = 'will not fix'
or state = 'fixed'
+ or state = 'fixed - council'
+ or state = 'fixed - user'
or state = 'hidden'
or state = 'partial'
),
diff --git a/db/schema_0006-alter_problem_state.sql b/db/schema_0006-alter_problem_state.sql
new file mode 100644
index 000000000..1fdd30cb2
--- /dev/null
+++ b/db/schema_0006-alter_problem_state.sql
@@ -0,0 +1,19 @@
+begin;
+
+ ALTER TABLE problem DROP CONSTRAINT problem_state_check;
+
+ ALTER TABLE problem ADD CONSTRAINT problem_state_check CHECK (
+ state = 'unconfirmed'
+ or state = 'confirmed'
+ or state = 'investigating'
+ or state = 'planned'
+ or state = 'in progress'
+ or state = 'will not fix'
+ or state = 'fixed'
+ or state = 'fixed - council'
+ or state = 'fixed - user'
+ or state = 'hidden'
+ or state = 'partial'
+ );
+
+commit;
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index 366024c7c..47dac1e8e 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -284,6 +284,43 @@ sub get_photo_params {
return $photo;
}
+=head2 is_open
+
+Returns 1 if the problem is in a open state otherwise 0;
+
+=cut
+
+sub is_open {
+ my $self = shift;
+
+ my %open_states = (
+ unconfirmed => 1,
+ partial => 1,
+ confirmed => 1,
+ 'planned' => 1,
+ 'investigating' => 1,
+ 'in progress' => 1,
+ );
+
+ return exists $open_states{ $self->state } ? 1 : 0;
+}
+
+=head2
+
+ @states = FixMyStreet::DB::Problem::visible_states();
+
+Returns a list of states that should be displayed on the site.
+
+=cut
+
+sub visible_states {
+ return (
+ 'confirmed', 'planned', 'investigating',
+ 'in progress', 'fixed', 'fixed - council',
+ 'fixed - user', 'will not fix',
+ );
+}
+
=head2 meta_line
Returns a string to be used on a problem report page, describing some of the
diff --git a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
index e490c77a6..665e0e3e0 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
@@ -19,7 +19,7 @@ sub send_questionnaires_period {
# Select all problems that need a questionnaire email sending
my $q_params = {
- state => [ 'confirmed', 'fixed' ],
+ state => [ FixMyStreet::DB::Result::Problem::visible_states() ],
whensent => [
'-and',
{ '!=', undef },
diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t
index 1f857a387..746f68cf6 100644
--- a/t/app/controller/report_display.t
+++ b/t/app/controller/report_display.t
@@ -119,6 +119,55 @@ subtest "test a good report" => sub {
is $update_form->value($_), $fields{$_}, "$_ value" for keys %fields;
};
+for my $test (
+ {
+ state => 'confirmed',
+ display => 1,
+ },
+ {
+ state => 'investigating',
+ display => 1,
+ },
+ {
+ state => 'planned',
+ display => 1,
+ },
+ {
+ state => 'in progress',
+ display => 1,
+ },
+ {
+ state => 'fixed',
+ display => 0,
+ },
+ {
+ state => 'fixed - council',
+ display => 0,
+ },
+ {
+ state => 'fixed - user',
+ display => 0,
+ },
+ {
+ state => 'will not fix',
+ display => 0,
+ },
+) {
+ subtest "check fixed checkbox display for state $test->{state}" => sub {
+ $report->state( $test->{state} );
+ $report->update;
+ $mech->get_ok("/report/$report_id");
+
+ my $update_form = $mech->form_name('updateForm');
+
+ if ( $test->{display} ) {
+ ok defined $update_form->find_input('#form_fixed', 'checkbox'), "fixed checkbox display";
+ } else {
+ is $update_form->find_input('#form_fixed', 'checkbox'), undef, "fixed checkbox display";
+ }
+ };
+}
+
foreach my $meta (
{
anonymous => 'f',
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
index 1b8804fce..5a5eb2520 100644
--- a/t/app/model/problem.t
+++ b/t/app/model/problem.t
@@ -152,4 +152,48 @@ for my $test (
};
}
+for my $test (
+ {
+ state => 'unconfirmed',
+ is_open => 1,
+ },
+ {
+ state => 'confirmed',
+ is_open => 1,
+ },
+ {
+ state => 'investigating',
+ is_open => 1,
+ },
+ {
+ state => 'planned',
+ is_open => 1,
+ },
+ {
+ state => 'in progress',
+ is_open => 1,
+ },
+ {
+ state => 'fixed',
+ is_open => 0,
+ },
+ {
+ state => 'fixed - council',
+ is_open => 0,
+ },
+ {
+ state => 'fixed - user',
+ is_open => 0,
+ },
+ {
+ state => 'will not fix',
+ is_open => 0,
+ },
+) {
+ subtest $test->{state} . ' is open/closed' => sub {
+ $problem->state( $test->{state} );
+ is $problem->is_open, $test->{is_open}, 'is_open';
+ };
+}
+
done_testing();
diff --git a/t/app/model/questionnaire.t b/t/app/model/questionnaire.t
new file mode 100644
index 000000000..2bc8f9b2c
--- /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 => 'will not fix',
+ 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/templates/web/default/report/display.html b/templates/web/default/report/display.html
index 1f4456086..89e2b6df2 100644
--- a/templates/web/default/report/display.html
+++ b/templates/web/default/report/display.html
@@ -105,7 +105,7 @@
</div>
- [% IF problem.state != 'fixed' %]
+ [% IF problem.is_open %]
<div class="checkbox">
<input type="checkbox" name="fixed" id="form_fixed" value="1"[% fixed %]>
<label for="form_fixed">[% loc('This problem has been fixed') %]</label>