6 use Test::More tests => 35;
12 use_ok( 'WebPAC::Test' );
13 use_ok( 'WebPAC::Output::KinoSearch' );
16 my $path = "$abs_path/kino/";
18 ok(my $out = new WebPAC::Output::KinoSearch({
25 ok( $out->init, 'init' );
30 'search' => [ 'tko zna' ]
36 'search' => [ qw/a1 a2 s3 a4 a5/ ],
39 'search' => [ 'foo' ],
43 throws_ok { $out->add( ) } qr/need id/, 'add without params';
44 throws_ok { $out->add( 42 ) } qr/need ds/, 'add without ds';
46 ok( $out->add( 42, $ds ), 'add 42' );
48 my @strange = ( qw/èajðinica odma¹æivanje ¾abokreèina ¹uma/ );
50 ok( $out->add( 99, { foo => { search => [ @strange ] } } ), 'add 99' );
52 ok( $out->add( 100, { foo => { search => [ qw/foo bar baz/ ] } } ), 'add 100' );
54 ok( -e $out->path, "created $path" );
56 ok( my $index = $out->index, 'have index' );
58 diag $out->path," eq ",$path;
59 cmp_ok( $out->path, 'eq', $path, 'path' );
62 my ( $query_string, $expected_hits ) = @_;
64 my $total_hits = $index->search(
65 query => $query_string,
70 ok( $total_hits, "search '$query_string'" );
72 diag "Total hits: $total_hits\n" if $debug;
74 cmp_ok( $total_hits, '==', $expected_hits, 'total_hits' );
76 while ( my $hit = $index->fetch_hit_hashref ) {
78 ok( $hit->{foo} =~ m/èajðinica/, 'utf-8 conversion' );
79 diag dump($hit) if $debug;
84 test_search( 'foo', 2 );
86 test_search( $_, 1 ) foreach @strange;
88 ok( $out->finish, 'finish' );