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

(-)a/t/db_dependent/Koha/Account/DebitType.t (+95 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2019 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 => 7;
23
24
use Koha::Account::DebitTypes;
25
use Koha::Database;
26
27
use t::lib::TestBuilder;
28
29
use Try::Tiny;
30
31
my $schema = Koha::Database->new->schema;
32
$schema->storage->txn_begin;
33
34
my $builder               = t::lib::TestBuilder->new;
35
my $number_of_debit_types = Koha::Account::DebitTypes->search->count;
36
37
my $new_debit_type_1 = Koha::Account::DebitType->new(
38
    {
39
        code                  => '3CODE',
40
        description           => 'my description 3',
41
        can_be_added_manually => 1,
42
        default_amount        => 0.45,
43
    }
44
)->store;
45
46
my $new_debit_type_2 = Koha::Account::DebitType->new(
47
    {
48
        code                  => '4CODE',
49
        description           => 'my description 4',
50
        can_be_added_manually => 1,
51
    }
52
)->store;
53
54
is(
55
    Koha::Account::DebitTypes->search->count,
56
    $number_of_debit_types + 2,
57
    '2 debit types added successfully'
58
);
59
60
my $retrieved_debit_type_1 =
61
  Koha::Account::DebitTypes->find( $new_debit_type_1->code );
62
is(
63
    $retrieved_debit_type_1->description,
64
    $new_debit_type_1->description,
65
    'Find a debit type by code should return the correct one (non-system)'
66
);
67
ok( !$retrieved_debit_type_1->is_system,
68
    'Non-system debit type identified correctly by "is_system"' );
69
70
my $retrieved_debit_type_system = Koha::Account::DebitTypes->find('OVERDUE');
71
is( $retrieved_debit_type_system->code,
72
    'OVERDUE',
73
    'Find a debit type by code should return the correct one (system)' );
74
ok( $retrieved_debit_type_system->is_system,
75
    'System debit type identified correctly by "is_system"' );
76
77
try {
78
    $retrieved_debit_type_system->delete;
79
}
80
catch {
81
    ok(
82
        $_->isa('Koha::Exceptions::CannotDeleteDefault'),
83
        'A system debit type cannot be deleted'
84
    );
85
};
86
$retrieved_debit_type_1->delete;
87
is(
88
    Koha::Account::DebitTypes->search->count,
89
    $number_of_debit_types + 1,
90
    'A non-system debit type can be deleted'
91
);
92
93
$schema->storage->txn_rollback;
94
95
1;
(-)a/t/db_dependent/Koha/Account/DebitTypes.t (-1 / +84 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2019 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 => 3;
23
24
use Koha::Account::DebitType;
25
use Koha::Account::DebitTypes;
26
use Koha::Database;
27
28
use t::lib::TestBuilder;
29
30
use Try::Tiny;
31
32
my $schema = Koha::Database->new->schema;
33
$schema->storage->txn_begin;
34
35
my $builder               = t::lib::TestBuilder->new;
36
my $number_of_debit_types = Koha::Account::DebitTypes->search->count;
37
38
my $new_debit_type_1 = Koha::Account::DebitType->new(
39
    {
40
        code                  => '3CODE',
41
        description           => 'my description 3',
42
        can_be_added_manually => 1,
43
        default_amount        => 0.45,
44
    }
45
)->store;
46
47
my $new_debit_type_2 = Koha::Account::DebitType->new(
48
    {
49
        code                  => '4CODE',
50
        description           => 'my description 4',
51
        can_be_added_manually => 1,
52
    }
53
)->store;
54
55
my $defaults                  = Koha::Account::DebitType::defaults;
56
my $number_of_system_types    = scalar @{$defaults};
57
my $retrieved_debit_types_all = Koha::Account::DebitTypes->search();
58
try {
59
    $retrieved_debit_types_all->delete;
60
}
61
catch {
62
    ok(
63
        $_->isa('Koha::Exceptions::CannotDeleteDefault'),
64
        'A system debit type cannot be deleted via the set'
65
    );
66
};
67
is(
68
    Koha::Account::DebitTypes->search->count,
69
    $number_of_debit_types + 2,
70
    'System debit types cannot be deleted as a set'
71
);
72
73
my $retrieved_debit_types_limited = Koha::Account::DebitTypes->search(
74
    {
75
        code => { 'in' => [ $new_debit_type_1->code, $new_debit_type_2->code ] }
76
    }
77
);
78
$retrieved_debit_types_limited->delete;
79
is( Koha::Account::DebitTypes->search->count,
80
    $number_of_debit_types, 'Non-system debit types can be deleted as a set' );
81
82
$schema->storage->txn_rollback;
83
84
1;

Return to bug 23049