| 1 | use strict; |
|---|
| 2 | use CGI::Wiki::Setup::SQLite; |
|---|
| 3 | use OpenGuides::SuperSearch; |
|---|
| 4 | use OpenGuides::Test; |
|---|
| 5 | use Test::More; |
|---|
| 6 | |
|---|
| 7 | eval { require DBD::SQLite; }; |
|---|
| 8 | if ( $@ ) { |
|---|
| 9 | plan skip_all => "DBD::SQLite not installed"; |
|---|
| 10 | } |
|---|
| 11 | |
|---|
| 12 | eval { require Plucene; }; |
|---|
| 13 | if ( $@ ) { |
|---|
| 14 | plan skip_all => "Plucene not installed"; |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | eval { require Test::HTML::Content; }; |
|---|
| 18 | if ( $@ ) { |
|---|
| 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. |
|---|
| 27 | eval { require Geography::NationalGrid; }; |
|---|
| 28 | if ( $@ ) { |
|---|
| 29 | plan skip_all => "Geography::NationalGrid not installed"; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | eval { require Geo::Coordinates::UTM; }; |
|---|
| 33 | if ( $@ ) { |
|---|
| 34 | plan skip_all => "Geo::Coordinates::UTM not installed"; |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | plan tests => 27; |
|---|
| 38 | |
|---|
| 39 | # Clear out the database from any previous runs. |
|---|
| 40 | unlink "t/node.db"; |
|---|
| 41 | unlink <t/indexes/*>; |
|---|
| 42 | |
|---|
| 43 | CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } ); |
|---|
| 44 | my $config = OpenGuides::Test->make_basic_config; |
|---|
| 45 | $config->use_plucene( 1 ); |
|---|
| 46 | |
|---|
| 47 | # British National Grid guides should have os and latlong search fields. |
|---|
| 48 | my $search = OpenGuides::SuperSearch->new( config => $config ); |
|---|
| 49 | my $output = $search->run( return_output => 1 ); |
|---|
| 50 | # Strip Content-Type header to stop Test::HTML::Content getting confused. |
|---|
| 51 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 52 | |
|---|
| 53 | Test::HTML::Content::tag_ok( $output, "input", { name => "os_dist" }, |
|---|
| 54 | "search page includes os_dist input with BNG" ); |
|---|
| 55 | Test::HTML::Content::tag_ok( $output, "input", { name => "os_x" }, |
|---|
| 56 | "...and os_x" ); |
|---|
| 57 | Test::HTML::Content::tag_ok( $output, "input", { name => "os_y" }, |
|---|
| 58 | "...and os_y" ); |
|---|
| 59 | Test::HTML::Content::tag_ok( $output, "input", { name => "latlong_dist" }, |
|---|
| 60 | "...and latlong_dist" ); |
|---|
| 61 | Test::HTML::Content::tag_ok( $output, "input", { name => "latitude" }, |
|---|
| 62 | "...and latitude" ); |
|---|
| 63 | Test::HTML::Content::tag_ok( $output, "input", { name => "longitude" }, |
|---|
| 64 | "...and longitude" ); |
|---|
| 65 | Test::HTML::Content::no_tag( $output, "input", { name => "osie_dist" }, |
|---|
| 66 | "...but not osie_dist" ); |
|---|
| 67 | Test::HTML::Content::no_tag( $output, "input", { name => "osie_x" }, |
|---|
| 68 | "...nor osie_x" ); |
|---|
| 69 | Test::HTML::Content::no_tag( $output, "input", { name => "osie_y" }, |
|---|
| 70 | "...nor osie_y" ); |
|---|
| 71 | |
|---|
| 72 | # Irish National Grid guides should have osie and latlong. |
|---|
| 73 | $config->geo_handler( 2 ); |
|---|
| 74 | $search = OpenGuides::SuperSearch->new( config => $config ); |
|---|
| 75 | $output = $search->run( return_output => 1 ); |
|---|
| 76 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 77 | |
|---|
| 78 | Test::HTML::Content::tag_ok( $output, "input", { name => "osie_dist" }, |
|---|
| 79 | "search page includes os_dist input with ING" ); |
|---|
| 80 | Test::HTML::Content::tag_ok( $output, "input", { name => "osie_x" }, |
|---|
| 81 | "...and osie_x" ); |
|---|
| 82 | Test::HTML::Content::tag_ok( $output, "input", { name => "osie_y" }, |
|---|
| 83 | "...and osie_y" ); |
|---|
| 84 | Test::HTML::Content::tag_ok( $output, "input", { name => "latlong_dist" }, |
|---|
| 85 | "...and latlong_dist" ); |
|---|
| 86 | Test::HTML::Content::tag_ok( $output, "input", { name => "latitude" }, |
|---|
| 87 | "...and latitude" ); |
|---|
| 88 | Test::HTML::Content::tag_ok( $output, "input", { name => "longitude" }, |
|---|
| 89 | "...and longitude" ); |
|---|
| 90 | Test::HTML::Content::no_tag( $output, "input", { name => "os_dist" }, |
|---|
| 91 | "...but not os_dist" ); |
|---|
| 92 | Test::HTML::Content::no_tag( $output, "input", { name => "os_x" }, |
|---|
| 93 | "...nor os_x" ); |
|---|
| 94 | Test::HTML::Content::no_tag( $output, "input", { name => "os_y" }, |
|---|
| 95 | "...nor os_y" ); |
|---|
| 96 | |
|---|
| 97 | # UTM guides should have latitude/longitude/latlong_dist only. |
|---|
| 98 | $config->geo_handler( 3 ); |
|---|
| 99 | $config->ellipsoid( "Airy" ); |
|---|
| 100 | $search = OpenGuides::SuperSearch->new( config => $config ); |
|---|
| 101 | $output = $search->run( return_output => 1 ); |
|---|
| 102 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 103 | |
|---|
| 104 | Test::HTML::Content::tag_ok( $output, "input", { name => "latlong_dist" }, |
|---|
| 105 | "includes latlong_dist with UTM" ); |
|---|
| 106 | Test::HTML::Content::tag_ok( $output, "input", { name => "latitude" }, |
|---|
| 107 | "...and latitude" ); |
|---|
| 108 | Test::HTML::Content::tag_ok( $output, "input", { name => "longitude" }, |
|---|
| 109 | "...and longitude" ); |
|---|
| 110 | Test::HTML::Content::no_tag( $output, "input", { name => "os_dist" }, |
|---|
| 111 | "...but not os_dist" ); |
|---|
| 112 | Test::HTML::Content::no_tag( $output, "input", { name => "os_x" }, |
|---|
| 113 | "...nor os_x" ); |
|---|
| 114 | Test::HTML::Content::no_tag( $output, "input", { name => "os_y" }, |
|---|
| 115 | "...nor os_y" ); |
|---|
| 116 | Test::HTML::Content::no_tag( $output, "input", { name => "osie_x" }, |
|---|
| 117 | "...but not osie_x" ); |
|---|
| 118 | Test::HTML::Content::no_tag( $output, "input", { name => "osie_y" }, |
|---|
| 119 | "...nor osie_y" ); |
|---|
| 120 | Test::HTML::Content::no_tag( $output, "input", { name => "osie_dist" }, |
|---|
| 121 | "...nor osie_dist" ); |
|---|