root/tags/rel0_59/t/17_commit_node.t

Revision 956, 3.3 kB (checked in by earle, 22 months ago)

Complete transition to using skip_all (remove old SKIP blocks).
More verbose reporting for error "require"ing DBD::SQLite.

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