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