source: trunk/t/17_commit_node.t @ 878

Last change on this file since 878 was 841, checked in by nick, 15 years ago

Fix a typo, and support the node image for editing (but not yet display)

File size: 3.3 KB
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    plan skip_all => "DBD::SQLite not installed";
12    exit 0;
13}
14
15eval { require Wiki::Toolkit::Search::Plucene; };
16if ( $@ ) {
17    plan skip_all => "Plucene not installed";
18    exit 0;
19}
20
21
22plan tests => 5;
23
24# Clear out the database from any previous runs.
25unlink "t/node.db";
26unlink <t/indexes/*>;
27
28Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
29my $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.
44my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
45
46my $feed = OpenGuides::Feed->new( wiki   => $wiki,
47                                  config => $config );
48
49
50# Write the first version
51my $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.
55my $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
74my $output = $guide->commit_node(
75                                  return_output => 1,
76                                  id => "Wombats",
77                                  cgi_obj => $q,
78                                );
79
80# Check we have it
81ok( $wiki->node_exists( "Wombats" ), "Wombats written" );
82
83my %node = $wiki->retrieve_node("Wombats");
84is( $node{version}, 1, "First version" );
85is( $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");
99is( $node{version}, 2, "First version" );
100is( $node{metadata}->{edit_type}[0], "Normal edit", "Right edit type" );
Note: See TracBrowser for help on using the repository browser.