Bug 29741: Unit tests
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
parent
b7b6a85de5
commit
b28f35efbf
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More tests => 10;
|
||||
use Test::More tests => 11;
|
||||
use Test::Exception;
|
||||
use Test::Warn;
|
||||
|
||||
|
|
@ -846,3 +846,52 @@ subtest 'article_requests() tests' => sub {
|
|||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest 'safe_to_delete() tests' => sub {
|
||||
|
||||
plan tests => 5;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
|
||||
|
||||
## Make it the anonymous
|
||||
t::lib::Mocks::mock_preference( 'AnonymousPatron', $patron->id );
|
||||
|
||||
is( $patron->safe_to_delete, 'is_anonymous_patron', 'Cannot delete, it is the anonymous patron' );
|
||||
# cleanup
|
||||
t::lib::Mocks::mock_preference( 'AnonymousPatron', 0 );
|
||||
|
||||
## Make it have a checkout
|
||||
my $checkout = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Checkouts',
|
||||
value => { borrowernumber => $patron->id }
|
||||
}
|
||||
);
|
||||
|
||||
is( $patron->safe_to_delete, 'has_checkouts', 'Cannot delete, has checkouts' );
|
||||
# cleanup
|
||||
$checkout->delete;
|
||||
|
||||
## Make it have a guarantee
|
||||
t::lib::Mocks::mock_preference( 'borrowerRelationship', 'parent' );
|
||||
$builder->build_object({ class => 'Koha::Patrons' })
|
||||
->add_guarantor({ guarantor_id => $patron->id, relationship => 'parent' });
|
||||
|
||||
is( $patron->safe_to_delete, 'has_guarantees', 'Cannot delete, has guarantees' );
|
||||
# cleanup
|
||||
$patron->guarantee_relationships->delete;
|
||||
|
||||
## Make it have debt
|
||||
my $debit = $patron->account->add_debit({ amount => 10, interface => 'intranet', type => 'MANUAL' });
|
||||
|
||||
is( $patron->safe_to_delete, 'has_debt', 'Cannot delete, has debt' );
|
||||
# cleanup
|
||||
$patron->account->pay({ amount => 10, debits => [ $debit ] });
|
||||
|
||||
## Happy case :-D
|
||||
is( $patron->safe_to_delete, 'ok', 'Can delete, all conditions met' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue