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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
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 FixMyStreet::Cobrand::AnonAllowedForCategory;
use parent 'FixMyStreet::Cobrand::FixMyStreet';
sub allow_anonymous_reports {
my ($self, $category) = @_;
$category ||= $self->{c}->stash->{category};
return 'button' if $category eq 'Trees';
}
sub anonymous_account { { email => 'anoncategory@example.org', name => 'Anonymous Category' } }
package FixMyStreet::Cobrand::AnonAllowedByCategory;
use parent 'FixMyStreet::Cobrand::UKCouncils';
sub council_url { 'anonbycategory' }
sub council_name { 'Edinburgh City Council' }
sub council_area { 'Edinburgh' }
sub council_area_id { 2651 }
sub anonymous_account { { email => 'anoncategory@example.org', name => 'Anonymous Category' } }
package main;
use FixMyStreet::TestMech;
# 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::DB->resultset('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::DB->resultset('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';
is $report->get_extra_metadata('contributed_by'), $staffuser->id;
my $alert = FixMyStreet::DB->resultset('Alert')->find( {
user => $report->user,
alert_type => 'new_updates',
parameter => $report->id,
} );
is $alert, undef, "no alert created";
$mech->log_out_ok;
};
};
FixMyStreet::override_config {
ALLOWED_COBRANDS => 'anonallowedforcategory',
MAPIT_URL => 'http://mapit.uk/',
}, sub {
subtest "test report creation anonymously by button, per category" => 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_category_part_only',
with_fields => {
category => 'Street lighting',
}
}, "submit category with no anonymous reporting");
$mech->content_lacks('<button name="report_anonymously" value="yes" class="btn btn--block">'); # non-JS button, JS button always there
$mech->submit_form_ok({
button => 'submit_register',
with_fields => {
category => 'Trees',
}
}, "submit category with anonymous reporting");
$mech->submit_form_ok({
button => 'report_anonymously',
with_fields => {
title => 'Test Report',
detail => 'Test report details.',
}
}, "submit good details");
$mech->content_contains('Thank you');
my $report = FixMyStreet::DB->resultset("Problem")->search({}, { order_by => { -desc => 'id' } })->first;
ok $report, "Found the report";
is $report->state, 'confirmed', "report confirmed";
is $report->bodies_str, $body->id;
is $report->name, 'Anonymous Category';
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';
};
};
$contact2->set_extra_metadata( anonymous_allowed => 1 );
$contact2->update;
FixMyStreet::override_config {
ALLOWED_COBRANDS => 'anonallowedbycategory',
MAPIT_URL => 'http://mapit.uk/',
}, sub {
subtest "test report creation anonymously by button, per category from metadata" => 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_category_part_only',
with_fields => {
category => 'Street lighting',
}
}, "submit category with no anonymous reporting");
$mech->content_lacks('<button name="report_anonymously" value="yes" class="btn btn--block">'); # non-JS button, JS button always there
$mech->submit_form_ok({
button => 'submit_register',
with_fields => {
category => 'Trees',
}
}, "submit category with anonymous reporting");
$mech->submit_form_ok({
button => 'report_anonymously',
with_fields => {
title => 'Test Report',
detail => 'Test report details.',
}
}, "submit good details");
$mech->content_contains('Your issue is on its way to the council');
my $report = FixMyStreet::DB->resultset("Problem")->search({}, { order_by => { -desc => 'id' } })->first;
ok $report, "Found the report";
is $report->state, 'confirmed', "report confirmed";
is $report->bodies_str, $body->id;
is $report->name, 'Anonymous Category';
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';
};
};
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
BASE_URL => 'https://www.fixmystreet.com',
MAPIT_URL => 'http://mapit.uk/',
}, sub {
subtest "test anonymously by button, per category from metadata limited to cobrand" => 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_category_part_only',
with_fields => {
category => 'Trees',
}
}, "submit category with no anonymous reporting");
$mech->content_lacks('<button name="report_anonymously" value="yes" class="btn btn--block">'); # non-JS button, JS button always there
};
};
done_testing();
|