From 51a414b32f403e26f276a99f419edd17c425828f Mon Sep 17 00:00:00 2001 From: Laura_Escamilla Date: Tue, 20 May 2025 13:03:52 +0000 Subject: [PATCH] Bug 39427: Unit tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To test: 1. Ensure that the virtual shelves system preference is enabled 2. Create one or two lists using a patron that has both a first and last name. You don’t have to add items to the list, the list itself is enough. 3. Under the Owner column in the Lists table search using the patron’s first name. Note that the name is properly filtered. 4. Next try to search by the last name. It is also properly filtered. 5. Now search using both the first name and the last name together. Note that the results come up empty. 6. Apply the patch. 7. Repeat steps 3-5. Note that the patron shows in the results with just the first name, the last name, and the full name. 8. Run t/db_dependent/Virtualshelves.t 9. Sign off and have a great day! :D --- t/db_dependent/Virtualshelves.t | 40 ++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Virtualshelves.t b/t/db_dependent/Virtualshelves.t index 1df952df22..0d37775c37 100755 --- a/t/db_dependent/Virtualshelves.t +++ b/t/db_dependent/Virtualshelves.t @@ -17,7 +17,7 @@ use Modern::Perl; use Test::NoWarnings; -use Test::More tests => 10; +use Test::More tests => 11; use Test::Exception; use DateTime::Duration; @@ -129,6 +129,44 @@ subtest 'CRUD' => sub { teardown(); }; +subtest 'Owner filter logic' => sub { + plan tests => 6; + + my ( @where_strs, @args ); + + my $test_logic = sub { + my ($owner) = @_; + @where_strs = (); + @args = (); + if ( defined $owner and $owner ne '' ) { + my @name_parts = split ' ', $owner; + + if ( @name_parts == 2 ) { + push @where_strs, '( bo.firstname LIKE ? AND bo.surname LIKE ? )'; + push @args, "%$name_parts[0]%", "%$name_parts[1]%"; + } else { + push @where_strs, '(bo.firstname LIKE ? OR bo.surname LIKE ?)'; + push @args, "%$owner%", "%$owner%"; + } + } + return ( \@where_strs, \@args ); + }; + + my ( $where, $args ); + + ( $where, $args ) = $test_logic->(undef); + is_deeply( $where, [], 'No where clause when owner is undef' ); + is_deeply( $args, [], 'No args when owner is undef' ); + + ( $where, $args ) = $test_logic->(''); + is_deeply( $where, [], 'No where clause when owner is empty' ); + is_deeply( $args, [], 'No args when owner is empty' ); + + ( $where, $args ) = $test_logic->('John Smith'); + is_deeply( $where, ['( bo.firstname LIKE ? AND bo.surname LIKE ? )'], 'AND clause for two name parts' ); + is_deeply( $args, [ '%John%', '%Smith%' ], 'Args match both names' ); +}; + subtest 'Sharing' => sub { plan tests => 21; my $patron_wants_to_share = $builder->build( -- 2.39.5