Bug 23049: Add tests

Test plan:
  prove t/db_dependent/Koha/Account/DebitType.t
  prove t/db_dependent/Koha/Account/DebitTypes.t

Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Martin Renvoize 2019-10-10 17:14:47 +01:00
parent f48a467fbc
commit 8356c56cc2
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
2 changed files with 179 additions and 0 deletions

View File

@ -0,0 +1,95 @@
#!/usr/bin/perl
# Copyright 2019 Koha Development team
#
# This file is part of Koha
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 7;
use Koha::Account::DebitTypes;
use Koha::Database;
use t::lib::TestBuilder;
use Try::Tiny;
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
my $builder = t::lib::TestBuilder->new;
my $number_of_debit_types = Koha::Account::DebitTypes->search->count;
my $new_debit_type_1 = Koha::Account::DebitType->new(
{
code => '3CODE',
description => 'my description 3',
can_be_added_manually => 1,
default_amount => 0.45,
}
)->store;
my $new_debit_type_2 = Koha::Account::DebitType->new(
{
code => '4CODE',
description => 'my description 4',
can_be_added_manually => 1,
}
)->store;
is(
Koha::Account::DebitTypes->search->count,
$number_of_debit_types + 2,
'2 debit types added successfully'
);
my $retrieved_debit_type_1 =
Koha::Account::DebitTypes->find( $new_debit_type_1->code );
is(
$retrieved_debit_type_1->description,
$new_debit_type_1->description,
'Find a debit type by code should return the correct one (non-system)'
);
ok( !$retrieved_debit_type_1->is_system,
'Non-system debit type identified correctly by "is_system"' );
my $retrieved_debit_type_system = Koha::Account::DebitTypes->find('OVERDUE');
is( $retrieved_debit_type_system->code,
'OVERDUE',
'Find a debit type by code should return the correct one (system)' );
ok( $retrieved_debit_type_system->is_system,
'System debit type identified correctly by "is_system"' );
try {
$retrieved_debit_type_system->delete;
}
catch {
ok(
$_->isa('Koha::Exceptions::CannotDeleteDefault'),
'A system debit type cannot be deleted'
);
};
$retrieved_debit_type_1->delete;
is(
Koha::Account::DebitTypes->search->count,
$number_of_debit_types + 1,
'A non-system debit type can be deleted'
);
$schema->storage->txn_rollback;
1;

View File

@ -0,0 +1,84 @@
#!/usr/bin/perl
# Copyright 2019 Koha Development team
#
# This file is part of Koha
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 3;
use Koha::Account::DebitType;
use Koha::Account::DebitTypes;
use Koha::Database;
use t::lib::TestBuilder;
use Try::Tiny;
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
my $builder = t::lib::TestBuilder->new;
my $number_of_debit_types = Koha::Account::DebitTypes->search->count;
my $new_debit_type_1 = Koha::Account::DebitType->new(
{
code => '3CODE',
description => 'my description 3',
can_be_added_manually => 1,
default_amount => 0.45,
}
)->store;
my $new_debit_type_2 = Koha::Account::DebitType->new(
{
code => '4CODE',
description => 'my description 4',
can_be_added_manually => 1,
}
)->store;
my $defaults = Koha::Account::DebitType::defaults;
my $number_of_system_types = scalar @{$defaults};
my $retrieved_debit_types_all = Koha::Account::DebitTypes->search();
try {
$retrieved_debit_types_all->delete;
}
catch {
ok(
$_->isa('Koha::Exceptions::CannotDeleteDefault'),
'A system debit type cannot be deleted via the set'
);
};
is(
Koha::Account::DebitTypes->search->count,
$number_of_debit_types + 2,
'System debit types cannot be deleted as a set'
);
my $retrieved_debit_types_limited = Koha::Account::DebitTypes->search(
{
code => { 'in' => [ $new_debit_type_1->code, $new_debit_type_2->code ] }
}
);
$retrieved_debit_types_limited->delete;
is( Koha::Account::DebitTypes->search->count,
$number_of_debit_types, 'Non-system debit types can be deleted as a set' );
$schema->storage->txn_rollback;
1;