|
Lines 19-33
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
<<<<<<< HEAD |
22 |
use Test::More tests => 12; |
| 23 |
use Test::More tests => 10; |
|
|
| 24 |
======= |
| 25 |
use Test::More tests => 14; |
| 26 |
>>>>>>> 5a26041... Bug 18539: Forbid list context calls for Koha::Objects->find |
| 27 |
use Test::Warn; |
23 |
use Test::Warn; |
| 28 |
|
24 |
|
| 29 |
use Koha::Authority::Types; |
25 |
use Koha::Authority::Types; |
| 30 |
use Koha::Cities; |
26 |
use Koha::Cities; |
|
|
27 |
use Koha::IssuingRules; |
| 31 |
use Koha::Patron::Category; |
28 |
use Koha::Patron::Category; |
| 32 |
use Koha::Patron::Categories; |
29 |
use Koha::Patron::Categories; |
| 33 |
use Koha::Patrons; |
30 |
use Koha::Patrons; |
|
Lines 48-60
my $borrowernumber_exists = grep { /^borrowernumber$/ } @columns;
Link Here
|
| 48 |
is( $borrowernumber_exists, 1, 'Koha::Objects->columns should return the table columns' ); |
45 |
is( $borrowernumber_exists, 1, 'Koha::Objects->columns should return the table columns' ); |
| 49 |
|
46 |
|
| 50 |
subtest 'find' => sub { |
47 |
subtest 'find' => sub { |
| 51 |
plan tests => 2; |
48 |
plan tests => 4; |
| 52 |
my $patron = $builder->build({source => 'Borrower'}); |
49 |
my $patron = $builder->build({source => 'Borrower'}); |
| 53 |
my $patron_object = Koha::Patrons->find( $patron->{borrowernumber} ); |
50 |
my $patron_object = Koha::Patrons->find( $patron->{borrowernumber} ); |
| 54 |
is( $patron_object->borrowernumber, $patron->{borrowernumber}, '->find should return the correct object' ); |
51 |
is( $patron_object->borrowernumber, $patron->{borrowernumber}, '->find should return the correct object' ); |
| 55 |
|
52 |
|
| 56 |
eval { my @patrons = Koha::Patrons->find( $patron->{borrowernumber} ); }; |
53 |
eval { my @patrons = Koha::Patrons->find( $patron->{borrowernumber} ); }; |
| 57 |
like( $@, qr|^Cannot use "->find" in list context|, "->find should not be called in list context to avoid side-effects" ); |
54 |
like( $@, qr|^Cannot use "->find" in list context|, "->find should not be called in list context to avoid side-effects" ); |
|
|
55 |
|
| 56 |
# Test sending undef to find; should not generate a warning |
| 57 |
warning_is { $patron = Koha::Patrons->find( undef ); } |
| 58 |
"", "Sending undef does not trigger a DBIx warning"; |
| 59 |
warning_is { $patron = Koha::Patrons->find( undef, undef ); } |
| 60 |
"", "Sending two undefs does not trigger a DBIx warning too"; |
| 58 |
}; |
61 |
}; |
| 59 |
|
62 |
|
| 60 |
subtest 'update' => sub { |
63 |
subtest 'update' => sub { |
|
Lines 112-117
subtest 'new' => sub {
Link Here
|
| 112 |
Koha::Patron::Categories->find($a_cat_code)->delete; |
115 |
Koha::Patron::Categories->find($a_cat_code)->delete; |
| 113 |
}; |
116 |
}; |
| 114 |
|
117 |
|
|
|
118 |
subtest 'find' => sub { |
| 119 |
plan tests => 5; |
| 120 |
|
| 121 |
# check find on a single PK |
| 122 |
my $patron = $builder->build({ source => 'Borrower' }); |
| 123 |
is( Koha::Patrons->find($patron->{borrowernumber})->surname, |
| 124 |
$patron->{surname}, "Checking an arbitrary patron column after find" |
| 125 |
); |
| 126 |
# check find with unique column |
| 127 |
my $obj = Koha::Patrons->find($patron->{cardnumber}, { key => 'cardnumber' }); |
| 128 |
is( $obj->borrowernumber, $patron->{borrowernumber}, |
| 129 |
'Find with unique column and key specified' ); |
| 130 |
# check find with an additional where clause in the attrs hash |
| 131 |
# we do not expect to find something now |
| 132 |
is( Koha::Patrons->find( |
| 133 |
$patron->{borrowernumber}, |
| 134 |
{ where => { surname => { '!=', $patron->{surname} }}}, |
| 135 |
), undef, 'Additional where clause in find call' ); |
| 136 |
|
| 137 |
# check find with a composite FK |
| 138 |
my $rule = $builder->build({ source => 'Issuingrule' }); |
| 139 |
my @pk = ( $rule->{branchcode}, $rule->{categorycode}, $rule->{itemtype} ); |
| 140 |
is( ref(Koha::IssuingRules->find(@pk)), "Koha::IssuingRule", |
| 141 |
'Find returned a Koha object for composite primary key' ); |
| 142 |
|
| 143 |
is( Koha::Patrons->find(), undef, 'Find returns undef if no params passed' ); |
| 144 |
}; |
| 145 |
|
| 115 |
subtest 'search_related' => sub { |
146 |
subtest 'search_related' => sub { |
| 116 |
plan tests => 8; |
147 |
plan tests => 8; |
| 117 |
my $builder = t::lib::TestBuilder->new; |
148 |
my $builder = t::lib::TestBuilder->new; |
| 118 |
- |
|
|