source: trunk/t/81_node_moderate_whitelist.t @ 1240

Last change on this file since 1240 was 1240, checked in by Dominic Hargreaves, 13 years ago

Add the ability to whitelist hosts who can change moderated nodes
without explicit moderation - thanks Oliver (fixes #203)

File size: 3.3 KB
Line 
1use strict;
2use Wiki::Toolkit::Setup::SQLite;
3use OpenGuides;
4use OpenGuides::Test;
5use Test::More;
6
7eval { require DBD::SQLite; };
8
9if ( $@ ) {
10    my ($error) = $@ =~ /^(.*?)\n/;
11    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
12}
13
14plan tests => 12;
15
16Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
17my $config = OpenGuides::Test->make_basic_config;
18$config->script_name( "wiki.cgi" );
19$config->script_url( "http://example.com/" );
20$config->moderate_whitelist( "127.0.0.1,127.0.0.2" );
21my $guide = OpenGuides->new( config => $config );
22isa_ok( $guide, "OpenGuides" );
23my $wiki = $guide->wiki;
24isa_ok( $wiki, "Wiki::Toolkit" );
25
26# Clear out the database from any previous runs.
27foreach my $del_node ( $wiki->list_all_nodes ) {
28    print "# Deleting node $del_node\n";
29    $wiki->delete_node( $del_node ) or die "Can't delete $del_node";
30}
31
32
33# Add a page
34my $q = CGI->new;
35$q->param( -name => "content", -value => "foo" );
36$q->param( -name => "categories", -value => "Alpha" );
37$q->param( -name => "locales", -value => "" );
38$q->param( -name => "phone", -value => "" );
39$q->param( -name => "fax", -value => "" );
40$q->param( -name => "website", -value => "" );
41$q->param( -name => "hours_text", -value => "" );
42$q->param( -name => "address", -value => "" );
43$q->param( -name => "postcode", -value => "" );
44$q->param( -name => "map_link", -value => "" );
45$q->param( -name => "os_x", -value => "" );
46$q->param( -name => "os_y", -value => "" );
47$q->param( -name => "username", -value => "bob" );
48$q->param( -name => "comment", -value => "foo" );
49$q->param( -name => "edit_type", -value => "Minor tidying" );
50$ENV{REMOTE_ADDR} = "127.0.0.1";
51
52my $output = $guide->commit_node(
53                                  return_output => 1,
54                                  id => "Wombats",
55                                  cgi_obj => $q,
56                                );
57
58# Check it's moderated
59my %details = $wiki->retrieve_node("Wombats");
60is($details{'moderated'}, 1, "Moderated");
61is($wiki->node_required_moderation("Wombats"), 0, "No moderation");
62
63# Turn on moderation
64$wiki->set_node_moderation(
65                            name => "Wombats",
66                            required => 1,
67);
68is($wiki->node_required_moderation("Wombats"), 1, "Moderation");
69
70
71# Now add a new one, with new categories and locales
72$q->param( -name => "categories", -value => "Alpha\r\nBeta" );
73$q->param( -name => "locales", -value => "Hello" );
74$q->param( -name => "edit_type", -value => "Normal edit" );
75$q->param( -name => "checksum", -value => $details{checksum} );
76$output = $guide->commit_node(
77                                  return_output => 1,
78                                  id => "Wombats",
79                                  cgi_obj => $q,
80                                );
81
82# Check that the current version is now 2
83%details = $wiki->retrieve_node("Wombats");
84is($details{'version'}, 2, "Still on v1");
85is($details{'moderated'}, 1, "v1 Moderated");
86
87# Check that version 2 is moderated
88my %v2 = $wiki->retrieve_node(name=>"Wombats",version=>2);
89is($v2{'version'}, 2, "Is v2");
90is($v2{'moderated'}, 1, "Moderated");
91
92# Check that the new categories and locales are there
93is(1, $wiki->node_exists("Category Alpha"), "Right Categories");
94is(1, $wiki->node_exists("Category Beta"), "Right Categories");
95is(1, $wiki->node_exists("Locale Hello"), "Right Locales");
96
Note: See TracBrowser for help on using the repository browser.