Lines 30-36
use Koha::Libraries;
Link Here
|
30 |
use Koha::ItemTypes; |
30 |
use Koha::ItemTypes; |
31 |
|
31 |
|
32 |
BEGIN { |
32 |
BEGIN { |
33 |
use_ok('C4::XSLT', qw( buildKohaItemsNamespace )); |
33 |
use_ok( 'C4::XSLT', qw( buildKohaItemsNamespace ) ); |
34 |
} |
34 |
} |
35 |
|
35 |
|
36 |
my $schema = Koha::Database->new->schema; |
36 |
my $schema = Koha::Database->new->schema; |
Lines 38-49
my $builder = t::lib::TestBuilder->new;
Link Here
|
38 |
our $cache = Koha::Caches->get_instance; |
38 |
our $cache = Koha::Caches->get_instance; |
39 |
|
39 |
|
40 |
subtest 'Tests moved from t' => sub { |
40 |
subtest 'Tests moved from t' => sub { |
41 |
plan tests => 11; |
41 |
plan tests => 14; |
42 |
$schema->storage->txn_begin; |
42 |
$schema->storage->txn_begin; |
43 |
|
43 |
|
44 |
my $dir = File::Temp->newdir(); |
44 |
my $dir = File::Temp->newdir(); |
45 |
my @themes = ('prog', 'test'); |
45 |
my @themes = ( 'prog', 'test' ); |
46 |
my @langs = ('en', 'es-ES'); |
46 |
my @langs = ( 'en', 'es-ES' ); |
47 |
|
47 |
|
48 |
# create temporary files to be tested later |
48 |
# create temporary files to be tested later |
49 |
foreach my $theme (@themes) { |
49 |
foreach my $theme (@themes) { |
Lines 56-64
subtest 'Tests moved from t' => sub {
Link Here
|
56 |
} |
56 |
} |
57 |
|
57 |
|
58 |
sub find_and_slurp { |
58 |
sub find_and_slurp { |
59 |
my ($dir, $theme, $lang) = @_; |
59 |
my ( $dir, $theme, $lang ) = @_; |
60 |
|
60 |
|
61 |
my $filename = C4::XSLT::_get_best_default_xslt_filename($dir, $theme, $lang, 'my_file.xslt'); |
61 |
my $filename = C4::XSLT::_get_best_default_xslt_filename( $dir, $theme, $lang, 'my_file.xslt' ); |
62 |
open my $fh, '<', $filename; |
62 |
open my $fh, '<', $filename; |
63 |
my $str = <$fh>; |
63 |
my $str = <$fh>; |
64 |
close $fh; |
64 |
close $fh; |
Lines 67-115
subtest 'Tests moved from t' => sub {
Link Here
|
67 |
|
67 |
|
68 |
# These tests verify that we're finding the right XSLT file when present, |
68 |
# These tests verify that we're finding the right XSLT file when present, |
69 |
# and falling back to the right XSLT file when an exact match is not present. |
69 |
# and falling back to the right XSLT file when an exact match is not present. |
70 |
is(find_and_slurp($dir, 'test', 'en' ), 'Theme test, language en', 'Found test/en'); |
70 |
is( find_and_slurp( $dir, 'test', 'en' ), 'Theme test, language en', 'Found test/en' ); |
71 |
is(find_and_slurp($dir, 'test', 'es-ES'), 'Theme test, language es-ES', 'Found test/es-ES'); |
71 |
is( find_and_slurp( $dir, 'test', 'es-ES' ), 'Theme test, language es-ES', 'Found test/es-ES' ); |
72 |
is(find_and_slurp($dir, 'prog', 'en', ), 'Theme prog, language en', 'Found test/en'); |
72 |
is( find_and_slurp( $dir, 'prog', 'en', ), 'Theme prog, language en', 'Found test/en' ); |
73 |
is(find_and_slurp($dir, 'prog', 'es-ES'), 'Theme prog, language es-ES', 'Found test/es-ES'); |
73 |
is( find_and_slurp( $dir, 'prog', 'es-ES' ), 'Theme prog, language es-ES', 'Found test/es-ES' ); |
74 |
is(find_and_slurp($dir, 'test', 'fr-FR'), 'Theme test, language en', 'Fell back to test/en for test/fr-FR'); |
74 |
is( find_and_slurp( $dir, 'test', 'fr-FR' ), 'Theme test, language en', 'Fell back to test/en for test/fr-FR' ); |
75 |
is(find_and_slurp($dir, 'nope', 'es-ES'), 'Theme prog, language es-ES', 'Fell back to prog/es-ES for nope/es-ES'); |
75 |
is( |
76 |
is(find_and_slurp($dir, 'nope', 'fr-FR'), 'Theme prog, language en', 'Fell back to prog/en for nope/fr-FR'); |
76 |
find_and_slurp( $dir, 'nope', 'es-ES' ), 'Theme prog, language es-ES', |
|
|
77 |
'Fell back to prog/es-ES for nope/es-ES' |
78 |
); |
79 |
is( find_and_slurp( $dir, 'nope', 'fr-FR' ), 'Theme prog, language en', 'Fell back to prog/en for nope/fr-FR' ); |
77 |
|
80 |
|
78 |
my $matching_string = q{<syspref name="singleBranchMode">[0|1]</syspref>}; |
81 |
my $matching_string = q{<syspref name="singleBranchMode">[0|1]</syspref>}; |
79 |
my $sysprefs_xml = C4::XSLT::get_xslt_sysprefs(); |
82 |
my $sysprefs_xml = C4::XSLT::get_xslt_sysprefs(); |
80 |
ok( $sysprefs_xml =~ m/$matching_string/, 'singleBranchMode has no value'); |
83 |
ok( $sysprefs_xml =~ m/$matching_string/, 'singleBranchMode has no value' ); |
|
|
84 |
|
85 |
sub createXSLTFiles { |
86 |
my ( $path ) = @_; |
87 |
|
88 |
open my $fh, '>', "$path/export_01.xsl"; |
89 |
print $fh qq|<?xml version="1.0" encoding="UTF-8"?> |
90 |
<xsl:stylesheet version="1.0" |
91 |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
92 |
xmlns:marc="http://www.loc.gov/MARC21/slim" |
93 |
title="Export 01"> |
94 |
</xsl:stylesheet>|; |
95 |
close $fh; |
96 |
|
97 |
# Make XSL without title |
98 |
open $fh, '>', "$path/export_02.xsl"; |
99 |
print $fh qq|<?xml version="1.0" encoding="UTF-8"?> |
100 |
<xsl:stylesheet version="1.0" |
101 |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
102 |
xmlns:marc="http://www.loc.gov/MARC21/slim"> |
103 |
</xsl:stylesheet>|; |
104 |
close $fh; |
105 |
|
106 |
open $fh, '>', "$path/export_03.xsl"; |
107 |
print $fh qq|<?xml version="1.0" encoding="UTF-8"?>|; |
108 |
close $fh; |
109 |
} |
110 |
|
111 |
t::lib::Mocks::mock_preference( 'CustomXSLTExportPath', '' ); |
112 |
t::lib::Mocks::mock_config( 'opachtdocs', "$dir" ); |
81 |
|
113 |
|
82 |
t::lib::Mocks::mock_config('opachtdocs', "$dir"); |
|
|
83 |
make_path("$dir/bootstrap/en/xslt/biblioexport"); |
114 |
make_path("$dir/bootstrap/en/xslt/biblioexport"); |
|
|
115 |
createXSLTFiles("$dir/bootstrap/en/xslt/biblioexport"); |
84 |
|
116 |
|
85 |
# Make XSL with title |
117 |
t::lib::Mocks::mock_preference( 'OpacExportOptions', 'custom' ); |
86 |
open my $fh, '>', "$dir/bootstrap/en/xslt/biblioexport/export_01.xsl"; |
118 |
my @custom_xslts = @{ C4::XSLT::CustomXSLTExportList(1) }; |
87 |
print $fh qq|<?xml version="1.0" encoding="UTF-8"?> |
119 |
|
88 |
<xsl:stylesheet version="1.0" |
120 |
ok( ( scalar @custom_xslts ) == 2, "CustomXSLTExportList finds custom XSLTs" ); |
89 |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
121 |
ok( $custom_xslts[0]->{filename} eq "Export 01", "Title is specified in root node" ); |
90 |
xmlns:marc="http://www.loc.gov/MARC21/slim" |
122 |
ok( $custom_xslts[1]->{filename} eq "export_02", "Title is filename if not specified" ); |
91 |
title="Export 01"> |
123 |
|
92 |
</xsl:stylesheet>|; |
124 |
# CustomXSLTExportPath |
93 |
close $fh; |
125 |
t::lib::Mocks::mock_preference( 'CustomXSLTExportPath', "/$dir/XSLTExportFiles" ); |
94 |
|
126 |
make_path("$dir/XSLTExportFiles"); |
95 |
# Make XSL without title |
127 |
createXSLTFiles("$dir/XSLTExportFiles"); |
96 |
open $fh, '>', "$dir/bootstrap/en/xslt/biblioexport/export_02.xsl"; |
128 |
@custom_xslts = @{ C4::XSLT::CustomXSLTExportList(1) }; |
97 |
print $fh qq|<?xml version="1.0" encoding="UTF-8"?> |
129 |
|
98 |
<xsl:stylesheet version="1.0" |
130 |
ok( ( scalar @custom_xslts ) == 2, "CustomXSLTExportList finds custom XSLTs with CustomXSLTExportPath" ); |
99 |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
131 |
ok( $custom_xslts[0]->{filename} eq "Export 01", "Title is specified in root node with CustomXSLTExportPath" ); |
100 |
xmlns:marc="http://www.loc.gov/MARC21/slim"> |
132 |
ok( $custom_xslts[1]->{filename} eq "export_02", "Title is filename if not specified with CustomXSLTExportPath" ); |
101 |
</xsl:stylesheet>|; |
|
|
102 |
close $fh; |
103 |
|
104 |
open $fh, '>', "$dir/bootstrap/en/xslt/biblioexport/export_03.xsl"; |
105 |
print $fh qq|<?xml version="1.0" encoding="UTF-8"?>|; |
106 |
close $fh; |
107 |
|
108 |
t::lib::Mocks::mock_preference( 'OpacExportOptions', 'custom'); |
109 |
my @custom_xslts = @{C4::XSLT::CustomXSLTExportList(1)}; |
110 |
ok((scalar @custom_xslts) == 2, "CustomXSLTExportList finds custom XSLTs"); |
111 |
ok($custom_xslts[0]->{filename} eq "Export 01", "Title is specified in root node"); |
112 |
ok($custom_xslts[1]->{filename} eq "export_02", "Title is filename if not specified"); |
113 |
|
133 |
|
114 |
$schema->storage->txn_rollback; |
134 |
$schema->storage->txn_rollback; |
115 |
}; |
135 |
}; |
Lines 118-220
subtest 'buildKohaItemsNamespace status tests' => sub {
Link Here
|
118 |
plan tests => 18; |
138 |
plan tests => 18; |
119 |
$schema->storage->txn_begin; |
139 |
$schema->storage->txn_begin; |
120 |
|
140 |
|
121 |
t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '1|2'); |
141 |
t::lib::Mocks::mock_preference( 'Reference_NFL_Statuses', '1|2' ); |
122 |
t::lib::Mocks::mock_preference( 'OPACResultsLibrary', 'holdingbranch' ); |
142 |
t::lib::Mocks::mock_preference( 'OPACResultsLibrary', 'holdingbranch' ); |
123 |
t::lib::Mocks::mock_preference( 'OPACResultsMaxItems', '2' ); |
143 |
t::lib::Mocks::mock_preference( 'OPACResultsMaxItems', '2' ); |
124 |
|
144 |
|
125 |
my $itype = $builder->build_object({ class => 'Koha::ItemTypes' }); |
145 |
my $itype = $builder->build_object( { class => 'Koha::ItemTypes' } ); |
126 |
my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' }); |
146 |
my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes' } ); |
127 |
my $holdinglibrary = $builder->build_object({ class => 'Koha::Libraries' }); |
147 |
my $holdinglibrary = $builder->build_object( { class => 'Koha::Libraries' } ); |
128 |
my $item = $builder->build_sample_item({ itype => $itype->itemtype }); |
148 |
my $item = $builder->build_sample_item( { itype => $itype->itemtype } ); |
129 |
$item->holdingbranch( $holdinglibrary->branchcode )->store; |
149 |
$item->holdingbranch( $holdinglibrary->branchcode )->store; |
130 |
$item->biblioitem->itemtype($itemtype->itemtype)->store; |
150 |
$item->biblioitem->itemtype( $itemtype->itemtype )->store; |
131 |
|
151 |
|
132 |
my $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
152 |
my $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber, [] ); |
133 |
like($xml,qr{<status>available</status>},"Item is available when no other status applied"); |
153 |
like( $xml, qr{<status>available</status>}, "Item is available when no other status applied" ); |
134 |
|
154 |
|
135 |
# notforloan |
155 |
# notforloan |
136 |
{ |
156 |
{ |
137 |
t::lib::Mocks::mock_preference('item-level_itypes', 0); |
157 |
t::lib::Mocks::mock_preference( 'item-level_itypes', 0 ); |
138 |
$item->notforloan(0)->store; |
158 |
$item->notforloan(0)->store; |
139 |
Koha::ItemTypes->find($item->itype)->notforloan(0)->store; |
159 |
Koha::ItemTypes->find( $item->itype )->notforloan(0)->store; |
140 |
Koha::ItemTypes->find($item->biblioitem->itemtype)->notforloan(1)->store; |
160 |
Koha::ItemTypes->find( $item->biblioitem->itemtype )->notforloan(1)->store; |
141 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
161 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber, [] ); |
142 |
like($xml,qr{<status>reference</status>},"reference if positive itype notforloan value"); |
162 |
like( $xml, qr{<status>reference</status>}, "reference if positive itype notforloan value" ); |
143 |
|
163 |
|
144 |
t::lib::Mocks::mock_preference('item-level_itypes', 1); |
164 |
t::lib::Mocks::mock_preference( 'item-level_itypes', 1 ); |
145 |
Koha::ItemTypes->find($item->itype)->notforloan(1)->store; |
165 |
Koha::ItemTypes->find( $item->itype )->notforloan(1)->store; |
146 |
Koha::ItemTypes->find($item->biblioitem->itemtype)->notforloan(0)->store; |
166 |
Koha::ItemTypes->find( $item->biblioitem->itemtype )->notforloan(0)->store; |
147 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
167 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber, [] ); |
148 |
like($xml,qr{<status>reference</status>},"reference if positive itemtype notforloan value"); |
168 |
like( $xml, qr{<status>reference</status>}, "reference if positive itemtype notforloan value" ); |
149 |
Koha::ItemTypes->find($item->itype)->notforloan(0)->store; |
169 |
Koha::ItemTypes->find( $item->itype )->notforloan(0)->store; |
150 |
|
170 |
|
151 |
my $substatus = Koha::AuthorisedValues->search({ category => 'NOT_LOAN', authorised_value => -1 })->next->lib; |
171 |
my $substatus = Koha::AuthorisedValues->search( { category => 'NOT_LOAN', authorised_value => -1 } )->next->lib; |
152 |
$item->notforloan(-1)->store; |
172 |
$item->notforloan(-1)->store; |
153 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
173 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber, [] ); |
154 |
like($xml,qr{<status>reallynotforloan</status>},"reallynotforloan if negative notforloan value"); |
174 |
like( $xml, qr{<status>reallynotforloan</status>}, "reallynotforloan if negative notforloan value" ); |
155 |
like($xml,qr{<substatus>$substatus</substatus>},"substatus set if negative notforloan value"); |
175 |
like( $xml, qr{<substatus>$substatus</substatus>}, "substatus set if negative notforloan value" ); |
156 |
|
176 |
|
157 |
$item->notforloan(1)->store; |
177 |
$item->notforloan(1)->store; |
158 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
178 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber, [] ); |
159 |
like($xml,qr{<status>reference</status>},"reference if positive notforloan value"); |
179 |
like( $xml, qr{<status>reference</status>}, "reference if positive notforloan value" ); |
160 |
|
180 |
|
161 |
# But now make status notforloan==1 count under Not available |
181 |
# But now make status notforloan==1 count under Not available |
162 |
t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '2'); |
182 |
t::lib::Mocks::mock_preference( 'Reference_NFL_Statuses', '2' ); |
163 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
183 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber, [] ); |
164 |
like($xml,qr{<status>reallynotforloan</status>},"reallynotforloan when we change Reference_NFL_Statuses"); |
184 |
like( $xml, qr{<status>reallynotforloan</status>}, "reallynotforloan when we change Reference_NFL_Statuses" ); |
165 |
t::lib::Mocks::mock_preference('Reference_NFL_Statuses', q{}); # empty, same effect |
185 |
t::lib::Mocks::mock_preference( 'Reference_NFL_Statuses', q{} ); # empty, same effect |
166 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
186 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber, [] ); |
167 |
like($xml,qr{<status>reallynotforloan</status>},"reallynotforloan when we empty Reference_NFL_Statuses"); |
187 |
like( $xml, qr{<status>reallynotforloan</status>}, "reallynotforloan when we empty Reference_NFL_Statuses" ); |
168 |
t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '1|2'); |
188 |
t::lib::Mocks::mock_preference( 'Reference_NFL_Statuses', '1|2' ); |
169 |
} |
189 |
} |
170 |
|
190 |
|
171 |
$item->onloan('2001-01-01')->store; |
191 |
$item->onloan('2001-01-01')->store; |
172 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
192 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber, [] ); |
173 |
like( $xml, qr/<status>other<\/status>/, "Checked out is part of other statuses" ); |
193 |
like( $xml, qr/<status>other<\/status>/, "Checked out is part of other statuses" ); |
174 |
like($xml,qr{<substatus>Checked out</substatus>},"Checked out status takes precedence over Not for loan"); |
194 |
like( $xml, qr{<substatus>Checked out</substatus>}, "Checked out status takes precedence over Not for loan" ); |
175 |
|
195 |
|
176 |
$item->withdrawn(1)->store; |
196 |
$item->withdrawn(1)->store; |
177 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
197 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber, [] ); |
178 |
like($xml,qr{<substatus>Withdrawn</substatus>},"Withdrawn status takes precedence over Checked out"); |
198 |
like( $xml, qr{<substatus>Withdrawn</substatus>}, "Withdrawn status takes precedence over Checked out" ); |
179 |
|
199 |
|
180 |
$item->itemlost(1)->store; |
200 |
$item->itemlost(1)->store; |
181 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
201 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber, [] ); |
182 |
like($xml,qr{<substatus>Lost</substatus>},"Lost status takes precedence over Withdrawn"); |
202 |
like( $xml, qr{<substatus>Lost</substatus>}, "Lost status takes precedence over Withdrawn" ); |
183 |
|
203 |
|
184 |
$item->damaged(1)->store; |
204 |
$item->damaged(1)->store; |
185 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
205 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber, [] ); |
186 |
like($xml,qr{<substatus>Damaged</substatus>},"Damaged status takes precedence over Lost"); |
206 |
like( $xml, qr{<substatus>Damaged</substatus>}, "Damaged status takes precedence over Lost" ); |
187 |
|
207 |
|
188 |
$builder->build({ source => "Branchtransfer", value => { |
208 |
$builder->build( |
189 |
itemnumber => $item->itemnumber, |
209 |
{ |
190 |
datearrived => undef, |
210 |
source => "Branchtransfer", |
191 |
datecancelled => undef, |
211 |
value => { |
|
|
212 |
itemnumber => $item->itemnumber, |
213 |
datearrived => undef, |
214 |
datecancelled => undef, |
215 |
} |
192 |
} |
216 |
} |
193 |
}); |
217 |
); |
194 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
218 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber, [] ); |
195 |
like($xml,qr{<substatus>In transit</substatus>},"In-transit status takes precedence over Damaged"); |
219 |
like( $xml, qr{<substatus>In transit</substatus>}, "In-transit status takes precedence over Damaged" ); |
196 |
|
220 |
|
197 |
my $hold = $builder->build_object({ class => 'Koha::Holds', value => { |
221 |
my $hold = $builder->build_object( |
198 |
biblionumber => $item->biblionumber, |
222 |
{ |
199 |
itemnumber => $item->itemnumber, |
223 |
class => 'Koha::Holds', |
200 |
found => 'W', |
224 |
value => { |
201 |
priority => 0, |
225 |
biblionumber => $item->biblionumber, |
|
|
226 |
itemnumber => $item->itemnumber, |
227 |
found => 'W', |
228 |
priority => 0, |
229 |
} |
202 |
} |
230 |
} |
203 |
}); |
231 |
); |
204 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
232 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber, [] ); |
205 |
like($xml,qr{<substatus>Hold waiting</substatus>},"Waiting status takes precedence over In transit (holds)"); |
233 |
like( $xml, qr{<substatus>Hold waiting</substatus>}, "Waiting status takes precedence over In transit (holds)" ); |
206 |
$hold->cancel; |
234 |
$hold->cancel; |
207 |
|
235 |
|
208 |
$builder->build({ source => "TmpHoldsqueue", value => { |
236 |
$builder->build( { source => "TmpHoldsqueue", value => { itemnumber => $item->itemnumber } } ); |
209 |
itemnumber => $item->itemnumber |
237 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber, [] ); |
210 |
} |
238 |
like( $xml, qr{<substatus>Pending hold</substatus>}, "Pending status takes precedence over all" ); |
211 |
}); |
|
|
212 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
213 |
like($xml,qr{<substatus>Pending hold</substatus>},"Pending status takes precedence over all"); |
214 |
my $library_name = $holdinglibrary->branchname; |
239 |
my $library_name = $holdinglibrary->branchname; |
215 |
like($xml,qr{<resultbranch>${library_name}</resultbranch>}, "Found resultbranch / holding branch" ); |
240 |
like( $xml, qr{<resultbranch>${library_name}</resultbranch>}, "Found resultbranch / holding branch" ); |
216 |
|
241 |
|
217 |
t::lib::Mocks::mock_preference('UseRecalls', 1); |
242 |
t::lib::Mocks::mock_preference( 'UseRecalls', 1 ); |
218 |
my $recall = $builder->build_object( |
243 |
my $recall = $builder->build_object( |
219 |
{ |
244 |
{ |
220 |
class => 'Koha::Recalls', |
245 |
class => 'Koha::Recalls', |
Lines 227-246
subtest 'buildKohaItemsNamespace status tests' => sub {
Link Here
|
227 |
} |
252 |
} |
228 |
); |
253 |
); |
229 |
$recall->set_waiting; |
254 |
$recall->set_waiting; |
230 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); |
255 |
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber, [] ); |
231 |
like($xml,qr{<substatus>Recall waiting</substatus>},"Waiting status takes precedence over In transit (recalls)"); |
256 |
like( |
232 |
t::lib::Mocks::mock_preference('UseRecalls', 0); |
257 |
$xml, qr{<substatus>Recall waiting</substatus>}, |
|
|
258 |
"Waiting status takes precedence over In transit (recalls)" |
259 |
); |
260 |
t::lib::Mocks::mock_preference( 'UseRecalls', 0 ); |
233 |
|
261 |
|
234 |
$schema->storage->txn_rollback; |
262 |
$schema->storage->txn_rollback; |
235 |
}; |
263 |
}; |
236 |
|
264 |
|
237 |
subtest 'CustomXSLTExportList: Check export options' => sub { |
265 |
subtest 'CustomXSLTExportList: Check export options' => sub { |
238 |
plan tests => 2; |
266 |
plan tests => 2; |
239 |
t::lib::Mocks::mock_preference('OpacExportOptions', 'custom'); |
267 |
t::lib::Mocks::mock_preference( 'OpacExportOptions', 'custom' ); |
240 |
my $list = C4::XSLT::CustomXSLTExportList(1); |
268 |
my $list = C4::XSLT::CustomXSLTExportList(1); |
241 |
is( $list>0, 1, 'We expect at least one result: simple export' ); |
269 |
is( $list > 0, 1, 'We expect at least one result: simple export' ); |
242 |
$cache->clear_from_cache('CustomXSLTExportListOPAC'); |
270 |
$cache->clear_from_cache('CustomXSLTExportListOPAC'); |
243 |
t::lib::Mocks::mock_preference('OpacExportOptions', 'dc'); |
271 |
t::lib::Mocks::mock_preference( 'OpacExportOptions', 'dc' ); |
244 |
$list = C4::XSLT::CustomXSLTExportList(1); |
272 |
$list = C4::XSLT::CustomXSLTExportList(1); |
245 |
is( @$list, 0, 'We expect an empty list now' ); |
273 |
is( @$list, 0, 'We expect an empty list now' ); |
246 |
}; |
274 |
}; |
Lines 250-268
subtest 'buildKohaItemsNamespace() including/omitting items tests' => sub {
Link Here
|
250 |
|
278 |
|
251 |
$schema->storage->txn_begin; |
279 |
$schema->storage->txn_begin; |
252 |
|
280 |
|
253 |
my $biblio = $builder->build_sample_biblio; |
281 |
my $biblio = $builder->build_sample_biblio; |
254 |
my $biblio2 = $builder->build_sample_biblio; |
282 |
my $biblio2 = $builder->build_sample_biblio; |
255 |
|
283 |
|
256 |
# Have two known libraries for testing purposes |
284 |
# Have two known libraries for testing purposes |
257 |
my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); |
285 |
my $library_1 = $builder->build_object( { class => 'Koha::Libraries' } ); |
258 |
my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); |
286 |
my $library_2 = $builder->build_object( { class => 'Koha::Libraries' } ); |
259 |
my $library_3 = $builder->build_object({ class => 'Koha::Libraries' }); |
287 |
my $library_3 = $builder->build_object( { class => 'Koha::Libraries' } ); |
260 |
|
288 |
|
261 |
my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, library => $library_1->id }); |
289 |
my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, library => $library_1->id } ); |
262 |
my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, library => $library_2->id }); |
290 |
my $item_2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, library => $library_2->id } ); |
263 |
my $item_3 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, library => $library_3->id }); |
291 |
my $item_3 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, library => $library_3->id } ); |
264 |
|
292 |
|
265 |
my $items_rs = $biblio->items->search({ "me.itemnumber" => { '!=' => $item_3->itemnumber } }); |
293 |
my $items_rs = $biblio->items->search( { "me.itemnumber" => { '!=' => $item_3->itemnumber } } ); |
266 |
|
294 |
|
267 |
## Test passing items_rs only |
295 |
## Test passing items_rs only |
268 |
my $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, undef, $items_rs ); |
296 |
my $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, undef, $items_rs ); |
Lines 271-296
subtest 'buildKohaItemsNamespace() including/omitting items tests' => sub {
Link Here
|
271 |
my $library_2_name = $library_2->branchname; |
299 |
my $library_2_name = $library_2->branchname; |
272 |
my $library_3_name = $library_3->branchname; |
300 |
my $library_3_name = $library_3->branchname; |
273 |
|
301 |
|
274 |
like( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 present in the XML' ); |
302 |
like( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 present in the XML' ); |
275 |
like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' ); |
303 |
like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' ); |
276 |
unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' ); |
304 |
unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' ); |
277 |
|
305 |
|
278 |
t::lib::Mocks::mock_preference('OpacHiddenItems', 'biblionumber: ['.$biblio2->biblionumber.']'); |
306 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', 'biblionumber: [' . $biblio2->biblionumber . ']' ); |
279 |
my $hid_rs = $biblio->items->search({ "me.itemnumber" => { '!=' => $item_3->itemnumber } })->filter_by_visible_in_opac(); |
307 |
my $hid_rs = |
|
|
308 |
$biblio->items->search( { "me.itemnumber" => { '!=' => $item_3->itemnumber } } )->filter_by_visible_in_opac(); |
280 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, undef, $hid_rs ); |
309 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, undef, $hid_rs ); |
281 |
like( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 present in the XML' ); |
310 |
like( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 present in the XML' ); |
282 |
like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' ); |
311 |
like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' ); |
283 |
unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' ); |
312 |
unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' ); |
284 |
|
313 |
|
285 |
## Test passing one item in hidden_items and items_rs |
314 |
## Test passing one item in hidden_items and items_rs |
286 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber ], $items_rs->reset ); |
315 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber ], $items_rs->reset ); |
287 |
|
316 |
|
288 |
unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' ); |
317 |
unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' ); |
289 |
like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' ); |
318 |
like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' ); |
290 |
unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' ); |
319 |
unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' ); |
291 |
|
320 |
|
292 |
## Test passing both items in hidden_items and items_rs |
321 |
## Test passing both items in hidden_items and items_rs |
293 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber, $item_2->itemnumber ], $items_rs->reset ); |
322 |
$xml = C4::XSLT::buildKohaItemsNamespace( |
|
|
323 |
$biblio->biblionumber, [ $item_1->itemnumber, $item_2->itemnumber ], |
324 |
$items_rs->reset |
325 |
); |
294 |
|
326 |
|
295 |
unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' ); |
327 |
unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' ); |
296 |
unlike( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 not present in the XML' ); |
328 |
unlike( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 not present in the XML' ); |
Lines 298-304
subtest 'buildKohaItemsNamespace() including/omitting items tests' => sub {
Link Here
|
298 |
is( $xml, '<items xmlns="http://www.koha-community.org/items"></items>', 'Empty XML' ); |
330 |
is( $xml, '<items xmlns="http://www.koha-community.org/items"></items>', 'Empty XML' ); |
299 |
|
331 |
|
300 |
## Test passing both items in hidden_items and no items_rs |
332 |
## Test passing both items in hidden_items and no items_rs |
301 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber, $item_2->itemnumber, $item_3->itemnumber ] ); |
333 |
$xml = C4::XSLT::buildKohaItemsNamespace( |
|
|
334 |
$biblio->biblionumber, |
335 |
[ $item_1->itemnumber, $item_2->itemnumber, $item_3->itemnumber ] |
336 |
); |
302 |
|
337 |
|
303 |
unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' ); |
338 |
unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' ); |
304 |
unlike( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 not present in the XML' ); |
339 |
unlike( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 not present in the XML' ); |
Lines 309-316
subtest 'buildKohaItemsNamespace() including/omitting items tests' => sub {
Link Here
|
309 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber ] ); |
344 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber ] ); |
310 |
|
345 |
|
311 |
unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' ); |
346 |
unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' ); |
312 |
like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' ); |
347 |
like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' ); |
313 |
like( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 present in the XML' ); |
348 |
like( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 present in the XML' ); |
314 |
|
349 |
|
315 |
## Test not passing any param |
350 |
## Test not passing any param |
316 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber ); |
351 |
$xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber ); |