Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision af205393

Von Bernd Blessmann vor fast 11 Jahren hinzugefügt

  • ID af2053931fb484b246ba42f93df4889c4257ab42
  • Vorgänger c8473408
  • Nachfolger 4b84cde9

SL::Helper::Csv kann mit Multiplex-Daten (mehreren Profilen) umgehen.

Unterschiede anzeigen:

t/helper/csv.t
1
use Test::More tests => 47;
1
use Test::More tests => 56;
2 2

  
3 3
use lib 't';
4 4
use utf8;
......
11 11
Support::TestSetup::login();
12 12

  
13 13
my $csv = SL::Helper::Csv->new(
14
  file    => \"Kaffee\n",
15
  header  => [ 'description' ],
16
  profile => { class  => 'SL::DB::Part', },
14
  file    => \"Kaffee\n",       # " # make emacs happy
15
  header  => [[ 'description' ]],
16
  profile => [{ class  => 'SL::DB::Part', }],
17 17
);
18 18

  
19 19
isa_ok $csv->_csv, 'Text::CSV_XS';
......
29 29

  
30 30
$csv = SL::Helper::Csv->new(
31 31
  file    => \"Kaffee;0.12;12,2;1,5234\n",
32
  header  => [ 'description', 'sellprice', 'lastcost_as_number', 'listprice' ],
33
  profile => {profile => { listprice => 'listprice_as_number' },
34
              class   => 'SL::DB::Part',},
32
  header  => [[ 'description', 'sellprice', 'lastcost_as_number', 'listprice' ]],
33
  profile => [{profile => { listprice => 'listprice_as_number' },
34
               class   => 'SL::DB::Part',}],
35 35
);
36 36
$csv->parse;
37 37

  
......
49 49
EOL
50 50
  sep_char => ',',
51 51
  quote_char => "'",
52
  profile => {profile => { listprice => 'listprice_as_number' },
53
              class   => 'SL::DB::Part',}
52
  profile => [{profile => { listprice => 'listprice_as_number' },
53
               class   => 'SL::DB::Part',}]
54 54
);
55 55
$csv->parse;
56 56
is scalar @{ $csv->get_objects }, 1, 'auto header works';
......
64 64
;;description;sellprice;lastcost_as_number;
65 65
#####;Puppy;Kaffee;0.12;12,2;1,5234
66 66
EOL
67
  profile => {class  => 'SL::DB::Part'},
67
  profile => [{class  => 'SL::DB::Part'}],
68 68
);
69 69
$csv->parse;
70 70
is scalar @{ $csv->get_objects }, 1, 'bozo header doesn\'t blow things up';
......
77 77
Kaffee;;0.12;12,2;1,5234
78 78
Beer;1123245;0.12;12,2;1,5234
79 79
EOL
80
  profile => {class  => 'SL::DB::Part'},
80
  profile => [{class  => 'SL::DB::Part'}],
81 81
);
82 82
$csv->parse;
83 83
is scalar @{ $csv->get_objects }, 2, 'multiple objects work';
......
93 93
Beer;1123245;0.12;1.5234
94 94
EOL
95 95
  numberformat => '1,000.00',
96
  profile => {class  => 'SL::DB::Part'},
96
  profile => [{class  => 'SL::DB::Part'}],
97 97
);
98 98
$csv->parse;
99 99
is $csv->get_objects->[0]->lastcost, '1221.52', 'formatnumber';
......
107 107
Beer;1123245;0.12;1.5234
108 108
EOL
109 109
  numberformat => '1,000.00',
110
  profile => {class  => 'SL::DB::Part'},
110
  profile => [{class  => 'SL::DB::Part'}],
111 111
);
112 112
is $csv->parse, undef, 'broken csv header won\'t get parsed';
113 113

  
......
120 120
Beer;1123245;0.12;1.5234
121 121
EOL
122 122
  numberformat => '1,000.00',
123
  profile => {class  => 'SL::DB::Part'},
123
  profile => [{class  => 'SL::DB::Part'}],
124 124
);
125 125
is $csv->parse, undef, 'broken csv content won\'t get parsed';
126 126
is_deeply $csv->errors, [ '"Kaf"fee";;0.12;1,221.52'."\n", 2023, 'EIQ - QUO character not allowed', 5, 2 ], 'error';
......
136 136
EOL
137 137
  numberformat => '1,000.00',
138 138
  ignore_unknown_columns => 1,
139
  profile => {class  => 'SL::DB::Part'},
139
  profile => [{class  => 'SL::DB::Part'}],
