bug 2284: ModMember can erase the dateofbirth field
patch to C4::Members::ModMember to prevent it from deleting the dateofbirth field when none is supplied. I also added a KohaTest::random_date method to help generate randomish dates for the test suite. Added some tests for Member::ModMember. This is an easy method to test, and this bug shows that it could use some closer examiniation. Signed-off-by: Joshua Ferraro <jmf@liblime.com>
This commit is contained in:
parent
b14eb8f093
commit
15ca4bd8fa
3 changed files with 122 additions and 1 deletions
|
@ -624,7 +624,7 @@ sub ModMember {
|
|||
}
|
||||
}
|
||||
if (!$data{'dateofbirth'}){
|
||||
undef $data{'dateofbirth'};
|
||||
delete $data{'dateofbirth'};
|
||||
}
|
||||
my $qborrower=$dbh->prepare("SHOW columns from borrowers");
|
||||
$qborrower->execute;
|
||||
|
|
|
@ -329,6 +329,7 @@ sub startup_24_add_member : Test(startup => 1) {
|
|||
categorycode => 'PT', # PT => PaTron
|
||||
dateexpiry => '2010-01-01',
|
||||
password => 'testpassword',
|
||||
dateofbirth => $self->random_date(),
|
||||
};
|
||||
|
||||
my $borrowernumber = AddMember( %$memberinfo );
|
||||
|
@ -456,6 +457,23 @@ sub random_ip {
|
|||
|
||||
}
|
||||
|
||||
=head3 random_date
|
||||
|
||||
returns a somewhat random date in the iso (yyyy-mm-dd) format.
|
||||
|
||||
=cut
|
||||
|
||||
sub random_date {
|
||||
my $self = shift;
|
||||
|
||||
my $year = 1800 + int( rand(300) ); # 1800 - 2199
|
||||
my $month = 1 + int( rand(12) ); # 1 - 12
|
||||
my $day = 1 + int( rand(28) ); # 1 - 28
|
||||
# stop at the 28th to keep us from generating February 31st and such.
|
||||
|
||||
return sprintf( '%04d-%02d-%02d', $year, $month, $day );
|
||||
|
||||
}
|
||||
|
||||
=head3 add_biblios
|
||||
|
||||
|
|
103
t/lib/KohaTest/Members/ModMember.pm
Normal file
103
t/lib/KohaTest/Members/ModMember.pm
Normal file
|
@ -0,0 +1,103 @@
|
|||
package KohaTest::Members::ModMember;
|
||||
use base qw( KohaTest::Members );
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More;
|
||||
|
||||
use C4::Members;
|
||||
sub testing_class { 'C4::Members' };
|
||||
|
||||
|
||||
sub a_simple_usage : Test( 7 ) {
|
||||
my $self = shift;
|
||||
|
||||
ok( $self->{'memberid'}, 'we have a valid memberid to test with' );
|
||||
|
||||
my $details = C4::Members::GetMemberDetails( $self->{'memberid'} );
|
||||
ok( exists $details->{'dateofbirth'}, 'member details has a "dateofbirth" attribute');
|
||||
ok( $details->{'dateofbirth'}, '...and it is set to something' );
|
||||
|
||||
my $new_date_of_birth = $self->random_date();
|
||||
like( $new_date_of_birth, qr(^\d\d\d\d-\d\d-\d\d$), 'The new date of birth is a yyyy-mm-dd' );
|
||||
|
||||
my $success = C4::Members::ModMember(
|
||||
borrowernumber => $self->{'memberid'},
|
||||
dateofbirth => $new_date_of_birth
|
||||
);
|
||||
|
||||
ok( $success, 'we successfully called ModMember' );
|
||||
|
||||
$details = C4::Members::GetMemberDetails( $self->{'memberid'} );
|
||||
ok( exists $details->{'dateofbirth'}, 'member details still has a "dateofbirth" attribute');
|
||||
is( $details->{'dateofbirth'}, $new_date_of_birth, '...and it is set to the new_date_of_birth' );
|
||||
|
||||
}
|
||||
|
||||
sub incorrect_usage : Test( 1 ) {
|
||||
my $self = shift;
|
||||
|
||||
local $TODO = 'ModMember does not fail gracefully yet';
|
||||
|
||||
my $result = C4::Members::ModMember();
|
||||
ok( ! defined $result, 'ModMember returns false when passed no parameters' );
|
||||
|
||||
}
|
||||
|
||||
=head2 preserve_dates
|
||||
|
||||
In bug 2284, it was determined that a Member's dateofbirth could be
|
||||
erased by a call to ModMember if no date_of_birth was passed in. Three
|
||||
date fields (dateofbirth, dateexpiry ,and dateenrolled) are treated
|
||||
differently than other fields by ModMember. This test method calls
|
||||
ModMember with none of the date fields set to ensure that they are not
|
||||
overwritten.
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
sub preserve_dates : Test( 18 ) {
|
||||
my $self = shift;
|
||||
|
||||
ok( $self->{'memberid'}, 'we have a valid memberid to test with' );
|
||||
|
||||
my %date_fields = (
|
||||
dateofbirth => $self->random_date(),
|
||||
dateexpiry => $self->random_date(),
|
||||
dateenrolled => $self->random_date(),
|
||||
);
|
||||
|
||||
# stage our member with valid dates in all of the date fields
|
||||
my $success = C4::Members::ModMember(
|
||||
borrowernumber => $self->{'memberid'},
|
||||
%date_fields,
|
||||
);
|
||||
ok( $success, 'succefully set the date fields.' );
|
||||
|
||||
# make sure that we successfully set the date fields. They're not undef.
|
||||
my $details = C4::Members::GetMemberDetails( $self->{'memberid'} );
|
||||
foreach my $date_field ( keys %date_fields ) {
|
||||
ok( exists $details->{$date_field}, qq(member details has a "$date_field" attribute) );
|
||||
ok( $details->{$date_field}, '...and it is set to something true' );
|
||||
is( $details->{$date_field}, $date_fields{$date_field}, '...and it is set to what we set it' );
|
||||
}
|
||||
|
||||
# call ModMember to update the firstname. Notice that we're not
|
||||
# updating any date fields.
|
||||
$success = C4::Members::ModMember(
|
||||
borrowernumber => $self->{'memberid'},
|
||||
firstname => $self->random_string,
|
||||
);
|
||||
ok( $success, 'we successfully called ModMember' );
|
||||
|
||||
# make sure that none of the date fields have been molested by our call to ModMember.
|
||||
$details = C4::Members::GetMemberDetails( $self->{'memberid'} );
|
||||
foreach my $date_field ( keys %date_fields ) {
|
||||
ok( exists $details->{$date_field}, qq(member details still has a "$date_field" attribute) );
|
||||
is( $details->{$date_field}, $date_fields{$date_field}, '...and it is set to the expected value' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
1;
|
Loading…
Reference in a new issue