5 # Note: this test depends on the env variable $SGN_TEST_MODE
6 # being set to 1 in the server process
11 use SGN
::Test
::WWW
::Mechanize
;
13 my $form_url = '/contact/form';
14 my $mech = SGN
::Test
::WWW
::Mechanize
->new;
16 form_basic_ok
( $mech, $form_url );
17 submit_form_ok
( $mech, $form_url );
19 $mech->while_logged_in(
20 { user_type
=> 'user' },
23 form_basic_ok
( $mech, $form_url );
24 form_has_user_defaults
( $mech, $user );
25 submit_form_ok
( $mech, $form_url );
32 # check contact form displays OK
34 my ( $mech, $form_url ) = @_;
35 $mech->get_ok( $form_url );
36 $mech->content_contains( $_ ) for (
47 sub form_has_user_defaults
{
48 my ( $mech, $user ) = @_;
49 $mech->form_name('contactForm');
50 like
$mech->value('name'), qr/$user->{first_name}/;
51 like
$mech->value('name'), qr/$user->{last_name}/;
54 my ( $mech, $form_url ) = @_;
55 $mech->get_ok( $form_url );
56 # submit a blank form and check for 'required' messages'
57 my @fieldnames = qw( name email subject body );
58 $mech->submit_form_ok({
59 form_name
=> 'contactForm',
66 $mech->content_like(qr/$_ is required/i) for @fieldnames;
68 # submit a form with with stuff in it and check was OK
69 $mech->submit_form_ok({
70 form_name
=> 'contactForm',
72 name
=> 'Test Tester',
73 email
=> 'test@example.com',
74 subject
=> 'Testing contact form',
75 body
=> 'this is a test of the SGN contact form',
76 contact_form_human_answer
=> $mech->context->get_conf("contact_form_human_answer"),
79 $mech->content_like(qr/your message has been sent/i);