From b54be4122401ae759b7239fa30005c11b242826b Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 22 Jul 2021 11:40:20 +0100 Subject: [PATCH] Bug 22690: (QA follow-up) Add TrackedLink classes and use them This patch adds Koha::TrackedLink(s) classes based on Koha::Object(s) and then adds the relationship accessor to Koha::Item and uses it within the move_to_biblio method. Tests for new relationship also added to t/db_dependent/Koha/Item.t https://bugs.koha-community.org/show_bug.cgi?id=20447 --- Koha/Item.pm | 21 +++++++++++++--- Koha/TrackedLink.pm | 43 +++++++++++++++++++++++++++++++++ Koha/TrackedLinks.pm | 49 ++++++++++++++++++++++++++++++++++++++ t/db_dependent/Koha/Item.t | 18 +++++++++++++- 4 files changed, 127 insertions(+), 4 deletions(-) create mode 100644 Koha/TrackedLink.pm create mode 100644 Koha/TrackedLinks.pm diff --git a/Koha/Item.pm b/Koha/Item.pm index b074d027fe..011f6276d7 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -1189,6 +1189,21 @@ sub orders { return Koha::Acquisition::Orders->_new_from_dbic($orders); } +=head3 tracked_links + + my $tracked_links = $item->tracked_links(); + +Returns a Koha::TrackedLinks object + +=cut + +sub tracked_links { + my ( $self ) = @_; + + my $tracked_links = $self->_result->linktrackers; + return Koha::TrackedLinks->_new_from_dbic($tracked_links); +} + =head3 move_to_biblio $item->move_to_biblio($to_biblio[, $params]); @@ -1255,9 +1270,9 @@ sub move_to_biblio { } ); - # linktrackers (there's no Koha object set available yet) - my $linktrackers = $self->_result->linktrackers; - $linktrackers->update_all({ biblionumber => $to_biblionumber }); + # tracked_links + my $tracked_links = $self->tracked_links; + $tracked_links->update({ biblionumber => $to_biblionumber }); return $to_biblionumber; } diff --git a/Koha/TrackedLink.pm b/Koha/TrackedLink.pm new file mode 100644 index 0000000000..3f37bc746d --- /dev/null +++ b/Koha/TrackedLink.pm @@ -0,0 +1,43 @@ +package Koha::TrackedLink; + +# 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 . + +use Modern::Perl; + + +use Koha::Database; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::TrackedLink - Koha TrackedLink Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'LinkTracker'; +} + +1; diff --git a/Koha/TrackedLinks.pm b/Koha/TrackedLinks.pm new file mode 100644 index 0000000000..3ae1a6b585 --- /dev/null +++ b/Koha/TrackedLinks.pm @@ -0,0 +1,49 @@ +package Koha::TrackedLinks; + +# 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 . + +use Modern::Perl; + + +use Koha::Database; + +use Koha::TrackedLink; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::TrackedLinks - Koha TrackedLink Object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'LinkTracker'; +} + +sub object_class { + return 'Koha::TrackedLink'; +} + +1; diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t index d03a60a30a..067cacd0f3 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 => 11; +use Test::More tests => 12; use Test::Exception; use C4::Biblio qw( GetMarcSubfieldStructure ); @@ -38,6 +38,22 @@ use t::lib::Mocks; my $schema = Koha::Database->new->schema; my $builder = t::lib::TestBuilder->new; +subtest 'tracked_links relationship' => sub { + plan tests => 3; + + my $biblio = $builder->build_sample_biblio(); + my $item = $builder->build_sample_item({ + biblionumber => $biblio->biblionumber, + }); + my $tracked_links = $item->tracked_links; + is( ref($tracked_links), 'Koha::TrackedLinks', 'tracked_links returns a Koha::TrackedLinks object set' ); + is($item->tracked_links->count, 0, "Empty Koha::TrackedLinks set returned if no tracked_links"); + my $link1 = $builder->build({ source => 'LinkTracker', value => { itemnumber => $item->itemnumber }}); + my $link2 = $builder->build({ source => 'LinkTracker', value => { itemnumber => $item->itemnumber }}); + + is($item->tracked_links()->count,2,"Two tracked links found"); +}; + subtest 'hidden_in_opac() tests' => sub { plan tests => 4; -- 2.25.1