3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test::More tests => 2;
27 subtest "_build_initial_query tests" => sub {
31 my ($query,$query_cgi,$query_desc,$previous_operand);
32 # all params have values
35 query_cgi => "query_cgi",
36 query_desc => "query_desc",
37 operator => "operator",
38 parsed_operand => "parsed_operand",
39 original_operand => "original_operand",
41 index_plus => "index_plus",
42 indexes_set => "indexes_set",
43 previous_operand => "previous_operand"
46 ($query,$query_cgi,$query_desc,$previous_operand) =
47 C4::Search::_build_initial_query($params);
48 is( $query, "query operator parsed_operand",
49 "\$query built correctly");
50 is( $query_cgi, "query_cgi&op=operator&idx=index&q=original_operand",
51 "\$query_cgi built correctly");
52 is( $query_desc, "query_desc operator index_plus original_operand",
53 "\$query_desc build correctly");
54 is( $previous_operand, "previous_operand",
55 "\$query build correctly");
60 query_cgi => "query_cgi",
61 query_desc => "query_desc",
63 parsed_operand => "parsed_operand",
64 original_operand => "original_operand",
66 index_plus => "index_plus",
67 indexes_set => "indexes_set",
68 previous_operand => "previous_operand"
71 ($query,$query_cgi,$query_desc,$previous_operand) =
72 C4::Search::_build_initial_query($params);
73 is( $query, "query AND parsed_operand",
74 "\$query built correctly (no operator)");
75 is( $query_cgi, "query_cgi&op=AND&idx=index&q=original_operand",
76 "\$query_cgi built correctly (no operator)");
77 is( $query_desc, "query_desc AND index_plus original_operand",
78 "\$query_desc build correctly (no operator)");
79 is( $previous_operand, "previous_operand",
80 "\$query build correctly (no operator)");
85 query_cgi => "query_cgi",
86 query_desc => "query_desc",
87 operator => "operator",
88 parsed_operand => "parsed_operand",
89 original_operand => "original_operand",
91 index_plus => "index_plus",
92 indexes_set => "indexes_set",
93 previous_operand => undef
96 ($query,$query_cgi,$query_desc,$previous_operand) =
97 C4::Search::_build_initial_query($params);
98 is( $query, "query parsed_operand",
99 "\$query built correctly (no previous operand)");
100 is( $query_cgi, "query_cgi&idx=index&q=original_operand",
101 "\$query_cgi built correctly (no previous operand)");
102 is( $query_desc, "query_desc index_plus original_operand",
103 "\$query_desc build correctly (no previous operand)");
104 is( $previous_operand, 1,
105 "\$query build correctly (no previous operand)");
110 query_cgi => "query_cgi",
111 query_desc => "query_desc",
112 operator => "operator",
113 parsed_operand => "parsed_operand",
114 original_operand => "original_operand",
116 index_plus => "index_plus",
117 indexes_set => "indexes_set",
118 previous_operand => "previous_operand"
121 ($query,$query_cgi,$query_desc,$previous_operand) =
122 C4::Search::_build_initial_query($params);
123 is( $query, "query operator parsed_operand",
124 "\$query built correctly (no index passed)");
125 is( $query_cgi, "query_cgi&op=operator&q=original_operand",
126 "\$query_cgi built correctly (no index passed)");
127 is( $query_desc, "query_desc operator index_plus original_operand",
128 "\$query_desc build correctly (no index passed)");
129 is( $previous_operand, "previous_operand",
130 "\$query build correctly (no index passed)");
132 # no index_plus passed
135 query_cgi => "query_cgi",
136 query_desc => "query_desc",
137 operator => "operator",
138 parsed_operand => "parsed_operand",
139 original_operand => "original_operand",
142 indexes_set => "indexes_set",
143 previous_operand => "previous_operand"
146 ($query,$query_cgi,$query_desc,$previous_operand) =
147 C4::Search::_build_initial_query($params);
148 is( $query, "query operator parsed_operand",
149 "\$query built correctly (no index_plus passed)");
150 is( $query_cgi, "query_cgi&op=operator&idx=index&q=original_operand",
151 "\$query_cgi built correctly (no index_plus passed)");
152 is( $query_desc, "query_desc operator original_operand",
153 "\$query_desc build correctly (no index_plus passed)");
154 is( $previous_operand, "previous_operand",
155 "\$query build correctly (no index_plus passed)");
159 subtest "searchResults PassItemMarcToXSLT test" => sub {
163 t::lib::Mocks::mock_preference('OPACXSLTResultsDisplay','default');
164 t::lib::Mocks::mock_preference('marcflavour','MARC21');
165 my $mock_xslt = Test::MockModule->new("C4::Search");
166 $mock_xslt->mock( XSLTParse4Display => sub {
168 my $record = $params->{record};
169 warn $record->field('952') ? "Item here" : "No item";
175 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
176 xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"
177 xmlns="http://www.loc.gov/MARC21/slim">
179 <leader>00144 a2200073 4500</leader>
180 <datafield tag="245" ind1=" " ind2=" ">
181 <subfield code="a">Some boring read</subfield>
183 <datafield tag="100" ind1=" " ind2=" ">
184 <subfield code="a">Some boring author</subfield>
186 <datafield tag="942" ind1=" " ind2=" ">
187 <subfield code="c">gOlAIZMF</subfield>
189 <datafield tag="952" ind1=" " ind2=" ">
190 <subfield code="0">0</subfield>
191 <subfield code="1">0</subfield>
192 <subfield code="4">0</subfield>
193 <subfield code="7">0</subfield>
194 <subfield code="9">1117</subfield>
195 <subfield code="a">D6C8Pj</subfield>
196 <subfield code="b">D6C8Pj</subfield>
197 <subfield code="d">2023-03-31</subfield>
198 <subfield code="l">0</subfield>
199 <subfield code="p">g57ad1Zn3NOYZ</subfield>
200 <subfield code="r">2023-03-31</subfield>
201 <subfield code="w">2023-03-31</subfield>
202 <subfield code="y">gOlAIZMF</subfield>
204 <datafield tag="999" ind1=" " ind2=" ">
205 <subfield code="c">553</subfield>
206 <subfield code="d">553</subfield>
210 t::lib::Mocks::mock_preference('PassItemMarcToXSLT','1');
212 # The routine uses a count of items in DB to determine if record should be hidden.
213 # Our item is not in the DB, so we avoid hiding the record which would
214 # mean we don't call XSLTParse4Display.
215 # Also ensure item is not hidden
216 t::lib::Mocks::mock_preference('OpacHiddenItems','');
217 t::lib::Mocks::mock_preference('OpacHiddenItemsHidesRecord','0');
219 warnings_like { C4::Search::searchResults({ interface => "opac" },"test",1,1,0,0,[ $xml_record ] ,undef) }
221 "Item field returned from default XSLT if pref set";
223 t::lib::Mocks::mock_preference('PassItemMarcToXSLT','0');
225 warnings_like { C4::Search::searchResults({ interface => "opac" },"test",1,1,0,0,[ $xml_record ] ,undef) }
227 "Item field returned from default XSLT if pref set";