|
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 46-208
subtest 'transformMARCXML4XSLT tests' => sub {
Link Here
|
| 46 |
}; |
46 |
}; |
| 47 |
|
47 |
|
| 48 |
subtest 'buildKohaItemsNamespace status tests' => sub { |
48 |
subtest 'buildKohaItemsNamespace status tests' => sub { |
| 49 |
plan tests => 14; |
49 |
plan tests => 12; |
| 50 |
|
50 |
|
| 51 |
t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '1|2'); |
51 |
t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '1|2'); |
| 52 |
|
52 |
|
| 53 |
my $itype = $builder->build_object({ class => 'Koha::ItemTypes' }); |
53 |
my $item = $builder->build_sample_item({})->unblessed; |
| 54 |
my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' }); |
|
|
| 55 |
my $item = $builder->build_sample_item({ itype => $itype->itemtype }); |
| 56 |
$item->biblioitem->itemtype($itemtype->itemtype)->store; |
| 57 |
|
54 |
|
| 58 |
my $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
55 |
|
|
|
56 |
my $xml = C4::XSLT::buildKohaItemsNamespace([$item]); |
| 59 |
like($xml,qr{<status>available</status>},"Item is available when no other status applied"); |
57 |
like($xml,qr{<status>available</status>},"Item is available when no other status applied"); |
| 60 |
|
58 |
|
| 61 |
# notforloan |
59 |
# notforloan |
| 62 |
{ |
60 |
{ |
| 63 |
t::lib::Mocks::mock_preference('item-level_itypes', 0); |
61 |
|
| 64 |
$item->notforloan(0)->store; |
62 |
$item->{notforloan} = 1; |
| 65 |
Koha::ItemTypes->find($item->itype)->notforloan(0)->store; |
63 |
$xml = C4::XSLT::buildKohaItemsNamespace([$item]); |
| 66 |
Koha::ItemTypes->find($item->biblioitem->itemtype)->notforloan(1)->store; |
64 |
like($xml,qr{<status>reference</status>},"reference if itemtype notforloan value in Reference_NFL_Statuses"); |
| 67 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
65 |
|
| 68 |
like($xml,qr{<status>reference</status>},"reference if positive itype notforloan value"); |
66 |
$item->{notforloan} = -1; |
| 69 |
|
67 |
$item->{notforloan_description} = 'nopenope'; |
| 70 |
t::lib::Mocks::mock_preference('item-level_itypes', 1); |
68 |
$xml = C4::XSLT::buildKohaItemsNamespace( [$item]); |
| 71 |
Koha::ItemTypes->find($item->itype)->notforloan(1)->store; |
69 |
like($xml,qr{<status>reallynotforloan</status>},"reallynotforloan if notforloan value not in Reference_NFL_Statuses"); |
| 72 |
Koha::ItemTypes->find($item->biblioitem->itemtype)->notforloan(0)->store; |
70 |
like($xml,qr{<substatus>nopenope</substatus>},"substatus set if notforloan value not in Reference_NFL_Statuses"); |
| 73 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
|
|
| 74 |
like($xml,qr{<status>reference</status>},"reference if positive itemtype notforloan value"); |
| 75 |
Koha::ItemTypes->find($item->itype)->notforloan(0)->store; |
| 76 |
|
| 77 |
my $substatus = Koha::AuthorisedValues->search({ category => 'NOT_LOAN', authorised_value => -1 })->next->lib; |
| 78 |
$item->notforloan(-1)->store; |
| 79 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
| 80 |
like($xml,qr{<status>reallynotforloan</status>},"reallynotforloan if negative notforloan value"); |
| 81 |
like($xml,qr{<substatus>$substatus</substatus>},"substatus set if negative notforloan value"); |
| 82 |
|
| 83 |
$item->notforloan(1)->store; |
| 84 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
| 85 |
like($xml,qr{<status>reference</status>},"reference if positive notforloan value"); |
| 86 |
|
71 |
|
| 87 |
# But now make status notforloan==1 count under Not available |
72 |
# But now make status notforloan==1 count under Not available |
|
|
73 |
$item->{notforloan} = 1; |
| 88 |
t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '2'); |
74 |
t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '2'); |
| 89 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
75 |
$xml = C4::XSLT::buildKohaItemsNamespace( [$item]); |
| 90 |
like($xml,qr{<status>reallynotforloan</status>},"reallynotforloan when we change Reference_NFL_Statuses"); |
76 |
like($xml,qr{<status>reallynotforloan</status>},"reallynotforloan when we change Reference_NFL_Statuses"); |
| 91 |
t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '1|2'); |
77 |
t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '1|2'); |
| 92 |
} |
78 |
} |
| 93 |
|
79 |
|
| 94 |
$item->onloan('2001-01-01')->store; |
80 |
$item->{onloan} = '2001-01-01'; |
| 95 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
81 |
$xml = C4::XSLT::buildKohaItemsNamespace( [$item]); |
| 96 |
like($xml,qr{<status>Checked out</status>},"Checked out status takes precedence over Not for loan"); |
82 |
like($xml,qr{<status>Checked out</status>},"Checked out status takes precedence over Not for loan"); |
| 97 |
|
83 |
|
| 98 |
$item->withdrawn(1)->store; |
84 |
$item->{withdrawn} = 1; |
| 99 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
85 |
$xml = C4::XSLT::buildKohaItemsNamespace( [$item]); |
| 100 |
like($xml,qr{<status>Withdrawn</status>},"Withdrawn status takes precedence over Checked out"); |
86 |
like($xml,qr{<status>Withdrawn</status>},"Withdrawn status takes precedence over Checked out"); |
| 101 |
|
87 |
|
| 102 |
$item->itemlost(1)->store; |
88 |
$item->{itemlost} = 1; |
| 103 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
89 |
$xml = C4::XSLT::buildKohaItemsNamespace( [$item]); |
| 104 |
like($xml,qr{<status>Lost</status>},"Lost status takes precedence over Withdrawn"); |
90 |
like($xml,qr{<status>Lost</status>},"Lost status takes precedence over Withdrawn"); |
| 105 |
|
91 |
|
| 106 |
$item->damaged(1)->store; |
92 |
$item->{damaged} = 1; |
| 107 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
93 |
$xml = C4::XSLT::buildKohaItemsNamespace( [$item]); |
| 108 |
like($xml,qr{<status>Damaged</status>},"Damaged status takes precedence over Lost"); |
94 |
like($xml,qr{<status>Damaged</status>},"Damaged status takes precedence over Lost"); |
| 109 |
|
95 |
|
| 110 |
$builder->build({ source => "Branchtransfer", value => { |
96 |
$builder->build({ source => "Branchtransfer", value => { |
| 111 |
itemnumber => $item->itemnumber, |
97 |
itemnumber => $item->{itemnumber}, |
| 112 |
datearrived => undef, |
98 |
datearrived => undef, |
| 113 |
datecancelled => undef, |
99 |
datecancelled => undef, |
| 114 |
} |
100 |
} |
| 115 |
}); |
101 |
}); |
| 116 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
102 |
$xml = C4::XSLT::buildKohaItemsNamespace( [$item]); |
| 117 |
like($xml,qr{<status>In transit</status>},"In-transit status takes precedence over Damaged"); |
103 |
like($xml,qr{<status>In transit</status>},"In-transit status takes precedence over Damaged"); |
| 118 |
|
104 |
|
| 119 |
my $hold = $builder->build_object({ class => 'Koha::Holds', value => { |
105 |
my $hold = $builder->build_object({ class => 'Koha::Holds', value => { |
| 120 |
biblionumber => $item->biblionumber, |
106 |
biblionumber => $item->{biblionumber}, |
| 121 |
itemnumber => $item->itemnumber, |
107 |
itemnumber => $item->{itemnumber}, |
| 122 |
found => 'W', |
108 |
found => 'W', |
| 123 |
priority => 0, |
109 |
priority => 0, |
| 124 |
} |
110 |
} |
| 125 |
}); |
111 |
}); |
| 126 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
112 |
$xml = C4::XSLT::buildKohaItemsNamespace( [$item]); |
| 127 |
like($xml,qr{<status>Waiting</status>},"Waiting status takes precedence over In transit"); |
113 |
like($xml,qr{<status>Waiting</status>},"Waiting status takes precedence over In transit"); |
| 128 |
|
114 |
|
| 129 |
$builder->build({ source => "TmpHoldsqueue", value => { |
115 |
$builder->build({ source => "TmpHoldsqueue", value => { |
| 130 |
itemnumber => $item->itemnumber |
116 |
itemnumber => $item->{itemnumber} |
| 131 |
} |
117 |
} |
| 132 |
}); |
118 |
}); |
| 133 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
119 |
$xml = C4::XSLT::buildKohaItemsNamespace( [$item]); |
| 134 |
like($xml,qr{<status>Pending hold</status>},"Pending status takes precedence over all"); |
120 |
like($xml,qr{<status>Pending hold</status>},"Pending status takes precedence over all"); |
| 135 |
|
121 |
|
| 136 |
|
122 |
|
| 137 |
}; |
123 |
}; |
| 138 |
|
124 |
|
| 139 |
$schema->storage->txn_rollback; |
125 |
$schema->storage->txn_rollback; |
| 140 |
|
|
|
| 141 |
subtest 'buildKohaItemsNamespace() including/omitting items tests' => sub { |
| 142 |
|
| 143 |
plan tests => 20; |
| 144 |
|
| 145 |
$schema->storage->txn_begin; |
| 146 |
|
| 147 |
my $biblio = $builder->build_sample_biblio; |
| 148 |
|
| 149 |
# Have two known libraries for testing purposes |
| 150 |
my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); |
| 151 |
my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); |
| 152 |
my $library_3 = $builder->build_object({ class => 'Koha::Libraries' }); |
| 153 |
|
| 154 |
my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, library => $library_1->id }); |
| 155 |
my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, library => $library_2->id }); |
| 156 |
my $item_3 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, library => $library_3->id }); |
| 157 |
|
| 158 |
my $items_rs = $biblio->items->search({ "me.itemnumber" => { '!=' => $item_3->itemnumber } }); |
| 159 |
|
| 160 |
## Test passing items_rs only |
| 161 |
my $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, undef, $items_rs ); |
| 162 |
|
| 163 |
my $library_1_name = $library_1->branchname; |
| 164 |
my $library_2_name = $library_2->branchname; |
| 165 |
my $library_3_name = $library_3->branchname; |
| 166 |
|
| 167 |
like( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 present in the XML' ); |
| 168 |
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' ); |
| 170 |
## Test passing one item in hidden_items and items_rs |
| 171 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber ], $items_rs->reset ); |
| 172 |
|
| 173 |
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' ); |
| 175 |
unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' ); |
| 176 |
|
| 177 |
## 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 ); |
| 179 |
|
| 180 |
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' ); |
| 182 |
unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' ); |
| 183 |
is( $xml, '<items xmlns="http://www.koha-community.org/items"></items>', 'Empty XML' ); |
| 184 |
|
| 185 |
## 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 ] ); |
| 187 |
|
| 188 |
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' ); |
| 190 |
unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' ); |
| 191 |
is( $xml, '<items xmlns="http://www.koha-community.org/items"></items>', 'Empty XML' ); |
| 192 |
|
| 193 |
## Test passing one item in hidden_items and items_rs |
| 194 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber ] ); |
| 195 |
|
| 196 |
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' ); |
| 198 |
like( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 present in the XML' ); |
| 199 |
|
| 200 |
## Test not passing any param |
| 201 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber ); |
| 202 |
|
| 203 |
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' ); |
| 205 |
like( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 present in the XML' ); |
| 206 |
|
| 207 |
$schema->storage->txn_rollback; |
| 208 |
}; |
| 209 |
- |