diff --git a/UnitTestContrib/test/unit/RegisterTests.pm b/UnitTestContrib/test/unit/RegisterTests.pm index efe57179a2..e0b2507c61 100644 --- a/UnitTestContrib/test/unit/RegisterTests.pm +++ b/UnitTestContrib/test/unit/RegisterTests.pm @@ -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; diff --git a/core/lib/Foswiki/UI/Register.pm b/core/lib/Foswiki/UI/Register.pm index 65fa45a07f..00d4757cf6 100755 --- a/core/lib/Foswiki/UI/Register.pm +++ b/core/lib/Foswiki/UI/Register.pm @@ -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 .= '
' . $e->stringify($session) . "
\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 .= '
' . $e->stringify($session) . "
\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 );