3 # Some tests for SIP::ILS::Patron
4 # This needs to be extended! Your help is appreciated..
7 use Test::More tests => 4;
10 use t::lib::TestBuilder;
12 use C4::SIP::ILS::Patron;
13 use Koha::Patron::Attributes;
15 my $schema = Koha::Database->new->schema;
16 $schema->storage->txn_begin;
18 my $builder = t::lib::TestBuilder->new();
19 my $patron1 = $builder->build({ source => 'Borrower' });
20 my $card = $patron1->{cardnumber};
22 # Check existing card number
23 my $sip_patron = C4::SIP::ILS::Patron->new( $card );
24 is( defined $sip_patron, 1, "Patron is valid" );
26 # Check invalid cardnumber by deleting patron
27 $schema->resultset('Borrower')->search({ cardnumber => $card })->delete;
28 my $sip_patron2 = C4::SIP::ILS::Patron->new( $card );
29 is( $sip_patron2, undef, "Patron is not valid (anymore)" );
31 subtest "OverduesBlockCirc tests" => sub {
35 my $odue_patron = $builder->build(
39 dateexpiry => "3000-01-01",
43 my $good_patron = $builder->build(
47 dateexpiry => "3000-01-01",
51 my $odue = $builder->build({ source => 'Issue', value => {
52 borrowernumber => $odue_patron->{borrowernumber},
53 date_due => '2017-01-01',
56 t::lib::Mocks::mock_preference( 'OverduesBlockCirc', 'noblock' );
57 my $odue_sip_patron = C4::SIP::ILS::Patron->new( $odue_patron->{cardnumber} );
58 is( $odue_sip_patron->{charge_ok}, 1, "Not blocked with overdues when set to 'Don't block'");
59 $odue_sip_patron = C4::SIP::ILS::Patron->new( $good_patron->{cardnumber} );
60 is( $odue_sip_patron->{charge_ok}, 1, "Not blocked without overdues when set to 'Don't block'");
62 t::lib::Mocks::mock_preference( 'OverduesBlockCirc', 'confirmation' );
63 $odue_sip_patron = C4::SIP::ILS::Patron->new( $odue_patron->{cardnumber} );
64 is( $odue_sip_patron->{charge_ok}, '', "Blocked with overdues when set to 'Ask for confirmation'");
65 $odue_sip_patron = C4::SIP::ILS::Patron->new( $good_patron->{cardnumber} );
66 is( $odue_sip_patron->{charge_ok}, 1, "Not blocked without overdues when set to 'confirmation'");
68 t::lib::Mocks::mock_preference( 'OverduesBlockCirc', 'block' );
69 $odue_sip_patron = C4::SIP::ILS::Patron->new( $odue_patron->{cardnumber} );
70 is( $odue_sip_patron->{charge_ok}, '', "Blocked with overdues when set to 'Block'");
71 $odue_sip_patron = C4::SIP::ILS::Patron->new( $good_patron->{cardnumber} );
72 is( $odue_sip_patron->{charge_ok}, 1, "Not blocked without overdues when set to 'Block'");
76 subtest "Test build_patron_attribute_string" => sub {
80 my $patron = $builder->build( { source => 'Borrower' } );
82 my $attribute_type = $builder->build( { source => 'BorrowerAttributeType' } );
83 my $attribute = Koha::Patron::Attribute->new(
85 borrowernumber => $patron->{borrowernumber},
86 code => $attribute_type->{code},
87 attribute => 'Test Attribute'
91 my $attribute_type2 = $builder->build( { source => 'BorrowerAttributeType' } );
92 my $attribute2 = Koha::Patron::Attribute->new(
94 borrowernumber => $patron->{borrowernumber},
95 code => $attribute_type2->{code},
96 attribute => 'Another Test Attribute'
100 my $ils_patron = C4::SIP::ILS::Patron->new( $patron->{cardnumber} );
103 $server->{account}->{patron_attribute}->{code} = $attribute->code;
104 $server->{account}->{patron_attribute}->{field} = 'XY';
105 my $attribute_string = $ils_patron->build_patron_attributes_string( $server );
106 is( $attribute_string, "XYTest Attribute|", 'Attribute field generated correctly with single param' );
109 $server->{account}->{patron_attribute}->[0]->{code} = $attribute->code;
110 $server->{account}->{patron_attribute}->[0]->{field} = 'XY';
111 $server->{account}->{patron_attribute}->[1]->{code} = $attribute2->code;
112 $server->{account}->{patron_attribute}->[1]->{field} = 'YZ';
113 $attribute_string = $ils_patron->build_patron_attributes_string( $server );
114 is( $attribute_string, "XYTest Attribute|YZAnother Test Attribute|", 'Attribute field generated correctly with multiple params' );
117 $schema->storage->txn_rollback;