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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
|
use strict;
use utf8; # sign in error message has – in it
use warnings;
use Test::More;
use utf8;
use FixMyStreet::TestMech;
use Web::Scraper;
use Path::Class;
my $mech = FixMyStreet::TestMech->new;
$mech->get_ok('/report/new');
my $sample_file = file(__FILE__)->parent->file("sample.jpg")->stringify;
ok -e $sample_file, "sample file $sample_file exists";
subtest "test that bare requests to /report/new get redirected" => sub {
$mech->get_ok('/report/new');
is $mech->uri->path, '/around', "went to /around";
is_deeply { $mech->uri->query_form }, {}, "query empty";
$mech->get_ok('/report/new?pc=SW1A%201AA');
is $mech->uri->path, '/around', "went to /around";
is_deeply { $mech->uri->query_form }, { pc => 'SW1A 1AA' },
"pc correctly transferred";
};
my %contact_params = (
confirmed => 1,
deleted => 0,
editor => 'Test',
whenedited => \'current_timestamp',
note => 'Created for test',
);
# Let's make some contacts to send things to!
FixMyStreet::App->model('DB::Contact')->search( {
email => { 'like', '%example.com' },
} )->delete;
my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
area_id => 2651, # Edinburgh
category => 'Street lighting',
email => 'highways@example.com',
} );
my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
area_id => 2226, # Gloucestershire
category => 'Potholes',
email => 'potholes@example.com',
} );
my $contact3 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
area_id => 2326, # Cheltenham
category => 'Trees',
email => 'trees@example.com',
} );
my $contact4 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
area_id => 2482, # Bromley
category => 'Trees',
email => 'trees@example.com',
} );
my $contact5 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
area_id => 2651, # Edinburgh
category => 'Trees',
email => 'trees@example.com',
} );
ok $contact1, "created test contact 1";
ok $contact2, "created test contact 2";
ok $contact3, "created test contact 3";
ok $contact4, "created test contact 4";
ok $contact5, "created test contact 5";
# test that the various bit of form get filled in and errors correctly
# generated.
foreach my $test (
{
msg => 'all fields empty',
pc => 'SW1A 1AA',
fields => {
title => '',
detail => '',
photo => '',
name => '',
may_show_name => '1',
email => '',
phone => '',
category => 'Street lighting',
password_sign_in => '',
password_register => '',
remember_me => undef,
},
changes => {},
errors => [
'Please enter a subject',
'Please enter some details',
'Please enter your email',
'Please enter your name',
],
},
{
msg => 'may_show_name is remembered',
pc => 'SW1A 1AA',
fields => {
title => '',
detail => '',
photo => '',
name => '',
may_show_name => undef,
email => '',
phone => '',
category => 'Street lighting',
password_sign_in => '',
password_register => '',
remember_me => undef,
},
changes => {},
errors => [
'Please enter a subject',
'Please enter some details',
'Please enter your email',
'Please enter your name',
],
},
{
msg => 'may_show_name unchanged if name is present (stays false)',
pc => 'SW1A 1AA',
fields => {
title => '',
detail => '',
photo => '',
name => 'Bob Jones',
may_show_name => undef,
email => '',
phone => '',
category => 'Street lighting',
password_sign_in => '',
password_register => '',
remember_me => undef,
},
changes => {},
errors => [
'Please enter a subject',
'Please enter some details',
'Please enter your email',
],
},
{
msg => 'may_show_name unchanged if name is present (stays true)',
pc => 'SW1A 1AA',
fields => {
title => '',
detail => '',
photo => '',
name => 'Bob Jones',
may_show_name => '1',
email => '',
phone => '',
category => 'Street lighting',
password_sign_in => '',
password_register => '',
remember_me => undef,
},
changes => {},
errors => [
'Please enter a subject',
'Please enter some details',
'Please enter your email',
],
},
{
msg => 'title and details tidied up',
pc => 'SW1A 1AA',
fields => {
title => "DOG SHIT\r\nON WALLS",
detail => "on this portakabin -\r\n\r\nmore of a portaloo HEH!!",
photo => '',
name => 'Bob Jones',
may_show_name => '1',
email => '',
phone => '',
category => 'Street lighting',
password_sign_in => '',
password_register => '',
remember_me => undef,
},
changes => {
title => 'Dog poo on walls',
detail =>
"On this [portable cabin] -\n\nMore of a [portable loo] HEH!!",
},
errors => [ 'Please enter your email', ],
},
{
msg => 'name too short',
pc => 'SW1A 1AA',
fields => {
title => 'Test title',
detail => 'Test detail',
photo => '',
name => 'DUDE',
may_show_name => '1',
email => '',
phone => '',
category => 'Street lighting',
password_sign_in => '',
password_register => '',
remember_me => undef,
},
changes => {},
errors => [
'Please enter your email',
'Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below',
],
},
{
msg => 'name is anonymous',
pc => 'SW1A 1AA',
fields => {
title => 'Test title',
detail => 'Test detail',
photo => '',
name => 'anonymous',
may_show_name => '1',
email => '',
phone => '',
category => 'Street lighting',
password_sign_in => '',
password_register => '',
remember_me => undef,
},
changes => {},
errors => [
'Please enter your email',
'Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below',
],
},
{
msg => 'email invalid',
pc => 'SW1A 1AA',
fields => {
title => 'Test title',
detail => 'Test detail',
photo => '',
name => 'Joe Smith',
may_show_name => '1',
email => 'not an email',
phone => '',
category => 'Street lighting',
password_sign_in => '',
password_register => '',
remember_me => undef,
},
changes => { email => 'notanemail', },
errors => [ 'Please enter a valid email', ],
},
{
msg => 'cleanup title and detail',
pc => 'SW1A 1AA',
fields => {
title => " Test title ",
detail => " first line \n\n second\nline\n\n ",
photo => '',
name => '',
may_show_name => '1',
email => '',
phone => '',
category => 'Street lighting',
password_sign_in => '',
password_register => '',
remember_me => undef,
},
changes => {
title => 'Test title',
detail => "First line\n\nSecond line",
},
errors => [
'Please enter your email',
'Please enter your name',
],
},
{
msg => 'clean up name and email',
pc => 'SW1A 1AA',
fields => {
title => '',
detail => '',
photo => '',
name => ' Bob Jones ',
may_show_name => '1',
email => ' BOB @ExAmplE.COM ',
phone => '',
category => 'Street lighting',
password_sign_in => '',
password_register => '',
remember_me => undef,
},
changes => {
name => 'Bob Jones',
email => 'bob@example.com',
},
errors => [ 'Please enter a subject', 'Please enter some details', ],
},
{
msg => 'non-photo upload gives error',
pc => 'SW1A 1AA',
fields => {
title => 'Title',
detail => 'Detail',
photo => [ [ undef, 'bad.txt', Content => 'This is not a JPEG', Content_Type => 'text/plain' ], 1 ],
name => 'Bob Jones',
may_show_name => '1',
email => 'bob@example.com',
phone => '',
category => 'Street lighting',
password_sign_in => '',
password_register => '',
remember_me => undef,
},
changes => {
photo => '',
},
errors => [ "Please upload a JPEG image only" ],
},
{
msg => 'bad photo upload gives error',
pc => 'SW1A 1AA',
fields => {
title => 'Title',
detail => 'Detail',
photo => [ [ undef, 'fake.jpeg', Content => 'This is not a JPEG', Content_Type => 'image/jpeg' ], 1 ],
name => 'Bob Jones',
may_show_name => '1',
email => 'bob@example.com',
phone => '',
category => 'Street lighting',
password_sign_in => '',
password_register => '',
remember_me => undef,
},
changes => {
photo => '',
},
errors => [ "That image doesn't appear to have uploaded correctly (Please upload a JPEG image only ), please try again." ],
},
{
msg => 'photo with octet-stream gets through okay',
pc => 'SW1A 1AA',
fields => {
title => '',
detail => 'Detail',
photo => [ [ $sample_file, undef, Content_Type => 'application/octet-stream' ], 1 ],
name => 'Bob Jones',
may_show_name => '1',
email => 'bob@example.com',
phone => '',
category => 'Street lighting',
password_sign_in => '',
password_register => '',
remember_me => undef,
},
changes => {
photo => '',
},
errors => [ "Please enter a subject" ],
},
)
{
subtest "check form errors where $test->{msg}" => sub {
$mech->get_ok('/around');
# submit initial pc form
$mech->submit_form_ok( { with_fields => { pc => $test->{pc} } },
"submit location" );
is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'";
# click through to the report page
$mech->follow_link_ok( { text_regex => qr/skip this step/i, },
"follow 'skip this step' link" );
# submit the main form
$mech->submit_form_ok( { with_fields => $test->{fields} },
"submit form" );
# check that we got the errors expected
is_deeply $mech->form_errors, $test->{errors}, "check errors";
# check that fields have changed as expected
my $new_values = {
%{ $test->{fields} }, # values added to form
%{ $test->{changes} }, # changes we expect
};
is_deeply $mech->visible_form_values, $new_values,
"values correctly changed";
};
}
my $first_user;
foreach my $test (
{
desc => 'does not have an account, does not set a password',
user => 0, password => 0,
},
{
desc => 'does not have an account, sets a password',
user => 0, password => 1,
},
{
desc => 'does have an account and is not signed in; does not sign in, does not set a password',
user => 1, password => 0,
},
{
desc => 'does have an account and is not signed in; does not sign in, sets a password',
user => 1, password => 1,
},
) {
subtest "test report creation for a user who " . $test->{desc} => sub {
$mech->log_out_ok;
$mech->clear_emails_ok;
# check that the user does not exist
my $test_email = 'test-1@example.com';
if ($test->{user}) {
my $user = FixMyStreet::App->model('DB::User')->find( { email => $test_email } );
ok $user, "test user does exist";
$user->problems->delete;
$user->name( 'Old Name' );
$user->password( 'old_password' );
$user->update;
} elsif (!$first_user) {
ok !FixMyStreet::App->model('DB::User')->find( { email => $test_email } ),
"test user does not exist";
$first_user = 1;
} else {
# Not first pass, so will exist, but want no user to start, so delete it.
$mech->delete_user($test_email);
}
# submit initial pc form
$mech->get_ok('/around');
$mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } },
"submit location" );
# click through to the report page
$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.',
photo => '',
name => 'Joe Bloggs',
may_show_name => '1',
email => 'test-1@example.com',
phone => '07903 123 456',
category => 'Street lighting',
password_register => $test->{password} ? 'secret' : '',
}
},
"submit good details"
);
# check that we got the errors expected
is_deeply $mech->form_errors, [], "check there were no errors";
# check that the user has been created/ not changed
my $user =
FixMyStreet::App->model('DB::User')->find( { email => $test_email } );
ok $user, "user found";
if ($test->{user}) {
is $user->name, 'Old Name', 'name unchanged';
ok $user->check_password('old_password'), 'password unchanged';
} else {
is $user->name, undef, 'name not yet set';
is $user->password, '', 'password not yet set for new user';
}
# find the report
my $report = $user->problems->first;
ok $report, "Found the report";
# check that the report is not available yet.
is $report->state, 'unconfirmed', "report not confirmed";
is $mech->get( '/report/' . $report->id )->code, 404, "report not found";
# Check the report has been assigned appropriately
is $report->council, 2651;
# receive token
my $email = $mech->get_email;
ok $email, "got an email";
like $email->body, qr/confirm the problem/i, "confirm the problem";
my ($url) = $email->body =~ m{(http://\S+)};
ok $url, "extracted confirm url '$url'";
# confirm token
$mech->get_ok($url);
$report->discard_changes;
is $report->state, 'confirmed', "Report is now confirmed";
$mech->get_ok( '/report/' . $report->id );
is $report->name, 'Joe Bloggs', 'name updated correctly';
if ($test->{password}) {
ok $report->user->check_password('secret'), 'password updated correctly';
} elsif ($test->{user}) {
ok $report->user->check_password('old_password'), 'password unchanged, as no new one given';
} else {
is $report->user->password, '', 'password still not set, as none given';
}
# check that the reporter has an alert
my $alert = FixMyStreet::App->model('DB::Alert')->find( {
user => $report->user,
alert_type => 'new_updates',
parameter => $report->id,
} );
ok $alert, "created new alert";
# user is created and logged in
$mech->logged_in_ok;
# cleanup
$mech->delete_user($user)
if $test->{user} && $test->{password};
};
}
# this test to make sure that we don't see spurious error messages about
# the name being blank when there is a sign in error
subtest "test password errors for a user who is signing in as they report" => sub {
$mech->log_out_ok;
$mech->clear_emails_ok;
# check that the user does not exist
my $test_email = 'test-2@example.com';
my $user = FixMyStreet::App->model('DB::User')->find_or_create( { email => $test_email } );
ok $user, "test user does exist";
# setup the user.
ok $user->update( {
name => 'Joe Bloggs',
phone => '01234 567 890',
password => 'secret2',
} ), "set user details";
# submit initial pc form
$mech->get_ok('/around');
$mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } },
"submit location" );
# click through to the report page
$mech->follow_link_ok( { text_regex => qr/skip this step/i, },
"follow 'skip this step' link" );
$mech->submit_form_ok(
{
button => 'submit_sign_in',
with_fields => {
title => 'Test Report',
detail => 'Test report details.',
photo => '',
email => 'test-2@example.com',
password_sign_in => 'secret1',
category => 'Street lighting',
}
},
"submit with wrong password"
);
# check that we got the errors expected
is_deeply $mech->form_errors, [
"There was a problem with your email/password combination. If you cannot remember your password, or do not have one, please fill in the \x{2018}sign in by email\x{2019} section of the form.",
], "check there were errors";
};
subtest "test report creation for a user who is signing in as they report" => sub {
$mech->log_out_ok;
$mech->clear_emails_ok;
# check that the user does not exist
my $test_email = 'test-2@example.com';
my $user = FixMyStreet::App->model('DB::User')->find_or_create( { email => $test_email } );
ok $user, "test user does exist";
# setup the user.
ok $user->update( {
name => 'Joe Bloggs',
phone => '01234 567 890',
password => 'secret2',
} ), "set user details";
# submit initial pc form
$mech->get_ok('/around');
$mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } },
"submit location" );
# click through to the report page
$mech->follow_link_ok( { text_regex => qr/skip this step/i, },
"follow 'skip this step' link" );
$mech->submit_form_ok(
{
button => 'submit_sign_in',
with_fields => {
title => 'Test Report',
detail => 'Test report details.',
photo => '',
email => 'test-2@example.com',
password_sign_in => 'secret2',
category => 'Street lighting',
}
},
"submit good details"
);
# check that we got the errors expected
is_deeply $mech->form_errors, [
'You have successfully signed in; please check and confirm your details are accurate:',
], "check there were errors";
# Now submit with a name
$mech->submit_form_ok(
{
with_fields => {
name => 'Joe Bloggs',
}
},
"submit good details"
);
# find the report
my $report = $user->problems->first;
ok $report, "Found the report";
# check that we got redirected to /report/
is $mech->uri->path, "/report/" . $report->id, "redirected to report page";
# Check the report has been assigned appropriately
is $report->council, 2651;
# check that no emails have been sent
$mech->email_count_is(0);
# check report is confirmed and available
is $report->state, 'confirmed', "report is now confirmed";
$mech->get_ok( '/report/' . $report->id );
# check that the reporter has an alert
my $alert = FixMyStreet::App->model('DB::Alert')->find( {
user => $report->user,
alert_type => 'new_updates',
parameter => $report->id,
} );
ok $alert, "created new alert";
# user is created and logged in
$mech->logged_in_ok;
# cleanup
$mech->delete_user($user)
};
#### test report creation for user with account and logged in
my ($saved_lat, $saved_lon);
foreach my $test (
{ category => 'Trees', council => 2326 },
{ category => 'Potholes', council => 2226 },
) {
subtest "test report creation for a user who is logged in" => sub {
# check that the user does not exist
my $test_email = 'test-2@example.com';
$mech->clear_emails_ok;
my $user = $mech->log_in_ok($test_email);
# setup the user.
ok $user->update(
{
name => 'Test User',
phone => '01234 567 890',
}
),
"set users details";
# submit initial pc form
$mech->get_ok('/around');
$mech->submit_form_ok( { with_fields => { pc => 'GL50 2PR', } },
"submit location" );
# click through to the report page
$mech->follow_link_ok( { text_regex => qr/skip this step/i, },
"follow 'skip this step' link" );
# check that the fields are correctly prefilled
is_deeply(
$mech->visible_form_values,
{
title => '',
detail => '',
may_show_name => '1',
name => 'Test User',
phone => '01234 567 890',
photo => '',
category => '-- Pick a category --',
},
"user's details prefilled"
);
$mech->submit_form_ok(
{
with_fields => {
title => "Test Report at café",
detail => 'Test report details.',
photo => '',
name => 'Joe Bloggs',
may_show_name => '1',
phone => '07903 123 456',
category => $test->{category},
}
},
"submit good details"
);
# find the report
my $report = $user->problems->first;
ok $report, "Found the report";
# Check the report has been assigned appropriately
is $report->council, $test->{council};
# check that we got redirected to /report/
is $mech->uri->path, "/report/" . $report->id, "redirected to report page";
# check that no emails have been sent
$mech->email_count_is(0);
# check report is confirmed and available
is $report->state, 'confirmed', "report is now confirmed";
$mech->get_ok( '/report/' . $report->id );
# check that the reporter has an alert
my $alert = FixMyStreet::App->model('DB::Alert')->find( {
user => $report->user,
alert_type => 'new_updates',
parameter => $report->id,
} );
ok $alert, "created new alert";
# user is still logged in
$mech->logged_in_ok;
# Test that AJAX pages return the right data
$mech->get_ok(
'/ajax?bbox=' . ($report->longitude - 0.01) . ',' . ($report->latitude - 0.01)
. ',' . ($report->longitude + 0.01) . ',' . ($report->latitude + 0.01)
);
$mech->content_contains( "Test Report at caf\xc3\xa9" );
$saved_lat = $report->latitude;
$saved_lon = $report->longitude;
# cleanup
$mech->delete_user($user);
};
}
$contact2->category( "Pothol\xc3\xa9s" );
$contact2->update;
$mech->get_ok( '/report/new/ajax?latitude=' . $saved_lat . '&longitude=' . $saved_lon );
$mech->content_contains( "Pothol\xc3\xa9s" );
#### test uploading an image
#### test completing a partial report (eq flickr upload)
#### possibly manual testing
# create report without using map
# create report by clicking on may with javascript off
# create report with images off
subtest "check that a lat/lon off coast leads to /around" => sub {
my $off_coast_latitude = 50.78301;
my $off_coast_longitude = -0.646929;
$mech->get_ok( #
"/report/new"
. "?latitude=$off_coast_latitude"
. "&longitude=$off_coast_longitude"
);
is $mech->uri->path, '/around', "redirected to '/around'";
is_deeply #
$mech->form_errors,
[ 'That spot does not appear to be covered by a council. If you have'
. ' tried to report an issue past the shoreline, for example, please'
. ' specify the closest point on land.' ], #
"Found location error";
};
for my $test (
{
desc => 'user title not set if not bromley problem',
host => 'http://www.fixmystreet.com',
postcode => 'EH99 1SP',
fms_extra_title => '',
extra => undef,
user_title => undef,
},
{
desc => 'title shown for bromley problem on main site',
host => 'http://www.fixmystreet.com',
postcode => 'BR1 3UH',
fms_extra_title => 'MR',
extra => [
{
name => 'fms_extra_title',
value => 'MR',
description => 'FMS_EXTRA_TITLE',
},
],
user_title => 'MR',
},
{
desc =>
'title, first and last name shown for bromley problem on cobrand',
host => 'http://bromley.fixmystreet.com',
postcode => 'BR1 3UH',
first_name => 'Test',
last_name => 'User',
fms_extra_title => 'MR',
extra => [
{
name => 'fms_extra_title',
value => 'MR',
description => 'FMS_EXTRA_TITLE',
},
{
name => 'first_name',
value => 'Test',
description => 'FIRST_NAME',
},
{
name => 'last_name',
value => 'User',
description => 'LAST_NAME',
},
],
user_title => 'MR',
},
)
{
subtest $test->{desc} => sub {
if ( $test->{host} =~ /bromley/ && !FixMyStreet::Cobrand->exists('bromley') ) {
ok 1, 'Skipping Bromley tests without Bromley cobrand';
return;
}
$mech->host( $test->{host} );
$mech->log_out_ok;
$mech->clear_emails_ok;
$mech->get_ok('/');
$mech->submit_form_ok( { with_fields => { pc => $test->{postcode}, } },
"submit location" );
$mech->follow_link_ok(
{ text_regex => qr/skip this step/i, },
"follow 'skip this step' link"
);
my $fields = $mech->visible_form_values('mapSkippedForm');
if ( $test->{fms_extra_title} ) {
ok exists( $fields->{fms_extra_title} ), 'user title field displayed';
} else {
ok !exists( $fields->{fms_extra_title} ), 'user title field not displayed';
}
if ( $test->{first_name} ) {
ok exists( $fields->{first_name} ), 'first name field displayed';
ok exists( $fields->{last_name} ), 'last name field displayed';
ok !exists( $fields->{name} ), 'no name field displayed';
}
else {
ok !exists( $fields->{first_name} ),
'first name field not displayed';
ok !exists( $fields->{last_name} ), 'last name field not displayed';
ok exists( $fields->{name} ), 'name field displayed';
}
my $submission_fields = {
title => "Test Report",
detail => 'Test report details.',
photo => '',
email => 'firstlast@example.com',
may_show_name => '1',
phone => '07903 123 456',
category => 'Trees',
password_register => '',
};
$submission_fields->{fms_extra_title} = $test->{fms_extra_title}
if $test->{fms_extra_title};
if ( $test->{first_name} ) {
$submission_fields->{first_name} = $test->{first_name};
$submission_fields->{last_name} = $test->{last_name};
}
else {
$submission_fields->{name} = 'Test User';
}
$mech->submit_form_ok( { with_fields => $submission_fields },
"submit good details" );
my $email = $mech->get_email;
ok $email, "got an email";
like $email->body, qr/confirm the problem/i, "confirm the problem";
my ($url) = $email->body =~ m{(https?://\S+)};
ok $url, "extracted confirm url '$url'";
# confirm token in order to update the user details
$mech->get_ok($url);
my $user =
FixMyStreet::App->model('DB::User')
->find( { email => 'firstlast@example.com' } );
my $report = $user->problems->first;
ok $report, "Found the report";
my $extras = $report->extra;
is $user->title, $test->{'user_title'}, 'user title correct';
is_deeply $extras, $test->{extra}, 'extra contains correct values';
$user->problems->delete;
$user->alerts->delete;
$user->delete;
};
}
$contact1->delete;
$contact2->delete;
$contact3->delete;
$contact4->delete;
$contact5->delete;
done_testing();
|