Lines 20-26
Link Here
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::NoWarnings; |
22 |
use Test::NoWarnings; |
23 |
use Test::More tests => 24; |
23 |
use Test::More tests => 25; |
24 |
use Test::Exception; |
24 |
use Test::Exception; |
25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
26 |
use Test::Warn; |
26 |
use Test::Warn; |
Lines 151-157
subtest 'new' => sub {
Link Here
|
151 |
}; |
151 |
}; |
152 |
|
152 |
|
153 |
subtest 'find' => sub { |
153 |
subtest 'find' => sub { |
154 |
plan tests => 4; |
154 |
plan tests => 5; |
155 |
|
155 |
|
156 |
# check find on a single PK |
156 |
# check find on a single PK |
157 |
my $patron = $builder->build( { source => 'Borrower' } ); |
157 |
my $patron = $builder->build( { source => 'Borrower' } ); |
Lines 179-184
subtest 'find' => sub {
Link Here
|
179 |
); |
179 |
); |
180 |
|
180 |
|
181 |
is( Koha::Patrons->find(), undef, 'Find returns undef if no params passed' ); |
181 |
is( Koha::Patrons->find(), undef, 'Find returns undef if no params passed' ); |
|
|
182 |
|
183 |
# Test that find passes $result in object_class call |
184 |
my $module = Test::MockModule->new('Koha::Patrons'); |
185 |
$module->mock( |
186 |
'object_class', |
187 |
sub { |
188 |
my ( $self, $params ) = @_; |
189 |
warn "Found " . ref $params; |
190 |
return $module->original("object_class")->( $self, $params ); |
191 |
} |
192 |
); |
193 |
warning_is { $obj = Koha::Patrons->find( $patron->{borrowernumber} ); } |
194 |
'Found Koha::Schema::Result::Borrower', "Koha::Objects->find passed DBIx::Class::Result to \$self->object_class"; |
195 |
$module->unmock('object_class'); |
182 |
}; |
196 |
}; |
183 |
|
197 |
|
184 |
subtest 'search_related' => sub { |
198 |
subtest 'search_related' => sub { |
Lines 209-215
subtest 'search_related' => sub {
Link Here
|
209 |
}; |
223 |
}; |
210 |
|
224 |
|
211 |
subtest 'single' => sub { |
225 |
subtest 'single' => sub { |
212 |
plan tests => 2; |
226 |
plan tests => 3; |
213 |
my $builder = t::lib::TestBuilder->new; |
227 |
my $builder = t::lib::TestBuilder->new; |
214 |
my $patron_1 = $builder->build( { source => 'Borrower' } ); |
228 |
my $patron_1 = $builder->build( { source => 'Borrower' } ); |
215 |
my $patron_2 = $builder->build( { source => 'Borrower' } ); |
229 |
my $patron_2 = $builder->build( { source => 'Borrower' } ); |
Lines 217-226
subtest 'single' => sub {
Link Here
|
217 |
is( ref($patron), 'Koha::Patron', 'Koha::Objects->single returns a single Koha::Patron object.' ); |
231 |
is( ref($patron), 'Koha::Patron', 'Koha::Objects->single returns a single Koha::Patron object.' ); |
218 |
warning_like { Koha::Patrons->search->single } qr/SQL that returns multiple rows/, |
232 |
warning_like { Koha::Patrons->search->single } qr/SQL that returns multiple rows/, |
219 |
"Warning is presented if single is used for a result with multiple rows."; |
233 |
"Warning is presented if single is used for a result with multiple rows."; |
|
|
234 |
|
235 |
# Test that single passes $result in object_class call |
236 |
my $module = Test::MockModule->new('Koha::Patrons'); |
237 |
$module->mock( |
238 |
'object_class', |
239 |
sub { |
240 |
my ( $self, $params ) = @_; |
241 |
warn "Found " . ref $params; |
242 |
return $module->original("object_class")->( $self, $params ); |
243 |
} |
244 |
); |
245 |
warning_is { $patron = Koha::Patrons->search( {}, { rows => 1 } )->single; } |
246 |
'Found Koha::Schema::Result::Borrower', |
247 |
"Koha::Objects->single passed DBIx::Class::Result into \$self->object_class"; |
248 |
|
249 |
$module->unmock('object_class'); |
250 |
}; |
251 |
|
252 |
subtest 'next' => sub { |
253 |
plan tests => 1; |
254 |
|
255 |
my $builder = t::lib::TestBuilder->new; |
256 |
my $patron_1 = $builder->build( { source => 'Borrower' } ); |
257 |
my $patron_2 = $builder->build( { source => 'Borrower' } ); |
258 |
|
259 |
# Test that single passes $result in object_class call |
260 |
my $module = Test::MockModule->new('Koha::Patrons'); |
261 |
$module->mock( |
262 |
'object_class', |
263 |
sub { |
264 |
my ( $self, $params ) = @_; |
265 |
warn "Found " . ref $params; |
266 |
return $module->original("object_class")->( $self, $params ); |
267 |
} |
268 |
); |
269 |
warning_is { my $next_patron = Koha::Patrons->search->next; } |
270 |
'Found Koha::Schema::Result::Borrower', "Koha::Objects->next passed DBIx::Class::Result into \$self->object_class"; |
271 |
|
272 |
$module->unmock('object_class'); |
220 |
}; |
273 |
}; |
221 |
|
274 |
|
222 |
subtest 'last' => sub { |
275 |
subtest 'last' => sub { |
223 |
plan tests => 3; |
276 |
plan tests => 4; |
224 |
my $builder = t::lib::TestBuilder->new; |
277 |
my $builder = t::lib::TestBuilder->new; |
225 |
my $patron_1 = $builder->build( { source => 'Borrower' } ); |
278 |
my $patron_1 = $builder->build( { source => 'Borrower' } ); |
226 |
my $patron_2 = $builder->build( { source => 'Borrower' } ); |
279 |
my $patron_2 = $builder->build( { source => 'Borrower' } ); |
Lines 233-238
subtest 'last' => sub {
Link Here
|
233 |
); |
286 |
); |
234 |
$last_patron = Koha::Patrons->search( { surname => 'should_not_exist' } )->last; |
287 |
$last_patron = Koha::Patrons->search( { surname => 'should_not_exist' } )->last; |
235 |
is( $last_patron, undef, '->last should return undef if search does not return any results' ); |
288 |
is( $last_patron, undef, '->last should return undef if search does not return any results' ); |
|
|
289 |
|
290 |
# Test that single passes $result in object_class call |
291 |
my $module = Test::MockModule->new('Koha::Patrons'); |
292 |
$module->mock( |
293 |
'object_class', |
294 |
sub { |
295 |
my ( $self, $params ) = @_; |
296 |
warn "Found " . ref $params; |
297 |
return $module->original("object_class")->( $self, $params ); |
298 |
} |
299 |
); |
300 |
warning_is { $last_patron = Koha::Patrons->search->last; } |
301 |
'Found Koha::Schema::Result::Borrower', "Koha::Objects->last passed DBIx::Class::Result into \$self->object_class"; |
302 |
|
303 |
$module->unmock('object_class'); |
236 |
}; |
304 |
}; |
237 |
|
305 |
|
238 |
subtest 'get_column' => sub { |
306 |
subtest 'get_column' => sub { |
239 |
- |
|
|