View | Details | Raw Unified | Return to bug 27550
Collapse All | Expand All

(-)a/t/db_dependent/Budgets/CloneBudgetHierarchy.t (-1 / +62 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use Test::More;
6
7
use Koha::Database;
8
use Koha::Acquisition::Budget;
9
use Koha::Acquisition::Fund;
10
11
use C4::Budgets qw(AddBudget CloneBudgetHierarchy GetBudgetHierarchy);
12
13
use t::lib::TestBuilder;
14
15
plan tests => 1;
16
17
my $schema = Koha::Database->schema;
18
my $builder = t::lib::TestBuilder->new;
19
20
subtest 'CloneBudgetHierarchy should clone budget users too' => sub {
21
    plan tests => 1;
22
    $schema->txn_begin;
23
24
    my $aqbudgetperiod_rs = $schema->resultset('Aqbudgetperiod');
25
    my $budget_1 = Koha::Acquisition::Budget->new(
26
        {
27
            budget_period_startdate => '2000-01-01',
28
            budget_period_enddate => '2999-12-31',
29
        }
30
    )->store;
31
32
    my $budget_1_fund_1 = Koha::Acquisition::Fund->new(
33
        {
34
            budget_period_id => $budget_1->id,
35
        }
36
    )->store;
37
38
    my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' });
39
    my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' });
40
41
    C4::Budgets::ModBudgetUsers($budget_1_fund_1->id, $patron_1->id, $patron_2->id);
42
43
    my $budget_2 = Koha::Acquisition::Budget->new(
44
        {
45
            budget_period_startdate => '2000-01-01',
46
            budget_period_enddate => '2999-12-31',
47
        }
48
    )->store;
49
50
    CloneBudgetHierarchy(
51
        {
52
            budgets => C4::Budgets::GetBudgetHierarchy($budget_1->id),
53
            new_budget_period_id => $budget_2->id,
54
        }
55
    );
56
57
    my @funds = Koha::Acquisition::Funds->search({ budget_period_id => $budget_2->id })->as_list;
58
    my @borrowernumbers = C4::Budgets::GetBudgetUsers($funds[0]->id);
59
    is_deeply(\@borrowernumbers, [$patron_1->id, $patron_2->id], 'cloned budget has the same users as the original');
60
61
    $schema->txn_rollback;
62
};

Return to bug 27550