From 7edc1c10a8895f9da446e2f5d7a873cb0f179990 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 Signed-off-by: Katrin Fischer (cherry picked from commit 30a5baa70623625d2856450293b00ce34a764cd8) Signed-off-by: Lucas Gass --- 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 28ac6e5e94..4794fb1b70 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.5