Fix the Shop/Transaction tests for JSON.
Convert Shop/Transaction and Shop/Tax to use buildDataTableStructure. Change SQL.pm to return a hash instead of a hashref for buildDataTableStructure.
This commit is contained in:
parent
4db53bb8ed
commit
875187ee74
4 changed files with 11 additions and 33 deletions
|
|
@ -241,7 +241,7 @@ Builds a data structure that can be converted to JSON and sent
|
|||
to a YUI Data Table. This is basically a hash of information about
|
||||
the results, with one of the keys being an array ref of hashrefs. It also
|
||||
calculates the total records that could have been matched without a limit
|
||||
statement, as well as how many were actually matched.
|
||||
statement, as well as how many were actually matched. It returns a hash.
|
||||
|
||||
=head3 sql
|
||||
|
||||
|
|
@ -270,7 +270,7 @@ sub buildDataTableStructure {
|
|||
$hash{totalRecords} = $self->quickScalar('select found_rows()') + 0; ##Convert to numeric
|
||||
$hash{recordsReturned} = $sth->rows();
|
||||
$sth->finish;
|
||||
return \%hash;
|
||||
return %hash;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -368,21 +368,10 @@ sub www_getTaxesAsJson {
|
|||
}
|
||||
push(@placeholders, $startIndex, $numberOfResults);
|
||||
$sql .= ' order by country desc limit ?,?';
|
||||
my $transactions = $db->read($sql, \@placeholders);
|
||||
my $totalRecords = 0+$db->quickScalar('select found_rows()'); ##Must explicitly convert to numerics
|
||||
my $tally = $transactions->rows();
|
||||
my @records = ();
|
||||
while (my $row = $transactions->hashRef) {
|
||||
push(@records, $row);
|
||||
}
|
||||
my %results = (
|
||||
totalRecords => $totalRecords + 0,
|
||||
recordsReturned => $tally,
|
||||
startIndex => $startIndex,
|
||||
sort => undef,
|
||||
dir => "desc",
|
||||
records => \@records,
|
||||
);
|
||||
my %results = $db->buildDataTableStructure($sql, \@placeholders);
|
||||
$results{'startIndex'} = $startIndex;
|
||||
$results{'sort'} = undef;
|
||||
$results{'dir'} = "desc";
|
||||
$session->http->setMimeType('text/json');
|
||||
return JSON::to_json(\%results);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -361,22 +361,10 @@ sub www_getTransactionsAsJson {
|
|||
}
|
||||
push(@placeholders, $startIndex, $numberOfResults);
|
||||
$sql .= ' order by dateOfPurchase desc limit ?,?';
|
||||
my $transactions = $db->read($sql, \@placeholders);
|
||||
my $totalRecords = $db->quickScalar('select found_rows()');
|
||||
my $tally = 0;
|
||||
my @records = ();
|
||||
while (my $row = $transactions->hashRef) {
|
||||
push(@records, $row);
|
||||
$tally++;
|
||||
}
|
||||
my %results = (
|
||||
totalRecords => $totalRecords + 0,
|
||||
recordsReturned => $tally,
|
||||
startIndex => $startIndex,
|
||||
sort => undef,
|
||||
dir => "desc",
|
||||
records => \@records,
|
||||
);
|
||||
my %results = $db->buildDataTableStructure($sql, \@placeholders);
|
||||
$results{'startIndex'} = $startIndex;
|
||||
$results{'sort'} = undef;
|
||||
$results{'dir'} = "desc";
|
||||
$session->http->setMimeType('text/json');
|
||||
return JSON::to_json(\%results);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -199,6 +199,7 @@ is(scalar @{$transaction->getItems}, 0, "can delete items");
|
|||
$session->user({userId=>3});
|
||||
my $json = WebGUI::Shop::Transaction->www_getTransactionsAsJson($session);
|
||||
ok($json, 'www_getTransactionsAsJson returned something');
|
||||
diag $json;
|
||||
my $jsonTransactions = JSON::from_json($json);
|
||||
cmp_deeply(
|
||||
$jsonTransactions,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue