From f64ada0225c2397c85900d99e89cc076c9f13ea0 Mon Sep 17 00:00:00 2001 From: Agustin Moyano Date: Fri, 9 Oct 2020 17:15:31 -0300 Subject: [PATCH] Bug 8179: Add tests This patch adds tests in: * t/db_dependent/Koha/Acquisition/Fund.t * t/db_dependent/Koha/Acquisitoin/Order.t * t/db_dependent/Koha/Item.t Sponsored-by: Virginia Polytechnic Institute and State University Signed-off-by: Tomas Cohen Arazi Signed-off-by: Laura Escamilla --- t/db_dependent/Koha/Acquisition/Fund.t | 15 ++++++++++- t/db_dependent/Koha/Acquisition/Order.t | 18 +++++++++++-- t/db_dependent/Koha/Item.t | 35 ++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 4 deletions(-) mode change 100755 => 100644 t/db_dependent/Koha/Item.t diff --git a/t/db_dependent/Koha/Acquisition/Fund.t b/t/db_dependent/Koha/Acquisition/Fund.t index 38dae6297a..80c4e4e65a 100755 --- a/t/db_dependent/Koha/Acquisition/Fund.t +++ b/t/db_dependent/Koha/Acquisition/Fund.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use t::lib::TestBuilder; @@ -43,6 +43,19 @@ subtest 'to_api() tests' => sub { $schema->storage->txn_rollback; }; +subtest 'budget ()' => sub { + plan tests => 1; + + $schema->storage->txn_begin; + + my $budget = $builder->build_object({ class => 'Koha::Acquisition::Budgets' }); + my $fund = $builder->build_object({ class => 'Koha::Acquisition::Funds', value => { budget_period_id => $budget->budget_period_id } }); + + is($budget->budget_period_id, $fund->budget->budget_period_id, 'Fund\'s budget retrieved correctly'); + + $schema->storage->txn_rollback; +}; + subtest 'budget' => sub { plan tests => 1; diff --git a/t/db_dependent/Koha/Acquisition/Order.t b/t/db_dependent/Koha/Acquisition/Order.t index 4d96e3b7d9..ea7afb0287 100755 --- a/t/db_dependent/Koha/Acquisition/Order.t +++ b/t/db_dependent/Koha/Acquisition/Order.t @@ -19,8 +19,7 @@ use Modern::Perl; -use Test::More tests => 12; -use Test::Exception; +use Test::More tests => 13; use t::lib::TestBuilder; use t::lib::Mocks; @@ -622,6 +621,21 @@ subtest 'filter_by_current & filter_by_cancelled' => sub { $schema->storage->txn_rollback; }; +subtest 'creator ()' => sub { + plan tests => 1; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object({ class => 'Koha::Patrons' }); + my $order = $builder->build_object({ class => 'Koha::Acquisition::Orders', value => { created_by => $patron->borrowernumber } }); + + my $creator = $order->creator; + + is($creator->borrowernumber, $patron->borrowernumber, 'Patron is order creator'); + + $schema->storage->txn_rollback; +}; + subtest 'cancel() tests' => sub { plan tests => 54; diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t old mode 100755 new mode 100644 index d9252ef3d8..5af5e70853 --- a/t/db_dependent/Koha/Item.t +++ b/t/db_dependent/Koha/Item.t @@ -20,7 +20,7 @@ use Modern::Perl; use utf8; -use Test::More tests => 28; +use Test::More tests => 29; use Test::Exception; use Test::MockModule; @@ -33,6 +33,8 @@ use Koha::Database; use Koha::DateUtils qw( dt_from_string ); use Koha::Old::Items; use Koha::Recalls; +use Koha::AuthorisedValueCategories; +use Koha::AuthorisedValues; use List::MoreUtils qw(all); @@ -2124,3 +2126,34 @@ subtest 'is_denied_renewal' => sub { $schema->storage->txn_rollback; }; + +subtest '_fetch_authorised_values' => sub { + plan tests => 1; + + $schema->storage->txn_begin; + + # Delete all Authorised Values of 'Countries' category + Koha::AuthorisedValues->search({category => 'Countries'})->delete; + Koha::AuthorisedValueCategories->search({category_name => 'Countries'})->delete; + + # Create 'Countries' category and authorised value + my $cat = $builder->build_object({ class => 'Koha::AuthorisedValueCategories'}); + my $country = $builder->build_object({ class => 'Koha::AuthorisedValues', value => { category => $cat->category_name } }); + + # Create a new biblio framework + my $fw = $builder->build_object({ class => 'Koha::BiblioFrameworks' }); + + # Add a Marc subfield with kohafield setted to 'items.itemnote' + $builder->build_object({class => 'Koha::MarcSubfieldStructures', value => {frameworkcode => $fw->frameworkcode, authorised_value => $cat->category_name, kohafield => 'items.itemnotes'}}); + + # Create biblio and item + my $biblio = $builder->build_sample_biblio({frameworkcode => $fw->frameworkcode}); + my $item = $builder->build_sample_item({biblionumber => $biblio->biblionumber, itemnotes => $country->authorised_value}); + + # Fetch authorised values + my $avs = $item->_fetch_authorised_values(); + + is($avs->{itemnotes}->{lib}, $country->lib, 'Fetched auhtorised value is ok'); + + $schema->storage->txn_rollback; +}; -- 2.30.2