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

Last change on this file since 883 was 883, checked in by Dominic Hargreaves, 15 years ago

Fix test failures with no Geo::HelmertTransform?, (from paulm)

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