Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
use Test::NoWarnings; |
19 |
use Test::NoWarnings; |
20 |
use Test::More tests => 10; |
20 |
use Test::More tests => 11; |
21 |
use Test::Exception; |
21 |
use Test::Exception; |
22 |
|
22 |
|
23 |
use DateTime::Duration; |
23 |
use DateTime::Duration; |
Lines 129-134
subtest 'CRUD' => sub {
Link Here
|
129 |
teardown(); |
129 |
teardown(); |
130 |
}; |
130 |
}; |
131 |
|
131 |
|
|
|
132 |
subtest 'Owner filter logic' => sub { |
133 |
plan tests => 6; |
134 |
|
135 |
my ( @where_strs, @args ); |
136 |
|
137 |
my $test_logic = sub { |
138 |
my ($owner) = @_; |
139 |
@where_strs = (); |
140 |
@args = (); |
141 |
if ( defined $owner and $owner ne '' ) { |
142 |
my @name_parts = split ' ', $owner; |
143 |
|
144 |
if ( @name_parts == 2 ) { |
145 |
push @where_strs, '( bo.firstname LIKE ? AND bo.surname LIKE ? )'; |
146 |
push @args, "%$name_parts[0]%", "%$name_parts[1]%"; |
147 |
} else { |
148 |
push @where_strs, '(bo.firstname LIKE ? OR bo.surname LIKE ?)'; |
149 |
push @args, "%$owner%", "%$owner%"; |
150 |
} |
151 |
} |
152 |
return ( \@where_strs, \@args ); |
153 |
}; |
154 |
|
155 |
my ( $where, $args ); |
156 |
|
157 |
( $where, $args ) = $test_logic->(undef); |
158 |
is_deeply( $where, [], 'No where clause when owner is undef' ); |
159 |
is_deeply( $args, [], 'No args when owner is undef' ); |
160 |
|
161 |
( $where, $args ) = $test_logic->(''); |
162 |
is_deeply( $where, [], 'No where clause when owner is empty' ); |
163 |
is_deeply( $args, [], 'No args when owner is empty' ); |
164 |
|
165 |
( $where, $args ) = $test_logic->('John Smith'); |
166 |
is_deeply( $where, ['( bo.firstname LIKE ? AND bo.surname LIKE ? )'], 'AND clause for two name parts' ); |
167 |
is_deeply( $args, [ '%John%', '%Smith%' ], 'Args match both names' ); |
168 |
}; |
169 |
|
132 |
subtest 'Sharing' => sub { |
170 |
subtest 'Sharing' => sub { |
133 |
plan tests => 21; |
171 |
plan tests => 21; |
134 |
my $patron_wants_to_share = $builder->build( |
172 |
my $patron_wants_to_share = $builder->build( |
135 |
- |
|
|