aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm23
-rw-r--r--perllib/FixMyStreet/App/View/Web.pm24
-rw-r--r--perllib/FixMyStreet/TestMech.pm22
-rw-r--r--t/app/controller/report_display.t8
-rw-r--r--t/app/controller/report_updates.t115
-rw-r--r--templates/web/default/report/display.html4
6 files changed, 188 insertions, 8 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index 92c89a864..f02b2cbe3 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -154,6 +154,26 @@ sub load_problem_or_display_error : Private {
$c->stash->{problem} = $problem;
+ my $updates = $c->model('DB::Comment')->search(
+ { problem_id => $problem->id }, #, state => 'confirmed' },
+ {
+ select => [
+ 'id', 'name', 'text',
+ 'mark_fixed',
+ 'mark_open',
+ 'photo',
+ 'cobrand',
+ {
+ extract => 'epoch from confirmed',
+ -as => 'confirmed',
+ }
+ ],
+ order_by => 'confirmed'
+ }
+ );
+
+ $c->stash->{updates} = $updates;
+
return 1;
}
@@ -164,9 +184,6 @@ sub format_problem_for_display : Private {
$c->stash->{banner} = $c->cobrand->generate_problem_banner($problem);
- ( my $detail = $problem->detail ) =~ s/\r//g;
- my @detail = split /\n{2,}/, $detail;
- $c->stash->{detail} = \@detail;
$c->stash->{allow_photo_upload} = $c->cobrand->allow_photo_display;
$c->stash->{cobrand_alert_fields} = $c->cobrand->form_elements( '/alerts' );
diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm
index cbb68df0d..61d7c6ca5 100644
--- a/perllib/FixMyStreet/App/View/Web.pm
+++ b/perllib/FixMyStreet/App/View/Web.pm
@@ -17,6 +17,7 @@ __PACKAGE__->config(
render_die => 1,
expose_methods => [
'loc', 'nget', 'tprintf', 'display_crossell_advert', 'prettify_epoch',
+ 'split_into_lines',
],
);
@@ -105,5 +106,28 @@ sub prettify_epoch {
return Page::prettify_epoch( $c->req, $epoch, $short_bool );
}
+=head2 split_into_lines
+
+ [% FOREACH line IN split_into_lines( text ) %]
+ <p>
+ [% line | html %]
+ </p>
+ [% END %]
+
+Split some text into an array of lines on double new lines.
+
+=cut
+
+sub split_into_lines {
+ my ( $self, $c, $text ) = @_;
+
+ my @lines;
+ $text =~ s/\r//g;
+
+ @lines = split /\n{2,}/, $text;
+
+ return \@lines;
+}
+
1;
diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm
index ecca3f7a8..6cd4a85f3 100644
--- a/perllib/FixMyStreet/TestMech.pm
+++ b/perllib/FixMyStreet/TestMech.pm
@@ -347,6 +347,28 @@ sub extract_problem_banner {
return $result;
}
+=head2 extract_update_metas
+
+ $metas = $mech->extract_update_metas;
+
+Returns an array ref of all the update meta information on the page. Strips whitespace from
+the start and end of all of them.
+
+=cut
+
+sub extract_update_metas {
+ my $mech = shift;
+
+ my $result = scraper {
+ process 'div#updates div.problem-update p em', 'meta[]', 'TEXT';
+ }
+ ->scrape( $mech->response );
+
+ my @metas = map { s/^\s+//; s/\s+$//; $_; } @{ $result->{meta} };
+
+ return \@metas;
+}
+
=head2 visible_form_values
$hashref = $mech->visible_form_values( );
diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t
index ee9172d11..2afff21dd 100644
--- a/t/app/controller/report_display.t
+++ b/t/app/controller/report_display.t
@@ -154,21 +154,21 @@ foreach my $meta (
meta => 'Reported anonymously at 15:47, Saturday 16 April 2011'
},
{
- anonymous => 'f',
+ anonymous => 't',
category => 'Roads',
service => '',
meta =>
'Reported in the Roads category anonymously at 15:47, Saturday 16 April 2011'
},
{
- anonymous => 'f',
+ anonymous => 't',
category => '',
service => 'Transport service',
meta =>
'Reported by Transport service anonymously at 15:47, Saturday 16 April 2011'
},
{
- anonymous => 'f',
+ anonymous => 't',
category => 'Roads',
service => 'Transport service',
meta =>
@@ -182,6 +182,8 @@ foreach my $meta (
$report->update;
subtest "test correct problem meta information" => sub {
$mech->get_ok("/report/$report_id");
+
+ is $mech->extract_problem_meta, $meta->{meta};
};
}
diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t
new file mode 100644
index 000000000..466fa71c1
--- /dev/null
+++ b/t/app/controller/report_updates.t
@@ -0,0 +1,115 @@
+use strict;
+use warnings;
+use Test::More;
+
+use FixMyStreet::TestMech;
+use Web::Scraper;
+use Path::Class;
+use DateTime;
+
+my $mech = FixMyStreet::TestMech->new;
+
+# create a test user and report
+$mech->delete_user('test@example.com');
+my $user =
+ FixMyStreet::App->model('DB::User')
+ ->find_or_create( { email => 'test@example.com', name => 'Test User' } );
+ok $user, "created test user";
+
+my $dt = DateTime->new(
+ year => 2011,
+ month => 04,
+ day => 16,
+ hour => 15,
+ minute => 47,
+ second => 23
+);
+
+my $report = FixMyStreet::App->model('DB::Problem')->find_or_create(
+ {
+ postcode => 'SW1A 1AA',
+ council => '2504',
+ areas => ',105255,11806,11828,2247,2504,',
+ category => 'Other',
+ title => 'Test 2',
+ detail => 'Test 2 Detail',
+ used_map => 't',
+ name => 'Test User',
+ anonymous => 'f',
+ state => 'confirmed',
+ confirmed => $dt->ymd . ' ' . $dt->hms,
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 't',
+ latitude => '51.5016605453401',
+ longitude => '-0.142497580865087',
+ user_id => $user->id,
+ }
+);
+my $report_id = $report->id;
+ok $report, "created test report - $report_id";
+
+my $comment = FixMyStreet::App->model('DB::Comment')->find_or_create(
+ {
+ problem_id => $report_id,
+ name => 'Other User',
+ mark_fixed => 'false',
+ text => 'This is some update text',
+ email => 'commenter@example.com',
+ state => 'confirmed',
+ confirmed => $dt->ymd . ' ' . $dt->hms,
+ }
+);
+
+my $comment_id = $comment->id;
+ok $comment, "created test update - $comment_id";
+
+for my $test (
+ {
+ name => 'Other User',
+ mark_fixed => 'false',
+ mark_open => 'false',
+ meta => 'Posted by Other User at 15:47, Saturday 16 April 2011',
+ },
+ {
+ name => '',
+ mark_fixed => 'false',
+ mark_open => 'false',
+ meta => 'Posted anonymously at 15:47, Saturday 16 April 2011',
+ },
+ {
+ name => '',
+ mark_fixed => 'true',
+ mark_open => 'false',
+ meta =>
+'Posted anonymously at 15:47, Saturday 16 April 2011, marked as fixed',
+ },
+ {
+ name => '',
+ mark_fixed => 'false',
+ mark_open => 'true',
+ meta => 'Posted anonymously at 15:47, Saturday 16 April 2011, reopened',
+ }
+ )
+{
+ subtest "test update displayed" => sub {
+ $comment->name( $test->{name} );
+ $comment->mark_fixed( $test->{mark_fixed} );
+ $comment->mark_open( $test->{mark_open} );
+ $comment->update;
+
+ $mech->get_ok("/report/$report_id");
+ is $mech->uri->path, "/report/$report_id", "at /report/$report_id";
+ $mech->content_contains('This is some update text');
+
+ my $meta = $mech->extract_update_metas;
+ is scalar @$meta, 1, 'number of updates';
+ is $meta->[0], $test->{meta};
+ };
+}
+
+ok $comment->delete, 'deleted comment';
+$mech->delete_user('test@example.com');
+done_testing();
diff --git a/templates/web/default/report/display.html b/templates/web/default/report/display.html
index ee14764f2..ea3877b28 100644
--- a/templates/web/default/report/display.html
+++ b/templates/web/default/report/display.html
@@ -15,7 +15,7 @@
<p><em>[% meta | html %]</em></p>
-[% FOREACH line IN detail %]
+[% FOREACH line IN split_into_lines( problem.detail ) %]
<p>
[% line | html %]
</p>
@@ -55,7 +55,7 @@
</a>
</div>
-{{ $problem_updates }}
+[% INCLUDE 'report/updates.html' %]
<div id="update_form">