Bug 19243: Amended Selenium test to add the creation of patron category and authorise...
[koha.git] / t / db_dependent / selenium / administration_tasks.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 #This selenium test tests the Koha Administration module functionality including adding circ rules, item types and modifying frameworks
19
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
21
22 use Modern::Perl;
23
24 use C4::Context;
25
26 use Test::More tests => 1;
27
28 use t::lib::Selenium;
29
30 my $login = $ENV{KOHA_USER} || 'koha';
31
32 my $itemtype      = 'UT_DVD';
33 my $frameworkcode = 'UTFW';     # frameworkcode is only 4 characters max!
34 my $branchcode    = 'UT_BC';
35 my $categoryname = 'Test';
36 our ($cleanup_needed);
37
38 SKIP: {
39     eval { require Selenium::Remote::Driver; };
40     skip "Selenium::Remote::Driver is needed for selenium tests.", 1 if $@;
41
42     $cleanup_needed = 1;
43
44     my $s        = t::lib::Selenium->new;
45     my $driver   = $s->driver;
46     my $mainpage = $s->base_url . q|mainpage.pl|;
47     $driver->get($mainpage);
48     like( $driver->get_title(), qr(Log in to Koha), );
49     $s->auth;
50     { # Item types
51         # Navigate to the Administration area and create an item type
52         $s->click( { href => '/admin/admin-home.pl', main => 'doc3' } )
53           ;    # Koha administration
54         $s->click( { href => '/admin/itemtypes.pl', main => 'doc' } );  # Item Types
55         $s->click( { href => '/admin/itemtypes.pl?op=add_form', main => 'doc3' } )
56           ;    # New item type
57         $s->fill_form(
58             { itemtype => $itemtype, description => "Digital Optical Disc" } );
59         $s->submit_form;
60         $s->click(
61             {
62                 href => '/admin/itemtypes.pl?op=add_form&itemtype=' . $itemtype,
63                 main => 'doc3'
64             }
65         );     # New item type
66     };
67
68     { # Circulation/fine rules
69         $driver->get($mainpage);
70         $s->click( { href => '/admin/admin-home.pl', main => 'doc3' } )
71           ;    # Koha administration
72         $s->click( { href => '/admin/smart-rules.pl', main => 'doc' } )
73           ;    # Circulation and fines rules
74                # TODO Create smart navigation here
75     };
76
77     { # Biblio frameworks
78         $driver->get($mainpage);
79         $s->click( { href => '/admin/admin-home.pl', main => 'doc3' } )
80           ;    # Koha administration
81         $s->click( { href => '/admin/biblio_framework.pl', main => 'doc' } )
82           ;    # MARC bibliographic framework
83         $s->click(
84             { href => '/admin/biblio_framework.pl?op=add_form', main => 'doc3' } )
85           ;    # New framework
86         $s->fill_form(
87             {
88                 frameworkcode => $frameworkcode,
89                 description   => 'just a description'
90             }
91         );
92         $s->submit_form;
93         $s->click( { id => 'frameworkactions' . $frameworkcode } );
94         $s->click(
95             {
96                 href => 'marctagstructure.pl?frameworkcode=' . $frameworkcode,
97                 main => 'doc3'
98             }
99         );    # MARC structure # FIXME '/admin/' is missing in the url
100               # TODO Click on OK to create the MARC structure
101     };
102
103     { #Libraries
104         $driver->get($mainpage);
105         $s->click( { href => '/admin/admin-home.pl', main => 'doc3' } )
106           ;    # Koha administration
107         $s->click( { href => '/admin/branches.pl', main => 'doc' } )
108           ;    # Libraries and groups
109         $s->click( { href => '/admin/branches.pl?op=add_form', main => 'doc3' } )
110           ;    # New library
111         $s->fill_form( { branchcode => $branchcode, branchname => 'my library' } );
112         $s->submit_form;
113         $s->click(
114             {
115                 href => '/admin/branches.pl?op=add_form&branchcode=' . $branchcode,
116                 main => 'doc3'
117             }
118         );     # Edit
119         $s->fill_form( { branchname => 'another branchname' } );
120         $s->submit_form;
121         $s->click(
122             {
123                 href => '/admin/branches.pl?op=delete_confirm&branchcode='. $branchcode,
124                 main => 'doc3'
125             }
126         );     # Delete
127     };
128
129     { #Authorized values
130         $driver->get($mainpage);
131         $s->click( { href => '/admin/admin-home.pl', main => 'doc3' } ); #Koha administration
132
133         $s->click( { href => '/admin/authorised_values.pl', main => 'doc' } ); #Authorized values
134
135         $s->click( { href => '/cgi-bin/koha/admin/authorised_values.pl?op=add_form&category=Adult', main => 'doc3' } ); # New category
136         $s->fill_form( { authorised_value => 'Hardover', lib => 'Hardcover book'} );
137         $s->submit_form;
138
139         $s->click(
140             {
141                 href => '/cgi-bin/koha/admin/authorised_values.pl?op=delete&searchfield=Adult&id=400',
142                 main => 'doc3'
143             }
144         );
145     };
146
147     { #Patron categories
148         $driver->get($mainpage);
149         $s->click( { href => '/cgi-bin/koha/admin/categories.pl', main => 'doc3' } ); #Koha administration
150         $s->click( { href => '/cgi-bin/koha/admin/categories.pl?op=add_form', main => 'doc' } ); #New patron category
151
152         $s->fill_form( { categorycode => 'Test', description => 'Test category', enrolmentperiod => 12, category_type => 'Adult' } );
153         $s->submit_form;
154
155         $s->click(
156             {
157                 href => '/cgi-bin/koha/admin/categories.pl?op=delete_confirm&categorycode=TEST',
158                 main => 'doc3'
159             }
160         );
161     };
162
163     $driver->quit();
164 }
165
166 END {
167     cleanup() if $cleanup_needed;
168 };
169
170 sub cleanup {
171     my $dbh = C4::Context->dbh;
172     $dbh->do(q|DELETE FROM itemtypes WHERE itemtype=?|, undef, $itemtype);
173     $dbh->do(q|DELETE FROM biblio_framework WHERE frameworkcode=?|, undef, $frameworkcode);
174     $dbh->do(q|DELETE FROM branches WHERE branchcode=?|, undef, $branchcode);
175 }