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 => 33;
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";
51 my $dbh = C4::Context->dbh;
55 my $agent = Test::WWW::Mechanize->new( autocheck => 1 );
57 my ($category, $expected_base, $add_form_link_exists, $delete_form_link_exists);
59 # -------------------------------------------------- LOGIN
62 $agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'connect to intranet' );
63 $agent->form_name('loginform');
64 $agent->field( 'password', $password );
65 $agent->field( 'userid', $user );
66 $agent->field( 'branch', '' );
67 $agent->click_ok( '', 'login to staff client' );
68 $agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'load main page' );
70 #--------------------------------------------------- Test with corean and greek chars
73 $dbh->do(q|DELETE FROM authorised_values WHERE category = ?|, undef, $category);
74 $dbh->do(q|DELETE FROM authorised_value_categories WHERE category_name = ?|, undef, $category);
76 $expected_base = q|authorised_values.pl|;
77 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Connect to Authorized values page' );
78 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?op=add_form", 'Open to create a new category' );
79 $agent->form_name('Aform');
80 $agent->field('category', $category);
81 $agent->click_ok( '', "Create new AV category " );
83 $agent->base_like(qr|$expected_base|, "check base");
84 $add_form_link_exists = 0;
85 for my $link ( $agent->links() ) {
86 if ( $link->url =~ m|authorised_values.pl\?op=add_form&category=$category| ) {
87 $add_form_link_exists = 1;
90 is( $add_form_link_exists, 1, 'Add a new category button should be displayed');
91 $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' );
93 $agent->form_name('Aform');
94 $agent->field('authorised_value', 'επιμεq');
95 $agent->field('lib_opac', 'autdesc2');
96 $agent->field('lib', 'desc1');
97 $agent->field('branches', '');
98 $agent->click_ok( '', "Create a new value for the category" );
100 $agent->base_like(qr|$expected_base|, "check base");
101 $add_form_link_exists = 0;
102 $delete_form_link_exists = 0;
103 for my $link ( $agent->links() ) {
104 if ( $link->url =~ m|authorised_values.pl\?op=add_form&category=$category| ) {
105 $add_form_link_exists = 1;
106 }elsif( $link->url =~ m|authorised_values.pl\?op=delete&searchfield=$category| ) {
107 $delete_form_link_exists = 1;
110 is( $add_form_link_exists, 1, 'Add a new category button should be displayed');
111 is( $delete_form_link_exists, 1, '');
113 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Return to Authorized values page' );
114 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?searchfield=学協会μμ&offset=0", 'Search the values inserted' );
115 my $text = $agent->text() ;
117 ok ( ( length(Encode::encode('UTF-8', $text)) != length($text) ) , 'UTF-8 are multi-byte. Good') ;
118 ok ($text =~ m/学協会μμ/, 'UTF-8 (Asia) chars are correctly present. Good');
119 ok ($text =~ m/επιμεq/, 'UTF-8 (Greek) chars are correctly present. Good');
120 my @links = $agent->links;
122 foreach my $dato (@links){
123 my $link = $dato->url;
124 if ($link =~ m/op=delete\&searchfield=学協会μμ\&id=(\d+)/){
130 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?op=delete&searchfield=学協会μμ&id=$id_to_del", 'UTF_8 auth. value deleted' );
132 ok($id_to_del ne undef, "error, link to delete not working");
135 #---------------------------------------- Test with only latin utf-8 (could be taken as Latin-1/ISO 8859-1)
138 $dbh->do(q|DELETE FROM authorised_values WHERE category = ?|, undef, $category);
139 $dbh->do(q|DELETE FROM authorised_value_categories WHERE category_name = ?|, undef, $category);
141 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Connect to Authorized values page' );
142 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?op=add_form", 'Open to create a new category' );
143 $agent->form_name('Aform');
144 $agent->field('category', $category);
145 $agent->click_ok( '', "Create new AV category" );
147 $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' );
148 $agent->form_name('Aform');
149 $agent->field('authorised_value', 'ràmen');
150 $agent->field('lib_opac', 'autdesc2');
151 $agent->field('lib', 'desc1');
152 $agent->field('branches', '');
153 $agent->click_ok( '', "Create a new value for the category" );
155 $expected_base = q|authorised_values.pl|;
156 $agent->base_like(qr|$expected_base|, "check base");
157 $add_form_link_exists = 0;
158 $delete_form_link_exists = 0;
159 for my $link ( $agent->links() ) {
160 if ( $link->url =~ m|authorised_values.pl\?op=add_form&category=$category| ) {
161 $add_form_link_exists = 1;
162 }elsif( $link->url =~ m|authorised_values.pl\?op=delete&searchfield=$category| ) {
163 $delete_form_link_exists = 1;
166 is( $add_form_link_exists, 1, );
167 is( $delete_form_link_exists, 1, );
169 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Return to Authorized values page' );
170 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?searchfield=tòmas&offset=0", 'Search the values inserted' );
171 my $text2 = $agent->text() ;
173 ok ( ( length(Encode::encode('UTF-8', $text)) != length($text) ) , 'UTF-8 are multi-byte. Good') ;
174 ok ($text2 =~ m/tòmas/, 'UTF-8 not Latin-1 first test is OK. Good');
175 ok ($text2=~ m/ràmen/, 'UTF-8 not Latin-1 second test is OK. Good');
176 my @links2 = $agent->links;
178 foreach my $dato (@links2){
179 my $link = $dato->url;
180 if ($link =~ m/op=delete\&searchfield=tòmas\&id=(\d+)/){
186 $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' );
188 ok($id_to_del2 ne undef, "error, link to delete not working");