diff --git a/lib/WebGUI/Macro/L_loginBox.pm b/lib/WebGUI/Macro/L_loginBox.pm index 99e2818c1..d7a99d9bd 100644 --- a/lib/WebGUI/Macro/L_loginBox.pm +++ b/lib/WebGUI/Macro/L_loginBox.pm @@ -47,12 +47,14 @@ sub _createURL { =head3 boxSize -The size of the login box. Defaults to 12. +The size of the username and password form fields. Defaults to 12. +Non-IE browsers will have their boxSize automatically scaled by 2/3 +due differences in the way they render text form boxes. =head3 text A custom text message, processed for embedded text surrounded by percent signs -to turn into links to logout. +to turn into a link to logout. =head3 templateId diff --git a/lib/WebGUI/i18n/English/Macro_L_loginBox.pm b/lib/WebGUI/i18n/English/Macro_L_loginBox.pm index 289ac096c..e5c386e5e 100644 --- a/lib/WebGUI/i18n/English/Macro_L_loginBox.pm +++ b/lib/WebGUI/i18n/English/Macro_L_loginBox.pm @@ -17,19 +17,14 @@ our $I18N = { lastUpdated => 1148963673, }, - 'customText' => { - message => q|The user defined text to display if the user is logged in.|, - lastUpdated => 1148963673, - }, - 'hello.label' => { message => q|Internationalized welcome message.|, lastUpdated => 1148963673, }, 'customText' => { - message => q|The text supplied to the macro to display if the user is logged in.|, - lastUpdated => 1148963673, + message => q|The text supplied to the macro to display if the user is logged in. In general, this is used instead of the logout.label and logout.url variables.|, + lastUpdated => 1158340176, }, 'account.display.url' => { @@ -90,14 +85,14 @@ our $I18N = { 'login box body' => { message => q|
^L; or ^L(); - Login Box
-A small login form. This macro takes up to three parameters. The first is used to set the width of the login box: ^L(20);. The second sets the message displayed after the user is logged in: ^L(20,"Hi ^a(^@;);. Click %here% if you wanna log out!");. Text between percent signs (%) is replaced by a link to the logout operation. The third parameter is the ID of a template in the Macro/L_loginBox namespace to replace the default template. The variables below are
+A small login form. This macro takes up to three parameters. The first is used to set the width of text boxes for entering the username and password: ^L(20);. This width is scaled by 2/3 if the user's browser isn't IE due to differences in the way that different browsers draw the text boxes. The second sets the message displayed after the user is logged in: ^L(20,"Hi ^a(^@;);. Click %here% if you have to scoot!");. Text between percent signs (%) is replaced by a link to the logout operation. The third parameter is the ID of a template in the Macro/L_loginBox namespace to replace the default template. The variables below are
available for use in the template.
NOTE: The .loginBox style sheet class is tied to this macro.
|, - lastUpdated => 1148963753, + lastUpdated => 1158340077, }, '48' => { diff --git a/t/Macro/L_loginBox.t b/t/Macro/L_loginBox.t index c2f71dc8b..8ca5cf656 100644 --- a/t/Macro/L_loginBox.t +++ b/t/Macro/L_loginBox.t @@ -15,7 +15,6 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; use HTML::TokeParser; -use Data::Dumper; use Test::More; # increment this value for each test you create @@ -26,24 +25,24 @@ $session->asset($homeAsset); my ($versionTag, $template) = setupTest($session, $homeAsset); $session->user({userId=>1}); +##Replace the original ENV hash with one that will return a +##known user agent. Since it usually contains a reference to %ENV, +##you can't just modify that hash since it's protected +my $origEnv = $session->{_env}; +my %newEnvHash = ('HTTP_USER_AGENT', 'mozilla'); +$session->{_env}->{_env} = \%newEnvHash; + my $i18n = WebGUI::International->new($session,'Macro_L_loginBox'); -my @testSets = ( -); - -my $numTests = 0; -foreach my $testSet (@testSets) { ##Count dynamic tests - $numTests += 1 + (ref $testSet->{output} eq 'CODE'); -} - -$numTests += 1; #Module loading test -$numTests += 11; #Static tests +my $numTests = 1; #Module loading test +$numTests += 29; #Static tests plan tests => $numTests; my $macro = 'WebGUI::Macro::L_loginBox'; my $loaded = use_ok($macro); -use Data::Dumper; + +my $originalEncryptLogin = $session->setting->get('encryptLogin'); SKIP: { @@ -58,22 +57,120 @@ is($vars{'username.label'}, $i18n->get(50, 'WebGUI'), 'username.label'); is($vars{'hello.label'}, $i18n->get(48), 'hello.label'); is($vars{'logout.label'}, $i18n->get(49), 'logout.label'); is($vars{'user.isVisitor'}, 1, 'user.isVisitor when user is visitor'); -is($vars{'customText'}, '', 'no custom test sent'); +is($vars{'customText'}, '', 'no custom text sent'); is($vars{'logout.url'}, $session->url->page('op=auth;method=logout'), 'logout.url'); is($vars{'account.display.url'}, $session->url->page('op=auth;method=displayAccount'), 'account.display.url'); is($vars{'account.create.url'}, $session->url->page('op=auth;method=createAccount'), 'account.create.url'); ##The purpose of the test is to make sure that the variables are what they say -##they are. +##they are. So we will duplicate a bunch of Form code here. -#diag $output; -#diag Dumper \%vars; +is( + $vars{'password.form'}, + WebGUI::Form::password($session,{ + name=>"identifier", + size=>8, + extras=>'class="loginBoxField"' + }), + 'password.form' +); + +is( + $vars{'username.form'}, + WebGUI::Form::text($session,{ + name=>"username", + size=>8, + extras=>'class="loginBoxField"' + }), + 'username.form' +); + +is( + $vars{'form.login'}, + WebGUI::Form::submit($session,{ + value=>$i18n->get(52, 'WebGUI'), + extras=>'class="loginBoxButton"' + }), + 'form.login' +); + +is( + $vars{'form.header'}, + WebGUI::Form::formHeader($session,{action=>''}) + .WebGUI::Form::hidden($session,{ + name=>"op", + value=>"auth" + }) + .WebGUI::Form::hidden($session,{ + name=>"method", + value=>"login" + }), + 'form.login' +); is($vars{'form.footer'}, WebGUI::Form::formFooter($session), 'form.footer'); -foreach my $testSet (@testSets) { +##Now, test variations on user input, browser type and config settings + +##Set non-default boxSize + +$output = WebGUI::Macro::L_loginBox::process($session,24,'Log In',$template->getId); +%vars = simpleTextParser($output); + +is($vars{'customText'}, 'Log In', 'custom text sent'); +like($vars{'username.form'}, qr/size="16"/, 'boxSize set in username.form'); +like($vars{'password.form'}, qr/size="16"/, 'boxSize set in password.form'); + +##Change browser to be MSIE like and watch boxSize change +$newEnvHash{'HTTP_USER_AGENT'} = "msie"; + +$output = WebGUI::Macro::L_loginBox::process($session,24,'Log In',$template->getId); +%vars = simpleTextParser($output); +like($vars{'username.form'}, qr/size="24"/, 'boxSize set in username.form with MSIE browser'); +like($vars{'password.form'}, qr/size="24"/, 'boxSize set in password.form with MSIE browser'); + +##Templated customText tests + +$output = WebGUI::Macro::L_loginBox::process($session,'','%Log Out%',$template->getId); +%vars = simpleTextParser($output); +isnt($vars{'customText'}, '%Log Out%', 'custom text templated via % is processed'); +my ($url, $label) = simpleHTMLParser($vars{'customText'}); +is($label, "Log Out", "templated custom text, href label"); +is($url, $session->url->page("op=auth;method=logout"), "templated custom text, href url"); + +##Templated customText tests, 2 templates to process + +$output = WebGUI::Macro::L_loginBox::process($session,'','%Get Out% %Scoot%',$template->getId); +%vars = simpleTextParser($output); +my ($url1, $label1, $url2, $label2) = twoLinkParser($vars{'customText'}); +is($label1, "Get Out", "templated custom text, href label, 1 of 2 labels"); +is($url1, $session->url->page("op=auth;method=logout"), "templated custom text, href url, 1 of 2 links"); +is($label2, "Scoot", "templated custom text, href label, 2 links, 2 of 2 labels"); +is($url2, $session->url->page("op=auth;method=logout"), "templated custom text, href url, 2 of 2 links"); + +##Change settings to use encrypt login and verify which links use https. +$session->setting->set("encryptLogin", 1); + +$output = WebGUI::Macro::L_loginBox::process($session,'','',$template->getId); +%vars = simpleTextParser($output); +like($vars{'form.header'}, qr{https://}, 'form.header action set to use SSL by encryptLogin'); + +##Finally, a test that the default Template exists + +$output = WebGUI::Macro::L_loginBox::process($session,'','',''); +my $passwordLabel = $i18n->get(51, 'WebGUI'); +like($output, qr/$passwordLabel/, 'default template works'); + } +sub simpleTextParser { + my ($text) = @_; + + my %pairedData = (); + while($text =~ m/^\s*(\S+)\s*=\s*(.*?)-\+-/smgc) { + $pairedData{$1} = $2; + } + return %pairedData; } sub simpleHTMLParser { @@ -87,16 +184,22 @@ sub simpleHTMLParser { return ($url, $label); } -sub simpleTextParser { +sub twoLinkParser { my ($text) = @_; + my $p = HTML::TokeParser->new(\$text); - my %pairedData = (); - while($text =~ m/^\s*(\S+)\s*=\s*(.*?)-\+-/smgc) { - $pairedData{$1} = $2; - } - return %pairedData; + my $token1 = $p->get_tag("a"); + my $url1 = $token1->[1]{href} || "-"; + my $label1 = $p->get_trimmed_text("/a"); + + my $token2 = $p->get_tag("a"); + my $url2 = $token2->[1]{href} || "-"; + my $label2 = $p->get_trimmed_text("/a"); + + return ($url1, $label1, $url2, $label2); } + sub setupTest { my ($session, $defaultNode) = @_; $session->user({userId=>3}); @@ -131,4 +234,5 @@ END { ##Clean-up after yourself, always if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') { $versionTag->rollback; } + $session->setting->set("encryptLogin", $originalEncryptLogin); } diff --git a/t/Macro/RootTitle.t b/t/Macro/RootTitle.t index 545dc55c3..fa54a4a70 100644 --- a/t/Macro/RootTitle.t +++ b/t/Macro/RootTitle.t @@ -101,8 +101,25 @@ my %properties_X = ( ); my $assetX = $assetZ->addChild(\%properties_X, $properties_X{id}); +my %properties__ = ( + className => 'WebGUI::Asset::Snippet', + title => 'Asset _', + url => 'asset-_', + snippet => 'Asset _', + ownerUserId => 3, + groupIdView => 7, + groupIdEdit => 3, + # '1234567890123456789012' + id => 'Root_-----------------', +); +my $asset_ = $root->addChild(\%properties__, $properties__{id}); + $versionTag->commit; +my $origLineage = $asset_->getLineage; +my $newLineage = substr $origLineage, 0, length($origLineage)-1; +$session->db->write('update asset set lineage=? where assetId=?',[$newLineage, $asset_->getId]); + my @testSets = ( { comment => q!B's root = A!, @@ -129,9 +146,36 @@ my @testSets = ( asset => $assetY, title => $assetZ->getTitle, }, + { + comment => q!The super root's root is itself!, + asset => $root, + title => $root->getTitle, + }, + { + comment => q!Unable to find root!, + asset => $asset_, + title => '', + }, +); + +my $numTests = scalar @testSets; +$numTests += 2; + +plan tests => $numTests; + +my $macro = 'WebGUI::Macro::RootTitle'; +my $loaded = use_ok($macro); + +SKIP: { + +skip "Unable to load $macro", $numTests-1 unless $loaded; + +is( + WebGUI::Macro::RootTitle::process($session), + '', + q!Call with no default session asset returns ''!, ); -plan tests => scalar @testSets; foreach my $testSet (@testSets) { $session->asset($testSet->{asset}); @@ -139,7 +183,10 @@ foreach my $testSet (@testSets) { is($output, $testSet->{title}, $testSet->{comment}); } +} + END { ##Clean-up after yourself, always + $session->db->write('update asset set lineage=? where assetId=?',[$origLineage, $asset_->getId]); if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') { $versionTag->rollback; }