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

(-)a/t/db_dependent/Koha/Patron.t (-2 / +50 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 10;
22
use Test::More tests => 11;
23
use Test::Exception;
23
use Test::Exception;
24
use Test::Warn;
24
use Test::Warn;
25
25
Lines 846-848 subtest 'article_requests() tests' => sub { Link Here
846
846
847
    $schema->storage->txn_rollback;
847
    $schema->storage->txn_rollback;
848
};
848
};
849
- 
849
850
subtest 'safe_to_delete() tests' => sub {
851
852
    plan tests => 5;
853
854
    $schema->storage->txn_begin;
855
856
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
857
858
    ## Make it the anonymous
859
    t::lib::Mocks::mock_preference( 'AnonymousPatron', $patron->id );
860
861
    is( $patron->safe_to_delete, 'is_anonymous_patron', 'Cannot delete, it is the anonymous patron' );
862
    # cleanup
863
    t::lib::Mocks::mock_preference( 'AnonymousPatron', 0 );
864
865
    ## Make it have a checkout
866
    my $checkout = $builder->build_object(
867
        {
868
            class => 'Koha::Checkouts',
869
            value => { borrowernumber => $patron->id }
870
        }
871
    );
872
873
    is( $patron->safe_to_delete, 'has_checkouts', 'Cannot delete, has checkouts' );
874
    # cleanup
875
    $checkout->delete;
876
877
    ## Make it have a guarantee
878
    t::lib::Mocks::mock_preference( 'borrowerRelationship', 'parent' );
879
    $builder->build_object({ class => 'Koha::Patrons' })
880
            ->add_guarantor({ guarantor_id => $patron->id, relationship => 'parent' });
881
882
    is( $patron->safe_to_delete, 'has_guarantees', 'Cannot delete, has guarantees' );
883
    # cleanup
884
    $patron->guarantee_relationships->delete;
885
886
    ## Make it have debt
887
    my $debit = $patron->account->add_debit({ amount => 10, interface => 'intranet', type => 'MANUAL' });
888
889
    is( $patron->safe_to_delete, 'has_debt', 'Cannot delete, has debt' );
890
    # cleanup
891
    $patron->account->pay({ amount => 10, debits => [ $debit ] });
892
893
    ## Happy case :-D
894
    is( $patron->safe_to_delete, 'ok', 'Can delete, all conditions met' );
895
896
    $schema->storage->txn_rollback;
897
};

Return to bug 29741