/usr/share/perl5/OpenGuides/Test.pm is in openguides 0.81-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | package OpenGuides::Test;
use OpenGuides::Config;
use Wiki::Toolkit::Setup::SQLite;
use strict;
use vars qw( $VERSION );
$VERSION = '0.07';
use CGI;
=head1 NAME
OpenGuides::Test - Methods to help test OpenGuides applications.
=head1 DESCRIPTION
Provides methods to help when writing tests for OpenGuides.
Distributed and installed as part of the OpenGuides project, not
intended for independent installation. This documentation is probably
only useful to OpenGuides developers.
=head1 SYNOPSIS
use OpenGuides;
use OpenGuides::Test;
OpenGuides::Test::refresh_db();
my $config = OpenGuides::Test->make_basic_config;
$config->default_language( "nl" );
my $guide = OpenGuides->new( config => $config );
OpenGuides::Test->write_data(
guide => $guide,
node => "Crabtree Tavern",
os_x => 523465,
os_y => 177490,
categories => "Pubs",
);
=head1 METHODS
=over 4
=item B<make_basic_config>
my $config = OpenGuides::Test->make_basic_config;
$config->default_language( "nl" );
Makes an L<OpenGuides::Config> object with needed fields pre-filled. You can
mess with it as you like then.
=cut
sub make_basic_config {
my $config = OpenGuides::Config->new(
vars => {
dbtype => "sqlite",
dbname => "t/node.db",
indexing_directory => "t/indexes",
script_url => "",
script_name => "",
site_name => "Test",
template_path => "./templates",
custom_template_path => "./custom-templates",
home_name => "Home",
geo_handler => 1,
force_wgs84 => 1,
contact_email => 'admins@example.org',
moderate_whitelist => "",
}
);
eval { require Wiki::Toolkit::Search::Plucene; };
if ( $@ ) { $config->use_plucene ( 0 ) };
return $config;
}
=item B<write_data>
my $config = OpenGuides::Test->make_basic_config;
my $guide = OpenGuides->new( config => $config );
OpenGuides::Test->write_data(
guide => $guide,
node => "Crabtree Tavern",
os_x => 523465,
os_y => 177490,
categories => "Pubs\r\nPub Food",
);
This method calls the C<make_cgi_object> method to make its CGI
object; you can supply values for any key mentioned there. You should
supply them exactly as they would come from a CGI form, eg lines in a
textarea are separated by C<\r\n>.
This method will automatically grab the checksum from the database, so
even if the node already exists your data will still be written. If you
don't want this behaviour (for example, if you're testing edit conflicts)
then pass in a true value to the C<omit_checksum> parameter:
OpenGuides::Test->write_data(
guide => $guide,
node => "Crabtree Tavern",
omit_checksum => 1,
);
If you want to grab the output, pass a true value to C<return_output>:
my $output = OpenGuides::Test->write_data(
guide => $guide,
node => "Crabtree Tavern",
return_output => 1,
);
Similarly, if you pass a true value to C<return_tt_vars>, the return value
will be the variables which would have been passed to the template for output:
my %vars = OpenGuides::Test->write_data(
guide => $guide,
node => "Crabtree Tavern",
return_tt_vars => 1,
);
=cut
sub write_data {
my ($class, %args) = @_;
my $guide = delete $args{guide};
my $node = delete $args{node};
my $q = $class->make_cgi_object( %args );
# Get the checksum of the current contents if necessary.
unless ( $args{omit_checksum} ) {
my $wiki = $guide->wiki;
if ( $wiki->node_exists( $node ) ) {
my %data = $wiki->retrieve_node( $node );
$q->param( -name => "checksum", -value => $data{checksum} );
}
}
if ( $args{return_output} ) {
return $guide->commit_node(
return_output => 1,
id => $node,
cgi_obj => $q,
);
} elsif ( $args{return_tt_vars} ) {
return $guide->commit_node(
return_tt_vars => 1,
id => $node,
cgi_obj => $q,
);
} else {
$guide->commit_node(
id => $node,
cgi_obj => $q,
);
}
}
=item B<make_cgi_object>
my $q = OpenGuides::Test->make_cgi_object;
You can supply values for the following keys: C<content>, C<categories>,
C<locales>, C<node_image>, C<node_image_licence>,
C<node_image_copyright>, C<node_image_url>, C<phone>, C<fax>,
C<website>, C<hours_text>, C<address>, C<postcode>, C<map_link>,
C<os_x>, C<os_y>, C<osie_x>, C<osie_y>, C<latitude>, C<longitude>,
C<summary>, C<username>, C<comment>, C<edit_type>. You should supply
them exactly as they would come from a CGI form, eg lines in a textarea
are separated by C<\r\n>.
=cut
sub make_cgi_object {
my ( $class, %args ) = @_;
# Set up CGI parameters ready for a node write.
# Most of these are in here to avoid uninitialised value warnings.
my $q = CGI->new( "" );
$args{content} ||= "foo";
$args{edit_type} ||= "Normal edit";
for my $param ( qw( content categories locales node_image node_image_licence
node_image_copyright node_image_url phone fax website
hours_text address postcode map_link os_x os_y osie_x osie_y
latitude longitude summary username comment edit_type
)
) {
if (defined $args{$param}) {
$q->param( -name => $param, -value => $args{$param} );
} else {
$q->param( -name => $param, -value => '' );
}
}
$ENV{REMOTE_ADDR} = "127.0.0.1";
return $q;
}
=item B<refresh_db>
Openguides::Test::refresh_db();
Unlink the existing SQLite database t/node.db and Plucene/Lucy indexes.
Then create a new SQLite database t/node.db
=cut
sub refresh_db {
unlink "t/node.db";
unlink <t/indexes/*>;
Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
}
=back
=head1 AUTHOR
The OpenGuides Project (openguides-dev@lists.openguides.org)
=head1 COPYRIGHT
Copyright (C) 2004-2013 The OpenGuides Project. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
1;
|