Lines 18-24
Link Here
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use MARC::Record; |
20 |
use MARC::Record; |
21 |
use Test::More tests => 4; |
21 |
use Test::More tests => 3; |
22 |
use Test::Warn; |
22 |
use Test::Warn; |
23 |
use t::lib::TestBuilder; |
23 |
use t::lib::TestBuilder; |
24 |
use t::lib::Mocks; |
24 |
use t::lib::Mocks; |
Lines 48-237
subtest 'transformMARCXML4XSLT tests' => sub {
Link Here
|
48 |
}; |
48 |
}; |
49 |
|
49 |
|
50 |
subtest 'buildKohaItemsNamespace status tests' => sub { |
50 |
subtest 'buildKohaItemsNamespace status tests' => sub { |
51 |
plan tests => 17; |
51 |
plan tests => 14; |
52 |
|
52 |
|
53 |
t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '1|2'); |
53 |
t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '1|2'); |
54 |
t::lib::Mocks::mock_preference( 'OPACResultsLibrary', 'holdingbranch' ); |
54 |
t::lib::Mocks::mock_preference( 'OPACResultsLibrary', 'holdingbranch' ); |
55 |
t::lib::Mocks::mock_preference( 'OPACResultsMaxItems', '2' ); |
55 |
t::lib::Mocks::mock_preference( 'OPACResultsMaxItems', '2' ); |
56 |
|
56 |
|
57 |
my $itype = $builder->build_object({ class => 'Koha::ItemTypes' }); |
57 |
my $holdingbranch = $builder->build_object({ class => 'Koha::Libraries' }); |
58 |
my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' }); |
58 |
my $item = $builder->build_sample_item({ holdingbranch => $holdingbranch->branchcode })->unblessed; |
59 |
my $holdinglibrary = $builder->build_object({ class => 'Koha::Libraries' }); |
|
|
60 |
my $item = $builder->build_sample_item({ itype => $itype->itemtype }); |
61 |
$item->holdingbranch( $holdinglibrary->branchcode )->store; |
62 |
$item->biblioitem->itemtype($itemtype->itemtype)->store; |
63 |
|
59 |
|
64 |
my $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
60 |
my $xml = C4::XSLT::buildKohaItemsNamespace([$item]); |
65 |
like($xml,qr{<status>available</status>},"Item is available when no other status applied"); |
61 |
like($xml,qr{<status>available</status>},"Item is available when no other status applied"); |
66 |
|
62 |
|
67 |
# notforloan |
63 |
# notforloan |
68 |
{ |
64 |
{ |
69 |
t::lib::Mocks::mock_preference('item-level_itypes', 0); |
65 |
|
70 |
$item->notforloan(0)->store; |
66 |
$item->{notforloan} = 1; |
71 |
Koha::ItemTypes->find($item->itype)->notforloan(0)->store; |
67 |
$xml = C4::XSLT::buildKohaItemsNamespace([$item]); |
72 |
Koha::ItemTypes->find($item->biblioitem->itemtype)->notforloan(1)->store; |
68 |
like($xml,qr{<status>reference</status>},"reference if itemtype notforloan value in Reference_NFL_Statuses"); |
73 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
69 |
|
74 |
like($xml,qr{<status>reference</status>},"reference if positive itype notforloan value"); |
70 |
$item->{notforloan} = -1; |
75 |
|
71 |
$item->{notforloan_description} = 'nopenope'; |
76 |
t::lib::Mocks::mock_preference('item-level_itypes', 1); |
72 |
$xml = C4::XSLT::buildKohaItemsNamespace( [$item]); |
77 |
Koha::ItemTypes->find($item->itype)->notforloan(1)->store; |
73 |
like($xml,qr{<status>reallynotforloan</status>},"reallynotforloan if notforloan value not in Reference_NFL_Statuses"); |
78 |
Koha::ItemTypes->find($item->biblioitem->itemtype)->notforloan(0)->store; |
74 |
like($xml,qr{<substatus>nopenope</substatus>},"substatus set if notforloan value not in Reference_NFL_Statuses"); |
79 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
|
|
80 |
like($xml,qr{<status>reference</status>},"reference if positive itemtype notforloan value"); |
81 |
Koha::ItemTypes->find($item->itype)->notforloan(0)->store; |
82 |
|
83 |
my $substatus = Koha::AuthorisedValues->search({ category => 'NOT_LOAN', authorised_value => -1 })->next->lib; |
84 |
$item->notforloan(-1)->store; |
85 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
86 |
like($xml,qr{<status>reallynotforloan</status>},"reallynotforloan if negative notforloan value"); |
87 |
like($xml,qr{<substatus>$substatus</substatus>},"substatus set if negative notforloan value"); |
88 |
|
89 |
$item->notforloan(1)->store; |
90 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
91 |
like($xml,qr{<status>reference</status>},"reference if positive notforloan value"); |
92 |
|
75 |
|
93 |
# But now make status notforloan==1 count under Not available |
76 |
# But now make status notforloan==1 count under Not available |
|
|
77 |
$item->{notforloan} = 1; |
94 |
t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '2'); |
78 |
t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '2'); |
95 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
79 |
$xml = C4::XSLT::buildKohaItemsNamespace( [$item]); |
96 |
like($xml,qr{<status>reallynotforloan</status>},"reallynotforloan when we change Reference_NFL_Statuses"); |
80 |
like($xml,qr{<status>reallynotforloan</status>},"reallynotforloan when we change Reference_NFL_Statuses"); |
97 |
t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '1|2'); |
81 |
t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '1|2'); |
98 |
} |
82 |
} |
99 |
|
83 |
|
100 |
$item->onloan('2001-01-01')->store; |
84 |
$item->{onloan} = '2001-01-01'; |
101 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
85 |
$xml = C4::XSLT::buildKohaItemsNamespace( [$item]); |
102 |
like( $xml, qr/<status>other<\/status>/, "Checked out is part of other statuses" ); |
|
|
103 |
like($xml,qr{<substatus>Checked out</substatus>},"Checked out status takes precedence over Not for loan"); |
86 |
like($xml,qr{<substatus>Checked out</substatus>},"Checked out status takes precedence over Not for loan"); |
104 |
|
87 |
|
105 |
$item->withdrawn(1)->store; |
88 |
$item->{withdrawn} = 1; |
106 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
89 |
$xml = C4::XSLT::buildKohaItemsNamespace( [$item]); |
107 |
like($xml,qr{<substatus>Withdrawn</substatus>},"Withdrawn status takes precedence over Checked out"); |
90 |
like($xml,qr{<substatus>Withdrawn</substatus>},"Withdrawn status takes precedence over Checked out"); |
108 |
|
91 |
|
109 |
$item->itemlost(1)->store; |
92 |
$item->{itemlost} = 1; |
110 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
93 |
$xml = C4::XSLT::buildKohaItemsNamespace( [$item]); |
111 |
like($xml,qr{<substatus>Lost</substatus>},"Lost status takes precedence over Withdrawn"); |
94 |
like($xml,qr{<substatus>Lost</substatus>},"Lost status takes precedence over Withdrawn"); |
112 |
|
95 |
|
113 |
$item->damaged(1)->store; |
96 |
$item->{damaged} = 1; |
114 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
97 |
$xml = C4::XSLT::buildKohaItemsNamespace( [$item]); |
115 |
like($xml,qr{<substatus>Damaged</substatus>},"Damaged status takes precedence over Lost"); |
98 |
like($xml,qr{<substatus>Damaged</substatus>},"Damaged status takes precedence over Lost"); |
116 |
|
99 |
|
117 |
$builder->build({ source => "Branchtransfer", value => { |
100 |
$builder->build({ source => "Branchtransfer", value => { |
118 |
itemnumber => $item->itemnumber, |
101 |
itemnumber => $item->{itemnumber}, |
119 |
datearrived => undef, |
102 |
datearrived => undef, |
120 |
datecancelled => undef, |
103 |
datecancelled => undef, |
121 |
} |
104 |
} |
122 |
}); |
105 |
}); |
123 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
106 |
$xml = C4::XSLT::buildKohaItemsNamespace( [$item]); |
124 |
like($xml,qr{<substatus>In transit</substatus>},"In-transit status takes precedence over Damaged"); |
107 |
like($xml,qr{<substatus>In transit</substatus>},"In-transit status takes precedence over Damaged"); |
125 |
|
108 |
|
126 |
my $hold = $builder->build_object({ class => 'Koha::Holds', value => { |
109 |
my $hold = $builder->build_object({ class => 'Koha::Holds', value => { |
127 |
biblionumber => $item->biblionumber, |
110 |
biblionumber => $item->{biblionumber}, |
128 |
itemnumber => $item->itemnumber, |
111 |
itemnumber => $item->{itemnumber}, |
129 |
found => 'W', |
112 |
found => 'W', |
130 |
priority => 0, |
113 |
priority => 0, |
131 |
} |
114 |
} |
132 |
}); |
115 |
}); |
133 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
116 |
$xml = C4::XSLT::buildKohaItemsNamespace( [$item]); |
134 |
like($xml,qr{<substatus>Hold waiting</substatus>},"Waiting status takes precedence over In transit (holds)"); |
117 |
like($xml,qr{<substatus>Waiting</substatus>},"Waiting status takes precedence over In transit"); |
135 |
$hold->cancel; |
|
|
136 |
|
118 |
|
137 |
$builder->build({ source => "TmpHoldsqueue", value => { |
119 |
$builder->build({ source => "TmpHoldsqueue", value => { |
138 |
itemnumber => $item->itemnumber |
120 |
itemnumber => $item->{itemnumber} |
139 |
} |
121 |
} |
140 |
}); |
122 |
}); |
141 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
123 |
|
|
|
124 |
$xml = C4::XSLT::buildKohaItemsNamespace( [$item]); |
142 |
like($xml,qr{<substatus>Pending hold</substatus>},"Pending status takes precedence over all"); |
125 |
like($xml,qr{<substatus>Pending hold</substatus>},"Pending status takes precedence over all"); |
143 |
my $library_name = $holdinglibrary->branchname; |
126 |
|
144 |
like($xml,qr{<resultbranch>${library_name}</resultbranch>}, "Found resultbranch / holding branch" ); |
127 |
my $resultbranch = $holdingbranch->branchcode; |
|
|
128 |
like($xml,qr{<resultbranch>${resultbranch}</resultbranch>}, "Found resultbranch / holding branch" ); |
145 |
|
129 |
|
146 |
t::lib::Mocks::mock_preference('UseRecalls', 1); |
130 |
t::lib::Mocks::mock_preference('UseRecalls', 1); |
147 |
my $recall = $builder->build_object({ class => 'Koha::Recalls', value => { |
131 |
my $recall = $builder->build_object({ class => 'Koha::Recalls', value => { |
148 |
biblio_id => $item->biblionumber, |
132 |
biblio_id => $item->{biblionumber}, |
149 |
item_id => $item->itemnumber, |
133 |
item_id => $item->{itemnumber}, |
150 |
pickup_library_id => $item->holdingbranch, |
134 |
pickup_library_id => $item->{holdingbranch}, |
151 |
}}); |
135 |
}}); |
152 |
$recall->set_waiting; |
136 |
$recall->set_waiting; |
153 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
137 |
$xml = C4::XSLT::buildKohaItemsNamespace( [$item] ); |
154 |
like($xml,qr{<substatus>Recall waiting</substatus>},"Waiting status takes precedence over In transit (recalls)"); |
138 |
like($xml,qr{<substatus>Recall waiting</substatus>},"Waiting status takes precedence over In transit (recalls)"); |
155 |
t::lib::Mocks::mock_preference('UseRecalls', 0); |
139 |
t::lib::Mocks::mock_preference('UseRecalls', 0); |
156 |
|
140 |
|
|
|
141 |
|
157 |
}; |
142 |
}; |
158 |
|
143 |
|
159 |
$schema->storage->txn_rollback; |
144 |
$schema->storage->txn_rollback; |
160 |
|
|
|
161 |
subtest 'buildKohaItemsNamespace() including/omitting items tests' => sub { |
162 |
|
163 |
plan tests => 23; |
164 |
|
165 |
$schema->storage->txn_begin; |
166 |
|
167 |
my $biblio = $builder->build_sample_biblio; |
168 |
my $biblio2 = $builder->build_sample_biblio; |
169 |
|
170 |
# Have two known libraries for testing purposes |
171 |
my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); |
172 |
my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); |
173 |
my $library_3 = $builder->build_object({ class => 'Koha::Libraries' }); |
174 |
|
175 |
my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, library => $library_1->id }); |
176 |
my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, library => $library_2->id }); |
177 |
my $item_3 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, library => $library_3->id }); |
178 |
|
179 |
my $items_rs = $biblio->items->search({ "me.itemnumber" => { '!=' => $item_3->itemnumber } }); |
180 |
|
181 |
## Test passing items_rs only |
182 |
my $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, undef, $items_rs ); |
183 |
|
184 |
my $library_1_name = $library_1->branchname; |
185 |
my $library_2_name = $library_2->branchname; |
186 |
my $library_3_name = $library_3->branchname; |
187 |
|
188 |
like( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 present in the XML' ); |
189 |
like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' ); |
190 |
unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' ); |
191 |
|
192 |
t::lib::Mocks::mock_preference('OpacHiddenItems', 'biblionumber: ['.$biblio2->biblionumber.']'); |
193 |
my $hid_rs = $biblio->items->search({ "me.itemnumber" => { '!=' => $item_3->itemnumber } })->filter_by_visible_in_opac(); |
194 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, undef, $hid_rs ); |
195 |
like( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 present in the XML' ); |
196 |
like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' ); |
197 |
unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' ); |
198 |
|
199 |
## Test passing one item in hidden_items and items_rs |
200 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber ], $items_rs->reset ); |
201 |
|
202 |
unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' ); |
203 |
like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' ); |
204 |
unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' ); |
205 |
|
206 |
## Test passing both items in hidden_items and items_rs |
207 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber, $item_2->itemnumber ], $items_rs->reset ); |
208 |
|
209 |
unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' ); |
210 |
unlike( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 not present in the XML' ); |
211 |
unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' ); |
212 |
is( $xml, '<items xmlns="http://www.koha-community.org/items"></items>', 'Empty XML' ); |
213 |
|
214 |
## Test passing both items in hidden_items and no items_rs |
215 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber, $item_2->itemnumber, $item_3->itemnumber ] ); |
216 |
|
217 |
unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' ); |
218 |
unlike( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 not present in the XML' ); |
219 |
unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' ); |
220 |
is( $xml, '<items xmlns="http://www.koha-community.org/items"></items>', 'Empty XML' ); |
221 |
|
222 |
## Test passing one item in hidden_items and items_rs |
223 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber ] ); |
224 |
|
225 |
unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' ); |
226 |
like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' ); |
227 |
like( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 present in the XML' ); |
228 |
|
229 |
## Test not passing any param |
230 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber ); |
231 |
|
232 |
like( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 present in the XML' ); |
233 |
like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' ); |
234 |
like( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 present in the XML' ); |
235 |
|
236 |
$schema->storage->txn_rollback; |
237 |
}; |
238 |
- |