package FixMyStreet::Cobrand::Tester; use parent 'FixMyStreet::Cobrand::Default'; sub send_moderation_notifications { 0 } package FixMyStreet::Cobrand::TestTitle; use parent 'FixMyStreet::Cobrand::Default'; sub moderate_permission_title { 0 } package main; use Path::Tiny; use File::Temp 'tempdir'; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; $mech->host('www.example.org'); my $BROMLEY_ID = 2482; my $body = $mech->create_body_ok( $BROMLEY_ID, 'Bromley Council' ); $mech->create_contact_ok( body => $body, category => 'Lost toys', email => 'losttoys@example.net' ); my $dt = DateTime->now; my $user = $mech->create_user_ok('test-moderation@example.com', name => 'Test User'); my $user2 = $mech->create_user_ok('test-moderation2@example.com', name => 'Test User 2'); sub create_report { FixMyStreet::DB->resultset('Problem')->create( { postcode => 'BR1 3SB', bodies_str => $body->id, areas => ",$BROMLEY_ID,", category => 'Other', title => 'Good bad good', detail => 'Good bad bad bad good bad', used_map => 't', name => 'Test User 2', anonymous => 'f', state => 'confirmed', confirmed => $dt->ymd . ' ' . $dt->hms, lang => 'en-gb', service => '', cobrand => 'default', cobrand_data => '', send_questionnaire => 't', latitude => '51.4129', longitude => '0.007831', user_id => $user2->id, photo => '74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg', extra => { moon => 'waxing full' }, }); } my $report = create_report(); my $REPORT_URL = '/report/' . $report->id ; subtest 'Auth' => sub { subtest 'Unaffiliated user cannot see moderation' => sub { $mech->get_ok($REPORT_URL); $mech->content_lacks('Moderat'); $mech->get_ok("$REPORT_URL/moderate"); $mech->content_lacks('Moderat'); $mech->log_in_ok( $user->email ); $mech->get_ok($REPORT_URL); $mech->content_lacks('Moderat'); $user->update({ from_body => $body->id }); $mech->get_ok($REPORT_URL); $mech->content_lacks('Moderat'); $mech->get('/contact?m=1&id=' . $report->id); is $mech->res->code, 400; $mech->content_lacks('Good bad bad bad'); }; subtest 'Affiliated and permissioned user can see moderation' => sub { # login and from_body are done in previous test. $user->user_body_permissions->create({ body => $body, permission_type => 'moderate', }); $mech->get_ok($REPORT_URL); $mech->content_contains('Moderat'); }; }; my %problem_prepopulated = ( problem_show_name => 1, problem_photo => 1, problem_title => 'Good bad good', problem_detail => 'Good bad bad bad good bad', ); subtest 'Problem moderation' => sub { subtest 'Post modify title and text' => sub { $mech->get_ok($REPORT_URL); $mech->content_lacks('show-moderation'); $mech->follow_link_ok({ text_regex => qr/^Moderate$/ }); $mech->content_contains('show-moderation'); $mech->submit_form_ok({ with_fields => { %problem_prepopulated, problem_title => 'Good good', problem_detail => 'Good good improved', }}); $mech->base_like( qr{\Q$REPORT_URL\E} ); $mech->content_like(qr/Moderated by Bromley Council/); $report->discard_changes; is $report->title, 'Good good'; is $report->detail, 'Good good improved'; }; subtest 'Revert title and text' => sub { $mech->submit_form_ok({ with_fields => { %problem_prepopulated, problem_revert_title => 1, problem_revert_detail => 1, }}); $mech->base_like( qr{\Q$REPORT_URL\E} ); $report->discard_changes; is $report->title, 'Good bad good'; is $report->detail, 'Good bad bad bad good bad'; my @history = $report->moderation_original_datas->search(undef, { order_by => 'id' })->all; is @history, 2, 'Right number of entries'; is $history[0]->title, 'Good bad good', 'Correct original title'; is $history[1]->title, 'Good good', 'Correct second title'; }; subtest 'Post modified title after edited elsewhere' => sub { $mech->submit_form_ok({ with_fields => { %problem_prepopulated, problem_title => 'Good good', form_started => 1, # January 1970! }}); $mech->base_like( qr{\Q/moderate$REPORT_URL\E} ); $mech->content_contains('Good bad good'); # Displayed title $mech->content_contains('Good good'); # Form edit $report->discard_changes; is $report->title, 'Good bad good', 'title unchanged'; }; subtest 'Make anonymous' => sub { $mech->content_lacks('Reported anonymously'); $mech->submit_form_ok({ with_fields => { %problem_prepopulated, problem_show_name => 0, }}); $mech->base_like( qr{\Q$REPORT_URL\E} ); $mech->content_contains('Reported anonymously'); $mech->submit_form_ok({ with_fields => { %problem_prepopulated, problem_show_name => 1, }}); $mech->base_like( qr{\Q$REPORT_URL\E} ); $mech->content_lacks('Reported anonymously')
$(function(){
$('#map_layer_toggle').on('click', function(e){
e.preventDefault();
var $t = $(this), text = $t.text();
if (text == translation_strings.map_map) {
$t.text(translation_strings.map_satellite);
fixmystreet.map.setBaseLayer(fixmystreet.map.layers[0]);
} else {
$t.text(translation_strings.map_map);
fixmystreet.map.setBaseLayer(fixmystreet.map.layers[1]);
}
});
if (typeof fixmystreet_google_default !== 'undefined' && fixmystreet_google_default == 'satellite') {
$('#map_layer_toggle').click();
}
});
fixmystreet.maps.config = function() {
var permalink_id;
if ($('#map_permalink').length) {
permalink_id = 'map_permalink';
}
fixmystreet.controls = [
new OpenLayers.Control.ArgParser(),
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PermalinkFMS(permalink_id),
new OpenLayers.Control.PanZoomFMS({id: 'fms_pan_zoom' })
];
fixmystreet.map_type = OpenLayers.Layer.Google;
fixmystreet.map_options = {
zoomDuration