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 tests => 28;
22 use Test::WWW::Mechanize;
31 my $testdir = File::Spec->rel2abs( dirname(__FILE__) );
33 my $koha_conf = $ENV{KOHA_CONF};
34 my $xml = XMLin($koha_conf);
40 plan skip_all => "Tests skip. You must have a working Context\n";
43 my $user = $ENV{KOHA_USER} || $xml->{config}->{user};
44 my $password = $ENV{KOHA_PASS} || $xml->{config}->{pass};
45 my $intranet = $ENV{KOHA_INTRANET_URL};
47 if (not defined $intranet) {
48 plan skip_all => "Tests skip. You must set env. variable KOHA_INTRANET_URL to do tests\n";
54 my $agent = Test::WWW::Mechanize->new( autocheck => 1 );
56 my ($category, $expected_base, $add_form_link_exists, $delete_form_link_exists);
58 # -------------------------------------------------- LOGIN
61 $agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'connect to intranet' );
62 $agent->form_name('loginform');
63 $agent->field( 'password', $password );
64 $agent->field( 'userid', $user );
65 $agent->field( 'branch', '' );
66 $agent->click_ok( '', 'login to staff client' );
67 $agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'load main page' );
69 #--------------------------------------------------- Test with corean and greek chars
73 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Connect to Authorized values page' );
74 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?op=add_form", 'Open to create a new category' );
75 $agent->form_name('Aform');
76 $agent->field('authorised_value', 'επιμεq');
77 $agent->field('lib_opac', 'autdesc2');
78 $agent->field('lib', 'desc1');
79 $agent->field('category', $category);
80 $agent->field('branches', '');
81 $agent->click_ok( '', "Create new auth category and value" );
83 $expected_base = q|authorised_values.pl\?searchfield=| . uri_escape_utf8( $category );
84 $agent->base_like(qr|$expected_base|, "check base");
85 $add_form_link_exists = 0;
86 $delete_form_link_exists = 0;
87 for my $link ( $agent->links() ) {
88 if ( $link->url =~ m|authorised_values.pl\?op=add_form&category=$category| ) {
89 $add_form_link_exists = 1;
90 }elsif( $link->url =~ m|authorised_values.pl\?op=delete_confirm&searchfield=$category| ) {
91 $delete_form_link_exists = 1;
94 is( $add_form_link_exists, 1, );
95 is( $delete_form_link_exists, 1, );
97 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Return to Authorized values page' );
98 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?searchfield=学協会μμ&offset=0", 'Search the values inserted' );
99 my $text = $agent->text() ;
101 ok ( ( length(Encode::encode('UTF-8', $text)) != length($text) ) , 'UTF-8 are multi-byte. Good') ;
102 ok ($text =~ m/学協会μμ/, 'UTF-8 (Asia) chars are correctly present. Good');
103 ok ($text =~ m/επιμεq/, 'UTF-8 (Greek) chars are correctly present. Good');
104 my @links = $agent->links;
106 foreach my $dato (@links){
107 my $link = $dato->url;
108 if ($link =~ m/op=delete_confirm\&searchfield=学協会μμ/){
109 $link =~ m/(.*&id=?)(\d{1,})(&.*)/;
115 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?op=delete_confirmed&searchfield=学協会μμ&id=$id_to_del", 'UTF_8 auth. value deleted' );
117 ok($id_to_del ne undef, "error, link to delete nor working");
120 #---------------------------------------- Test with only latin utf-8 (could be taken as Latin-1/ISO 8859-1)
124 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Connect to Authorized values page' );
125 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?op=add_form", 'Open to create a new category' );
126 $agent->form_name('Aform');
127 $agent->field('authorised_value', 'ràmen');
128 $agent->field('lib_opac', 'autdesc2');
129 $agent->field('lib', 'desc1');
130 $agent->field('category', $category);
131 $agent->field('branches', '');
132 $agent->click_ok( '', "Create new auth category and value" );
133 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?searchfield=tòmas&offset=0", 'Search the values inserted' );
135 $expected_base = q|authorised_values.pl\?searchfield=| . uri_escape_utf8( $category );
136 #$expected_base = q|authorised_values.pl\?searchfield=| . $category;
137 $agent->base_like(qr|$expected_base|, "check base");
138 $add_form_link_exists = 0;
139 $delete_form_link_exists = 0;
140 for my $link ( $agent->links() ) {
141 if ( $link->url =~ m|authorised_values.pl\?op=add_form&category=$category| ) {
142 $add_form_link_exists = 1;
143 }elsif( $link->url =~ m|authorised_values.pl\?op=delete_confirm&searchfield=$category| ) {
144 $delete_form_link_exists = 1;
147 is( $add_form_link_exists, 1, );
148 is( $delete_form_link_exists, 1, );
150 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Return to Authorized values page' );
151 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?searchfield=tòmas&offset=0", 'Search the values inserted' );
152 my $text2 = $agent->text() ;
154 ok ( ( length(Encode::encode('UTF-8', $text)) != length($text) ) , 'UTF-8 are multi-byte. Good') ;
155 ok ($text2 =~ m/tòmas/, 'UTF-8 not Latin-1 first test is OK. Good');
156 ok ($text2=~ m/ràmen/, 'UTF-8 not Latin-1 second test is OK. Good');
157 my @links2 = $agent->links;
159 foreach my $dato (@links2){
160 my $link = $dato->url;
161 if ($link =~ m/op=delete_confirm\&searchfield=tòmas/){
162 $link =~ m/(.*&id=?)(\d{1,})(&.*)/;
168 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?op=delete_confirmed&searchfield=tòmas&id=$id_to_del2", 'UTF_8 auth. value deleted' );
170 ok($id_to_del ne undef, "error, link to delete nor working");