aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2018-05-22 11:14:54 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2018-05-23 13:45:54 +0100
commit6150cdcb32474102370a4be4d730ca55c1a74e7e (patch)
treeabe6bef0b6803fdf592793a3a312d1b91bb579d7 /t
parent1c8249e4b9a7199cad448de3eeb8e1c6b0fb7f1f (diff)
Escape data attributes in template.
This fixes a bug whereby a double quote in an item would not be JSON-escaped due to being HTML-escaped first, meaning it would not parse as JSON on the client.
Diffstat (limited to 't')
-rw-r--r--t/app/model/defecttype.t21
-rw-r--r--t/app/model/responsepriority.t18
-rw-r--r--t/app/model/responsetemplate.t28
3 files changed, 28 insertions, 39 deletions
diff --git a/t/app/model/defecttype.t b/t/app/model/defecttype.t
index 4f380db59..e924129e2 100644
--- a/t/app/model/defecttype.t
+++ b/t/app/model/defecttype.t
@@ -99,27 +99,6 @@ subtest 'by_categories returns defect types for an area with multiple bodies' =>
is scalar @$pavements, 3, 'Pavements have 3 defect types';
};
-subtest 'by_categories encodes HTML entities' => sub {
- my $apostrophe_defect_type = FixMyStreet::App->model('DB::DefectType')->find_or_create(
- {
- body_id => $oxfordshire->id,
- name => 'This defect type\'s name has an apostrophe',
- description => 'This defect type is for all categories'
- }
- );
- $apostrophe_defect_type->set_extra_metadata('defect_code' => 'Here\'s an apostrophe');
- $apostrophe_defect_type->update();
-
- my @contacts = FixMyStreet::DB->resultset('Contact')->not_deleted->search( { body_id => [ $oxfordshire->id ] } )->all;
- my $defect_types = FixMyStreet::App->model('DB::DefectType')->by_categories($area_id, @contacts);
- my $traffic_lights = decode_json($defect_types->{'Traffic lights'});
- my $defect_type = @$traffic_lights[2];
- is $defect_type->{name}, 'This defect type&#39;s name has an apostrophe';
- is $defect_type->{extra}->{defect_code}, 'Here&#39;s an apostrophe';
-
-};
-
-
END {
done_testing();
}
diff --git a/t/app/model/responsepriority.t b/t/app/model/responsepriority.t
index 03c5bccae..4e624bf07 100644
--- a/t/app/model/responsepriority.t
+++ b/t/app/model/responsepriority.t
@@ -78,24 +78,6 @@ subtest 'by_categories returns all response priorities for an area with multiple
is scalar @$traffic_lights, 2, 'Traffic lights have 2 defect types';
};
-subtest 'by_categories encodes HTML entities' => sub {
- FixMyStreet::App->model('DB::ResponsePriority')->find_or_create(
- {
- body_id => $other_body->id,
- name => 'This priority\'s name has an apostrophe',
- description => 'This priority is for all categories'
- }
- );
-
- my @contacts = FixMyStreet::DB->resultset('Contact')->not_deleted->search( { body_id => [ $oxfordshire->id ] } )->all;
- my $priorities = FixMyStreet::App->model('DB::ResponsePriority')->by_categories($area_id, @contacts);
-
- my $traffic_lights = decode_json($priorities->{'Traffic lights'});
- use Data::Dumper;
- my $priority = @$traffic_lights[2];
- is $priority->{name}, 'This priority&#39;s name has an apostrophe';
-};
-
END {
$mech->delete_body( $other_body );
$mech->delete_body( $oxfordshire );
diff --git a/t/app/model/responsetemplate.t b/t/app/model/responsetemplate.t
new file mode 100644
index 000000000..fbabc1c12
--- /dev/null
+++ b/t/app/model/responsetemplate.t
@@ -0,0 +1,28 @@
+use FixMyStreet::TestMech;
+use JSON::MaybeXS;
+
+my $mech = FixMyStreet::TestMech->new;
+my $area_id = 2651;
+
+my $body = $mech->create_body_ok($area_id, 'Edinburgh Council');
+my $c1 = $mech->create_contact_ok(category => 'Potholes', body_id => $body->id, email => 'p');
+my $c2 = $mech->create_contact_ok(category => 'Graffiti', body_id => $body->id, email => 'g');
+my $t1 = FixMyStreet::DB->resultset('ResponseTemplate')->create({ body_id => $body->id, title => "Title 1", text => "Text 1" });
+my $t2 = FixMyStreet::DB->resultset('ResponseTemplate')->create({ body_id => $body->id, title => "Title 2", text => "Text 2", state => 'investigating' });
+my $t3 = FixMyStreet::DB->resultset('ResponseTemplate')->create({ body_id => $body->id, title => "Title 3", text => "Text 3" });
+$t1->add_to_contacts($c1);
+$t2->add_to_contacts($c2);
+
+my @contacts = FixMyStreet::DB->resultset('Contact')->not_deleted->search( { body_id => [ $body->id ] } )->all;
+
+subtest 'by_categories returns allresponse templates grouped by category' => sub {
+ my $templates = FixMyStreet::App->model('DB::ResponseTemplate')->by_categories($area_id, @contacts);
+ my $potholes = decode_json($templates->{Potholes});
+ my $graffiti = decode_json($templates->{Graffiti});
+
+ is scalar @$potholes, 2, 'Potholes have 2 templates';
+ is scalar @$graffiti, 2, 'Graffiti has 2 templates';
+ is $graffiti->[0]->{state}, 'investigating', 'Graffiti first template has right state';
+};
+
+done_testing;