| 1 | use strict; |
|---|
| 2 | use Wiki::Toolkit::Setup::SQLite; |
|---|
| 3 | use OpenGuides::Config; |
|---|
| 4 | use OpenGuides; |
|---|
| 5 | use OpenGuides::Feed; |
|---|
| 6 | use OpenGuides::Utils; |
|---|
| 7 | use Test::More; |
|---|
| 8 | |
|---|
| 9 | eval { require DBD::SQLite; }; |
|---|
| 10 | if ( $@ ) { |
|---|
| 11 | plan skip_all => "DBD::SQLite not installed"; |
|---|
| 12 | exit 0; |
|---|
| 13 | } |
|---|
| 14 | |
|---|
| 15 | eval { require Wiki::Toolkit::Search::Plucene; }; |
|---|
| 16 | if ( $@ ) { |
|---|
| 17 | plan skip_all => "Plucene not installed"; |
|---|
| 18 | exit 0; |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | # Which feed types do we test? |
|---|
| 23 | my @feed_types = qw( rss atom ); |
|---|
| 24 | plan tests => 8 * scalar @feed_types; |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | foreach 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 $feed_output = eval { $feed->make_feed(feed_type => $feed_type, feed_listing => 'recent_changes'); }; |
|---|
| 54 | is( $@, "", "->make_feed for $feed_type doesn't croak" ); |
|---|
| 55 | |
|---|
| 56 | # Ensure that the feed actually contained rss/atom (a good guide |
|---|
| 57 | # that we actually got the right feed) |
|---|
| 58 | like( $feed_output, "/$feed_type/i", "Does contain the feed type" ); |
|---|
| 59 | |
|---|
| 60 | # Now write some data, first a minor edit then a non-minor one. |
|---|
| 61 | my $guide = OpenGuides->new( config => $config ); |
|---|
| 62 | |
|---|
| 63 | # Set up CGI parameters ready for a node write. |
|---|
| 64 | # Most of these are in here to avoid uninitialised value warnings. |
|---|
| 65 | my $q = CGI->new; |
|---|
| 66 | $q->param( -name => "content", -value => "foo" ); |
|---|
| 67 | $q->param( -name => "categories", -value => "" ); |
|---|
| 68 | $q->param( -name => "locales", -value => "" ); |
|---|
| 69 | $q->param( -name => "phone", -value => "" ); |
|---|
| 70 | $q->param( -name => "fax", -value => "" ); |
|---|
| 71 | $q->param( -name => "website", -value => "" ); |
|---|
| 72 | $q->param( -name => "hours_text", -value => "" ); |
|---|
| 73 | $q->param( -name => "address", -value => "" ); |
|---|
| 74 | $q->param( -name => "postcode", -value => "" ); |
|---|
| 75 | $q->param( -name => "map_link", -value => "" ); |
|---|
| 76 | $q->param( -name => "os_x", -value => "" ); |
|---|
| 77 | $q->param( -name => "os_y", -value => "" ); |
|---|
| 78 | $q->param( -name => "username", -value => "bob" ); |
|---|
| 79 | $q->param( -name => "comment", -value => "foo" ); |
|---|
| 80 | $q->param( -name => "edit_type", -value => "Minor tidying" ); |
|---|
| 81 | $ENV{REMOTE_ADDR} = "127.0.0.1"; |
|---|
| 82 | |
|---|
| 83 | my $output = $guide->commit_node( |
|---|
| 84 | return_output => 1, |
|---|
| 85 | id => "Wombats", |
|---|
| 86 | cgi_obj => $q, |
|---|
| 87 | ); |
|---|
| 88 | |
|---|
| 89 | $q->param( -name => "edit_type", -value => "Normal edit" ); |
|---|
| 90 | $output = $guide->commit_node( |
|---|
| 91 | return_output => 1, |
|---|
| 92 | id => "Badgers", |
|---|
| 93 | cgi_obj => $q, |
|---|
| 94 | ); |
|---|
| 95 | |
|---|
| 96 | $q->param( -name => "username", -value => "Kake" ); |
|---|
| 97 | $output = $guide->commit_node( |
|---|
| 98 | return_output => 1, |
|---|
| 99 | id => "Wombles", |
|---|
| 100 | cgi_obj => $q, |
|---|
| 101 | ); |
|---|
| 102 | |
|---|
| 103 | # Check that the writes went in. |
|---|
| 104 | ok( $wiki->node_exists( "Wombats" ), "Wombats written" ); |
|---|
| 105 | ok( $wiki->node_exists( "Badgers" ), "Badgers written" ); |
|---|
| 106 | ok( $wiki->node_exists( "Wombles" ), "Wombles written" ); |
|---|
| 107 | |
|---|
| 108 | # Check that the minor edits can be filtered out. |
|---|
| 109 | $output = $guide->display_feed( |
|---|
| 110 | feed_type => $feed_type, |
|---|
| 111 | feed_listing => "recent_changes", |
|---|
| 112 | items => 5, |
|---|
| 113 | username => "bob", |
|---|
| 114 | ignore_minor_edits => 1, |
|---|
| 115 | return_output => 1, |
|---|
| 116 | ); |
|---|
| 117 | unlike( $output, qr/Wombats/, "minor edits filtered out when required" ); |
|---|
| 118 | like( $output, qr/Badgers/, "but normal edits still in" ); |
|---|
| 119 | |
|---|
| 120 | # Check that the username parameter is taken notice of. |
|---|
| 121 | unlike( $output, qr/Wombles/, "username parameter taken note of" ); |
|---|
| 122 | } |
|---|