root/branches/new-install-process/t/17_commit_node.t

Revision 1077, 3.3 kB (checked in by dom, 19 months ago)

Fix silly my $foo bug

Line 
1use strict;
2use Wiki::Toolkit::Setup::SQLite;
3use OpenGuides::Config;
4use OpenGuides;
5use OpenGuides::Feed;
6use OpenGuides::Utils;
7use OpenGuides::Test;
8use Test::More;
9
10eval { require DBD::SQLite; };
11if ( $@ ) {
12    my ($error) = $@ =~ /^(.*?)\n/;
13    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
14}
15
16eval { require Wiki::Toolkit::Search::Plucene; };
17if ( $@ ) {
18    plan skip_all => "Plucene not installed";
19}
20
21
22plan tests => 7;
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.
54my $q = OpenGuides::Test->make_cgi_object(
55    content => "foo",
56    username => "bob",
57    comment => "foo",
58    node_image => "image",
59    edit_type => "Minor tidying"
60);
61
62my $output = $guide->commit_node(
63                                  return_output => 1,
64                                  id => "Wombats",
65                                  cgi_obj => $q,
66                                );
67
68# Check we have it
69ok( $wiki->node_exists( "Wombats" ), "Wombats written" );
70
71my %node = $wiki->retrieve_node("Wombats");
72is( $node{version}, 1, "First version" );
73is( $node{metadata}->{edit_type}[0], "Minor tidying", "Right edit type" );
74
75
76# Now write a second version of it
77$q->param( -name => "edit_type", -value => "Normal edit" );
78$q->param( -name => "checksum", -value => $node{checksum} );
79$output = $guide->commit_node(
80                               return_output => 1,
81                               id => "Wombats",
82                               cgi_obj => $q,
83                             );
84
85# Check it's as expected
86%node = $wiki->retrieve_node("Wombats");
87is( $node{version}, 2, "First version" );
88is( $node{metadata}->{edit_type}[0], "Normal edit", "Right edit type" );
89
90# Now try to commit some invalid data, and make sure we get an edit form back
91$q = OpenGuides::Test->make_cgi_object(
92    content => "foo",
93    os_x => "fooooo",
94    username => "bob",
95    comment => "foo",
96    node_image => "image",
97    edit_type => "Minor tidying"
98);
99
100$output = $guide->commit_node(
101                                return_output => 1,
102                                id => "Wombats again",
103                                cgi_obj => $q,
104                             );
105
106like( $output, qr/Your input was invalid/,
107    "Edit form displayed and invalid input message shown if invalid input" );
108
109like( $output, qr/os_x must be integer/,
110    "Edit form displayed and os_x integer message displayed" );
Note: See TracBrowser for help on using the browser.