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

Last change on this file since 594 was 594, checked in by Dominic Hargreaves, 17 years ago

Update tests so they pass without Plucene installed again (was affected by
config rejig).

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