source: trunk/t/76_detect_spam.t @ 1037

Last change on this file since 1037 was 1037, checked in by kake, 14 years ago

Added experimental support for local spam detection modules.

File size: 1.6 KB
Line 
1use strict;
2
3use OpenGuides;
4use OpenGuides::Test;
5use Test::More;
6use Wiki::Toolkit::Setup::SQLite;
7
8eval { require DBD::SQLite; };
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 => 2;
15
16# Clear out the database from any previous runs.
17unlink "t/node.db";
18unlink <t/indexes/*>;
19Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
20
21# Set up a guide which uses a spam detector module.
22my $config = OpenGuides::Test->make_basic_config;
23$config->spam_detector_module( "OpenGuides::Local::SpamDetector" );
24my $guide = OpenGuides->new( config => $config );
25
26# Try to write something that isn't spam.
27my $q = OpenGuides::Test->make_cgi_object( content => "puppies" );
28my $output = $guide->commit_node(
29                                  id            => "Puppies",
30                                  cgi_obj       => $q,
31                                  return_output => 1,
32                                );
33ok( $guide->wiki->node_exists( "Puppies" ), "can write non-spam node" );
34
35# Try to write something that is.
36$q = OpenGuides::Test->make_cgi_object( content => "kittens" );
37$output = $guide->commit_node(
38                               id            => "Kittens",
39                               cgi_obj       => $q,
40                               return_output => 1,
41                             );
42ok( !$guide->wiki->node_exists( "Kittens" ), "can't write spammy node" );
43
44package OpenGuides::Local::SpamDetector;
45
46sub looks_like_spam {
47    my ( $class, %args ) = @_;
48    if ( $args{content} =~ /kittens/i ) {
49        return 1;
50    }
51    return 0;
52}
Note: See TracBrowser for help on using the repository browser.