root/tags/rel0_58/t/53_show_index.t

Revision 899, 5.1 kB (checked in by nick, 2 years ago)

Add in skips if no Helmert Transform provider is found

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
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    # They will need a Helmert Transform provider for this to work
100    $config->gmaps_api_key("yes I have one");
101    $config->geo_handler(1);
102    $config->force_wgs84(0);
103
104    my $has_helmert = 0;
105    eval {
106        use OpenGuides::Utils;
107        $has_helmert = OpenGuides::Utils->get_wgs84_coords(latitude=>1,longitude=>1,config=>$config);
108    };
109
110    SKIP: {
111        skip "No Helmert Transform provider installed, can't test geo stuff", 6
112          unless $has_helmert;
113
114        $output = eval {
115            $guide->show_index(
116                                return_output => 1,
117                                format        => "map",
118                              );
119        };
120        is( $@, "", "->show_index doesn't die when asked for map" );
121        like( $output, qr|Content-Type: text/html|,
122              "Map output gets content-type of text/html" );
123        like( $output, qr|new GMap|, "Really is google map" );
124        my @points = ($output =~ /point\d+ = (new GPoint\(.*?, .*?\))/g);
125        is( 1, scalar @points, "Right number of nodes included on map" );
126
127        # -1.259687,51.754813
128        like( $points[0], qr|51.75481|, "Has latitude");
129        like( $points[0], qr|-1.25968|, "Has longitude");
130    }
131}
Note: See TracBrowser for help on using the browser.