Conflicts: docs/gotcha.txt docs/previousVersion.sql docs/templates.txt lib/WebGUI.pm lib/WebGUI/Asset.pm lib/WebGUI/Asset/Event.pm lib/WebGUI/Asset/File.pm lib/WebGUI/Asset/MapPoint.pm lib/WebGUI/Asset/RichEdit.pm lib/WebGUI/Asset/Sku/Product.pm lib/WebGUI/Asset/Snippet.pm lib/WebGUI/Asset/Story.pm lib/WebGUI/Asset/Template.pm lib/WebGUI/Asset/Template/TemplateToolkit.pm lib/WebGUI/Asset/Wobject/Calendar.pm lib/WebGUI/Asset/Wobject/Carousel.pm lib/WebGUI/Asset/Wobject/Collaboration.pm lib/WebGUI/Asset/Wobject/Dashboard.pm lib/WebGUI/Asset/Wobject/DataForm.pm lib/WebGUI/Asset/Wobject/Folder.pm lib/WebGUI/Asset/Wobject/Map.pm lib/WebGUI/Asset/Wobject/Search.pm lib/WebGUI/Asset/Wobject/Shelf.pm lib/WebGUI/Asset/Wobject/StockData.pm lib/WebGUI/Asset/Wobject/StoryTopic.pm lib/WebGUI/Asset/Wobject/SyndicatedContent.pm lib/WebGUI/Asset/Wobject/Thingy.pm lib/WebGUI/Asset/Wobject/WeatherData.pm lib/WebGUI/AssetClipboard.pm lib/WebGUI/AssetCollateral/DataForm/Entry.pm lib/WebGUI/AssetExportHtml.pm lib/WebGUI/AssetLineage.pm lib/WebGUI/AssetMetaData.pm lib/WebGUI/AssetTrash.pm lib/WebGUI/AssetVersioning.pm lib/WebGUI/Auth.pm lib/WebGUI/Cache/CHI.pm lib/WebGUI/Content/AssetManager.pm lib/WebGUI/Fork/ProgressBar.pm lib/WebGUI/Form/JsonTable.pm lib/WebGUI/Form/TimeField.pm lib/WebGUI/Form/Zipcode.pm lib/WebGUI/Group.pm lib/WebGUI/International.pm lib/WebGUI/Macro/AssetProxy.pm lib/WebGUI/Macro/FileUrl.pm lib/WebGUI/Operation/SSO.pm lib/WebGUI/Operation/User.pm lib/WebGUI/Role/Asset/Subscribable.pm lib/WebGUI/Shop/Cart.pm lib/WebGUI/Shop/Transaction.pm lib/WebGUI/Shop/TransactionItem.pm lib/WebGUI/Test.pm lib/WebGUI/URL/Content.pm lib/WebGUI/URL/Uploads.pm lib/WebGUI/User.pm lib/WebGUI/Workflow/Activity/ExtendCalendarRecurrences.pm lib/WebGUI/Workflow/Activity/SendNewsletters.pm lib/WebGUI/i18n/English/Asset.pm lib/WebGUI/i18n/English/WebGUI.pm sbin/installClass.pl sbin/rebuildLineage.pl sbin/search.pl sbin/testEnvironment.pl t/Asset/Asset.t t/Asset/AssetClipboard.t t/Asset/AssetLineage.t t/Asset/AssetMetaData.t t/Asset/Event.t t/Asset/File.t t/Asset/File/Image.t t/Asset/Post/notification.t t/Asset/Sku.t t/Asset/Story.t t/Asset/Template.t t/Asset/Wobject/Collaboration/templateVariables.t t/Asset/Wobject/Collaboration/unarchiveAll.t t/Asset/Wobject/Shelf.t t/Auth.t t/Macro/EditableToggle.t t/Macro/FilePump.t t/Shop/Cart.t t/Shop/Transaction.t t/Storage.t t/User.t t/Workflow.t
186 lines
6.6 KiB
Perl
186 lines
6.6 KiB
Perl
#-------------------------------------------------------------------
|
|
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
|
|
#-------------------------------------------------------------------
|
|
# Please read the legal notices (docs/legal.txt) and the license
|
|
# (docs/license.txt) that came with this distribution before using
|
|
# this software.
|
|
#-------------------------------------------------------------------
|
|
# http://www.plainblack.com info@plainblack.com
|
|
#-------------------------------------------------------------------
|
|
|
|
use strict;
|
|
|
|
use WebGUI::Test;
|
|
use WebGUI::Form;
|
|
use WebGUI::Form::Date;
|
|
use WebGUI::Session;
|
|
use HTML::Form;
|
|
use WebGUI::Form_Checking;
|
|
|
|
#The goal of this test is to verify that Text form elements work
|
|
|
|
use Test::More; # increment this value for each test you create
|
|
|
|
my $session = WebGUI::Test->session;
|
|
|
|
# put your tests here
|
|
|
|
my $testBlock = [
|
|
{
|
|
key => 'Date1',
|
|
testValue => '1217608466',
|
|
expected => '1217608466',
|
|
comment => 'epoch to epoch',
|
|
},
|
|
{
|
|
key => 'Date2',
|
|
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 = 28 + scalar @{ $testBlock } ;
|
|
|
|
|
|
plan tests => $numTests;
|
|
|
|
my ($header, $footer) = (WebGUI::Form::formHeader($session), WebGUI::Form::formFooter($session));
|
|
my $defaultTime = time();
|
|
|
|
my $html = join "\n",
|
|
$header,
|
|
WebGUI::Form::Date->new($session, {
|
|
name => 'TestDate',
|
|
value => $defaultTime,
|
|
})->toHtml,
|
|
$footer;
|
|
|
|
my @forms = HTML::Form->parse($html, 'http://www.webgui.org');
|
|
|
|
##Test Form Generation
|
|
|
|
is(scalar @forms, 1, '1 form was parsed');
|
|
|
|
my @inputs = $forms[0]->inputs;
|
|
is(scalar @inputs, 2, 'The form has 2 inputs');
|
|
#Basic tests
|
|
my $input = $inputs[1];
|
|
|
|
is($input->name, 'TestDate', 'Checking input name');
|
|
is($input->type, 'text', 'Checking input type');
|
|
is(
|
|
$input->value,
|
|
WebGUI::DateTime->new($session, $defaultTime)->set_time_zone($session->user->get('timeZone'))->toMysqlDate,
|
|
"Checking default value"
|
|
);
|
|
is($input->{size}, 10, 'Checking size param, default');
|
|
is($input->{maxlength}, 10, 'Checking maxlength param, default');
|
|
|
|
##Form value preprocessing
|
|
##Note that HTML::Form will unencode the text for you.
|
|
|
|
$html = join "\n",
|
|
$header,
|
|
WebGUI::Form::Date->new($session, {
|
|
name => 'preDateValue',
|
|
value => 1217608466,
|
|
size => 10,
|
|
maxlength => 10,
|
|
})->toHtml,
|
|
$footer;
|
|
|
|
@forms = HTML::Form->parse($html, 'http://www.webgui.org');
|
|
@inputs = $forms[0]->inputs;
|
|
$input = $inputs[1];
|
|
is($input->name, 'preDateValue', 'Checking input name');
|
|
is($input->{size}, 10, 'Checking size param, set');
|
|
is($input->{maxlength}, 10, 'Checking maxlength param, set');
|
|
|
|
##Test Form Output parsing
|
|
#Dates to Epoch
|
|
WebGUI::Form_Checking::auto_check($session, $formType, $testBlock);
|
|
|
|
|
|
#Dates 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");
|
|
|
|
$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");
|
|
|
|
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 => '2008-008-001'});
|
|
is(
|
|
getValueFromForm($session, $date2->toHtml),
|
|
'1970-01-01',
|
|
"toHtml: defaultValue in bad mysql format returns date from epoch 0"
|
|
);
|
|
|
|
$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");
|
|
|
|
my $dutchie = WebGUI::User->create($session);
|
|
WebGUI::Test->addToCleanup($dutchie);
|
|
$dutchie->update({timeZone => 'Europe/Amsterdam', });
|
|
$session->user({user => $dutchie});
|
|
my $date_form = WebGUI::Form::Date->new($session, { name => 'test_date', });
|
|
$session->request->setup_body({ test_date => '2001-08-16', });
|
|
my $epochal_value = $date_form->getValue;
|
|
|
|
$date_form->set(value => $epochal_value);
|
|
my $mysql_date = getValueFromForm($session, $date_form->toHtml);
|
|
is $mysql_date, '2001-08-16', 'Form data processed and rendered round trip';
|
|
$session->request->setup_body({});
|
|
|
|
$session->user({userId => 1, });
|
|
my $day_form = WebGUI::Form::Date->new($session, { name => 'day_date', value=>'2001-08-16'});
|
|
my $day16 = getValueFromForm($session, $day_form->toHtml);
|
|
is $day16, '2001-08-16', 'day set correctly in form';
|
|
|
|
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};
|
|
}
|