source: trunk/t/72_node_moderation.t @ 878

Last change on this file since 878 was 847, checked in by Dominic Hargreaves, 15 years ago

Minor warning fixes

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