|
Revision 1037, 1.6 kB
(checked in by kake, 20 months ago)
|
|
Added experimental support for local spam detection modules.
|
| Line | |
|---|
| 1 | use strict; |
|---|
| 2 | |
|---|
| 3 | use OpenGuides; |
|---|
| 4 | use OpenGuides::Test; |
|---|
| 5 | use Test::More; |
|---|
| 6 | use Wiki::Toolkit::Setup::SQLite; |
|---|
| 7 | |
|---|
| 8 | eval { require DBD::SQLite; }; |
|---|
| 9 | if ( $@ ) { |
|---|
| 10 | my ($error) = $@ =~ /^(.*?)\n/; |
|---|
| 11 | plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; |
|---|
| 12 | } |
|---|
| 13 | |
|---|
| 14 | plan tests => 2; |
|---|
| 15 | |
|---|
| 16 | # Clear out the database from any previous runs. |
|---|
| 17 | unlink "t/node.db"; |
|---|
| 18 | unlink <t/indexes/*>; |
|---|
| 19 | Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); |
|---|
| 20 | |
|---|
| 21 | # Set up a guide which uses a spam detector module. |
|---|
| 22 | my $config = OpenGuides::Test->make_basic_config; |
|---|
| 23 | $config->spam_detector_module( "OpenGuides::Local::SpamDetector" ); |
|---|
| 24 | my $guide = OpenGuides->new( config => $config ); |
|---|
| 25 | |
|---|
| 26 | # Try to write something that isn't spam. |
|---|
| 27 | my $q = OpenGuides::Test->make_cgi_object( content => "puppies" ); |
|---|
| 28 | my $output = $guide->commit_node( |
|---|
| 29 | id => "Puppies", |
|---|
| 30 | cgi_obj => $q, |
|---|
| 31 | return_output => 1, |
|---|
| 32 | ); |
|---|
| 33 | ok( $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 | ); |
|---|
| 42 | ok( !$guide->wiki->node_exists( "Kittens" ), "can't write spammy node" ); |
|---|
| 43 | |
|---|
| 44 | package OpenGuides::Local::SpamDetector; |
|---|
| 45 | |
|---|
| 46 | sub looks_like_spam { |
|---|
| 47 | my ( $class, %args ) = @_; |
|---|
| 48 | if ( $args{content} =~ /kittens/i ) { |
|---|
| 49 | return 1; |
|---|
| 50 | } |
|---|
| 51 | return 0; |
|---|
| 52 | } |
|---|