|
Lines 1-60
Link Here
|
| 1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
| 2 |
|
2 |
|
|
|
3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Koha is free software; you can redistribute it and/or modify it |
| 6 |
# under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# Koha is distributed in the hope that it will be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 17 |
|
| 3 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 4 |
|
19 |
|
| 5 |
use Test::More tests => 10; |
20 |
use Test::More tests => 10; |
| 6 |
use Test::MockModule; |
21 |
use Test::MockModule; |
|
|
22 |
use t::lib::TestBuilder; |
| 23 |
|
| 7 |
use C4::Biblio; |
24 |
use C4::Biblio; |
|
|
25 |
use C4::Circulation; |
| 8 |
use C4::Items; |
26 |
use C4::Items; |
| 9 |
use C4::Members; |
27 |
use C4::Members; |
| 10 |
use C4::Circulation; |
28 |
|
| 11 |
use Koha::Library; |
29 |
use Koha::Library; |
| 12 |
use Koha::Libraries; |
30 |
use Koha::Libraries; |
| 13 |
use Koha::Patron::Categories; |
31 |
use Koha::Patron::Categories; |
|
|
32 |
|
| 14 |
use MARC::Record; |
33 |
use MARC::Record; |
| 15 |
|
34 |
|
|
|
35 |
my $schema = Koha::Database->schema; |
| 36 |
$schema->storage->txn_begin; |
| 37 |
|
| 38 |
my $builder = t::lib::TestBuilder->new; |
| 16 |
my $dbh = C4::Context->dbh; |
39 |
my $dbh = C4::Context->dbh; |
| 17 |
$dbh->{AutoCommit} = 0; |
|
|
| 18 |
$dbh->{RaiseError} = 1; |
| 19 |
|
40 |
|
| 20 |
$dbh->do(q|DELETE FROM issues|); |
41 |
$dbh->do(q|DELETE FROM issues|); |
| 21 |
|
42 |
|
| 22 |
my $branchcode; |
43 |
my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; |
| 23 |
my $branch_created; |
44 |
my $itemtype = $builder->build({ source => 'Itemtype' })->{ itemtype }; |
| 24 |
my @libraries = Koha::Libraries->search; |
45 |
|
| 25 |
if (@libraries) { |
46 |
my %item_infos = ( |
| 26 |
$branchcode = $libraries[0]->branchcode; |
47 |
homebranch => $branchcode, |
| 27 |
} else { |
|
|
| 28 |
$branchcode = 'B'; |
| 29 |
Koha::Library->new({ branchcode => $branchcode, branchname => 'Branch' })->store; |
| 30 |
$branch_created = 1; |
| 31 |
} |
| 32 |
|
| 33 |
my %item_branch_infos = ( |
| 34 |
homebranch => $branchcode, |
| 35 |
holdingbranch => $branchcode, |
48 |
holdingbranch => $branchcode, |
|
|
49 |
itype => $itemtype |
| 36 |
); |
50 |
); |
| 37 |
|
51 |
|
| 38 |
my ($biblionumber1) = AddBiblio(MARC::Record->new, ''); |
52 |
my ($biblionumber1) = AddBiblio(MARC::Record->new, ''); |
| 39 |
my $itemnumber1 = AddItem({ barcode => '0101', %item_branch_infos }, $biblionumber1); |
53 |
my $itemnumber1 = AddItem({ barcode => '0101', %item_infos }, $biblionumber1); |
| 40 |
my $itemnumber2 = AddItem({ barcode => '0102', %item_branch_infos }, $biblionumber1); |
54 |
my $itemnumber2 = AddItem({ barcode => '0102', %item_infos }, $biblionumber1); |
| 41 |
|
55 |
|
| 42 |
my ($biblionumber2) = AddBiblio(MARC::Record->new, ''); |
56 |
my ($biblionumber2) = AddBiblio(MARC::Record->new, ''); |
| 43 |
my $itemnumber3 = AddItem({ barcode => '0203', %item_branch_infos }, $biblionumber2); |
57 |
my $itemnumber3 = AddItem({ barcode => '0203', %item_infos }, $biblionumber2); |
| 44 |
|
58 |
|
| 45 |
my $categorycode; |
59 |
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; |
| 46 |
my $category_created; |
60 |
my $borrowernumber = $builder->build( |
| 47 |
my @categories = Koha::Patron::Categories->search_limited; |
61 |
{ source => 'Borrower', |
| 48 |
if (@categories) { |
62 |
value => { categorycode => $categorycode, branchcode => $branchcode } |
| 49 |
$categorycode = $categories[0]->categorycode |
63 |
} |
| 50 |
} else { |
64 |
)->{borrowernumber}; |
| 51 |
$categorycode = 'C'; |
65 |
|
| 52 |
C4::Context->dbh->do( |
|
|
| 53 |
"INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode); |
| 54 |
$category_created = 1; |
| 55 |
} |
| 56 |
|
| 57 |
my $borrowernumber = AddMember(categorycode => $categorycode, branchcode => $branchcode); |
| 58 |
my $borrower = GetMember(borrowernumber => $borrowernumber); |
66 |
my $borrower = GetMember(borrowernumber => $borrowernumber); |
| 59 |
|
67 |
|
| 60 |
# Need to mock userenv for AddIssue |
68 |
# Need to mock userenv for AddIssue |
|
Lines 88-94
is(scalar @$issues, 0, "No one has issued the second item of biblio $biblionumbe
Link Here
|
| 88 |
my $onsite_checkouts = GetPendingOnSiteCheckouts; |
96 |
my $onsite_checkouts = GetPendingOnSiteCheckouts; |
| 89 |
is( scalar @$onsite_checkouts, 0, "No pending on-site checkouts" ); |
97 |
is( scalar @$onsite_checkouts, 0, "No pending on-site checkouts" ); |
| 90 |
|
98 |
|
| 91 |
my $itemnumber4 = AddItem({ barcode => '0104', %item_branch_infos }, $biblionumber1); |
99 |
my $itemnumber4 = AddItem({ barcode => '0104', %item_infos }, $biblionumber1); |
| 92 |
AddIssue( $borrower, '0104', undef, undef, undef, undef, { onsite_checkout => 1 } ); |
100 |
AddIssue( $borrower, '0104', undef, undef, undef, undef, { onsite_checkout => 1 } ); |
| 93 |
$onsite_checkouts = GetPendingOnSiteCheckouts; |
101 |
$onsite_checkouts = GetPendingOnSiteCheckouts; |
| 94 |
is( scalar @$onsite_checkouts, 1, "There is 1 pending on-site checkout" ); |
102 |
is( scalar @$onsite_checkouts, 1, "There is 1 pending on-site checkout" ); |
| 95 |
- |
103 |
|
|
|
104 |
$schema->storage->txn_rollback; |
| 105 |
|
| 106 |
1; |