| 1 | use strict; |
|---|
| 2 | use Wiki::Toolkit::Setup::SQLite; |
|---|
| 3 | use OpenGuides::Config; |
|---|
| 4 | use OpenGuides::Search; |
|---|
| 5 | use OpenGuides::Test; |
|---|
| 6 | use Test::More; |
|---|
| 7 | |
|---|
| 8 | eval { require DBD::SQLite; }; |
|---|
| 9 | if ( $@ ) { |
|---|
| 10 | plan skip_all => "DBD::SQLite not installed"; |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | eval { require Plucene; }; |
|---|
| 14 | if ( $@ ) { |
|---|
| 15 | plan skip_all => "Plucene not installed"; |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | plan tests => 9; |
|---|
| 19 | |
|---|
| 20 | # Clear out the database from any previous runs. |
|---|
| 21 | unlink "t/node.db"; |
|---|
| 22 | unlink <t/indexes/*>; |
|---|
| 23 | Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); |
|---|
| 24 | |
|---|
| 25 | my $config = OpenGuides::Test->make_basic_config; |
|---|
| 26 | $config->use_plucene( 1 ); |
|---|
| 27 | my $search = OpenGuides::Search->new( config => $config ); |
|---|
| 28 | my $guide = OpenGuides->new( config => $config ); |
|---|
| 29 | |
|---|
| 30 | # Test with OS co-ords. |
|---|
| 31 | eval { require Geography::NationalGrid::GB; }; |
|---|
| 32 | SKIP: { |
|---|
| 33 | skip "Geography::NationalGrid::GB not installed", 3 if $@; |
|---|
| 34 | $config->geo_handler( 1 ); |
|---|
| 35 | |
|---|
| 36 | foreach my $i ( 1 .. 30 ) { |
|---|
| 37 | OpenGuides::Test->write_data( |
|---|
| 38 | guide => $guide, |
|---|
| 39 | node => "Crabtree Tavern $i", |
|---|
| 40 | os_x => 523465, |
|---|
| 41 | os_y => 177490, |
|---|
| 42 | categories => "Pubs", |
|---|
| 43 | ); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | my $output = $search->run( |
|---|
| 47 | return_output => 1, |
|---|
| 48 | vars => { |
|---|
| 49 | os_dist => 1500, |
|---|
| 50 | os_x => 523500, |
|---|
| 51 | os_y => 177500, |
|---|
| 52 | }, |
|---|
| 53 | ); |
|---|
| 54 | like( $output, qr/search.cgi\?.*os_x=523500.*Next.*results/s, |
|---|
| 55 | "os_x retained in next page link" ); |
|---|
| 56 | like( $output, qr/search.cgi\?.*os_y=177500.*Next.*results/s, |
|---|
| 57 | "os_y retained in next page link" ); |
|---|
| 58 | like( $output, qr/search.cgi\?.*os_dist=1500.*Next.*results/s, |
|---|
| 59 | "os_dist retained in next page link" ); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | # Test with OSIE co-ords. |
|---|
| 63 | eval { require Geography::NationalGrid::IE; }; |
|---|
| 64 | SKIP: { |
|---|
| 65 | skip "Geography::NationalGrid::IE not installed", 3 if $@; |
|---|
| 66 | |
|---|
| 67 | # We must create a new search object after changing the geo_handler |
|---|
| 68 | # in order to force it to create a fresh locator. |
|---|
| 69 | $config->geo_handler( 2 ); |
|---|
| 70 | my $search = OpenGuides::Search->new( config => $config ); |
|---|
| 71 | |
|---|
| 72 | foreach my $i ( 1 .. 30 ) { |
|---|
| 73 | OpenGuides::Test->write_data( |
|---|
| 74 | guide => $guide, |
|---|
| 75 | node => "I Made This Place Up $i", |
|---|
| 76 | osie_x => 100005, |
|---|
| 77 | osie_y => 200005, |
|---|
| 78 | ); |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | my $output = $search->run( |
|---|
| 82 | return_output => 1, |
|---|
| 83 | vars => { |
|---|
| 84 | osie_dist => 1500, |
|---|
| 85 | osie_x => 100000, |
|---|
| 86 | osie_y => 200000, |
|---|
| 87 | }, |
|---|
| 88 | ); |
|---|
| 89 | like( $output, qr/search.cgi\?.*osie_x=100000.*Next.*results/s, |
|---|
| 90 | "osie_x retained in next page link" ); |
|---|
| 91 | like( $output, qr/search.cgi\?.*osie_y=200000.*Next.*results/s, |
|---|
| 92 | "osie_y retained in next page link" ); |
|---|
| 93 | like( $output, qr/search.cgi\?.*osie_dist=1500.*Next.*results/s, |
|---|
| 94 | "osie_dist retained in next page link" ); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | # Test with UTM. |
|---|
| 98 | eval { require Geo::Coordinates::UTM; }; |
|---|
| 99 | SKIP: { |
|---|
| 100 | skip "Geo::Coordinates::UTM not installed", 3 if $@; |
|---|
| 101 | |
|---|
| 102 | # We must create a new search object after changing the geo_handler |
|---|
| 103 | # in order to force it to create a fresh locator. |
|---|
| 104 | $config->geo_handler( 3 ); |
|---|
| 105 | my $search = OpenGuides::Search->new( config => $config ); |
|---|
| 106 | |
|---|
| 107 | foreach my $i ( 1 .. 30 ) { |
|---|
| 108 | OpenGuides::Test->write_data( |
|---|
| 109 | guide => $guide, |
|---|
| 110 | node => "London Aquarium $i", |
|---|
| 111 | latitude => 51.502, |
|---|
| 112 | longitude => -0.118, |
|---|
| 113 | ); |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | my $output = $search->run( |
|---|
| 117 | return_output => 1, |
|---|
| 118 | vars => { |
|---|
| 119 | latlong_dist => 1500, |
|---|
| 120 | latitude => 51.5, |
|---|
| 121 | longitude => -0.12, |
|---|
| 122 | }, |
|---|
| 123 | ); |
|---|
| 124 | like( $output, qr/search.cgi\?.*latitude=51.5.*Next.*results/s, |
|---|
| 125 | "latitude retained in next page link" ); |
|---|
| 126 | like( $output, qr/search.cgi\?.*longitude=-0.12.*Next.*results/s, |
|---|
| 127 | "longitude retained in next page link" ); |
|---|
| 128 | like( $output, qr/search.cgi\?.*latlong_dist=1500.*Next.*results/s, |
|---|
| 129 | "latlong_dist retained in next page link" ); |
|---|
| 130 | } |
|---|