Lines 487-524
subtest 'to_api() tests' => sub {
Link Here
|
487 |
}; |
487 |
}; |
488 |
|
488 |
|
489 |
subtest 'merge of records' => sub { |
489 |
subtest 'merge of records' => sub { |
490 |
plan tests => 3; |
490 |
plan tests => 9; |
491 |
$schema->storage->txn_begin; |
491 |
$schema->storage->txn_begin; |
492 |
|
492 |
|
493 |
#Three biblio |
493 |
# 3 items from 3 different biblio records |
494 |
my $biblio1 = $builder->build_sample_biblio( { title => 'Title number 1' } ); |
494 |
my $item1 = $builder->build_sample_item; |
495 |
my $biblio2 = $builder->build_sample_biblio( { title => 'Title number 2' } ); |
495 |
my $item2 = $builder->build_sample_item; |
496 |
my $biblio3 = $builder->build_sample_biblio( { title => 'Title number 3' } ); |
496 |
my $item3 = $builder->build_sample_item; |
497 |
|
497 |
|
498 |
# One items each |
498 |
my $biblio1 = $item1->biblio; |
499 |
my $item1_1 = $builder->build_sample_item( { biblionumber => $biblio1->biblionumber, barcode => 'bar11' } ); |
499 |
my $biblio2 = $item2->biblio; |
500 |
my $item2_1 = $builder->build_sample_item( { biblionumber => $biblio2->biblionumber, barcode => 'bar22' } ); |
500 |
my $biblio3 = $item3->biblio; |
501 |
my $item3_1 = $builder->build_sample_item( { biblionumber => $biblio3->biblionumber, barcode => 'bar33' } ); |
|
|
502 |
my $results = ''; |
503 |
my @to_merge = ( $biblio2->biblionumber, $biblio3->biblionumber ); |
504 |
|
501 |
|
505 |
my $pre_merged_rs = Koha::Biblios->search( |
502 |
my $pre_merged_rs = Koha::Biblios->search( |
506 |
{ biblionumber => [ $biblio1->biblionumber, $biblio2->biblionumber, $biblio3->biblionumber ] } ); |
503 |
{ biblionumber => [ $biblio1->biblionumber, $biblio2->biblionumber, $biblio3->biblionumber ] } ); |
507 |
is( $pre_merged_rs->count, 3, '3 biblios exist' ); |
504 |
is( $pre_merged_rs->count, 3, '3 biblios exist' ); |
508 |
|
505 |
|
509 |
eval { $results = $biblio1->merge_with( \@to_merge ); }; |
506 |
warning_like { $biblio1->merge_with( [ $biblio2->biblionumber, $biblio3->biblionumber ] ) } q{}; |
510 |
if ($@) { |
507 |
is( $biblio1->items->count, 3, "After merge we have 3 items on first record" ); |
511 |
is( 0, 1, "Not working. Error: " . $@ ); |
|
|
512 |
} else { |
513 |
my $items = $biblio1->items; |
514 |
is( $items->count, 3, "After merge we have 3 items on first record" ); |
515 |
|
508 |
|
516 |
my $merged_rs = Koha::Biblios->search( |
509 |
is( ref( $biblio1->get_from_storage ), 'Koha::Biblio', 'biblio record 1 still exists' ); |
517 |
{ biblionumber => [ $biblio1->biblionumber, $biblio2->biblionumber, $biblio3->biblionumber ] } ); |
510 |
is( $biblio2->get_from_storage, undef, 'biblio record 2 no longer exists' ); |
518 |
is( $merged_rs->count, 1, 'only 1 biblio left, the merged ones are gone' ); |
511 |
is( $biblio3->get_from_storage, undef, 'biblio record 3 no longer exists' ); |
519 |
} |
512 |
|
|
|
513 |
is( $item1->get_from_storage->biblionumber, $biblio1->biblionumber ); |
514 |
is( $item2->get_from_storage->biblionumber, $biblio1->biblionumber ); |
515 |
is( $item3->get_from_storage->biblionumber, $biblio1->biblionumber ); |
520 |
|
516 |
|
521 |
#End work |
|
|
522 |
$schema->storage->txn_rollback; |
517 |
$schema->storage->txn_rollback; |
523 |
}; |
518 |
}; |
524 |
|
519 |
|
525 |
- |
|
|