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

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

Clarify how you supply values.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
1package OpenGuides::Test;
2
3use OpenGuides::Config;
4
5use strict;
6use vars qw( $VERSION );
7$VERSION = '0.02';
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 an L<OpenGuides::Config> 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 = OpenGuides::Config->new(
56           vars => {
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    );
69    return $config;
70}
71
72=item B<write_data>
73
74  my $config = OpenGuides::Test->make_basic_config;
75  my $guide = OpenGuides->new( config => $config );
76
77  OpenGuides::Test->write_data(
78                                guide      => $guide,
79                                node       => "Crabtree Tavern",
80                                os_x       => 523465,
81                                os_y       => 177490,
82                                categories => "Pubs\r\nPub Food",
83                              );
84
85You can supply values for the following keys: C<content>,
86C<categories>, C<locales>, C<os_x>, C<os_y>, C<osie_x>, C<osie_y>,
87C<latitude>, C<longitude>.  You should supply them exactly as they
88would come from a CGI form, eg lines in a textarea are separated by C<\r\n>.
89
90=cut
91
92sub write_data {
93    my ($class, %args) = @_;
94
95    # Set up CGI parameters ready for a node write.
96    # Most of these are in here to avoid uninitialised value warnings.
97    my $q = CGI->new( "" );
98    $q->param( -name => "content", -value => $args{content} || "foo" );
99    $q->param( -name => "categories", -value => $args{categories} || "" );
100    $q->param( -name => "locales", -value => $args{locales} || "" );
101    $q->param( -name => "phone", -value => "" );
102    $q->param( -name => "fax", -value => "" );
103    $q->param( -name => "website", -value => "" );
104    $q->param( -name => "hours_text", -value => "" );
105    $q->param( -name => "address", -value => "" );
106    $q->param( -name => "postcode", -value => "" );
107    $q->param( -name => "map_link", -value => "" );
108    $q->param( -name => "os_x", -value => $args{os_x} || "" );
109    $q->param( -name => "os_y", -value => $args{os_y} || "" );
110    $q->param( -name => "osie_x", -value => $args{osie_x} || "" );
111    $q->param( -name => "osie_y", -value => $args{osie_y} || "" );
112    $q->param( -name => "latitude", -value => $args{latitude} || "" );
113    $q->param( -name => "longitude", -value => $args{longitude} || "" );
114    $q->param( -name => "username", -value => "Kake" );
115    $q->param( -name => "comment", -value => "foo" );
116    $q->param( -name => "edit_type", -value => "Normal edit" );
117    $ENV{REMOTE_ADDR} = "127.0.0.1";
118   
119    # Get the checksum of the current contents if necessary.
120    my $wiki = $args{guide}->wiki;
121    if ( $wiki->node_exists( $args{node} ) ) {
122        my %data = $wiki->retrieve_node( $args{node} );
123        $q->param( -name => "checksum", -value => $data{checksum} );
124    }
125
126    $args{guide}->commit_node(
127                               return_output => 1,
128                               id => $args{node},
129                               cgi_obj => $q,
130                             );
131}
132
133=back
134
135=head1 AUTHOR
136
137The OpenGuides Project (openguides-dev@openguides.org)
138
139=head1 COPYRIGHT
140
141  Copyright (C) 2004 The OpenGuides Project.  All Rights Reserved.
142
143This module is free software; you can redistribute it and/or modify it
144under the same terms as Perl itself.
145
146=cut
147
1481;
Note: See TracBrowser for help on using the repository browser.