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

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

Encapsulate config data in OpenGuides::Config.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 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",
83                              );
84
85=cut
86
87sub write_data {
88    my ($class, %args) = @_;
89
90    # Set up CGI parameters ready for a node write.
91    # Most of these are in here to avoid uninitialised value warnings.
92    my $q = CGI->new( "" );
93    $q->param( -name => "content", -value => $args{content} || "foo" );
94    $q->param( -name => "categories", -value => $args{categories} || "" );
95    $q->param( -name => "locales", -value => "" );
96    $q->param( -name => "phone", -value => "" );
97    $q->param( -name => "fax", -value => "" );
98    $q->param( -name => "website", -value => "" );
99    $q->param( -name => "hours_text", -value => "" );
100    $q->param( -name => "address", -value => "" );
101    $q->param( -name => "postcode", -value => "" );
102    $q->param( -name => "map_link", -value => "" );
103    $q->param( -name => "os_x", -value => $args{os_x} || "" );
104    $q->param( -name => "os_y", -value => $args{os_y} || "" );
105    $q->param( -name => "osie_x", -value => $args{osie_x} || "" );
106    $q->param( -name => "osie_y", -value => $args{osie_y} || "" );
107    $q->param( -name => "latitude", -value => $args{latitude} || "" );
108    $q->param( -name => "longitude", -value => $args{longitude} || "" );
109    $q->param( -name => "username", -value => "Kake" );
110    $q->param( -name => "comment", -value => "foo" );
111    $q->param( -name => "edit_type", -value => "Normal edit" );
112    $ENV{REMOTE_ADDR} = "127.0.0.1";
113   
114    # Get the checksum of the current contents if necessary.
115    my $wiki = $args{guide}->wiki;
116    if ( $wiki->node_exists( $args{node} ) ) {
117        my %data = $wiki->retrieve_node( $args{node} );
118        $q->param( -name => "checksum", -value => $data{checksum} );
119    }
120
121    $args{guide}->commit_node(
122                               return_output => 1,
123                               id => $args{node},
124                               cgi_obj => $q,
125                             );
126}
127
128=back
129
130=head1 AUTHOR
131
132The OpenGuides Project (openguides-dev@openguides.org)
133
134=head1 COPYRIGHT
135
136  Copyright (C) 2004 The OpenGuides Project.  All Rights Reserved.
137
138This module is free software; you can redistribute it and/or modify it
139under the same terms as Perl itself.
140
141=cut
142
1431;
Note: See TracBrowser for help on using the repository browser.