Fixed confirming user registration by staff

This commit is contained in:
Marcin Kurczewski 2014-05-12 20:10:19 +02:00
parent d8808df091
commit 4395087a7c
3 changed files with 46 additions and 3 deletions

View file

@ -10,7 +10,7 @@ class AcceptUserRegistrationJob extends AbstractJob
public function execute()
{
$user = $this->userRetriever->getRequiredArguments();
$user = $this->userRetriever->retrieve();
$user->setStaffConfirmed(true);
UserModel::save($user);
@ -18,6 +18,8 @@ class AcceptUserRegistrationJob extends AbstractJob
Logger::log('{user} confirmed {subject}\'s account', [
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
'subject' => TextHelper::reprUser($user)]);
return $user;
}
public function getRequiredArguments()

View file

@ -0,0 +1,22 @@
<?php
class AcceptUserRegistrationJobTest extends AbstractTest
{
public function testConfirming()
{
$this->grantAccess('acceptUserRegistration');
$user = $this->mockUser();
$this->assert->isFalse($user->isStaffConfirmed());
$user = $this->assert->doesNotThrow(function() use ($user)
{
return Api::run(
new AcceptUserRegistrationJob(),
[
JobArgs::ARG_USER_NAME => $user->getName(),
]);
});
$this->assert->isTrue($user->isStaffConfirmed());
}
}

View file

@ -78,7 +78,7 @@ class AuthTest extends AbstractTest
}, 'You are banned');
}
public function testStaffConfirmationEnabled()
public function testStaffConfirmationEnabledFail()
{
getConfig()->registration->staffActivation = true;
getConfig()->registration->needEmailForRegistering = false;
@ -93,7 +93,24 @@ class AuthTest extends AbstractTest
}, 'staff hasn\'t confirmed');
}
public function testStaffConfirmationDisabled()
public function testStaffConfirmationEnabledPass()
{
getConfig()->registration->staffActivation = true;
getConfig()->registration->needEmailForRegistering = false;
$user = $this->prepareValidUser();
$user->setStaffConfirmed(true);
UserModel::save($user);
$this->assert->doesNotThrow(function()
{
Auth::login('existing', 'bleee', false);
});
$this->assert->isTrue(Auth::isLoggedIn());
}
public function testStaffConfirmationDisabledPass()
{
getConfig()->registration->staffActivation = false;
getConfig()->registration->needEmailForRegistering = false;
@ -106,6 +123,8 @@ class AuthTest extends AbstractTest
{
Auth::login('existing', 'bleee', false);
});
$this->assert->isTrue(Auth::isLoggedIn());
}
public function testMailConfirmationEnabledFail1()