Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 6; |
22 |
use Test::More tests => 7; |
23 |
|
23 |
|
24 |
use C4::Circulation; |
24 |
use C4::Circulation; |
25 |
use Koha::Item; |
25 |
use Koha::Item; |
Lines 41-46
my $new_item_1 = Koha::Item->new(
Link Here
|
41 |
homebranch => $library->{branchcode}, |
41 |
homebranch => $library->{branchcode}, |
42 |
holdingbranch => $library->{branchcode}, |
42 |
holdingbranch => $library->{branchcode}, |
43 |
barcode => "a_barcode_for_t", |
43 |
barcode => "a_barcode_for_t", |
|
|
44 |
itype => 'BK', |
44 |
} |
45 |
} |
45 |
)->store; |
46 |
)->store; |
46 |
my $new_item_2 = Koha::Item->new( |
47 |
my $new_item_2 = Koha::Item->new( |
Lines 49-57
my $new_item_2 = Koha::Item->new(
Link Here
|
49 |
homebranch => $library->{branchcode}, |
50 |
homebranch => $library->{branchcode}, |
50 |
holdingbranch => $library->{branchcode}, |
51 |
holdingbranch => $library->{branchcode}, |
51 |
barcode => "another_barcode_for_t", |
52 |
barcode => "another_barcode_for_t", |
|
|
53 |
itype => 'BK', |
52 |
} |
54 |
} |
53 |
)->store; |
55 |
)->store; |
54 |
|
56 |
|
|
|
57 |
C4::Context->_new_userenv('xxx'); |
58 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, 'Midway Public Library', '', '', ''); |
59 |
|
55 |
like( $new_item_1->itemnumber, qr|^\d+$|, 'Adding a new item should have set the itemnumber' ); |
60 |
like( $new_item_1->itemnumber, qr|^\d+$|, 'Adding a new item should have set the itemnumber' ); |
56 |
is( Koha::Items->search->count, $nb_of_items + 2, 'The 2 items should have been added' ); |
61 |
is( Koha::Items->search->count, $nb_of_items + 2, 'The 2 items should have been added' ); |
57 |
|
62 |
|
Lines 82-87
subtest 'biblio' => sub {
Link Here
|
82 |
is( $biblio->biblionumber, $retrieved_item_1->biblionumber, 'Koha::Item->biblio should return the correct biblio' ); |
87 |
is( $biblio->biblionumber, $retrieved_item_1->biblionumber, 'Koha::Item->biblio should return the correct biblio' ); |
83 |
}; |
88 |
}; |
84 |
|
89 |
|
|
|
90 |
subtest 'checkout' => sub { |
91 |
plan tests => 5; |
92 |
my $item = Koha::Items->find( $new_item_1->itemnumber ); |
93 |
# No checkout yet |
94 |
my $checkout = $item->checkout; |
95 |
is( $checkout, undef, 'Koha::Item->checkout should return undef if there is no current checkout on this item' ); |
96 |
|
97 |
# Add a checkout |
98 |
my $patron = $builder->build({ source => 'Borrower' }); |
99 |
C4::Circulation::AddIssue( $patron, $item->barcode ); |
100 |
$checkout = $retrieved_item_1->checkout; |
101 |
is( ref( $checkout ), 'Koha::Checkout', 'Koha::Item->checkout should return a Koha::Checkout' ); |
102 |
is( $checkout->itemnumber, $item->itemnumber, 'Koha::Item->checkout should return the correct checkout' ); |
103 |
is( $checkout->borrowernumber, $patron->{borrowernumber}, 'Koha::Item->checkout should return the correct checkout' ); |
104 |
|
105 |
# Do the return |
106 |
C4::Circulation::AddReturn( $item->barcode ); |
107 |
|
108 |
# There is no more checkout on this item, making sure it will not return old checkouts |
109 |
$checkout = $item->checkout; |
110 |
is( $checkout, undef, 'Koha::Item->checkout should return undef if there is no *current* checkout on this item' ); |
111 |
}; |
112 |
|
85 |
$retrieved_item_1->delete; |
113 |
$retrieved_item_1->delete; |
86 |
is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' ); |
114 |
is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' ); |
87 |
|
115 |
|
88 |
- |
|
|