Revision f5df17ca
Von Sven Schöling vor mehr als 7 Jahren hinzugefügt
t/db_helper/record_links.t | ||
---|---|---|
1 |
use Test::More tests => 49;
|
|
1 |
use Test::More tests => 66;
|
|
2 | 2 |
|
3 | 3 |
use strict; |
4 | 4 |
|
... | ... | |
9 | 9 |
use Data::Dumper; |
10 | 10 |
use Support::TestSetup; |
11 | 11 |
use Test::Exception; |
12 |
use Test::Deep qw(cmp_bag); |
|
12 | 13 |
use List::Util qw(max); |
13 | 14 |
|
14 | 15 |
use SL::DB::Buchungsgruppe; |
... | ... | |
318 | 319 |
$links = $o1->linked_records(direction => 'both', recursive => 1, save_path => 1); |
319 | 320 |
is @$links, 4, 'recursive dir=both does not give duplicates'; |
320 | 321 |
|
321 |
clear_up(); |
|
322 |
|
|
323 |
# test batch mode |
|
324 |
# |
|
325 |
# |
|
326 |
# |
|
327 |
|
|
328 |
reset_state(); |
|
329 |
|
|
330 |
$o1 = new_order(); |
|
331 |
$o2 = new_order(); |
|
332 |
my $i1 = new_invoice(); |
|
333 |
my $i2 = new_invoice(); |
|
334 |
|
|
335 |
$o1->link_to_record($i1); |
|
336 |
$o2->link_to_record($i2); |
|
337 |
|
|
338 |
$links = $o1->linked_records(direction => 'to', to => 'Invoice', batch => [ $o1->id, $o2->id ]); |
|
339 |
is_deeply [ map { $_->id } @$links ], [ $i1->id , $i2->id ], "batch works"; |
|
340 |
|
|
341 |
$links = $o1->linked_records(direction => 'to', recursive => 1, batch => [ $o1->id, $o2->id ]); |
|
342 |
cmp_bag [ map { $_->id } @$links ], [ $i1->id , $i2->id ], "batch works recursive"; |
|
343 |
|
|
344 |
$links = $o1->linked_records(direction => 'to', to => 'Invoice', batch => [ $o1->id, $o2->id ], by_id => 1); |
|
345 |
# $::lxdebug->dump(0, "links", $links); |
|
346 |
is @{ $links->{$o1->id} }, 1, "batch by_id 1"; |
|
347 |
is @{ $links->{$o2->id} }, 1, "batch by_id 2"; |
|
348 |
is keys %$links, 2, "batch by_id 3"; |
|
349 |
is $links->{$o1->id}[0]->id, $i1->id, "batch by_id 4"; |
|
350 |
is $links->{$o2->id}[0]->id, $i2->id, "batch by_id 5"; |
|
351 |
|
|
352 |
$links = $o1->linked_records(direction => 'to', recursive => 1, batch => [ $o1->id, $o2->id ], by_id => 1); |
|
353 |
is @{ $links->{$o1->id} }, 1, "batch recursive by_id 1"; |
|
354 |
is @{ $links->{$o2->id} }, 1, "batch recursive by_id 2"; |
|
355 |
is keys %$links, 2, "batch recursive by_id 3"; |
|
356 |
is $links->{$o1->id}[0]->id, $i1->id, "batch recursive by_id 4"; |
|
357 |
is $links->{$o2->id}[0]->id, $i2->id, "batch recursive by_id 5"; |
|
358 |
|
|
359 |
$links = $o1->linked_records(direction => 'both', recursive => 1, batch => [ $o1->id, $o2->id ], by_id => 1); |
|
360 |
is @{ $links->{$o1->id} }, 1, "batch recursive by_id direction both 1"; |
|
361 |
is @{ $links->{$o2->id} }, 1, "batch recursive by_id direction both 2"; |
|
362 |
is keys %$links, 2, "batch recursive by_id direction both 3"; |
|
363 |
is $links->{$o1->id}[0]->id, $i1->id, "batch recursive by_id direction both 4"; |
|
364 |
is $links->{$o2->id}[0]->id, $i2->id, "batch recursive by_id direction both 5"; |
|
322 | 365 |
|
323 | 366 |
1; |
Auch abrufbar als: Unified diff
LinkedRecord: Batch mode