Lines 10-18
use t::lib::TestBuilder;
Link Here
|
10 |
|
10 |
|
11 |
use C4::Context; |
11 |
use C4::Context; |
12 |
use Koha::Database; |
12 |
use Koha::Database; |
13 |
use Koha::Upload; |
|
|
14 |
use Koha::UploadedFile; |
13 |
use Koha::UploadedFile; |
15 |
use Koha::UploadedFiles; |
14 |
use Koha::UploadedFiles; |
|
|
15 |
use Koha::Uploader; |
16 |
|
16 |
|
17 |
my $schema = Koha::Database->new->schema; |
17 |
my $schema = Koha::Database->new->schema; |
18 |
$schema->storage->txn_begin; |
18 |
$schema->storage->txn_begin; |
Lines 95-101
sub test01 {
Link Here
|
95 |
is( Koha::UploadedFile->temporary_directory, $tempdir, |
95 |
is( Koha::UploadedFile->temporary_directory, $tempdir, |
96 |
'Check temporary directory' ); |
96 |
'Check temporary directory' ); |
97 |
|
97 |
|
98 |
my $upl = Koha::Upload->new({ |
98 |
my $upl = Koha::Uploader->new({ |
99 |
category => $uploads->[$current_upload]->[0]->{cat}, |
99 |
category => $uploads->[$current_upload]->[0]->{cat}, |
100 |
}); |
100 |
}); |
101 |
my $cgi= $upl->cgi; |
101 |
my $cgi= $upl->cgi; |
Lines 118-124
sub test01 {
Link Here
|
118 |
} |
118 |
} |
119 |
|
119 |
|
120 |
sub test02 { |
120 |
sub test02 { |
121 |
my $upl = Koha::Upload->new({ |
121 |
my $upl = Koha::Uploader->new({ |
122 |
category => $uploads->[$current_upload]->[0]->{cat}, |
122 |
category => $uploads->[$current_upload]->[0]->{cat}, |
123 |
public => 1, |
123 |
public => 1, |
124 |
}); |
124 |
}); |
Lines 138-144
sub test02 {
Link Here
|
138 |
} |
138 |
} |
139 |
|
139 |
|
140 |
sub test03 { |
140 |
sub test03 { |
141 |
my $upl = Koha::Upload->new({ tmp => 1 }); #temporary |
141 |
my $upl = Koha::Uploader->new({ tmp => 1 }); #temporary |
142 |
my $cgi= $upl->cgi; |
142 |
my $cgi= $upl->cgi; |
143 |
is( $upl->count, 1, 'Upload 3 includes one temporary file' ); |
143 |
is( $upl->count, 1, 'Upload 3 includes one temporary file' ); |
144 |
my $rec = Koha::UploadedFiles->find( $upl->result ); |
144 |
my $rec = Koha::UploadedFiles->find( $upl->result ); |
Lines 146-152
sub test03 {
Link Here
|
146 |
} |
146 |
} |
147 |
|
147 |
|
148 |
sub test04 { # Fail on a file already there |
148 |
sub test04 { # Fail on a file already there |
149 |
my $upl = Koha::Upload->new({ |
149 |
my $upl = Koha::Uploader->new({ |
150 |
category => $uploads->[$current_upload]->[0]->{cat}, |
150 |
category => $uploads->[$current_upload]->[0]->{cat}, |
151 |
}); |
151 |
}); |
152 |
my $cgi= $upl->cgi; |
152 |
my $cgi= $upl->cgi; |
Lines 157-163
sub test04 { # Fail on a file already there
Link Here
|
157 |
} |
157 |
} |
158 |
|
158 |
|
159 |
sub test05 { # add temporary file with same name and contents, delete it |
159 |
sub test05 { # add temporary file with same name and contents, delete it |
160 |
my $upl = Koha::Upload->new({ tmp => 1 }); |
160 |
my $upl = Koha::Uploader->new({ tmp => 1 }); |
161 |
my $cgi= $upl->cgi; |
161 |
my $cgi= $upl->cgi; |
162 |
is( $upl->count, 1, 'Upload 5 adds duplicate temporary file' ); |
162 |
is( $upl->count, 1, 'Upload 5 adds duplicate temporary file' ); |
163 |
my $id = $upl->result; |
163 |
my $id = $upl->result; |
Lines 171-177
sub test05 { # add temporary file with same name and contents, delete it
Link Here
|
171 |
|
171 |
|
172 |
# testing delete via UploadedFile (singular) |
172 |
# testing delete via UploadedFile (singular) |
173 |
# Note that find returns a Koha::Object |
173 |
# Note that find returns a Koha::Object |
174 |
$upl = Koha::Upload->new({ tmp => 1 }); |
174 |
$upl = Koha::Uploader->new({ tmp => 1 }); |
175 |
$upl->cgi; |
175 |
$upl->cgi; |
176 |
my $kohaobj = Koha::UploadedFiles->find( $upl->result ); |
176 |
my $kohaobj = Koha::UploadedFiles->find( $upl->result ); |
177 |
my $name = $kohaobj->filename; |
177 |
my $name = $kohaobj->filename; |
Lines 208-226
sub test08 { # allows_add_by
Link Here
|
208 |
value => { flags => 0 }, #no permissions |
208 |
value => { flags => 0 }, #no permissions |
209 |
}); |
209 |
}); |
210 |
my $patronid = $patron->{borrowernumber}; |
210 |
my $patronid = $patron->{borrowernumber}; |
211 |
is( Koha::Upload->allows_add_by( $patron->{userid} ), |
211 |
is( Koha::Uploader->allows_add_by( $patron->{userid} ), |
212 |
undef, 'Patron is not allowed to do anything' ); |
212 |
undef, 'Patron is not allowed to do anything' ); |
213 |
|
213 |
|
214 |
# add some permissions: edit_catalogue |
214 |
# add some permissions: edit_catalogue |
215 |
my $fl = 2**9; # edit_catalogue |
215 |
my $fl = 2**9; # edit_catalogue |
216 |
$schema->resultset('Borrower')->find( $patronid )->update({ flags => $fl }); |
216 |
$schema->resultset('Borrower')->find( $patronid )->update({ flags => $fl }); |
217 |
is( Koha::Upload->allows_add_by( $patron->{userid} ), |
217 |
is( Koha::Uploader->allows_add_by( $patron->{userid} ), |
218 |
undef, 'Patron is still not allowed to add uploaded files' ); |
218 |
undef, 'Patron is still not allowed to add uploaded files' ); |
219 |
|
219 |
|
220 |
# replace flags by all tools |
220 |
# replace flags by all tools |
221 |
$fl = 2**13; # tools |
221 |
$fl = 2**13; # tools |
222 |
$schema->resultset('Borrower')->find( $patronid )->update({ flags => $fl }); |
222 |
$schema->resultset('Borrower')->find( $patronid )->update({ flags => $fl }); |
223 |
is( Koha::Upload->allows_add_by( $patron->{userid} ), |
223 |
is( Koha::Uploader->allows_add_by( $patron->{userid} ), |
224 |
1, 'Patron should be allowed now to add uploaded files' ); |
224 |
1, 'Patron should be allowed now to add uploaded files' ); |
225 |
|
225 |
|
226 |
# remove all tools and add upload_general_files only |
226 |
# remove all tools and add upload_general_files only |
Lines 234-240
sub test08 { # allows_add_by
Link Here
|
234 |
code => 'upload_general_files', |
234 |
code => 'upload_general_files', |
235 |
}, |
235 |
}, |
236 |
}); |
236 |
}); |
237 |
is( Koha::Upload->allows_add_by( $patron->{userid} ), |
237 |
is( Koha::Uploader->allows_add_by( $patron->{userid} ), |
238 |
1, 'Patron is still allowed to add uploaded files' ); |
238 |
1, 'Patron is still allowed to add uploaded files' ); |
239 |
} |
239 |
} |
240 |
|
240 |
|