Bug 23591: Add some useful methods to Koha::Suggestions
Those are methods initially written for bug 23991. I finally need them before than expected. Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
parent
f5b8b6b38c
commit
41e6f0447c
2 changed files with 121 additions and 4 deletions
|
@ -71,9 +71,67 @@ sub suggester {
|
|||
return Koha::Patron->_new_from_dbic($suggester_rs);
|
||||
}
|
||||
|
||||
=head2 Internal methods
|
||||
=head3 manager
|
||||
|
||||
=head3 _type
|
||||
my $manager = $suggestion->manager;
|
||||
|
||||
Returns the manager of the suggestion (Koha::Patron for managedby field)
|
||||
|
||||
=cut
|
||||
|
||||
sub manager {
|
||||
my ($self) = @_;
|
||||
my $manager_rs = $self->_result->managedby;
|
||||
return unless $manager_rs;
|
||||
return Koha::Patron->_new_from_dbic($manager_rs);
|
||||
}
|
||||
|
||||
=head3 rejecter
|
||||
|
||||
my $rejecter = $suggestion->rejecter;
|
||||
|
||||
Returns the rejecter of the suggestion (Koha::Patron for rejectebby field)
|
||||
|
||||
=cut
|
||||
|
||||
sub rejecter {
|
||||
my ($self) = @_;
|
||||
my $rejecter_rs = $self->_result->managedby;
|
||||
return unless $rejecter_rs;
|
||||
return Koha::Patron->_new_from_dbic($rejecter_rs);
|
||||
}
|
||||
|
||||
=head3 last_modifier
|
||||
|
||||
my $last_modifier = $suggestion->last_modifier;
|
||||
|
||||
Returns the librarian who last modified the suggestion (Koha::Patron for lastmodificationby field)
|
||||
|
||||
=cut
|
||||
|
||||
sub last_modifier {
|
||||
my ($self) = @_;
|
||||
my $last_modifier_rs = $self->_result->managedby;
|
||||
return unless $last_modifier_rs;
|
||||
return Koha::Patron->_new_from_dbic($last_modifier_rs);
|
||||
}
|
||||
|
||||
=head3 fund
|
||||
|
||||
my $fund = $suggestion->fund;
|
||||
|
||||
Return the fund associated to the suggestion
|
||||
|
||||
=cut
|
||||
|
||||
sub fund {
|
||||
my ($self) = @_;
|
||||
my $fund_rs = $self->_result->budgetid;
|
||||
return unless $fund_rs;
|
||||
return Koha::Acquisition::Fund->_new_from_dbic($fund_rs);
|
||||
}
|
||||
|
||||
=head3 type
|
||||
|
||||
=cut
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
# Copyright 2015 Koha Development team
|
||||
# Copyright 2015-2019 Koha Development team
|
||||
#
|
||||
# This file is part of Koha
|
||||
#
|
||||
|
@ -19,7 +19,7 @@
|
|||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More tests => 6;
|
||||
use Test::More tests => 8;
|
||||
use Test::Exception;
|
||||
|
||||
use Koha::Suggestion;
|
||||
|
@ -171,3 +171,62 @@ subtest 'constraints' => sub {
|
|||
$schema->storage->dbh->{PrintError} = $print_error;
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest 'manager, suggester, rejecter, last_modifier' => sub {
|
||||
plan tests => 8;
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
my $suggestion = $builder->build_object( { class => 'Koha::Suggestions' } );
|
||||
|
||||
is( ref( $suggestion->manager ),
|
||||
'Koha::Patron',
|
||||
'->manager should have returned a Koha::Patron object' );
|
||||
is( ref( $suggestion->rejecter ),
|
||||
'Koha::Patron',
|
||||
'->rejecter should have returned a Koha::Patron object' );
|
||||
is( ref( $suggestion->suggester ),
|
||||
'Koha::Patron',
|
||||
'->suggester should have returned a Koha::Patron object' );
|
||||
is( ref( $suggestion->last_modifier ),
|
||||
'Koha::Patron',
|
||||
'->last_modifier should have returned a Koha::Patron object' );
|
||||
|
||||
$suggestion->set(
|
||||
{
|
||||
managedby => undef,
|
||||
rejectedby => undef,
|
||||
suggestedby => undef,
|
||||
lastmodificationby => undef
|
||||
}
|
||||
);
|
||||
|
||||
is( $suggestion->manager, undef,
|
||||
'->manager should have returned undef if no manager set' );
|
||||
is( $suggestion->rejecter, undef,
|
||||
'->rejecter should have returned undef if no rejecter set' );
|
||||
is( $suggestion->suggester, undef,
|
||||
'->suggester should have returned undef if no suggester set' );
|
||||
is( $suggestion->last_modifier,
|
||||
undef,
|
||||
'->last_modifier should have returned undef if no last_modifier set' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest 'fund' => sub {
|
||||
plan tests => 2;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
my $suggestion = $builder->build_object( { class => 'Koha::Suggestions' } );
|
||||
is( ref( $suggestion->fund ),
|
||||
'Koha::Acquisition::Fund',
|
||||
'->fund should have returned a Koha::Acquisition::Fund object' );
|
||||
|
||||
$suggestion->set( { budgetid => undef } );
|
||||
|
||||
is( $suggestion->fund, undef,
|
||||
'->fund should have returned undef if not fund set' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue