From 704d136c81a3334b9546072de033aad53c45162f Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 29 Jul 2024 09:16:11 -0300 Subject: [PATCH] Bug 37510: Unit tests Signed-off-by: David Nind Signed-off-by: Pedro Amorim --- t/db_dependent/Koha/Object.t | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t index b1c6bb5172..abf2129530 100755 --- a/t/db_dependent/Koha/Object.t +++ b/t/db_dependent/Koha/Object.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 22; +use Test::More tests => 23; use Test::Exception; use Test::Warn; @@ -1237,3 +1237,30 @@ subtest 'is_accessible() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'delete() tests' => sub { + + plan tests => 6; + + $schema->storage->txn_begin; + + my $rs = $builder->build_object( { class => 'Koha::RecordSources' } ); + my $biblio = $builder->build_sample_biblio(); + + $biblio->metadata->set( { record_source_id => $rs->id } )->store(); + + throws_ok { $rs->delete(); } + 'Koha::Exceptions::Object::FKConstraintDeletion'; + + is( $@->column, 'record_source_id' ); + is( $@->constraint, 'record_metadata_fk_2' ); + is( $@->fk, 'record_source_id' ); + is( $@->table, 'biblio_metadata' ); + + $biblio->metadata->set( { record_source_id => undef } )->store(); + + lives_ok { $rs->delete(); } + 'No exception thrown'; + + $schema->storage->txn_rollback; +}; -- 2.39.2