|
Lines 1-8
Link Here
|
| 1 |
#!/usr/bin/env perl |
1 |
#!/usr/bin/perl |
|
|
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>. |
| 2 |
|
17 |
|
| 3 |
use Modern::Perl; |
18 |
use Modern::Perl; |
|
|
19 |
|
| 4 |
use Test::More tests => 14; |
20 |
use Test::More tests => 14; |
| 5 |
use Test::MockModule; |
21 |
use Test::MockModule; |
|
|
22 |
use t::lib::TestBuilder; |
| 6 |
|
23 |
|
| 7 |
use C4::Context; |
24 |
use C4::Context; |
| 8 |
use C4::Circulation; |
25 |
use C4::Circulation; |
|
Lines 12-52
use C4::Members;
Link Here
|
| 12 |
|
29 |
|
| 13 |
use Koha::Database; |
30 |
use Koha::Database; |
| 14 |
|
31 |
|
| 15 |
my $dbh = C4::Context->dbh; |
32 |
my $schema = Koha::Database->new()->schema(); |
| 16 |
my $schema = Koha::Database->new()->schema(); |
33 |
my $dbh = $schema->storage->dbh; |
|
|
34 |
my $builder = t::lib::TestBuilder->new(); |
| 17 |
|
35 |
|
| 18 |
# Start transaction |
36 |
# Start transaction |
| 19 |
$dbh->{RaiseError} = 1; |
37 |
$dbh->{RaiseError} = 1; |
| 20 |
$schema->storage->txn_begin(); |
38 |
$schema->storage->txn_begin(); |
| 21 |
|
39 |
|
| 22 |
$dbh->do(q{INSERT INTO itemtypes (itemtype) VALUES ('GTI_I_TEST')}); |
40 |
my $itemtype = $builder->build({ source => 'Itemtype' })->{ itemtype }; |
| 23 |
$schema->resultset('Category')->create({ categorycode => 'GTI_C_TEST' }); |
41 |
my $category = $builder->build({ source => 'Category' })->{ categorycode }; |
| 24 |
$schema->resultset('Branch')->create({ branchcode => 'GTI_B_1', branchname => 'GTI_B_1' }); |
42 |
my $branch_1 = $builder->build({ source => 'Branch' }); |
| 25 |
$schema->resultset('Branch')->create({ branchcode => 'GTI_B_2', branchname => 'GTI_B_2' }); |
43 |
my $branch_2 = $builder->build({ source => 'Branch' }); |
| 26 |
|
44 |
|
| 27 |
my $c4_context = Test::MockModule->new('C4::Context'); |
45 |
my $c4_context = Test::MockModule->new('C4::Context'); |
| 28 |
$c4_context->mock('userenv', sub { |
46 |
$c4_context->mock('userenv', sub { |
| 29 |
{ branch => 'GTI_B_1' } |
47 |
{ branch => $branch_1->{ branchcode } } |
| 30 |
}); |
48 |
}); |
| 31 |
C4::Context->set_preference('item-level_itypes', '0'); |
49 |
C4::Context->set_preference('item-level_itypes', '0'); |
| 32 |
|
50 |
|
| 33 |
my $biblionumber = create_biblio('Test 1', 'GTI_I_TEST'); |
51 |
my $biblionumber = create_biblio('Test 1', $itemtype); |
| 34 |
AddItem({ |
52 |
AddItem({ |
| 35 |
barcode => 'GTI_BARCODE_001', |
53 |
barcode => 'GTI_BARCODE_001', |
| 36 |
homebranch => 'GTI_B_1', |
54 |
homebranch => $branch_1->{ branchcode }, |
| 37 |
ccode => 'GTI_CCODE', |
55 |
ccode => 'GTI_CCODE', |
| 38 |
}, $biblionumber); |
56 |
}, $biblionumber); |
| 39 |
|
57 |
|
| 40 |
$biblionumber = create_biblio('Test 2', 'GTI_I_TEST'); |
58 |
$biblionumber = create_biblio('Test 2', $itemtype); |
| 41 |
AddItem({ |
59 |
AddItem({ |
| 42 |
barcode => 'GTI_BARCODE_002', |
60 |
barcode => 'GTI_BARCODE_002', |
| 43 |
homebranch => 'GTI_B_2', |
61 |
homebranch => $branch_2->{ branchcode }, |
| 44 |
}, $biblionumber); |
62 |
}, $biblionumber); |
| 45 |
|
63 |
|
| 46 |
my $borrowernumber = AddMember( |
64 |
my $borrowernumber = AddMember( |
| 47 |
userid => 'gti.test', |
65 |
userid => 'gti.test', |
| 48 |
categorycode => 'GTI_C_TEST', |
66 |
categorycode => $category, |
| 49 |
branchcode => 'GTI_B_1' |
67 |
branchcode => $branch_1->{ branchcode } |
| 50 |
); |
68 |
); |
| 51 |
my $borrower = GetMember(borrowernumber => $borrowernumber); |
69 |
my $borrower = GetMember(borrowernumber => $borrowernumber); |
| 52 |
|
70 |
|
|
Lines 57-72
AddIssue($borrower, 'GTI_BARCODE_002');
Link Here
|
| 57 |
# Start of tests |
75 |
# Start of tests |
| 58 |
# |
76 |
# |
| 59 |
|
77 |
|
| 60 |
my @issues = GetTopIssues({count => 10, itemtype => 'GTI_I_TEST'}); |
78 |
my @issues = GetTopIssues({count => 10, itemtype => $itemtype}); |
| 61 |
is(scalar @issues, 2); |
79 |
is(scalar @issues, 2); |
| 62 |
is($issues[0]->{title}, 'Test 1'); |
80 |
is($issues[0]->{title}, 'Test 1'); |
| 63 |
is($issues[1]->{title}, 'Test 2'); |
81 |
is($issues[1]->{title}, 'Test 2'); |
| 64 |
|
82 |
|
| 65 |
@issues = GetTopIssues({count => 1, itemtype => 'GTI_I_TEST'}); |
83 |
@issues = GetTopIssues({count => 1, itemtype => $itemtype}); |
| 66 |
is(scalar @issues, 1); |
84 |
is(scalar @issues, 1); |
| 67 |
is($issues[0]->{title}, 'Test 1'); |
85 |
is($issues[0]->{title}, 'Test 1'); |
| 68 |
|
86 |
|
| 69 |
@issues = GetTopIssues({count => 10, branch => 'GTI_B_2'}); |
87 |
@issues = GetTopIssues({count => 10, branch => $branch_2->{ branchcode }}); |
| 70 |
is(scalar @issues, 1); |
88 |
is(scalar @issues, 1); |
| 71 |
is($issues[0]->{title}, 'Test 2'); |
89 |
is($issues[0]->{title}, 'Test 2'); |
| 72 |
|
90 |
|
|
Lines 74-80
is($issues[0]->{title}, 'Test 2');
Link Here
|
| 74 |
is(scalar @issues, 1); |
92 |
is(scalar @issues, 1); |
| 75 |
is($issues[0]->{title}, 'Test 1'); |
93 |
is($issues[0]->{title}, 'Test 1'); |
| 76 |
|
94 |
|
| 77 |
@issues = GetTopIssues({count => 10, itemtype => 'GTI_I_TEST', newness => 1}); |
95 |
@issues = GetTopIssues({count => 10, itemtype => $itemtype, newness => 1}); |
| 78 |
is(scalar @issues, 2); |
96 |
is(scalar @issues, 2); |
| 79 |
is($issues[0]->{title}, 'Test 1'); |
97 |
is($issues[0]->{title}, 'Test 1'); |
| 80 |
is($issues[1]->{title}, 'Test 2'); |
98 |
is($issues[1]->{title}, 'Test 2'); |
|
Lines 85-91
$dbh->do(q{
Link Here
|
| 85 |
WHERE biblionumber = ? |
103 |
WHERE biblionumber = ? |
| 86 |
}, undef, $biblionumber); |
104 |
}, undef, $biblionumber); |
| 87 |
|
105 |
|
| 88 |
@issues = GetTopIssues({count => 10, itemtype => 'GTI_I_TEST', newness => 1}); |
106 |
@issues = GetTopIssues({count => 10, itemtype => $itemtype, newness => 1}); |
| 89 |
is(scalar @issues, 1); |
107 |
is(scalar @issues, 1); |
| 90 |
is($issues[0]->{title}, 'Test 1'); |
108 |
is($issues[0]->{title}, 'Test 1'); |
| 91 |
|
109 |
|
| 92 |
- |
|
|