tests and such

This commit is contained in:
Doug Bell 2010-05-11 16:05:02 -05:00
parent 5c2581850f
commit e891410075
7 changed files with 254 additions and 3 deletions

View file

@ -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;

View file

@ -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

View file

@ -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;
}

View file

@ -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'} .= '<script type="text/javascript">';
if ( $session->asset ) {
my $assetDef = {
assetId => $session->asset->getId,
@ -261,13 +262,12 @@ if ($self->session->user->isRegistered || $self->session->setting->get("preventP
icon => $session->asset->getIcon(1),
};
$var{'head.tags'} .= sprintf <<'ADMINJS', JSON->new->encode( $assetDef );
<script type="text/javascript">
if ( window.parent && window.parent.admin ) {
window.parent.admin.navigate( %s );
}
</script>
ADMINJS
}
$var{'head.tags'} .= '</script>';
# Removing the newlines will probably annoy people.
# Perhaps turn it off under debug mode?

86
t/Form/ButtonGroup.t Normal file
View file

@ -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

40
t/Session/Cache.t Normal file
View file

@ -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

View file

@ -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;