Bug 24430: Unit tests

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Tomas Cohen Arazi 2020-01-15 16:25:19 -03:00 committed by Martin Renvoize
parent d0446c835c
commit f06578b34e
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
1 changed files with 48 additions and 1 deletions

View File

@ -17,10 +17,11 @@
use Modern::Perl;
use Test::More tests => 10;
use Test::More tests => 11;
use C4::Biblio;
use Koha::Database;
use Koha::Acquisition::Orders;
use t::lib::TestBuilder;
use t::lib::Mocks;
@ -490,3 +491,49 @@ subtest 'suggestions() tests' => sub {
$schema->storage->txn_rollback;
};
subtest 'orders() and active_orders_count() tests' => sub {
plan tests => 4;
$schema->storage->txn_begin;
my $biblio = $builder->build_sample_biblio();
my $orders = $biblio->orders;
my $active_orders_count = $biblio->active_orders_count;
is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
is( $orders->count, $active_orders_count, '->orders_count returns the count for the resultset' );
# Add a couple orders
foreach (1..2) {
$builder->build_object(
{
class => 'Koha::Acquisition::Orders',
value => {
biblionumber => $biblio->biblionumber,
datecancellationprinted => '2019-12-31'
}
}
);
}
$builder->build_object(
{
class => 'Koha::Acquisition::Orders',
value => {
biblionumber => $biblio->biblionumber,
datecancellationprinted => undef
}
}
);
$orders = $biblio->orders;
$active_orders_count = $biblio->active_orders_count;
is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
is( $orders->count, $active_orders_count + 2, '->active_orders_count returns the rigt count' );
$schema->storage->txn_rollback;
};