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

(-)a/t/db_dependent/Borrower_Files.t (-1 / +121 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright 2014  Biblibre SARL
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use C4::Context;
23
use C4::Members;
24
25
use Test::More tests => 23;
26
27
use_ok('Koha::Borrower::Files');
28
29
my $dbh = C4::Context->dbh;
30
$dbh->{AutoCommit} = 0;
31
$dbh->{RaiseError} = 1;
32
33
$dbh->do(q|DELETE FROM borrowers|);
34
$dbh->do(q|DELETE FROM borrower_files|);
35
36
my $borrowernumber = AddMember(
37
    firstname =>  'my firstname',
38
    surname => 'my surname',
39
    categorycode => 'S',
40
    branchcode => 'CPL',
41
);
42
43
my $bf = Koha::Borrower::Files->new(
44
    borrowernumber => $borrowernumber,
45
);
46
47
48
my $addFile = $bf->AddFile(
49
    name => 'my filename',
50
    type => 'text/plain',
51
);
52
is( $addFile, undef, 'AddFile without the required parameter content returns undef' );
53
my $files = $bf->GetFilesInfo();
54
is( @$files, 0, 'AddFile does not add a file without the parameter content' );
55
56
$addFile = $bf->AddFile(
57
    type => 'text/plain',
58
    content => 'my filecontent',
59
);
60
is( $addFile, undef, 'AddFile without the required parameter name returns undef' );
61
$files = $bf->GetFilesInfo();
62
is( @$files, 0, 'AddFile does not add a file without the parameter name' );
63
64
65
my $file1 = {
66
    name => 'my filename1',
67
    type => 'text/plain',
68
    content => 'my filecontent1',
69
};
70
$addFile = $bf->AddFile(%$file1);
71
is( $addFile, 1, 'AddFile with the required parameters returns 1' );
72
$files = $bf->GetFilesInfo();
73
is( @$files, 1, 'GetFilesInfo returns 1 file' );
74
is( $files->[0]->{file_name}, $file1->{name}, 'Correctly stored name' );
75
is( $files->[0]->{file_type}, $file1->{type}, 'Correctly stored type' );
76
77
78
my $file2 = {
79
    name => 'my filename2',
80
    type => 'text/html',
81
    description => 'my filedescription2',
82
    content => 'my filecontent2',
83
};
84
$addFile = $bf->AddFile(%$file2);
85
is( $addFile, 1, 'AddFile with the required parameters returns 1' );
86
$files = $bf->GetFilesInfo();
87
is( @$files, 2, "GetFilesInfo returns 2 files" );
88
is( $files->[1]->{file_name}, $file2->{name}, 'Correctly stored name' );
89
is( $files->[1]->{file_type}, $file2->{type}, 'Correctly stored type' );
90
is( $files->[1]->{file_description}, $file2->{description}, 'Correctly stored description' );
91
92
my $file = $bf->GetFile();
93
is( $file, undef, 'GetFile without parameters returns undef' );
94
95
$file = $bf->GetFile(
96
    id => $files->[1]->{file_id},
97
);
98
is( $file->{file_name}, $files->[1]->{file_name}, 'GetFile returns the correct name' );
99
is( $file->{file_type}, $files->[1]->{file_type}, 'GetFile returns the correct type' );
100
is( $file->{file_description}, $files->[1]->{file_description}, 'GetFile returns the correct description' );
101
102
103
$bf->DelFile();
104
$files = $bf->GetFilesInfo();
105
is( @$files, 2, 'DelFile without parameters does not delete a file' );
106
107
$bf->DelFile(
108
    id => $files->[1]->{file_id},
109
);
110
$files = $bf->GetFilesInfo();
111
is( @$files, 1, 'DelFile delete a file' );
112
is( $files->[0]->{file_name}, $file1->{name}, 'DelFile delete the correct entry' );
113
is( $files->[0]->{file_type}, $file1->{type}, 'DelFile delete the correct entry' );
114
115
$bf->DelFile(
116
    id => $files->[0]->{file_id},
117
);
118
$files = $bf->GetFilesInfo();
119
is( @$files, 0, 'DelFile delete a file' );
120
121
$dbh->rollback;

Return to bug 12417