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

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

Check to ensure the feed type turns up in the feed (should spot when we invert atom and rss, for example)

File size: 5.7 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 => 11 * 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                   }
45    );
46
47    # Basic sanity check first.
48    my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
49
50    my $feed = OpenGuides::Feed->new( wiki   => $wiki,
51                                      config => $config );
52
53    my $feed_output = eval { $feed->make_feed(feed_type => $feed_type, feed_listing => 'recent_changes'); };
54    is( $@, "", "->make_feed for $feed_type doesn't croak" );
55
56    # Ensure that the feed actually contained rss/atom (a good guide
57    #  that we actually got the right feed)
58    like( $feed_output, "/$feed_type/i", "Does contain the feed type" );
59
60
61    # Now write some data: 3 versions of one node, and 1 of another
62    my $guide = OpenGuides->new( config => $config );
63       
64    # Set up CGI parameters ready for a node write.
65    # Most of these are in here to avoid uninitialised value warnings.
66    my $q = CGI->new;
67    $q->param( -name => "content", -value => "foo" );
68    $q->param( -name => "categories", -value => "" );
69    $q->param( -name => "locales", -value => "" );
70    $q->param( -name => "phone", -value => "" );
71    $q->param( -name => "fax", -value => "" );
72    $q->param( -name => "website", -value => "" );
73    $q->param( -name => "hours_text", -value => "" );
74    $q->param( -name => "address", -value => "" );
75    $q->param( -name => "postcode", -value => "" );
76    $q->param( -name => "map_link", -value => "" );
77    $q->param( -name => "os_x", -value => "" );
78    $q->param( -name => "os_y", -value => "" );
79    $q->param( -name => "username", -value => "bob" );
80    $q->param( -name => "comment", -value => "foo" );
81    $q->param( -name => "edit_type", -value => "Minor tidying" );
82    $ENV{REMOTE_ADDR} = "127.0.0.1";
83
84    # First version of Wombats
85    my $output = $guide->commit_node(
86                                      return_output => 1,
87                                      id => "Wombats",
88                                      cgi_obj => $q,
89                                    );
90    my %node = $wiki->retrieve_node(name=>"Wombats");
91
92    # Now second and third
93    $q->param( -name => "edit_type", -value => "Normal edit" );
94    $q->param( -name => "checksum", -value => $node{"checksum"} );
95    $output = $guide->commit_node(
96                                      return_output => 1,
97                                      id => "Wombats",
98                                      cgi_obj => $q,
99                                    );
100
101    %node = $wiki->retrieve_node(name=>"Wombats");
102    $q->param( -name => "username", -value => "Kake" );
103    $q->param( -name => "checksum", -value => $node{"checksum"} );
104    $output = $guide->commit_node(
105                                      return_output => 1,
106                                      id => "Wombats",
107                                      cgi_obj => $q,
108                                    );
109
110    # Now a different node
111    $q->delete('checksum');
112    $output = $guide->commit_node(
113                                   return_output => 1,
114                                   id => "Badgers",
115                                   cgi_obj => $q,
116                                 );
117
118    # Check that the writes went in.
119    ok( $wiki->node_exists( "Wombats" ), "Wombats written" );
120    ok( $wiki->node_exists( "Badgers" ), "Badgers written" );
121    is( scalar $wiki->list_node_all_versions("Wombats"), 3, "3 Wombat versions");
122    is( scalar $wiki->list_node_all_versions("Badgers"), 1, "1 Badger version");
123
124    # Fetch for Badgers
125    $output = $guide->display_feed(
126                                   return_output      => 1,
127                                   feed_type          => $feed_type,
128                                   feed_listing       => "node_all_versions",
129                                   name               => "Badgers"
130                                 );
131    unlike( $output, qr/<title>Wombats/, "Was on Badgers, so no wombats" );
132    like( $output, qr/<title>Badgers/, "Badgers correctly found" );
133
134    # Now for Wombats
135    $output = $guide->display_feed(
136                                   return_output      => 1,
137                                   feed_type          => $feed_type,
138                                   feed_listing       => "node_all_versions",
139                                   name               => "Wombats"
140                                 );
141    unlike( $output, qr/<title>Badgers/, "Was on Wombats, so no badgers" );
142    like( $output, qr/<title>Wombats/, "Wombats correctly found" );
143
144    my @wombats = $output =~ /(<title>Wombats)/g;
145    is( scalar @wombats, 3, "All 3 wombat versions found" );
146}
Note: See TracBrowser for help on using the repository browser.