r1373@llin: dpavlin | 2007-10-30 21:11:01 +0100
[webpac2] / t / 5-output-kinosearch.t
diff --git a/t/5-output-kinosearch.t b/t/5-output-kinosearch.t
new file mode 100755 (executable)
index 0000000..03fb846
--- /dev/null
@@ -0,0 +1,73 @@
+#!/usr/bin/perl -w
+
+use Test::More tests => 14;
+use Test::Exception;
+use Cwd qw/abs_path/;
+use KinoSearch;
+use File::Slurp;
+use Data::Dump qw/dump/;
+use blib;
+use strict;
+
+BEGIN {
+use_ok( 'WebPAC::Output::KinoSearch' );
+}
+
+my $debug = shift @ARGV;
+
+ok(my $abs_path = abs_path($0), "abs_path");
+$abs_path =~ s#/[^/]*$#/#; #
+diag "abs_path: $abs_path";
+my $path = "$abs_path/kino/";
+
+ok(my $out = new WebPAC::Output::KinoSearch({
+       path => $path,
+       database => 'test',
+}), "new");
+
+ok( $out->init, 'init' );
+
+my $ds = {
+       'Source' => {
+               'name' => 'Izvor: ',
+               'search' => [ 'foo' ]
+       },
+       'ID' => {
+               'search' => 'id',
+       },
+       'Array' => {
+               'search' => [ qw/a1 a2 s3 a4 a5/ ],
+       },
+};
+
+throws_ok { $out->add( ) } qr/need id/, 'add without params';
+throws_ok { $out->add( 42 ) } qr/need ds/, 'add without ds';
+
+ok( $out->add( 42, $ds ), 'add 42' );
+
+ok( $out->add( 99, { foo => { search => 'bar' } } ), 'add 99' );
+
+ok( $out->add( 100, { foo => { search => [ qw/foo bar baz/ ] } } ), 'add 100' );
+
+ok( -e $out->path, "created $path" );
+
+ok( my $index = $out->index, 'have index' );
+
+diag $out->path," eq ",$path;
+cmp_ok( $out->path, 'eq', $path, 'path' );
+
+my $query_string = 'foo';
+
+my $total_hits = $index->search(
+       query      => $query_string,
+       offset     => 0,
+       num_wanted => 10,
+);
+                                                                                                                  
+diag "Total hits: $total_hits\n";
+while ( my $hit = $index->fetch_hit_hashref ) {
+       diag dump($hit);
+}
+
+ok( $out->finish, 'finish' );
+