root/tags/rel0_58/t/22_feed_recent_changes.t

Revision 903, 5.0 kB (checked in by nick, 2 years ago)

Pass the output encoding to the wiki toolkit feeds stuff

  • 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    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
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                     http_charset       => "UTF-7",
46                   }
47    );
48
49    # Basic sanity check first.
50    my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
51
52    my $feed = OpenGuides::Feed->new( wiki   => $wiki,
53                                      config => $config );
54    is( $feed->default_content_type($feed_type), $content_types{$feed_type}, "Return the right content type" );
55
56    my $feed_output = eval { $feed->make_feed(feed_type => $feed_type, feed_listing => 'recent_changes'); };
57    is( $@, "", "->make_feed for $feed_type doesn't croak" );
58
59    # Ensure that the feed actually contained rss/atom (a good guide
60    #  that we actually got the right feed)
61    like( $feed_output, "/$feed_type/i", "Does contain the feed type" );
62
63    # Check the XML
64    like( $feed_output, qr/<?xml version="1.0" encoding="UTF-7"/, "Right XML type and encoding" );
65
66    # Now write some data, first a minor edit then a non-minor one.
67    my $guide = OpenGuides->new( config => $config );
68       
69    # Set up CGI parameters ready for a node write.
70    # Most of these are in here to avoid uninitialised value warnings.
71    my $q = CGI->new;
72    $q->param( -name => "content", -value => "foo" );
73    $q->param( -name => "categories", -value => "" );
74    $q->param( -name => "locales", -value => "" );
75    $q->param( -name => "phone", -value => "" );
76    $q->param( -name => "fax", -value => "" );
77    $q->param( -name => "website", -value => "" );
78    $q->param( -name => "hours_text", -value => "" );
79    $q->param( -name => "address", -value => "" );
80    $q->param( -name => "postcode", -value => "" );
81    $q->param( -name => "map_link", -value => "" );
82    $q->param( -name => "os_x", -value => "" );
83    $q->param( -name => "os_y", -value => "" );
84    $q->param( -name => "username", -value => "bob" );
85    $q->param( -name => "comment", -value => "foo" );
86    $q->param( -name => "edit_type", -value => "Minor tidying" );
87    $ENV{REMOTE_ADDR} = "127.0.0.1";
88
89    my $output = $guide->commit_node(
90                                      return_output => 1,
91                                      id => "Wombats",
92                                      cgi_obj => $q,
93                                    );
94
95    $q->param( -name => "edit_type", -value => "Normal edit" );
96    $output = $guide->commit_node(
97                                   return_output => 1,
98                                   id => "Badgers",
99                                   cgi_obj => $q,
100                                 );
101
102    $q->param( -name => "username", -value => "Kake" );
103    $output = $guide->commit_node(
104                                   return_output => 1,
105                                   id => "Wombles",
106                                   cgi_obj => $q,
107                                 );
108
109    # Check that the writes went in.
110    ok( $wiki->node_exists( "Wombats" ), "Wombats written" );
111    ok( $wiki->node_exists( "Badgers" ), "Badgers written" );
112    ok( $wiki->node_exists( "Wombles" ), "Wombles written" );
113
114    # Check that the minor edits can be filtered out.
115    $output = $guide->display_feed(
116                                   feed_type          => $feed_type,
117                                   feed_listing       => "recent_changes",
118                                   items              => 5,
119                                   username           => "bob",
120                                   ignore_minor_edits => 1,
121                                   return_output      => 1,
122                                 );
123    unlike( $output, qr/Wombats/, "minor edits filtered out when required" );
124    like( $output, qr/Badgers/, "but normal edits still in" );
125
126    # Check that the username parameter is taken notice of.
127    unlike( $output, qr/Wombles/, "username parameter taken note of" );
128}
Note: See TracBrowser for help on using the browser.