source: trunk/t/23_feed_node_all_versions.t @ 898

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

Include the charset in the feeds, as we do with the pages

File size: 6.0 KB
Line 
1use strict;
2use Wiki::Toolkit::Setup::SQLite;
3use OpenGuides::Config;
4use OpenGuides;
5use OpenGuides::Feed;
6use OpenGuides::Utils;
7use Test::More;
8
9eval { require DBD::SQLite; };
10if ( $@ ) {
11    plan skip_all => "DBD::SQLite not installed";
12    exit 0;
13}
14
15eval { require Wiki::Toolkit::Search::Plucene; };
16if ( $@ ) {
17    plan skip_all => "Plucene not installed";
18    exit 0;
19}
20
21
22# Which feed types do we test?
23my @feed_types = qw( rss atom );
24plan tests => 14 * scalar @feed_types;
25
26
27foreach my $feed_type (@feed_types) {
28    # Clear out the database from any previous runs.
29    unlink "t/node.db";
30    unlink <t/indexes/*>;
31
32    Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
33    my $config = OpenGuides::Config->new(
34           vars => {
35                     dbtype             => "sqlite",
36                     dbname             => "t/node.db",
37                     indexing_directory => "t/indexes",
38                     script_name        => "wiki.cgi",
39                     script_url         => "http://example.com/",
40                     site_name          => "Test Site",
41                     template_path      => "./templates",
42                     home_name          => "Home",
43                     use_plucene        => 1,
44                     http_charset       => "UTF-8"
45                   }
46    );
47
48    # Basic sanity check first.
49    my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
50
51    my $feed = OpenGuides::Feed->new( wiki   => $wiki,
52                                      config => $config );
53
54    my $feed_output = eval { $feed->make_feed(feed_type => $feed_type, feed_listing => 'recent_changes'); };
55    is( $@, "", "->make_feed for $feed_type doesn't croak" );
56
57    # Ensure that the feed actually contained rss/atom (a good guide
58    #  that we actually got the right feed)
59    like( $feed_output, "/$feed_type/i", "Does contain the feed type" );
60
61
62    # Now write some data: 3 versions of one node, and 1 of another
63    my $guide = OpenGuides->new( config => $config );
64       
65    # Set up CGI parameters ready for a node write.
66    # Most of these are in here to avoid uninitialised value warnings.
67    my $q = CGI->new;
68    $q->param( -name => "content", -value => "foo" );
69    $q->param( -name => "categories", -value => "" );
70    $q->param( -name => "locales", -value => "" );
71    $q->param( -name => "phone", -value => "" );
72    $q->param( -name => "fax", -value => "" );
73    $q->param( -name => "website", -value => "" );
74    $q->param( -name => "hours_text", -value => "" );
75    $q->param( -name => "address", -value => "" );
76    $q->param( -name => "postcode", -value => "" );
77    $q->param( -name => "map_link", -value => "" );
78    $q->param( -name => "os_x", -value => "" );
79    $q->param( -name => "os_y", -value => "" );
80    $q->param( -name => "username", -value => "bob" );
81    $q->param( -name => "comment", -value => "foo" );
82    $q->param( -name => "edit_type", -value => "Minor tidying" );
83    $ENV{REMOTE_ADDR} = "127.0.0.1";
84
85    # First version of Wombats
86    my $output = $guide->commit_node(
87                                      return_output => 1,
88                                      id => "Wombats",
89                                      cgi_obj => $q,
90                                    );
91    my %node = $wiki->retrieve_node(name=>"Wombats");
92
93    # Now second and third
94    $q->param( -name => "edit_type", -value => "Normal edit" );
95    $q->param( -name => "checksum", -value => $node{"checksum"} );
96    $output = $guide->commit_node(
97                                      return_output => 1,
98                                      id => "Wombats",
99                                      cgi_obj => $q,
100                                    );
101
102    %node = $wiki->retrieve_node(name=>"Wombats");
103    $q->param( -name => "username", -value => "Kake" );
104    $q->param( -name => "checksum", -value => $node{"checksum"} );
105    $output = $guide->commit_node(
106                                      return_output => 1,
107                                      id => "Wombats",
108                                      cgi_obj => $q,
109                                    );
110
111    # Now a different node
112    $q->delete('checksum');
113    $output = $guide->commit_node(
114                                   return_output => 1,
115                                   id => "Badgers",
116                                   cgi_obj => $q,
117                                 );
118
119    # Check that the writes went in.
120    ok( $wiki->node_exists( "Wombats" ), "Wombats written" );
121    ok( $wiki->node_exists( "Badgers" ), "Badgers written" );
122    is( scalar $wiki->list_node_all_versions("Wombats"), 3, "3 Wombat versions");
123    is( scalar $wiki->list_node_all_versions("Badgers"), 1, "1 Badger version");
124
125    # Fetch for Badgers
126    $output = $guide->display_feed(
127                                   return_output      => 1,
128                                   feed_type          => $feed_type,
129                                   feed_listing       => "node_all_versions",
130                                   name               => "Badgers"
131                                 );
132    unlike( $output, qr/<title>Wombats/, "Was on Badgers, so no wombats" );
133    like( $output, qr/<title>Badgers/, "Badgers correctly found" );
134
135    # Now for Wombats
136    $output = $guide->display_feed(
137                                   return_output      => 1,
138                                   feed_type          => $feed_type,
139                                   feed_listing       => "node_all_versions",
140                                   name               => "Wombats"
141                                 );
142    unlike( $output, qr/<title>Badgers/, "Was on Wombats, so no badgers" );
143    like( $output, qr/<title>Wombats/, "Wombats correctly found" );
144
145    my @wombats = $output =~ /(<title>Wombats)/g;
146    is( scalar @wombats, 3, "All 3 wombat versions found" );
147
148    # Check the content type and charset
149    like( $output, qr/Content-Type: /, "Has content type" );
150    like( $output, qr/$feed_type/, "Which is the right one" );
151    like( $output, qr/charset=UTF-8/, "And a charset" );
152}
Note: See TracBrowser for help on using the repository browser.