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

(-)a/t/db_dependent/Virtualshelves.t (-2 / +28 lines)
Lines 130-136 subtest 'CRUD' => sub { Link Here
130
};
130
};
131
131
132
subtest 'Owner filter logic' => sub {
132
subtest 'Owner filter logic' => sub {
133
    plan tests => 6;
133
    plan tests => 16;
134
134
135
    my ( @where_strs, @args );
135
    my ( @where_strs, @args );
136
136
Lines 138-144 subtest 'Owner filter logic' => sub { Link Here
138
        my ($owner) = @_;
138
        my ($owner) = @_;
139
        @where_strs = ();
139
        @where_strs = ();
140
        @args       = ();
140
        @args       = ();
141
141
        if ( defined $owner and $owner ne '' ) {
142
        if ( defined $owner and $owner ne '' ) {
143
            $owner =~ s/^\s+|\s+$//g;    # Trim leading/trailing spaces
144
            $owner =~ s/\s+/ /g;         # Normalize internal whitespace
145
146
            return ( [], [] ) if $owner eq '';
147
142
            my @name_parts = split ' ', $owner;
148
            my @name_parts = split ' ', $owner;
143
149
144
            if ( @name_parts == 2 ) {
150
            if ( @name_parts == 2 ) {
Lines 149-154 subtest 'Owner filter logic' => sub { Link Here
149
                push @args, "%$owner%", "%$owner%";
155
                push @args, "%$owner%", "%$owner%";
150
            }
156
            }
151
        }
157
        }
158
152
        return ( \@where_strs, \@args );
159
        return ( \@where_strs, \@args );
153
    };
160
    };
154
161
Lines 165-170 subtest 'Owner filter logic' => sub { Link Here
165
    ( $where, $args ) = $test_logic->('John Smith');
172
    ( $where, $args ) = $test_logic->('John Smith');
166
    is_deeply( $where, ['( bo.firstname LIKE ? AND bo.surname LIKE ? )'], 'AND clause for two name parts' );
173
    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' );
174
    is_deeply( $args,  [ '%John%', '%Smith%' ],                           'Args match both names' );
175
176
    ( $where, $args ) = $test_logic->('  John Smith  ');
177
    is_deeply( $where, ['( bo.firstname LIKE ? AND bo.surname LIKE ? )'], 'Trimmed whitespace around two name parts' );
178
    is_deeply( $args,  [ '%John%', '%Smith%' ],                           'Args match trimmed names' );
179
180
    ( $where, $args ) = $test_logic->('John     Smith');
181
    is_deeply( $where, ['( bo.firstname LIKE ? AND bo.surname LIKE ? )'], 'Normalized internal whitespace' );
182
    is_deeply( $args,  [ '%John%', '%Smith%' ],                           'Args match normalized names' );
183
184
    ( $where, $args ) = $test_logic->('John ');
185
    is_deeply( $where, ['(bo.firstname LIKE ? OR bo.surname LIKE ?)'], 'Single name with trailing space' );
186
    is_deeply( $args,  [ '%John%', '%John%' ],                         'Args match single name trimmed' );
187
188
    ( $where, $args ) = $test_logic->('   ');
189
    is_deeply( $where, [], 'No where clause when owner is only whitespace' );
190
    is_deeply( $args,  [], 'No args when owner is only whitespace' );
191
192
    ( $where, $args ) = $test_logic->('   John    ');
193
    is_deeply( $where, ['(bo.firstname LIKE ? OR bo.surname LIKE ?)'], 'Single name with leading/trailing spaces' );
194
    is_deeply( $args,  [ '%John%', '%John%' ],                         'Args match cleaned single name' );
168
};
195
};
169
196
170
subtest 'Sharing' => sub {
197
subtest 'Sharing' => sub {
171
- 

Return to bug 39427