fix ticketing system error on bootstrap of new install
[freeside.git] / rt / t / web / install.t
1 use strict;
2 use warnings;
3 use File::Spec;
4
5 $ENV{RT_TEST_WEB_HANDLER} = 'plack+rt-server';
6 use RT::Test
7     tests     => undef,
8     nodb      => 1,
9     server_ok => 1;
10
11 my $dbname     = 'rt4test_install_xxx';
12 my $rtname     = 'rttestname';
13 my $domain     = 'rttes.com';
14 my $password   = 'newpass';
15 my $correspond = 'reply@example.com';
16 my $comment    = 'comment@example.com';
17
18 # use bin/rt to fake sendmail to make sure the file exists
19 my $sendmail = File::Spec->catfile( $RT::BinPath, 'rt' );
20 my $owner = 'root@localhost';
21
22 unlink File::Spec->catfile( $RT::VarPath, $dbname );
23
24 my ( $url, $m ) = RT::Test->started_ok;
25 $m->warning_like(qr/If this is a new installation of RT/,
26                  "Got startup warning");
27
28 my ($port) = $url =~ /:(\d+)/;
29 $m->get_ok($url);
30
31 is( $m->uri, $url . '/Install/index.html', 'install page' );
32 $m->select( 'Lang', 'zh-cn' );
33 $m->click('ChangeLang');
34 $m->content_contains( Encode::decode("UTF-8",'语言'), 'select chinese' );
35
36 $m->click('Run');
37 $m->content_contains( Encode::decode("UTF-8",'数据库'), 'select db type in chinese' );
38
39 $m->back;
40 $m->select( 'Lang', 'en' );
41 $m->click('ChangeLang');
42 $m->content_contains( 'Select another language', 'back to english' );
43
44 $m->click('Run');
45
46 is( $m->uri, $url . '/Install/DatabaseType.html', 'db type page' );
47 my $select_type    = $m->current_form->find_input('DatabaseType');
48 my @possible_types = $select_type->possible_values;
49 ok( @possible_types, 'we have at least 1 db type' );
50
51 SKIP: {
52     skip 'no mysql found', 7 unless grep { /mysql/ } @possible_types;
53     $m->select( 'DatabaseType', 'mysql' );
54     $m->click;
55     for my $field (qw/Name Host Port Admin AdminPassword User Password/) {
56         ok( $m->current_form->find_input("Database$field"),
57             "db mysql has field Database$field" );
58     }
59     $m->back;
60 }
61
62 SKIP: {
63     skip 'no pg found', 8 unless grep { /Pg/ } @possible_types;
64     $m->select( 'DatabaseType', 'Pg' );
65     $m->click;
66     for my $field (
67         qw/Name Host Port Admin AdminPassword User Password/)
68     {
69         ok( $m->current_form->find_input("Database$field"),
70             "db Pg has field Database$field" );
71     }
72     $m->back;
73 }
74
75 $m->select( 'DatabaseType', 'SQLite' );
76 $m->click;
77
78 is( $m->uri, $url . '/Install/DatabaseDetails.html', 'db details page' );
79 $m->field( 'DatabaseName' => $dbname );
80 $m->submit_form( fields => { DatabaseName => $dbname } );
81 $m->content_contains( 'Connection succeeded', 'succeed msg' );
82 $m->content_contains(
83 qq{$dbname already exists, but does not contain RT's tables or metadata. The 'Initialize Database' step later on can insert tables and metadata into this existing database. if this is acceptable, click 'Customize Basic' below to continue customizing RT.},
84     'more db state msg'
85 );
86 $m->click;
87
88 is( $m->uri, $url . '/Install/Basics.html', 'basics page' );
89 $m->click;
90 $m->content_contains(
91     'You must enter an Administrative password',
92     "got password can't be empty error"
93 );
94
95 for my $field (qw/rtname WebDomain WebPort Password/) {
96     ok( $m->current_form->find_input($field), "has field $field" );
97 }
98 is( $m->value('WebPort'), $port, 'default port' );
99 $m->field( 'rtname'    => $rtname );
100 $m->field( 'WebDomain' => $domain );
101 $m->field( 'Password'  => $password );
102 $m->click;
103
104 is( $m->uri, $url . '/Install/Sendmail.html', 'mail page' );
105 for my $field (qw/SendmailPath OwnerEmail/) {
106     ok( $m->current_form->find_input($field), "has field $field" );
107 }
108
109 $m->field( 'OwnerEmail' => '' );
110 $m->click;
111 $m->content_contains( "doesn't look like an email address",
112     'got email error' );
113
114 $m->field( 'SendmailPath' => '/fake/path/sendmail' );
115 $m->click;
116 $m->content_contains( "/fake/path/sendmail doesn't exist",
117     'got sendmail error' );
118
119 $m->field( 'SendmailPath' => $sendmail );
120 $m->field( 'OwnerEmail'   => $owner );
121 $m->click;
122
123 is( $m->uri, $url . '/Install/Global.html', 'global page' );
124 for my $field (qw/CommentAddress CorrespondAddress/) {
125     ok( $m->current_form->find_input($field), "has field $field" );
126 }
127
128 $m->click;
129 is( $m->uri, $url . '/Install/Initialize.html', 'init db page' );
130 $m->back;
131
132 is( $m->uri, $url . '/Install/Global.html', 'global page' );
133 $m->field( 'CorrespondAddress' => 'reply' );
134 $m->click;
135 $m->content_contains( "doesn't look like an email address",
136     'got email error' );
137 $m->field( 'CommentAddress' => 'comment' );
138 $m->click;
139 $m->content_contains( "doesn't look like an email address",
140     'got email error' );
141
142 $m->field( 'CorrespondAddress' => 'reply@example.com' );
143 $m->field( 'CommentAddress'    => 'comment@example.com' );
144 $m->click;
145
146 is( $m->uri, $url . '/Install/Initialize.html', 'init db page' );
147 $m->click;
148
149 is( $m->uri, $url . '/Install/Finish.html', 'finish page' );
150 $m->click;
151
152 is( $m->uri, $url . '/', 'home page' );
153 $m->login( 'root', $password );
154 $m->content_contains( 'RT at a glance', 'logged in with newpass' );
155
156 RT->LoadConfig;
157 my $config = RT->Config;
158
159 is( $config->Get('DatabaseType'), 'SQLite',  'DatabaseType in config' );
160 is( $config->Get('DatabaseName'), $dbname,   'DatabaseName in config' );
161 is( $config->Get('rtname'),       $rtname,   'rtname in config' );
162 is( $config->Get('WebDomain'),    $domain,   'WebDomain email in config' );
163 is( $config->Get('WebPort'),      $port,     'WebPort email in config' );
164 is( $config->Get('SendmailPath'), $sendmail, 'SendmailPath in config' );
165 is( $config->Get('OwnerEmail'),   $owner,    'OwnerEmail in config' );
166 is( $config->Get('CorrespondAddress'),
167     $correspond, 'correspond address in config' );
168 is( $config->Get('CommentAddress'), $comment, 'comment address in config' );
169
170 unlink File::Spec->catfile( $RT::VarPath, $dbname );
171
172 undef $m;
173 done_testing;