szurubooru/tests/Tests/JobTests/EditUserEmailJobTest.php

109 lines
3 KiB
PHP
Raw Permalink Normal View History

<?php
class EditUserEmailJobTest extends AbstractTest
{
public function testNoConfirmation()
{
2014-05-15 10:32:53 +02:00
Core::getConfig()->registration->needEmailForRegistering = false;
Mailer::mockSending();
$this->assert->areEqual(0, Mailer::getMailCounter());
Core::getConfig()->privileges->editUserEmailNoConfirm = 'anonymous';
$this->grantAccess('editUserEmail');
$user = $this->userMocker->mockSingle();
$user = $this->assert->doesNotThrow(function() use ($user)
{
return Api::run(
new EditUserEmailJob(),
[
JobArgs::ARG_USER_NAME => $user->getName(),
JobArgs::ARG_NEW_EMAIL => 'xena@other-side.gr',
]);
});
2014-05-14 18:07:31 +02:00
$this->assert->isNull($user->getUnconfirmedEmail());
$this->assert->areEqual('xena@other-side.gr', $user->getConfirmedEmail());
$this->assert->areEqual(0, Mailer::getMailCounter());
}
public function testConfirmation()
{
2014-05-15 10:32:53 +02:00
Core::getConfig()->registration->needEmailForRegistering = false;
Mailer::mockSending();
$this->assert->areEqual(0, Mailer::getMailCounter());
Core::getConfig()->privileges->editUserEmailNoConfirm = 'admin';
$this->grantAccess('editUserEmail');
$user = $this->userMocker->mockSingle();
$user = $this->assert->doesNotThrow(function() use ($user)
{
return Api::run(
new EditUserEmailJob(),
[
JobArgs::ARG_USER_NAME => $user->getName(),
JobArgs::ARG_NEW_EMAIL => 'xena@other-side.gr',
]);
});
$this->assert->areEqual('xena@other-side.gr', $user->getUnconfirmedEmail());
2014-05-14 18:07:31 +02:00
$this->assert->isNull($user->getConfirmedEmail());
$this->assert->areEqual(1, Mailer::getMailCounter());
}
public function testInvalidEmail()
{
2014-05-15 10:32:53 +02:00
Core::getConfig()->registration->needEmailForRegistering = false;
Mailer::mockSending();
Core::getConfig()->privileges->editUserEmailNoConfirm = 'nobody';
$this->grantAccess('editUserEmail');
$user = $this->userMocker->mockSingle();
$this->assert->throws(function() use ($user)
{
Api::run(
new EditUserEmailJob(),
[
JobArgs::ARG_USER_NAME => $user->getName(),
JobArgs::ARG_NEW_EMAIL => 'hrmfbpdvpds@brtedf',
]);
}, 'E-mail address appears to be invalid');
2014-05-13 00:02:25 +02:00
}
public function testChangingToExistingDenial()
{
2014-05-15 10:32:53 +02:00
Core::getConfig()->registration->needEmailForRegistering = false;
2014-05-13 00:02:25 +02:00
Mailer::mockSending();
$this->assert->areEqual(0, Mailer::getMailCounter());
Core::getConfig()->privileges->editUserEmailNoConfirm = 'anonymous';
$this->grantAccess('editUserEmail');
2014-05-13 00:02:25 +02:00
list ($user, $otherUser)
= $this->userMocker->mockMultiple(2);
2014-05-13 00:02:25 +02:00
$otherUser->setUnconfirmedEmail('super@mario.plumbing');
UserModel::save($otherUser);
2014-05-13 00:02:25 +02:00
$this->assert->throws(function() use ($user, $otherUser)
{
Api::run(
new EditUserEmailJob(),
[
JobArgs::ARG_USER_NAME => $user->getName(),
JobArgs::ARG_NEW_EMAIL => $otherUser->getUnconfirmedEmail(),
]);
}, 'User with this e-mail is already registered');
2014-05-14 18:07:31 +02:00
$this->assert->isNull($user->getUnconfirmedEmail());
$this->assert->isNull($user->getConfirmedEmail());
2014-05-13 00:02:25 +02:00
$this->assert->areEqual(0, Mailer::getMailCounter());
}
}