View | Details | Raw Unified | Return to bug 23591
Collapse All | Expand All

(-)a/Koha/Suggestion.pm (+75 lines)
Lines 53-58 sub store { Link Here
53
    return $self->SUPER::store();
53
    return $self->SUPER::store();
54
}
54
}
55
55
56
=head3 manager
57
58
my $manager = $suggestion->manager;
59
60
Returns the manager of the suggestion (Koha::Patron for managedby field)
61
62
=cut
63
64
sub manager {
65
    my ($self) = @_;
66
    my $manager_rs = $self->_result->managedby;
67
    return unless $manager_rs;
68
    return Koha::Patron->_new_from_dbic($manager_rs);
69
}
70
71
=head3 suggester
72
73
my $suggester = $suggestion->suggester;
74
75
Returns the suggester of the suggestion (Koha::Patron for suggestedby field)
76
77
=cut
78
79
sub suggester {
80
    my ($self) = @_;
81
    my $suggester_rs = $self->_result->managedby;
82
    return unless $suggester_rs;
83
    return Koha::Patron->_new_from_dbic($suggester_rs);
84
}
85
86
=head3 rejecter
87
88
my $rejecter = $suggestion->rejecter;
89
90
Returns the rejecter of the suggestion (Koha::Patron for rejectebby field)
91
92
=cut
93
94
sub rejecter {
95
    my ($self) = @_;
96
    my $rejecter_rs = $self->_result->managedby;
97
    return unless $rejecter_rs;
98
    return Koha::Patron->_new_from_dbic($rejecter_rs);
99
}
100
101
=head3 last_modifier
102
103
my $last_modifier = $suggestion->last_modifier;
104
105
Returns the librarian who last modified the suggestion (Koha::Patron for lastmodificationby field)
106
107
=cut
108
109
sub last_modifier {
110
    my ($self) = @_;
111
    my $last_modifier_rs = $self->_result->managedby;
112
    return unless $last_modifier_rs;
113
    return Koha::Patron->_new_from_dbic($last_modifier_rs);
114
}
115
116
=head3 fund
117
118
my $fund = $suggestion->fund;
119
120
Return the fund associated to the suggestion
121
122
=cut
123
124
sub fund {
125
    my ($self) = @_;
126
    my $fund_rs = $self->_result->budgetid;
127
    return unless $fund_rs;
128
    return Koha::Acquisition::Fund->_new_from_dbic($fund_rs);
129
}
130
56
=head3 type
131
=head3 type
57
132
58
=cut
133
=cut
(-)a/t/db_dependent/Koha/Suggestions.t (-3 / +61 lines)
Lines 1-6 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
# Copyright 2015 Koha Development team
3
# Copyright 2015-2019 Koha Development team
4
#
4
#
5
# This file is part of Koha
5
# This file is part of Koha
6
#
6
#
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 6;
22
use Test::More tests => 8;
23
use Test::Exception;
23
use Test::Exception;
24
24
25
use Koha::Suggestion;
25
use Koha::Suggestion;
Lines 171-173 subtest 'constraints' => sub { Link Here
171
    $schema->storage->dbh->{PrintError} = $print_error;
171
    $schema->storage->dbh->{PrintError} = $print_error;
172
    $schema->storage->txn_rollback;
172
    $schema->storage->txn_rollback;
173
};
173
};
174
- 
174
175
subtest 'manager, suggester, rejecter, last_modifier' => sub {
176
    plan tests => 8;
177
    $schema->storage->txn_begin;
178
179
    my $suggestion = $builder->build_object( { class => 'Koha::Suggestions' } );
180
181
    is( ref( $suggestion->manager ),
182
        'Koha::Patron',
183
        '->manager should have returned a Koha::Patron object' );
184
    is( ref( $suggestion->rejecter ),
185
        'Koha::Patron',
186
        '->rejecter should have returned a Koha::Patron object' );
187
    is( ref( $suggestion->suggester ),
188
        'Koha::Patron',
189
        '->suggester should have returned a Koha::Patron object' );
190
    is( ref( $suggestion->last_modifier ),
191
        'Koha::Patron',
192
        '->last_modifier should have returned a Koha::Patron object' );
193
194
    $suggestion->set(
195
        {
196
            managedby          => undef,
197
            rejectedby         => undef,
198
            suggestedby        => undef,
199
            lastmodificationby => undef
200
        }
201
    );
202
203
    is( $suggestion->manager, undef,
204
        '->manager should have returned undef if no manager set' );
205
    is( $suggestion->rejecter, undef,
206
        '->rejecter should have returned undef if no rejecter set' );
207
    is( $suggestion->suggester, undef,
208
        '->suggester should have returned undef if no suggester set' );
209
    is( $suggestion->last_modifier,
210
        undef,
211
        '->last_modifier should have returned undef if no last_modifier set' );
212
213
    $schema->storage->txn_rollback;
214
};
215
216
subtest 'fund' => sub {
217
    plan tests => 2;
218
219
    $schema->storage->txn_begin;
220
221
    my $suggestion = $builder->build_object( { class => 'Koha::Suggestions' } );
222
    is( ref( $suggestion->fund ),
223
        'Koha::Acquisition::Fund',
224
        '->fund should have returned a Koha::Acquisition::Fund object' );
225
226
    $suggestion->set( { budgetid => undef } );
227
228
    is( $suggestion->fund, undef,
229
        '->fund should have returned undef if not fund set' );
230
231
    $schema->storage->txn_rollback;
232
  } :

Return to bug 23591