From 439bfedfb1d250bb99ef8daa1376573f7656685a Mon Sep 17 00:00:00 2001 From: Casey Conlin <101153261+CaseyConlin@users.noreply.github.com> Date: Sun, 13 Jul 2025 09:09:00 -0400 Subject: [PATCH 12/16] Add unit tests for reports_branches updates. --- t/db_dependent/Koha/Reports.t | 38 ++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Reports.t b/t/db_dependent/Koha/Reports.t index 205b1df60a..9778357d87 100755 --- a/t/db_dependent/Koha/Reports.t +++ b/t/db_dependent/Koha/Reports.t @@ -18,7 +18,7 @@ use Modern::Perl; use Test::NoWarnings; -use Test::More tests => 9; +use Test::More tests => 10; use Koha::Report; use Koha::Reports; @@ -185,4 +185,40 @@ subtest '_might_add_limit' => sub { ); }; +subtest 'reports_branches are added and removed from report_branches table' => sub { + plan tests => 4; + + my $updated_nb_of_reports = Koha::Reports->search->count; + my $report = Koha::Report->new( + { + report_name => 'report_name_for_test_1', + savedsql => 'SELECT * FROM items WHERE itemnumber IN <>', + } + )->store; + + my $id = $report->id; + my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); + my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); + my $library3 = $builder->build_object( { class => 'Koha::Libraries' } ); + my @branches = ( $library1->branchcode, $library2->branchcode, $library3->branchcode ); + + $report->replace_library_limits( \@branches ); + + my @branches_loop = $report->get_library_limits->as_list; + is( scalar @branches_loop, 3, '3 branches added to report_branches table' ); + + $report->replace_library_limits( [ $library1->branchcode, $library2->branchcode ] ); + + @branches_loop = $report->get_library_limits->as_list; + is( scalar @branches_loop, 2, '1 branch removed from report_branches table' ); + + $report->delete; + is( Koha::Reports->search->count, $updated_nb_of_reports, 'Report deleted, count is back to original' ); + is( + $schema->resultset('ReportsBranch')->search( { report_id => $id } )->count, + 0, + 'No branches left in reports_branches table after report deletion' + ); +}; + $schema->storage->txn_rollback; -- 2.39.5