Skip to content

Commit

Permalink
ACQUI-158: Object class unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mblenk committed Aug 27, 2024
1 parent 52e9e6f commit aeca959
Show file tree
Hide file tree
Showing 8 changed files with 737 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Koha/Plugin/Acquire/lib/Koha/Acquire/Funds/FiscalPeriod.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ sub store {

$self->SUPER::store;

$self->cascade_to_ledgers;
$self->cascade_to_ledgers unless $args->{no_cascade};

return $self;
}
Expand Down
9 changes: 5 additions & 4 deletions Koha/Plugin/Acquire/lib/Koha/Acquire/Funds/Fund.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ sub store {

$self->SUPER::store;

$self->cascade_to_fund_allocations;
$self->cascade_to_sub_funds;
unless ($args->{no_cascade}) {
$self->cascade_to_fund_allocations;
$self->cascade_to_sub_funds;
}

return $self;
}
Expand Down Expand Up @@ -80,7 +82,6 @@ sub cascade_to_fund_allocations {

my @fund_allocations = $self->koha_plugin_acquire_fund_allocations->as_list;
my $visible_to = $self->visible_to;
my $status = $self->status;

foreach my $fund_allocation (@fund_allocations) {
my $visibility_updated = Koha::Acquire::Funds::Utils->cascade_lib_group_visibility(
Expand Down Expand Up @@ -164,7 +165,7 @@ sub update_fund_total {
foreach my $allocation (@allocations) {
$total += $allocation->allocation_amount;
}
$self->fund_value($total)->store;
$self->fund_value($total)->store({ no_cascade => 1 });

my $ledger = $self->ledger;
$ledger->update_ledger_total;
Expand Down
4 changes: 2 additions & 2 deletions Koha/Plugin/Acquire/lib/Koha/Acquire/Funds/Ledger.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ sub store {

$self->SUPER::store;

$self->cascade_to_funds;
$self->cascade_to_funds unless $args->{no_cascade};

return $self;
}
Expand Down Expand Up @@ -102,7 +102,7 @@ sub update_ledger_total {
foreach my $fund (@funds) {
$total += $fund->fund_value;
}
$self->ledger_value($total)->store;
$self->ledger_value($total)->store({ no_cascade => 1 });
return $total;
}

Expand Down
4 changes: 2 additions & 2 deletions Koha/Plugin/Acquire/lib/Koha/Acquire/Funds/SubFund.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ sub store {

$self->SUPER::store;

$self->cascade_to_fund_allocations;
$self->cascade_to_fund_allocations unless $args->{no_cascade};

return $self;
}
Expand Down Expand Up @@ -102,7 +102,7 @@ sub update_sub_fund_total {
foreach my $allocation (@allocations) {
$total += $allocation->allocation_amount;
}
$self->sub_fund_value($total)->store;
$self->sub_fund_value($total)->store({ no_cascade => 1 });

my $fund = $self->fund;
$fund->update_fund_total;
Expand Down
75 changes: 75 additions & 0 deletions tests/t/Koha/FundManagement/FiscalPeriod.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/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 <http://www.gnu.org/licenses>.

use Modern::Perl;

use Test::More tests => 1;

use t::lib::TestBuilder;
use t::lib::Mocks;

use Koha::Database;
use Koha::Acquire::Funds::FiscalPeriods;

my $schema = Koha::Database->new->schema;
my $builder = t::lib::TestBuilder->new;

subtest 'cascade_to_ledgers' => sub {

plan tests => 4;

$schema->storage->txn_begin;

my $fiscal_period = $builder->build_object(
{ class => 'Koha::Acquire::Funds::FiscalPeriods', value => { status => 1, visible_to => '1|2' } } );
my $ledger_1 = $builder->build_object(
{
class => 'Koha::Acquire::Funds::Ledgers',
value => {
fiscal_period_id => $fiscal_period->fiscal_period_id,
visible_to => $fiscal_period->visible_to,
status => $fiscal_period->status
}
}
);

my $ledger_2 = $builder->build_object(
{
class => 'Koha::Acquire::Funds::Ledgers',
value => {
fiscal_period_id => $fiscal_period->fiscal_period_id,
visible_to => $fiscal_period->visible_to,
status => $fiscal_period->status
}
}
);

$fiscal_period->status(0);
$fiscal_period->visible_to('1');
$fiscal_period->store();

my $updated_ledger_1 = Koha::Acquire::Funds::Ledgers->find( $ledger_1->ledger_id );
my $updated_ledger_2 = Koha::Acquire::Funds::Ledgers->find( $ledger_2->ledger_id );

is( $fiscal_period->status, $updated_ledger_1->status, 'Ledger one has updated' );
is( $fiscal_period->status, $updated_ledger_2->status, 'Ledger two has updated' );
is( $fiscal_period->visible_to, $updated_ledger_1->visible_to, 'Ledger one has updated' );
is( $fiscal_period->visible_to, $updated_ledger_2->visible_to, 'Ledger two has updated' );

$schema->storage->txn_rollback;

};
Loading

0 comments on commit aeca959

Please sign in to comment.