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

(-)a/Koha/Suggestion.pm (-2 / +60 lines)
Lines 71-79 sub suggester { Link Here
71
    return Koha::Patron->_new_from_dbic($suggester_rs);
71
    return Koha::Patron->_new_from_dbic($suggester_rs);
72
}
72
}
73
73
74
=head2 Internal methods
74
=head3 manager
75
75
76
=head3 _type
76
my $manager = $suggestion->manager;
77
78
Returns the manager of the suggestion (Koha::Patron for managedby field)
79
80
=cut
81
82
sub manager {
83
    my ($self) = @_;
84
    my $manager_rs = $self->_result->managedby;
85
    return unless $manager_rs;
86
    return Koha::Patron->_new_from_dbic($manager_rs);
87
}
88
89
=head3 rejecter
90
91
my $rejecter = $suggestion->rejecter;
92
93
Returns the rejecter of the suggestion (Koha::Patron for rejectebby field)
94
95
=cut
96
97
sub rejecter {
98
    my ($self) = @_;
99
    my $rejecter_rs = $self->_result->managedby;
100
    return unless $rejecter_rs;
101
    return Koha::Patron->_new_from_dbic($rejecter_rs);
102
}
103
104
=head3 last_modifier
105
106
my $last_modifier = $suggestion->last_modifier;
107
108
Returns the librarian who last modified the suggestion (Koha::Patron for lastmodificationby field)
109
110
=cut
111
112
sub last_modifier {
113
    my ($self) = @_;
114
    my $last_modifier_rs = $self->_result->managedby;
115
    return unless $last_modifier_rs;
116
    return Koha::Patron->_new_from_dbic($last_modifier_rs);
117
}
118
119
=head3 fund
120
121
my $fund = $suggestion->fund;
122
123
Return the fund associated to the suggestion
124
125
=cut
126
127
sub fund {
128
    my ($self) = @_;
129
    my $fund_rs = $self->_result->budgetid;
130
    return unless $fund_rs;
131
    return Koha::Acquisition::Fund->_new_from_dbic($fund_rs);
132
}
133
134
=head3 type
77
135
78
=cut
136
=cut
79
137
(-)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