cbcebb1276f9ada9a13ad2a494b7631c73b2064c
[koha.git] / t / db_dependent / SIP / Patron.t
1 #!/usr/bin/perl
2
3 # Some tests for SIP::ILS::Patron
4 # This needs to be extended! Your help is appreciated..
5
6 use Modern::Perl;
7 use Test::More tests => 3;
8
9 use Koha::Database;
10 use t::lib::TestBuilder;
11 use t::lib::Mocks;
12 use C4::SIP::ILS::Patron;
13
14 my $schema = Koha::Database->new->schema;
15 $schema->storage->txn_begin;
16
17 my $builder = t::lib::TestBuilder->new();
18 my $patron1 = $builder->build({ source => 'Borrower' });
19 my $card = $patron1->{cardnumber};
20
21 # Check existing card number
22 my $sip_patron = C4::SIP::ILS::Patron->new( $card );
23 is( defined $sip_patron, 1, "Patron is valid" );
24
25 # Check invalid cardnumber by deleting patron
26 $schema->resultset('Borrower')->search({ cardnumber => $card })->delete;
27 my $sip_patron2 = C4::SIP::ILS::Patron->new( $card );
28 is( $sip_patron2, undef, "Patron is not valid (anymore)" );
29
30 subtest "OverduesBlockCirc tests" => sub {
31
32     plan tests => 6;
33
34     my $odue_patron = $builder->build(
35         {
36             source => 'Borrower',
37             value  => {
38                 debarred      => undef,
39                 dateexpiry    => "3000-01-01",
40                 lost          => 0,
41                 gonenoaddress => 0,
42             }
43         }
44     );
45     my $good_patron = $builder->build(
46         {
47             source => 'Borrower',
48             value  => {
49                 debarred      => undef,
50                 dateexpiry    => "3000-01-01",
51                 lost          => 0,
52                 gonenoaddress => 0,
53             }
54         }
55     );
56     my $odue = $builder->build({ source => 'Issue', value => {
57             borrowernumber => $odue_patron->{borrowernumber},
58             date_due => '2017-01-01',
59             }
60     });
61     t::lib::Mocks::mock_preference( 'OverduesBlockCirc', 'noblock' );
62     my $odue_sip_patron = C4::SIP::ILS::Patron->new( $odue_patron->{cardnumber} );
63     is( $odue_sip_patron->{charge_ok}, 1, "Not blocked with overdues when set to 'Don't block'");
64     $odue_sip_patron = C4::SIP::ILS::Patron->new( $good_patron->{cardnumber} );
65     is( $odue_sip_patron->{charge_ok}, 1, "Not blocked without overdues when set to 'Don't block'");
66
67     t::lib::Mocks::mock_preference( 'OverduesBlockCirc', 'confirmation' );
68     $odue_sip_patron = C4::SIP::ILS::Patron->new( $odue_patron->{cardnumber} );
69     is( $odue_sip_patron->{charge_ok}, '', "Blocked with overdues when set to 'Ask for confirmation'");
70     $odue_sip_patron = C4::SIP::ILS::Patron->new( $good_patron->{cardnumber} );
71     is( $odue_sip_patron->{charge_ok}, 1, "Not blocked without overdues when set to 'confirmation'");
72
73     t::lib::Mocks::mock_preference( 'OverduesBlockCirc', 'block' );
74     $odue_sip_patron = C4::SIP::ILS::Patron->new( $odue_patron->{cardnumber} );
75     is( $odue_sip_patron->{charge_ok}, '', "Blocked with overdues when set to 'Block'");
76     $odue_sip_patron = C4::SIP::ILS::Patron->new( $good_patron->{cardnumber} );
77     is( $odue_sip_patron->{charge_ok}, 1, "Not blocked without overdues when set to 'Block'");
78
79 };
80
81 $schema->storage->txn_rollback;