aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Test.pm
blob: ce54f004f9d7be315ae76a9c8d20971e5e5167c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package FixMyStreet::App::Controller::Test;
use Moose;
use namespace::autoclean;

use File::Basename;

BEGIN { extends 'Catalyst::Controller'; }

=head1 NAME

FixMyStreet::App::Controller::Test - Catalyst Controller

=head1 DESCRIPTION

Test-helping Catalyst Controller.

=head1 METHODS

=over 4

=item auto

Makes sure this controller is only available when run in test.

=cut

sub auto : Private {
    my ($self, $c) = @_;
    $c->detach( '/page_error_404_not_found' ) unless FixMyStreet->test_mode;
    return 1;
}

=item setup

Sets up a particular browser test.

=cut

sub setup : Path('/_test/setup') : Args(1) {
    my ( $self, $c, $test ) = @_;
    if ($test eq 'regression-duplicate-hide') {
        my $problem = FixMyStreet::DB->resultset("Problem")->find(1);
        $problem->update({ category => 'Skips' });
        $c->response->body("OK");
    } elsif ( $test eq 'regression-duplicate-stopper') {
        my $problem = FixMyStreet::DB->resultset("Problem")->find(1);
        $problem->update({ category => 'Flytipping' });
        my $category = FixMyStreet::DB->resultset('Contact')->search({
            category => 'Flytipping',
        })->first;
        $category->push_extra_fields({
            code => 'hazardous',
            datatype => 'singlevaluelist',
            description => 'Hazardous material',
            order => 0,
            variable => 'true',
            values => [
                { key => 'yes', name => 'Yes', disable => 1, disable_message => 'Please phone' },
                { key => 'no', name => 'No' },
            ],
        });
        $category->update;
        $c->response->body("OK");
    } elsif ($test eq 'simple-service-check') {
        my $problem = FixMyStreet::DB->resultset("Problem")->search(undef, { order_by => { -desc => 'id' } })->first;
        $c->response->body($problem->service);
    }
}

sub teardown : Path('/_test/teardown') : Args(1) {
    my ( $self, $c, $test ) = @_;
    if ($test eq 'regression-duplicate-hide') {
        my $problem = FixMyStreet::DB->resultset("Problem")->find(1);
        $problem->update({ category => 'Potholes' });
        $c->response->body("OK");
    } elsif ( $test eq 'regression-duplicate-stopper') {
        my $problem = FixMyStreet::DB->resultset("Problem")->find(1);
        $problem->update({ category => 'Potholes' });
        my $category = FixMyStreet::DB->resultset('Contact')->search({
            category => 'Flytipping',
        })->first;
        $category->remove_extra_field('hazardous');
        $category->update;
        $c->response->body("OK");
    }
}

__PACKAGE__->meta->make_immutable;

1;