|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 24; |
22 |
use Test::More tests => 23; |
| 23 |
use Test::Exception; |
23 |
use Test::Exception; |
| 24 |
use Test::MockModule; |
24 |
use Test::MockModule; |
| 25 |
use Test::Warn; |
25 |
use Test::Warn; |
|
Lines 141-147
subtest 'find' => sub {
Link Here
|
| 141 |
}; |
141 |
}; |
| 142 |
|
142 |
|
| 143 |
subtest 'search_related' => sub { |
143 |
subtest 'search_related' => sub { |
| 144 |
plan tests => 6; |
144 |
|
|
|
145 |
plan tests => 3; |
| 146 |
|
| 145 |
my $builder = t::lib::TestBuilder->new; |
147 |
my $builder = t::lib::TestBuilder->new; |
| 146 |
my $patron_1 = $builder->build( { source => 'Borrower' } ); |
148 |
my $patron_1 = $builder->build( { source => 'Borrower' } ); |
| 147 |
my $patron_2 = $builder->build( { source => 'Borrower' } ); |
149 |
my $patron_2 = $builder->build( { source => 'Borrower' } ); |
|
Lines 163-188
subtest 'search_related' => sub {
Link Here
|
| 163 |
[ $patron_1->{branchcode}, $patron_2->{branchcode} ] ), |
165 |
[ $patron_1->{branchcode}, $patron_2->{branchcode} ] ), |
| 164 |
'Koha::Objects->search_related should work as expected' |
166 |
'Koha::Objects->search_related should work as expected' |
| 165 |
); |
167 |
); |
| 166 |
|
|
|
| 167 |
my @libraries = Koha::Patrons->search( |
| 168 |
{ |
| 169 |
-or => { |
| 170 |
borrowernumber => |
| 171 |
[ $patron_1->{borrowernumber}, $patron_2->{borrowernumber} ] |
| 172 |
} |
| 173 |
} |
| 174 |
)->search_related('branchcode'); |
| 175 |
is( |
| 176 |
ref( $libraries[0] ), 'Koha::Library', |
| 177 |
'Koha::Objects->search_related should return a list of Koha::Object-based objects' |
| 178 |
); |
| 179 |
is( scalar(@libraries), 2, |
| 180 |
'Koha::Objects->search_related should work as expected' ); |
| 181 |
ok( eq_array( |
| 182 |
[ map { $_->branchcode } @libraries ], |
| 183 |
[ $patron_1->{branchcode}, $patron_2->{branchcode} ] ), |
| 184 |
'Koha::Objects->search_related should work as expected' |
| 185 |
); |
| 186 |
}; |
168 |
}; |
| 187 |
|
169 |
|
| 188 |
subtest 'single' => sub { |
170 |
subtest 'single' => sub { |
|
Lines 211-217
subtest 'last' => sub {
Link Here
|
| 211 |
|
193 |
|
| 212 |
subtest 'get_column' => sub { |
194 |
subtest 'get_column' => sub { |
| 213 |
plan tests => 1; |
195 |
plan tests => 1; |
| 214 |
my @cities = Koha::Cities->search; |
196 |
my @cities = Koha::Cities->search->as_list; |
| 215 |
my @city_names = map { $_->city_name } @cities; |
197 |
my @city_names = map { $_->city_name } @cities; |
| 216 |
is_deeply( [ Koha::Cities->search->get_column('city_name') ], \@city_names, 'Koha::Objects->get_column should be allowed' ); |
198 |
is_deeply( [ Koha::Cities->search->get_column('city_name') ], \@city_names, 'Koha::Objects->get_column should be allowed' ); |
| 217 |
}; |
199 |
}; |
|
Lines 287-318
subtest '->is_paged and ->pager tests' => sub {
Link Here
|
| 287 |
$schema->storage->txn_rollback; |
269 |
$schema->storage->txn_rollback; |
| 288 |
}; |
270 |
}; |
| 289 |
|
271 |
|
| 290 |
subtest '->search() tests' => sub { |
|
|
| 291 |
|
| 292 |
plan tests => 12; |
| 293 |
|
| 294 |
$schema->storage->txn_begin; |
| 295 |
|
| 296 |
my $count = Koha::Patrons->search->count; |
| 297 |
|
| 298 |
# Create 10 patrons |
| 299 |
foreach (1..10) { |
| 300 |
$builder->build_object({ class => 'Koha::Patrons' }); |
| 301 |
} |
| 302 |
|
| 303 |
my $patrons = Koha::Patrons->search(); |
| 304 |
is( ref($patrons), 'Koha::Patrons', 'search in scalar context returns the Koha::Object-based type' ); |
| 305 |
my @patrons = Koha::Patrons->search(); |
| 306 |
is( scalar @patrons, $count + 10, 'search in list context returns a list of objects' ); |
| 307 |
my $i = 0; |
| 308 |
foreach (1..10) { |
| 309 |
is( ref($patrons[$i]), 'Koha::Patron', 'Objects in the list have the singular type' ); |
| 310 |
$i++; |
| 311 |
} |
| 312 |
|
| 313 |
$schema->storage->txn_rollback; |
| 314 |
}; |
| 315 |
|
| 316 |
subtest "to_api() tests" => sub { |
272 |
subtest "to_api() tests" => sub { |
| 317 |
|
273 |
|
| 318 |
plan tests => 19; |
274 |
plan tests => 19; |
| 319 |
- |
|
|