| 1 | use strict; |
|---|
| 2 | use Wiki::Toolkit::Setup::SQLite; |
|---|
| 3 | use OpenGuides; |
|---|
| 4 | use OpenGuides::Test; |
|---|
| 5 | use Test::More; |
|---|
| 6 | |
|---|
| 7 | eval { require DBD::SQLite; }; |
|---|
| 8 | |
|---|
| 9 | if ( $@ ) { |
|---|
| 10 | my ($error) = $@ =~ /^(.*?)\n/; |
|---|
| 11 | plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; |
|---|
| 12 | } |
|---|
| 13 | |
|---|
| 14 | plan tests => 23; # 25 when all enabled |
|---|
| 15 | |
|---|
| 16 | Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); |
|---|
| 17 | my $config = OpenGuides::Test->make_basic_config; |
|---|
| 18 | $config->script_name( "wiki.cgi" ); |
|---|
| 19 | $config->script_url( "http://example.com/" ); |
|---|
| 20 | my $guide = OpenGuides->new( config => $config ); |
|---|
| 21 | isa_ok( $guide, "OpenGuides" ); |
|---|
| 22 | my $wiki = $guide->wiki; |
|---|
| 23 | isa_ok( $wiki, "Wiki::Toolkit" ); |
|---|
| 24 | |
|---|
| 25 | # Clear out the database from any previous runs. |
|---|
| 26 | foreach my $del_node ( $wiki->list_all_nodes ) { |
|---|
| 27 | print "# Deleting node $del_node\n"; |
|---|
| 28 | $wiki->delete_node( $del_node ) or die "Can't delete $del_node"; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | $wiki->write_node( "Test Page", "foo", undef, |
|---|
| 32 | { category => "Alpha", latitude=>51.754349, longitude=>-1.258200 } ) |
|---|
| 33 | or die "Couldn't write node"; |
|---|
| 34 | $wiki->write_node( "Test Page 2", "foo", undef, |
|---|
| 35 | { category => "Alpha" } ) |
|---|
| 36 | or die "Couldn't write node"; |
|---|
| 37 | |
|---|
| 38 | # Test the normal, HTML version |
|---|
| 39 | my $output = eval { |
|---|
| 40 | $guide->show_index( |
|---|
| 41 | type => "category", |
|---|
| 42 | value => "Alpha", |
|---|
| 43 | return_output => 1, |
|---|
| 44 | ); |
|---|
| 45 | }; |
|---|
| 46 | is( $@, "", "->show_index doesn't die" ); |
|---|
| 47 | like( $output, qr|wiki.cgi\?Test_Page|, |
|---|
| 48 | "...and includes correct links" ); |
|---|
| 49 | unlike( $output, qr|<title>\s*-|, "...sets <title> correctly" ); |
|---|
| 50 | |
|---|
| 51 | # Test the RDF version |
|---|
| 52 | $output = $guide->show_index( |
|---|
| 53 | type => "category", |
|---|
| 54 | value => "Alpha", |
|---|
| 55 | return_output => 1, |
|---|
| 56 | format => "rdf" |
|---|
| 57 | ); |
|---|
| 58 | like( $output, qr|Content-Type: application/rdf\+xml|, |
|---|
| 59 | "RDF output gets content-type of application/rdf+xml" ); |
|---|
| 60 | like( $output, qr|<rdf:RDF|, "Really is rdf" ); |
|---|
| 61 | like( $output, qr|<dc:title>Category Alpha</dc:title>|, "Right rdf title" ); |
|---|
| 62 | my @entries = ($output =~ /(\<rdf\:li\>)/g); |
|---|
| 63 | is( 2, scalar @entries, "Right number of nodes included in rdf" ); |
|---|
| 64 | |
|---|
| 65 | # Test the RSS version |
|---|
| 66 | $output = eval { |
|---|
| 67 | $guide->show_index( |
|---|
| 68 | type => "category", |
|---|
| 69 | value => "Alpha", |
|---|
| 70 | return_output => 1, |
|---|
| 71 | format => "rss", |
|---|
| 72 | ); |
|---|
| 73 | }; |
|---|
| 74 | is( $@, "", "->show_index doesn't die when asked for rss" ); |
|---|
| 75 | like( $output, qr|Content-Type: application/rdf\+xml|, |
|---|
| 76 | "RSS output gets content-type of application/rdf+xml" ); |
|---|
| 77 | like( $output, "/\<rdf\:RDF.*?http\:\/\/purl.org\/rss\//s", "Really is rss" ); |
|---|
| 78 | #like( $output, qr|<title>Category Alpha</title>|, "Right rss title" ); |
|---|
| 79 | @entries = ($output =~ /(\<\/item\>)/g); |
|---|
| 80 | is( 2, scalar @entries, "Right number of nodes included in rss" ); |
|---|
| 81 | |
|---|
| 82 | # Test the Atom version |
|---|
| 83 | $output = eval { |
|---|
| 84 | $guide->show_index( |
|---|
| 85 | type => "category", |
|---|
| 86 | value => "Alpha", |
|---|
| 87 | return_output => 1, |
|---|
| 88 | format => "atom", |
|---|
| 89 | ); |
|---|
| 90 | }; |
|---|
| 91 | is( $@, "", "->show_index doesn't die when asked for atom" ); |
|---|
| 92 | like( $output, qr|Content-Type: application/atom\+xml|, |
|---|
| 93 | "Atom output gets content-type of application/atom+xml" ); |
|---|
| 94 | like( $output, qr|<feed|, "Really is atom" ); |
|---|
| 95 | #like( $output, qr|<title>Category Alpha</title>|, "Right atom title" ); |
|---|
| 96 | @entries = ($output =~ /(\<entry\>)/g); |
|---|
| 97 | is( 2, scalar @entries, "Right number of nodes included in atom" ); |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | # Test the map version |
|---|
| 101 | # They will need a Helmert Transform provider for this to work |
|---|
| 102 | $config->gmaps_api_key("yes I have one"); |
|---|
| 103 | $config->geo_handler(1); |
|---|
| 104 | $config->force_wgs84(0); |
|---|
| 105 | |
|---|
| 106 | my $has_helmert = 0; |
|---|
| 107 | eval { |
|---|
| 108 | use OpenGuides::Utils; |
|---|
| 109 | $has_helmert = OpenGuides::Utils->get_wgs84_coords(latitude=>1,longitude=>1,config=>$config); |
|---|
| 110 | }; |
|---|
| 111 | |
|---|
| 112 | SKIP: { |
|---|
| 113 | skip "No Helmert Transform provider installed, can't test geo stuff", 6 |
|---|
| 114 | unless $has_helmert; |
|---|
| 115 | |
|---|
| 116 | $output = eval { |
|---|
| 117 | $guide->show_index( |
|---|
| 118 | return_output => 1, |
|---|
| 119 | format => "map", |
|---|
| 120 | ); |
|---|
| 121 | }; |
|---|
| 122 | is( $@, "", "->show_index doesn't die when asked for map" ); |
|---|
| 123 | like( $output, qr|Content-Type: text/html|, |
|---|
| 124 | "Map output gets content-type of text/html" ); |
|---|
| 125 | like( $output, qr|new GMap|, "Really is google map" ); |
|---|
| 126 | my @points = ($output =~ /point\d+ = (new GPoint\(.*?, .*?\))/g); |
|---|
| 127 | is( 1, scalar @points, "Right number of nodes included on map" ); |
|---|
| 128 | |
|---|
| 129 | # -1.259687,51.754813 |
|---|
| 130 | like( $points[0], qr|51.75481|, "Has latitude"); |
|---|
| 131 | like( $points[0], qr|-1.25968|, "Has longitude"); |
|---|
| 132 | } |
|---|