From d8c4befc47afee2da94dbc2411a849f14cd1a7f7 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 7 Jun 2018 15:32:27 +0100 Subject: include automated field when editing contacts Display fields that are automatically filled in the contact editing form otherwise the data is lost. Also include the automated field in the form. Fixes #2136 --- t/app/controller/admin/reportextrafields.t | 56 ++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 't/app/controller/admin') diff --git a/t/app/controller/admin/reportextrafields.t b/t/app/controller/admin/reportextrafields.t index fb06665f4..4549eeadf 100644 --- a/t/app/controller/admin/reportextrafields.t +++ b/t/app/controller/admin/reportextrafields.t @@ -120,6 +120,34 @@ FixMyStreet::override_config { $contact->update; }; + subtest 'check contact updating does not remove server_set' => sub { + $contact->set_extra_fields(({ code => 'POT', automated => 'server_set' })); + $contact->update; + + $mech->get_ok("/admin/body/" . $body->id . "/" . $contact->category); + $mech->submit_form_ok( { with_fields => { + email => 'test4@example.com', + note => 'test4 note', + } } ); + + $mech->content_like(qr'test4@example.com's); + + $contact->discard_changes; + my $meta_data = $contact->get_extra_fields; + is $contact->email, 'test4@example.com', 'contact updated'; + is_deeply $meta_data, [ { + order => 0, + datatype => 'string', + datatype_description => '', + description => '', + required => 'false', + variable => 'true', + code => 'POT', + automated => 'server_set' + } ], "automated fields not unset"; + }; + + subtest 'Create and update new ReportExtraFields' => sub { my $extra_fields = []; @@ -181,10 +209,38 @@ FixMyStreet::override_config { { name => "name1", key => "key1" }, ] }; + $object->discard_changes; is_deeply $object->get_extra_fields, $extra_fields, 'new list field was added'; is $object->language, "en-gb", "Correct language was set"; + $mech->get_ok("/admin/reportextrafields/" . $object->id); + $mech->submit_form_ok({ with_fields => { + "metadata[2].order" => "3", + "metadata[2].code" => "automated_test", + "metadata[2].required" => undef, + "metadata[2].notice" => "", + "metadata[2].description" => "", + "metadata[2].datatype_description" => "", + "metadata[2].datatype" => "string", + "metadata[2].automated" => "server_set", + }}); + + push @$extra_fields, { + order => "3", + code => "automated_test", + required => "false", + variable => "true", + description => "", + datatype_description => "", + datatype => "string", + automated => "server_set", + }; + + $object->discard_changes; + is_deeply $object->get_extra_fields, $extra_fields, 'new automated field was added'; + is $object->language, "en-gb", "Correct language was set"; + $mech->get_ok("/admin/reportextrafields/" . $object->id); $mech->submit_form_ok( { with_fields => { "metadata[1].values[1].key" => "key2", -- cgit v1.2.3