3 # Tests for SIP::ILS::Transaction
4 # Current state is very rudimentary. Please help to extend it!
7 use Test::More tests => 4;
10 use t::lib::TestBuilder;
12 use C4::SIP::ILS::Patron;
13 use C4::SIP::ILS::Transaction::RenewAll;
14 use C4::SIP::ILS::Transaction::Checkout;
17 use Koha::IssuingRules;
19 my $schema = Koha::Database->new->schema;
20 $schema->storage->txn_begin;
22 my $builder = t::lib::TestBuilder->new();
23 my $borr1 = $builder->build({ source => 'Borrower' });
24 my $card = $borr1->{cardnumber};
25 my $sip_patron = C4::SIP::ILS::Patron->new( $card );
27 # Create transaction RenewAll, assign patron, and run (no items)
28 my $transaction = C4::SIP::ILS::Transaction::RenewAll->new();
29 is( ref $transaction, "C4::SIP::ILS::Transaction::RenewAll", "New transaction created" );
30 is( $transaction->patron( $sip_patron ), $sip_patron, "Patron assigned to transaction" );
31 isnt( $transaction->do_renew_all, undef, "RenewAll on zero items" );
33 subtest fill_holds_at_checkout => sub {
37 my $category = $builder->build({ source => 'Category' });
38 my $branch = $builder->build({ source => 'Branch' });
39 my $borrower = $builder->build({ source => 'Borrower', value =>{
40 branchcode => $branch->{branchcode},
41 categorycode=>$category->{categorycode}
44 t::lib::Mocks::mock_userenv({ branchcode => $branch->{branchcode}, flags => 1 });
46 my $itype = $builder->build({ source => 'Itemtype', value =>{notforloan=>0} });
47 my $biblio = $builder->build({ source => 'Biblio' });
48 my $biblioitem = $builder->build({ source => 'Biblioitem', value=>{biblionumber=>$biblio->{biblionumber}} });
49 my $item1 = $builder->build({ source => 'Item', value => {
50 barcode => 'barcode4test',
51 homebranch => $branch->{branchcode},
52 holdingbranch => $branch->{branchcode},
53 biblionumber => $biblio->{biblionumber},
54 itype => $itype->{itemtype},
58 my $item2 = $builder->build({ source => 'Item', value => {
59 homebranch => $branch->{branchcode},
60 holdingbranch => $branch->{branchcode},
61 biblionumber => $biblio->{biblionumber},
62 itype => $itype->{itemtype},
67 Koha::IssuingRule->new({
68 categorycode => $borrower->{categorycode},
69 itemtype => $itype->{itemtype},
70 branchcode => $branch->{branchcode},
73 holds_per_record => 3,
78 my $reserve1 = AddReserve($branch->{branchcode},$borrower->{borrowernumber},$biblio->{biblionumber});
79 my $reserve2 = AddReserve($branch->{branchcode},$borrower->{borrowernumber},$biblio->{biblionumber});
80 my $bib = Koha::Biblios->find( $biblio->{biblionumber} );
81 is( $bib->holds->count(), 2, "Bib has 2 holds");
83 my $sip_patron = C4::SIP::ILS::Patron->new( $borrower->{cardnumber} );
84 my $sip_item = C4::SIP::ILS::Item->new( $item1->{barcode} );
85 my $transaction = C4::SIP::ILS::Transaction::Checkout->new();
86 is( ref $transaction, "C4::SIP::ILS::Transaction::Checkout", "New transaction created" );
87 is( $transaction->patron( $sip_patron ), $sip_patron, "Patron assigned to transaction" );
88 is( $transaction->item( $sip_item ), $sip_item, "Item assigned to transaction" );
89 my $checkout = $transaction->do_checkout();
90 use Data::Printer colored => 1; # Temporary debug statement
91 is( $bib->holds->count(), 1, "Bib has 1 holds remaining") or diag p $checkout;
93 t::lib::Mocks::mock_preference('itemBarcodeInputFilter', 'whitespace');
94 $sip_item = C4::SIP::ILS::Item->new( ' barcode 4 test ');
95 $transaction = C4::SIP::ILS::Transaction::Checkout->new();
96 is( $sip_item->{barcode}, $item1->{barcode}, "Item assigned to transaction" );
98 $schema->storage->txn_rollback;