root/trunk/t/32_search_simple_metadata.t

Revision 956, 5.1 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.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1use strict;
2use Wiki::Toolkit::Setup::SQLite;
3use OpenGuides::Config;
4use OpenGuides::Search;
5use Test::More;
6
7eval { require DBD::SQLite; };
8
9if ( $@ ) {
10    my ($error) = $@ =~ /^(.*?)\n/;
11    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
12}
13
14plan tests => 10;
15
16# Clear out the database from any previous runs.
17unlink "t/node.db";
18unlink <t/indexes/*>;
19
20Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
21my $config = OpenGuides::Config->new(
22       vars => {
23                 dbtype             => "sqlite",
24                 dbname             => "t/node.db",
25                 indexing_directory => "t/indexes",
26                 script_name        => "wiki.cgi",
27                 script_url         => "http://example.com/",
28                 site_name          => "Test Site",
29                 template_path      => "./templates",
30               }
31);
32
33# Plucene is the recommended searcher now.
34eval { require Wiki::Toolkit::Search::Plucene; };
35if ( $@ ) { $config->use_plucene( 0 ) };
36
37my $search = OpenGuides::Search->new( config => $config );
38
39# Add some data.  We write it twice to avoid hitting the redirect.
40my $wiki = $search->{wiki}; # white boxiness
41$wiki->write_node( "Calthorpe Arms", "Serves beer.", undef,
42                   { category => "Pubs", locale => "Holborn" } );
43$wiki->write_node( "Penderel's Oak", "Serves beer.", undef,
44                   { category => "Pubs", locale => "Holborn" } );
45$wiki->write_node( "British Museum", "Huge museum, lots of artifacts.", undef,
46                   { category => ["Museums", "Major Attractions"]
47                   , locale => ["Holborn", "Bloomsbury"] } );
48
49# Check that a search on its category works.
50my %tt_vars = $search->run(
51                            return_tt_vars => 1,
52                            vars           => { search => "Pubs" },
53                          );
54my @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
55is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
56           "simple search looks in category" );
57
58%tt_vars = $search->run(
59                         return_tt_vars => 1,
60                         vars           => { search => "pubs" },
61                       );
62@found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
63is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
64           "...and is case-insensitive" );
65
66# Check that a search on its locale works.
67%tt_vars = $search->run(
68                         return_tt_vars => 1,
69                         vars           => { search => "Holborn" },
70                       );
71@found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
72is_deeply( \@found, [ "British Museum", "Calthorpe Arms", "Penderel's Oak" ],
73           "simple search looks in locale" );
74
75%tt_vars = $search->run(
76                         return_tt_vars => 1,
77                         vars           => { search => "holborn" },
78                       );
79@found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
80is_deeply( \@found, [ "British Museum", "Calthorpe Arms", "Penderel's Oak" ],
81           "...and is case-insensitive" );
82
83# Test AND search in various combinations.
84%tt_vars = $search->run(
85                         return_tt_vars => 1,
86                         vars           => { search => "Holborn Pubs" },
87                       );
88@found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
89is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
90           "AND search works between category and locale" );
91
92%tt_vars = $search->run(
93                         return_tt_vars => 1,
94                         vars         => { search => "Holborn Penderel" },
95                       );
96@found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
97is_deeply( \@found, [ "Penderel's Oak" ],
98           "AND search works between title and locale" );
99
100%tt_vars = $search->run(
101                         return_tt_vars => 1,
102                         vars           => { search => "Pubs Penderel" },
103                       );
104@found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
105is_deeply( \@found, [ "Penderel's Oak" ],
106           "AND search works between title and category" );
107
108%tt_vars = $search->run(
109                         return_tt_vars => 1,
110                         vars           => { search => "Holborn beer" },
111                       );
112@found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
113is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
114           "...and between body and locale" );
115
116%tt_vars = $search->run(
117                         return_tt_vars => 1,
118                         vars           => { search => "Pubs beer" },
119                       );
120@found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
121is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
122           "...and between body and category" );
123
124%tt_vars = $search->run(
125                         return_tt_vars => 1,
126                         vars           => { search => '"major attractions"' },
127                       );
128@found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
129is_deeply( \@found, [ "British Museum", ],
130           "Multi word category name" );
Note: See TracBrowser for help on using the browser.