source: wiki-toolkit/trunk/t/152_pre_plugin_approval.t @ 322

Last change on this file since 322 was 322, checked in by nick, 14 years ago

Correctly calculate (and skip) the number of tests when test::mockobject isn't installed

File size: 3.3 KB
Line 
1use strict;
2use Wiki::Toolkit::TestLib;
3use Test::More;
4
5if ( scalar @Wiki::Toolkit::TestLib::wiki_info == 0 ) {
6    plan skip_all => "no backends configured";
7} else {
8    plan tests => ( 12 * scalar @Wiki::Toolkit::TestLib::wiki_info );
9}
10
11my $iterator = Wiki::Toolkit::TestLib->new_wiki_maker;
12
13while ( my $wiki = $iterator->new_wiki ) {
14    SKIP: {
15        eval { require Test::MockObject; };
16        skip "Test::MockObject not installed", 12 if $@;
17
18        my $null_plugin = Test::MockObject->new;
19
20        my $plugin = Test::MockObject->new;
21        $plugin->mock( "on_register",
22                       sub {
23                           my $self = shift;
24                           $self->{__registered} = 1;
25                           $self->{__pre_moderate_called} = 0;
26                           $self->{__pre_rename_called} = 0;
27                           $self->{__pre_write_called} = 0;
28                           }
29                      );
30                eval { $wiki->register_plugin( plugin => $plugin ); };
31                ok( $plugin->{__registered}, "->on_register method called" );
32
33
34# ===========================================================================
35
36                # Test the pre moderation plugin not allowing moderation
37        $plugin->mock( "pre_moderate",
38                                                sub {
39                                                        my ($self, %args) = @_;
40                                                        $self->{__pre_moderate_called}++;
41                                                        return -1;
42                                                }
43        );
44
45                # Add a node
46        $wiki->write_node( "Test Node 3", "bar", undef, undef, 1 )
47            or die "Can't write first version node";
48
49                # Try to Moderate
50                my $ok = $wiki->moderate_node( name=>"Test Node 3", version=>1 )
51            or die "Can't moderate node";
52                is($plugin->{__pre_moderate_called}, 1, "Plugin was called");
53                is($ok, -1, "Wasn't allowed to moderate the node");
54
55                # Check it really wasn't
56                my %node = $wiki->retrieve_node("Test Node 3");
57                is($node{'version'}, 1, "Node correctly retrieved");
58                is($node{'moderated'}, 0, "Still not moderated");
59
60# ===========================================================================
61
62                # Test the pre rename plugin not allowing rename
63        $plugin->mock( "pre_rename",
64                                                sub {
65                                                        my ($self, %args) = @_;
66                                                        $self->{__pre_rename_called}++;
67                                                        return -1;
68                                                }
69        );
70
71                # Add another node
72        $wiki->write_node( "Test Node 2", "bar" )
73            or die "Can't write first version node";
74
75                # Try to Rename
76                $ok = $wiki->rename_node( old_name=>"Test Node 2", new_name=>"ren" )
77            or die "Can't rename node";
78                is($plugin->{__pre_rename_called}, 1, "Plugin was called");
79                is($ok, -1, "Wasn't allowed to rename the node");
80
81                # Check it really wasn't
82                %node = $wiki->retrieve_node("Test Node 2");
83                is($node{'version'}, 1, "Node correctly retrieved");
84
85# ===========================================================================
86
87                # Test the pre write plugin not allowing write
88        $plugin->mock( "pre_write",
89                                                sub {
90                                                        my ($self, %args) = @_;
91                                                        $self->{__pre_write_called}++;
92                                                        return -1;
93                                                }
94        );
95
96                # Try to Add
97                $ok = $wiki->write_node( "Test Node 4", "bar" )
98            or die "Can't add node";
99                is($plugin->{__pre_write_called}, 1, "Plugin was called");
100                is($ok, -1, "Wasn't allowed to write the node");
101
102                # Check it really wasn't
103                %node = $wiki->retrieve_node("Test Node 4");
104                is($node{'version'}, 0, "Node wasn't added");
105                is($node{'content'}, '', "Node wasn't added");
106    }
107}
Note: See TracBrowser for help on using the repository browser.