Add a SQL method for building searchable queries.
Add tests for that method. Convert Shop/Tax and Shop/Transaction to use that for their JSON generating methods.
This commit is contained in:
parent
d11899cf19
commit
f3fd67378f
4 changed files with 61 additions and 13 deletions
20
t/SQL.t
20
t/SQL.t
|
|
@ -17,7 +17,7 @@ use WebGUI::Session;
|
|||
use Data::Dumper;
|
||||
use Test::Deep;
|
||||
|
||||
use Test::More tests => 53; # increment this value for each test you create
|
||||
use Test::More tests => 57; # increment this value for each test you create
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
|
|
@ -267,6 +267,8 @@ cmp_deeply($hrefHref, \%expected, 'buildHashRefOfHashRefs, 2 columns, 1 param');
|
|||
#
|
||||
# buildDataTableStructure
|
||||
#
|
||||
# Uses the testTable data from the preceeding *RefOf*Ref tests above
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
my %tableStruct = $session->db->buildDataTableStructure('select * from testTable');
|
||||
|
|
@ -283,6 +285,22 @@ cmp_deeply(
|
|||
'Check table structure',
|
||||
);
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# buildSearchQuery
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
my ($searchQuery, @placeHolders) = $session->db->buildSearchQuery('select * from users', 'Admin', [qw{username alias}]);
|
||||
like($searchQuery, qr{^select \* from users}, 'returned query begins with original query');
|
||||
cmp_deeply(
|
||||
\@placeHolders,
|
||||
[('%Admin%') x 2],
|
||||
'placeholders are the keyword repeated 2 times, one for each column, sandwiched in %'
|
||||
);
|
||||
like($searchQuery, qr{where username like \?}, 'returned query searches username column, first column uses where');
|
||||
like($searchQuery, qr{or alias like \?}, 'returned query searches alias column, second column uses or');
|
||||
|
||||
END: {
|
||||
$session->db->dbh->do('DROP TABLE IF EXISTS testTable');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue