Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# Copyright 2016 Koha-Suomi Oy |
4 |
# |
5 |
# This file is part of Koha |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it |
8 |
# under the terms of the GNU General Public License as published by |
9 |
# the Free Software Foundation; either version 3 of the License, or |
10 |
# (at your option) any later version. |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but |
13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
# GNU General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
20 |
use Modern::Perl; |
21 |
|
22 |
use Test::More tests => 1; |
23 |
|
24 |
use Koha::IssuingRules; |
25 |
|
26 |
use t::lib::TestBuilder; |
27 |
|
28 |
my $schema = Koha::Database->new->schema; |
29 |
$schema->storage->txn_begin; |
30 |
|
31 |
my $builder = t::lib::TestBuilder->new; |
32 |
|
33 |
subtest 'get_effective_issuing_rule' => sub { |
34 |
plan tests => 1; |
35 |
|
36 |
my $patron = $builder->build({ source => 'Borrower' }); |
37 |
my $item = $builder->build({ source => 'Item' }); |
38 |
|
39 |
my $categorycode = $patron->{'categorycode'}; |
40 |
my $itemtype = $item->{'itype'}; |
41 |
my $branchcode = $item->{'homebranch'}; |
42 |
|
43 |
subtest 'Get effective issuing rule in correct order' => sub { |
44 |
plan tests => 18; |
45 |
|
46 |
my $rule; |
47 |
Koha::IssuingRules->delete; |
48 |
ok(!Koha::IssuingRules->search->count, 'There are no issuing rules.'); |
49 |
$rule = Koha::IssuingRules->get_effective_issuing_rule({ |
50 |
branchcode => $branchcode, |
51 |
categorycode => $categorycode, |
52 |
itemtype => $itemtype, |
53 |
}); |
54 |
is($rule, undef, 'When I attempt to get effective issuing rule, then undef' |
55 |
.' is returned.'); |
56 |
|
57 |
ok(Koha::IssuingRule->new({ |
58 |
branchcode => '*', |
59 |
categorycode => '*', |
60 |
itemtype => '*', |
61 |
})->store, 'Given I added an issuing rule branchcode => *, categorycode => *, itemtype => *,'); |
62 |
$rule = Koha::IssuingRules->get_effective_issuing_rule({ |
63 |
branchcode => $branchcode, |
64 |
categorycode => $categorycode, |
65 |
itemtype => $itemtype, |
66 |
}); |
67 |
ok(_row_match($rule, '*', '*', '*'), 'When I attempt to get effective issuing rule,' |
68 |
.' then the above one is returned.'); |
69 |
|
70 |
ok(Koha::IssuingRule->new({ |
71 |
branchcode => '*', |
72 |
categorycode => '*', |
73 |
itemtype => $itemtype, |
74 |
})->store, "Given I added an issuing rule branchcode => *, categorycode => *, itemtype => $itemtype,"); |
75 |
$rule = Koha::IssuingRules->get_effective_issuing_rule({ |
76 |
branchcode => $branchcode, |
77 |
categorycode => $categorycode, |
78 |
itemtype => $itemtype, |
79 |
}); |
80 |
ok(_row_match($rule, '*', '*', $itemtype), 'When I attempt to get effective issuing rule,' |
81 |
.' then the above one is returned.'); |
82 |
|
83 |
ok(Koha::IssuingRule->new({ |
84 |
branchcode => '*', |
85 |
categorycode => $categorycode, |
86 |
itemtype => '*', |
87 |
})->store, "Given I added an issuing rule branchcode => *, categorycode => $categorycode, itemtype => *,"); |
88 |
$rule = Koha::IssuingRules->get_effective_issuing_rule({ |
89 |
branchcode => $branchcode, |
90 |
categorycode => $categorycode, |
91 |
itemtype => $itemtype, |
92 |
}); |
93 |
ok(_row_match($rule, '*', $categorycode, '*'), 'When I attempt to get effective issuing rule,' |
94 |
.' then the above one is returned.'); |
95 |
|
96 |
ok(Koha::IssuingRule->new({ |
97 |
branchcode => '*', |
98 |
categorycode => $categorycode, |
99 |
itemtype => $itemtype, |
100 |
})->store, "Given I added an issuing rule branchcode => *, categorycode => $categorycode, itemtype => $itemtype,"); |
101 |
$rule = Koha::IssuingRules->get_effective_issuing_rule({ |
102 |
branchcode => $branchcode, |
103 |
categorycode => $categorycode, |
104 |
itemtype => $itemtype, |
105 |
}); |
106 |
ok(_row_match($rule, '*', $categorycode, $itemtype), 'When I attempt to get effective issuing rule,' |
107 |
.' then the above one is returned.'); |
108 |
|
109 |
ok(Koha::IssuingRule->new({ |
110 |
branchcode => $branchcode, |
111 |
categorycode => '*', |
112 |
itemtype => '*', |
113 |
})->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => '*', itemtype => '*',"); |
114 |
$rule = Koha::IssuingRules->get_effective_issuing_rule({ |
115 |
branchcode => $branchcode, |
116 |
categorycode => $categorycode, |
117 |
itemtype => $itemtype, |
118 |
}); |
119 |
ok(_row_match($rule, $branchcode, '*', '*'), 'When I attempt to get effective issuing rule,' |
120 |
.' then the above one is returned.'); |
121 |
|
122 |
ok(Koha::IssuingRule->new({ |
123 |
branchcode => $branchcode, |
124 |
categorycode => '*', |
125 |
itemtype => $itemtype, |
126 |
})->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => '*', itemtype => $itemtype,"); |
127 |
$rule = Koha::IssuingRules->get_effective_issuing_rule({ |
128 |
branchcode => $branchcode, |
129 |
categorycode => $categorycode, |
130 |
itemtype => $itemtype, |
131 |
}); |
132 |
ok(_row_match($rule, $branchcode, '*', $itemtype), 'When I attempt to get effective issuing rule,' |
133 |
.' then the above one is returned.'); |
134 |
|
135 |
ok(Koha::IssuingRule->new({ |
136 |
branchcode => $branchcode, |
137 |
categorycode => $categorycode, |
138 |
itemtype => '*', |
139 |
})->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => '*',"); |
140 |
$rule = Koha::IssuingRules->get_effective_issuing_rule({ |
141 |
branchcode => $branchcode, |
142 |
categorycode => $categorycode, |
143 |
itemtype => $itemtype, |
144 |
}); |
145 |
ok(_row_match($rule, $branchcode, $categorycode, '*'), 'When I attempt to get effective issuing rule,' |
146 |
.' then the above one is returned.'); |
147 |
|
148 |
ok(Koha::IssuingRule->new({ |
149 |
branchcode => $branchcode, |
150 |
categorycode => $categorycode, |
151 |
itemtype => $itemtype, |
152 |
})->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => $itemtype,"); |
153 |
$rule = Koha::IssuingRules->get_effective_issuing_rule({ |
154 |
branchcode => $branchcode, |
155 |
categorycode => $categorycode, |
156 |
itemtype => $itemtype, |
157 |
}); |
158 |
ok(_row_match($rule, $branchcode, $categorycode, $itemtype), 'When I attempt to get effective issuing rule,' |
159 |
.' then the above one is returned.'); |
160 |
}; |
161 |
}; |
162 |
|
163 |
sub _row_match { |
164 |
my ($rule, $branchcode, $categorycode, $itemtype) = @_; |
165 |
|
166 |
return $rule->branchcode eq $branchcode && $rule->categorycode eq $categorycode |
167 |
&& $rule->itemtype eq $itemtype; |
168 |
} |
169 |
|
170 |
$schema->storage->txn_rollback; |
171 |
|
172 |
1; |