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>.
21 use Test
::More
; #See plan tests => \d+ below
22 use Test
::WWW
::Mechanize
;
31 use Koha
::AuthorisedValueCategories
;
33 my $testdir = File
::Spec
->rel2abs( dirname
(__FILE__
) );
35 my $koha_conf = $ENV{KOHA_CONF
};
36 my $xml = XMLin
($koha_conf);
38 my $user = $ENV{KOHA_USER
} || $xml->{config
}->{user
};
39 my $password = $ENV{KOHA_PASS
} || $xml->{config
}->{pass
};
40 my $intranet = $ENV{KOHA_INTRANET_URL
};
46 plan skip_all
=> "Tests skip. You must have a working Context\n";
48 elsif (not defined $intranet) {
49 plan skip_all
=> "Tests skip. You must set env. variable KOHA_INTRANET_URL to do tests\n";
55 my $dbh = C4
::Context
->dbh;
59 my $agent = Test
::WWW
::Mechanize
->new( autocheck
=> 1 );
61 my ($category, $expected_base, $add_form_link_exists, $delete_form_link_exists);
63 # -------------------------------------------------- LOGIN
66 $agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'connect to intranet' );
67 $agent->form_name('loginform');
68 $agent->field( 'password', $password );
69 $agent->field( 'userid', $user );
70 $agent->field( 'branch', '' );
71 $agent->click_ok( '', 'login to staff client' );
72 $agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'load main page' );
74 #---------------------------------------- Test with corean, greek and emoji chars
77 $dbh->do(q
|DELETE FROM authorised_values WHERE category
= ?
|, undef, $category);
78 $dbh->do(q
|DELETE FROM authorised_value_categories WHERE category_name
= ?
|, undef, $category);
80 $expected_base = q
|authorised_values
.pl
|;
81 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Connect to Authorized values page' );
82 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?op=add_form", 'Open to create a new category' );
83 $agent->form_name('Aform');
84 $agent->field('category', $category);
85 $agent->click_ok( '', "Create new AV category " );
87 $agent->base_like(qr
|$expected_base|, "check base");
88 $add_form_link_exists = 0;
89 for my $link ( $agent->links() ) {
90 if ( $link->url =~ m
|authorised_values
.pl
\?op
=add_form
&category
=| . uri_escape_utf8
($category) ) {
91 $add_form_link_exists = 1;
94 is
( $add_form_link_exists, 1, 'Add a new category button should be displayed');
95 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?op=add_form&category=" . uri_escape_utf8
($category), 'Open to create a new AV for this category' );
97 $agent->form_name('Aform');
98 $agent->field('authorised_value', 'επιμεq');
99 $agent->field('lib_opac', 'autdesc2');
100 $agent->field('lib', 'desc1');
101 $agent->field('branches', '');
102 $agent->click_ok( '', "Create a new value for the category" );
104 $agent->base_like(qr
|$expected_base|, "check base");
105 $add_form_link_exists = 0;
106 $delete_form_link_exists = 0;
107 my $add_form_re = q
|authorised_values
.pl
\?op
=add_form
&category
=| . uri_escape_utf8
($category);
108 my $delete_re = q
|authorised_values
.pl
\?op
=delete&searchfield
=| . uri_escape_utf8
($category);
109 for my $link ( $agent->links() ) {
110 if ( $link->url =~ qr
|$add_form_re| ) {
111 $add_form_link_exists = 1;
112 } elsif ( $link->url =~ qr
|$delete_re| ) {
113 $delete_form_link_exists = 1;
116 is
( $add_form_link_exists, 1, 'Add a new category button should be displayed');
117 is
( $delete_form_link_exists, 1, '');
119 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Return to Authorized values page' );
120 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?searchfield=" . uri_escape_utf8
($category) . "&offset=0", 'Search the values inserted' );
121 my $text = $agent->text() ;
123 ok
( ( length(Encode
::encode
('UTF-8', $text)) != length($text) ) , 'UTF-8 are multi-byte. Good') ;
124 ok
($text =~ m/学協会μμ/, 'UTF-8 (Asia) chars are correctly present. Good');
125 ok
($text =~ m/επιμεq/, 'UTF-8 (Greek) chars are correctly present. Good');
126 ok
($text =~ m/😀/, 'UTF-8 (emoji) chars are correctly present. Good');
127 my @links = $agent->links;
129 $delete_re = q
|op
=delete\
&searchfield
=| . uri_escape_utf8
($category) . '\&id=(\d+)';
130 foreach my $dato (@links){
131 my $link = $dato->url;
132 if ($link =~ qr
|$delete_re| ) {
138 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?op=delete&searchfield=" . uri_escape_utf8
($category) . "&id=$id_to_del", 'UTF_8 auth. value deleted' );
140 ok
($id_to_del ne undef, "error, link to delete not working");
143 Koha
::AuthorisedValueCategories
->find($category)->delete; # Clean up
145 #---------------------------------------- Test with only latin utf-8 (could be taken as Latin-1/ISO 8859-1)
148 $dbh->do(q
|DELETE FROM authorised_values WHERE category
= ?
|, undef, $category);
149 $dbh->do(q
|DELETE FROM authorised_value_categories WHERE category_name
= ?
|, undef, $category);
151 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Connect to Authorized values page' );
152 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?op=add_form", 'Open to create a new category' );
153 $agent->form_name('Aform');
154 $agent->field('category', $category);
155 $agent->click_ok( '', "Create new AV category" );
157 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?op=add_form&category=$category", 'Open to create a new AV for this category' );
158 $agent->form_name('Aform');
159 $agent->field('authorised_value', 'ràmen');
160 $agent->field('lib_opac', 'autdesc2');
161 $agent->field('lib', 'desc1');
162 $agent->field('branches', '');
163 $agent->click_ok( '', "Create a new value for the category" );
165 $expected_base = q
|authorised_values
.pl
|;
166 $agent->base_like(qr
|$expected_base|, "check base");
167 $add_form_link_exists = 0;
168 $delete_form_link_exists = 0;
169 $add_form_re = q
|authorised_values
.pl
\?op
=add_form
&category
=| . uri_escape_utf8
($category);
170 $delete_re = q
|authorised_values
.pl
\?op
=delete&searchfield
=| . uri_escape_utf8
($category);
171 for my $link ( $agent->links() ) {
172 if ( $link->url =~ qr
|$add_form_re| ) {
173 $add_form_link_exists = 1;
174 }elsif( $link->url =~ qr
|$delete_re| ) {
175 $delete_form_link_exists = 1;
178 is
( $add_form_link_exists, 1, );
179 is
( $delete_form_link_exists, 1, );
181 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Return to Authorized values page' );
182 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?searchfield=tòmas&offset=0", 'Search the values inserted' );
183 my $text2 = $agent->text() ;
185 ok
( ( length(Encode
::encode
('UTF-8', $text)) != length($text) ) , 'UTF-8 are multi-byte. Good') ;
186 ok
($text2 =~ m/tòmas/, 'UTF-8 not Latin-1 first test is OK. Good');
187 ok
($text2=~ m/ràmen/, 'UTF-8 not Latin-1 second test is OK. Good');
188 my @links2 = $agent->links;
190 $delete_re = q
|op
=delete\
&searchfield
=| . uri_escape_utf8
($category) . q
|\
&id
=(\d
+)|;
191 foreach my $dato (@links2){
192 my $link = $dato->url;
193 if ($link =~ qr
|$delete_re| ){
199 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?op=delete&searchfield=tòmas&id=$id_to_del2", 'UTF_8 auth. value deleted' );
201 ok
($id_to_del2 ne undef, "error, link to delete not working");
204 Koha
::AuthorisedValueCategories
->find($category)->delete; # Clean up