root/trunk/t/72_node_moderation.t

Revision 956, 4.0 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 => 19;
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 a page
33my $q = CGI->new;
34$q->param( -name => "content", -value => "foo" );
35$q->param( -name => "categories", -value => "Alpha" );
36$q->param( -name => "locales", -value => "" );
37$q->param( -name => "phone", -value => "" );
38$q->param( -name => "fax", -value => "" );
39$q->param( -name => "website", -value => "" );
40$q->param( -name => "hours_text", -value => "" );
41$q->param( -name => "address", -value => "" );
42$q->param( -name => "postcode", -value => "" );
43$q->param( -name => "map_link", -value => "" );
44$q->param( -name => "os_x", -value => "" );
45$q->param( -name => "os_y", -value => "" );
46$q->param( -name => "username", -value => "bob" );
47$q->param( -name => "comment", -value => "foo" );
48$q->param( -name => "edit_type", -value => "Minor tidying" );
49$ENV{REMOTE_ADDR} = "127.0.0.1";
50
51my $output = $guide->commit_node(
52                                  return_output => 1,
53                                  id => "Wombats",
54                                  cgi_obj => $q,
55                                );
56
57# Check it's moderated
58my %details = $wiki->retrieve_node("Wombats");
59is($details{'moderated'}, 1, "Moderated");
60is($wiki->node_required_moderation("Wombats"), 0, "No moderation");
61
62# Turn on moderation
63$wiki->set_node_moderation(
64                            name => "Wombats",
65                            required => 1,
66);
67is($wiki->node_required_moderation("Wombats"), 1, "Moderation");
68
69
70# Now add a new one, with new categories and locales
71$q->param( -name => "categories", -value => "Alpha\r\nBeta" );
72$q->param( -name => "locales", -value => "Hello" );
73$q->param( -name => "edit_type", -value => "Normal edit" );
74$q->param( -name => "checksum", -value => $details{checksum} );
75$output = $guide->commit_node(
76                                  return_output => 1,
77                                  id => "Wombats",
78                                  cgi_obj => $q,
79                                );
80
81# Check that the current version is still 1
82%details = $wiki->retrieve_node("Wombats");
83is($details{'version'}, 1, "Still on v1");
84is($details{'moderated'}, 1, "v1 Moderated");
85
86# Check that version 2 isn't moderated
87my %v2 = $wiki->retrieve_node(name=>"Wombats",version=>2);
88is($v2{'version'}, 2, "Is v2");
89is($v2{'moderated'}, 0, "Not moderated");
90
91# Check that the new categories and locales aren't there
92is(1, $wiki->node_exists("Category Alpha"), "Right Categories");
93is(0, $wiki->node_exists("Category Beta"), "Right Categories");
94is(0, $wiki->node_exists("Locale Hello"), "Right Locales");
95
96
97# Moderate
98$guide->moderate_node(
99                        id       => "Wombats",
100                        version  => 2,
101                        password => $guide->config->admin_pass
102);
103
104
105# Check that the current version is 2
106%details = $wiki->retrieve_node(name=>"Wombats");
107is($details{'version'}, 2, "Is v2");
108is($details{'moderated'}, 1, "Moderated");
109
110# Check that version 2 is moderated
111%v2 = $wiki->retrieve_node(name=>"Wombats",version=>2);
112is($v2{'version'}, 2, "Is v2");
113is($v2{'moderated'}, 1, "Moderated");
114
115# Check that the new categories and locales exist
116is(1, $wiki->node_exists("Category Alpha"), "Right Categories");
117is(1, $wiki->node_exists("Category Beta"), "Right Categories");
118is(1, $wiki->node_exists("Locale Hello"), "Right Locales");
Note: See TracBrowser for help on using the browser.