source: trunk/t/24_feed_node_listings.t @ 878

Last change on this file since 878 was 847, checked in by Dominic Hargreaves, 15 years ago

Minor warning fixes

File size: 6.5 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 => 17 * 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
125
126    # Grab a list of all the nodes
127    my @all_names = $wiki->list_all_nodes();
128    my @all_nodes;
129    foreach my $name (@all_names) {
130        my %node = $wiki->retrieve_node(name=>$name);
131        $node{name} = $name;
132        push @all_nodes,  \%node;
133    }
134
135    # Ask build_feed_for_nodes to make a feed of these
136    $output = $feed->build_feed_for_nodes($feed_type,@all_nodes);
137
138    like( $output, qr/<title>Wombats/, "Found wombats" );
139    like( $output, qr/<title>Badgers/, "Found badgers" );
140
141    # Check it had the extra metadata
142    if($feed_type eq "rss") {
143        like( $output, qr/<dc:date>/, "Found metadata" );
144        like( $output, qr/<modwiki:diff>/, "Found metadata" );
145        like( $output, qr/<modwiki:version>/, "Found metadata" );
146    } else {
147        like( $output, qr/<updated>/, "Found metadata" );
148        like( $output, qr/<summary>/, "Found metadata" );
149        like( $output, qr/<author>/, "Found metadata" );
150    }
151
152
153    # Grab a list of the different versions of Wombats
154    my @wombats = $wiki->list_node_all_versions("Wombats");
155
156    # Ask build_mini_feed_for_nodes to make a mini feed of these
157    $output = $feed->build_mini_feed_for_nodes($feed_type,@wombats);
158
159    like( $output, qr/<title>Wombats/, "Wombats had wombats" );
160    unlike( $output, qr/<title>Badgers/, "Wombats didn't have Badgers" );
161
162    @wombats = $output =~ /(<title>Wombats)/g;
163    is( scalar @wombats, 3, "All 3 wombat versions found" );
164
165    # Check it was really the mini version
166
167    if($feed_type eq "rss") {
168        like( $output, qr/<link>/, "Has link" );
169        unlike( $output, qr/<dc:contributor>/, "Really mini version" );
170        unlike( $output, qr/<modwiki:history>/, "Really mini version" );
171    } else {
172        like( $output, qr/<link href=/, "Has link" );
173        unlike( $output, qr/<summary>/, "Really mini version" );
174        unlike( $output, qr/<author>/, "Really mini version" );
175    }
176}
Note: See TracBrowser for help on using the repository browser.