From aeb3a88224782944e46f9c56e99a5ff375cf77b5 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 26 Dec 2017 12:33:39 -0300 Subject: [PATCH] Bug 19826: Add tests Signed-off-by: Jonathan Druart --- Koha/Acquisition/Budgets.pm | 2 + Koha/Acquisition/Funds.pm | 2 + t/db_dependent/Koha/Acquisition/Budgets.t | 54 +++++++++++++++++++++++ t/db_dependent/Koha/Acquisition/Funds.t | 49 ++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 t/db_dependent/Koha/Acquisition/Budgets.t create mode 100644 t/db_dependent/Koha/Acquisition/Funds.t diff --git a/Koha/Acquisition/Budgets.pm b/Koha/Acquisition/Budgets.pm index e9cae2227b..2a50f1d9bb 100644 --- a/Koha/Acquisition/Budgets.pm +++ b/Koha/Acquisition/Budgets.pm @@ -19,6 +19,8 @@ use Modern::Perl; use Koha::Database; +use Koha::Acquisition::Budget; + use base qw(Koha::Objects); =head1 NAME diff --git a/Koha/Acquisition/Funds.pm b/Koha/Acquisition/Funds.pm index 4812ddfe9b..82480e9410 100644 --- a/Koha/Acquisition/Funds.pm +++ b/Koha/Acquisition/Funds.pm @@ -19,6 +19,8 @@ use Modern::Perl; use Koha::Database; +use Koha::Acquisition::Fund; + use base qw(Koha::Objects); =head1 NAME diff --git a/t/db_dependent/Koha/Acquisition/Budgets.t b/t/db_dependent/Koha/Acquisition/Budgets.t new file mode 100644 index 0000000000..e5aedefdad --- /dev/null +++ b/t/db_dependent/Koha/Acquisition/Budgets.t @@ -0,0 +1,54 @@ +#!/usr/bin/perl + +# Copyright 2017 Koha Development team +# +# 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 => 4; + +use Koha::Acquisition::Budgets; +use Koha::Database; +use Koha::DateUtils qw( dt_from_string ); + +use t::lib::TestBuilder; + +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +my $builder = t::lib::TestBuilder->new; +my $nb_of_budgets= Koha::Acquisition::Budgets->search->count; +my $now = dt_from_string; +my $new_budget = Koha::Acquisition::Budget->new({ + budget_period_startdate => $now, + budget_period_enddate => $now, + budget_period_active => 1, + budget_period_description => 'a new budget', + budget_period_total => 1000, +})->store; + +like( $new_budget->budget_period_id, qr|^\d+$|, 'Adding a new budget should have set the budget_period_id'); +is( Koha::Acquisition::Budgets->search->count, $nb_of_budgets + 1, 'The budget should have been added' ); + +my $retrieved_budget = Koha::Acquisition::Budgets->find( $new_budget->budget_period_id); +is( $retrieved_budget->budget_period_description, $new_budget->budget_period_description, 'Find a budget by budget_period_id should return the correct budget' ); + +$retrieved_budget->delete; +is( Koha::Acquisition::Budgets->search->count, $nb_of_budgets, 'Delete should have deleted the budget' ); + +$schema->storage->txn_rollback; + diff --git a/t/db_dependent/Koha/Acquisition/Funds.t b/t/db_dependent/Koha/Acquisition/Funds.t new file mode 100644 index 0000000000..4232571746 --- /dev/null +++ b/t/db_dependent/Koha/Acquisition/Funds.t @@ -0,0 +1,49 @@ +#!/usr/bin/perl + +# Copyright 2017 Koha Development team +# +# 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 => 4; + +use Koha::Acquisition::Funds; +use Koha::Database; + +use t::lib::TestBuilder; + +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +my $builder = t::lib::TestBuilder->new; +my $nb_of_funds = Koha::Acquisition::Funds->search->count; +my $new_fund = Koha::Acquisition::Fund->new({ + budget_code => 'my_budget_code_for_test', + budget_name => 'my_budget_name_for_test', +})->store; + +like( $new_fund->budget_id, qr|^\d+$|, 'Adding a new fund should have set the budget_id'); +is( Koha::Acquisition::Funds->search->count, $nb_of_funds + 1, 'The fund should have been added' ); + +my $retrieved_fund_1 = Koha::Acquisition::Funds->find( $new_fund->budget_id ); +is( $retrieved_fund_1->budget_name, $new_fund->budget_name, 'Find a fund by budget_id should return the correct fund' ); + +$retrieved_fund_1->delete; +is( Koha::Acquisition::Funds->search->count, $nb_of_funds, 'Delete should have deleted the fund' ); + +$schema->storage->txn_rollback; + -- 2.39.5