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

(-)a/t/db_dependent/XSLT.t (-26 / +74 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' }) };
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' }) };
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-146 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>Waiting</substatus>},"Waiting status takes precedence over In transit");
178
    like($xml,qr{<substatus>Waiting</substatus>},"Waiting status takes precedence over In transit");
135
179
136
    $builder->build({ source => "TmpHoldsqueue", value => {
180
    $builder->build({ source => "TmpHoldsqueue", value => {
137
        itemnumber => $item->itemnumber
181
        itemnumber => $item->itemnumber
138
        }
182
        }
139
    });
183
    });
140
    $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
184
185
    $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[], undef, $branches, $itemtypes);
141
    like($xml,qr{<substatus>Pending hold</substatus>},"Pending status takes precedence over all");
186
    like($xml,qr{<substatus>Pending hold</substatus>},"Pending status takes precedence over all");
142
    my $library_name = $holdinglibrary->branchname;
187
    my $library_name = $holdinglibrary->branchname;
143
    like($xml,qr{<resultbranch>${library_name}</resultbranch>}, "Found resultbranch / holding branch" );
188
    like($xml,qr{<resultbranch>${library_name}</resultbranch>}, "Found resultbranch / holding branch" );
189
144
};
190
};
145
191
146
$schema->storage->txn_rollback;
192
$schema->storage->txn_rollback;
Lines 164-171 subtest 'buildKohaItemsNamespace() including/omitting items tests' => sub { Link Here
164
210
165
    my $items_rs = $biblio->items->search({ "me.itemnumber" => { '!=' => $item_3->itemnumber } });
211
    my $items_rs = $biblio->items->search({ "me.itemnumber" => { '!=' => $item_3->itemnumber } });
166
212
213
    my $branches = { map { $_->branchcode => $_->branchname } Koha::Libraries->search({}, { order_by => 'branchname' }) };
214
    my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } };
215
167
    ## Test passing items_rs only
216
    ## Test passing items_rs only
168
    my $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, undef, $items_rs );
217
    my $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, undef, $items_rs, $branches, $itemtypes );
169
218
170
    my $library_1_name = $library_1->branchname;
219
    my $library_1_name = $library_1->branchname;
171
    my $library_2_name = $library_2->branchname;
220
    my $library_2_name = $library_2->branchname;
Lines 175-188 subtest 'buildKohaItemsNamespace() including/omitting items tests' => sub { Link Here
175
    like(   $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' );
224
    like(   $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' );
176
    unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' );
225
    unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' );
177
    ## Test passing one item in hidden_items and items_rs
226
    ## Test passing one item in hidden_items and items_rs
178
    $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber ], $items_rs->reset );
227
    $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber ], $items_rs->reset, $branches, $itemtypes );
179
228
180
    unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' );
229
    unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' );
181
    like(   $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' );
230
    like(   $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' );
182
    unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' );
231
    unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' );
183
232
184
    ## Test passing both items in hidden_items and items_rs
233
    ## Test passing both items in hidden_items and items_rs
185
    $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber, $item_2->itemnumber ], $items_rs->reset );
234
    $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber, $item_2->itemnumber ], $items_rs->reset, $branches, $itemtypes );
186
235
187
    unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' );
236
    unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' );
188
    unlike( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 not present in the XML' );
237
    unlike( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 not present in the XML' );
Lines 190-196 subtest 'buildKohaItemsNamespace() including/omitting items tests' => sub { Link Here
190
    is( $xml, '<items xmlns="http://www.koha-community.org/items"></items>', 'Empty XML' );
239
    is( $xml, '<items xmlns="http://www.koha-community.org/items"></items>', 'Empty XML' );
191
240
192
    ## Test passing both items in hidden_items and no items_rs
241
    ## Test passing both items in hidden_items and no items_rs
193
    $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber, $item_2->itemnumber, $item_3->itemnumber ] );
242
    $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber, $item_2->itemnumber, $item_3->itemnumber ], $branches, $itemtypes );
194
243
195
    unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' );
244
    unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' );
196
    unlike( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 not present in the XML' );
245
    unlike( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 not present in the XML' );
Lines 198-211 subtest 'buildKohaItemsNamespace() including/omitting items tests' => sub { Link Here
198
    is( $xml, '<items xmlns="http://www.koha-community.org/items"></items>', 'Empty XML' );
247
    is( $xml, '<items xmlns="http://www.koha-community.org/items"></items>', 'Empty XML' );
199
248
200
    ## Test passing one item in hidden_items and items_rs
249
    ## Test passing one item in hidden_items and items_rs
201
    $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber ] );
250
    $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber ], undef, $branches, $itemtypes );
202
251
203
    unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' );
252
    unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' );
204
    like(   $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' );
253
    like(   $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' );
205
    like(   $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 present in the XML' );
254
    like(   $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 present in the XML' );
206
255
207
    ## Test not passing any param
256
    ## Test not passing any param
208
    $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber );
257
    $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, undef, undef, $branches, $itemtypes );
209
258
210
    like( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 present in the XML' );
259
    like( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 present in the XML' );
211
    like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' );
260
    like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' );
212
- 

Return to bug 28371