diff options
author | Struan Donald <struan@exo.org.uk> | 2011-07-26 16:57:08 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2011-07-26 16:57:08 +0100 |
commit | 54066cd1387643dd6c6cb3040c520bee66881fd7 (patch) | |
tree | eda84b3f347220ed12de3aa690116148287891bd /t/app/controller | |
parent | 8146bad18eeaab658871dd28eb38199a5d068395 (diff) | |
parent | 198fcef62892fe0b2fbb3ea8a080fca87843445e (diff) |
Merge branch 'master' of ssh://git.mysociety.org/data/git/public/fixmystreet into new_statuses
Conflicts:
perllib/FixMyStreet/App/Controller/Admin.pm
perllib/FixMyStreet/App/Controller/JSON.pm
perllib/FixMyStreet/Map/Tilma/Original.pm
web/css/core.css
Diffstat (limited to 't/app/controller')
-rw-r--r-- | t/app/controller/admin.t | 12 | ||||
-rw-r--r-- | t/app/controller/alert_new.t | 17 | ||||
-rw-r--r-- | t/app/controller/around.t | 2 | ||||
-rw-r--r-- | t/app/controller/index.t | 6 | ||||
-rw-r--r-- | t/app/controller/json.t | 10 | ||||
-rw-r--r-- | t/app/controller/report_import.t | 98 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 18 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 66 | ||||
-rw-r--r-- | t/app/controller/tilma.t | 12 |
9 files changed, 211 insertions, 30 deletions
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index dcf45e983..25b79dc44 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -108,9 +108,9 @@ subtest 'check summary counts' => sub { $mech->get_ok('/admin'); $mech->title_like(qr/Summary/); - $mech->content_contains( "0</strong> live problems" ); - $mech->content_contains( "0 confirmed alerts" ); - $mech->content_contains( "0 questionnaires sent" ); + my ($num_live) = $mech->content =~ /(\d+)<\/strong> live problems/; + my ($num_alerts) = $mech->content =~ /(\d+) confirmed alerts/; + my ($num_qs) = $mech->content =~ /(\d+) questionnaires sent/; $report->council(2489); $report->cobrand('barnet'); @@ -121,9 +121,9 @@ subtest 'check summary counts' => sub { $mech->get_ok('/admin'); - $mech->content_contains( "1</strong> live problems" ); - $mech->content_contains( "1 confirmed alerts" ); - $mech->content_contains( "1 questionnaires sent" ); + $mech->content_contains( ($num_live+1) . "</strong> live problems" ); + $mech->content_contains( ($num_alerts+1) . " confirmed alerts" ); + $mech->content_contains( ($num_qs+1) . " questionnaires sent" ); $report->council(2504); $report->cobrand(''); diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index cb3b4b656..580a5ad9a 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -431,6 +431,19 @@ subtest "Test normal alert signups and that alerts are sent" => sub { my $update_id = $update->id; ok $update, "created test update - $update_id"; + $update = FixMyStreet::App->model('DB::Comment')->create( { + problem_id => $report_id, + user_id => $user2->id, + name => 'Anonymous User', + mark_fixed => 'false', + text => 'This is some more update text', + state => 'confirmed', + confirmed => $dt->clone->add( hours => 8 ), + anonymous => 't', + } ); + $update_id = $update->id; + ok $update, "created test update - $update_id"; + FixMyStreet::App->model('DB::AlertType')->email_alerts(); $mech->email_count_is(3); my @emails = $mech->get_email; @@ -442,6 +455,10 @@ subtest "Test normal alert signups and that alerts are sent" => sub { } is $count, 3, 'Three emails with the right things in them'; + my $email = $emails[0]; + like $email->body, qr/Other User/, 'Update name given'; + unlike $email->body, qr/Anonymous User/, 'Update name not given'; + my ( $url, $url_token ) = $emails[0]->body =~ m{http://\S+(/A/(\S+))}; $mech->get_ok( $url ); $mech->content_contains('successfully deleted'); diff --git a/t/app/controller/around.t b/t/app/controller/around.t index 0060e957c..ca1694b49 100644 --- a/t/app/controller/around.t +++ b/t/app/controller/around.t @@ -19,7 +19,7 @@ subtest "redirect x,y requests to lat/lon (301 - permanent)" => sub { # did we redirect to lat,lon? is $mech->uri->path, '/around', "still on /around"; is_deeply { $mech->uri->query_form }, - { lat => 51.499825, lon => -0.140137, }, + { lat => 51.499825, lon => -0.140137, zoom => 3 }, "lat,lon correctly set"; # was it a 301? diff --git a/t/app/controller/index.t b/t/app/controller/index.t index be947e344..bf9124ee0 100644 --- a/t/app/controller/index.t +++ b/t/app/controller/index.t @@ -30,15 +30,15 @@ subtest "does pc, (x,y), (e,n) or (lat,lon) go to /around" => sub { }, { in => { lat => 51.50100, lon => -0.14158 }, - out => { lat => 51.50100, lon => -0.14158 }, + out => { lat => 51.50100, lon => -0.14158, zoom => 3 }, }, { in => { x => 3281, y => 1113, }, - out => { lat => 51.499825, lon => -0.140137 }, + out => { lat => 51.499825, lon => -0.140137, zoom => 3 }, }, { in => { e => 1234, n => 4567 }, - out => { lat => 49.808509, lon => -7.544784 }, + out => { lat => 49.808509, lon => -7.544784, zoom => 3 }, }, ) { diff --git a/t/app/controller/json.t b/t/app/controller/json.t index d6820e1be..468fa5b31 100644 --- a/t/app/controller/json.t +++ b/t/app/controller/json.t @@ -78,9 +78,14 @@ is_deeply # "/json/problems/new?start_date=2000-01-01&end_date=2000-02-01"), # [ { + 'state' => 'confirmed', + 'longitude' => -0.23021896608596, + 'latitude' => 51.4531988729771, + 'used_map' => 1, 'anonymous' => 0, 'category' => 'test category', 'confirmed' => '2000-01-01 12:01:00', + 'lastupdate' => '2000-01-01 12:00:00', 'council' => 'Wandsworth Borough Council', 'detail' => 'Test detail', 'id' => $problem->id, @@ -90,9 +95,14 @@ is_deeply # 'whensent' => undef }, { + 'state' => 'confirmed', + 'longitude' => -0.23021896608596, + 'latitude' => 51.4531988729771, + 'used_map' => 1, 'anonymous' => 1, 'category' => 'test category', 'confirmed' => '2000-01-01 12:02:00', + 'lastupdate' => '2000-01-01 12:00:00', 'council' => 'Wandsworth Borough Council', 'detail' => 'Test detail', 'id' => $anon_problem->id, diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t index ba73b2555..61ee28b88 100644 --- a/t/app/controller/report_import.t +++ b/t/app/controller/report_import.t @@ -68,7 +68,6 @@ subtest "Test creating bad partial entries" => sub { }; -# submit an empty report to import - check we get all errors subtest "Submit a correct entry" => sub { $mech->get_ok('/import'); @@ -128,6 +127,35 @@ subtest "Submit a correct entry" => sub { }, "check imported fields are shown"; + # Check photo present, and still there after map submission (testing bug #18) + $mech->content_contains( '<img align="right" src="/photo?id' ); + $mech->content_contains('latitude" value="51.50101"', 'Check latitude'); + $mech->content_contains('longitude" value="-0.141587"', 'Check longitude'); + $mech->submit_form_ok( + { + button => 'tile_32742.21793', + x => 10, + y => 10, + }, + "New map location" + ); + $mech->content_contains( '<img align="right" src="/photo?id' ); + $mech->content_contains('latitude" value="51.50519"', 'Check latitude'); + $mech->content_contains('longitude" value="-0.142608"', 'Check longitude'); + + # check that fields haven't changed at all + is_deeply $mech->visible_form_values, + { + name => 'Test User', + title => 'Test report', + detail => 'This is a test report', + photo => '', + phone => '', + may_show_name => '1', + category => '-- Pick a category --', + }, + "check imported fields are shown"; + # change the details $mech->submit_form_ok( # { @@ -156,7 +184,6 @@ subtest "Submit a correct entry" => sub { $mech->delete_user($user); }; -# submit an empty report to import - check we get all errors subtest "Submit a correct entry (with location)" => sub { $mech->get_ok('/import'); @@ -235,4 +262,71 @@ subtest "Submit a correct entry (with location)" => sub { $mech->delete_user($user); }; +subtest "Submit a correct entry (with location) to cobrand" => sub { + + skip( "Need 'fiksgatami' in ALLOWED_COBRANDS config", 8 ) + unless FixMyStreet::App->config->{ALLOWED_COBRANDS} =~ m{fiksgatami}; + mySociety::MaPit::configure('http://mapit.nuug.no/'); + ok $mech->host("fiksgatami.no"), 'change host to fiksgatami'; + + $mech->get_ok('/import'); + + $mech->submit_form_ok( # + { + with_fields => { + service => 'test-script', + lat => '59', + lon => '10', + name => 'Test User ll', + email => 'test-ll@example.com', + subject => 'Test report ll', + detail => 'This is a test report ll', + photo => $sample_file, + } + }, + "fill in form" + ); + + is_deeply( $mech->import_errors, [], "got no errors" ); + is $mech->content, 'SUCCESS', "Got success response"; + + # check that we have received the email + $mech->email_count_is(1); + my $email = $mech->get_email; + $mech->clear_emails_ok; + + my ($token_url) = $email->body =~ m{(http://\S+)}; + ok $token_url, "Found a token url $token_url"; + + # go to the token url + $mech->get_ok($token_url); + + # check that we are on '/report/new' + is $mech->uri->path, '/report/new', "sent to /report/new"; + + # check that fields are prefilled for us + is_deeply $mech->visible_form_values, + { + name => 'Test User ll', + title => 'Test report ll', + detail => 'This is a test report ll', + photo => '', + phone => '', + may_show_name => '1', + }, + "check imported fields are shown"; + + my $user = + FixMyStreet::App->model('DB::User') + ->find( { email => 'test-ll@example.com' } ); + ok $user, "Found a user"; + + my $report = $user->problems->first; + is $report->state, 'partial', 'is still partial'; + is $report->title, 'Test report ll', 'title is correct'; + is $report->lang, 'nb', 'language is correct'; + + $mech->delete_user($user); +}; + done_testing(); diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 537786ebc..f06c23501 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -331,6 +331,9 @@ foreach my $test ( 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; } else { ok !FixMyStreet::App->model('DB::User')->find( { email => $test_email } ), "test user does not exist"; @@ -366,11 +369,15 @@ foreach my $test ( # check that we got the errors expected is_deeply $mech->form_errors, [], "check there were no errors"; - # check that the user has been created + # check that the user has been created/ not changed my $user = FixMyStreet::App->model('DB::User')->find( { email => $test_email } ); - ok $user, "created new user"; - ok $user->check_password('secret'), 'password set correctly'; + ok $user, "user found"; + if ($test->{user}) { + ok $user->check_password('old_password'), 'password unchanged'; + } else { + ok $user->check_password('secret'), 'password set correctly'; + } # find the report my $report = $user->problems->first; @@ -398,6 +405,11 @@ foreach my $test ( $mech->get_ok( '/report/' . $report->id ); + if ($test->{user}) { + is $report->name, 'Joe Bloggs', 'name updated correctly'; + ok $report->user->check_password('secret'), 'password updated correctly'; + } + # check that the reporter has an alert my $alert = FixMyStreet::App->model('DB::Alert')->find( { user => $report->user, diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index e8acbfd14..0a9c5db1f 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -584,7 +584,7 @@ $report->update; for my $test ( { - desc => 'submit an update for a non registered user, signing in with wrong password', + desc => 'submit an update for a registered user, signing in with wrong password', form_values => { submit_update => 1, rznvy => 'registered@example.com', @@ -593,12 +593,12 @@ for my $test ( password_sign_in => 'secret', }, field_errors => [ - 'There was a problem with your email/password combination. Please try again.', + "There was a problem with your email/password combination. Passwords and user accounts are a brand new service, so you probably do not have one yet \x{2013} please fill in the right hand side of this form to get one.", 'Please enter your name', # FIXME Not really necessary error ], }, { - desc => 'submit an update for a non registered user and sign in', + desc => 'submit an update for a registered user and sign in', form_values => { submit_update => 1, rznvy => 'registered@example.com', @@ -657,6 +657,66 @@ for my $test ( }; } +subtest 'submit an update for a registered user, creating update by email' => sub { + my $user = $mech->create_user_ok( 'registered@example.com' ); + $user->update( { name => 'Mr Reg', password => 'secret2' } ); + $report->comments->delete; + $mech->log_out_ok(); + $mech->clear_emails_ok(); + $mech->get_ok("/report/$report_id"); + $mech->submit_form_ok( { + with_fields => { + submit_update => 1, + rznvy => 'registered@example.com', + update => 'Update from a user', + add_alert => undef, + name => 'New Name', + password_register => 'new_secret', + }, + }, 'submit update' ); + + $mech->content_contains('Nearly Done! Now check your email'); + + # No change to user yet. + $user->discard_changes; + ok $user->check_password( 'secret2' ), 'password unchanged'; + is $user->name, 'Mr Reg', 'name unchanged'; + + my $email = $mech->get_email; + ok $email, "got an email"; + like $email->body, qr/confirm the update you/i, "Correct email text"; + + my ( $url, $url_token ) = $email->body =~ m{(http://\S+/C/)(\S+)}; + ok $url, "extracted confirm url '$url'"; + + my $token = FixMyStreet::App->model('DB::Token')->find( { + token => $url_token, + scope => 'comment' + } ); + ok $token, 'Token found in database'; + + my $update_id = $token->data->{id}; + my $add_alerts = $token->data->{add_alert}; + my $update = FixMyStreet::App->model('DB::Comment')->find( { id => $update_id } ); + + ok $update, 'found update in database'; + is $update->state, 'unconfirmed', 'update unconfirmed'; + is $update->user->email, 'registered@example.com', 'update email'; + is $update->text, 'Update from a user', 'update text'; + + $mech->get_ok( $url . $url_token ); + $mech->content_contains("/report/$report_id#update_$update_id"); + + # User should have new name and password + $user->discard_changes; + ok $user->check_password( 'new_secret' ), 'password changed'; + is $user->name, 'New Name', 'name changed'; + + $update->discard_changes; + is $update->state, 'confirmed', 'update confirmed'; + $mech->delete_user( $user ); +}; + for my $test ( { desc => 'submit update for registered user', diff --git a/t/app/controller/tilma.t b/t/app/controller/tilma.t deleted file mode 100644 index 0eb0b251e..000000000 --- a/t/app/controller/tilma.t +++ /dev/null @@ -1,12 +0,0 @@ -use strict; -use warnings; - -use Test::More; -use FixMyStreet::TestMech; - -my $mech = FixMyStreet::TestMech->new; - -$mech->get_ok('/tilma/tileserver/10k-full/3278-3283,1110-1115/JSON'); -is $mech->res->content_type, 'text/javascript', "got JS response"; - -done_testing();
\ No newline at end of file |