2 use Test::More tests => 14;
7 use Support::TestSetup;
10 use SL::Dev::File qw(create_uploaded create_scanned create_created);
13 Support::TestSetup::login();
15 my $temp_dir = File::Temp::tempdir("kivi-t-file-filesystem.XXXXXX", TMPDIR => 1, CLEANUP => 1);
16 my $storage_dir = "$temp_dir/storage";
18 mkdir($storage_dir) || die $!;
20 local $::lx_office_conf{paths}->{document_path} = $storage_dir;
21 $::instance_conf->data;
22 local $::instance_conf->{data}{doc_files} = 1;
24 my $scannerfile = "${temp_dir}/f2";
29 my $file1 = create_uploaded( file_name => 'file1', file_contents => 'inhalt1 uploaded' );
30 my $file2 = create_scanned( file_name => 'file2', file_contents => 'inhalt2 scanned', file_path => $scannerfile );
31 my $file3 = create_created( file_name => 'file3', file_contents => 'inhalt3 created' );
32 my $file4 = create_created( file_name => 'file3', file_contents => 'inhalt3 new version');
34 is( SL::Dev::File::get_all_count(), 3,"total number of files created is 3");
35 ok( $file1->file_name eq 'file1' ,"file has right name");
36 my $content1 = $file1->get_content;
37 ok( $$content1 eq 'inhalt1 uploaded' ,"file has right content");
39 is( -f $scannerfile ? 1 : 0, 0,"scanned document is moved from scanner");
42 is( -f $scannerfile ? 1 : 0, 1,"scanned document is moved back to scanner");
43 my $content2 = File::Slurp::read_file($scannerfile);
44 ok( $content2 eq 'inhalt2 scanned' ,"scanned file has right content");
46 my @file5 = SL::Dev::File::get_all(file_name => 'file3');
47 is( scalar( @file5), 1, "one actual file found");
48 my $content5 = $file5[0]->get_content();
49 ok( $$content5 eq 'inhalt3 new version' ,"file has right actual content");
51 my @file6 = SL::Dev::File::get_all_versions(file_name => 'file3');
52 is( scalar( @file6), 2,"two file versions found");
53 $content5 = $file6[0]->get_content;
54 ok( $$content5 eq 'inhalt3 new version' ,"file has right actual content");
55 $content5 = $file6[1]->get_content;
56 ok( $$content5 eq 'inhalt3 created' ,"file has right old content");
58 #print "\n\nController Test:\n";
60 #$::form->{object_id} = 1;
61 #$::form->{object_type}= 'sales_order';
62 #$::form->{file_type} = 'document';
65 open(my $outputFH, '>', \$output) or die; # This shouldn't fail
66 my $oldFH = select $outputFH;
68 $::form->{id} = $file1->id;
69 use SL::Controller::File;
70 SL::Controller::File->action_download();
74 my @lines = split "\n" , $output;
75 ok($lines[4] eq 'inhalt1 uploaded' ,"controller download has correct content");
77 #some controller checks
78 $::form->{object_id} = 12345678;
79 $::form->{object_type} = undef;
82 SL::Controller::File->check_object_params();
88 $result = substr($result,0,14);
90 ok($result eq "No object type","correct error 'No object type'");
92 $::form->{object_type} ='sales_order';
93 $::form->{file_type} ='';
96 SL::Controller::File->check_object_params();
102 $result = substr($result,0,12);
104 ok($result eq "No file type","correct error 'No file type'");
110 # Cleaning up may fail.
112 SL::Dev::File::delete_all();
113 unlink($scannerfile);