From e7f5fffd9afea0fe6a60bc1e31b7a4be79889f80 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 8 Jan 2018 13:48:28 -0300 Subject: [PATCH] Bug 19926: Add tests for Koha::Object->unblessed_all_relateds Signed-off-by: Benjamin Rokseth Signed-off-by: Josef Moravec --- t/db_dependent/Koha/Object.t | 58 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t index 542b1e2..125394c 100755 --- a/t/db_dependent/Koha/Object.t +++ b/t/db_dependent/Koha/Object.t @@ -17,11 +17,15 @@ use Modern::Perl; -use Test::More tests => 10; +use Test::More tests => 11; use Test::Exception; use Test::Warn; +use DateTime; use C4::Context; +use C4::Biblio; # AddBiblio +use C4::Circulation; # AddIssue +use C4::Members;# AddMember use Koha::Database; use Koha::DateUtils qw( dt_from_string ); use Koha::Libraries; @@ -309,3 +313,55 @@ subtest 'store() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'unblessed_all_relateds' => sub { + plan tests => 3; + + $schema->storage->txn_begin; + + # FIXME It's very painful to create an issue in tests! + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + C4::Context->_new_userenv('xxx'); + C4::Context->set_userenv(0,0,0,'firstname','surname', $library->branchcode, 'Midway Public Library', '', '', ''); + my $patron_category = $builder->build( + { + source => 'Category', + value => { + category_type => 'P', + enrolmentfee => 0, + BlockExpiredPatronOpacActions => -1, # Pick the pref value + } + } + ); + my $patron_data = { + firstname => 'firstname', + surname => 'surname', + categorycode => $patron_category->{categorycode}, + branchcode => $library->branchcode, + }; + my $borrowernumber = C4::Members::AddMember(%$patron_data); + my $patron = Koha::Patrons->find( $borrowernumber ); + my ($biblionumber) = AddBiblio( MARC::Record->new, '' ); + my $biblio = Koha::Biblios->find( $biblionumber ); + my $item = $builder->build_object( + { + class => 'Koha::Items', + value => { + homebranch => $library->branchcode, + holdingbranch => $library->branchcode, + biblionumber => $biblio->biblionumber, + itemlost => 0, + withdrawn => 0, + } + } + ); + + my $issue = AddIssue( $patron->unblessed, $item->barcode, DateTime->now->subtract( days => 1 ) ); + my $overdues = Koha::Patrons->find( $patron->id )->get_overdues; # Koha::Patron->get_overdue prefetches + my $overdue = $overdues->next->unblessed_all_relateds; + is( $overdue->{issue_id}, $issue->issue_id, 'unblessed_all_relateds has field from the original table (issues)' ); + is( $overdue->{title}, $biblio->title, 'unblessed_all_relateds has field from other tables (biblio)' ); + is( $overdue->{homebranch}, $item->homebranch, 'unblessed_all_relateds has field from other tables (items)' ); + + $schema->storage->txn_rollback; +}; -- 2.1.4