314a2f23dca0d8ec7c435daacbbc09346dc5c9ab
[kivitendo-erp.git] / filesystem.t
1 use strict;
2 use Test::More tests => 11;
3
4 use lib 't';
5 use Support::TestSetup;
6 use Test::Exception;
7 use SL::File;
8 use SL::Dev::File;
9
10 Support::TestSetup::login();
11
12 my $db = SL::DB::Object->new->db;
13 $db->dbh->do("UPDATE defaults SET doc_files = 't'");
14 $db->dbh->do("UPDATE defaults SET doc_files_rootpath = '/var/tmp/kivifs'");
15
16 my $scannerfile = '/var/tmp/f2';
17
18 clear_up();
19 reset_state();
20
21 my $file1 = SL::Dev::File::create_uploaded( file_name => 'file1', file_contents => 'inhalt1 uploaded' );
22 my $file2 = SL::Dev::File::create_scanned(  file_name => 'file2', file_contents => 'inhalt2 scanned', file_path => $scannerfile );
23 my $file3 = SL::Dev::File::create_created(  file_name => 'file3', file_contents => 'inhalt3 created'    );
24 my $file4 = SL::Dev::File::create_created(  file_name => 'file3', file_contents => 'inhalt3 new version');
25
26 is( SL::Dev::File->get_all_count(),                    3,"total number of files created is 3");
27 ok( $file1->file_name                        eq 'file1' ,"file has right name");
28 my $content1 = $file1->get_content;
29 ok( $$content1 eq 'inhalt1 uploaded'                    ,"file has right content");
30
31 is( -f $scannerfile ? 1 : 0,                           0,"scanned document is moved from scanner");
32
33 $file2->delete;
34 is( -f $scannerfile ? 1 : 0,                           1,"scanned document is moved back to scanner");
35 my $content2 = File::Slurp::read_file($scannerfile);
36 ok( $content2 eq 'inhalt2 scanned'                      ,"scanned file has right content");
37
38 my @file5 = SL::Dev::File->get_all(file_name => 'file3');
39 is(   scalar( @file5),                                 1, "one actual file found");
40 my $content5 = $file5[0]->get_content();
41 ok( $$content5 eq 'inhalt3 new version'                 ,"file has right actual content");
42
43 my @file6 = SL::Dev::File->get_all_versions(file_name => 'file3');
44 is(   scalar( @file6),                                 2,"two file versions found");
45 $content5 = $file6[0]->get_content;
46 ok( $$content5 eq 'inhalt3 new version'                 ,"file has right actual content");
47 $content5 = $file6[1]->get_content;
48 ok( $$content5 eq 'inhalt3 created'                     ,"file has right old content");
49
50 print "\n\nController:\n";
51 # now test controller
52 #$::form->{object_id}  = 1;
53 #$::form->{object_type}= 'sales_order';
54 #$::form->{file_type}  = 'document';
55 $::form->{id}  = $file1->id;
56 print "id=".$::form->{id}."\n";
57 use SL::Controller::File;
58 SL::Controller::File->action_download();
59 $::form->{object_id}   = 12345678;
60 $::form->{object_type} = undef;
61 eval {
62   SL::Controller::File->check_object_params();
63   1;
64 } or do {
65     print $@;
66 };
67 $::form->{object_type} ='xx';
68 $::form->{file_type} ='yy';
69 eval {
70   SL::Controller::File->check_object_params();
71   1;
72 } or do {
73     print $@;
74 };
75
76 clear_up();
77 done_testing;
78
79 sub clear_up {
80   SL::Dev::File->delete_all();
81   unlink($scannerfile);
82 };
83
84 sub reset_state {
85   my %params = @_;
86
87 };
88
89 1;