root/tags/rel0_58/t/40_search_as_feed.t

Revision 818, 2.0 kB (checked in by nick, 3 years ago)

Support (+test) searching as a feed

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