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
26 use Test::More tests => 3;
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);
43 eval { require Selenium::Remote::Driver; };
44 skip "Selenium::Remote::Driver is needed for selenium tests.", 3 if $@;
48 my $s = t::lib::Selenium->new;
49 my $driver = $s->driver;
50 $driver->set_window_size(3840,1080);
51 my $mainpage = $s->base_url . q|mainpage.pl|;
52 $driver->get($mainpage);
53 like( $driver->get_title(), qr(Log in to Koha), );
56 # Navigate to the Administration area and create an item type
57 $s->click( { href => '/admin/admin-home.pl', main => 'container-main' } )
58 ; # Koha administration
59 $s->click( { href => '/admin/itemtypes.pl', main_class => 'main container-fluid' } ); # Item Types
60 $s->click( { href => '/admin/itemtypes.pl?op=add_form', main_class => 'main container-fluid' } )
63 { itemtype => $itemtype, description => "Digital Optical Disc" } );
67 href => '/admin/itemtypes.pl?op=add_form&itemtype=' . $itemtype,
68 main_class => 'main container-fluid'
73 { # Circulation/fine rules
74 my $itype = $builder->build_object({ class => "Koha::ItemTypes" });
75 $driver->get($mainpage);
76 $s->click( { href => '/admin/admin-home.pl', main => 'container-main' } )
77 ; # Koha administration
78 $s->click( { href => '/admin/smart-rules.pl', main_class => 'main container-fluid' } )
79 ; # Circulation and fine rules
80 my $elt = $driver->find_element('//tr[@id="edit_row"]/td/select[@id="matrixitemtype"]/option[@value="'.$itype->itemtype.'"]');
81 is( $elt->get_text(),$itype->description,"Our new itemtype is in the list");
83 $elt = $driver->find_element('//tr[@id="edit_row"]/td[@class="actions"]/button[@type="submit"]');
85 $elt = $driver->find_elements('//table[@id="default-circulation-rules"]/tbody/tr/td[contains(text(),"'.$itype->description.'")]/following-sibling::td/span[text() = "Unlimited"]');
86 is( @$elt, 5, "We have unlimited checkouts and holds" );
88 Koha::CirculationRules->search( { itemtype => $itype->itemtype } )->delete;
90 # TODO Create more smart rules navigation here
94 $driver->get($mainpage);
95 $s->click( { href => '/admin/admin-home.pl', main => 'container-main' } )
96 ; # Koha administration
97 $s->click( { href => '/admin/biblio_framework.pl', main_class => 'main container-fluid' } )
98 ; # MARC bibliographic framework
100 { href => '/admin/biblio_framework.pl?op=add_form', main_class => 'main container-fluid' } )
104 frameworkcode => $frameworkcode,
105 description => 'just a description'
109 $s->click( { id => 'frameworkactions' . $frameworkcode } );
112 href => 'marctagstructure.pl?frameworkcode=' . $frameworkcode,
113 main_class => 'main container-fluid'
115 ); # MARC structure # FIXME '/admin/' is missing in the url
116 # TODO Click on OK to create the MARC structure
120 $driver->get($mainpage);
121 $s->click( { href => '/admin/admin-home.pl', main => 'container-main' } )
122 ; # Koha administration
123 $s->click( { href => '/admin/branches.pl', main_class => 'main container-fluid' } )
124 ; # Libraries and groups
125 $s->click( { href => '/admin/branches.pl?op=add_form', main_class => 'main container-fluid' } )
127 $s->fill_form( { branchcode => $branchcode, branchname => 'my library' } );
130 # Select "Show all" in the datatable "Show x entries" dropdown list to make sure our library is not hidden
131 $s->show_all_entries('//div[@id="libraries_wrapper"]');
134 href => '/admin/branches.pl?op=add_form&branchcode=' . $branchcode,
135 main_class => 'main container-fluid'
138 $s->fill_form( { branchname => 'another branchname' } );
141 # Select "Show all" in the datatable "Show x entries" dropdown list to make sure our library is not hidden
142 $s->show_all_entries('//div[@id="libraries_wrapper"]');
145 id => 'delete_library_'.$branchcode,
151 $driver->get($mainpage);
152 $s->click( { href => '/admin/admin-home.pl', main => 'container-main' } ); #Koha administration
154 $s->click( { href => '/admin/authorised_values.pl', main_class => 'main container-fluid' } ); #Authorized values
156 $s->click( { href => { 'ends-with' => '/admin/authorised_values.pl?op=add_form' }, main_class => 'main container-fluid' } ); # New category
157 $s->fill_form( { category => $av_category } );
162 href => '/admin/authorised_values.pl?op=add_form&category=' . $av_category,
163 main_class => 'main container-fluid'
165 ); # New authorised value for ...
168 authorised_value => "$av_category" . "_xxx",
169 lib => "This is a description for staff",
170 lib_opac => "This is a description for OPAC"
175 my $dbh = C4::Context->dbh;
176 my ( $av_id ) = $dbh->selectrow_array(q|
177 SELECT id FROM authorised_values WHERE category=?|, undef, $av_category );
180 href => '/admin/authorised_values.pl?op=delete&searchfield=' . $av_category . '&id=' . $av_id,
181 main_class => 'main container-fluid'
184 $s->driver->accept_alert; # Accept the modal "Are you sure you want to delete this authorized value?"
186 # For an unknown reason the click on the next admin-home link does not work
187 # We were still on the authorised value list view.
188 # A workaround (and dirty fix) is to wait for 1 second and see if it fixes the problem
192 { # Patron categories
193 $driver->get($mainpage);
194 $s->click( { href => '/admin/admin-home.pl', main => 'container-main' } ); # Koha administration
195 $s->click( { href => '/admin/categories.pl', main_class => 'main container-fluid' } ); # Patron categories
196 $s->click( { href => '/admin/categories.pl?op=add_form', main_class => 'main container-fluid' } ); # New patron category
198 $s->fill_form( { categorycode => $category_code, description => 'Test category', enrolmentperiod => 12, category_type => 'A' } );
201 # Select "Show all" in the datatable "Show x entries" dropdown list to make sure our category is not hidden
202 $s->show_all_entries('//div[@id="patron_categories_wrapper"]');
206 href => '/admin/categories.pl?op=delete_confirm&categorycode=' . $category_code,
207 main_class => 'main container-fluid'
211 $s->submit_form; # Delete this category
213 # TODO Make sure the category has been deleted
220 cleanup() if $cleanup_needed;
224 my $dbh = C4::Context->dbh;
225 $dbh->do(q|DELETE FROM itemtypes WHERE itemtype=?|, undef, $itemtype);
226 $dbh->do(q|DELETE FROM biblio_framework WHERE frameworkcode=?|, undef, $frameworkcode);
227 $dbh->do(q|DELETE FROM branches WHERE branchcode=?|, undef, $branchcode);
228 $dbh->do(q|DELETE FROM authorised_value_categories WHERE category_name=?|, undef, $av_category);
229 $dbh->do(q|DELETE FROM categories WHERE categorycode=?|, undef, $category_code);