source: trunk/t/73_toggle_moderation.t @ 878

Last change on this file since 878 was 871, checked in by nick, 15 years ago

Get the right URL in the test

File size: 4.5 KB
Line 
1use strict;
2use Wiki::Toolkit::Setup::SQLite;
3use OpenGuides;
4use OpenGuides::Test;
5use Test::More tests => 12;
6
7eval { require DBD::SQLite; };
8my $have_sqlite = $@ ? 0 : 1;
9
10SKIP: {
11    skip "DBD::SQLite not installed - no database to test with", 12
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 3 different pages, one of which with two versions
31    $wiki->write_node( "Test Page", "foo", undef,
32                       { category => "Alpha", lat=>"" } )
33      or die "Couldn't write node";
34    $wiki->write_node( "Test Page 2", "foo2", undef,
35                       { category => "Alpha", lat=>"22.22" } )
36      or die "Couldn't write node";
37    $wiki->write_node( "Test Page 3", "foo33", undef,
38                       { category => "Alpha" } )
39      or die "Couldn't write node";
40    $wiki->write_node( "Category Foo", "foo", undef,
41                       { category => "Categories", lat=>"-8.77" } )
42      or die "Couldn't write category";
43    $wiki->write_node( "Locale Bar", "foo", undef,
44                       { category => "Locales", lat=>"8.22" } )
45      or die "Couldn't write locale";
46    my %data = $wiki->retrieve_node( "Locale Bar" );
47    $wiki->write_node( "Locale Bar", "foo version 2", $data{checksum},
48                       { category => "Locales", lat=>"8.88" } )
49      or die "Couldn't write locale for the 2nd time";
50
51
52    # First up, try with no password
53    my $output = $guide->set_node_moderation(
54                                id => "Test Page 3",
55                                moderation_flag => 0,
56                                return_output => 1
57    );
58    like($output, qr|Change moderation status|, "Confirm page");
59    like($output, qr|Confirm Moderation|, "Confirm page");
60
61
62    # Now, try with the wrong password
63    $output = $guide->set_node_moderation(
64                                id => "Test Page 3",
65                                moderation_flag => 0,
66                                password => "I_AM_WRONG",
67                                return_output => 1
68    );
69    like($output, qr|Incorrect Password|, "Wrong password");
70    like($output, qr|Incorrect password for page moderation|, "Wrong password");
71
72
73    # Check that "Test Page 3" doesn't have moderation set
74    my %node = $wiki->retrieve_node("Test Page 3");
75    is($node{'node_requires_moderation'}, 0, "Doesn't have moderation on by default");
76
77    # Set the moderation flag on it to off
78    $guide->set_node_moderation(
79                                id => "Test Page 3",
80                                moderation_flag => 0,
81                                password => $guide->config->admin_pass
82    );
83    %node = $wiki->retrieve_node("Test Page 3");
84    is($node{'node_requires_moderation'}, 0, "Doesn't have moderation set when called with 0");
85
86    # Set it to on
87    $guide->set_node_moderation(
88                                id => "Test Page 3",
89                                moderation_flag => 1,
90                                password => $guide->config->admin_pass
91    );
92    %node = $wiki->retrieve_node("Test Page 3");
93    is($node{'node_requires_moderation'}, 1, "Turned on properly");
94   
95    # Set it back to off
96    $guide->set_node_moderation(
97                                id => "Test Page 3",
98                                moderation_flag => 0,
99                                password => $guide->config->admin_pass
100    );
101    %node = $wiki->retrieve_node("Test Page 3");
102    is($node{'node_requires_moderation'}, 0, "Turned off properly");
103
104
105    # Test we were sent to the right place
106    $output = $guide->set_node_moderation(
107                                id => "Test Page 3",
108                                moderation_flag => 0,
109                                password => $guide->config->admin_pass,
110                                return_output => 1
111    );
112    like($output, qr|Location: http://example.com/wiki.cgi?action=admin;moderation=changed|, "Right location");
113    like($output, qr|Status: 302 Moved|, "Right status");
114}
Note: See TracBrowser for help on using the repository browser.