3 # This file is part of Koha.
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.
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.
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>.
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 all the sample data checked!
25 use Test::More tests => 2;
30 my $superlibrarian = {
50 eval { require Selenium::Remote::Driver; };
51 skip "Selenium::Remote::Driver is needed for selenium tests.", 2 if $@;
53 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};
55 my $dbh = eval { C4::Context->dbh; };
56 skip "Tests won't run if the database does not exist", 2 if $@;
61 open STDERR, ">>", \$dup_err;
63 SELECT * FROM systempreferences WHERE 1 = 0 |
67 skip "Tests won't run if the database is not empty", 2 if $@;
71 my $s = t::lib::Selenium->new;
73 my $driver = $s->driver;
74 my $base_url = $s->base_url;
75 my $db_user = C4::Context->config('user');
76 my $db_pass = C4::Context->config('pass');
78 $driver->get($base_url."mainpage.pl");
80 my $lang = "en"; # The idea here is to loop on all languages
82 $driver->set_window_size(3840,1080);
83 # Welcome to the Koha web installer
84 $s->fill_form({userid => $db_user, password => $db_pass });
87 # Choose your language
88 $s->fill_form({ language => $languages->{$lang} });
91 # Check Perl dependencies
98 # Connection established
99 $s->driver->find_element('//div[@class="alert alert-success"]');
106 # Database tables created
107 $s->driver->find_element('//div[@class="alert alert-success"]');
110 # Install basic configuration settings
113 # Select your MARC flavor
114 $s->fill_form({ marcflavour => 'MARC21' });
117 # Selecting default settings
118 my @checkboxes = $driver->find_elements('//input[@type="checkbox" and not(@checked="checked")]');
119 for my $c ( @checkboxes ) {
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|;
130 # Default data loaded
133 my $RequireStrongPassword = C4::Context->preference('RequireStrongPassword');
134 my $minPasswordLength = C4::Context->preference('minPasswordLength');
135 C4::Context->set_preference('RequireStrongPassword', 0 );
136 C4::Context->set_preference('minPasswordLength', 3 );
138 # Installation complete
139 $s->click( { href => '/installer/onboarding.pl', main => 'installer-step3' } );
141 # Create Koha administrator patron
142 $s->fill_form({ %$superlibrarian, password2 => $superlibrarian->{password} });
144 C4::Context->set_preference('RequireStrongPassword', $RequireStrongPassword );
145 C4::Context->set_preference('minPasswordLength', $minPasswordLength );
147 # Create a new circulation rule
148 # Keep default values
151 # Get the interface in the correct language
152 C4::Context->set_preference('language', $languages->{$lang} );
153 C4::Context->set_preference('opaclanguages', $languages->{$lang} );
155 $s->click( { href => '/mainpage.pl', main => 'onboarding-step5' } );
157 $s->fill_form({ userid => $superlibrarian->{userid}, password => $superlibrarian->{password} });
159 like( $s->driver->get_title, qr(Log in to Koha), 'After the onboarding process the user should have landed in the login form page');
162 is( $s->driver->get_title, 'Koha staff interface', 'The credentials we created should work');