Merge branch 'master' of git@github.com:plainblack/webgui
Conflicts: docs/upgrades/upgrade_7.8.0-7.8.1.pl
This commit is contained in:
commit
5f3477be4a
17 changed files with 347 additions and 194 deletions
|
|
@ -16,7 +16,7 @@ use lib "$FindBin::Bin/../../lib";
|
|||
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use Test::More tests => 26; # increment this value for each test you create
|
||||
use Test::More tests => 28; # increment this value for each test you create
|
||||
use Test::Deep;
|
||||
use JSON;
|
||||
use WebGUI::Asset::Wobject::Thingy;
|
||||
|
|
@ -373,28 +373,51 @@ is($table, undef, '... drops thing specific table');
|
|||
#
|
||||
#################################################################
|
||||
|
||||
%otherThingProperties = %thingProperties;
|
||||
$otherThingProperties{'groupIdView'} = 3;
|
||||
$otherThingId = $thingy->addThing(\%otherThingProperties, 0);
|
||||
%otherFieldProperties = %fieldProperties;
|
||||
$otherFieldProperties{thingId} = $otherThingId;
|
||||
$otherFieldId = $thingy->addField(\%otherFieldProperties, 0);
|
||||
$thingy->editThingDataSave($otherThingId, 'new', {"field_".$otherFieldId => 'value 1'} );
|
||||
$thingy->editThingDataSave($otherThingId, 'new', {"field_".$otherFieldId => 'value 2'} );
|
||||
$thingy->editThingDataSave($otherThingId, 'new', {"field_".$otherFieldId => 'value 3'} );
|
||||
{
|
||||
my %newThingProperties = %thingProperties;
|
||||
$newThingProperties{'groupIdView'} = 3;
|
||||
my $newThingId = $thingy->addThing(\%newThingProperties, 0);
|
||||
my %newFieldProperties = %fieldProperties;
|
||||
$newFieldProperties{thingId} = $newThingId;
|
||||
my $newFieldId = $thingy->addField(\%newFieldProperties, 0);
|
||||
$thingy->editThingDataSave($newThingId, 'new', {"field_".$newFieldId => 'value 1'} );
|
||||
$thingy->editThingDataSave($newThingId, 'new', {"field_".$newFieldId => 'value 2'} );
|
||||
$thingy->editThingDataSave($newThingId, 'new', {"field_".$newFieldId => 'value 3'} );
|
||||
|
||||
my $andy = WebGUI::User->create($session);
|
||||
WebGUI::Test->usersToDelete($andy);
|
||||
$session->user({userId => $andy->userId});
|
||||
my $andy = WebGUI::User->create($session);
|
||||
WebGUI::Test->usersToDelete($andy);
|
||||
$session->user({userId => $andy->userId});
|
||||
|
||||
my $form = $thingy->getFormPlugin({
|
||||
name => 'fakeFormForTesting',
|
||||
fieldType => 'otherThing_'.$otherThingId,
|
||||
fieldInOtherThingId => $otherFieldId,
|
||||
});
|
||||
my $form = $thingy->getFormPlugin({
|
||||
name => 'fakeFormForTesting',
|
||||
fieldType => 'otherThing_'.$newThingId,
|
||||
fieldInOtherThingId => $newFieldId,
|
||||
});
|
||||
|
||||
cmp_deeply(
|
||||
$form->get('options'),
|
||||
{},
|
||||
'getFormPlugin: form has no data since the user does not have viewing privileges'
|
||||
);
|
||||
}
|
||||
|
||||
#################################################################
|
||||
#
|
||||
# getFieldValue
|
||||
#
|
||||
#################################################################
|
||||
{
|
||||
my %newThingProperties = %thingProperties;
|
||||
my $newThingId = $thingy->addThing(\%newThingProperties, 0);
|
||||
my %newFieldProperties = %fieldProperties;
|
||||
$newFieldProperties{thingId} = $newThingId;
|
||||
$newFieldProperties{fieldType} = 'Date';
|
||||
|
||||
my $date = $thingy->getFieldValue(WebGUI::Test->webguiBirthday, \%newFieldProperties);
|
||||
like($date, qr{\d+/\d+/\d+}, "getFieldValue: Date field type returns data in user's format");
|
||||
|
||||
$newFieldProperties{fieldType} = 'DateTime';
|
||||
my $datetime = $thingy->getFieldValue(WebGUI::Test->webguiBirthday, \%newFieldProperties);
|
||||
like($datetime, qr{^\d+/\d+/\d+\s+\d+:\d+}, "... DateTime field also returns data in user's format");
|
||||
}
|
||||
|
||||
cmp_deeply(
|
||||
$form->get('options'),
|
||||
{},
|
||||
'getFormPlugin: form has no data since the user does not have viewing privileges'
|
||||
);
|
||||
|
|
|
|||
31
t/DateTime.t
31
t/DateTime.t
|
|
@ -14,29 +14,25 @@ use lib "$FindBin::Bin/lib";
|
|||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::User;
|
||||
use DateTime;
|
||||
use WebGUI::DateTime;
|
||||
|
||||
# load your modules here
|
||||
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
# put your tests here
|
||||
|
||||
my $numTests = 1 + 17;
|
||||
plan tests => $numTests;
|
||||
|
||||
my $loaded = use_ok("WebGUI::DateTime");
|
||||
plan tests => 23;
|
||||
|
||||
my $timeZoneUser = addUser($session);
|
||||
|
||||
SKIP: {
|
||||
|
||||
skip "Unable to load WebGUI::DateTime", $numTests-1 unless $loaded;
|
||||
|
||||
my $dt = WebGUI::DateTime->new($session,"2006-11-06 21:12:45");
|
||||
|
||||
isa_ok($dt, "WebGUI::DateTime", "constructor");
|
||||
isa_ok($dt, "WebGUI::DateTime", "constructor via epoch");
|
||||
isa_ok($dt, "DateTime", "constructor");
|
||||
|
||||
is($dt->toDatabase, "2006-11-06 21:12:45", "toDatabase returns the identical string since it is in UTC");
|
||||
|
|
@ -67,7 +63,18 @@ is($copiedDt->toUserTimeZone(), "2006-11-06 15:12:45", "add returns the correct
|
|||
my $epochDt = WebGUI::DateTime->new($session, "1169141075");
|
||||
isa_ok($epochDt, "WebGUI::DateTime", "epochal construction");
|
||||
|
||||
}
|
||||
my $now;
|
||||
my $nowDt = WebGUI::DateTime->new($session);
|
||||
isa_ok($nowDt, 'WebGUI::DateTime', 'constructed with undef');
|
||||
cmp_deeply($nowDt->epoch, num(time(),5), '... uses now as the epoch');
|
||||
|
||||
$nowDt = WebGUI::DateTime->new($session, '');
|
||||
isa_ok($nowDt, 'WebGUI::DateTime', 'constructed with empty string');
|
||||
cmp_deeply($nowDt->epoch, num(time(),5), '... uses now as the epoch');
|
||||
|
||||
my $dt1970 = WebGUI::DateTime->new($session, 0);
|
||||
isa_ok($dt1970, 'WebGUI::DateTime', 'constructed with 0');
|
||||
is($dt1970->epoch, 0, '... uses 0 for epoch');
|
||||
|
||||
sub addUser {
|
||||
my $session = shift;
|
||||
|
|
@ -80,7 +87,3 @@ sub addUser {
|
|||
WebGUI::Test->usersToDelete($user);
|
||||
return $user;
|
||||
}
|
||||
|
||||
END { ##Clean-up after yourself, always
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,15 +36,21 @@ my $testBlock = [
|
|||
},
|
||||
{
|
||||
key => 'Date2',
|
||||
testValue => "2008-08-01 16:34:26",
|
||||
expected => $session->datetime->setToEpoch("2008-08-01 16:34:26"),#must call this so that value is appropriate for testers timezone
|
||||
testValue => "2008-08-01",
|
||||
expected => $session->datetime->setToEpoch("2008-08-01"),#must call this so that value is appropriate for testers timezone
|
||||
comment => 'MySQL formatted to epoch',
|
||||
},
|
||||
{
|
||||
key => 'Date3',
|
||||
testValue => '-1',
|
||||
expected => '-1',
|
||||
comment => 'negative epoch to negative epoch',
|
||||
},
|
||||
];
|
||||
|
||||
my $formType = 'date';
|
||||
|
||||
my $numTests = 16 + scalar @{ $testBlock } ;
|
||||
my $numTests = 25 + scalar @{ $testBlock } ;
|
||||
|
||||
|
||||
plan tests => $numTests;
|
||||
|
|
@ -73,10 +79,11 @@ my $input = $inputs[1];
|
|||
|
||||
is($input->name, 'TestDate', 'Checking input name');
|
||||
is($input->type, 'text', 'Checking input type');
|
||||
TODO: {
|
||||
local $TODO = "Figure out why this is returning a MySQL value instead of an epoch.";
|
||||
is($input->value, $defaultTime, "Checking default value");
|
||||
}
|
||||
is(
|
||||
$input->value,
|
||||
WebGUI::DateTime->new($session, $defaultTime)->toMysqlDate,
|
||||
"Checking default value"
|
||||
);
|
||||
is($input->{size}, 10, 'Checking size param, default');
|
||||
is($input->{maxlength}, 10, 'Checking maxlength param, default');
|
||||
|
||||
|
|
@ -97,10 +104,6 @@ $html = join "\n",
|
|||
@inputs = $forms[0]->inputs;
|
||||
$input = $inputs[1];
|
||||
is($input->name, 'preDateValue', 'Checking input name');
|
||||
TODO: {
|
||||
local $TODO = "Figure out why this is returning a MySQL value instead of an epoch.";
|
||||
is($input->value, 1217608466, 'Checking default value');
|
||||
}
|
||||
is($input->{size}, 10, 'Checking size param, set');
|
||||
is($input->{maxlength}, 10, 'Checking maxlength param, set');
|
||||
|
||||
|
|
@ -110,13 +113,50 @@ WebGUI::Form_Checking::auto_check($session, $formType, $testBlock);
|
|||
|
||||
|
||||
#Dates to MySQL
|
||||
my $date2 = WebGUI::Form::Date->new($session, {'defaultValue' => '2008-08-01 16:34:26'});
|
||||
is($date2->getValue(1217608466), '2008-08-01 11:34:26', "Epoch to MySQL");
|
||||
is($date2->getValue('2008-08-01 11:34:26'), '2008-08-01 11:34:26', "MySQL to MySQL");
|
||||
my $date2;
|
||||
$date2 = WebGUI::Form::Date->new($session, {'defaultValue' => '2008-08-01 16:34:26'});
|
||||
is($date2->getValue(1217608466), '2008-08-01 11:34:26', "getValue, defaultValue MySQL format: Epoch to MySQL");
|
||||
is($date2->getValue('2008-08-01'), '2008-08-01', "... MySQL to MySQL");
|
||||
is($date2->getValue(-1), '1969-12-31 17:59:59', "... Negative epoch to MySQL");
|
||||
|
||||
my $date2 = WebGUI::Form::Date->new($session);
|
||||
is($date2->getValue(1217608466), 1217608466, "Default Epoch to Epoch");
|
||||
is($date2->getValue('2008-08-01 11:34:26'), 1217608466, "Default MySQL to Epoch");
|
||||
$date2 = WebGUI::Form::Date->new($session);
|
||||
is($date2->getValue(1217608466), 1217608466, "getValue, no default: Default Epoch to Epoch");
|
||||
is($date2->getValue('2008-08-01'), 1217566800, "... Default MySQL to Epoch");
|
||||
is($date2->getValue(-1), -1, "... Default negative epoch to negative epoch");
|
||||
|
||||
__END__
|
||||
my $bday = WebGUI::Test->webguiBirthday;
|
||||
|
||||
$date2 = WebGUI::Form::Date->new($session);
|
||||
is($date2->getValueAsHtml(), $session->datetime->epochToHuman($date2->getDefaultValue,'%z'), "getValueAsHtml: no defaultValue set, no value set, returns now in user's format");
|
||||
|
||||
$date2 = WebGUI::Form::Date->new($session, {defaultValue => 1217608466});
|
||||
is($date2->getValueAsHtml(), '8/1/2008', "getValueAsHtml: defaultValue in epoch format, returns now in user's format");
|
||||
is(
|
||||
getValueFromForm($session, $date2->toHtmlAsHidden),
|
||||
'2008-08-01',
|
||||
"toHtmlAsHidden: defaultValue in epoch format, returns date in mysql format"
|
||||
);
|
||||
is(
|
||||
getValueFromForm($session, $date2->toHtml),
|
||||
'2008-08-01',
|
||||
"toHtml: defaultValue in epoch format, returns date in mysql format"
|
||||
);
|
||||
$date2 = WebGUI::Form::Date->new($session, {defaultValue => -1});
|
||||
is($date2->getValueAsHtml(), '12/31/1969', "getValueAsHtml: defaultValue as negative epoch, returns in users's format");
|
||||
|
||||
$date2 = WebGUI::Form::Date->new($session, {defaultValue => '2008-08-01'});
|
||||
is($date2->getValueAsHtml(), '2008-08-01', "getValueAsHtml: defaultValue in mysql format, returns default value in mysql format");
|
||||
|
||||
$date2 = WebGUI::Form::Date->new($session, {defaultValue => '2008-08-01', value => $bday, });
|
||||
is($date2->getValueAsHtml(), '8/16/2001', "getValueAsHtml: defaultValue in mysql format, value as epoch returns value in user's format");
|
||||
|
||||
$date2 = WebGUI::Form::Date->new($session, {defaultValue => '2008-08-01', value => '2001-08-16', });
|
||||
is($date2->getValueAsHtml(), '2001-08-16', "getValueAsHtml: defaultValue in mysql format, value as mysql returns value in mysql format");
|
||||
|
||||
sub getValueFromForm {
|
||||
my ($session, $textForm) = @_;
|
||||
my ($header, $footer) = (WebGUI::Form::formHeader($session), WebGUI::Form::formFooter($session));
|
||||
my @forms = HTML::Form->parse($header.$textForm.$footer, 'http://www.webgui.org');
|
||||
my @inputs = $forms[0]->inputs;
|
||||
return $inputs[1]->{value};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ my $session = WebGUI::Test->session;
|
|||
|
||||
my $formType = 'datetime';
|
||||
|
||||
my $numTests = 15;
|
||||
my $numTests = 34;
|
||||
|
||||
plan tests => $numTests;
|
||||
|
||||
|
|
@ -82,23 +82,111 @@ is($input->name, 'preDateValue', 'Checking input name');
|
|||
is($input->{size}, 19, 'Checking size param, set');
|
||||
is($input->{maxlength}, 19, 'Checking maxlength param, set');
|
||||
|
||||
##Test Form Output parsing
|
||||
#Dates to Epoch
|
||||
#WebGUI::Form_Checking::auto_check($session, $formType, $testBlock);
|
||||
#########################################
|
||||
#
|
||||
# getValue
|
||||
#
|
||||
#########################################
|
||||
|
||||
my $date1 = WebGUI::Form::DateTime->new($session, {'defaultValue' => time()});
|
||||
$session->user->profileField( 'timeZone' , 'America/Chicago');
|
||||
is($date1->getValue(1217608466), 1217608466, "Epoch to Epch");
|
||||
is($date1->getValue('2008-08-01 16:34:26'), $session->datetime->setToEpoch("2008-08-01 16:34:26"), "MySQL to Epoch");
|
||||
is($date1->getValue(1217608466), 1217608466, "getValue, defaultValue epoch: Epoch to Epch");
|
||||
is($date1->getValue('2008-08-01 16:34:26'), 1217626466, "... MySQL to Epoch");
|
||||
is($date1->getValue(-1), -1, "... negative epoch to epoch");
|
||||
|
||||
my $date2 = WebGUI::Form::DateTime->new($session);
|
||||
is($date2->getValue(1217608466), 1217608466, "Default Epoch to Epch");
|
||||
is($date2->getValue('2008-08-01 16:34:26'), $session->datetime->setToEpoch("2008-08-01 16:34:26"), "Default MySQL to Epoch");
|
||||
is($date2->getValue(1217608466), 1217608466, "getValue, no default: Default Epoch to Epch");
|
||||
is($date2->getValue('2008-08-01 16:34:26'), 1217626466, "... Default MySQL to Epoch");
|
||||
is($date2->getValue(-1), -1, "... negative epoch to epoch");
|
||||
|
||||
#Dates to MySQL
|
||||
my $date3 = WebGUI::Form::DateTime->new($session, {'defaultValue' => '2008-08-01 16:34:26'});
|
||||
is($date3->getValue(1217608466), '2008-08-01 11:34:26', "Epoch to MySQL");
|
||||
is($date3->getValue('2008-08-01 11:34:26'), '2008-08-01 16:34:26', "MySQL to MySQL");#UTC is 5 hours ahead of Chicago
|
||||
is($date3->getValue(1217608466), '2008-08-01 11:34:26', "getValue, defaultValue is mysql, epoch to mySQL");
|
||||
is($date3->getValue('2008-08-01 11:34:26'), '2008-08-01 16:34:26', "... MySQL to MySQL");#UTC is 5 hours ahead of Chicago
|
||||
is($date3->getValue(-1), '1969-12-31 17:59:59', "... negative epoch to mysql");
|
||||
|
||||
__END__
|
||||
#########################################
|
||||
#
|
||||
# getValueAsHtml
|
||||
#
|
||||
#########################################
|
||||
|
||||
my $bday = WebGUI::Test->webguiBirthday;
|
||||
|
||||
$date2 = WebGUI::Form::DateTime->new($session);
|
||||
is($date2->getValueAsHtml(), $session->datetime->epochToHuman($date2->getDefaultValue,'%z %Z'), "getValueAsHtml: no defaultValue set, no value set, returns now in user's format");
|
||||
|
||||
$date2 = WebGUI::Form::DateTime->new($session, {defaultValue => 1217608466});
|
||||
is($date2->getValueAsHtml(), '8/1/2008 11:34 am', "getValueAsHtml: defaultValue in epoch format, returns now in user's format");
|
||||
is(
|
||||
getValueFromForm($session, $date2->toHtmlAsHidden),
|
||||
'2008-08-01 11:34:26',
|
||||
"toHtmlAsHidden: defaultValue in mysql format, returns date in mysql format"
|
||||
);
|
||||
is(
|
||||
getValueFromForm($session, $date2->toHtml),
|
||||
'2008-08-01 11:34:26',
|
||||
"toHtml: defaultValue in mysql format, returns date in mysql format"
|
||||
);
|
||||
|
||||
$date2 = WebGUI::Form::DateTime->new($session, {defaultValue => -1});
|
||||
is($date2->getValueAsHtml(), '12/31/1969 5:59 pm', "getValueAsHtml: defaultValue as negative epoch, returns as user's format");
|
||||
is(
|
||||
getValueFromForm($session, $date2->toHtmlAsHidden),
|
||||
'1969-12-31 17:59:59',
|
||||
"toHtmlAsHidden: defaultValue as negative epoch, returns date/time in mysql format"
|
||||
);
|
||||
is(
|
||||
getValueFromForm($session, $date2->toHtml),
|
||||
'1969-12-31 17:59:59',
|
||||
"toHtml: defaultValue in mysql format, returns date in mysql format"
|
||||
);
|
||||
|
||||
|
||||
$date2 = WebGUI::Form::DateTime->new($session, {defaultValue => '2008-08-01 11:34:26'});
|
||||
is($date2->getValueAsHtml(), '2008-08-01 06:34:26', "getValueAsHtml: defaultValue in mysql format, returns default value in mysql format");
|
||||
is(
|
||||
getValueFromForm($session, $date2->toHtmlAsHidden),
|
||||
'2008-08-01 06:34:26',
|
||||
"toHtmlAsHidden: defaultValue in mysql format, returns date in mysql format"
|
||||
);
|
||||
is(
|
||||
getValueFromForm($session, $date2->toHtml),
|
||||
'2008-08-01 06:34:26',
|
||||
"toHtml: defaultValue in mysql format, returns date in mysql format"
|
||||
);
|
||||
|
||||
|
||||
$date2 = WebGUI::Form::DateTime->new($session, {defaultValue => '2008-08-01 11:34:26', value => $bday, });
|
||||
is($date2->getValueAsHtml(), '8/16/2001 8:00 am', "getValueAsHtml: defaultValue in mysql format, value as epoch returns value in user's format");
|
||||
is(
|
||||
getValueFromForm($session, $date2->toHtmlAsHidden),
|
||||
'2001-08-16 08:00:00',
|
||||
"toHtmlAsHidden: defaultValue in mysql format, value as epoch returns date in mysql format"
|
||||
);
|
||||
is(
|
||||
getValueFromForm($session, $date2->toHtml),
|
||||
'2001-08-16 08:00:00',
|
||||
"toHtml: defaultValue in mysql format, value as epoch returns date in mysql format"
|
||||
);
|
||||
|
||||
$date2 = WebGUI::Form::DateTime->new($session, {defaultValue => '2008-08-01 11:34:26', value => '2001-08-16 13:00:00', });
|
||||
is($date2->getValueAsHtml(), '2001-08-16 08:00:00', "getValueAsHtml: defaultValue in mysql format, value as mysql returns value in mysql format");
|
||||
is(
|
||||
getValueFromForm($session, $date2->toHtmlAsHidden),
|
||||
'2001-08-16 08:00:00',
|
||||
"toHtmlAsHidden: defaultValue in mysql format, value as mysql returns date in mysql format, adjusted for time zone"
|
||||
);
|
||||
is(
|
||||
getValueFromForm($session, $date2->toHtml),
|
||||
'2001-08-16 08:00:00',
|
||||
"toHtml: defaultValue in mysql format, value as mysql returns date in mysql format, adjusted for time zone"
|
||||
);
|
||||
|
||||
sub getValueFromForm {
|
||||
my ($session, $textForm) = @_;
|
||||
my ($header, $footer) = (WebGUI::Form::formHeader($session), WebGUI::Form::formFooter($session));
|
||||
my @forms = HTML::Form->parse($header.$textForm.$footer, 'http://www.webgui.org');
|
||||
my @inputs = $forms[0]->inputs;
|
||||
return $inputs[1]->{value};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue