Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision c8473408

Von Bernd Blessmann vor fast 11 Jahren hinzugefügt

  • ID c8473408202bb3b821a14cee9f8945405d8eeffc
  • Vorgänger f33995ff
  • Nachfolger af205393

SL::Helper::Csv bekommt Klasse im Profil mitgeteilt.

Unterschiede anzeigen:

t/helper/csv.t
11 11
Support::TestSetup::login();
12 12

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

  
19 19
isa_ok $csv->_csv, 'Text::CSV_XS';
......
28 28
$::myconfig{dateformat} = 'dd.mm.yyyy';
29 29

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

  
......
49 49
EOL
50 50
  sep_char => ',',
51 51
  quote_char => "'",
52
  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
  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
  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
  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
  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
  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
  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
  class  => 'SL::DB::Part',
154 153
  profile => {
155
    buchungsgruppe => "buchungsgruppen.description",
154
    profile => {buchungsgruppe => "buchungsgruppen.description"},
155
    class  => 'SL::DB::Part',
156 156
  }
157 157
);
158 158
$csv->parse;
......
169 169
Beer;1123245;0.12;1.5234;
170 170
EOL
171 171
  numberformat => '1,000.00',
172
  class  => 'SL::DB::Part',
173 172
  profile => {
174
    make_1 => "makemodels.0.make",
175
    model_1 => "makemodels.0.model",
176
  }
173
    profile => {
174
      make_1 => "makemodels.0.make",
175
      model_1 => "makemodels.0.model",
176
    },
177
    class  => 'SL::DB::Part',
178
  },
177 179
);
178 180
$csv->parse;
179 181
my @mm = $csv->get_objects->[0]->makemodel;
......
189 191
 Kaffee;;0.12;1,221.52;213;Chair 0815;523;Table 15
190 192
EOL
191 193
  numberformat => '1,000.00',
192
  class  => 'SL::DB::Part',
193 194
  profile => {
194
    make_1 => "makemodels.0.make",
195
    model_1 => "makemodels.0.model",
196
    make_2 => "makemodels.1.make",
197
    model_2 => "makemodels.1.model",
195
    profile => {
196
      make_1 => "makemodels.0.make",
197
      model_1 => "makemodels.0.model",
198
      make_2 => "makemodels.1.make",
199
      model_2 => "makemodels.1.model",
200
    },
201
    class  => 'SL::DB::Part',
198 202
  }
199 203
);
200 204
$csv->parse;
......
215 219
description;partnumber;sellprice;lastcost_as_number;buchungsgruppe;
216 220
EOL
217 221
  numberformat => '1,000.00',
218
  class  => 'SL::DB::Part',
219 222
  profile => {
220
    buchungsgruppe => "buchungsgruppen.1.description",
223
    profile => {buchungsgruppe => "buchungsgruppen.1.description"},
224
    class  => 'SL::DB::Part',
221 225
  }
222 226
);
223 227
is $csv->parse, undef, 'wrong profile gets rejected';
......
235 239
  numberformat => '1,000.00',
236 240
  ignore_unknown_columns => 1,
237 241
  strict_profile => 1,
238
  class  => 'SL::DB::Part',
239 242
  profile => {
240
    lastcost => 'lastcost_as_number',
243
    profile => {lastcost => 'lastcost_as_number'},
244
    class  => 'SL::DB::Part',
241 245
  }
242 246
);
243 247
$csv->parse;
......
254 258
EOL
255 259
  numberformat => '1,000.00',
256 260
  strict_profile => 1,
257
  class  => 'SL::DB::Part',
258 261
  profile => {
259
    lastcost => 'lastcost_as_number',
262
    profile => {lastcost => 'lastcost_as_number'},
263
    class  => 'SL::DB::Part',
260 264
  }
261 265
);
262 266
$csv->parse;
......
268 272
$csv = SL::Helper::Csv->new(
269 273
  file   => \"Kaffee",
270 274
  header => [ 'description' ],
271
  class  => 'SL::DB::Part',
275
  profile => {class  => 'SL::DB::Part'},
272 276
);
273 277
$csv->parse;
274 278
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'eol bug at the end of files';
......
277 281

  
278 282
$csv = SL::Helper::Csv->new(
279 283
  file   => \"Description\nKaffee",
280
  class  => 'SL::DB::Part',
281 284
  case_insensitive_header => 1,
282
  profile => { description => 'description' },
285
  profile => {profile => { description => 'description' }, class  => 'SL::DB::Part'},
283 286
);
284 287
$csv->parse;
285 288
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'case insensitive header from csv works';
......
289 292
$csv = SL::Helper::Csv->new(
290 293
  file   => \"Kaffee",
291 294
  header => [ 'Description' ],
292
  class  => 'SL::DB::Part',
293 295
  case_insensitive_header => 1,
294
  profile => { description => 'description' },
296
  profile => {profile => { description => 'description' }, class  => 'SL::DB::Part'},
295 297
);
296 298
$csv->parse;
297 299
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'case insensitive header as param works';
......
300 302

  
301 303
$csv = SL::Helper::Csv->new(
302 304
  file   => \"\x{EF}\x{BB}\x{BF}description\nKaffee",
303
  class  => 'SL::DB::Part',
305
  profile => {class  => 'SL::DB::Part'},
304 306
  encoding => 'utf8',
305 307
);
306 308
$csv->parse;
......
356 358
is_deeply $csv->get_data, [ { cvar_Groundhog => 'Phil' } ], 'using empty path to get cvars working';
357 359
ok $csv->get_objects->[0], '...and not destorying the objects';
358 360

  
361
$csv = SL::Helper::Csv->new(
362
  file   => \"description\nKaffee",
363
);
364
$csv->parse;
365
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'without profile and class works';
366

  
359 367
# vim: ft=perl

Auch abrufbar als: Unified diff