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
|
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
|
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
|
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
|
=head3 sql
|
||||||
|
|
||||||
|
|
@ -270,7 +270,7 @@ sub buildDataTableStructure {
|
||||||
$hash{totalRecords} = $self->quickScalar('select found_rows()') + 0; ##Convert to numeric
|
$hash{totalRecords} = $self->quickScalar('select found_rows()') + 0; ##Convert to numeric
|
||||||
$hash{recordsReturned} = $sth->rows();
|
$hash{recordsReturned} = $sth->rows();
|
||||||
$sth->finish;
|
$sth->finish;
|
||||||
return \%hash;
|
return %hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -368,21 +368,10 @@ sub www_getTaxesAsJson {
|
||||||
}
|
}
|
||||||
push(@placeholders, $startIndex, $numberOfResults);
|
push(@placeholders, $startIndex, $numberOfResults);
|
||||||
$sql .= ' order by country desc limit ?,?';
|
$sql .= ' order by country desc limit ?,?';
|
||||||
my $transactions = $db->read($sql, \@placeholders);
|
my %results = $db->buildDataTableStructure($sql, \@placeholders);
|
||||||
my $totalRecords = 0+$db->quickScalar('select found_rows()'); ##Must explicitly convert to numerics
|
$results{'startIndex'} = $startIndex;
|
||||||
my $tally = $transactions->rows();
|
$results{'sort'} = undef;
|
||||||
my @records = ();
|
$results{'dir'} = "desc";
|
||||||
while (my $row = $transactions->hashRef) {
|
|
||||||
push(@records, $row);
|
|
||||||
}
|
|
||||||
my %results = (
|
|
||||||
totalRecords => $totalRecords + 0,
|
|
||||||
recordsReturned => $tally,
|
|
||||||
startIndex => $startIndex,
|
|
||||||
sort => undef,
|
|
||||||
dir => "desc",
|
|
||||||
records => \@records,
|
|
||||||
);
|
|
||||||
$session->http->setMimeType('text/json');
|
$session->http->setMimeType('text/json');
|
||||||
return JSON::to_json(\%results);
|
return JSON::to_json(\%results);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -361,22 +361,10 @@ sub www_getTransactionsAsJson {
|
||||||
}
|
}
|
||||||
push(@placeholders, $startIndex, $numberOfResults);
|
push(@placeholders, $startIndex, $numberOfResults);
|
||||||
$sql .= ' order by dateOfPurchase desc limit ?,?';
|
$sql .= ' order by dateOfPurchase desc limit ?,?';
|
||||||
my $transactions = $db->read($sql, \@placeholders);
|
my %results = $db->buildDataTableStructure($sql, \@placeholders);
|
||||||
my $totalRecords = $db->quickScalar('select found_rows()');
|
$results{'startIndex'} = $startIndex;
|
||||||
my $tally = 0;
|
$results{'sort'} = undef;
|
||||||
my @records = ();
|
$results{'dir'} = "desc";
|
||||||
while (my $row = $transactions->hashRef) {
|
|
||||||
push(@records, $row);
|
|
||||||
$tally++;
|
|
||||||
}
|
|
||||||
my %results = (
|
|
||||||
totalRecords => $totalRecords + 0,
|
|
||||||
recordsReturned => $tally,
|
|
||||||
startIndex => $startIndex,
|
|
||||||
sort => undef,
|
|
||||||
dir => "desc",
|
|
||||||
records => \@records,
|
|
||||||
);
|
|
||||||
$session->http->setMimeType('text/json');
|
$session->http->setMimeType('text/json');
|
||||||
return JSON::to_json(\%results);
|
return JSON::to_json(\%results);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -199,6 +199,7 @@ is(scalar @{$transaction->getItems}, 0, "can delete items");
|
||||||
$session->user({userId=>3});
|
$session->user({userId=>3});
|
||||||
my $json = WebGUI::Shop::Transaction->www_getTransactionsAsJson($session);
|
my $json = WebGUI::Shop::Transaction->www_getTransactionsAsJson($session);
|
||||||
ok($json, 'www_getTransactionsAsJson returned something');
|
ok($json, 'www_getTransactionsAsJson returned something');
|
||||||
|
diag $json;
|
||||||
my $jsonTransactions = JSON::from_json($json);
|
my $jsonTransactions = JSON::from_json($json);
|
||||||
cmp_deeply(
|
cmp_deeply(
|
||||||
$jsonTransactions,
|
$jsonTransactions,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue