View | Details | Raw Unified | Return to bug 33036
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Biblio.t (-22 / +167 lines)
Lines 23-28 use Test::Warn; Link Here
23
23
24
use C4::Biblio qw( AddBiblio ModBiblio ModBiblioMarc );
24
use C4::Biblio qw( AddBiblio ModBiblio ModBiblioMarc );
25
use C4::Circulation qw( AddIssue AddReturn );
25
use C4::Circulation qw( AddIssue AddReturn );
26
use C4::Reserves qw( AddReserve );
26
27
27
use Koha::Database;
28
use Koha::Database;
28
use Koha::Cache::Memory::Lite;
29
use Koha::Cache::Memory::Lite;
Lines 487-520 subtest 'to_api() tests' => sub { Link Here
487
};
488
};
488
489
489
subtest 'merge of records' => sub {
490
subtest 'merge of records' => sub {
490
    plan tests => 9;
491
    plan tests => 8;
491
    $schema->storage->txn_begin;
492
492
493
    # 3 items from 3 different biblio records
493
    subtest 'move items' => sub {
494
    my $item1    = $builder->build_sample_item;
494
        plan tests => 9;
495
    my $item2    = $builder->build_sample_item;
495
        $schema->storage->txn_begin;
496
    my $item3    = $builder->build_sample_item;
497
496
498
    my $biblio1 = $item1->biblio;
497
        # 3 items from 3 different biblio records
499
    my $biblio2 = $item2->biblio;
498
        my $item1 = $builder->build_sample_item;
500
    my $biblio3 = $item3->biblio;
499
        my $item2 = $builder->build_sample_item;
500
        my $item3 = $builder->build_sample_item;
501
501
502
    my $pre_merged_rs = Koha::Biblios->search(
502
        my $biblio1 = $item1->biblio;
503
        { biblionumber => [ $biblio1->biblionumber, $biblio2->biblionumber, $biblio3->biblionumber ] } );
503
        my $biblio2 = $item2->biblio;
504
    is( $pre_merged_rs->count, 3, '3 biblios exist' );
504
        my $biblio3 = $item3->biblio;
505
505
506
    warning_like { $biblio1->merge_with( [ $biblio2->biblionumber, $biblio3->biblionumber ] ) } q{};
506
        my $pre_merged_rs = Koha::Biblios->search(
507
    is( $biblio1->items->count, 3, "After merge we have 3 items on first record" );
507
            { biblionumber => [ $biblio1->biblionumber, $biblio2->biblionumber, $biblio3->biblionumber ] } );
508
        is( $pre_merged_rs->count, 3, '3 biblios exist' );
508
509
509
    is( ref( $biblio1->get_from_storage ), 'Koha::Biblio', 'biblio record 1 still exists' );
510
        warning_like { $biblio1->merge_with( [ $biblio2->biblionumber, $biblio3->biblionumber ] ) } q{};
510
    is( $biblio2->get_from_storage,        undef,          'biblio record 2 no longer exists' );
511
        is( $biblio1->items->count, 3, "After merge we have 3 items on first record" );
511
    is( $biblio3->get_from_storage,        undef,          'biblio record 3 no longer exists' );
512
512
513
    is( $item1->get_from_storage->biblionumber, $biblio1->biblionumber );
513
        is( ref( $biblio1->get_from_storage ), 'Koha::Biblio', 'biblio record 1 still exists' );
514
    is( $item2->get_from_storage->biblionumber, $biblio1->biblionumber );
514
        is( $biblio2->get_from_storage,        undef,          'biblio record 2 no longer exists' );
515
    is( $item3->get_from_storage->biblionumber, $biblio1->biblionumber );
515
        is( $biblio3->get_from_storage,        undef,          'biblio record 3 no longer exists' );
516
517
        is( $item1->get_from_storage->biblionumber, $biblio1->biblionumber );
518
        is( $item2->get_from_storage->biblionumber, $biblio1->biblionumber );
519
        is( $item3->get_from_storage->biblionumber, $biblio1->biblionumber );
520
521
        $schema->storage->txn_rollback;
522
    };
523
524
    subtest 'move holds' => sub {
525
        plan tests => 3;
526
        $schema->storage->txn_begin;
527
528
        my $biblio1 = $builder->build_sample_biblio;
529
        my $biblio2 = $builder->build_sample_biblio;
530
531
        my $hold1 =
532
            $builder->build_object( { class => 'Koha::Holds', value => { biblionumber => $biblio1->biblionumber } } );
533
        my $hold2 =
534
            $builder->build_object( { class => 'Koha::Holds', value => { biblionumber => $biblio2->biblionumber } } );
535
536
        warning_like { $biblio1->merge_with( [ $biblio2->biblionumber ] ) } q{};
537
538
        is( $hold1->get_from_storage->biblionumber, $biblio1->biblionumber );
539
        is( $hold2->get_from_storage->biblionumber, $biblio1->biblionumber );
540
541
        $schema->storage->txn_rollback;
542
    };
543
544
    subtest 'move article requests' => sub {
545
        plan tests => 3;
546
        $schema->storage->txn_begin;
547
548
        my $biblio1 = $builder->build_sample_biblio;
549
        my $biblio2 = $builder->build_sample_biblio;
550
551
        my $ar1 = $builder->build_object(
552
            { class => 'Koha::ArticleRequests', value => { biblionumber => $biblio1->biblionumber } } );
553
        my $ar2 = $builder->build_object(
554
            { class => 'Koha::ArticleRequests', value => { biblionumber => $biblio2->biblionumber } } );
555
556
        warning_like { $biblio1->merge_with( [ $biblio2->biblionumber ] ) } q{};
557
558
        is( $ar1->get_from_storage->biblionumber, $biblio1->biblionumber );
559
        is( $ar2->get_from_storage->biblionumber, $biblio1->biblionumber );
560
561
        $schema->storage->txn_rollback;
562
    };
563
564
    subtest 'move subscriptions' => sub {
565
        plan tests => 3;
566
        $schema->storage->txn_begin;
567
568
        my $biblio1 = $builder->build_sample_biblio;
569
        my $biblio2 = $builder->build_sample_biblio;
570
571
        my $sub1 = $builder->build_object(
572
            { class => 'Koha::Subscriptions', value => { biblionumber => $biblio1->biblionumber } } );
573
        my $sub2 = $builder->build_object(
574
            { class => 'Koha::Subscriptions', value => { biblionumber => $biblio2->biblionumber } } );
575
576
        warning_like { $biblio1->merge_with( [ $biblio2->biblionumber ] ) } q{};
577
578
        is( $sub1->get_from_storage->biblionumber, $biblio1->biblionumber );
579
        is( $sub2->get_from_storage->biblionumber, $biblio1->biblionumber );
580
581
        $schema->storage->txn_rollback;
582
    };
583
584
    subtest 'move serials' => sub {
585
        plan tests => 3;
586
        $schema->storage->txn_begin;
587
588
        my $biblio1 = $builder->build_sample_biblio;
589
        my $biblio2 = $builder->build_sample_biblio;
590
591
        my $serial1 =
592
            $builder->build_object( { class => 'Koha::Serials', value => { biblionumber => $biblio1->biblionumber } } );
593
        my $serial2 =
594
            $builder->build_object( { class => 'Koha::Serials', value => { biblionumber => $biblio2->biblionumber } } );
595
596
        warning_like { $biblio1->merge_with( [ $biblio2->biblionumber ] ) } q{};
597
598
        is( $serial1->get_from_storage->biblionumber, $biblio1->biblionumber );
599
        is( $serial2->get_from_storage->biblionumber, $biblio1->biblionumber );
600
601
        $schema->storage->txn_rollback;
602
    };
603
604
    subtest 'move subscription history' => sub {
605
        plan tests => 3;
606
        $schema->storage->txn_begin;
607
608
        my $biblio1 = $builder->build_sample_biblio;
609
        my $biblio2 = $builder->build_sample_biblio;
610
611
        my $sh1 = $builder->build_object(
612
            { class => 'Koha::Subscription::Histories', value => { biblionumber => $biblio1->biblionumber } } );
613
        my $sh2 = $builder->build_object(
614
            { class => 'Koha::Subscription::Histories', value => { biblionumber => $biblio2->biblionumber } } );
615
616
        warning_like { $biblio1->merge_with( [ $biblio2->biblionumber ] ) } q{};
617
618
        is( $sh1->get_from_storage->biblionumber, $biblio1->biblionumber );
619
        is( $sh2->get_from_storage->biblionumber, $biblio1->biblionumber );
620
621
        $schema->storage->txn_rollback;
622
    };
623
624
    subtest 'move suggestions' => sub {
625
        plan tests => 3;
626
        $schema->storage->txn_begin;
627
628
        my $biblio1 = $builder->build_sample_biblio;
629
        my $biblio2 = $builder->build_sample_biblio;
630
631
        my $suggestion1 = $builder->build_object(
632
            { class => 'Koha::Suggestions', value => { biblionumber => $biblio1->biblionumber } } );
633
        my $suggestion2 = $builder->build_object(
634
            { class => 'Koha::Suggestions', value => { biblionumber => $biblio2->biblionumber } } );
635
636
        warning_like { $biblio1->merge_with( [ $biblio2->biblionumber ] ) } q{};
637
638
        is( $suggestion1->get_from_storage->biblionumber, $biblio1->biblionumber );
639
        is( $suggestion2->get_from_storage->biblionumber, $biblio1->biblionumber );
640
641
        $schema->storage->txn_rollback;
642
    };
643
644
    subtest 'move orders' => sub {
645
        plan tests => 3;
646
        $schema->storage->txn_begin;
647
648
        my $biblio1 = $builder->build_sample_biblio;
649
        my $biblio2 = $builder->build_sample_biblio;
650
651
        my $order1 = $builder->build_object(
652
            { class => 'Koha::Acquisition::Orders', value => { biblionumber => $biblio1->biblionumber } } );
653
        my $order2 = $builder->build_object(
654
            { class => 'Koha::Acquisition::Orders', value => { biblionumber => $biblio2->biblionumber } } );
655
656
        warning_like { $biblio1->merge_with( [ $biblio2->biblionumber ] ) } q{};
657
658
        is( $order1->get_from_storage->biblionumber, $biblio1->biblionumber );
659
        is( $order2->get_from_storage->biblionumber, $biblio1->biblionumber );
660
661
        $schema->storage->txn_rollback;
662
    };
516
663
517
    $schema->storage->txn_rollback;
518
};
664
};
519
665
520
subtest 'suggestions() tests' => sub {
666
subtest 'suggestions() tests' => sub {
521
- 

Return to bug 33036