Tweaks to trials.mas: hides breeding program table in non-accession stocks and rename...
[sgn.git] / t / legacy / integration / contact.t
blob759daab68e9b24c0a234880cc6dbada2fb895d1a
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
5 # Note: this test depends on the env variable $SGN_TEST_MODE
6 # being set to 1 in the server process
8 use Test::More;
10 use lib 't/lib';
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' },
21 sub {
22 my $user = shift;
23 form_basic_ok( $mech, $form_url );
24 form_has_user_defaults( $mech, $user );
25 submit_form_ok( $mech, $form_url );
29 done_testing;
30 exit;
32 # check contact form displays OK
33 sub form_basic_ok {
34 my ( $mech, $form_url ) = @_;
35 $mech->get_ok( $form_url );
36 $mech->content_contains( $_ ) for (
37 'Name',
38 'Email',
39 'Subject',
40 'Body',
41 'name="name"',
42 'name="subject"',
43 'name="body"',
44 '<textarea',
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}/;
53 sub submit_form_ok {
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',
60 fields => {
61 map { $_ => ''}
62 @fieldnames
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',
71 fields => {
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"),
78 });
79 $mech->content_like(qr/your message has been sent/i);