From e891410075b38158c3ae2df78cb34aa1afe1d9f0 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Tue, 11 May 2010 16:05:02 -0500 Subject: [PATCH] tests and such --- lib/WebGUI/Asset/EMSSubmission.pm | 1 + lib/WebGUI/Form/ButtonGroup.pm | 106 ++++++++++++++++++++++++++++++ lib/WebGUI/Pluggable.pm | 6 ++ lib/WebGUI/Session/Style.pm | 4 +- t/Form/ButtonGroup.t | 86 ++++++++++++++++++++++++ t/Session/Cache.t | 40 +++++++++++ t/tests/Test/WebGUI/Asset.pm | 14 +++- 7 files changed, 254 insertions(+), 3 deletions(-) create mode 100644 lib/WebGUI/Form/ButtonGroup.pm create mode 100644 t/Form/ButtonGroup.t create mode 100644 t/Session/Cache.t diff --git a/lib/WebGUI/Asset/EMSSubmission.pm b/lib/WebGUI/Asset/EMSSubmission.pm index a1387917b..985a72b89 100644 --- a/lib/WebGUI/Asset/EMSSubmission.pm +++ b/lib/WebGUI/Asset/EMSSubmission.pm @@ -142,6 +142,7 @@ property ticketId => ( with 'WebGUI::Role::Asset::Comments'; use Tie::IxHash; +use base qw(WebGUI::Asset); use WebGUI::Utility; use WebGUI::Inbox; diff --git a/lib/WebGUI/Form/ButtonGroup.pm b/lib/WebGUI/Form/ButtonGroup.pm new file mode 100644 index 000000000..f4395ef15 --- /dev/null +++ b/lib/WebGUI/Form/ButtonGroup.pm @@ -0,0 +1,106 @@ +package WebGUI::Form::ButtonGroup; + +=head1 LEGAL + + ------------------------------------------------------------------- + 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 + ------------------------------------------------------------------- + +=cut + +use strict; +use base 'WebGUI::Form::Control'; +use WebGUI::International; +use WebGUI::Pluggable; + +=head1 NAME + +Package WebGUI::Form::ButtonGroup + +=head1 DESCRIPTION + +Creates a series of buttons + +=head1 SEE ALSO + +This is a subclass of WebGUI::Form::Control. + +=head1 METHODS + +The following methods are specifically available from this class. Check the superclass for additional methods. + +=cut + +#------------------------------------------------------------------- + +=head2 definition ( [ additionalTerms ] ) + +See the super class for additional details. + +=head3 additionalTerms + +The following additional parameters have been added via this sub class. + +=head4 buttons + +The buttons in this button group + +=cut + +sub definition { + my $class = shift; + my $session = shift; + my $definition = shift || []; + push @{$definition}, { + buttons => { + defaultValue=>[], + }, + }; + return $class->SUPER::definition($session, $definition); +} + +#------------------------------------------------------------------- + +=head2 addButton ( type, params ) + +Add a new button to the button group. + +=cut + +sub addButton { + my ( $self, $type, $params ) = @_; + my $buttons = $self->get('buttons'); + + my $button = WebGUI::Pluggable::instanciate("WebGUI::Form::".ucfirst($type), "new", [$self->session, $params]); + + push @{$buttons}, $button; + $self->set('buttons', $buttons); + return $button; +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a button group + +=cut + +sub toHtml { + my $self = shift; + my $html = ''; + + for my $button ( @{ $self->get('buttons') } ) { + $html .= $button->toHtml; # Inline as toHtml + } + return $html; +} + +1; +#vim:ft=perl diff --git a/lib/WebGUI/Pluggable.pm b/lib/WebGUI/Pluggable.pm index 80a95df9c..b338c3c66 100644 --- a/lib/WebGUI/Pluggable.pm +++ b/lib/WebGUI/Pluggable.pm @@ -235,9 +235,15 @@ sub load { croak $moduleError{$module}; } + # Check if we already have it # Try to load the module my $modulePath = $module . ".pm"; $modulePath =~ s{::|'}{/}g; + + if ( $INC{$modulePath} ) { + return 1; + } + if (eval { require $modulePath; 1 }) { return 1; } diff --git a/lib/WebGUI/Session/Style.pm b/lib/WebGUI/Session/Style.pm index 7258c4016..fbce50be2 100644 --- a/lib/WebGUI/Session/Style.pm +++ b/lib/WebGUI/Session/Style.pm @@ -253,6 +253,7 @@ if ($self->session->user->isRegistered || $self->session->setting->get("preventP # TODO: Figure out if user is still in the admin console + $var{'head.tags'} .= ' ADMINJS } + $var{'head.tags'} .= ''; # Removing the newlines will probably annoy people. # Perhaps turn it off under debug mode? diff --git a/t/Form/ButtonGroup.t b/t/Form/ButtonGroup.t new file mode 100644 index 000000000..960a29daf --- /dev/null +++ b/t/Form/ButtonGroup.t @@ -0,0 +1,86 @@ +# vim:syntax=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 +#------------------------------------------------------------------ + +# Test the ButtonGroup form element +# +# + +use FindBin; +use strict; +use lib "$FindBin::Bin/../lib"; +use Test::More; +use Test::Deep; +use WebGUI::Test; # Must use this before any other WebGUI modules +use WebGUI::Session; + +#---------------------------------------------------------------------------- +# Init +my $session = WebGUI::Test->session; + + +#---------------------------------------------------------------------------- +# Tests + +plan tests => 6; # Increment this number for each test you create + +#---------------------------------------------------------------------------- +# put your tests here + +use_ok( 'WebGUI::Form::ButtonGroup' ); + +#---------------------------------------------------------------------------- +# buttons as params + +my $bOne = WebGUI::Form::TestButton->new( $session, { name => "one" } ); +my $bTwo = WebGUI::Form::TestButton->new( $session, { name => "two" } ); +my $bg = WebGUI::Form::ButtonGroup->new( $session, { + buttons => [ $bOne, $bTwo ], +} ); + +cmp_deeply( + $bg->get('buttons'), + [ $bOne, $bTwo ], + "buttons is arrayref of objects", +); + +#---------------------------------------------------------------------------- +# addButton + +my $bThree = $bg->addButton( "TestButton", { name => "three" } ); +isa_ok( $bThree, 'WebGUI::Form::TestButton', 'addButton returns object' ); +is( $bThree->get('name'), "three", 'addButton passes params to constructor' ); +cmp_deeply( + $bg->get('buttons'), + [ $bOne, $bTwo, $bThree ], + "addButton adds button to list", +); + +#---------------------------------------------------------------------------- +# toHtml + +my $html = $bg->toHtml; +like( $html, qr/onetwothree/, 'buttons rendered without extras between or around' ); + + +#---------------------------------------------------------------------------- +# Test collateral + +package WebGUI::Form::TestButton; +# Fool WebGUI::Pluggable to prevent complaints +BEGIN { $INC{'WebGUI/Form/TestButton.pm'} = __FILE__ } + +use base 'WebGUI::Form::Control'; + +sub toHtml { + return $_[0]->get('name'); +} + +#vim:ft=perl diff --git a/t/Session/Cache.t b/t/Session/Cache.t new file mode 100644 index 000000000..d1696f88d --- /dev/null +++ b/t/Session/Cache.t @@ -0,0 +1,40 @@ +# vim:syntax=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 +#------------------------------------------------------------------ + +# Test the CHI cache +# +# + +use FindBin; +use strict; +use lib "$FindBin::Bin/../lib"; +use Test::More; +use WebGUI::Test; # Must use this before any other WebGUI modules +use WebGUI::Session; + +#---------------------------------------------------------------------------- +# Init +my $session = WebGUI::Test->session; + + +#---------------------------------------------------------------------------- +# Tests + +plan tests => 1; # Increment this number for each test you create + +my $cache = $session->cache; +isa_ok( $cache, "CHI::Driver" ); + +#---------------------------------------------------------------------------- +# put your tests here + + +#vim:ft=perl diff --git a/t/tests/Test/WebGUI/Asset.pm b/t/tests/Test/WebGUI/Asset.pm index 0343bb189..9c23647cc 100644 --- a/t/tests/Test/WebGUI/Asset.pm +++ b/t/tests/Test/WebGUI/Asset.pm @@ -340,15 +340,26 @@ sub addRevision : Tests { $newRevision->purgeRevision; } +sub getEditForm : Tests { + note "getEditForm"; + my ( $test ) = @_; + my $session = $test->session; + my ( $tag, $asset, @parents ) = $test->getAnchoredAsset(); + +} + sub www_editSave : Tests { note "www_editSave"; my ( $test ) = @_; my $session = $test->session; my ( $tag, $asset, @parents ) = $test->getAnchoredAsset(); + my $oldGroupId = $asset->groupIdEdit; + $asset->groupIdEdit( 7 ); # Everybody! Everybody! + $tag->setWorking; $session->request->setup_body({ title => "Newly Saved Title", - } ); + }); $asset->www_editSave; # Get the newly-created revision of the asset @@ -356,6 +367,7 @@ sub www_editSave : Tests { ok( $newRevision->tagId, 'new revision has a tag' ); is( $newRevision->tagId, $tag->getId, 'new revision tagId is current working tag' ); + $asset->groupIdEdit( $oldGroupId ); } 1;