3 # Some tests for SIP::ILS::Patron
4 # This needs to be extended! Your help is appreciated..
7 use Test
::More tests
=> 5;
12 use t
::lib
::TestBuilder
;
14 use C4
::SIP
::ILS
::Patron
;
15 use Koha
::Patron
::Attributes
;
17 my $schema = Koha
::Database
->new->schema;
18 $schema->storage->txn_begin;
20 my $builder = t
::lib
::TestBuilder
->new();
21 my $patron1 = $builder->build({ source
=> 'Borrower' });
22 my $card = $patron1->{cardnumber
};
24 # Check existing card number
25 my $sip_patron = C4
::SIP
::ILS
::Patron
->new( $card );
26 is
( defined $sip_patron, 1, "Patron is valid" );
28 # Check invalid cardnumber by deleting patron
29 $schema->resultset('Borrower')->search({ cardnumber
=> $card })->delete;
30 my $sip_patron2 = C4
::SIP
::ILS
::Patron
->new( $card );
31 is
( $sip_patron2, undef, "Patron is not valid (anymore)" );
33 subtest
"OverduesBlockCirc tests" => sub {
37 my $odue_patron = $builder->build(
41 dateexpiry
=> "3000-01-01",
45 my $good_patron = $builder->build(
49 dateexpiry
=> "3000-01-01",
53 my $odue = $builder->build({ source
=> 'Issue', value
=> {
54 borrowernumber
=> $odue_patron->{borrowernumber
},
55 date_due
=> '2017-01-01',
58 t
::lib
::Mocks
::mock_preference
( 'OverduesBlockCirc', 'noblock' );
59 my $odue_sip_patron = C4
::SIP
::ILS
::Patron
->new( $odue_patron->{cardnumber
} );
60 is
( $odue_sip_patron->{charge_ok
}, 1, "Not blocked with overdues when set to 'Don't block'");
61 $odue_sip_patron = C4
::SIP
::ILS
::Patron
->new( $good_patron->{cardnumber
} );
62 is
( $odue_sip_patron->{charge_ok
}, 1, "Not blocked without overdues when set to 'Don't block'");
64 t
::lib
::Mocks
::mock_preference
( 'OverduesBlockCirc', 'confirmation' );
65 $odue_sip_patron = C4
::SIP
::ILS
::Patron
->new( $odue_patron->{cardnumber
} );
66 is
( $odue_sip_patron->{charge_ok
}, '', "Blocked with overdues when set to 'Ask for confirmation'");
67 $odue_sip_patron = C4
::SIP
::ILS
::Patron
->new( $good_patron->{cardnumber
} );
68 is
( $odue_sip_patron->{charge_ok
}, 1, "Not blocked without overdues when set to 'confirmation'");
70 t
::lib
::Mocks
::mock_preference
( 'OverduesBlockCirc', 'block' );
71 $odue_sip_patron = C4
::SIP
::ILS
::Patron
->new( $odue_patron->{cardnumber
} );
72 is
( $odue_sip_patron->{charge_ok
}, '', "Blocked with overdues when set to 'Block'");
73 $odue_sip_patron = C4
::SIP
::ILS
::Patron
->new( $good_patron->{cardnumber
} );
74 is
( $odue_sip_patron->{charge_ok
}, 1, "Not blocked without overdues when set to 'Block'");
78 subtest
"Test build_patron_attribute_string" => sub {
82 my $patron = $builder->build( { source
=> 'Borrower' } );
84 my $attribute_type = $builder->build( { source
=> 'BorrowerAttributeType' } );
85 my $attribute = Koha
::Patron
::Attribute
->new(
87 borrowernumber
=> $patron->{borrowernumber
},
88 code
=> $attribute_type->{code
},
89 attribute
=> 'Test Attribute'
93 my $attribute_type2 = $builder->build( { source
=> 'BorrowerAttributeType' } );
94 my $attribute2 = Koha
::Patron
::Attribute
->new(
96 borrowernumber
=> $patron->{borrowernumber
},
97 code
=> $attribute_type2->{code
},
98 attribute
=> 'Another Test Attribute'
102 my $ils_patron = C4
::SIP
::ILS
::Patron
->new( $patron->{cardnumber
} );
105 $server->{account
}->{patron_attribute
}->{code
} = $attribute->code;
106 $server->{account
}->{patron_attribute
}->{field
} = 'XY';
107 my $attribute_string = $ils_patron->build_patron_attributes_string( $server );
108 is
( $attribute_string, "XYTest Attribute|", 'Attribute field generated correctly with single param' );
111 $server->{account
}->{patron_attribute
}->[0]->{code
} = $attribute->code;
112 $server->{account
}->{patron_attribute
}->[0]->{field
} = 'XY';
113 $server->{account
}->{patron_attribute
}->[1]->{code
} = $attribute2->code;
114 $server->{account
}->{patron_attribute
}->[1]->{field
} = 'YZ';
115 $attribute_string = $ils_patron->build_patron_attributes_string( $server );
116 is
( $attribute_string, "XYTest Attribute|YZAnother Test Attribute|", 'Attribute field generated correctly with multiple params' );
119 subtest
"update_lastseen tests" => sub {
122 my $seen_patron = $builder->build(
124 source
=> 'Borrower',
126 lastseen
=> "2001-01-01",
130 my $sip_patron = C4
::SIP
::ILS
::Patron
->new( $seen_patron->{cardnumber
} );
131 t
::lib
::Mocks
::mock_preference
( 'TrackLastPatronActivity', '' );
132 $sip_patron->update_lastseen();
133 $seen_patron = Koha
::Patrons
->find({ cardnumber
=> $seen_patron->{cardnumber
} });
134 is
( output_pref
({str
=> $seen_patron->lastseen(), dateonly
=> 1}), output_pref
({str
=> '2001-01-01', dateonly
=> 1}),'Last seen not updated if not tracking patrons');
135 t
::lib
::Mocks
::mock_preference
( 'TrackLastPatronActivity', '1' );
136 $sip_patron->update_lastseen();
137 $seen_patron = Koha
::Patrons
->find({ cardnumber
=> $seen_patron->cardnumber() });
138 is
( output_pref
({str
=> $seen_patron->lastseen(), dateonly
=> 1}), output_pref
({dt
=> dt_from_string
(), dateonly
=> 1}),'Last seen updated to today if tracking patrons');
141 $schema->storage->txn_rollback;