source: trunk/t/53_show_index.t @ 878

Last change on this file since 878 was 872, checked in by nick, 15 years ago

Do the wgs84 convertion for the google maps page. Add tests for this too. References #89

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