Bug 19826: Add tests
[koha.git] / t / db_dependent / Koha / Acquisition / Budgets.t
1 #!/usr/bin/perl
2
3 # Copyright 2017 Koha Development team
4 #
5 # This file is part of Koha
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21
22 use Test::More tests => 4;
23
24 use Koha::Acquisition::Budgets;
25 use Koha::Database;
26 use Koha::DateUtils qw( dt_from_string );
27
28 use t::lib::TestBuilder;
29
30 my $schema = Koha::Database->new->schema;
31 $schema->storage->txn_begin;
32
33 my $builder = t::lib::TestBuilder->new;
34 my $nb_of_budgets= Koha::Acquisition::Budgets->search->count;
35 my $now = dt_from_string;
36 my $new_budget = Koha::Acquisition::Budget->new({
37     budget_period_startdate => $now,
38     budget_period_enddate => $now,
39     budget_period_active => 1,
40     budget_period_description => 'a new budget',
41     budget_period_total => 1000,
42 })->store;
43
44 like( $new_budget->budget_period_id, qr|^\d+$|, 'Adding a new budget should have set the budget_period_id');
45 is( Koha::Acquisition::Budgets->search->count, $nb_of_budgets + 1, 'The budget should have been added' );
46
47 my $retrieved_budget = Koha::Acquisition::Budgets->find( $new_budget->budget_period_id);
48 is( $retrieved_budget->budget_period_description, $new_budget->budget_period_description, 'Find a budget by budget_period_id should return the correct budget' );
49
50 $retrieved_budget->delete;
51 is( Koha::Acquisition::Budgets->search->count, $nb_of_budgets, 'Delete should have deleted the budget' );
52
53 $schema->storage->txn_rollback;
54