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>.
25 use t::lib::TestBuilder;
27 use Module::Load::Conditional qw/check_install/;
30 if ( check_install( module => 'Test::DBIx::Class' ) ) {
33 plan skip_all => "Need Test::DBIx::Class"
37 # Mock the DB connexion and C4::Context
38 use Test::DBIx::Class;
42 qw/_build_initial_query/);
44 subtest "_build_initial_query tests" => sub {
48 my ($query,$query_cgi,$query_desc,$previous_operand);
49 # all params have values
52 query_cgi => "query_cgi",
53 query_desc => "query_desc",
54 operator => "operator",
55 parsed_operand => "parsed_operand",
56 original_operand => "original_operand",
58 index_plus => "index_plus",
59 indexes_set => "indexes_set",
60 previous_operand => "previous_operand"
63 ($query,$query_cgi,$query_desc,$previous_operand) =
64 C4::Search::_build_initial_query($params);
65 is( $query, "query operator parsed_operand",
66 "\$query built correctly");
67 is( $query_cgi, "query_cgi&op=%20operator%20&idx=index&q=original_operand",
68 "\$query_cgi built correctly");
69 is( $query_desc, "query_desc operator index_plus original_operand",
70 "\$query_desc build correctly");
71 is( $previous_operand, "previous_operand",
72 "\$query build correctly");
77 query_cgi => "query_cgi",
78 query_desc => "query_desc",
80 parsed_operand => "parsed_operand",
81 original_operand => "original_operand",
83 index_plus => "index_plus",
84 indexes_set => "indexes_set",
85 previous_operand => "previous_operand"
88 ($query,$query_cgi,$query_desc,$previous_operand) =
89 C4::Search::_build_initial_query($params);
90 is( $query, "query AND parsed_operand",
91 "\$query built correctly (no operator)");
92 is( $query_cgi, "query_cgi&op=%20AND%20&idx=index&q=original_operand",
93 "\$query_cgi built correctly (no operator)");
94 is( $query_desc, "query_desc AND index_plus original_operand",
95 "\$query_desc build correctly (no operator)");
96 is( $previous_operand, "previous_operand",
97 "\$query build correctly (no operator)");
102 query_cgi => "query_cgi",
103 query_desc => "query_desc",
104 operator => "operator",
105 parsed_operand => "parsed_operand",
106 original_operand => "original_operand",
108 index_plus => "index_plus",
109 indexes_set => "indexes_set",
110 previous_operand => undef
113 ($query,$query_cgi,$query_desc,$previous_operand) =
114 C4::Search::_build_initial_query($params);
115 is( $query, "queryparsed_operand",
116 "\$query built correctly (no previous operand)");
117 is( $query_cgi, "query_cgi&idx=index&q=original_operand",
118 "\$query_cgi built correctly (no previous operand)");
119 is( $query_desc, "query_descindex_plus original_operand",
120 "\$query_desc build correctly (no previous operand)");
121 is( $previous_operand, 1,
122 "\$query build correctly (no previous operand)");
127 query_cgi => "query_cgi",
128 query_desc => "query_desc",
129 operator => "operator",
130 parsed_operand => "parsed_operand",
131 original_operand => "original_operand",
133 index_plus => "index_plus",
134 indexes_set => "indexes_set",
135 previous_operand => "previous_operand"
138 ($query,$query_cgi,$query_desc,$previous_operand) =
139 C4::Search::_build_initial_query($params);
140 is( $query, "query operator parsed_operand",
141 "\$query built correctly (no index passed)");
142 is( $query_cgi, "query_cgi&op=%20operator%20&q=original_operand",
143 "\$query_cgi built correctly (no index passed)");
144 is( $query_desc, "query_desc operator index_plus original_operand",
145 "\$query_desc build correctly (no index passed)");
146 is( $previous_operand, "previous_operand",
147 "\$query build correctly (no index passed)");
149 # no index_plus passed
152 query_cgi => "query_cgi",
153 query_desc => "query_desc",
154 operator => "operator",
155 parsed_operand => "parsed_operand",
156 original_operand => "original_operand",
159 indexes_set => "indexes_set",
160 previous_operand => "previous_operand"
163 ($query,$query_cgi,$query_desc,$previous_operand) =
164 C4::Search::_build_initial_query($params);
165 is( $query, "query operator parsed_operand",
166 "\$query built correctly (no index_plus passed)");
167 is( $query_cgi, "query_cgi&op=%20operator%20&idx=index&q=original_operand",
168 "\$query_cgi built correctly (no index_plus passed)");
169 is( $query_desc, "query_desc operator original_operand",
170 "\$query_desc build correctly (no index_plus passed)");
171 is( $previous_operand, "previous_operand",
172 "\$query build correctly (no index_plus passed)");
176 subtest "searchResults PassItemMarcToXSLT test" => sub {
180 t::lib::Mocks::mock_preference('OPACXSLTResultsDisplay','default');
181 t::lib::Mocks::mock_preference('marcflavour','MARC21');
182 my $mock_xslt = Test::MockModule->new("C4::Search");
183 $mock_xslt->mock( XSLTParse4Display => sub {
185 my $record = $params->{record};
186 warn $record->field('952') ? "Item here" : "No item";
190 my $builder = t::lib::TestBuilder->new;
192 my $item = $builder->build_sample_item();
193 my $record = $item->biblio->metadata->record;
194 C4::Biblio::EmbedItemsInMarcBiblio({ marc_record => $record, biblionumber => $item->biblionumber });
196 t::lib::Mocks::mock_preference('PassItemMarcToXSLT','1');
198 warnings_like { C4::Search::searchResults({ interface => "opac" },"test",1,1,0,0,[ $record->as_xml_record ] ,undef) }
200 "Item field returned from default XSLT if pref set";
202 t::lib::Mocks::mock_preference('PassItemMarcToXSLT','0');
204 warnings_like { C4::Search::searchResults({ interface => "opac" },"test",1,1,0,0,[ $record->as_xml_record ] ,undef) }
206 "Item field returned from default XSLT if pref set";