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

Last change on this file since 956 was 956, checked in by Earle Martin, 15 years ago

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

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    my ($error) = $@ =~ /^(.*?)\n/;
12    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
13}
14
15eval { require Wiki::Toolkit::Search::Plucene; };
16if ( $@ ) {
17    plan skip_all => "Plucene not installed";
18}
19
20
21# Which feed types do we test?
22my @feed_types = qw( rss atom );
23plan tests => 14 * scalar @feed_types;
24
25
26foreach my $feed_type (@feed_types) {
27    # Clear out the database from any previous runs.
28    unlink "t/node.db";
29    unlink <t/indexes/*>;
30
31    Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
32    my $config = OpenGuides::Config->new(
33           vars => {
34                     dbtype             => "sqlite",
35                     dbname             => "t/node.db",
36                     indexing_directory => "t/indexes",
37                     script_name        => "wiki.cgi",
38                     script_url         => "http://example.com/",
39                     site_name          => "Test Site",
40                     template_path      => "./templates",
41                     home_name          => "Home",
42                     use_plucene        => 1,
43                     http_charset       => "UTF-8"
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
147    # Check the content type and charset
148    like( $output, qr/Content-Type: /, "Has content type" );
149    like( $output, qr/$feed_type/, "Which is the right one" );
150    like( $output, qr/charset=UTF-8/, "And a charset" );
151}
Note: See TracBrowser for help on using the repository browser.