Bug 19185: Fix tests
[koha-ffzg.git] / t / db_dependent / selenium / 00-installation.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 use Modern::Perl;
19
20 use Test::More tests => 2;
21
22 use t::lib::Selenium;
23 use C4::Context;
24
25 my $superlibrarian = {
26     surname    => 'Super',
27     firstname  => 'Librarian',
28     cardnumber => '143749305',
29     userid     => 'SuperL',
30     password   => 'aA1bB2cC3dD4'
31 };
32 my $languages = {
33     en    => 'en',
34     ar    => 'ar-Arab',
35     es    => 'es-ES',
36     fr    => 'fr-FR',
37     it    => 'it-IT',
38     pt_BR => 'pt-BR',
39     tr    => 'tr-TR',
40     zh_TW => 'zh-Hans-TW'
41 };
42
43 SKIP: {
44     eval { require Selenium::Remote::Driver; };
45     skip "Selenium::Remote::Driver is needed for selenium tests.", 2 if $@;
46
47     my $s = t::lib::Selenium->new;
48
49     my $driver = $s->driver;
50     my $base_url = $s->base_url;
51     my $db_user = C4::Context->config('user');
52     my $db_pass = C4::Context->config('pass');
53
54     $driver->get($base_url."mainpage.pl");
55
56     my $lang = "en"; # The idea here is to loop on all languages
57
58     $driver->set_window_size(3840,1080);
59     # Welcome to the Koha web installer
60     $s->fill_form({userid => $db_user, password => $db_pass });
61     $s->submit_form;
62
63     # Choose your language
64     $s->fill_form({ language => $languages->{$lang} });
65     $s->submit_form;
66
67     # Check Perl dependencies
68     $s->submit_form;
69
70     # Database settings
71     $s->submit_form;
72
73     # Database settings
74     # Connection established
75     $s->driver->find_element('//div[@class="alert alert-success"]');
76     $s->submit_form;
77
78     # Set up database
79     $s->submit_form;
80
81     # Success
82     # Database tables created
83     $s->driver->find_element('//div[@class="alert alert-success"]');
84     $s->submit_form;
85
86     # Install basic configuration settings
87     $s->submit_form;
88
89     # Select your MARC flavor
90     $s->fill_form({ marcflavour => 'MARC21' });
91     $s->submit_form;
92
93     # Selecting default settings
94     # Do not check otherwise no onboarding
95     #my @checkboxes = $driver->find_elements('//input[@type="checkbox" and not(@checked="checked")]');
96     #for my $c ( @checkboxes ) {
97     #    $c->click;
98     #}
99     $s->submit_form;
100
101     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
102         my $title = $s->driver->get_title;
103         last if $title =~ m|Default data loaded|;
104         sleep 1;
105     }
106
107     # Default data loaded
108     $s->submit_form;
109
110     $s->click( { href => '/installer/onboarding.pl', main => 'installer-step3' } );
111
112     # Create a library
113     $s->fill_form({ branchcode => 'CPL', branchname => 'Centerville' });
114     $s->submit_form;
115
116     # Library created!
117     $s->driver->find_element('//div[@class="alert alert-success"]');
118     # Create a patron category
119     $s->fill_form({ categorycode => 'S', description => 'Staff', enrolmentperiod => 12 });
120     $s->submit_form;
121
122     # Patron category created!
123     $s->driver->find_element('//div[@class="alert alert-success"]');
124     # Create Koha administrator patron
125     $s->fill_form({ %$superlibrarian, password2 => $superlibrarian->{password} });
126     $s->submit_form;
127
128     #Administrator account created!
129     $s->driver->find_element('//div[@class="alert alert-success"]');
130     # Create a new item type
131     $s->fill_form({ itemtype => 'BK', description => 'Book' });
132     $s->submit_form;
133
134     # New item type created!
135     $s->driver->find_element('//div[@class="alert alert-success"]');
136     # Create a new circulation rule
137     # Keep default values
138     $s->submit_form;
139
140     # Get the interface in the correct language
141     C4::Context->set_preference('language', $languages->{$lang} );
142     C4::Context->set_preference('opaclanguages', $languages->{$lang} );
143
144     $s->click( { href => '/mainpage.pl', main => 'onboarding-step5' } );
145
146     $s->fill_form({ userid => $superlibrarian->{userid}, password => $superlibrarian->{password} });
147
148     like( $s->driver->get_title, qr(Log in to Koha), 'After the onboarding process the user should have landed in the login form page');
149     $s->submit_form;
150
151     is( $s->driver->get_title, 'Koha staff interface', 'The credentials we created should work');
152
153     $driver->quit();
154 };