source: trunk/lib/OpenGuides/Test.pm @ 567

Last change on this file since 567 was 567, checked in by kake, 17 years ago

Make sure second write works.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
Line 
1package OpenGuides::Test;
2
3use Config::Tiny;
4
5use strict;
6use vars qw( $VERSION );
7$VERSION = '0.01';
8
9use CGI;
10
11=head1 NAME
12
13OpenGuides::Test - Methods to help test OpenGuides applications.
14
15=head1 DESCRIPTION
16
17Provides methods to help when writing tests for OpenGuides.
18Distributed and installed as part of the OpenGuides project, not
19intended for independent installation.  This documentation is probably
20only useful to OpenGuides developers.
21
22=head1 SYNOPSIS
23
24  use OpenGuides;
25  use OpenGuides::Test;
26
27  my $config = OpenGuides::Test->make_basic_config;
28  $config->{_}{default_language} = "nl";
29
30  my $guide = OpenGuides->new( config => $config );
31
32  OpenGuides::Test->write_data(
33                                guide      => $guide,
34                                node       => "Crabtree Tavern",
35                                os_x       => 523465,
36                                os_y       => 177490,
37                                categories => "Pubs",
38                              );
39
40=head1 METHODS
41
42=over 4
43
44=item B<make_basic_config>
45
46  my $config = OpenGuides::Test->make_basic_config;
47  $config->{_}{default_language} = "nl";
48
49Makes a L<Config::Tiny> object with needed fields pre-filled.  You can
50mess with it as you like then.
51
52=cut
53
54sub make_basic_config {
55    my $config = Config::Tiny->new;
56    $config->{_} = {
57                     dbtype               => "sqlite",
58                     dbname               => "t/node.db",
59                     indexing_directory   => "t/indexes",
60                     script_url           => "",
61                     script_name          => "",
62                     site_name            => "Test",
63                     template_path        => "./templates",
64                     custom_template_path => "./custom-templates",
65                     home_name            => "Home",
66                     geo_handler          => 1,
67                   };
68    return $config;
69}
70
71=item B<write_data>
72
73  my $guide = OpenGuides->new( config => $config );
74
75  OpenGuides::Test->write_data(
76                                guide      => $guide,
77                                node       => "Crabtree Tavern",
78                                os_x       => 523465,
79                                os_y       => 177490,
80                                categories => "Pubs",
81                              );
82
83=cut
84
85sub write_data {
86    my ($class, %args) = @_;
87
88    # Set up CGI parameters ready for a node write.
89    # Most of these are in here to avoid uninitialised value warnings.
90    my $q = CGI->new( "" );
91    $q->param( -name => "content", -value => $args{content} || "foo" );
92    $q->param( -name => "categories", -value => $args{categories} || "" );
93    $q->param( -name => "locales", -value => "" );
94    $q->param( -name => "phone", -value => "" );
95    $q->param( -name => "fax", -value => "" );
96    $q->param( -name => "website", -value => "" );
97    $q->param( -name => "hours_text", -value => "" );
98    $q->param( -name => "address", -value => "" );
99    $q->param( -name => "postcode", -value => "" );
100    $q->param( -name => "map_link", -value => "" );
101    $q->param( -name => "os_x", -value => $args{os_x} || "" );
102    $q->param( -name => "os_y", -value => $args{os_y} || "" );
103    $q->param( -name => "osie_x", -value => $args{osie_x} || "" );
104    $q->param( -name => "osie_y", -value => $args{osie_y} || "" );
105    $q->param( -name => "latitude", -value => $args{latitude} || "" );
106    $q->param( -name => "longitude", -value => $args{longitude} || "" );
107    $q->param( -name => "username", -value => "Kake" );
108    $q->param( -name => "comment", -value => "foo" );
109    $q->param( -name => "edit_type", -value => "Normal edit" );
110    $ENV{REMOTE_ADDR} = "127.0.0.1";
111   
112    # Get the checksum of the current contents if necessary.
113    my $wiki = $args{guide}->wiki;
114    if ( $wiki->node_exists( $args{node} ) ) {
115        my %data = $wiki->retrieve_node( $args{node} );
116        $q->param( -name => "checksum", -value => $data{checksum} );
117    }
118
119    $args{guide}->commit_node(
120                               return_output => 1,
121                               id => $args{node},
122                               cgi_obj => $q,
123                             );
124}
125
126=back
127
128=head1 AUTHOR
129
130The OpenGuides Project (openguides-dev@openguides.org)
131
132=head1 COPYRIGHT
133
134  Copyright (C) 2004 The OpenGuides Project.  All Rights Reserved.
135
136This module is free software; you can redistribute it and/or modify it
137under the same terms as Perl itself.
138
139=cut
140
1411;
Note: See TracBrowser for help on using the repository browser.