1 | use strict; |
---|
2 | use Wiki::Toolkit::TestLib; |
---|
3 | use Test::More; |
---|
4 | |
---|
5 | my $iterator = Wiki::Toolkit::TestLib->new_wiki_maker; |
---|
6 | plan tests => ( 1 + $iterator->number * 6 ); |
---|
7 | |
---|
8 | use_ok( "Wiki::Toolkit::Plugin::Categoriser" ); |
---|
9 | |
---|
10 | while ( my $wiki = $iterator->new_wiki ) { |
---|
11 | print "#\n##### TEST CONFIG: Store: " . (ref $wiki->store) . "\n"; |
---|
12 | |
---|
13 | my $categoriser = eval { Wiki::Toolkit::Plugin::Categoriser->new; }; |
---|
14 | is( $@, "", "'new' doesn't croak" ); |
---|
15 | isa_ok( $categoriser, "Wiki::Toolkit::Plugin::Categoriser" ); |
---|
16 | $wiki->register_plugin( plugin => $categoriser ); |
---|
17 | |
---|
18 | $wiki->write_node( "Calthorpe Arms", "beer", undef, |
---|
19 | { category => [ "Pubs", "Pub Food" ] } ) |
---|
20 | or die "Can't write node"; |
---|
21 | $wiki->write_node( "Albion", "pub", undef, |
---|
22 | { category => [ "Pubs", "Pub Food" ] } ) |
---|
23 | or die "Can't write node"; |
---|
24 | $wiki->write_node( "Ken Livingstone", "Congestion charge hero", undef, |
---|
25 | { category => [ "People" ] } ) |
---|
26 | or die "Can't write node"; |
---|
27 | |
---|
28 | # Test ->in_category |
---|
29 | my $isa_pub = $categoriser->in_category( category => "Pubs", |
---|
30 | node => "Albion" ); |
---|
31 | ok( $isa_pub, "in_category returns true for things in the category" ); |
---|
32 | $isa_pub = $categoriser->in_category( category => "Pubs", |
---|
33 | node => "Ken Livingstone" ); |
---|
34 | ok( !$isa_pub, "...and false for things not in the category" ); |
---|
35 | |
---|
36 | $isa_pub = $categoriser->in_category( category => "pubs", |
---|
37 | node => "Albion" ); |
---|
38 | ok( $isa_pub, "...and is case-insensitive" ); |
---|
39 | |
---|
40 | # Test ->categories |
---|
41 | my @categories = $categoriser->categories( node => "Calthorpe Arms" ); |
---|
42 | is_deeply( [ sort @categories ], [ "Pub Food", "Pubs" ], |
---|
43 | "...->categories returns all categories" ); |
---|
44 | } |
---|