Lines 35-48
my $builder = t::lib::TestBuilder->new;
Link Here
|
35 |
$schema->storage->txn_begin; |
35 |
$schema->storage->txn_begin; |
36 |
|
36 |
|
37 |
subtest 'transformMARCXML4XSLT tests' => sub { |
37 |
subtest 'transformMARCXML4XSLT tests' => sub { |
38 |
plan tests => 1; |
38 |
plan tests => 8; |
39 |
my $mock_xslt = Test::MockModule->new("C4::XSLT"); |
39 |
my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' }); |
40 |
$mock_xslt->mock( getAuthorisedValues4MARCSubfields => sub { return { 942 => { 'n' => 1 } } } ); |
40 |
my $itemtype_2 = $builder->build_object({ class => 'Koha::ItemTypes' }); |
41 |
$mock_xslt->mock( GetAuthorisedValueDesc => sub { warn "called"; }); |
41 |
my $branch = $builder->build_object({ class => 'Koha::Libraries' }); |
|
|
42 |
my $branch_2 = $builder->build_object({ class => 'Koha::Libraries' }); |
43 |
$itemtype_2->delete; |
44 |
$branch_2->delete; |
45 |
|
46 |
my $branches = { map { $_->branchcode => $_->branchname } Koha::Libraries->search({}, { order_by => 'branchname' }) }; |
47 |
my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; |
48 |
my $auth_val = $builder->build_object({ class => 'Koha::AuthorisedValues' }); |
49 |
my $av = { |
50 |
942 => { 'n' => { category => "SUPPRESS", SUPPRESS => { 1 => 'banana' } } }, |
51 |
952 => { |
52 |
'a' => { category => $auth_val->category, $auth_val->category => { |
53 |
$auth_val->authorised_value => $auth_val->unblessed |
54 |
}}, |
55 |
'b' => { category => $auth_val->category, $auth_val->category => { |
56 |
$auth_val->authorised_value => $auth_val->unblessed |
57 |
}}, |
58 |
'c' => { category => "branches" }, |
59 |
'd' => { category => "itemtypes" } |
60 |
} |
61 |
}; |
42 |
my $record = MARC::Record->new(); |
62 |
my $record = MARC::Record->new(); |
43 |
my $suppress_field = MARC::Field->new( 942, ' ', ' ', n => '1' ); |
63 |
my $suppress_field = MARC::Field->new( 942, ' ', ' ', n => '1' ); |
44 |
$record->append_fields($suppress_field); |
64 |
my $mapped_field = MARC::Field->new( 952, ' ', ' ', |
45 |
warning_is { C4::XSLT::transformMARCXML4XSLT( 3,$record ) } undef, "942n auth value not translated"; |
65 |
a => $auth_val->authorised_value, |
|
|
66 |
b => "POTATO", |
67 |
c => $branch->branchcode, |
68 |
d => $itemtype->itemtype |
69 |
); |
70 |
$record->append_fields( ($suppress_field, $mapped_field ) ); |
71 |
C4::XSLT::transformMARCXML4XSLT( 3, $record, $branches, $itemtypes, $av ); |
72 |
is($record->subfield( '942', 'n' ),1,'942$n is not transformed'); |
73 |
is($record->subfield( '952', 'a' ),$auth_val->lib,'952$a is transformed when value found'); |
74 |
is($record->subfield( '952', 'b' ),'POTATO','952$b is not transformed when value not found'); |
75 |
is($record->subfield( '952', 'c' ),$branch->branchname,'952$c is transformed when valid branchcode'); |
76 |
is($record->subfield( '952', 'd' ),$itemtype->translated_description,'952$d is transformed when valid itemtype'); |
77 |
|
78 |
$av->{952}->{a}->{$auth_val->category}->{$auth_val->authorised_value}->{lib} = ""; |
79 |
$record->field(952)->update( a => $auth_val->authorised_value, c => $branch_2->branchcode, d => $itemtype_2->itemtype ); |
80 |
C4::XSLT::transformMARCXML4XSLT( 3, $record, $branches, $itemtypes, $av ); |
81 |
is($record->subfield( '952', 'a' ),$auth_val->authorised_value,'952$a is not transformed when value found but blank'); |
82 |
is($record->subfield( '952', 'c' ),'','952$c is blanked when invalid branchcode'); |
83 |
is($record->subfield( '952', 'd' ),'','952$d is blanked when invalid itemtype'); |
84 |
|
85 |
|
46 |
}; |
86 |
}; |
47 |
|
87 |
|
48 |
subtest 'buildKohaItemsNamespace status tests' => sub { |
88 |
subtest 'buildKohaItemsNamespace status tests' => sub { |
Lines 55-61
subtest 'buildKohaItemsNamespace status tests' => sub {
Link Here
|
55 |
my $item = $builder->build_sample_item({ itype => $itype->itemtype }); |
95 |
my $item = $builder->build_sample_item({ itype => $itype->itemtype }); |
56 |
$item->biblioitem->itemtype($itemtype->itemtype)->store; |
96 |
$item->biblioitem->itemtype($itemtype->itemtype)->store; |
57 |
|
97 |
|
58 |
my $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
98 |
my $branches = { map { $_->branchcode => $_->branchname } Koha::Libraries->search({}, { order_by => 'branchname' }) }; |
|
|
99 |
my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; |
100 |
my $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[], undef, undef, $branches, $itemtypes); |
59 |
like($xml,qr{<status>available</status>},"Item is available when no other status applied"); |
101 |
like($xml,qr{<status>available</status>},"Item is available when no other status applied"); |
60 |
|
102 |
|
61 |
# notforloan |
103 |
# notforloan |
Lines 64-110
subtest 'buildKohaItemsNamespace status tests' => sub {
Link Here
|
64 |
$item->notforloan(0)->store; |
106 |
$item->notforloan(0)->store; |
65 |
Koha::ItemTypes->find($item->itype)->notforloan(0)->store; |
107 |
Koha::ItemTypes->find($item->itype)->notforloan(0)->store; |
66 |
Koha::ItemTypes->find($item->biblioitem->itemtype)->notforloan(1)->store; |
108 |
Koha::ItemTypes->find($item->biblioitem->itemtype)->notforloan(1)->store; |
67 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
109 |
$itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; |
|
|
110 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[], undef, $branches, $itemtypes); |
68 |
like($xml,qr{<status>reference</status>},"reference if positive itype notforloan value"); |
111 |
like($xml,qr{<status>reference</status>},"reference if positive itype notforloan value"); |
69 |
|
112 |
|
70 |
t::lib::Mocks::mock_preference('item-level_itypes', 1); |
113 |
t::lib::Mocks::mock_preference('item-level_itypes', 1); |
71 |
Koha::ItemTypes->find($item->itype)->notforloan(1)->store; |
114 |
Koha::ItemTypes->find($item->itype)->notforloan(1)->store; |
72 |
Koha::ItemTypes->find($item->biblioitem->itemtype)->notforloan(0)->store; |
115 |
Koha::ItemTypes->find($item->biblioitem->itemtype)->notforloan(0)->store; |
73 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
116 |
$itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; |
|
|
117 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[], undef, $branches, $itemtypes); |
74 |
like($xml,qr{<status>reference</status>},"reference if positive itemtype notforloan value"); |
118 |
like($xml,qr{<status>reference</status>},"reference if positive itemtype notforloan value"); |
75 |
Koha::ItemTypes->find($item->itype)->notforloan(0)->store; |
119 |
Koha::ItemTypes->find($item->itype)->notforloan(0)->store; |
76 |
|
120 |
|
77 |
my $substatus = Koha::AuthorisedValues->search({ category => 'NOT_LOAN', authorised_value => -1 })->next->lib; |
121 |
my $substatus = Koha::AuthorisedValues->search({ category => 'NOT_LOAN', authorised_value => -1 })->next->lib; |
78 |
$item->notforloan(-1)->store; |
122 |
$item->notforloan(-1)->store; |
79 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
123 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[], undef, $branches, $itemtypes); |
80 |
like($xml,qr{<status>reallynotforloan</status>},"reallynotforloan if negative notforloan value"); |
124 |
like($xml,qr{<status>reallynotforloan</status>},"reallynotforloan if negative notforloan value"); |
81 |
like($xml,qr{<substatus>$substatus</substatus>},"substatus set if negative notforloan value"); |
125 |
like($xml,qr{<substatus>$substatus</substatus>},"substatus set if negative notforloan value"); |
82 |
|
126 |
|
83 |
$item->notforloan(1)->store; |
127 |
$item->notforloan(1)->store; |
84 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
128 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[], undef, $branches, $itemtypes); |
85 |
like($xml,qr{<status>reference</status>},"reference if positive notforloan value"); |
129 |
like($xml,qr{<status>reference</status>},"reference if positive notforloan value"); |
86 |
|
130 |
|
87 |
# But now make status notforloan==1 count under Not available |
131 |
# But now make status notforloan==1 count under Not available |
88 |
t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '2'); |
132 |
t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '2'); |
89 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
133 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[], undef, $branches, $itemtypes); |
90 |
like($xml,qr{<status>reallynotforloan</status>},"reallynotforloan when we change Reference_NFL_Statuses"); |
134 |
like($xml,qr{<status>reallynotforloan</status>},"reallynotforloan when we change Reference_NFL_Statuses"); |
91 |
t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '1|2'); |
135 |
t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '1|2'); |
92 |
} |
136 |
} |
93 |
|
137 |
|
94 |
$item->onloan('2001-01-01')->store; |
138 |
$item->onloan('2001-01-01')->store; |
95 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
139 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[], undef, $branches, $itemtypes); |
96 |
like($xml,qr{<status>Checked out</status>},"Checked out status takes precedence over Not for loan"); |
140 |
like($xml,qr{<status>Checked out</status>},"Checked out status takes precedence over Not for loan"); |
97 |
|
141 |
|
98 |
$item->withdrawn(1)->store; |
142 |
$item->withdrawn(1)->store; |
99 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
143 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[], undef, $branches, $itemtypes); |
100 |
like($xml,qr{<status>Withdrawn</status>},"Withdrawn status takes precedence over Checked out"); |
144 |
like($xml,qr{<status>Withdrawn</status>},"Withdrawn status takes precedence over Checked out"); |
101 |
|
145 |
|
102 |
$item->itemlost(1)->store; |
146 |
$item->itemlost(1)->store; |
103 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
147 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[], undef, $branches, $itemtypes); |
104 |
like($xml,qr{<status>Lost</status>},"Lost status takes precedence over Withdrawn"); |
148 |
like($xml,qr{<status>Lost</status>},"Lost status takes precedence over Withdrawn"); |
105 |
|
149 |
|
106 |
$item->damaged(1)->store; |
150 |
$item->damaged(1)->store; |
107 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
151 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[], undef, $branches, $itemtypes); |
108 |
like($xml,qr{<status>Damaged</status>},"Damaged status takes precedence over Lost"); |
152 |
like($xml,qr{<status>Damaged</status>},"Damaged status takes precedence over Lost"); |
109 |
|
153 |
|
110 |
$builder->build({ source => "Branchtransfer", value => { |
154 |
$builder->build({ source => "Branchtransfer", value => { |
Lines 113-119
subtest 'buildKohaItemsNamespace status tests' => sub {
Link Here
|
113 |
datecancelled => undef, |
157 |
datecancelled => undef, |
114 |
} |
158 |
} |
115 |
}); |
159 |
}); |
116 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
160 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[], undef, $branches, $itemtypes); |
117 |
like($xml,qr{<status>In transit</status>},"In-transit status takes precedence over Damaged"); |
161 |
like($xml,qr{<status>In transit</status>},"In-transit status takes precedence over Damaged"); |
118 |
|
162 |
|
119 |
my $hold = $builder->build_object({ class => 'Koha::Holds', value => { |
163 |
my $hold = $builder->build_object({ class => 'Koha::Holds', value => { |
Lines 123-136
subtest 'buildKohaItemsNamespace status tests' => sub {
Link Here
|
123 |
priority => 0, |
167 |
priority => 0, |
124 |
} |
168 |
} |
125 |
}); |
169 |
}); |
126 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
170 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[], undef, $branches, $itemtypes); |
127 |
like($xml,qr{<status>Waiting</status>},"Waiting status takes precedence over In transit"); |
171 |
like($xml,qr{<status>Waiting</status>},"Waiting status takes precedence over In transit"); |
128 |
|
172 |
|
129 |
$builder->build({ source => "TmpHoldsqueue", value => { |
173 |
$builder->build({ source => "TmpHoldsqueue", value => { |
130 |
itemnumber => $item->itemnumber |
174 |
itemnumber => $item->itemnumber |
131 |
} |
175 |
} |
132 |
}); |
176 |
}); |
133 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
177 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[], undef, $branches, $itemtypes); |
134 |
like($xml,qr{<status>Pending hold</status>},"Pending status takes precedence over all"); |
178 |
like($xml,qr{<status>Pending hold</status>},"Pending status takes precedence over all"); |
135 |
|
179 |
|
136 |
|
180 |
|
Lines 157-164
subtest 'buildKohaItemsNamespace() including/omitting items tests' => sub {
Link Here
|
157 |
|
201 |
|
158 |
my $items_rs = $biblio->items->search({ "me.itemnumber" => { '!=' => $item_3->itemnumber } }); |
202 |
my $items_rs = $biblio->items->search({ "me.itemnumber" => { '!=' => $item_3->itemnumber } }); |
159 |
|
203 |
|
|
|
204 |
my $branches = { map { $_->branchcode => $_->branchname } Koha::Libraries->search({}, { order_by => 'branchname' }) }; |
205 |
my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; |
206 |
|
160 |
## Test passing items_rs only |
207 |
## Test passing items_rs only |
161 |
my $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, undef, $items_rs ); |
208 |
my $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, undef, $items_rs, $branches, $itemtypes ); |
162 |
|
209 |
|
163 |
my $library_1_name = $library_1->branchname; |
210 |
my $library_1_name = $library_1->branchname; |
164 |
my $library_2_name = $library_2->branchname; |
211 |
my $library_2_name = $library_2->branchname; |
Lines 168-181
subtest 'buildKohaItemsNamespace() including/omitting items tests' => sub {
Link Here
|
168 |
like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' ); |
215 |
like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' ); |
169 |
unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' ); |
216 |
unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' ); |
170 |
## Test passing one item in hidden_items and items_rs |
217 |
## Test passing one item in hidden_items and items_rs |
171 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber ], $items_rs->reset ); |
218 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber ], $items_rs->reset, $branches, $itemtypes ); |
172 |
|
219 |
|
173 |
unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' ); |
220 |
unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' ); |
174 |
like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' ); |
221 |
like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' ); |
175 |
unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' ); |
222 |
unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' ); |
176 |
|
223 |
|
177 |
## Test passing both items in hidden_items and items_rs |
224 |
## Test passing both items in hidden_items and items_rs |
178 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber, $item_2->itemnumber ], $items_rs->reset ); |
225 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber, $item_2->itemnumber ], $items_rs->reset, $branches, $itemtypes ); |
179 |
|
226 |
|
180 |
unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' ); |
227 |
unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' ); |
181 |
unlike( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 not present in the XML' ); |
228 |
unlike( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 not present in the XML' ); |
Lines 183-189
subtest 'buildKohaItemsNamespace() including/omitting items tests' => sub {
Link Here
|
183 |
is( $xml, '<items xmlns="http://www.koha-community.org/items"></items>', 'Empty XML' ); |
230 |
is( $xml, '<items xmlns="http://www.koha-community.org/items"></items>', 'Empty XML' ); |
184 |
|
231 |
|
185 |
## Test passing both items in hidden_items and no items_rs |
232 |
## Test passing both items in hidden_items and no items_rs |
186 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber, $item_2->itemnumber, $item_3->itemnumber ] ); |
233 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber, $item_2->itemnumber, $item_3->itemnumber ], $branches, $itemtypes ); |
187 |
|
234 |
|
188 |
unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' ); |
235 |
unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' ); |
189 |
unlike( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 not present in the XML' ); |
236 |
unlike( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 not present in the XML' ); |
Lines 191-204
subtest 'buildKohaItemsNamespace() including/omitting items tests' => sub {
Link Here
|
191 |
is( $xml, '<items xmlns="http://www.koha-community.org/items"></items>', 'Empty XML' ); |
238 |
is( $xml, '<items xmlns="http://www.koha-community.org/items"></items>', 'Empty XML' ); |
192 |
|
239 |
|
193 |
## Test passing one item in hidden_items and items_rs |
240 |
## Test passing one item in hidden_items and items_rs |
194 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber ] ); |
241 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber ], undef, $branches, $itemtypes ); |
195 |
|
242 |
|
196 |
unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' ); |
243 |
unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' ); |
197 |
like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' ); |
244 |
like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' ); |
198 |
like( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 present in the XML' ); |
245 |
like( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 present in the XML' ); |
199 |
|
246 |
|
200 |
## Test not passing any param |
247 |
## Test not passing any param |
201 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber ); |
248 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, undef, undef, $branches, $itemtypes ); |
202 |
|
249 |
|
203 |
like( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 present in the XML' ); |
250 |
like( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 present in the XML' ); |
204 |
like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' ); |
251 |
like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' ); |
205 |
- |
|
|