Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 1bed9601

Von Kivitendo Admin vor mehr als 7 Jahren hinzugefügt

  • ID 1bed9601d931c64f2f3d29bd3d7622ad4283fce4
  • Vorgänger e14e91e1
  • Nachfolger 43de7ef1

SL::Dev::File und t/file/filesystem.t überarbeitet

  • Einrückungen / Syntax überarbeitet
  • Englisch leicht verbessert

SL/Dev/File.pm:

  • die %common_params aus SL/Dev/File sind nur für den speziellen Test
    filesystem.t, daher in den Test verlagert.
  • ebenfalls die get_all, get_all_count entfernt, SL/Dev/ soll nicht nur die
    Anzahl der zu tippenden Zeichen in Tests verringern, sondern allgemeine
    Funktionen für verschiedene Tests bereitstellen oder sinnvolle Defaults
    vorbelegen

Unterschiede anzeigen:

t/file/filesystem.t
9 9
use SL::File;
10 10
use SL::Dev::File qw(create_uploaded create_scanned create_created);
11 11

  
12

  
13 12
Support::TestSetup::login();
14 13

  
15 14
my $temp_dir    = File::Temp::tempdir("kivi-t-file-filesystem.XXXXXX", TMPDIR => 1, CLEANUP => 1);
16 15
my $storage_dir = "$temp_dir/storage";
17 16

  
17
my %common_params = (
18
  object_id   => 1,
19
  object_type => 'sales_order',
20
);
21

  
18 22
mkdir($storage_dir) || die $!;
19 23
{
20 24
local $::lx_office_conf{paths}->{document_path} = $storage_dir;
21 25
$::instance_conf->data;
22 26
local $::instance_conf->{data}{doc_files} = 1;
23 27

  
24
my $scannerfile = "${temp_dir}/f2";
28
my $scanner_file = "${temp_dir}/f2";
25 29

  
26 30
clear_up();
27
reset_state();
28 31

  
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');
32
note('testing SL::File');
33 33

  
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");
34
my $file1 = create_uploaded( %common_params, file_name => 'file1', file_contents => 'content1 uploaded' );
35
my $file2 = create_scanned(  %common_params, file_name => 'file2', file_contents => 'content2 scanned', file_path => $scanner_file );
36
my $file3 = create_created(  %common_params, file_name => 'file3', file_contents => 'content3 created'    );
37
my $file4 = create_created(  %common_params, file_name => 'file3', file_contents => 'content3 new version');
38

  
39
is( SL::File->get_all_count(%common_params), 3, "3 files were created");
40
ok( $file1->file_name              eq 'file1' , "file1 has correct name");
36 41
my $content1 = $file1->get_content;
37
ok( $$content1 eq 'inhalt1 uploaded'                    ,"file has right content");
42
ok( $$content1 eq 'content1 uploaded'         , "file1 has correct content");
38 43

  
39
is( -f $scannerfile ? 1 : 0,                           0,"scanned document is moved from scanner");
44
is( -f $scanner_file ? 1 : 0,                0, "scanned document was moved from scanner");
40 45

  
41 46
$file2->delete;
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");
47
is( -f $scanner_file ? 1 : 0,                1, "scanned document was moved back to scanner");
48
my $content2 = File::Slurp::read_file($scanner_file);
49
ok( $content2 eq 'content2 scanned'           , "scanned file has correct content");
45 50

  
46
my @file5 = SL::Dev::File::get_all(file_name => 'file3');
47
is(   scalar( @file5),                                 1, "one actual file found");
51
my @file5 = SL::File->get_all(%common_params, file_name => 'file3');
52
is( scalar @file5,                           1, "get_all file3: one currnt file found");
48 53
my $content5 = $file5[0]->get_content();
49
ok( $$content5 eq 'inhalt3 new version'                 ,"file has right actual content");
50

  
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");
54
ok( $$content5 eq 'content3 new version'      , "file has correct current content");
57 55

  
58
#print "\n\nController Test:\n";
59
# now test controller
60
#$::form->{object_id}  = 1;
61
#$::form->{object_type}= 'sales_order';
62
#$::form->{file_type}  = 'document';
56
my @file6 = SL::File->get_all_versions(%common_params, file_name => 'file3');
57
is( scalar @file6 ,                           2, "file3: two file versions found");
58
my $content6 = $file6[0]->get_content;
59
ok( $$content6 eq 'content3 new version'      , "file has correct current content");
60
$content6 = $file6[1]->get_content;
61
ok( $$content6 eq 'content3 created'          , "file has correct old content");
63 62

  
63
note('testing controller');
64 64
my $output;
65 65
open(my $outputFH, '>', \$output) or die; # This shouldn't fail
66 66
my $oldFH = select $outputFH;
67 67

  
68
$::form->{id}  = $file1->id;
68
$::form->{id} = $file1->id;
69 69
use SL::Controller::File;
70 70
SL::Controller::File->action_download();
71 71

  
72 72
select $oldFH;
73 73
close $outputFH;
74 74
my @lines = split "\n" , $output;
75
ok($lines[4] eq 'inhalt1 uploaded'                 ,"controller download has correct content");
75
ok($lines[4] eq 'content1 uploaded', "controller download has correct content");
76 76

  
77 77
#some controller checks
78
$::form = Support::TestSetup->create_new_form;
78 79
$::form->{object_id}   = 12345678;
79 80
$::form->{object_type} = undef;
80 81
my $result='xx1';
81 82
eval {
82 83
  SL::Controller::File->check_object_params();
83
  $result='yy1';
84
  $result = 'yy1';
84 85
  1;
85 86
} or do {
86
  $result=$@;
87
  $result = $@;
87 88
};
88
$result = substr($result,0,14);
89
#print $result."\n";
90
ok($result eq "No object type","correct error 'No object type'");
89
is(substr($result,0,14), "No object type", "controller error response 'No object type' ok");
90

  
91
$::form = Support::TestSetup->create_new_form;
92
$::form->{object_type} = 'sales_order';
93
$::form->{file_type}   = '';
91 94

  
92
$::form->{object_type} ='sales_order';
93
$::form->{file_type} ='';
94 95
$result='xx2';
95 96
eval {
96 97
  SL::Controller::File->check_object_params();
......
99 100
} or do {
100 101
  $result=$@;
101 102
};
102
$result = substr($result,0,12);
103
#print $result."\n";
104
ok($result eq "No file type","correct error 'No file type'");
105

  
106
clear_up();
107
done_testing;
103
is(substr($result,0,12), "No file type", "controller error response 'No file type' ok");
108 104

  
109 105
sub clear_up {
110 106
  # Cleaning up may fail.
111 107
  eval {
112
    SL::Dev::File::delete_all();
113
    unlink($scannerfile);
108
    SL::File->delete_all(%common_params);
109
    unlink($scanner_file);
114 110
  };
115 111
}
116 112

  
117 113
}
118 114

  
119
sub reset_state {
120
  my %params = @_;
121

  
122
};
115
clear_up();
116
done_testing;
123 117

  
124 118
1;

Auch abrufbar als: Unified diff