| 1 | use strict; |
|---|
| 2 | use Wiki::Toolkit::Setup::SQLite; |
|---|
| 3 | use OpenGuides::Search; |
|---|
| 4 | use OpenGuides::Test; |
|---|
| 5 | use Test::More; |
|---|
| 6 | |
|---|
| 7 | eval { require DBD::SQLite; }; |
|---|
| 8 | if ( $@ ) { |
|---|
| 9 | my ($error) = $@ =~ /^(.*?)\n/; |
|---|
| 10 | plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | plan tests => 7; |
|---|
| 14 | |
|---|
| 15 | # Clear out the database from any previous runs. |
|---|
| 16 | unlink "t/node.db"; |
|---|
| 17 | unlink <t/indexes/*>; |
|---|
| 18 | |
|---|
| 19 | Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); |
|---|
| 20 | my $config = OpenGuides::Test->make_basic_config; |
|---|
| 21 | $config->script_name( "wiki.cgi" ); |
|---|
| 22 | $config->script_url( "http://example.com/" ); |
|---|
| 23 | |
|---|
| 24 | # Plucene is the recommended searcher now. |
|---|
| 25 | eval { require Wiki::Toolkit::Search::Plucene; }; |
|---|
| 26 | if ( $@ ) { $config->use_plucene( 0 ) }; |
|---|
| 27 | |
|---|
| 28 | my $search = OpenGuides::Search->new( config => $config ); |
|---|
| 29 | isa_ok( $search, "OpenGuides::Search" ); |
|---|
| 30 | |
|---|
| 31 | # Pop some test data in |
|---|
| 32 | my $wiki = $search->{wiki}; # white boxiness |
|---|
| 33 | $wiki->write_node( "Banana", "banana" ); |
|---|
| 34 | $wiki->write_node( "Monkey", "banana brains" ); |
|---|
| 35 | $wiki->write_node( "Monkey Brains", "BRANES" ); |
|---|
| 36 | $wiki->write_node( "Want Pie Now", "weebl" ); |
|---|
| 37 | $wiki->write_node( "Punctuation", "*" ); |
|---|
| 38 | $wiki->write_node( "Choice", "Eenie meenie minie mo"); |
|---|
| 39 | |
|---|
| 40 | # RSS search, should give 2 hits |
|---|
| 41 | my $output = $search->run( |
|---|
| 42 | return_output => 1, |
|---|
| 43 | vars => { search => "banana", format => "rss" }, |
|---|
| 44 | ); |
|---|
| 45 | |
|---|
| 46 | like($output, qr/<rdf:RDF/, "Really was RSS"); |
|---|
| 47 | like($output, qr/<items>/, "Really was RSS"); |
|---|
| 48 | |
|---|
| 49 | my @found = ($output =~ /(<rdf:li)/g); |
|---|
| 50 | is( scalar @found, 2, "found right entries in feed" ); |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | # Atom search, should give 1 hit |
|---|
| 54 | $output = $search->run( |
|---|
| 55 | return_output => 1, |
|---|
| 56 | vars => { search => "weebl", format => "atom" }, |
|---|
| 57 | ); |
|---|
| 58 | like($output, qr/<feed/, "Really was Atom"); |
|---|
| 59 | like($output, qr/<entry>/, "Really was Atom"); |
|---|
| 60 | |
|---|
| 61 | @found = ($output =~ /(<entry>)/g); |
|---|
| 62 | is( scalar @found, 1, "found right entries in feed" ); |
|---|