source: trunk/t/32_search_simple_metadata.t @ 717

Last change on this file since 717 was 717, checked in by Earle Martin, 16 years ago

Sorry, I screwed up the last commit - tests pass now. This fixes bug #17.

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