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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
package FixMyStreet::Cobrand::AnonAllowed;
use parent 'FixMyStreet::Cobrand::FixMyStreet';
sub allow_anonymous_reports { 1 }
sub anonymous_account { { email => 'anon@example.org', name => 'Anonymous' } }
package FixMyStreet::Cobrand::AnonAllowedByButton;
use parent 'FixMyStreet::Cobrand::FixMyStreet';
sub allow_anonymous_reports { 'button' }
sub anonymous_account { { email => 'anonbutton@example.org', name => 'Anonymous Button' } }
package main;
use FixMyStreet::TestMech;
use FixMyStreet::App;
# 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, 'Edinburgh');
my $staffuser = $mech->create_user_ok('counciluser@example.com', name => 'Council User', from_body => $body);
$staffuser->user_body_permissions->create({
body => $body,
permission_type => 'contribute_as_body',
});
$staffuser->user_body_permissions->create({
body => $body,
permission_type => 'default_to_body',
});
my $contact1 = $mech->create_contact_ok(
body_id => $body->id,
category => 'Street lighting',
email => 'highways@example.com',
);
my $contact2 = $mech->create_contact_ok(
body_id => $body->id,
category => 'Trees',
email => 'trees@example.com',
);
FixMyStreet::override_config {
ALLOWED_COBRANDS => 'anonallowed',
MAPIT_URL => 'http://mapit.uk/',
}, sub {
subtest "check form errors when anonymous account is on" => sub {
$mech->get_ok('/around');
$mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } }, "submit location" );
$mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
$mech->submit_form_ok( { with_fields => { category => "Street lighting" } }, "submit form" );
my @errors = (
'Please enter a subject',
'Please enter some details',
# No user errors
);
is_deeply [ sort @{$mech->page_errors} ], [ sort @errors ], "check errors";
};
subtest "test report creation anonymously" => sub {
$mech->get_ok('/around');
$mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" );
$mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
$mech->submit_form_ok(
{
button => 'submit_register',
with_fields => {
title => 'Test Report',
detail => 'Test report details.',
name => 'Joe Bloggs',
may_show_name => '1',
category => 'Street lighting',
}
},
"submit good details"
);
$mech->content_contains('Thank you');
is_deeply $mech->page_errors, [], "check there were no errors";
my $report = FixMyStreet::DB->resultset("Problem")->first;
ok $report, "Found the report";
is $report->state, 'confirmed', "report confirmed";
$mech->get_ok( '/report/' . $report->id );
is $report->bodies_str, $body->id;
is $report->name, 'Anonymous';
is $report->anonymous, 0; # Doesn't change behaviour here, but uses anon account's name always
my $alert = FixMyStreet::App->model('DB::Alert')->find( {
user => $report->user,
alert_type => 'new_updates',
parameter => $report->id,
} );
is $alert, undef, "no alert created";
$mech->not_logged_in_ok;
};
};
FixMyStreet::override_config {
ALLOWED_COBRANDS => 'anonallowedbybutton',
MAPIT_URL => 'http://mapit.uk/',
}, sub {
subtest "test report creation anonymously by button" => sub {
$mech->get_ok('/around');
$mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" );
$mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
$mech->submit_form_ok(
{
button => 'submit_register',
with_fields => {
title => 'Test Report',
detail => 'Test report details.',
name => 'Joe Bloggs',
may_show_name => '1',
category => 'Street lighting',
}
},
"submit good details"
);
is_deeply $mech->page_errors, [
'Please enter your email'
], "check there were no errors";
$mech->get_ok('/around');
$mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" );
$mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
$mech->submit_form_ok(
{
button => 'report_anonymously',
with_fields => {
title => 'Test Report',
detail => 'Test report details.',
category => 'Street lighting',
}
},
"submit good details"
);
$mech->content_contains('Thank you');
is_deeply $mech->page_errors, [], "check there were no errors";
my $report = FixMyStreet::DB->resultset("Problem")->search({}, { order_by => { -desc => 'id' } })->first;
ok $report, "Found the report";
is $report->state, 'confirmed', "report confirmed";
$mech->get_ok( '/report/' . $report->id );
is $report->bodies_str, $body->id;
is $report->name, 'Anonymous Button';
is $report->anonymous, 1; # Doesn't change behaviour here, but uses anon account's name always
is $report->get_extra_metadata('contributed_as'), 'anonymous_user';
my $alert = FixMyStreet::App->model('DB::Alert')->find( {
user => $report->user,
alert_type => 'new_updates',
parameter => $report->id,
} );
is $alert, undef, "no alert created";
$mech->not_logged_in_ok;
};
subtest "test report creation anonymously by staff user" => sub {
FixMyStreet::DB->resultset("Problem")->delete_all;
$mech->log_in_ok( $staffuser->email );
$mech->get_ok('/around');
$mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" );
$mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
$mech->submit_form_ok(
{
button => 'report_anonymously',
with_fields => {
title => 'Test Report',
detail => 'Test report details.',
category => 'Street lighting',
}
},
"submit good details"
);
$mech->content_contains('Thank you');
is_deeply $mech->page_errors, [], "check there were no errors";
my $report = FixMyStreet::DB->resultset("Problem")->first;
ok $report, "Found the report";
is $report->state, 'confirmed', "report confirmed";
$mech->get_ok( '/report/' . $report->id );
is $report->bodies_str, $body->id;
is $report->name, 'Anonymous Button';
is $report->anonymous, 1;
is $report->get_extra_metadata('contributed_as'), 'anonymous_user';
my $alert = FixMyStreet::App->model('DB::Alert')->find( {
user => $report->user,
alert_type => 'new_updates',
parameter => $report->id,
} );
is $alert, undef, "no alert created";
$mech->log_out_ok;
};
};
done_testing();
|