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.", 1 if $@;
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), );
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' } )
62 { itemtype => $itemtype, description => "Digital Optical Disc" } );
66 href => '/admin/itemtypes.pl?op=add_form&itemtype=' . $itemtype,
67 main_class => 'main container-fluid'
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");
82 $elt = $driver->find_element('//tr[@id="edit_row"]/td[@class="actions"]/button[@type="submit"]');
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" );
87 Koha::CirculationRules->search( { itemtype => $itype->itemtype } )->delete;
89 # TODO Create more smart rules navigation here
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
99 { href => '/admin/biblio_framework.pl?op=add_form', main_class => 'main container-fluid' } )
103 frameworkcode => $frameworkcode,
104 description => 'just a description'
108 $s->click( { id => 'frameworkactions' . $frameworkcode } );
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
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' } )
126 $s->fill_form( { branchcode => $branchcode, branchname => 'my library' } );
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"]');
133 href => '/admin/branches.pl?op=add_form&branchcode=' . $branchcode,
134 main_class => 'main container-fluid'
137 $s->fill_form( { branchname => 'another branchname' } );
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"]');
144 id => 'delete_library_'.$branchcode,
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 } );
161 href => '/admin/authorised_values.pl?op=add_form&category=' . $av_category,
162 main_class => 'main container-fluid'
164 ); # New authorised value for ...
167 authorised_value => "$av_category" . "_xxx",
168 lib => "This is a description for staff",
169 lib_opac => "This is a description for OPAC"
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 );
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 # For an unknown reason the click on the admin-home link does not work
188 # At this point we were still on the authorised value list view.
189 # A workaround (and dirty fix) is to logout/login and see if it fixes the problem
190 $driver->get( $mainpage . q|?logout.x=1| );
192 $driver->get($mainpage);
193 $s->click( { href => '/admin/admin-home.pl', main => 'container-main' } ); # Koha administration
194 $s->click( { href => '/admin/categories.pl', main_class => 'main container-fluid' } ); # Patron categories
195 $s->click( { href => '/admin/categories.pl?op=add_form', main_class => 'main container-fluid' } ); # New patron category
197 $s->fill_form( { categorycode => $category_code, description => 'Test category', enrolmentperiod => 12, category_type => 'A' } );
200 # Select "Show all" in the datatable "Show x entries" dropdown list to make sure our category is not hidden
201 $s->show_all_entries('//div[@id="patron_categories_wrapper"]');
205 href => '/admin/categories.pl?op=delete_confirm&categorycode=' . $category_code,
206 main_class => 'main container-fluid'
210 $s->submit_form; # Delete this category
212 # TODO Make sure the category has been deleted
219 cleanup() if $cleanup_needed;
223 my $dbh = C4::Context->dbh;
224 $dbh->do(q|DELETE FROM itemtypes WHERE itemtype=?|, undef, $itemtype);
225 $dbh->do(q|DELETE FROM biblio_framework WHERE frameworkcode=?|, undef, $frameworkcode);
226 $dbh->do(q|DELETE FROM branches WHERE branchcode=?|, undef, $branchcode);
227 $dbh->do(q|DELETE FROM authorised_value_categories WHERE category_name=?|, undef, $av_category);
228 $dbh->do(q|DELETE FROM categories WHERE categorycode=?|, undef, $category_code);