Bug 26384: Fix executable flags
[koha.git] / t / db_dependent / selenium / administration_tasks.t
blob080bb38912d4408f3552f9268e43a12e818ba7b9
1 #!/usr/bin/perl
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 selenium test tests the Koha Administration module functionality including adding circ rules, item types and modifying frameworks
20 #Note: If you are testing this on kohadevbox with selenium installed in kohadevbox then you need to set the staffClientBaseURL to localhost:8080 and the OPACBaseURL to http://localhost:80
22 use Modern::Perl;
24 use C4::Context;
26 use Test::More tests => 3;
28 use t::lib::Selenium;
29 use t::lib::TestBuilder;
31 my $builder = t::lib::TestBuilder->new;
33 my $login = $ENV{KOHA_USER} || 'koha';
35 my $itemtype = 'UT_DVD';
36 my $frameworkcode = 'UTFW'; # frameworkcode is only 4 characters max!
37 my $branchcode = 'UT_BC';
38 my $av_category = 'AV_CAT_TEST';
39 my $category_code = 'PATRON_CAT';
40 our ($cleanup_needed);
42 SKIP: {
43 eval { require Selenium::Remote::Driver; };
44 skip "Selenium::Remote::Driver is needed for selenium tests.", 1 if $@;
46 $cleanup_needed = 1;
48 my $s = t::lib::Selenium->new;
49 my $driver = $s->driver;
50 my $mainpage = $s->base_url . q|mainpage.pl|;
51 $driver->get($mainpage);
52 like( $driver->get_title(), qr(Log in to Koha), );
53 $s->auth;
54 { # Item types
55 # Navigate to the Administration area and create an item type
56 $s->click( { href => '/admin/admin-home.pl', main => 'container-main' } )
57 ; # Koha administration
58 $s->click( { href => '/admin/itemtypes.pl', main_class => 'main container-fluid' } ); # Item Types
59 $s->click( { href => '/admin/itemtypes.pl?op=add_form', main_class => 'main container-fluid' } )
60 ; # New item type
61 $s->fill_form(
62 { itemtype => $itemtype, description => "Digital Optical Disc" } );
63 $s->submit_form;
64 $s->click(
66 href => '/admin/itemtypes.pl?op=add_form&itemtype=' . $itemtype,
67 main_class => 'main container-fluid'
69 ); # New item type
72 { # Circulation/fine rules
73 my $itype = $builder->build_object({ class => "Koha::ItemTypes" });
74 $driver->get($mainpage);
75 $s->click( { href => '/admin/admin-home.pl', main => 'container-main' } )
76 ; # Koha administration
77 $s->click( { href => '/admin/smart-rules.pl', main_class => 'main container-fluid' } )
78 ; # Circulation and fines rules
79 my $elt = $driver->find_element('//tr[@id="edit_row"]/td/select[@id="matrixitemtype"]/option[@value="'.$itype->itemtype.'"]');
80 is( $elt->get_text(),$itype->description,"Our new itemtype is in the list");
81 $elt->click();
82 $elt = $driver->find_element('//tr[@id="edit_row"]/td[@class="actions"]/button[@type="submit"]');
83 $elt->click();
84 $elt = $driver->find_elements('//table[@id="default-circulation-rules"]/tbody/tr/td[contains(text(),"'.$itype->description.'")]/following-sibling::td/span[text() = "Unlimited"]');
85 is( @$elt, 5, "We have unlimited checkouts and holds" );
86 #Clean up
87 Koha::CirculationRules->search( { itemtype => $itype->itemtype } )->delete;
88 $itype->delete;
89 # TODO Create more smart rules navigation here
92 { # Biblio frameworks
93 $driver->get($mainpage);
94 $s->click( { href => '/admin/admin-home.pl', main => 'container-main' } )
95 ; # Koha administration
96 $s->click( { href => '/admin/biblio_framework.pl', main_class => 'main container-fluid' } )
97 ; # MARC bibliographic framework
98 $s->click(
99 { href => '/admin/biblio_framework.pl?op=add_form', main_class => 'main container-fluid' } )
100 ; # New framework
101 $s->fill_form(
103 frameworkcode => $frameworkcode,
104 description => 'just a description'
107 $s->submit_form;
108 $s->click( { id => 'frameworkactions' . $frameworkcode } );
109 $s->click(
111 href => 'marctagstructure.pl?frameworkcode=' . $frameworkcode,
112 main_class => 'main container-fluid'
114 ); # MARC structure # FIXME '/admin/' is missing in the url
115 # TODO Click on OK to create the MARC structure
118 { #Libraries
119 $driver->get($mainpage);
120 $s->click( { href => '/admin/admin-home.pl', main => 'container-main' } )
121 ; # Koha administration
122 $s->click( { href => '/admin/branches.pl', main_class => 'main container-fluid' } )
123 ; # Libraries and groups
124 $s->click( { href => '/admin/branches.pl?op=add_form', main_class => 'main container-fluid' } )
125 ; # New library
126 $s->fill_form( { branchcode => $branchcode, branchname => 'my library' } );
127 $s->submit_form;
129 # Select "Show all" in the datatable "Show x entries" dropdown list to make sure our library is not hidden
130 $s->show_all_entries('//div[@id="libraries_wrapper"]');
131 $s->click(
133 href => '/admin/branches.pl?op=add_form&branchcode=' . $branchcode,
134 main_class => 'main container-fluid'
136 ); # Edit
137 $s->fill_form( { branchname => 'another branchname' } );
138 $s->submit_form;
140 # Select "Show all" in the datatable "Show x entries" dropdown list to make sure our library is not hidden
141 $s->show_all_entries('//div[@id="libraries_wrapper"]');
142 $s->click(
144 id => 'delete_library_'.$branchcode,
146 ); # Delete
149 { #Authorized values
150 $driver->get($mainpage);
151 $s->click( { href => '/admin/admin-home.pl', main => 'container-main' } ); #Koha administration
153 $s->click( { href => '/admin/authorised_values.pl', main_class => 'main container-fluid' } ); #Authorized values
155 $s->click( { href => { 'ends-with' => '/admin/authorised_values.pl?op=add_form' }, main_class => 'main container-fluid' } ); # New category
156 $s->fill_form( { category => $av_category } );
157 $s->submit_form;
159 $s->click(
161 href => '/admin/authorised_values.pl?op=add_form&category=' . $av_category,
162 main_class => 'main container-fluid'
164 ); # New authorised value for ...
165 $s->fill_form(
167 authorised_value => "$av_category" . "_xxx",
168 lib => "This is a description for staff",
169 lib_opac => "This is a description for OPAC"
172 $s->submit_form;
174 my $dbh = C4::Context->dbh;
175 my ( $av_id ) = $dbh->selectrow_array(q|
176 SELECT id FROM authorised_values WHERE category=?|, undef, $av_category );
177 $s->click(
179 href => '/admin/authorised_values.pl?op=delete&searchfield=' . $av_category . '&id=' . $av_id,
180 main_class => 'main container-fluid'
183 $s->driver->accept_alert; # Accept the modal "Are you sure you want to delete this authorized value?"
186 { # Patron categories
187 $driver->get($mainpage);
188 $s->click( { href => '/admin/admin-home.pl', main => 'container-main' } ); # Koha administration
189 $s->click( { href => '/admin/categories.pl', main_class => 'main container-fluid' } ); # Patron categories
190 $s->click( { href => '/admin/categories.pl?op=add_form', main_class => 'main container-fluid' } ); # New patron category
192 $s->fill_form( { categorycode => $category_code, description => 'Test category', enrolmentperiod => 12, category_type => 'A' } );
193 $s->submit_form;
195 # Select "Show all" in the datatable "Show x entries" dropdown list to make sure our category is not hidden
196 $s->show_all_entries('//div[@id="patron_categories_wrapper"]');
198 $s->click(
200 href => '/admin/categories.pl?op=delete_confirm&categorycode=' . $category_code,
201 main_class => 'main container-fluid'
203 ); # Delete button
205 $s->submit_form; # Delete this category
207 # TODO Make sure the category has been deleted
210 $driver->quit();
213 END {
214 cleanup() if $cleanup_needed;
217 sub cleanup {
218 my $dbh = C4::Context->dbh;
219 $dbh->do(q|DELETE FROM itemtypes WHERE itemtype=?|, undef, $itemtype);
220 $dbh->do(q|DELETE FROM biblio_framework WHERE frameworkcode=?|, undef, $frameworkcode);
221 $dbh->do(q|DELETE FROM branches WHERE branchcode=?|, undef, $branchcode);
222 $dbh->do(q|DELETE FROM authorised_value_categories WHERE category_name=?|, undef, $av_category);
223 $dbh->do(q|DELETE FROM categories WHERE categorycode=?|, undef, $category_code);