diff options
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 31 | ||||
-rw-r--r-- | t/app/model/problem.t | 128 |
2 files changed, 69 insertions, 90 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index c607cc89b..fa3772310 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -162,6 +162,25 @@ sub fixed_states { =head2 + @states = FixMyStreet::DB::Problem::closed_states(); + +Get a list or states that should be regarded as closed. If called in +array context then returns an array of names, otherwise returns a +HASHREF. + +=cut + +sub closed_states { + my $states = { + 'closed' => 1, + }; + + return wantarray ? keys %{$states} : $states; +} + + +=head2 + @states = FixMyStreet::DB::Problem::visible_states(); Get a list or states that should be visible on the site. If called in @@ -376,6 +395,18 @@ sub is_fixed { return exists $self->fixed_states->{ $self->state } ? 1 : 0; } +=head2 is_closed + +Returns 1 if the problem is in a closed state otherwise 0. + +=cut + +sub is_closed { + my $self = shift; + + return exists $self->closed_states->{ $self->state } ? 1 : 0; +} + =head2 is_visible Returns 1 if the problem should be displayed on the site otherwise 0. diff --git a/t/app/model/problem.t b/t/app/model/problem.t index e7c9d79bb..4c6be6a8d 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -154,141 +154,89 @@ for my $test ( for my $test ( { - state => 'unconfirmed', - is_open => 0, - }, - { - 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 => 'closed', - is_open => 0, - }, -) { - subtest $test->{state} . ' is open/closed' => sub { - $problem->state( $test->{state} ); - is $problem->is_open, $test->{is_open}, 'is_open'; - }; -} - -for my $test ( - { - state => 'unconfirmed', - is_fixed => 0, - }, - { - state => 'confirmed', - is_fixed => 0, - }, - { - state => 'investigating', - is_fixed => 0, - }, - { - state => 'planned', - is_fixed => 0, - }, - { - state => 'in progress', - is_fixed => 0, - }, - { - state => 'fixed', - is_fixed => 1, - }, - { - state => 'fixed - council', - is_fixed => 1, - }, - { - state => 'fixed - user', - is_fixed => 1, - }, - { - state => 'closed', - is_fixed => 0, - }, -) { - subtest $test->{state} . ' is fixed/open' => sub { - $problem->state( $test->{state} ); - is $problem->is_fixed, $test->{is_fixed}, 'is_fixed'; - }; -} - -for my $test ( - { state => 'partial', - is_visible => 0, + 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' => sub { + 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'; }; } |