From 455fdea067a38ac7bd1e071d4a1f74084e0df5e2 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 3 Sep 2015 16:03:17 +0100 Subject: [PATCH] [PASSED QA] Bug 14717: Prevent 0000-00-00 on updating a patron Signed-off-by: Jonathan Druart Signed-off-by: Katrin Fischer --- C4/Members.pm | 1 + t/db_dependent/Members.t | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 0f4aeba..0b8e7d7 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -667,6 +667,7 @@ sub ModMember { $new_borrower->{dateofbirth} ||= undef if exists $new_borrower->{dateofbirth}; $new_borrower->{dateenrolled} ||= undef if exists $new_borrower->{dateenrolled}; $new_borrower->{dateexpiry} ||= undef if exists $new_borrower->{dateexpiry}; + $new_borrower->{debarred} ||= undef if exists $new_borrower->{debarred}; my $rs = $schema->resultset('Borrower')->search({ borrowernumber => $new_borrower->{borrowernumber}, }); diff --git a/t/db_dependent/Members.t b/t/db_dependent/Members.t index ad9ef7e..b2ebc9c 100755 --- a/t/db_dependent/Members.t +++ b/t/db_dependent/Members.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 62; +use Test::More tests => 74; use Test::MockModule; use Data::Dumper; use C4::Context; @@ -217,7 +217,9 @@ is( $borrower, undef, 'DelMember should remove the patron' ); categorycode => "S", branchcode => "MPL", dateofbirth => '', - dateexpiry => '9999-12-31', + debarred => '', + dateexpiry => '', + dateenrolled => '', ); # Add a new borrower my $borrowernumber = AddMember( %data ); @@ -230,6 +232,26 @@ is( Check_Userid( 'tomasito.none', '' ), 0, is( Check_Userid( 'tomasitoxxx', '' ), 1, 'non-existent userid -> unique (blank borrowernumber)' ); +$borrower = GetMember( borrowernumber => $borrowernumber ); +is( $borrower->{dateofbirth}, undef, 'AddMember should undef dateofbirth if empty string is given'); +is( $borrower->{debarred}, undef, 'AddMember should undef debarred if empty string is given'); +isnt( $borrower->{dateexpiry}, '0000-00-00', 'AddMember should not set dateexpiry to 0000-00-00 if empty string is given'); +isnt( $borrower->{dateenrolled}, '0000-00-00', 'AddMember should not set dateenrolled to 0000-00-00 if empty string is given'); + +ModMember( borrowernumber => $borrowernumber, dateofbirth => '', debarred => '', dateexpiry => '', dateenrolled => '' ); +$borrower = GetMember( borrowernumber => $borrowernumber ); +is( $borrower->{dateofbirth}, undef, 'ModMember should undef dateofbirth if empty string is given'); +is( $borrower->{debarred}, undef, 'ModMember should undef debarred if empty string is given'); +isnt( $borrower->{dateexpiry}, '0000-00-00', 'ModMember should not set dateexpiry to 0000-00-00 if empty string is given'); +isnt( $borrower->{dateenrolled}, '0000-00-00', 'ModMember should not set dateenrolled to 0000-00-00 if empty string is given'); + +ModMember( borrowernumber => $borrowernumber, dateofbirth => '1970-01-01', debarred => '2042-01-01', dateexpiry => '9999-12-31', dateenrolled => '2015-09-06' ); +$borrower = GetMember( borrowernumber => $borrowernumber ); +is( $borrower->{dateofbirth}, '1970-01-01', 'ModMember should correctly set dateofbirth if a valid date is given'); +is( $borrower->{debarred}, '2042-01-01', 'ModMember should correctly set debarred if a valid date is given'); +is( $borrower->{dateexpiry}, '9999-12-31', 'ModMember should correctly set dateexpiry if a valid date is given'); +is( $borrower->{dateenrolled}, '2015-09-06', 'ModMember should correctly set dateenrolled if a valid date is given'); + # Add a new borrower with the same userid but different cardnumber $data{ cardnumber } = "987654321"; my $new_borrowernumber = AddMember( %data ); -- 1.9.1