View | Details | Raw Unified | Return to bug 17934
Collapse All | Expand All

(-)a/t/db_dependent/www/auth_values_input_www.t (-49 / +58 lines)
Lines 18-24 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use utf8;
20
use utf8;
21
use Test::More tests => 33;
21
use Test::More tests => 34;
22
use Test::WWW::Mechanize;
22
use Test::WWW::Mechanize;
23
use XML::Simple;
23
use XML::Simple;
24
use JSON;
24
use JSON;
Lines 27-73 use File::Spec; Link Here
27
use POSIX;
27
use POSIX;
28
use URI::Escape;
28
use URI::Escape;
29
use Encode;
29
use Encode;
30
use Carp;
31
use Module::Load::Conditional qw/check_install can_load/;
30
32
31
my $testdir = File::Spec->rel2abs( dirname(__FILE__) );
33
my $skip_all = q{};
34
if ( ! check_install( module => 'C4::Context' ) ) {
35
    $skip_all = "Tests skipped. You must have a working C4::Context.\n";
36
}
37
elsif ( ! can_load( modules => { 'C4::Context' => undef } ) ) {
38
    $skip_all = "Tests skipped. You must be able to load C4::Context.\n";
39
}
32
40
33
my $koha_conf = $ENV{KOHA_CONF};
41
my $koha_conf = $ENV{KOHA_CONF};
34
my $xml       = XMLin($koha_conf);
42
my ($xml, $user, $password);
35
43
if ($koha_conf) {
36
eval{
44
    $xml       = XMLin($koha_conf);
37
    use C4::Context;
45
    $user     = $ENV{KOHA_USER} || $xml->{config}->{user};
38
};
46
    $password = $ENV{KOHA_PASS} || $xml->{config}->{pass};
39
if ($@) {
47
}
40
    plan skip_all => "Tests skip. You must have a working Context\n";
48
elsif ($skip_all eq q{}) {
49
    $skip_all = "Tests skipped. You must set env. variable KOHA_CONF to run tests.\n";
41
}
50
}
42
51
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};
52
my $intranet = $ENV{KOHA_INTRANET_URL};
46
53
47
if (not defined $intranet) {
54
if ($skip_all eq q{} && ! $intranet) {
48
    plan skip_all => "Tests skip. You must set env. variable KOHA_INTRANET_URL to do tests\n";
55
    $skip_all = "Tests skipped. You must set env. variable KOHA_INTRANET_URL to run tests\n";
49
}
56
}
50
57
58
if (length $skip_all > 0) {
59
    croak $skip_all; # to keep Test Summary output
60
}
61
62
use_ok('C4::Context');
51
my $dbh = C4::Context->dbh;
63
my $dbh = C4::Context->dbh;
52
64
53
$intranet =~ s#/$##;
65
$intranet =~ s/\/$//xsm;
54
66
55
my $agent = Test::WWW::Mechanize->new( autocheck => 1 );
67
my $agent = Test::WWW::Mechanize->new( autocheck => 1 );
56
my $jsonresponse;
57
my ($category, $expected_base, $add_form_link_exists, $delete_form_link_exists);
68
my ($category, $expected_base, $add_form_link_exists, $delete_form_link_exists);
58
69
59
# -------------------------------------------------- LOGIN
70
# -------------------------------------------------- LOGIN
60
71
61
62
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'connect to intranet' );
72
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'connect to intranet' );
63
$agent->form_name('loginform');
73
$agent->form_name('loginform');
64
$agent->field( 'password', $password );
74
$agent->field( 'password', $password );
65
$agent->field( 'userid',   $user );
75
$agent->field( 'userid',   $user );
66
$agent->field( 'branch',   '' );
76
$agent->field( 'branch',   q{} );
67
$agent->click_ok( '', 'login to staff client' );
77
$agent->click_ok( q{}, 'login to staff client' );
68
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'load main page' );
78
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'load main page' );
69
79
70
#--------------------------------------------------- Test with corean and greek chars
80
#--------------------------------------------------- Test with Korean and greek chars
71
81
72
$category = '学協会μμ';
82
$category = '学協会μμ';
73
$dbh->do(q|DELETE FROM authorised_values WHERE category = ?|, undef, $category);
83
$dbh->do(q|DELETE FROM authorised_values WHERE category = ?|, undef, $category);
Lines 78-89 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Connect to Link Here
78
$agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?op=add_form", 'Open to create a new category' );
88
$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');
89
$agent->form_name('Aform');
80
$agent->field('category', $category);
90
$agent->field('category', $category);
81
$agent->click_ok( '', "Create new AV category " );
91
$agent->click_ok( q{}, 'Create new AV category ' );
82
92
83
$agent->base_like(qr|$expected_base|, "check base");
93
$agent->base_like(qr/$expected_base/xsm, 'check base');
84
$add_form_link_exists = 0;
94
$add_form_link_exists = 0;
85
for my $link ( $agent->links() ) {
95
for my $link ( $agent->links() ) {
86
    if ( $link->url =~ m|authorised_values.pl\?op=add_form&category=$category| ) {
96
    if ( $link->url =~ m/authorised_values.pl\x3Fop=add_form&category=$category/xsm ) {
87
        $add_form_link_exists = 1;
97
        $add_form_link_exists = 1;
88
    }
98
    }
89
}
99
}
Lines 94-127 $agent->form_name('Aform'); Link Here
94
$agent->field('authorised_value', 'επιμεq');
104
$agent->field('authorised_value', 'επιμεq');
95
$agent->field('lib_opac', 'autdesc2');
105
$agent->field('lib_opac', 'autdesc2');
96
$agent->field('lib', 'desc1');
106
$agent->field('lib', 'desc1');
97
$agent->field('branches', '');
107
$agent->field('branches', q{});
98
$agent->click_ok( '', "Create a new value for the category" );
108
$agent->click_ok( q{}, 'Create a new value for the category' );
99
109
100
$agent->base_like(qr|$expected_base|, "check base");
110
$agent->base_like(qr/$expected_base/xsm, 'check base');
101
$add_form_link_exists = 0;
111
$add_form_link_exists = 0;
102
$delete_form_link_exists = 0;
112
$delete_form_link_exists = 0;
103
for my $link ( $agent->links() ) {
113
for my $link ( $agent->links() ) {
104
    if ( $link->url =~ m|authorised_values.pl\?op=add_form&category=$category| ) {
114
    if ( $link->url =~ m/authorised_values.pl\x3Fop=add_form&category=$category/xsm ) {
105
        $add_form_link_exists = 1;
115
        $add_form_link_exists = 1;
106
    }elsif( $link->url =~ m|authorised_values.pl\?op=delete&searchfield=$category| ) {
116
    }elsif( $link->url =~ m/authorised_values.pl\x3Fop=delete&searchfield=$category/xsm ) {
107
        $delete_form_link_exists = 1;
117
        $delete_form_link_exists = 1;
108
    }
118
    }
109
}
119
}
110
is( $add_form_link_exists, 1, 'Add a new category button should be displayed');
120
is( $add_form_link_exists, 1, 'Add a new category button should be displayed');
111
is( $delete_form_link_exists, 1, '');
121
is( $delete_form_link_exists, 1, q{});
112
122
113
$agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Return to Authorized values page' );
123
$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' );
124
$agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?searchfield=学協会μμ&offset=0", 'Search the values inserted' );
115
my $text = $agent->text() ;
125
my $text = $agent->text() ;
116
#Tests on UTF-8
126
#Tests on UTF-8
117
ok ( ( length(Encode::encode('UTF-8', $text)) != length($text) ) , 'UTF-8 are multi-byte. Good') ;
127
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');
128
ok ($text =~  m/学協会μμ/xsm, 'UTF-8 (Asia) chars are correctly present. Good');
119
ok ($text =~  m/επιμεq/, 'UTF-8 (Greek) chars are correctly present. Good');
129
ok ($text =~  m/επιμεq/xsm, 'UTF-8 (Greek) chars are correctly present. Good');
120
my @links = $agent->links;
130
my @links = $agent->links;
121
my $id_to_del ='';
131
my $id_to_del =q{};
122
foreach my $dato (@links){
132
foreach my $dato (@links){
123
    my $link = $dato->url;
133
    my $link = $dato->url;
124
    if ($link =~  m/op=delete\&searchfield=学協会μμ\&id=(\d+)/){
134
    if ($link =~  m/op=delete\&searchfield=学協会μμ\&id=(\d+)/xsm){
125
        $id_to_del = $1;
135
        $id_to_del = $1;
126
        last;
136
        last;
127
    }
137
    }
Lines 129-135 foreach my $dato (@links){ Link Here
129
if ($id_to_del) {
139
if ($id_to_del) {
130
    $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?op=delete&searchfield=学協会μμ&id=$id_to_del", 'UTF_8 auth. value deleted' );
140
    $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?op=delete&searchfield=学協会μμ&id=$id_to_del", 'UTF_8 auth. value deleted' );
131
}else{
141
}else{
132
    ok($id_to_del ne undef, "error, link to delete not working");
142
    ok($id_to_del ne undef, 'error, link to delete not working');
133
}
143
}
134
144
135
#---------------------------------------- Test with only latin utf-8 (could be taken as Latin-1/ISO 8859-1)
145
#---------------------------------------- Test with only latin utf-8 (could be taken as Latin-1/ISO 8859-1)
Lines 142-183 $agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl", 'Connect to Link Here
142
$agent->get_ok( "$intranet/cgi-bin/koha/admin/authorised_values.pl?op=add_form", 'Open to create a new category' );
152
$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');
153
$agent->form_name('Aform');
144
$agent->field('category', $category);
154
$agent->field('category', $category);
145
$agent->click_ok( '', "Create new AV category" );
155
$agent->click_ok( q{}, 'Create new AV category' );
146
156
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' );
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' );
148
$agent->form_name('Aform');
158
$agent->form_name('Aform');
149
$agent->field('authorised_value', 'ràmen');
159
$agent->field('authorised_value', 'ràmen');
150
$agent->field('lib_opac', 'autdesc2');
160
$agent->field('lib_opac', 'autdesc2');
151
$agent->field('lib', 'desc1');
161
$agent->field('lib', 'desc1');
152
$agent->field('branches', '');
162
$agent->field('branches', q{});
153
$agent->click_ok( '', "Create a new value for the category" );
163
$agent->click_ok( q{}, 'Create a new value for the category' );
154
164
155
$expected_base = q|authorised_values.pl|;
165
$expected_base = q|authorised_values.pl|;
156
$agent->base_like(qr|$expected_base|, "check base");
166
$agent->base_like(qr/$expected_base/xsm, 'check base');
157
$add_form_link_exists = 0;
167
$add_form_link_exists = 0;
158
$delete_form_link_exists = 0;
168
$delete_form_link_exists = 0;
159
for my $link ( $agent->links() ) {
169
for my $link ( $agent->links() ) {
160
    if ( $link->url =~ m|authorised_values.pl\?op=add_form&category=$category| ) {
170
    if ( $link->url =~ m/authorised_values.pl\x3Fop=add_form&category=$category/xsm ) {
161
        $add_form_link_exists = 1;
171
        $add_form_link_exists = 1;
162
    }elsif( $link->url =~ m|authorised_values.pl\?op=delete&searchfield=$category| ) {
172
    }elsif( $link->url =~ m/authorised_values.pl\x3Fop=delete&searchfield=$category/xsm ) {
163
        $delete_form_link_exists = 1;
173
        $delete_form_link_exists = 1;
164
    }
174
    }
165
}
175
}
166
is( $add_form_link_exists, 1, );
176
is( $add_form_link_exists, 1, 'Add form link exists');
167
is( $delete_form_link_exists, 1, );
177
is( $delete_form_link_exists, 1, 'Delete form link exists');
168
178
169
$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", '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' );
180
$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() ;
181
my $text2 = $agent->text() ;
172
#Tests on UTF-8
182
#Tests on UTF-8
173
ok ( ( length(Encode::encode('UTF-8', $text)) != length($text) ) , 'UTF-8 are multi-byte. Good') ;
183
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');
184
ok ($text2 =~  m/tòmas/xsm, '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');
185
ok ($text2=~  m/ràmen/xsm, 'UTF-8 not Latin-1 second test is OK. Good');
176
my @links2 = $agent->links;
186
my @links2 = $agent->links;
177
my $id_to_del2 ='';
187
my $id_to_del2 =q{};
178
foreach my $dato (@links2){
188
foreach my $dato (@links2){
179
    my $link = $dato->url;
189
    my $link = $dato->url;
180
    if ($link =~  m/op=delete\&searchfield=tòmas\&id=(\d+)/){
190
    if ($link =~  m/op=delete\&searchfield=tòmas\&id=(\d+)/xsm){
181
        $id_to_del2 = $1;
191
        $id_to_del2 = $1;
182
        last;
192
        last;
183
    }
193
    }
Lines 185-191 foreach my $dato (@links2){ Link Here
185
if ($id_to_del2) {
195
if ($id_to_del2) {
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' );
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' );
187
}else{
197
}else{
188
    ok($id_to_del2 ne undef, "error, link to delete not working");
198
    ok($id_to_del2 ne undef, 'error, link to delete not working');
189
}
199
}
190
200
191
1;
201
1;
192
- 

Return to bug 17934