bae6a43cc82120aa50908a72884c08facddfb31d
[kivitendo-erp.git] / t / request / post_multipart.t
1 use strict;
2 use utf8;
3
4 use lib 't';
5 BEGIN {
6   unshift @INC, 'modules/override';
7 }
8
9 use Support::TestSetup;
10 use Test::More tests => 2;
11 use Data::Dumper;
12 require Test::Deep;
13 use Encode;
14
15 use SL::Request;
16
17 Support::TestSetup::login();
18
19 open my $fh, '<', 't/request/post_multipart_1' or die "can't load test";
20 my $data = do { $/ = undef; <$fh> };
21
22 my $t = {};
23 my $tt = {};
24
25 local $ENV{CONTENT_TYPE} = 'multipart/form-data; boundary=---------------------------23281168279961';
26 SL::Request::_parse_multipart_formdata($t, $tt, $data);
27
28
29 my $blob = Encode::encode('utf-8', qq|\x{feff}Stunde;Montag;Dienstag;Mittwoch;Donnerstag;Freitag
30 1;Mathe;Deutsch;Englisch;Mathe;Kunst
31 2;Sport;Französisch;Geschichte;Sport;Geschichte
32 3;Sport;"Religion ev;kath";Kunst;;Kunst|);
33
34 my $t_cmp = {
35           'profile' => {
36                        'name' => undef,
37                        'type' => undef
38                      },
39           'quote_char' => undef,
40           'file' => $blob,
41           'custom_sep_char' => undef,
42           'sep_char' => undef,
43           'settings' => {
44                         'article_number_policy' => undef,
45                         'sellprice_places' => undef,
46                         'charset' => undef,
47                         'apply_buchungsgruppe' => undef,
48                         'full_preview' => undef,
49                         'part_type' => undef,
50                         'default_unit' => undef,
51                         'default_buchungsgruppe' => undef,
52                         'duplicates' => undef,
53                         'numberformat' => undef,
54                         'sellprice_adjustment_type' => undef,
55                         'shoparticle_if_missing' => undef,
56                         'sellprice_adjustment' => undef
57                       },
58           'custom_escape_char' => undef,
59           'action_test' => undef,
60           'custom_quote_char' => undef,
61           'escape_char' => undef,
62           'action' => undef
63         };
64 $t_cmp->{ATTACHMENTS}{file}{data} =  \$t_cmp->{'file'};
65
66
67 is_deeply $t, $t_cmp;
68
69 is_deeply $tt,
70         {
71           'profile' => {
72                        'name' => '',
73                        'type' =>'parts',
74                      },
75           'file' => undef,
76           'quote_char' => 'quote',
77           'custom_sep_char' => '',
78           'sep_char' => 'semicolon',
79           'settings' => {
80                         'article_number_policy' => 'update_prices',
81                         'sellprice_places' => 2,
82                         'charset' => 'UTF-8',
83                         'apply_buchungsgruppe' => 'all',
84                         'full_preview' => '0',
85                         'part_type' => 'part',
86                         'default_unit' => 'g',
87                         'default_buchungsgruppe' => '815',
88                         'duplicates' => 'no_check',
89                         'numberformat' => '1.000,00',
90                         'sellprice_adjustment_type' => 'percent',
91                         'shoparticle_if_missing' => '0',
92                         'sellprice_adjustment' =>'0'
93                       },
94           'custom_escape_char' => '',
95           'action_test' => 'Test und Vorschau',
96           'ATTACHMENTS' => {
97                            'file' => {
98                                      'filename' => 'from_wikipedia.csv'
99                                    }
100                          },
101           'custom_quote_char' => '',
102           'escape_char' => 'quote',
103           'action' => 'CsvImport/dispatch',
104           'FILENAME' => 'from_wikipedia.csv'
105         };