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 use Koha::AuthorisedValueCategories;
33 my $testdir = File::Spec->rel2abs( dirname(__FILE__) );
35 my $koha_conf = $ENV{KOHA_CONF};
36 my $xml = XMLin($koha_conf);
42 plan skip_all => "Tests skip. You must have a working Context\n";
45 my $user = $ENV{KOHA_USER} || $xml->{config}->{user};
46 my $password = $ENV{KOHA_PASS} || $xml->{config}->{pass};
47 my $intranet = $ENV{KOHA_INTRANET_URL};
49 if (not defined $intranet) {
50 plan skip_all => "Tests skip. You must set env. variable KOHA_INTRANET_URL to do tests\n";
53 my $dbh = C4::Context->dbh;
57 my $agent = Test::WWW::Mechanize->new( autocheck => 1 );
59 my ($category, $expected_base, $add_form_link_exists, $delete_form_link_exists);
61 # -------------------------------------------------- LOGIN
64 $agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'connect to intranet' );
65 $agent->form_name('loginform');
66 $agent->field( 'password', $password );
67 $agent->field( 'userid', $user );
68 $agent->field( 'branch', '' );
69 $agent->click_ok( '', 'login to staff client' );
70 $agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'load main page' );
72 #--------------------------------------------------- Test with corean and greek chars
75 $dbh->do(q|DELETE FROM authorised_values WHERE category = ?|, undef, $category);
76 $dbh->do(q|DELETE FROM authorised_value_categories WHERE category_name = ?|, undef, $category);
78 $expected_base = q|authorised_values.pl|;
79 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Connect to Authorized values page' );
80 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?op=add_form", 'Open to create a new category' );
81 $agent->form_name('Aform');
82 $agent->field('category', $category);
83 $agent->click_ok( '', "Create new AV category " );
85 $agent->base_like(qr|$expected_base|, "check base");
86 $add_form_link_exists = 0;
87 for my $link ( $agent->links() ) {
88 if ( $link->url =~ m|authorised_values.pl\?op=add_form&category=| . uri_escape_utf8($category) ) {
89 $add_form_link_exists = 1;
92 is( $add_form_link_exists, 1, 'Add a new category button should be displayed');
93 $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' );
95 $agent->form_name('Aform');
96 $agent->field('authorised_value', 'επιμεq');
97 $agent->field('lib_opac', 'autdesc2');
98 $agent->field('lib', 'desc1');
99 $agent->field('branches', '');
100 $agent->click_ok( '', "Create a new value for the category" );
102 $agent->base_like(qr|$expected_base|, "check base");
103 $add_form_link_exists = 0;
104 $delete_form_link_exists = 0;
105 my $add_form_re = q|authorised_values.pl\?op=add_form&category=| . uri_escape_utf8($category);
106 my $delete_re = q|authorised_values.pl\?op=delete&searchfield=| . uri_escape_utf8($category);
107 for my $link ( $agent->links() ) {
108 if ( $link->url =~ qr|$add_form_re| ) {
109 $add_form_link_exists = 1;
110 } elsif ( $link->url =~ qr|$delete_re| ) {
111 $delete_form_link_exists = 1;
114 is( $add_form_link_exists, 1, 'Add a new category button should be displayed');
115 is( $delete_form_link_exists, 1, '');
117 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Return to Authorized values page' );
118 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?searchfield=" . uri_escape_utf8($category) . "&offset=0", 'Search the values inserted' );
119 my $text = $agent->text() ;
121 ok ( ( length(Encode::encode('UTF-8', $text)) != length($text) ) , 'UTF-8 are multi-byte. Good') ;
122 ok ($text =~ m/学協会μμ/, 'UTF-8 (Asia) chars are correctly present. Good');
123 ok ($text =~ m/επιμεq/, 'UTF-8 (Greek) chars are correctly present. Good');
124 my @links = $agent->links;
126 $delete_re = q|op=delete\&searchfield=| . uri_escape_utf8($category) . '\&id=(\d+)';
127 foreach my $dato (@links){
128 my $link = $dato->url;
129 if ($link =~ qr|$delete_re| ) {
135 $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' );
137 ok($id_to_del ne undef, "error, link to delete not working");
140 Koha::AuthorisedValueCategories->find($category)->delete; # Clean up
142 #---------------------------------------- Test with only latin utf-8 (could be taken as Latin-1/ISO 8859-1)
145 $dbh->do(q|DELETE FROM authorised_values WHERE category = ?|, undef, $category);
146 $dbh->do(q|DELETE FROM authorised_value_categories WHERE category_name = ?|, undef, $category);
148 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Connect to Authorized values page' );
149 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?op=add_form", 'Open to create a new category' );
150 $agent->form_name('Aform');
151 $agent->field('category', $category);
152 $agent->click_ok( '', "Create new AV category" );
154 $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' );
155 $agent->form_name('Aform');
156 $agent->field('authorised_value', 'ràmen');
157 $agent->field('lib_opac', 'autdesc2');
158 $agent->field('lib', 'desc1');
159 $agent->field('branches', '');
160 $agent->click_ok( '', "Create a new value for the category" );
162 $expected_base = q|authorised_values.pl|;
163 $agent->base_like(qr|$expected_base|, "check base");
164 $add_form_link_exists = 0;
165 $delete_form_link_exists = 0;
166 $add_form_re = q|authorised_values.pl\?op=add_form&category=| . uri_escape_utf8($category);
167 $delete_re = q|authorised_values.pl\?op=delete&searchfield=| . uri_escape_utf8($category);
168 for my $link ( $agent->links() ) {
169 if ( $link->url =~ qr|$add_form_re| ) {
170 $add_form_link_exists = 1;
171 }elsif( $link->url =~ qr|$delete_re| ) {
172 $delete_form_link_exists = 1;
175 is( $add_form_link_exists, 1, );
176 is( $delete_form_link_exists, 1, );
178 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Return to Authorized values page' );
179 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?searchfield=tòmas&offset=0", 'Search the values inserted' );
180 my $text2 = $agent->text() ;
182 ok ( ( length(Encode::encode('UTF-8', $text)) != length($text) ) , 'UTF-8 are multi-byte. Good') ;
183 ok ($text2 =~ m/tòmas/, 'UTF-8 not Latin-1 first test is OK. Good');
184 ok ($text2=~ m/ràmen/, 'UTF-8 not Latin-1 second test is OK. Good');
185 my @links2 = $agent->links;
187 $delete_re = q|op=delete\&searchfield=| . uri_escape_utf8($category) . q|\&id=(\d+)|;
188 foreach my $dato (@links2){
189 my $link = $dato->url;
190 if ($link =~ qr|$delete_re| ){
196 $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' );
198 ok($id_to_del2 ne undef, "error, link to delete not working");
201 Koha::AuthorisedValueCategories->find($category)->delete; # Clean up