summaryrefslogtreecommitdiff
path: root/rt/t/web/install.t
blob: e33e58b161b22e5d86ad82e8c61dbeafeaf088d6 (plain)
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
use strict;
use warnings;
use File::Spec;

$ENV{RT_TEST_WEB_HANDLER} = 'plack+rt-server';
use RT::Test
    tests     => undef,
    nodb      => 1,
    server_ok => 1;

my $dbname     = 'rt4test_install_xxx';
my $rtname     = 'rttestname';
my $domain     = 'rttes.com';
my $password   = 'newpass';
my $correspond = 'reply@example.com';
my $comment    = 'comment@example.com';

# use bin/rt to fake sendmail to make sure the file exists
my $sendmail = File::Spec->catfile( $RT::BinPath, 'rt' );
my $owner = 'root@localhost';

unlink File::Spec->catfile( $RT::VarPath, $dbname );

my ( $url, $m ) = RT::Test->started_ok;
$m->warning_like(qr/If this is a new installation of RT/,
                 "Got startup warning");

my ($port) = $url =~ /:(\d+)/;
$m->get_ok($url);

is( $m->uri, $url . '/Install/index.html', 'install page' );
$m->select( 'Lang', 'zh-cn' );
$m->click('ChangeLang');
$m->content_contains( Encode::decode("UTF-8",'语言'), 'select chinese' );

$m->click('Run');
$m->content_contains( Encode::decode("UTF-8",'数据库'), 'select db type in chinese' );

$m->back;
$m->select( 'Lang', 'en' );
$m->click('ChangeLang');
$m->content_contains( 'Select another language', 'back to english' );

$m->click('Run');

is( $m->uri, $url . '/Install/DatabaseType.html', 'db type page' );
my $select_type    = $m->current_form->find_input('DatabaseType');
my @possible_types = $select_type->possible_values;
ok( @possible_types, 'we have at least 1 db type' );

SKIP: {
    skip 'no mysql found', 7 unless grep { /mysql/ } @possible_types;
    $m->select( 'DatabaseType', 'mysql' );
    $m->click;
    for my $field (qw/Name Host Port Admin AdminPassword User Password/) {
        ok( $m->current_form->find_input("Database$field"),
            "db mysql has field Database$field" );
    }
    $m->back;
}

SKIP: {
    skip 'no pg found', 8 unless grep { /Pg/ } @possible_types;
    $m->select( 'DatabaseType', 'Pg' );
    $m->click;
    for my $field (
        qw/Name Host Port Admin AdminPassword User Password/)
    {
        ok( $m->current_form->find_input("Database$field"),
            "db Pg has field Database$field" );
    }
    $m->back;
}

$m->select( 'DatabaseType', 'SQLite' );
$m->click;

is( $m->uri, $url . '/Install/DatabaseDetails.html', 'db details page' );
$m->field( 'DatabaseName' => $dbname );
$m->submit_form( fields => { DatabaseName => $dbname } );
$m->content_contains( 'Connection succeeded', 'succeed msg' );
$m->content_contains(
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.},
    'more db state msg'
);
$m->click;

is( $m->uri, $url . '/Install/Basics.html', 'basics page' );
$m->click;
$m->content_contains(
    'You must enter an Administrative password',
    "got password can't be empty error"
);

for my $field (qw/rtname WebDomain WebPort Password/) {
    ok( $m->current_form->find_input($field), "has field $field" );
}
is( $m->value('WebPort'), $port, 'default port' );
$m->field( 'rtname'    => $rtname );
$m->field( 'WebDomain' => $domain );
$m->field( 'Password'  => $password );
$m->click;

is( $m->uri, $url . '/Install/Sendmail.html', 'mail page' );
for my $field (qw/SendmailPath OwnerEmail/) {
    ok( $m->current_form->find_input($field), "has field $field" );
}

$m->field( 'OwnerEmail' => '' );
$m->click;
$m->content_contains( "doesn't look like an email address",
    'got email error' );

$m->field( 'SendmailPath' => '/fake/path/sendmail' );
$m->click;
$m->content_contains( "/fake/path/sendmail doesn't exist",
    'got sendmail error' );

$m->field( 'SendmailPath' => $sendmail );
$m->field( 'OwnerEmail'   => $owner );
$m->click;

is( $m->uri, $url . '/Install/Global.html', 'global page' );
for my $field (qw/CommentAddress CorrespondAddress/) {
    ok( $m->current_form->find_input($field), "has field $field" );
}

$m->click;
is( $m->uri, $url . '/Install/Initialize.html', 'init db page' );
$m->back;

is( $m->uri, $url . '/Install/Global.html', 'global page' );
$m->field( 'CorrespondAddress' => 'reply' );
$m->click;
$m->content_contains( "doesn't look like an email address",
    'got email error' );
$m->field( 'CommentAddress' => 'comment' );
$m->click;
$m->content_contains( "doesn't look like an email address",
    'got email error' );

$m->field( 'CorrespondAddress' => 'reply@example.com' );
$m->field( 'CommentAddress'    => 'comment@example.com' );
$m->click;

is( $m->uri, $url . '/Install/Initialize.html', 'init db page' );
$m->click;

is( $m->uri, $url . '/Install/Finish.html', 'finish page' );
$m->click;

is( $m->uri, $url . '/', 'home page' );
$m->login( 'root', $password );
$m->content_contains( 'RT at a glance', 'logged in with newpass' );

RT->LoadConfig;
my $config = RT->Config;

is( $config->Get('DatabaseType'), 'SQLite',  'DatabaseType in config' );
is( $config->Get('DatabaseName'), $dbname,   'DatabaseName in config' );
is( $config->Get('rtname'),       $rtname,   'rtname in config' );
is( $config->Get('WebDomain'),    $domain,   'WebDomain email in config' );
is( $config->Get('WebPort'),      $port,     'WebPort email in config' );
is( $config->Get('SendmailPath'), $sendmail, 'SendmailPath in config' );
is( $config->Get('OwnerEmail'),   $owner,    'OwnerEmail in config' );
is( $config->Get('CorrespondAddress'),
    $correspond, 'correspond address in config' );
is( $config->Get('CommentAddress'), $comment, 'comment address in config' );

unlink File::Spec->catfile( $RT::VarPath, $dbname );

undef $m;
done_testing;