From a888f0e31747bd6e1b3733d70569d151607fde22 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 27 May 2011 16:40:36 +0100 Subject: check for uninflated/null dates before trying to set the timezoned --- t/app/model/problem.t | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 t/app/model/problem.t (limited to 't/app/model/problem.t') diff --git a/t/app/model/problem.t b/t/app/model/problem.t new file mode 100644 index 000000000..74dd877ae --- /dev/null +++ b/t/app/model/problem.t @@ -0,0 +1,34 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 4; + +use FixMyStreet; +use FixMyStreet::App; + +my $problem_rs = FixMyStreet::App->model('DB::Problem'); + +my $problem = $problem_rs->new( + { + postcode => 'EH99 1SP', + latitude => 1, + longitude => 1, + areas => 1, + title => '', + detail => '', + used_map => 1, + user_id => 1, + name => '', + state => 'confirmed', + service => '', + cobrand => 'default', + cobrand_data => '', + } +); + +is $problem->confirmed_local, undef, 'inflating null confirmed ok'; +is $problem->whensent_local, undef, 'inflating null confirmed ok'; +is $problem->lastupdate_local, undef, 'inflating null confirmed ok'; +is $problem->created_local, undef, 'inflating null confirmed ok'; -- cgit v1.2.3 From 07a94e225605c51612548a34c3a6269ae3fb0b5e Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 27 May 2011 17:14:32 +0100 Subject: tests for check_for errors --- t/app/model/problem.t | 123 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 1 deletion(-) (limited to 't/app/model/problem.t') diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 74dd877ae..1b8804fce 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -3,10 +3,13 @@ use strict; use warnings; -use Test::More tests => 4; +use Test::More; use FixMyStreet; use FixMyStreet::App; +use mySociety::Locale; + +mySociety::Locale::gettext_domain('FixMyStreet'); my $problem_rs = FixMyStreet::App->model('DB::Problem'); @@ -32,3 +35,121 @@ is $problem->confirmed_local, undef, 'inflating null confirmed ok'; is $problem->whensent_local, undef, 'inflating null confirmed ok'; is $problem->lastupdate_local, undef, 'inflating null confirmed ok'; is $problem->created_local, undef, 'inflating null confirmed ok'; + +for my $test ( + { + desc => 'more or less empty problem', + changed => {}, + errors => { + title => 'Please enter a subject', + detail => 'Please enter some details', + council => 'No council selected', + name => 'Please enter your name', + } + }, + { + desc => 'name too short', + changed => { + name => 'xx', + }, + errors => { + title => 'Please enter a subject', + detail => 'Please enter some details', + council => 'No council selected', + name => 'Please enter your full name, councils need this information - if you do not wish your name to be shown on the site, untick the box', + } + }, + { + desc => 'name is anonymous', + changed => { + name => 'anonymous', + }, + errors => { + title => 'Please enter a subject', + detail => 'Please enter some details', + council => 'No council selected', + name => 'Please enter your full name, councils need this information - if you do not wish your name to be shown on the site, untick the box', + } + }, + { + desc => 'correct name', + changed => { + name => 'A User', + }, + errors => { + title => 'Please enter a subject', + detail => 'Please enter some details', + council => 'No council selected', + } + }, + { + desc => 'correct title', + changed => { + title => 'A Title', + }, + errors => { + detail => 'Please enter some details', + council => 'No council selected', + } + }, + { + desc => 'correct detail', + changed => { + detail => 'Some information about the problem', + }, + errors => { + council => 'No council selected', + } + }, + { + desc => 'incorrectly formatted council', + changed => { + council => 'my council', + }, + errors => { + council => 'No council selected', + } + }, + { + desc => 'correctly formatted council', + changed => { + council => '1001', + }, + errors => { + } + }, + { + desc => 'bad category', + changed => { + category => '-- Pick a category --', + }, + errors => { + category => 'Please choose a category', + } + }, + { + desc => 'bad category', + changed => { + category => '-- Pick a property type --', + }, + errors => { + category => 'Please choose a property type', + } + }, + { + desc => 'correct category', + changed => { + category => 'Horse!', + }, + errors => { + } + }, +) { + $problem->$_( $test->{changed}->{$_} ) for keys %{$test->{changed}}; + + subtest $test->{desc} => sub { + is_deeply $problem->check_for_errors, $test->{errors}, 'check for errors'; + }; +} + +done_testing(); -- cgit v1.2.3