From 4051b110f61f32dfc7da32c2883ab1a67fa7fbc1 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Thu, 24 Apr 2025 15:14:22 +0100 Subject: [PATCH] Bug 39711: Add unit tests --- t/db_dependent/Koha/Acquisition/Booksellers.t | 16 ++--- t/db_dependent/Koha/Acquisition/Contracts.t | 63 +++++++++++++++++++ 2 files changed, 72 insertions(+), 7 deletions(-) create mode 100755 t/db_dependent/Koha/Acquisition/Contracts.t diff --git a/t/db_dependent/Koha/Acquisition/Booksellers.t b/t/db_dependent/Koha/Acquisition/Booksellers.t index 14512113598..2ce1fa5597b 100755 --- a/t/db_dependent/Koha/Acquisition/Booksellers.t +++ b/t/db_dependent/Koha/Acquisition/Booksellers.t @@ -23,7 +23,6 @@ use t::lib::TestBuilder; use C4::Acquisition qw( NewBasket ); use C4::Biblio qw( AddBiblio ); -use C4::Contract qw( AddContract ); use C4::Budgets qw( AddBudgetPeriod AddBudget ); use C4::Serials qw( NewSubscription SearchSubscriptions ); @@ -270,18 +269,21 @@ subtest 'contracts' => sub { my $vendor = $builder->build_object( { class => 'Koha::Acquisition::Booksellers' } ); - is( scalar( @{ $vendor->contracts } ), 0, 'Vendor has no contracts' ); + is( scalar( @{ $vendor->contracts->as_list } ), 0, 'Vendor has no contracts' ); - AddContract( + my $contract = $builder->build_object( { - booksellerid => $vendor->id, - contractname => 'Test contract', + class => 'Koha::Acquisition::Contracts', + value => { + booksellerid => $vendor->id, + contractname => 'Test contract', + } } ); $vendor = $vendor->get_from_storage; - my $contracts = $vendor->contracts; - is( scalar( @{$contracts} ), 1, '1 contract stored' ); + my @contracts = $vendor->contracts->as_list; + is( scalar(@contracts), 1, '1 contract stored' ); $schema->storage->txn_rollback(); }; diff --git a/t/db_dependent/Koha/Acquisition/Contracts.t b/t/db_dependent/Koha/Acquisition/Contracts.t new file mode 100755 index 00000000000..81b0f67f2f7 --- /dev/null +++ b/t/db_dependent/Koha/Acquisition/Contracts.t @@ -0,0 +1,63 @@ +#!/usr/bin/perl +# +# This file is part of Koha +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Test::More tests => 3; +use Test::Exception; + +use t::lib::TestBuilder; +use t::lib::Mocks; + +use Koha::Database; + +use_ok('Koha::Acquisition::Contract'); +use_ok('Koha::Acquisition::Contracts'); + +my $schema = Koha::Database->schema; +my $builder = t::lib::TestBuilder->new; + +subtest 'store' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + my $starting_contract_count = Koha::Acquisition::Contracts->count; + + my $new_contract = Koha::Acquisition::Contract->new( + { + contractname => 'Test contract', + booksellerid => 1, + } + )->store; + my $contract_count_1 = Koha::Acquisition::Contracts->count; + + is( $contract_count_1, $starting_contract_count + 1, '1 contract stored' ); + + throws_ok { + my $contract_with_missing_vendor = Koha::Acquisition::Contract->new( + { + contractname => 'Test contract', + } + )->store; + } + 'Koha::Exceptions::MissingParameter', + + $schema->storage->txn_rollback; +}; + -- 2.48.1