42325717468b5115172630ff328f4c7e79e9dce9
[srvgit] / t / db_dependent / Koha / Acquisition / Funds.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::Funds;
25 use Koha::Database;
26
27 use t::lib::TestBuilder;
28
29 my $schema = Koha::Database->new->schema;
30 $schema->storage->txn_begin;
31
32 my $builder = t::lib::TestBuilder->new;
33 my $nb_of_funds = Koha::Acquisition::Funds->search->count;
34 my $new_fund = Koha::Acquisition::Fund->new({
35     budget_code => 'my_budget_code_for_test',
36     budget_name => 'my_budget_name_for_test',
37 })->store;
38
39 like( $new_fund->budget_id, qr|^\d+$|, 'Adding a new fund should have set the budget_id');
40 is( Koha::Acquisition::Funds->search->count, $nb_of_funds + 1, 'The fund should have been added' );
41
42 my $retrieved_fund_1 = Koha::Acquisition::Funds->find( $new_fund->budget_id );
43 is( $retrieved_fund_1->budget_name, $new_fund->budget_name, 'Find a fund by budget_id should return the correct fund' );
44
45 $retrieved_fund_1->delete;
46 is( Koha::Acquisition::Funds->search->count, $nb_of_funds, 'Delete should have deleted the fund' );
47
48 $schema->storage->txn_rollback;
49