merging 8374
This commit is contained in:
parent
c9946708b5
commit
2f8869292f
4 changed files with 140 additions and 5 deletions
|
|
@ -228,6 +228,10 @@ form.
|
|||
|
||||
=cut
|
||||
|
||||
# FIXME This would be better if it returned an OBJECT not the HTML
|
||||
# TODO add a toHtml sub to take the place of this sub and a getFormControl
|
||||
# And refactor to not require all these arguments HERE but rather in the
|
||||
# constructor or something...
|
||||
sub formField {
|
||||
my $self = shift;
|
||||
my $properties = $self->formProperties(shift);
|
||||
|
|
@ -245,9 +249,8 @@ sub formField {
|
|||
# start with specified (or current) user's data. previous data needed by some form types as well (file).
|
||||
$properties->{value} = $u->profileField($self->getId);
|
||||
# use submitted data if it exists
|
||||
# FIXME Is $properties->{name} or $self->getId the correct way to get the form name?
|
||||
if (defined $self->session->form->process($properties->{name}, $self->get("fieldType"))) {
|
||||
$properties->{value} = $self->session->form->process($self->getId,$self->get("fieldType"), undef, $properties);
|
||||
if ($self->formProcess($u) != $self->get('dataDefault')) {
|
||||
$properties->{value} = $self->formProcess($u);
|
||||
}
|
||||
# fall back on default
|
||||
if(!defined $properties->{value}) {
|
||||
|
|
@ -768,6 +771,7 @@ sub setCategory {
|
|||
$self->_reorderFields($categoryId);
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ use strict;
|
|||
use WebGUI::Cache;
|
||||
use WebGUI::Group;
|
||||
use WebGUI::DatabaseLink;
|
||||
use WebGUI::Exception;
|
||||
use WebGUI::Utility;
|
||||
use WebGUI::Operation::Shared;
|
||||
|
||||
|
|
@ -61,6 +62,9 @@ These methods are available from this class:
|
|||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# TODO This stays like this until we can break API, just in case somebody
|
||||
# doesn't realize that _ means private.
|
||||
# After API unfreeze, put this in the WebGUI::User->create routine
|
||||
sub _create {
|
||||
my $session = shift;
|
||||
my $userId = shift || $session->id->generate();
|
||||
|
|
@ -157,6 +161,31 @@ sub authMethod {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 create ( session, [userId] )
|
||||
|
||||
Create a new user. C<userId> is an option user ID to give the new user.
|
||||
Returns the newly created WebGUI::User object.
|
||||
|
||||
=cut
|
||||
|
||||
sub create {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $userId = shift;
|
||||
|
||||
if ( !ref $session || !$session->isa( 'WebGUI::Session' ) ) {
|
||||
WebGUI::Error::InvalidObject->throw(
|
||||
expected => "WebGUI::Session",
|
||||
got => (ref $session),
|
||||
error => q{Must provide a session variable},
|
||||
);
|
||||
}
|
||||
|
||||
return WebGUI::User->new( $session, "new", $userId );
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 cache ( )
|
||||
|
||||
Saves the user object into the cache.
|
||||
|
|
|
|||
84
t/ProfileField.t
Normal file
84
t/ProfileField.t
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
# vim:syntax=perl
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2008 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
|
||||
#------------------------------------------------------------------
|
||||
|
||||
# This test the WebGUI::ProfileField object
|
||||
#
|
||||
#
|
||||
|
||||
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;
|
||||
|
||||
my $newUser = WebGUI::User->create( $session );
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 17; # Increment this number for each test you create
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test the creation of ProfileField
|
||||
use_ok( 'WebGUI::ProfileField' );
|
||||
|
||||
is( WebGUI::ProfileField->new( $session ), undef, 'new() returns undef with no id' );
|
||||
is( WebGUI::ProfileField->new( $session, 'op'), undef, 'new() returns undef with reserved field ID "op"' );
|
||||
is( WebGUI::ProfileField->new( $session, 'func' ), undef, 'new() returns undef with reserved field ID "func"' );
|
||||
is( WebGUI::ProfileField->new( $session, 'fjnwsifkmamdiwjen' ), undef, 'new() returns undef with field ID not found' );
|
||||
my $aliasField;
|
||||
ok( $aliasField = WebGUI::ProfileField->new( $session, 'alias' ), 'field "alias" instantiated' );
|
||||
isa_ok( $aliasField, 'WebGUI::ProfileField' );
|
||||
|
||||
my $uilevelField;
|
||||
ok( $uilevelField = WebGUI::ProfileField->new( $session, 'uiLevel' ), 'field "uiLevel instantiated' );
|
||||
isa_ok( $uilevelField, 'WebGUI::ProfileField' );
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test the formField method
|
||||
|
||||
my $ff = undef;
|
||||
my $ffvalue = undef;
|
||||
ok( $ff = $aliasField->formField, 'formField method returns something, alias field, session user' );
|
||||
$ffvalue = $session->user->profileField('alias');
|
||||
like( $ff, qr/$ffvalue/, 'html returned contains value, alias field, session user' );
|
||||
|
||||
$ff = undef;
|
||||
$ffvalue = undef;
|
||||
ok( $ff = $uilevelField->formField, 'formField method returns something, uiLevel field, session user' );
|
||||
$ffvalue = $session->user->profileField('uiLevel');
|
||||
like( $ff, qr/value="$ffvalue"[^>]+selected/, 'html returned contains value, uiLevel field, session user' );
|
||||
|
||||
# Test with a newly created user that has no profile fields filled in
|
||||
$ff = undef;
|
||||
$ffvalue = undef;
|
||||
ok( $ff = $aliasField->formField(undef, undef, $newUser), 'formField method returns something, alias field, defaulted user' );
|
||||
my $ffvalue = $newUser->profileField('alias');
|
||||
like( $ff, qr/$ffvalue/, 'html returned contains value, alias field, defaulted user' );
|
||||
|
||||
$ff = undef;
|
||||
$ffvalue = undef;
|
||||
ok( $ff = $uilevelField->formField(undef, undef, $newUser), 'formField method returns something, uiLevel field, defaulted user' );
|
||||
my $ffvalue = $newUser->profileField('uiLevel');
|
||||
like( $ff, qr/$ffvalue/, 'html returned contains value, uiLevel field, defaulted user' );
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Cleanup
|
||||
END {
|
||||
$newUser->delete;
|
||||
}
|
||||
|
||||
|
||||
22
t/User.t
22
t/User.t
|
|
@ -20,7 +20,7 @@ use WebGUI::Cache;
|
|||
use WebGUI::User;
|
||||
use WebGUI::ProfileField;
|
||||
|
||||
use Test::More tests => 140; # increment this value for each test you create
|
||||
use Test::More tests => 143; # increment this value for each test you create
|
||||
use Test::Deep;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
|
@ -620,8 +620,26 @@ cmp_bag(
|
|||
'getGroupIdsRecursive returns the correct set of groups, ignoring expire date and not duplicating groups'
|
||||
);
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test the new create() method
|
||||
SKIP: {
|
||||
eval{ require Test::Exception; import Test::Exception };
|
||||
skip 1, 'Test::Exception not found' if $@;
|
||||
|
||||
throws_ok( sub{ WebGUI::User->create }, 'WebGUI::Error::InvalidObject',
|
||||
'create() throws if no session passed'
|
||||
);
|
||||
};
|
||||
|
||||
ok( my $newCreateUser = WebGUI::User->create( $session ),
|
||||
'create() returns something'
|
||||
);
|
||||
isa_ok( $newCreateUser, 'WebGUI::User', 'create() returns a WebGUI::User' );
|
||||
|
||||
|
||||
END {
|
||||
foreach my $account ($user, $dude, $buster, $buster3, $neighbor, $friend, $newFish) {
|
||||
foreach my $account ($user, $dude, $buster, $buster3, $neighbor, $friend, $newFish, $newCreateUser) {
|
||||
(defined $account and ref $account eq 'WebGUI::User') and $account->delete;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue