|
Line 0
Link Here
|
| 0 |
- |
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 all the sample data checked! |
| 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 => 'koha', |
| 32 |
firstname => 'koha', |
| 33 |
cardnumber => '42', |
| 34 |
userid => 'koha', |
| 35 |
password => 'koha' |
| 36 |
}; |
| 37 |
|
| 38 |
my $languages = { |
| 39 |
en => 'en', |
| 40 |
ar => 'ar-Arab', |
| 41 |
es => 'es-ES', |
| 42 |
fr => 'fr-FR', |
| 43 |
it => 'it-IT', |
| 44 |
pt_BR => 'pt-BR', |
| 45 |
tr => 'tr-TR', |
| 46 |
zh_TW => 'zh-Hans-TW' |
| 47 |
}; |
| 48 |
|
| 49 |
SKIP: { |
| 50 |
eval { require Selenium::Remote::Driver; }; |
| 51 |
skip "Selenium::Remote::Driver is needed for selenium tests.", 2 if $@; |
| 52 |
|
| 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}; |
| 54 |
|
| 55 |
my $dbh = eval { C4::Context->dbh; }; |
| 56 |
skip "Tests won't run if the database does not exist", 2 if $@; |
| 57 |
|
| 58 |
{ |
| 59 |
my $dup_err; |
| 60 |
local *STDERR; |
| 61 |
open STDERR, ">>", \$dup_err; |
| 62 |
$dbh->do(q| |
| 63 |
SELECT * FROM systempreferences WHERE 1 = 0 | |
| 64 |
); |
| 65 |
close STDERR; |
| 66 |
if ( $dup_err ) { |
| 67 |
skip "Tests won't run if the database is not empty", 2 if $@; |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
my $s = t::lib::Selenium->new; |
| 72 |
|
| 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'); |
| 77 |
|
| 78 |
$driver->get($base_url."mainpage.pl"); |
| 79 |
|
| 80 |
my $lang = "en"; # The idea here is to loop on all languages |
| 81 |
|
| 82 |
$driver->set_window_size(3840,1080); |
| 83 |
# Welcome to the Koha web installer |
| 84 |
$s->fill_form({userid => $db_user, password => $db_pass }); |
| 85 |
$s->submit_form; |
| 86 |
|
| 87 |
# Choose your language |
| 88 |
$s->fill_form({ language => $languages->{$lang} }); |
| 89 |
$s->submit_form; |
| 90 |
|
| 91 |
# Check Perl dependencies |
| 92 |
$s->submit_form; |
| 93 |
|
| 94 |
# Database settings |
| 95 |
$s->submit_form; |
| 96 |
|
| 97 |
# Database settings |
| 98 |
# Connection established |
| 99 |
$s->driver->find_element('//div[@class="alert alert-success"]'); |
| 100 |
$s->submit_form; |
| 101 |
|
| 102 |
# Set up database |
| 103 |
$s->submit_form; |
| 104 |
|
| 105 |
# Success |
| 106 |
# Database tables created |
| 107 |
$s->driver->find_element('//div[@class="alert alert-success"]'); |
| 108 |
$s->submit_form; |
| 109 |
|
| 110 |
# Install basic configuration settings |
| 111 |
$s->submit_form; |
| 112 |
|
| 113 |
# Select your MARC flavor |
| 114 |
$s->fill_form({ marcflavour => 'MARC21' }); |
| 115 |
$s->submit_form; |
| 116 |
|
| 117 |
# Selecting default settings |
| 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 |
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 ); |
| 137 |
|
| 138 |
# Installation complete |
| 139 |
$s->click( { href => '/installer/onboarding.pl', main => 'installer-step3' } ); |
| 140 |
|
| 141 |
# Create Koha administrator patron |
| 142 |
$s->fill_form({ %$superlibrarian, password2 => $superlibrarian->{password} }); |
| 143 |
$s->submit_form; |
| 144 |
C4::Context->set_preference('RequireStrongPassword', $RequireStrongPassword ); |
| 145 |
C4::Context->set_preference('minPasswordLength', $minPasswordLength ); |
| 146 |
|
| 147 |
# Create a new circulation rule |
| 148 |
# Keep default values |
| 149 |
$s->submit_form; |
| 150 |
|
| 151 |
# Get the interface in the correct language |
| 152 |
C4::Context->set_preference('language', $languages->{$lang} ); |
| 153 |
C4::Context->set_preference('opaclanguages', $languages->{$lang} ); |
| 154 |
|
| 155 |
$s->click( { href => '/mainpage.pl', main => 'onboarding-step5' } ); |
| 156 |
|
| 157 |
$s->fill_form({ userid => $superlibrarian->{userid}, password => $superlibrarian->{password} }); |
| 158 |
|
| 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'); |
| 160 |
$s->submit_form; |
| 161 |
|
| 162 |
is( $s->driver->get_title, 'Koha staff interface', 'The credentials we created should work'); |
| 163 |
|
| 164 |
$driver->quit(); |
| 165 |
}; |