root/trunk/t/11_utils.t

Revision 1066, 2.2 kB (checked in by kake, 19 months ago)

Refactor redirect detection into OpenGuides::Utils->detect_redirect

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1use strict;
2use Wiki::Toolkit::Setup::SQLite;
3use OpenGuides::Config;
4use OpenGuides::Utils;
5use Test::More tests => 10;
6
7eval { my $wiki = OpenGuides::Utils->make_wiki_object; };
8ok( $@, "->make_wiki_object croaks if no config param supplied" );
9
10eval { my $wiki = OpenGuides::Utils->make_wiki_object( config => "foo" ); };
11ok( $@, "...and if config param isn't an OpenGuides::Config object" );
12
13eval {
14    my $wiki = OpenGuides::Utils->make_wiki_object(
15        config => OpenGuides::Config->new( file => 'fake' )
16    );
17};
18
19like( $@, qr/File 'fake' does not exist/, '...and Config::Tiny errors are reported');
20
21my $have_sqlite = 1;
22my $sqlite_error;
23
24eval { require DBD::SQLite; };
25if ( $@ ) {
26    ($sqlite_error) = $@ =~ /^(.*?)\n/;
27    $have_sqlite = 0;
28}
29
30SKIP: {
31    skip "DBD::SQLite could not be used - no database to test with. "
32         . "($sqlite_error)", 7
33      unless $have_sqlite;
34
35    # Clear out the database from any previous runs.
36    unlink "t/node.db";
37    unlink <t/indexes/*>;
38    Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
39
40    my $config = OpenGuides::Config->new(
41           vars => {
42                     dbtype             => "sqlite",
43                     dbname             => "t/node.db",
44                     indexing_directory => "t/indexes",
45                     script_url         => "",
46                     script_name        => "",
47                   }
48    );
49
50    eval { require Wiki::Toolkit::Search::Plucene; };
51    if ( $@ ) { $config->use_plucene ( 0 ) };
52
53    my $wiki = eval {
54        OpenGuides::Utils->make_wiki_object( config => $config );
55    };
56    is( $@, "",
57        "...but not with an OpenGuides::Config object with suitable data" );
58    isa_ok( $wiki, "Wiki::Toolkit" );
59
60    ok( $wiki->store,      "...and store defined" );
61    ok( $wiki->search_obj, "...and search defined" );
62    ok( $wiki->formatter,  "...and formatter defined" );
63
64    # Now test ->detect_redirect
65    is( OpenGuides::Utils->detect_redirect( content => "#REDIRECT [[Foo]]" ),
66        "Foo",
67        "->detect_redirect successfully detects redirect content" );
68    ok( !OpenGuides::Utils->detect_redirect( content => "Mmmm, tea." ),
69        "...and successfully detects non-redirect content" );
70}
Note: See TracBrowser for help on using the browser.