root/tags/rel0_59/t/73_toggle_moderation.t

Revision 956, 4.6 kB (checked in by earle, 22 months ago)

Complete transition to using skip_all (remove old SKIP blocks).
More verbose reporting for error "require"ing DBD::SQLite.

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 => 14;
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/" );
20my $guide = OpenGuides->new( config => $config );
21isa_ok( $guide, "OpenGuides" );
22my $wiki = $guide->wiki;
23isa_ok( $wiki, "Wiki::Toolkit" );
24
25# Clear out the database from any previous runs.
26foreach my $del_node ( $wiki->list_all_nodes ) {
27    print "# Deleting node $del_node\n";
28    $wiki->delete_node( $del_node ) or die "Can't delete $del_node";
29}
30
31
32# Add 3 different pages, one of which with two versions
33$wiki->write_node( "Test Page", "foo", undef,
34                   { category => "Alpha", lat=>"" } )
35  or die "Couldn't write node";
36$wiki->write_node( "Test Page 2", "foo2", undef,
37                   { category => "Alpha", lat=>"22.22" } )
38  or die "Couldn't write node";
39$wiki->write_node( "Test Page 3", "foo33", undef,
40                   { category => "Alpha" } )
41  or die "Couldn't write node";
42$wiki->write_node( "Category Foo", "foo", undef,
43                   { category => "Categories", lat=>"-8.77" } )
44  or die "Couldn't write category";
45$wiki->write_node( "Locale Bar", "foo", undef,
46                   { category => "Locales", lat=>"8.22" } )
47  or die "Couldn't write locale";
48my %data = $wiki->retrieve_node( "Locale Bar" );
49$wiki->write_node( "Locale Bar", "foo version 2", $data{checksum},
50                   { category => "Locales", lat=>"8.88" } )
51  or die "Couldn't write locale for the 2nd time";
52
53
54# First up, try with no password
55my $output = $guide->set_node_moderation(
56                            id => "Test Page 3",
57                            moderation_flag => 0,
58                            return_output => 1
59);
60like($output, qr|Change moderation status|, "Confirm page");
61like($output, qr|Confirm Moderation|, "Confirm page");
62
63
64# Now, try with the wrong password
65$output = $guide->set_node_moderation(
66                            id => "Test Page 3",
67                            moderation_flag => 0,
68                            password => "I_AM_WRONG",
69                            return_output => 1
70);
71like($output, qr|Incorrect Password|, "Wrong password");
72like($output, qr|Incorrect password for page moderation|, "Wrong password");
73
74
75# Check that "Test Page 3" doesn't have moderation set
76my %node = $wiki->retrieve_node("Test Page 3");
77is($node{'node_requires_moderation'}, 0, "Doesn't have moderation on by default");
78
79# Set the moderation flag on it to off
80$guide->set_node_moderation(
81                            id => "Test Page 3",
82                            moderation_flag => 0,
83                            password => $guide->config->admin_pass
84);
85%node = $wiki->retrieve_node("Test Page 3");
86is($node{'node_requires_moderation'}, 0, "Doesn't have moderation set when called with 0");
87
88# Set it to on
89$guide->set_node_moderation(
90                            id => "Test Page 3",
91                            moderation_flag => 1,
92                            password => $guide->config->admin_pass
93);
94%node = $wiki->retrieve_node("Test Page 3");
95is($node{'node_requires_moderation'}, 1, "Turned on properly");
96
97# Set it back to off
98$guide->set_node_moderation(
99                            id => "Test Page 3",
100                            moderation_flag => 0,
101                            password => $guide->config->admin_pass
102);
103%node = $wiki->retrieve_node("Test Page 3");
104is($node{'node_requires_moderation'}, 0, "Turned off properly");
105
106
107# Test we were sent to the right place
108$output = $guide->set_node_moderation(
109                            id => "Test Page 3",
110                            moderation_flag => 0,
111                            password => $guide->config->admin_pass,
112                            return_output => 1
113);
114like($output, qr|Location: http://example.com/wiki.cgi\?action=admin;moderation=changed|, "Right location");
115like($output, qr|Status: 302|, "Right status");
116
117# And again, but this time with a made up node
118$output = $guide->set_node_moderation(
119                            id => "THIS PAGE DOES NOT EXIST",
120                            moderation_flag => 0,
121                            password => $guide->config->admin_pass,
122                            return_output => 1
123);
124like($output, qr|Location: http://example.com/wiki.cgi\?action=admin;moderation=unknown_node|, "Right location");
125like($output, qr|Status: 302|, "Right status");
Note: See TracBrowser for help on using the browser.