root/trunk/t/22_feed_recent_changes.t

Revision 1026, 4.5 kB (checked in by kake, 19 months ago)

Fixed bug in OpenGuides::Feed - HTML equivalent link now works even if your script_name isn't blank.

  • 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::Test;
7use OpenGuides::Utils;
8use Test::More;
9
10eval { require DBD::SQLite; };
11if ( $@ ) {
12    my ($error) = $@ =~ /^(.*?)\n/;
13    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
14}
15
16eval { require Wiki::Toolkit::Search::Plucene; };
17if ( $@ ) {
18    plan skip_all => "Plucene not installed";
19}
20
21
22# Which feed types do we test?
23my @feed_types = qw( rss atom );
24plan tests => 12 * 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::Test->make_basic_config;
35    $config->script_name( "wiki.cgi" );
36    $config->script_url( "http://example.com/" );
37    $config->http_charset( "UTF-7" );
38
39    # Basic sanity check first.
40    my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
41
42    my $feed = OpenGuides::Feed->new( wiki   => $wiki,
43                                      config => $config );
44    is( $feed->default_content_type($feed_type), $content_types{$feed_type}, "Return the right content type" );
45
46    like( $feed->html_equiv_link, qr|http://example.com/wiki.cgi\?|,
47          "html_equiv_link looks right" );
48
49    my $feed_output = eval { $feed->make_feed(feed_type => $feed_type, feed_listing => 'recent_changes'); };
50    is( $@, "", "->make_feed for $feed_type doesn't croak" );
51
52    # Ensure that the feed actually contained rss/atom (a good guide
53    #  that we actually got the right feed)
54    like( $feed_output, "/$feed_type/i", "Does contain the feed type" );
55
56    # Check the XML
57    like( $feed_output, qr/<?xml version="1.0" encoding="UTF-7"/, "Right XML type and encoding" );
58
59    # Now write some data, first a minor edit then a non-minor one.
60    my $guide = OpenGuides->new( config => $config );
61
62    OpenGuides::Test->write_data(
63                                  node          => "Wombats",
64                                  guide         => $guide,
65                                  username      => "bob",
66                                  edit_type     => "Minor tidying",
67                                  return_output => 1,
68                                );
69    OpenGuides::Test->write_data(
70                                  node          => "Badgers",
71                                  guide         => $guide,
72                                  username      => "bob",
73                                  edit_type     => "Normal edit",
74                                  return_output => 1,
75                                );
76    OpenGuides::Test->write_data(
77                                  node          => "Wombles",
78                                  guide         => $guide,
79                                  username      => "Kake",
80                                  edit_type     => "Normal edit",
81                                  return_output => 1,
82                                );
83
84    # Check that the writes went in.
85    ok( $wiki->node_exists( "Wombats" ), "Wombats written" );
86    ok( $wiki->node_exists( "Badgers" ), "Badgers written" );
87    ok( $wiki->node_exists( "Wombles" ), "Wombles written" );
88
89    # Check that the minor edits can be filtered out.
90    my $output = $guide->display_feed(
91                                       feed_type          => $feed_type,
92                                       feed_listing       => "recent_changes",
93                                       items              => 5,
94                                       username           => "bob",
95                                       ignore_minor_edits => 1,
96                                       return_output      => 1,
97                                     );
98    unlike( $output, qr/Wombats/, "minor edits filtered out when required" );
99    like( $output, qr/Badgers/, "but normal edits still in" );
100
101    # Check that the username parameter is taken notice of.
102    unlike( $output, qr/Wombles/, "username parameter taken note of" );
103
104    # Now make sure that the HTTP euiv link still works with a blank scriptname
105    $config->script_name( "" );
106    $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
107
108    $feed = OpenGuides::Feed->new( wiki   => $wiki,
109                                   config => $config );
110    like( $feed->html_equiv_link, qr|http://example.com/\?|,
111          "html_equiv_link looks right with blank script_name" );
112}
Note: See TracBrowser for help on using the browser.