Bugzilla – Attachment 97385 Details for
Bug 24419
Add Koha::Suggestion->suggester accessor
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24419: Add Koha::Suggestion->suggestor accessor
Bug-24419-Add-KohaSuggestion-suggestor-accessor.patch (text/plain), 4.38 KB, created by
Martin Renvoize (ashimema)
on 2020-01-15 08:39:08 UTC
(
hide
)
Description:
Bug 24419: Add Koha::Suggestion->suggestor accessor
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2020-01-15 08:39:08 UTC
Size:
4.38 KB
patch
obsolete
>From a28324f1e37a2b4f93425dd6a3463a59663e9d70 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 14 Jan 2020 12:47:19 -0300 >Subject: [PATCH] Bug 24419: Add Koha::Suggestion->suggestor accessor > >This patch adds a ->suggestor accessor to the Koha::Suggestion class. It >will return undef if no suggestor, and a Koha::Patron object otherwise. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/db_dependent/Koha/Suggestion.t >=> SUCCESS: Tests pass! >3. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/Schema/Result/Suggestion.pm | 12 ++++++++ > Koha/Suggestion.pm | 24 +++++++++++++-- > t/db_dependent/Koha/Suggestion.t | 50 ++++++++++++++++++++++++++++++++ > 3 files changed, 84 insertions(+), 2 deletions(-) > create mode 100644 t/db_dependent/Koha/Suggestion.t > >diff --git a/Koha/Schema/Result/Suggestion.pm b/Koha/Schema/Result/Suggestion.pm >index c65b3da7fe..26e5ce8006 100644 >--- a/Koha/Schema/Result/Suggestion.pm >+++ b/Koha/Schema/Result/Suggestion.pm >@@ -443,6 +443,18 @@ __PACKAGE__->belongs_to( > # Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-03-11 12:56:41 > # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:UsG/gxLa0HMMbcpbscV29Q > >+__PACKAGE__->belongs_to( >+ "suggestor", >+ "Koha::Schema::Result::Borrower", >+ { "foreign.borrowernumber" => "self.suggestedby" }, >+ { >+ is_deferrable => 1, >+ join_type => "LEFT", >+ on_delete => "SET NULL", >+ on_update => "CASCADE", >+ }, >+); >+ > sub koha_objects_class { > 'Koha::Suggestions'; > } >diff --git a/Koha/Suggestion.pm b/Koha/Suggestion.pm >index 2fef425197..61b810aa92 100644 >--- a/Koha/Suggestion.pm >+++ b/Koha/Suggestion.pm >@@ -23,6 +23,7 @@ use Carp; > > use Koha::Database; > use Koha::DateUtils qw(dt_from_string); >+use Koha::Patrons; > > use base qw(Koha::Object); > >@@ -32,7 +33,7 @@ Koha::Suggestion - Koha Suggestion object class > > =head1 API > >-=head2 Class Methods >+=head2 Class methods > > =cut > >@@ -53,7 +54,26 @@ sub store { > return $self->SUPER::store(); > } > >-=head3 type >+=head3 suggestor >+ >+ my $patron = $suggestion->suggestor >+ >+Returns the I<Koha::Patron> for the suggestion generator. I<undef> is >+returned if no suggestor is linked. >+ >+=cut >+ >+sub suggestor { >+ my ($self) = @_; >+ >+ my $suggestor_rs = $self->_result->suggestor; >+ return unless $suggestor_rs; >+ return Koha::Patron->_new_from_dbic($suggestor_rs); >+} >+ >+=head2 Internal methods >+ >+=head3 _type > > =cut > >diff --git a/t/db_dependent/Koha/Suggestion.t b/t/db_dependent/Koha/Suggestion.t >new file mode 100644 >index 0000000000..dbd7f2acbb >--- /dev/null >+++ b/t/db_dependent/Koha/Suggestion.t >@@ -0,0 +1,50 @@ >+#!/usr/bin/perl >+ >+# Copyright 2020 Koha Development team >+# >+# 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 <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 1; >+ >+use Koha::Database; >+use Koha::Suggestions; >+ >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'suggestor() tests' => sub { >+ >+ plan tests => 3; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $suggestion = $builder->build_object( >+ { class => 'Koha::Suggestions', value => { suggestedby => undef } } ); >+ >+ is( $suggestion->suggestor, undef, 'Returns undef if no suggestor' ); >+ # Set a borrowernumber >+ $suggestion->suggestedby($patron->borrowernumber)->store->discard_changes; >+ my $suggestor = $suggestion->suggestor; >+ is( ref($suggestor), 'Koha::Patron', 'Type is correct for suggestor' ); >+ is_deeply( $patron->unblessed, $suggestor->unblessed, 'It returns the right patron' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 24419
:
97356
|
97368
|
97385
|
97515