| 1 | use strict; |
|---|
| 2 | use Wiki::Toolkit::Setup::SQLite; |
|---|
| 3 | use OpenGuides::Config; |
|---|
| 4 | use OpenGuides; |
|---|
| 5 | use OpenGuides::Feed; |
|---|
| 6 | use OpenGuides::Utils; |
|---|
| 7 | use Test::More; |
|---|
| 8 | |
|---|
| 9 | eval { require DBD::SQLite; }; |
|---|
| 10 | if ( $@ ) { |
|---|
| 11 | plan skip_all => "DBD::SQLite not installed"; |
|---|
| 12 | exit 0; |
|---|
| 13 | } |
|---|
| 14 | |
|---|
| 15 | eval { require Wiki::Toolkit::Search::Plucene; }; |
|---|
| 16 | if ( $@ ) { |
|---|
| 17 | plan skip_all => "Plucene not installed"; |
|---|
| 18 | exit 0; |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | plan tests => 5; |
|---|
| 23 | |
|---|
| 24 | # Clear out the database from any previous runs. |
|---|
| 25 | unlink "t/node.db"; |
|---|
| 26 | unlink <t/indexes/*>; |
|---|
| 27 | |
|---|
| 28 | Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); |
|---|
| 29 | my $config = OpenGuides::Config->new( |
|---|
| 30 | vars => { |
|---|
| 31 | dbtype => "sqlite", |
|---|
| 32 | dbname => "t/node.db", |
|---|
| 33 | indexing_directory => "t/indexes", |
|---|
| 34 | script_name => "wiki.cgi", |
|---|
| 35 | script_url => "http://example.com/", |
|---|
| 36 | site_name => "Test Site", |
|---|
| 37 | template_path => "./templates", |
|---|
| 38 | home_name => "Home", |
|---|
| 39 | use_plucene => 1 |
|---|
| 40 | } |
|---|
| 41 | ); |
|---|
| 42 | |
|---|
| 43 | # Basic sanity check first. |
|---|
| 44 | my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); |
|---|
| 45 | |
|---|
| 46 | my $feed = OpenGuides::Feed->new( wiki => $wiki, |
|---|
| 47 | config => $config ); |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | # Write the first version |
|---|
| 51 | my $guide = OpenGuides->new( config => $config ); |
|---|
| 52 | |
|---|
| 53 | # Set up CGI parameters ready for a node write. |
|---|
| 54 | # Most of these are in here to avoid uninitialised value warnings. |
|---|
| 55 | my $q = CGI->new; |
|---|
| 56 | $q->param( -name => "content", -value => "foo" ); |
|---|
| 57 | $q->param( -name => "categories", -value => "" ); |
|---|
| 58 | $q->param( -name => "locales", -value => "" ); |
|---|
| 59 | $q->param( -name => "phone", -value => "" ); |
|---|
| 60 | $q->param( -name => "fax", -value => "" ); |
|---|
| 61 | $q->param( -name => "website", -value => "" ); |
|---|
| 62 | $q->param( -name => "hours_text", -value => "" ); |
|---|
| 63 | $q->param( -name => "address", -value => "" ); |
|---|
| 64 | $q->param( -name => "postcode", -value => "" ); |
|---|
| 65 | $q->param( -name => "map_link", -value => "" ); |
|---|
| 66 | $q->param( -name => "os_x", -value => "" ); |
|---|
| 67 | $q->param( -name => "os_y", -value => "" ); |
|---|
| 68 | $q->param( -name => "username", -value => "bob" ); |
|---|
| 69 | $q->param( -name => "comment", -value => "foo" ); |
|---|
| 70 | $q->param( -name => "node_image", -value => "image" ); |
|---|
| 71 | $q->param( -name => "edit_type", -value => "Minor tidying" ); |
|---|
| 72 | $ENV{REMOTE_ADDR} = "127.0.0.1"; |
|---|
| 73 | |
|---|
| 74 | my $output = $guide->commit_node( |
|---|
| 75 | return_output => 1, |
|---|
| 76 | id => "Wombats", |
|---|
| 77 | cgi_obj => $q, |
|---|
| 78 | ); |
|---|
| 79 | |
|---|
| 80 | # Check we have it |
|---|
| 81 | ok( $wiki->node_exists( "Wombats" ), "Wombats written" ); |
|---|
| 82 | |
|---|
| 83 | my %node = $wiki->retrieve_node("Wombats"); |
|---|
| 84 | is( $node{version}, 1, "First version" ); |
|---|
| 85 | is( $node{metadata}->{edit_type}[0], "Minor tidying", "Right edit type" ); |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | # Now write a second version of it |
|---|
| 89 | $q->param( -name => "edit_type", -value => "Normal edit" ); |
|---|
| 90 | $q->param( -name => "checksum", -value => $node{checksum} ); |
|---|
| 91 | $output = $guide->commit_node( |
|---|
| 92 | return_output => 1, |
|---|
| 93 | id => "Wombats", |
|---|
| 94 | cgi_obj => $q, |
|---|
| 95 | ); |
|---|
| 96 | |
|---|
| 97 | # Check it's as expected |
|---|
| 98 | %node = $wiki->retrieve_node("Wombats"); |
|---|
| 99 | is( $node{version}, 2, "First version" ); |
|---|
| 100 | is( $node{metadata}->{edit_type}[0], "Normal edit", "Right edit type" ); |
|---|