Lines 3-10
Link Here
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
4 |
|
4 |
|
5 |
use Test::More tests => 3; |
5 |
use Test::More tests => 3; |
|
|
6 |
use Test::WWW::Mechanize; |
6 |
use t::lib::Mocks qw(mock_preference); |
7 |
use t::lib::Mocks qw(mock_preference); |
7 |
|
8 |
|
|
|
9 |
use File::Basename; |
10 |
use XML::LibXML; |
8 |
use YAML; |
11 |
use YAML; |
9 |
use ZOOM; |
12 |
use ZOOM; |
10 |
|
13 |
|
Lines 17-23
our $child;
Link Here
|
17 |
|
20 |
|
18 |
subtest 'test_search' => sub { |
21 |
subtest 'test_search' => sub { |
19 |
|
22 |
|
20 |
plan tests => 9; |
23 |
plan tests => 20; |
21 |
|
24 |
|
22 |
t::lib::Mocks::mock_preference('SearchEngine', 'Elasticsearch'); |
25 |
t::lib::Mocks::mock_preference('SearchEngine', 'Elasticsearch'); |
23 |
|
26 |
|
Lines 51-57
subtest 'test_search' => sub {
Link Here
|
51 |
biblios => { |
54 |
biblios => { |
52 |
use => { |
55 |
use => { |
53 |
1 => 'author', |
56 |
1 => 'author', |
54 |
4 => 'title' |
57 |
4 => 'title', |
|
|
58 |
1003 => 'author' |
55 |
} |
59 |
} |
56 |
} |
60 |
} |
57 |
}; |
61 |
}; |
Lines 68-74
subtest 'test_search' => sub {
Link Here
|
68 |
$search->mock('simple_search_compat', sub { |
72 |
$search->mock('simple_search_compat', sub { |
69 |
my ( $self, $query ) = @_; |
73 |
my ( $self, $query ) = @_; |
70 |
|
74 |
|
71 |
return (1, undef, 0) unless $query eq '((author:(author)) AND ((title:(title\(s\))) OR (title:(another))))'; |
75 |
return ('unexpected query', undef, 0) unless $query eq '((author:(author)) AND ((title:(title\(s\))) OR (title:(another))))'; |
72 |
|
76 |
|
73 |
my @records = ($marc_record_1, $marc_record_2); |
77 |
my @records = ($marc_record_1, $marc_record_2); |
74 |
return (undef, \@records, 2); |
78 |
return (undef, \@records, 2); |
Lines 76-91
subtest 'test_search' => sub {
Link Here
|
76 |
|
80 |
|
77 |
$child = fork(); |
81 |
$child = fork(); |
78 |
if ($child == 0) { |
82 |
if ($child == 0) { |
79 |
my @yaz_options = ( '@:42111' ); |
83 |
my $config_dir = dirname(__FILE__) . '/'; |
80 |
my $z = Koha::Z3950Responder->new( { |
84 |
my $z = Koha::Z3950Responder->new( { |
81 |
config_dir => '', |
85 |
config_dir => $config_dir |
82 |
yaz_options => [ @yaz_options ] |
|
|
83 |
}); |
86 |
}); |
84 |
$z->start(); |
87 |
$z->start(); |
85 |
exit; |
88 |
exit; |
86 |
} |
89 |
} |
87 |
sleep(1); |
90 |
sleep(1); |
88 |
|
91 |
|
|
|
92 |
# Z39.50 protocol tests |
89 |
my $o = new ZOOM::Options(); |
93 |
my $o = new ZOOM::Options(); |
90 |
$o->option(preferredRecordSyntax => 'xml'); |
94 |
$o->option(preferredRecordSyntax => 'xml'); |
91 |
$o->option(elementSetName => 'marcxml'); |
95 |
$o->option(elementSetName => 'marcxml'); |
Lines 94-100
subtest 'test_search' => sub {
Link Here
|
94 |
my $Zconn = ZOOM::Connection->create($o); |
98 |
my $Zconn = ZOOM::Connection->create($o); |
95 |
ok($Zconn, 'ZOOM connection created'); |
99 |
ok($Zconn, 'ZOOM connection created'); |
96 |
|
100 |
|
97 |
$Zconn->connect('127.0.0.1:42111', 0); |
101 |
$Zconn->connect('localhost:42111', 0); |
98 |
is($Zconn->errcode(), 0, 'Connection is successful: ' . $Zconn->errmsg()); |
102 |
is($Zconn->errcode(), 0, 'Connection is successful: ' . $Zconn->errmsg()); |
99 |
|
103 |
|
100 |
my $rs = $Zconn->search_pqf('@and @attr 1=1 @attr 4=1 author @or @attr 1=4 title(s) @attr 1=4 another'); |
104 |
my $rs = $Zconn->search_pqf('@and @attr 1=1 @attr 4=1 author @or @attr 1=4 title(s) @attr 1=4 another'); |
Lines 103-117
subtest 'test_search' => sub {
Link Here
|
103 |
is($rs->size(), 2, 'Two results returned'); |
107 |
is($rs->size(), 2, 'Two results returned'); |
104 |
|
108 |
|
105 |
my $returned1 = MARC::Record->new_from_xml($rs->record(0)->raw()); |
109 |
my $returned1 = MARC::Record->new_from_xml($rs->record(0)->raw()); |
106 |
ok ($returned1, 'Record 1 returned as MARCXML'); |
110 |
ok($returned1, 'Record 1 returned as MARCXML'); |
107 |
is($returned1->as_xml, $marc_record_1->as_xml, 'Record 1 returned properly'); |
111 |
is($returned1->as_xml, $marc_record_1->as_xml, 'Record 1 returned properly'); |
108 |
|
112 |
|
109 |
my $returned2= MARC::Record->new_from_xml($rs->record(1)->raw()); |
113 |
my $returned2= MARC::Record->new_from_xml($rs->record(1)->raw()); |
110 |
ok ($returned2, 'Record 2 returned as MARCXML'); |
114 |
ok($returned2, 'Record 2 returned as MARCXML'); |
111 |
is($returned2->as_xml, $marc_record_2->as_xml, 'Record 2 returned properly'); |
115 |
is($returned2->as_xml, $marc_record_2->as_xml, 'Record 2 returned properly'); |
112 |
|
116 |
|
113 |
is($rs->record(2), undef, 'Record 3 does not exist'); |
117 |
is($rs->record(2), undef, 'Record 3 does not exist'); |
114 |
|
118 |
|
|
|
119 |
# SRU protocol tests |
120 |
my $base = 'http://localhost:42111'; |
121 |
my $ns = 'http://docs.oasis-open.org/ns/search-ws/sruResponse'; |
122 |
my $marc_ns = 'http://www.loc.gov/MARC21/slim'; |
123 |
my $agent = Test::WWW::Mechanize->new( autocheck => 1 ); |
124 |
|
125 |
$agent->get_ok("$base", 'Retrieve explain response'); |
126 |
my $dom = XML::LibXML->load_xml(string => $agent->content()); |
127 |
my @nodes = $dom->getElementsByTagNameNS($ns, 'explainResponse'); |
128 |
is(scalar(@nodes), 1, 'explainResponse returned'); |
129 |
|
130 |
$agent->get_ok("$base/biblios?operation=searchRetrieve&recordSchema=marcxml&maximumRecords=10&query=", 'Try bad search query'); |
131 |
$dom = XML::LibXML->load_xml(string => $agent->content()); |
132 |
@nodes = $dom->getElementsByTagNameNS($ns, 'diagnostics'); |
133 |
is(scalar(@nodes), 1, 'diagnostics returned for bad query'); |
134 |
|
135 |
$agent->get_ok("$base/biblios?operation=searchRetrieve&recordSchema=marcxml&maximumRecords=10&query=(dc.author%3dauthor AND (dc.title%3d\"title(s)\" OR dc.title%3danother))", 'Retrieve search results'); |
136 |
$dom = XML::LibXML->load_xml(string => $agent->content()); |
137 |
@nodes = $dom->getElementsByTagNameNS($ns, 'searchRetrieveResponse'); |
138 |
is(scalar(@nodes), 1, 'searchRetrieveResponse returned'); |
139 |
my @records = $nodes[0]->getElementsByTagNameNS($marc_ns, 'record'); |
140 |
is(scalar(@records), 2, 'Two results returned'); |
141 |
|
142 |
$returned1 = MARC::Record->new_from_xml($records[0]->toString()); |
143 |
ok($returned1, 'Record 1 returned as MARCXML'); |
144 |
is($returned1->as_xml, $marc_record_1->as_xml, 'Record 1 returned properly'); |
145 |
|
146 |
$returned2= MARC::Record->new_from_xml($records[1]->toString()); |
147 |
ok($returned2, 'Record 2 returned as MARCXML'); |
148 |
is($returned2->as_xml, $marc_record_2->as_xml, 'Record 2 returned properly'); |
149 |
|
115 |
cleanup(); |
150 |
cleanup(); |
116 |
}; |
151 |
}; |
117 |
|
152 |
|
Lines 122-129
sub cleanup {
Link Here
|
122 |
} |
157 |
} |
123 |
} |
158 |
} |
124 |
|
159 |
|
125 |
# Fall back to make sure that the Zebra process |
160 |
# Fall back to make sure that the server process gets cleaned up |
126 |
# and files get cleaned up |
|
|
127 |
END { |
161 |
END { |
128 |
cleanup(); |
162 |
cleanup(); |
129 |
} |
163 |
} |