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 => 15;
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 );
57 # -------------------------------------------------- LOAD RECORD
59 my $category = '学協会μμ';
60 $agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'connect to intranet' );
61 $agent->form_name('loginform');
62 $agent->field( 'password', $password );
63 $agent->field( 'userid', $user );
64 $agent->field( 'branch', '' );
65 $agent->click_ok( '', 'login to staff client' );
66 $agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'load main page' );
68 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Connect to Authorized values page' );
69 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?op=add_form", 'Open to create a new category' );
70 $agent->form_name('Aform');
71 $agent->field('authorised_value', 'επιμεq');
72 $agent->field('lib_opac', 'autdesc2');
73 $agent->field('lib', 'desc1');
74 $agent->field('category', $category);
75 $agent->field('branches', '');
76 $agent->click_ok( '', "Create new auth category and value" );
78 my $expected_base = q|authorised_values.pl\?searchfield=| . uri_escape_utf8( $category );
79 $agent->base_like(qr|$expected_base|, "check base");
80 my $add_form_link_exists = 0;
81 my $delete_form_link_exists = 0;
82 for my $link ( $agent->links() ) {
83 if ( $link->url =~ m|authorised_values.pl\?op=add_form&category=$category| ) {
84 $add_form_link_exists = 1;
85 }elsif( $link->url =~ m|authorised_values.pl\?op=delete_confirm&searchfield=$category| ) {
86 $delete_form_link_exists = 1;
89 is( $add_form_link_exists, 1, );
90 is( $delete_form_link_exists, 1, );
92 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Return to Authorized values page' );
93 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?searchfield=学協会μμ&offset=0", 'Search the values inserted' );
94 my $text = $agent->text() ;
96 ok ( ( length(Encode::encode('UTF-8', $text)) != length($text) ) , 'UTF-8 are multi-byte. Good') ;
97 ok ($text =~ m/学協会μμ/, 'UTF-8 (Asia) chars are correctly present. Good');
98 ok ($text =~ m/επιμεq/, 'UTF-8 (Greek) chars are correctly present. Good');
99 my @links = $agent->links;
101 foreach my $dato (@links){
102 my $link = $dato->url;
103 if ($link =~ m/op=delete_confirm\&searchfield=学協会μμ/){
104 $link =~ m/(.*&id=?)(\d{1,})(&.*)/;
110 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?op=delete_confirmed&searchfield=学協会μμ&id=$id_to_del", 'UTF_8 auth. value deleted' );
112 ok($id_to_del ne undef, "error, link to delete nor working");