140 140
);
141 141
$csv->parse;
142 142
is $csv->get_objects->[0]->lastcost, '1221.52', 'ignore_unkown_columns works';
......
150 150
Beer;1123245;0.12;1.5234;16 %
151 151
EOL
152 152
  numberformat => '1,000.00',
153
  profile => {
153
  profile => [{
154 154
    profile => {buchungsgruppe => "buchungsgruppen.description"},
155 155
    class  => 'SL::DB::Part',
156
  }
156
  }]
157 157
);
158 158
$csv->parse;
159 159
isa_ok $csv->get_objects->[0]->buchungsgruppe, 'SL::DB::Buchungsgruppe', 'deep dispatch auto vivify works';
......
169 169
Beer;1123245;0.12;1.5234;
170 170
EOL
171 171
  numberformat => '1,000.00',
172
  profile => {
172
  profile => [{
173 173
    profile => {
174 174
      make_1 => "makemodels.0.make",
175 175
      model_1 => "makemodels.0.model",
176 176
    },
177 177
    class  => 'SL::DB::Part',
178
  },
178
  }],
179 179
);
180 180
$csv->parse;
181 181
my @mm = $csv->get_objects->[0]->makemodel;
......
191 191
 Kaffee;;0.12;1,221.52;213;Chair 0815;523;Table 15
192 192
EOL
193 193
  numberformat => '1,000.00',
194
  profile => {
194
  profile => [{
195 195
    profile => {
196 196
      make_1 => "makemodels.0.make",
197 197
      model_1 => "makemodels.0.model",
......
199 199
      model_2 => "makemodels.1.model",
200 200
    },
201 201
    class  => 'SL::DB::Part',
202
  }
202
  }]
203 203
);
204 204
$csv->parse;
205 205

  
......
219 219
description;partnumber;sellprice;lastcost_as_number;buchungsgruppe;
220 220
EOL
221 221
  numberformat => '1,000.00',
222
  profile => {
222
  profile => [{
223 223
    profile => {buchungsgruppe => "buchungsgruppen.1.description"},
224 224
    class  => 'SL::DB::Part',
225
  }
225
  }]
226 226
);
227 227
is $csv->parse, undef, 'wrong profile gets rejected';
228 228
is_deeply $csv->errors, [ 'buchungsgruppen.1.description', undef, "Profile path error. Indexed relationship is not OneToMany around here: 'buchungsgruppen.1'", undef ,0 ], 'error indicates wrong header';
......
239 239
  numberformat => '1,000.00',
240 240
  ignore_unknown_columns => 1,
241 241
  strict_profile => 1,
242
  profile => {
242
  profile => [{
243 243
    profile => {lastcost => 'lastcost_as_number'},
244 244
    class  => 'SL::DB::Part',
245
  }
245
  }]
246 246
);
247 247
$csv->parse;
248 248
is $csv->get_objects->[0]->lastcost, '1221.52', 'strict_profile with ignore';
......
258 258
EOL
259 259
  numberformat => '1,000.00',
260 260
  strict_profile => 1,
261
  profile => {
261
  profile => [{
262 262
    profile => {lastcost => 'lastcost_as_number'},
263 263
    class  => 'SL::DB::Part',
264
  }
264
  }]
265 265
);
266 266
$csv->parse;
267 267

  
......
271 271

  
272 272
$csv = SL::Helper::Csv->new(
273 273
  file   => \"Kaffee",
274
  header => [ 'description' ],
275
  profile => {class  => 'SL::DB::Part'},
274
  header =>  [[ 'description' ]],
275
  profile => [{class  => 'SL::DB::Part'}],
276 276
);
277 277
$csv->parse;
278 278
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'eol bug at the end of files';
......
302 302

  
303 303
$csv = SL::Helper::Csv->new(
304 304
  file   => \"\x{EF}\x{BB}\x{BF}description\nKaffee",
305
  profile => {class  => 'SL::DB::Part'},
305
  profile => [{class  => 'SL::DB::Part'}],
306 306
  encoding => 'utf8',
307 307
);
308 308
$csv->parse;
......
313 313
$csv = SL::Helper::Csv->new(
314 314
  file   => \"Kaffee",
315 315
  header => [ 'Description' ],
316
  class  => 'SL::DB::Part',
316
  profile => [{class  => 'SL::DB::Part'}],
317 317
);
318 318
$csv->parse;
319 319
is_deeply $csv->get_data, undef, 'case insensitive header without flag ignores';
......
365 365
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'without profile and class works';
366 366

  
367 367
# vim: ft=perl
368
# set emacs to perl mode
369
# Local Variables:
370
# mode: perl
371
# End:

Auch abrufbar als: Unified diff