updated to work with new API, 33/33
This commit is contained in:
parent
b7512133dc
commit
a5e3489f63
1 changed files with 27 additions and 28 deletions
55
t/SQL.t
55
t/SQL.t
|
|
@ -12,17 +12,16 @@
|
||||||
use strict;
|
use strict;
|
||||||
use lib '../lib';
|
use lib '../lib';
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
|
use WebGUI::Session;
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
# ---- END DO NOT EDIT ----
|
# ---- END DO NOT EDIT ----
|
||||||
|
|
||||||
|
|
||||||
use Test::More tests => 33; # increment this value for each test you create
|
use Test::More tests => 33; # increment this value for each test you create
|
||||||
use WebGUI::SQL;
|
|
||||||
|
|
||||||
my $session = initialize(); # this line is required
|
my $session = initialize(); # this line is required
|
||||||
|
|
||||||
# read
|
# read
|
||||||
ok(my $sth = WebGUI::SQL->read("select * from settings"), "read()");
|
ok(my $sth = $session->db->read("select * from settings"), "read()");
|
||||||
|
|
||||||
# array
|
# array
|
||||||
my @row = $sth->array;
|
my @row = $sth->array;
|
||||||
|
|
@ -46,7 +45,7 @@ ok($sth->rows > 1, "rows()");
|
||||||
ok($sth->finish, "finish()");
|
ok($sth->finish, "finish()");
|
||||||
|
|
||||||
# unconditionalRead
|
# unconditionalRead
|
||||||
ok(my $sth = WebGUI::SQL->unconditionalRead("select * from tableThatDoesntExist"), "unconditionalRead()");
|
ok(my $sth = $session->db->unconditionalRead("select * from tableThatDoesntExist"), "unconditionalRead()");
|
||||||
|
|
||||||
# errorCode
|
# errorCode
|
||||||
is($sth->errorCode, "1146" ,"errorCode()");
|
is($sth->errorCode, "1146" ,"errorCode()");
|
||||||
|
|
@ -57,13 +56,13 @@ like ($sth->errorMessage, qr/Table [^.]*\.tableThatDoesntExist' doesn't exist/i
|
||||||
$sth->finish;
|
$sth->finish;
|
||||||
|
|
||||||
# quote
|
# quote
|
||||||
is(quote("that's great"), "'that\\\'s great'", "quote()");
|
is($session->db->quote("that's great"), "'that\\\'s great'", "quote()");
|
||||||
is(quote(0), "'0'", "quote(0)");
|
is($session->db->quote(0), "'0'", "quote(0)");
|
||||||
is(quote(''), "''", "quote('')");
|
is($session->db->quote(''), "''", "quote('')");
|
||||||
|
|
||||||
# quoteAndJoin
|
# quoteAndJoin
|
||||||
my @quoteAndJoin = ("that's great", '"Howdy partner!"');
|
my @quoteAndJoin = ("that's great", '"Howdy partner!"');
|
||||||
is(quoteAndJoin(\@quoteAndJoin), "'that\\\'s great','\\\"Howdy partner!\\\"'", "quoteAndJoin()");
|
is($session->db->quoteAndJoin(\@quoteAndJoin), "'that\\\'s great','\\\"Howdy partner!\\\"'", "quoteAndJoin()");
|
||||||
|
|
||||||
# beginTransaction
|
# beginTransaction
|
||||||
SKIP: {
|
SKIP: {
|
||||||
|
|
@ -84,7 +83,7 @@ SKIP: {
|
||||||
}
|
}
|
||||||
|
|
||||||
# prepare
|
# prepare
|
||||||
ok(my $sth = WebGUI::SQL->prepare("select value from settings where name=?"), "prepare()");
|
ok(my $sth = $session->db->prepare("select value from settings where name=?"), "prepare()");
|
||||||
|
|
||||||
# execute
|
# execute
|
||||||
$sth->execute(['showDebug']);
|
$sth->execute(['showDebug']);
|
||||||
|
|
@ -93,59 +92,59 @@ is($sth->errorCode, undef, "execute()");
|
||||||
$sth->finish;
|
$sth->finish;
|
||||||
|
|
||||||
# quickArray
|
# quickArray
|
||||||
my ($value) = WebGUI::SQL->quickArray("select value from settings where name='authMethod'");
|
my ($value) = $session->db->quickArray("select value from settings where name='authMethod'");
|
||||||
ok($value, "quickArray()");
|
ok($value, "quickArray()");
|
||||||
|
|
||||||
# write
|
# write
|
||||||
WebGUI::SQL->write("delete from incrementer where incrementerId='theBigTest'"); # clean up previous failures
|
$session->db->write("delete from incrementer where incrementerId='theBigTest'"); # clean up previous failures
|
||||||
WebGUI::SQL->write("insert into incrementer (incrementerId, nextValue) values ('theBigTest',25)");
|
$session->db->write("insert into incrementer (incrementerId, nextValue) values ('theBigTest',25)");
|
||||||
my ($value) = WebGUI::SQL->quickArray("select nextValue from incrementer where incrementerId='theBigTest'");
|
my ($value) = $session->db->quickArray("select nextValue from incrementer where incrementerId='theBigTest'");
|
||||||
is($value, 25, 'write()');
|
is($value, 25, 'write()');
|
||||||
|
|
||||||
# quickCSV
|
# quickCSV
|
||||||
is(WebGUI::SQL->quickCSV("select * from incrementer where incrementerId='theBigTest'"), "incrementerId,nextValue\ntheBigTest,25\n", "quickCSV()");
|
is($session->db->quickCSV("select * from incrementer where incrementerId='theBigTest'"), "incrementerId,nextValue\ntheBigTest,25\n", "quickCSV()");
|
||||||
|
|
||||||
# quickHash
|
# quickHash
|
||||||
my %quickHash = WebGUI::SQL->quickHash("select * from incrementer where incrementerId='theBigTest'");
|
my %quickHash = $session->db->quickHash("select * from incrementer where incrementerId='theBigTest'");
|
||||||
is($quickHash{nextValue}, 25, "quickHash()");
|
is($quickHash{nextValue}, 25, "quickHash()");
|
||||||
|
|
||||||
# quickHash
|
# quickHash
|
||||||
my $quickHashRef = WebGUI::SQL->quickHashRef("select * from incrementer where incrementerId='theBigTest'");
|
my $quickHashRef = $session->db->quickHashRef("select * from incrementer where incrementerId='theBigTest'");
|
||||||
is($quickHashRef->{nextValue}, 25, "quickHashRef()");
|
is($quickHashRef->{nextValue}, 25, "quickHashRef()");
|
||||||
|
|
||||||
# quickTab
|
# quickTab
|
||||||
is(WebGUI::SQL->quickTab("select * from incrementer where incrementerId='theBigTest'"), "incrementerId\tnextValue\ntheBigTest\t25\n", "quickCSV()");
|
is($session->db->quickTab("select * from incrementer where incrementerId='theBigTest'"), "incrementerId\tnextValue\ntheBigTest\t25\n", "quickCSV()");
|
||||||
|
|
||||||
# buildArray
|
# buildArray
|
||||||
my ($buildArray) = WebGUI::SQL->buildArray("select nextValue from incrementer where incrementerId='theBigTest'");
|
my ($buildArray) = $session->db->buildArray("select nextValue from incrementer where incrementerId='theBigTest'");
|
||||||
is($buildArray, 25, "buildArray()");
|
is($buildArray, 25, "buildArray()");
|
||||||
|
|
||||||
# buildArrayRef
|
# buildArrayRef
|
||||||
my $buildArrayRef = WebGUI::SQL->buildArrayRef("select nextValue from incrementer where incrementerId='theBigTest'");
|
my $buildArrayRef = $session->db->buildArrayRef("select nextValue from incrementer where incrementerId='theBigTest'");
|
||||||
is($buildArrayRef->[0], 25, "buildArrayRef()");
|
is($buildArrayRef->[0], 25, "buildArrayRef()");
|
||||||
|
|
||||||
# buildHash
|
# buildHash
|
||||||
my %buildHash = WebGUI::SQL->buildHash("select incrementerId,nextValue from incrementer where incrementerId='theBigTest'");
|
my %buildHash = $session->db->buildHash("select incrementerId,nextValue from incrementer where incrementerId='theBigTest'");
|
||||||
is($buildHash{theBigTest}, 25, "buildHash()");
|
is($buildHash{theBigTest}, 25, "buildHash()");
|
||||||
|
|
||||||
# buildHashRef
|
# buildHashRef
|
||||||
my $buildHashRef = WebGUI::SQL->buildHashRef("select incrementerId,nextValue from incrementer where incrementerId='theBigTest'");
|
my $buildHashRef = $session->db->buildHashRef("select incrementerId,nextValue from incrementer where incrementerId='theBigTest'");
|
||||||
is($buildHashRef->{theBigTest}, 25, "buildHashRef()");
|
is($buildHashRef->{theBigTest}, 25, "buildHashRef()");
|
||||||
|
|
||||||
# getNextId
|
# getNextId
|
||||||
is(getNextId('theBigTest'), 25, "getNextId()");
|
is($session->db->getNextId('theBigTest'), 25, "getNextId()");
|
||||||
WebGUI::SQL->write("delete from incrementer where incrementerId='theBigTest'");
|
$session->db->write("delete from incrementer where incrementerId='theBigTest'");
|
||||||
|
|
||||||
# setRow
|
# setRow
|
||||||
my $setRowId = WebGUI::SQL->setRow("incrementer","incrementerId",{incrementerId=>"new", nextValue=>47});
|
my $setRowId = $session->db->setRow("incrementer","incrementerId",{incrementerId=>"new", nextValue=>47});
|
||||||
ok($setRowId ne "", "setRow() - return ID");
|
ok($setRowId ne "", "setRow() - return ID");
|
||||||
my ($setRowResult) = WebGUI::SQL->quickArray("select nextValue from incrementer where incrementerId=".quote($setRowId));
|
my ($setRowResult) = $session->db->quickArray("select nextValue from incrementer where incrementerId=".$session->db->quote($setRowId));
|
||||||
is($setRowResult, 47, "setRow() - set data");
|
is($setRowResult, 47, "setRow() - set data");
|
||||||
|
|
||||||
# getRow
|
# getRow
|
||||||
my $getRow = WebGUI::SQL->getRow("incrementer","incrementerId",$setRowId);
|
my $getRow = $session->db->getRow("incrementer","incrementerId",$setRowId);
|
||||||
is($getRow->{nextValue}, 47, "getRow()");
|
is($getRow->{nextValue}, 47, "getRow()");
|
||||||
WebGUI::SQL->write("delete from incrementer where incrementerId=".quote($setRowId));
|
$session->db->write("delete from incrementer where incrementerId=".$session->db->quote($setRowId));
|
||||||
|
|
||||||
|
|
||||||
cleanup($session); # this line is required
|
cleanup($session); # this line is required
|
||||||
|
|
@ -153,7 +152,7 @@ cleanup($session); # this line is required
|
||||||
|
|
||||||
# ---- DO NOT EDIT BELOW THIS LINE -----
|
# ---- DO NOT EDIT BELOW THIS LINE -----
|
||||||
|
|
||||||
nitialize {
|
sub initialize {
|
||||||
$|=1; # disable output buffering
|
$|=1; # disable output buffering
|
||||||
my $configFile;
|
my $configFile;
|
||||||
GetOptions(
|
GetOptions(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue