root/tags/rel0_59/t/22_feed_recent_changes.t

Revision 956, 5.1 kB (checked in by earle, 22 months ago)

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

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
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 => 10 * scalar @feed_types;
24
25my %content_types = (rss=>'application/rdf+xml', atom=>'application/atom+xml');
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                     http_charset       => "UTF-7",
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    # Check the XML
63    like( $feed_output, qr/<?xml version="1.0" encoding="UTF-7"/, "Right XML type and encoding" );
64
65    # Now write some data, first a minor edit then a non-minor one.
66    my $guide = OpenGuides->new( config => $config );
67       
68    # Set up CGI parameters ready for a node write.
69    # Most of these are in here to avoid uninitialised value warnings.
70    my $q = CGI->new;
71    $q->param( -name => "content", -value => "foo" );
72    $q->param( -name => "categories", -value => "" );
73    $q->param( -name => "locales", -value => "" );
74    $q->param( -name => "phone", -value => "" );
75    $q->param( -name => "fax", -value => "" );
76    $q->param( -name => "website", -value => "" );
77    $q->param( -name => "hours_text", -value => "" );
78    $q->param( -name => "address", -value => "" );
79    $q->param( -name => "postcode", -value => "" );
80    $q->param( -name => "map_link", -value => "" );
81    $q->param( -name => "os_x", -value => "" );
82    $q->param( -name => "os_y", -value => "" );
83    $q->param( -name => "username", -value => "bob" );
84    $q->param( -name => "comment", -value => "foo" );
85    $q->param( -name => "edit_type", -value => "Minor tidying" );
86    $ENV{REMOTE_ADDR} = "127.0.0.1";
87
88    my $output = $guide->commit_node(
89                                      return_output => 1,
90                                      id => "Wombats",
91                                      cgi_obj => $q,
92                                    );
93
94    $q->param( -name => "edit_type", -value => "Normal edit" );
95    $output = $guide->commit_node(
96                                   return_output => 1,
97                                   id => "Badgers",
98                                   cgi_obj => $q,
99                                 );
100
101    $q->param( -name => "username", -value => "Kake" );
102    $output = $guide->commit_node(
103                                   return_output => 1,
104                                   id => "Wombles",
105                                   cgi_obj => $q,
106                                 );
107
108    # Check that the writes went in.
109    ok( $wiki->node_exists( "Wombats" ), "Wombats written" );
110    ok( $wiki->node_exists( "Badgers" ), "Badgers written" );
111    ok( $wiki->node_exists( "Wombles" ), "Wombles written" );
112
113    # Check that the minor edits can be filtered out.
114    $output = $guide->display_feed(
115                                   feed_type          => $feed_type,
116                                   feed_listing       => "recent_changes",
117                                   items              => 5,
118                                   username           => "bob",
119                                   ignore_minor_edits => 1,
120                                   return_output      => 1,
121                                 );
122    unlike( $output, qr/Wombats/, "minor edits filtered out when required" );
123    like( $output, qr/Badgers/, "but normal edits still in" );
124
125    # Check that the username parameter is taken notice of.
126    unlike( $output, qr/Wombles/, "username parameter taken note of" );
127}
Note: See TracBrowser for help on using the browser.