root/tags/rel0_59/t/53_show_index.t

Revision 956, 4.7 kB (checked in by earle, 22 months ago)

Complete transition to using skip_all (remove old SKIP blocks).
More verbose reporting for error "require"ing DBD::SQLite.

  • 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;
6
7eval { require DBD::SQLite; };
8
9if ( $@ ) {
10    my ($error) = $@ =~ /^(.*?)\n/;
11    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
12}
13
14plan tests => 23; # 25 when all enabled
15
16Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
17my $config = OpenGuides::Test->make_basic_config;
18$config->script_name( "wiki.cgi" );
19$config->script_url( "http://example.com/" );
20my $guide = OpenGuides->new( config => $config );
21isa_ok( $guide, "OpenGuides" );
22my $wiki = $guide->wiki;
23isa_ok( $wiki, "Wiki::Toolkit" );
24
25# Clear out the database from any previous runs.
26foreach 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
39my $output = eval {
40    $guide->show_index(
41                        type          => "category",
42                        value         => "Alpha",
43                        return_output => 1,
44                      );
45};
46is( $@, "", "->show_index doesn't die" );
47like( $output, qr|wiki.cgi\?Test_Page|,
48      "...and includes correct links" );
49unlike( $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                            );
58like( $output, qr|Content-Type: application/rdf\+xml|,
59      "RDF output gets content-type of application/rdf+xml" );
60like( $output, qr|<rdf:RDF|, "Really is rdf" );
61like( $output, qr|<dc:title>Category Alpha</dc:title>|, "Right rdf title" );
62my @entries = ($output =~ /(\<rdf\:li\>)/g);
63is( 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};
74is( $@, "", "->show_index doesn't die when asked for rss" );
75like( $output, qr|Content-Type: application/rdf\+xml|,
76      "RSS output gets content-type of application/rdf+xml" );
77like( $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);
80is( 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};
91is( $@, "", "->show_index doesn't die when asked for atom" );
92like( $output, qr|Content-Type: application/atom\+xml|,
93      "Atom output gets content-type of application/atom+xml" );
94like( $output, qr|<feed|, "Really is atom" );
95#like( $output, qr|<title>Category Alpha</title>|, "Right atom title" );
96@entries = ($output =~ /(\<entry\>)/g);
97is( 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
106my $has_helmert = 0;
107eval {
108    use OpenGuides::Utils;
109    $has_helmert = OpenGuides::Utils->get_wgs84_coords(latitude=>1,longitude=>1,config=>$config);
110};
111
112SKIP: {
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}
Note: See TracBrowser for help on using the browser.