Bug 19185: Add missing +x on new test files
[koha.git] / t / db_dependent / selenium / 00-onboarding.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 # This test file is made to be run by our CI
19 # - KOHA_TESTING must be set
20 # - the database must exist but be empty
21 # It will go through the installer process with only the mandatory sample data checked, to test the onboarding process
22
23 use Modern::Perl;
24
25 use Test::More tests => 2;
26
27 use t::lib::Selenium;
28 use C4::Context;
29
30 my $superlibrarian = {
31     surname    => 'Super',
32     firstname  => 'Librarian',
33     cardnumber => '143749305',
34     userid     => 'SuperL',
35     password   => 'aA1bB2cC3dD4'
36 };
37 my $languages = {
38     en    => 'en',
39     ar    => 'ar-Arab',
40     es    => 'es-ES',
41     fr    => 'fr-FR',
42     it    => 'it-IT',
43     pt_BR => 'pt-BR',
44     tr    => 'tr-TR',
45     zh_TW => 'zh-Hans-TW'
46 };
47
48 SKIP: {
49     eval { require Selenium::Remote::Driver; };
50     skip "Selenium::Remote::Driver is needed for selenium tests.", 2 if $@;
51
52     skip "This test must be run with an empty DB. We are using KOHA_TESTING that is set by our CI\nIf you really want to run it, set this env var.", 2 unless $ENV{KOHA_TESTING};
53
54     my $dbh = eval { C4::Context->dbh; };
55     skip "Tests won't run if the database does not exist", 2 if $@;
56
57     {
58         my $dup_err;
59         local *STDERR;
60         open STDERR, ">>", \$dup_err;
61         $dbh->do(q|
62             SELECT * FROM systempreferences WHERE 1 = 0 |
63         );
64         close STDERR;
65         if ( $dup_err ) {
66             skip "Tests won't run if the database is not empty", 2 if $@;
67         }
68     }
69
70     my $s = t::lib::Selenium->new;
71
72     my $driver = $s->driver;
73     my $base_url = $s->base_url;
74     my $db_user = C4::Context->config('user');
75     my $db_pass = C4::Context->config('pass');
76
77     $driver->get($base_url."mainpage.pl");
78
79     my $lang = "en"; # The idea here is to loop on all languages
80
81     $driver->set_window_size(3840,1080);
82     # Welcome to the Koha web installer
83     $s->fill_form({userid => $db_user, password => $db_pass });
84     $s->submit_form;
85
86     # Choose your language
87     $s->fill_form({ language => $languages->{$lang} });
88     $s->submit_form;
89
90     # Check Perl dependencies
91     $s->submit_form;
92
93     # Database settings
94     $s->submit_form;
95
96     # Database settings
97     # Connection established
98     $s->driver->find_element('//div[@class="alert alert-success"]');
99     $s->submit_form;
100
101     # Set up database
102     $s->submit_form;
103
104     # Success
105     # Database tables created
106     $s->driver->find_element('//div[@class="alert alert-success"]');
107     $s->submit_form;
108
109     # Install basic configuration settings
110     $s->submit_form;
111
112     # Select your MARC flavor
113     $s->fill_form({ marcflavour => 'MARC21' });
114     $s->submit_form;
115
116     # Selecting default settings
117     # Do not check otherwise no onboarding
118     #my @checkboxes = $driver->find_elements('//input[@type="checkbox" and not(@checked="checked")]');
119     #for my $c ( @checkboxes ) {
120     #    $c->click;
121     #}
122     $s->submit_form;
123
124     for (1..20){ # FIXME This is really ugly, but for an unknown reason the next submit_form is resubmitting the same form. So waiting for the next page to be effectively loaded
125         my $title = $s->driver->get_title;
126         last if $title =~ m|Default data loaded|;
127         sleep 1;
128     }
129
130     # Default data loaded
131     $s->submit_form;
132
133     # Installation complete
134     $s->click( { href => '/installer/onboarding.pl', main => 'installer-step3' } );
135
136     # Create a library
137     $s->fill_form({ branchcode => 'CPL', branchname => 'Centerville' });
138     $s->submit_form;
139
140     # Library created!
141     $s->driver->find_element('//div[@class="alert alert-success"]');
142     # Create a patron category
143     $s->fill_form({ categorycode => 'S', description => 'Staff', enrolmentperiod => 12 });
144     $s->submit_form;
145
146     # Patron category created!
147     $s->driver->find_element('//div[@class="alert alert-success"]');
148     # Create Koha administrator patron
149     $s->fill_form({ %$superlibrarian, password2 => $superlibrarian->{password} });
150     $s->submit_form;
151
152     #Administrator account created!
153     $s->driver->find_element('//div[@class="alert alert-success"]');
154     # Create a new item type
155     $s->fill_form({ itemtype => 'BK', description => 'Book' });
156     $s->submit_form;
157
158     # New item type created!
159     $s->driver->find_element('//div[@class="alert alert-success"]');
160     # Create a new circulation rule
161     # Keep default values
162     $s->submit_form;
163
164     # Get the interface in the correct language
165     C4::Context->set_preference('language', $languages->{$lang} );
166     C4::Context->set_preference('opaclanguages', $languages->{$lang} );
167
168     $s->click( { href => '/mainpage.pl', main => 'onboarding-step5' } );
169
170     $s->fill_form({ userid => $superlibrarian->{userid}, password => $superlibrarian->{password} });
171
172     like( $s->driver->get_title, qr(Log in to Koha), 'After the onboarding process the user should have landed in the login form page');
173     $s->submit_form;
174
175     is( $s->driver->get_title, 'Koha staff interface', 'The credentials we created should work');
176
177     $driver->quit();
178 };