source: trunk/t/39_supersearch_form.t @ 559

Last change on this file since 559 was 559, checked in by kake, 17 years ago

Huge-ass pile of changes to make geo stuff work worldwide.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1use strict;
2use CGI::Wiki::Setup::SQLite;
3use Config::Tiny;
4use OpenGuides::SuperSearch;
5use Test::More;
6
7eval { require DBD::SQLite; };
8if ( $@ ) {
9    plan skip_all => "DBD::SQLite not installed";
10}
11
12eval { require Plucene; };
13if ( $@ ) {
14    plan skip_all => "Plucene not installed";
15}
16
17eval { require Test::HTML::Content; };
18if ( $@ ) {
19    plan skip_all => "Test::HTML::Content not installed";
20    exit 0;
21}
22
23# Strictly speaking we don't need to skip _all_ tests if we don't have
24# the modules below.  Revisit this when not in a hurry.
25# We only actually need the former for the National Grid tests and the
26# latter for the UTM tests.
27eval { require Geography::NationalGrid; };
28if ( $@ ) {
29    plan skip_all => "Geography::NationalGrid not installed";
30}
31
32eval { require Geo::Coordinates::UTM; };
33if ( $@ ) {
34    plan skip_all => "Geo::Coordinates::UTM not installed";
35}
36
37plan tests => 27;
38
39# Clear out the database from any previous runs.
40unlink "t/node.db";
41unlink <t/indexes/*>;
42
43CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
44my $config = Config::Tiny->new;
45$config->{_} = {
46                 dbtype             => "sqlite",
47                 dbname             => "t/node.db",
48                 indexing_directory => "t/indexes",
49                 script_name        => "wiki.cgi",
50                 script_url         => "http://example.com/",
51                 site_name          => "Test Site",
52                 home_name          => "Home",
53                 template_path      => "./templates",
54                 use_plucene        => 1,
55                 geo_handler        => 1,
56               };
57
58# British National Grid guides should have os and latlong search fields.
59my $search = OpenGuides::SuperSearch->new( config => $config );
60my $output = $search->run( return_output => 1 );
61# Strip Content-Type header to stop Test::HTML::Content getting confused.
62$output =~ s/^Content-Type.*[\r\n]+//m;
63
64Test::HTML::Content::tag_ok( $output, "input", { name => "os_dist" },
65                             "search page includes os_dist input with BNG" );
66Test::HTML::Content::tag_ok( $output, "input", { name => "os_x" },
67                             "...and os_x" );
68Test::HTML::Content::tag_ok( $output, "input", { name => "os_y" },
69                             "...and os_y" );
70Test::HTML::Content::tag_ok( $output, "input", { name => "latlong_dist" },
71                             "...and latlong_dist" );
72Test::HTML::Content::tag_ok( $output, "input", { name => "latitude" },
73                             "...and latitude" );
74Test::HTML::Content::tag_ok( $output, "input", { name => "longitude" },
75                             "...and longitude" );
76Test::HTML::Content::no_tag( $output, "input", { name => "osie_dist" },
77                             "...but not osie_dist" );
78Test::HTML::Content::no_tag( $output, "input", { name => "osie_x" },
79                             "...nor osie_x" );
80Test::HTML::Content::no_tag( $output, "input", { name => "osie_y" },
81                             "...nor osie_y" );
82
83# Irish National Grid guides should have osie and latlong.
84$config->{_}{geo_handler} = 2;
85$search = OpenGuides::SuperSearch->new( config => $config );
86$output = $search->run( return_output => 1 );
87$output =~ s/^Content-Type.*[\r\n]+//m;
88
89Test::HTML::Content::tag_ok( $output, "input", { name => "osie_dist" },
90                             "search page includes os_dist input with ING" );
91Test::HTML::Content::tag_ok( $output, "input", { name => "osie_x" },
92                             "...and osie_x" );
93Test::HTML::Content::tag_ok( $output, "input", { name => "osie_y" },
94                             "...and osie_y" );
95Test::HTML::Content::tag_ok( $output, "input", { name => "latlong_dist" },
96                             "...and latlong_dist" );
97Test::HTML::Content::tag_ok( $output, "input", { name => "latitude" },
98                             "...and latitude" );
99Test::HTML::Content::tag_ok( $output, "input", { name => "longitude" },
100                             "...and longitude" );
101Test::HTML::Content::no_tag( $output, "input", { name => "os_dist" },
102                             "...but not os_dist" );
103Test::HTML::Content::no_tag( $output, "input", { name => "os_x" },
104                             "...nor os_x" );
105Test::HTML::Content::no_tag( $output, "input", { name => "os_y" },
106                             "...nor os_y" );
107
108# UTM guides should have latitude/longitude/latlong_dist only.
109$config->{_}{geo_handler} = 3;
110$config->{_}{ellipsoid} = "Airy";
111$search = OpenGuides::SuperSearch->new( config => $config );
112$output = $search->run( return_output => 1 );
113$output =~ s/^Content-Type.*[\r\n]+//m;
114
115Test::HTML::Content::tag_ok( $output, "input", { name => "latlong_dist" },
116                             "includes latlong_dist with UTM" );
117Test::HTML::Content::tag_ok( $output, "input", { name => "latitude" },
118                             "...and latitude" );
119Test::HTML::Content::tag_ok( $output, "input", { name => "longitude" },
120                             "...and longitude" );
121Test::HTML::Content::no_tag( $output, "input", { name => "os_dist" },
122                             "...but not os_dist" );
123Test::HTML::Content::no_tag( $output, "input", { name => "os_x" },
124                             "...nor os_x" );
125Test::HTML::Content::no_tag( $output, "input", { name => "os_y" },
126                             "...nor os_y" );
127Test::HTML::Content::no_tag( $output, "input", { name => "osie_x" },
128                             "...but not osie_x" );
129Test::HTML::Content::no_tag( $output, "input", { name => "osie_y" },
130                             "...nor osie_y" );
131Test::HTML::Content::no_tag( $output, "input", { name => "osie_dist" },
132                             "...nor osie_dist" );
Note: See TracBrowser for help on using the repository browser.