View | Details | Raw Unified | Return to bug 28371
Collapse All | Expand All

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

Return to bug 28371