Bug 14077: Remove unused AUTH_UPDATE_FAILED from moremember.tt
[koha.git] / t / db_dependent / Borrower_Files.t
blob281cefde37e91d960b776a9b71847bc4c1e9c4d3
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Copyright 2014 Biblibre SARL
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.
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.
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>.
20 use Modern::Perl;
22 use C4::Context;
23 use C4::Members;
25 use Test::More tests => 23;
27 use_ok('Koha::Borrower::Files');
29 my $dbh = C4::Context->dbh;
30 $dbh->{AutoCommit} = 0;
31 $dbh->{RaiseError} = 1;
33 $dbh->do(q|DELETE FROM issues|);
34 $dbh->do(q|DELETE FROM borrowers|);
35 $dbh->do(q|DELETE FROM borrower_files|);
37 my $borrowernumber = AddMember(
38 firstname => 'my firstname',
39 surname => 'my surname',
40 categorycode => 'S',
41 branchcode => 'CPL',
44 my $bf = Koha::Borrower::Files->new(
45 borrowernumber => $borrowernumber,
49 my $addFile = $bf->AddFile(
50 name => 'my filename',
51 type => 'text/plain',
53 is( $addFile, undef, 'AddFile without the required parameter content returns undef' );
54 my $files = $bf->GetFilesInfo();
55 is( @$files, 0, 'AddFile does not add a file without the parameter content' );
57 $addFile = $bf->AddFile(
58 type => 'text/plain',
59 content => 'my filecontent',
61 is( $addFile, undef, 'AddFile without the required parameter name returns undef' );
62 $files = $bf->GetFilesInfo();
63 is( @$files, 0, 'AddFile does not add a file without the parameter name' );
66 my $file1 = {
67 name => 'my filename1',
68 type => 'text/plain',
69 content => 'my filecontent1',
71 $addFile = $bf->AddFile(%$file1);
72 is( $addFile, 1, 'AddFile with the required parameters returns 1' );
73 $files = $bf->GetFilesInfo();
74 is( @$files, 1, 'GetFilesInfo returns 1 file' );
75 is( $files->[0]->{file_name}, $file1->{name}, 'Correctly stored name' );
76 is( $files->[0]->{file_type}, $file1->{type}, 'Correctly stored type' );
79 my $file2 = {
80 name => 'my filename2',
81 type => 'text/html',
82 description => 'my filedescription2',
83 content => 'my filecontent2',
85 $addFile = $bf->AddFile(%$file2);
86 is( $addFile, 1, 'AddFile with the required parameters returns 1' );
87 $files = $bf->GetFilesInfo();
88 is( @$files, 2, "GetFilesInfo returns 2 files" );
89 is( $files->[1]->{file_name}, $file2->{name}, 'Correctly stored name' );
90 is( $files->[1]->{file_type}, $file2->{type}, 'Correctly stored type' );
91 is( $files->[1]->{file_description}, $file2->{description}, 'Correctly stored description' );
93 my $file = $bf->GetFile();
94 is( $file, undef, 'GetFile without parameters returns undef' );
96 $file = $bf->GetFile(
97 id => $files->[1]->{file_id},
99 is( $file->{file_name}, $files->[1]->{file_name}, 'GetFile returns the correct name' );
100 is( $file->{file_type}, $files->[1]->{file_type}, 'GetFile returns the correct type' );
101 is( $file->{file_description}, $files->[1]->{file_description}, 'GetFile returns the correct description' );
104 $bf->DelFile();
105 $files = $bf->GetFilesInfo();
106 is( @$files, 2, 'DelFile without parameters does not delete a file' );
108 $bf->DelFile(
109 id => $files->[1]->{file_id},
111 $files = $bf->GetFilesInfo();
112 is( @$files, 1, 'DelFile delete a file' );
113 is( $files->[0]->{file_name}, $file1->{name}, 'DelFile delete the correct entry' );
114 is( $files->[0]->{file_type}, $file1->{type}, 'DelFile delete the correct entry' );
116 $bf->DelFile(
117 id => $files->[0]->{file_id},
119 $files = $bf->GetFilesInfo();
120 is( @$files, 0, 'DelFile delete a file' );
122 $dbh->rollback;