root/branches/new-install-process/t/30_search_raw.t

Revision 1024, 3.4 kB (checked in by kake, 21 months ago)

Fix to [1023] - I misunderstood how the format parameter should be supplied.

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 => 16;
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;
21my $guide = OpenGuides->new( config => $config );
22my $search = OpenGuides::Search->new( config => $config );
23
24my %results;
25
26%results = $search->run( vars => { format => "raw" } );
27is_deeply( \%results, { },
28           "raw search returns empty hash if no criteria supplied" );
29%results = $search->run( vars => { search => "banananana", format => "raw" } );
30is_deeply( \%results, { },
31           "raw search returns empty hash if no hits on search string" );
32
33# Pop some data in and search again.
34OpenGuides::Test->write_data( guide => $guide,
35                              node  => "Red Lion",
36                              content => "A nice pub in Anyville.",
37                              summary => "Nice pub.",
38                              os_x => 500000,
39                              os_y => 150000,
40                            );
41OpenGuides::Test->write_data( guide => $guide,
42                              node  => "Blacksmiths Arms",
43                              content => "Not a very nice pub.",
44                              summary => "Rubbish pub.",
45                              os_x => 500100,
46                              os_y => 150000,
47                            );
48OpenGuides::Test->write_data( guide => $guide,
49                              node  => "Carpenters Arms",
50                              content => "Not a bad pub.",
51                              summary => "Average pub.",
52                              os_x => 450000,
53                              os_y => 140000,
54                            );
55
56%results = $search->run( vars => { search => "arms", format => "raw" } );
57is_deeply( [ sort keys %results ], [ "Blacksmiths Arms", "Carpenters Arms" ],
58           "raw search on single word finds the right nodes" );
59my %ba = %{$results{"Blacksmiths Arms"}};
60is( $ba{name}, "Blacksmiths Arms", "result hash has correct name" );
61is( $ba{summary}, "Rubbish pub.", "...and correct summary" );
62ok( $ba{wgs84_long}, "...WGS-84 latitude returned" );
63ok( $ba{wgs84_lat}, "...WGS-84 longitude returned" );
64ok( $ba{score}, "...score returned" );
65ok( !$ba{distance}, "...no distance returned" );
66
67# Now try a distance search.
68%results = $search->run(
69                         vars => {
70                                   os_dist => 1000,
71                                   os_x    => 500200,
72                                   os_y    => 150000,
73                                   format  => "raw",
74                                 } );
75is_deeply( [ sort keys %results ], [ "Blacksmiths Arms", "Red Lion" ],
76           "raw distance search finds the right nodes" );
77my %rl = %{$results{"Red Lion"}};
78is( $rl{name}, "Red Lion", "result hash has correct name" );
79is( $rl{summary}, "Nice pub.", "...and correct summary" );
80ok( $rl{wgs84_lat}, "...WGS-84 latitude returned" );
81ok( $rl{wgs84_long}, "...WGS-84 longitude returned" );
82ok( !$rl{score}, "...no score returned" );
83is( $rl{distance}, 200, "...correct distance returned" );
Note: See TracBrowser for help on using the browser.