1 package KohaTest::Members::ModMember;
2 use base qw( KohaTest::Members );
10 sub testing_class { 'C4::Members' };
13 sub a_simple_usage : Test( 7 ) {
16 ok( $self->{'memberid'}, 'we have a valid memberid to test with' );
18 my $details = C4::Members::GetMemberDetails( $self->{'memberid'} );
19 ok( exists $details->{'dateofbirth'}, 'member details has a "dateofbirth" attribute');
20 ok( $details->{'dateofbirth'}, '...and it is set to something' );
22 my $new_date_of_birth = $self->random_date();
23 like( $new_date_of_birth, qr(^\d\d\d\d-\d\d-\d\d$), 'The new date of birth is a yyyy-mm-dd' );
25 my $success = C4::Members::ModMember(
26 borrowernumber => $self->{'memberid'},
27 dateofbirth => $new_date_of_birth
30 ok( $success, 'we successfully called ModMember' );
32 $details = C4::Members::GetMemberDetails( $self->{'memberid'} );
33 ok( exists $details->{'dateofbirth'}, 'member details still has a "dateofbirth" attribute');
34 is( $details->{'dateofbirth'}, $new_date_of_birth, '...and it is set to the new_date_of_birth' );
38 sub incorrect_usage : Test( 1 ) {
41 local $TODO = 'ModMember does not fail gracefully yet';
43 my $result = C4::Members::ModMember();
44 ok( ! defined $result, 'ModMember returns false when passed no parameters' );
50 In bug 2284, it was determined that a Member's dateofbirth could be
51 erased by a call to ModMember if no date_of_birth was passed in. Three
52 date fields (dateofbirth, dateexpiry ,and dateenrolled) are treated
53 differently than other fields by ModMember. This test method calls
54 ModMember with none of the date fields set to ensure that they are not
60 sub preserve_dates : Test( 18 ) {
63 ok( $self->{'memberid'}, 'we have a valid memberid to test with' );
66 dateofbirth => $self->random_date(),
67 dateexpiry => $self->random_date(),
68 dateenrolled => $self->random_date(),
71 # stage our member with valid dates in all of the date fields
72 my $success = C4::Members::ModMember(
73 borrowernumber => $self->{'memberid'},
76 ok( $success, 'succefully set the date fields.' );
78 # make sure that we successfully set the date fields. They're not undef.
79 my $details = C4::Members::GetMemberDetails( $self->{'memberid'} );
80 foreach my $date_field ( keys %date_fields ) {
81 ok( exists $details->{$date_field}, qq(member details has a "$date_field" attribute) );
82 ok( $details->{$date_field}, '...and it is set to something true' );
83 is( $details->{$date_field}, $date_fields{$date_field}, '...and it is set to what we set it' );
86 # call ModMember to update the firstname. Notice that we're not
87 # updating any date fields.
88 $success = C4::Members::ModMember(
89 borrowernumber => $self->{'memberid'},
90 firstname => $self->random_string,
92 ok( $success, 'we successfully called ModMember' );
94 # make sure that none of the date fields have been molested by our call to ModMember.
95 $details = C4::Members::GetMemberDetails( $self->{'memberid'} );
96 foreach my $date_field ( keys %date_fields ) {
97 ok( exists $details->{$date_field}, qq(member details still has a "$date_field" attribute) );
98 is( $details->{$date_field}, $date_fields{$date_field}, '...and it is set to the expected value' );