source: trunk/t/22_feed_recent_changes.t @ 817

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

Shift the content type method
Add mini feed method
Start to do urls, names etc for feeds properly
New tests

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 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 => 9 * scalar @feed_types;
25
26my %content_types = (rss=>'application/rdf+xml', atom=>'application/atom+xml');
27
28foreach my $feed_type (@feed_types) {
29    # Clear out the database from any previous runs.
30    unlink "t/node.db";
31    unlink <t/indexes/*>;
32
33    Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
34    my $config = OpenGuides::Config->new(
35           vars => {
36                     dbtype             => "sqlite",
37                     dbname             => "t/node.db",
38                     indexing_directory => "t/indexes",
39                     script_name        => "wiki.cgi",
40                     script_url         => "http://example.com/",
41                     site_name          => "Test Site",
42                     template_path      => "./templates",
43                     home_name          => "Home",
44                     use_plucene        => 1
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    is( $feed->default_content_type($feed_type), $content_types{$feed_type}, "Return the right content type" );
54
55    my $feed_output = eval { $feed->make_feed(feed_type => $feed_type, feed_listing => 'recent_changes'); };
56    is( $@, "", "->make_feed for $feed_type doesn't croak" );
57
58    # Ensure that the feed actually contained rss/atom (a good guide
59    #  that we actually got the right feed)
60    like( $feed_output, "/$feed_type/i", "Does contain the feed type" );
61
62    # Now write some data, first a minor edit then a non-minor one.
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    my $output = $guide->commit_node(
86                                      return_output => 1,
87                                      id => "Wombats",
88                                      cgi_obj => $q,
89                                    );
90
91    $q->param( -name => "edit_type", -value => "Normal edit" );
92    $output = $guide->commit_node(
93                                   return_output => 1,
94                                   id => "Badgers",
95                                   cgi_obj => $q,
96                                 );
97
98    $q->param( -name => "username", -value => "Kake" );
99    $output = $guide->commit_node(
100                                   return_output => 1,
101                                   id => "Wombles",
102                                   cgi_obj => $q,
103                                 );
104
105    # Check that the writes went in.
106    ok( $wiki->node_exists( "Wombats" ), "Wombats written" );
107    ok( $wiki->node_exists( "Badgers" ), "Badgers written" );
108    ok( $wiki->node_exists( "Wombles" ), "Wombles written" );
109
110    # Check that the minor edits can be filtered out.
111    $output = $guide->display_feed(
112                                   feed_type          => $feed_type,
113                                   feed_listing       => "recent_changes",
114                                   items              => 5,
115                                   username           => "bob",
116                                   ignore_minor_edits => 1,
117                                   return_output      => 1,
118                                 );
119    unlike( $output, qr/Wombats/, "minor edits filtered out when required" );
120    like( $output, qr/Badgers/, "but normal edits still in" );
121
122    # Check that the username parameter is taken notice of.
123    unlike( $output, qr/Wombles/, "username parameter taken note of" );
124}
Note: See TracBrowser for help on using the repository browser.