|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# Copyright 2016 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 => 8; |
| 23 |
|
| 24 |
#use Koha::Account::CreditType; |
| 25 |
use Koha::Account::CreditTypes; |
| 26 |
#use Koha::Account::DebitType; |
| 27 |
use Koha::Account::DebitTypes; |
| 28 |
use Koha::Database; |
| 29 |
|
| 30 |
use t::lib::TestBuilder; |
| 31 |
|
| 32 |
use Try::Tiny; |
| 33 |
|
| 34 |
my $schema = Koha::Database->new->schema; |
| 35 |
$schema->storage->txn_begin; |
| 36 |
|
| 37 |
my $builder = t::lib::TestBuilder->new; |
| 38 |
my $number_of_credit_types = Koha::Account::CreditTypes->search->count; |
| 39 |
my $number_of_debit_types = Koha::Account::DebitTypes->search->count; |
| 40 |
my $new_credit_type_1 = Koha::Account::CreditType->new({ |
| 41 |
type_code => '1CODE', |
| 42 |
description => 'my description 1', |
| 43 |
can_be_deleted => 0, |
| 44 |
can_be_added_manually => 1, |
| 45 |
})->store; |
| 46 |
|
| 47 |
my $new_credit_type_2 = Koha::Account::CreditType->new({ |
| 48 |
type_code => '2CODE', |
| 49 |
description => 'my description 2', |
| 50 |
can_be_deleted => 1, |
| 51 |
can_be_added_manually => 1, |
| 52 |
})->store; |
| 53 |
|
| 54 |
my $new_debit_type_1 = Koha::Account::DebitType->new({ |
| 55 |
type_code => '3CODE', |
| 56 |
description => 'my description 3', |
| 57 |
can_be_deleted => 0, |
| 58 |
can_be_added_manually => 1, |
| 59 |
default_amount => 0.45, |
| 60 |
})->store; |
| 61 |
|
| 62 |
my $new_debit_type_2 = Koha::Account::DebitType->new({ |
| 63 |
type_code => '4CODE', |
| 64 |
description => 'my description 4', |
| 65 |
can_be_deleted => 1, |
| 66 |
can_be_added_manually => 1, |
| 67 |
})->store; |
| 68 |
|
| 69 |
is( Koha::Account::CreditTypes->search->count, $number_of_credit_types + 2, 'The 2 credit types should have been added' ); |
| 70 |
is( Koha::Account::DebitTypes->search->count, $number_of_debit_types + 2, 'The 2 debit types should have been added' ); |
| 71 |
|
| 72 |
my $retrieved_credit_type_1 = Koha::Account::CreditTypes->find( $new_credit_type_1->type_code ); |
| 73 |
is( $retrieved_credit_type_1->description, $new_credit_type_1->description, 'Find a credit type by type_code should return the correct one' ); |
| 74 |
|
| 75 |
my $retrieved_debit_type_1 = Koha::Account::DebitTypes->find( $new_debit_type_1->type_code ); |
| 76 |
is( $retrieved_debit_type_1->description, $new_debit_type_1->description, 'Find a debit type by type_code should return the correct one' ); |
| 77 |
|
| 78 |
my $retrieved_credit_type_2 = Koha::Account::CreditTypes->find( $new_credit_type_2->type_code ); |
| 79 |
my $retrieved_debit_type_2 = Koha::Account::DebitTypes->find( $new_debit_type_2->type_code ); |
| 80 |
|
| 81 |
try { |
| 82 |
$retrieved_credit_type_1->delete; |
| 83 |
} catch { |
| 84 |
ok( $_->isa('Koha::Exceptions::CannotDeleteDefault'), 'The first credit type should not be deleted' ); |
| 85 |
}; |
| 86 |
$retrieved_credit_type_2->delete; |
| 87 |
is( Koha::Account::CreditTypes->search->count, $number_of_credit_types + 1, 'The second credit type should be deleted' ); |
| 88 |
|
| 89 |
try { |
| 90 |
$retrieved_debit_type_1->delete; |
| 91 |
} catch { |
| 92 |
ok( $_->isa('Koha::Exceptions::CannotDeleteDefault'), 'The first debit type should not be deleted' ); |
| 93 |
}; |
| 94 |
$retrieved_debit_type_2->delete; |
| 95 |
is( Koha::Account::DebitTypes->search->count, $number_of_debit_types + 1, 'The second debit type should be deleted' ); |
| 96 |
|
| 97 |
$schema->storage->txn_rollback; |
| 98 |
|
| 99 |
1; |