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

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

Proper test for committing nodes. Tests for the nodes_all_versions feeds

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