root/tags/rel0_59/t/40_search_as_feed.t

Revision 956, 1.9 kB (checked in by earle, 22 months ago)

Complete transition to using skip_all (remove old SKIP blocks).
More verbose reporting for error "require"ing DBD::SQLite.

Line 
1use strict;
2use Wiki::Toolkit::Setup::SQLite;
3use OpenGuides::Search;
4use OpenGuides::Test;
5use Test::More;
6
7eval { require DBD::SQLite; };
8if ( $@ ) {
9    my ($error) = $@ =~ /^(.*?)\n/;
10    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
11}
12
13plan tests => 7;
14
15# Clear out the database from any previous runs.
16unlink "t/node.db";
17unlink <t/indexes/*>;
18
19Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
20my $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.
25eval { require Wiki::Toolkit::Search::Plucene; };
26if ( $@ ) { $config->use_plucene( 0 ) };
27
28my $search = OpenGuides::Search->new( config => $config );
29isa_ok( $search, "OpenGuides::Search" );
30
31# Pop some test data in
32my $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
41my $output = $search->run(
42                         return_output => 1,
43                         vars => { search => "banana", format => "rss" },
44                       );
45
46like($output, qr/<rdf:RDF/, "Really was RSS");
47like($output, qr/<items>/, "Really was RSS");
48
49my @found = ($output =~ /(<rdf:li)/g);
50is( 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                      );
58like($output, qr/<feed/, "Really was Atom");
59like($output, qr/<entry>/, "Really was Atom");
60
61@found = ($output =~ /(<entry>)/g);
62is( scalar @found, 1, "found right entries in feed" );
Note: See TracBrowser for help on using the browser.