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 only the mandatory sample data checked, to test the onboarding process
25 use Test::More tests => 2;
30 my $superlibrarian = {
32 firstname => 'Librarian',
33 cardnumber => '143749305',
35 password => 'aA1bB2cC3dD4'
49 eval { require Selenium::Remote::Driver; };
50 skip "Selenium::Remote::Driver is needed for selenium tests.", 2 if $@;
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};
54 my $dbh = eval { C4::Context->dbh; };
55 skip "Tests won't run if the database does not exist", 2 if $@;
60 open STDERR, ">>", \$dup_err;
62 SELECT * FROM systempreferences WHERE 1 = 0 |
66 skip "Tests won't run if the database is not empty", 2 if $@;
70 my $s = t::lib::Selenium->new;
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');
77 $driver->get($base_url."mainpage.pl");
79 my $lang = "en"; # The idea here is to loop on all languages
81 $driver->set_window_size(3840,1080);
82 # Welcome to the Koha web installer
83 $s->fill_form({userid => $db_user, password => $db_pass });
86 # Choose your language
87 $s->fill_form({ language => $languages->{$lang} });
90 # Check Perl dependencies
97 # Connection established
98 $s->driver->find_element('//div[@class="alert alert-success"]');
105 # Database tables created
106 $s->driver->find_element('//div[@class="alert alert-success"]');
109 # Install basic configuration settings
112 # Select your MARC flavor
113 $s->fill_form({ marcflavour => 'MARC21' });
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 ) {
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 # Installation complete
134 $s->click( { href => '/installer/onboarding.pl', main => 'installer-step3' } );
137 $s->fill_form({ branchcode => 'CPL', branchname => 'Centerville' });
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 });
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} });
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' });
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
164 # Get the interface in the correct language
165 C4::Context->set_preference('language', $languages->{$lang} );
166 C4::Context->set_preference('opaclanguages', $languages->{$lang} );
168 $s->click( { href => '/mainpage.pl', main => 'onboarding-step5' } );
170 $s->fill_form({ userid => $superlibrarian->{userid}, password => $superlibrarian->{password} });
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');
175 is( $s->driver->get_title, 'Koha staff interface', 'The credentials we created should work');