Skip to content

Commit

Permalink
Item2191: move the test for the required fields to before where we as…
Browse files Browse the repository at this point in the history
…sume they exist, and then fix the error logging code to not crash if there is one missing. this coder should have been .........

git-svn-id: http://svn.foswiki.org/trunk@5225 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed Oct 7, 2009
1 parent f207dd2 commit f985c0f
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 11 deletions.
69 changes: 69 additions & 0 deletions UnitTestContrib/test/unit/RegisterTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2010,4 +2010,73 @@ sub verify_Default_NameFilter {

}

#in which a user correctly points out that the error checking is a bit minimal
sub verify_bulkRegister_Item2191 {
my $this = shift;

my $testReg = <<'EOM';
| Vorname | Nachname | Mailadresse | WikiName | LoginName | CustomFieldThis | SomeOtherRandomField | WhateverYouLike |
| Test | User | Martin.Cleaver@BCS.org.uk | TestBulkUser1 | a | A | B | C |
| Test | User2 | Martin.Cleaver@BCS.org.uk | TestBulkUser2 | b | A | B | C |
| Test | User3 | Martin.Cleaver@BCS.org.uk | TestBulkUser3 | c | A | B | C |
EOM

my $regTopic = 'UnprocessedRegistrations2';

my $logTopic = 'UnprocessedRegistrations2Log';
my $file =
$Foswiki::cfg{DataDir} . '/'
. $this->{test_web} . '/'
. $regTopic . '.txt';
my $fh = new FileHandle;

die "Can't write $file" unless ( $fh->open(">$file") );
print $fh $testReg;
$fh->close;

my $query = new Unit::Request(
{
'LogTopic' => [$logTopic],
'EmailUsersWithDetails' => ['0'],
'OverwriteHomeTopics' => ['1'],
}
);

$query->path_info("/$this->{test_web}/$regTopic");
$this->{session}->finish();
$this->{session} = new Foswiki( $Foswiki::cfg{SuperAdminGroup}, $query );
$this->{session}->net->setMailHandler( \&FoswikiFnTestCase::sentMail );
$this->{session}->{topicName} = $regTopic;
$this->{session}->{webName} = $this->{test_web};
try {
my ($text) = $this->capture( \&Foswiki::UI::Register::bulkRegister,
$this->{session} );

#TODO: um, really need to test what the output was, and
#TODO: test if a user was registered..
#$this->assert( '', $text);
#my $readMeta = Foswiki::Meta->load( $this->{session}, $this->{test_web}, 'TemporaryRegistrationTestWebRegistration/UnprocessedRegistrations2Log' );
#$this->assert( '', $readMeta->text());
}
catch Foswiki::OopsException with {
my $e = shift;
$this->assert( 0, $e->stringify() . " UNEXPECTED" );

}
catch Error::Simple with {
my $e = shift;
$this->assert( 0, $e->stringify );

}
catch Foswiki::AccessControlException with {
my $e = shift;
$this->assert( 0, $e->stringify );

}
otherwise {
$this->assert( 0, "expected an oops redirect" );
};
$this->assert_equals( 0, scalar(@FoswikiFnTestCase::mails) );
}

1;
22 changes: 11 additions & 11 deletions core/lib/Foswiki/UI/Register.pm
Original file line number Diff line number Diff line change
Expand Up @@ -233,30 +233,30 @@ sub _registerSingleBulkUser {

my $log = "---++ Registering $row->{WikiName}\n";

try {
_validateRegistration( $session, $row, 0 );
}
catch Foswiki::OopsException with {
my $e = shift;
$log .= '<blockquote>' . $e->stringify($session) . "</blockquote>\n";
return $log . "$b1 Registration failed\n";
};

#-- call to the registrationHandler (to amend fields) should
# really happen in here.

#-- Ensure every required field exists
# NB. LoginName is OPTIONAL
my @requiredFields = qw(WikiName FirstName LastName);
my @requiredFields = qw(WikiName FirstName LastName Email);
if ( _missingElements( $fieldNames, \@requiredFields ) ) {
$log .=
$b1
. join( ' ', @{ $settings->{fieldNames} } )
. join( ' ', map {$_.' : '.$row->{$_}} @$fieldNames )
. ' does not contain the full set of required fields '
. join( ' ', @requiredFields ) . "\n";
return ( undef, $log );
}

try {
_validateRegistration( $session, $row, 0 );
}
catch Foswiki::OopsException with {
my $e = shift;
$log .= '<blockquote>' . $e->stringify($session) . "</blockquote>\n";
return $log . "$b1 Registration failed\n";
};

#-- Generation of the page is done from the {form} subhash,
# so align the two
$row->{form} = _makeFormFieldOrderMatch( $fieldNames, $row );
Expand Down

0 comments on commit f985c0f

Please sign in to comment.