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 lib '../lib';
|
||||
use Getopt::Long;
|
||||
use WebGUI::Session;
|
||||
use Data::Dumper;
|
||||
# ---- END DO NOT EDIT ----
|
||||
|
||||
|
||||
use Test::More tests => 33; # increment this value for each test you create
|
||||
use WebGUI::SQL;
|
||||
|
||||
my $session = initialize(); # this line is required
|
||||
|
||||
# read
|
||||
ok(my $sth = WebGUI::SQL->read("select * from settings"), "read()");
|
||||
ok(my $sth = $session->db->read("select * from settings"), "read()");
|
||||
|
||||
# array
|
||||
my @row = $sth->array;
|
||||
|
|
@ -46,7 +45,7 @@ ok($sth->rows > 1, "rows()");
|
|||
ok($sth->finish, "finish()");
|
||||
|
||||
# unconditionalRead
|
||||
ok(my $sth = WebGUI::SQL->unconditionalRead("select * from tableThatDoesntExist"), "unconditionalRead()");
|
||||
ok(my $sth = $session->db->unconditionalRead("select * from tableThatDoesntExist"), "unconditionalRead()");
|
||||
|
||||
# errorCode
|
||||
is($sth->errorCode, "1146" ,"errorCode()");
|
||||
|
|
@ -57,13 +56,13 @@ like ($sth->errorMessage, qr/Table [^.]*\.tableThatDoesntExist' doesn't exist/i
|
|||
$sth->finish;
|
||||
|
||||
# quote
|
||||
is(quote("that's great"), "'that\\\'s great'", "quote()");
|
||||
is(quote(0), "'0'", "quote(0)");
|
||||
is(quote(''), "''", "quote('')");
|
||||
is($session->db->quote("that's great"), "'that\\\'s great'", "quote()");
|
||||
is($session->db->quote(0), "'0'", "quote(0)");
|
||||
is($session->db->quote(''), "''", "quote('')");
|
||||
|
||||
# quoteAndJoin
|
||||
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
|
||||
SKIP: {
|
||||
|
|
@ -84,7 +83,7 @@ SKIP: {
|
|||
}
|
||||
|
||||
# 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
|
||||
$sth->execute(['showDebug']);
|
||||
|
|
@ -93,59 +92,59 @@ is($sth->errorCode, undef, "execute()");
|
|||
$sth->finish;
|
||||
|
||||
# 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()");
|
||||
|
||||
# write
|
||||
WebGUI::SQL->write("delete from incrementer where incrementerId='theBigTest'"); # clean up previous failures
|
||||
WebGUI::SQL->write("insert into incrementer (incrementerId, nextValue) values ('theBigTest',25)");
|
||||
my ($value) = WebGUI::SQL->quickArray("select nextValue from incrementer where incrementerId='theBigTest'");
|
||||
$session->db->write("delete from incrementer where incrementerId='theBigTest'"); # clean up previous failures
|
||||
$session->db->write("insert into incrementer (incrementerId, nextValue) values ('theBigTest',25)");
|
||||
my ($value) = $session->db->quickArray("select nextValue from incrementer where incrementerId='theBigTest'");
|
||||
is($value, 25, 'write()');
|
||||
|
||||
# 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
|
||||
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()");
|
||||
|
||||
# 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()");
|
||||
|
||||
# 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
|
||||
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()");
|
||||
|
||||
# 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()");
|
||||
|
||||
# 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()");
|
||||
|
||||
# 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()");
|
||||
|
||||
# getNextId
|
||||
is(getNextId('theBigTest'), 25, "getNextId()");
|
||||
WebGUI::SQL->write("delete from incrementer where incrementerId='theBigTest'");
|
||||
is($session->db->getNextId('theBigTest'), 25, "getNextId()");
|
||||
$session->db->write("delete from incrementer where incrementerId='theBigTest'");
|
||||
|
||||
# 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");
|
||||
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");
|
||||
|
||||
# getRow
|
||||
my $getRow = WebGUI::SQL->getRow("incrementer","incrementerId",$setRowId);
|
||||
my $getRow = $session->db->getRow("incrementer","incrementerId",$setRowId);
|
||||
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
|
||||
|
|
@ -153,7 +152,7 @@ cleanup($session); # this line is required
|
|||
|
||||
# ---- DO NOT EDIT BELOW THIS LINE -----
|
||||
|
||||
nitialize {
|
||||
sub initialize {
|
||||
$|=1; # disable output buffering
|
||||
my $configFile;
|
||||
GetOptions(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue