From ecbad2dbfeebd75933ef34f8b1194896351fb1b9 Mon Sep 17 00:00:00 2001
From: Agustin Moyano <agustinmoyano@theke.io>
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
---
 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(-)

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 8919fe29af..cd3c3550e9 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;
@@ -590,6 +589,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 => 52;
diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t
index f2713b4e26..50dbf56c9b 100755
--- a/t/db_dependent/Koha/Item.t
+++ b/t/db_dependent/Koha/Item.t
@@ -19,7 +19,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 7;
+use Test::More tests => 8;
 
 use C4::Biblio;
 use C4::Circulation;
@@ -27,6 +27,8 @@ use C4::Circulation;
 use Koha::Items;
 use Koha::Database;
 use Koha::Old::Items;
+use Koha::AuthorisedValueCategories;
+use Koha::AuthorisedValues;
 
 use List::MoreUtils qw(all);
 
@@ -628,3 +630,34 @@ subtest 'Tests for itemtype' => 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.25.0