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

Last change on this file since 814 was 814, checked in by nick, 16 years ago

Support RSS and Atom for category and locale indicies, + test for this

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1use strict;
2use Wiki::Toolkit::Setup::SQLite;
3use OpenGuides;
4use OpenGuides::Test;
5use Test::More tests => 17; # 19 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", 17
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" } )
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    my @entries = ($output =~ /(\<\/item\>)/g);
78    is( 2, scalar @entries, "Right number of nodes included in rss" );
79warn($output);
80
81    # Test the Atom version
82    $output = eval {
83        $guide->show_index(
84                            type          => "category",
85                            value         => "Alpha",
86                            return_output => 1,
87                            format        => "atom",
88                          );
89    };
90    is( $@, "", "->show_index doesn't die when asked for atom" );
91    like( $output, qr|Content-Type: application/atom\+xml|,
92          "Atom output gets content-type of application/atom+xml" );
93    like( $output, qr|<feed|, "Really is atom" );
94    #like( $output, qr|<title>Category Alpha</title>|, "Right atom title" );
95    my @entries = ($output =~ /(\<entry\>)/g);
96    is( 2, scalar @entries, "Right number of nodes included in atom" );
97}
Note: See TracBrowser for help on using the repository browser.