2014-05-13 00:02:25 +02:00
|
|
|
<?php
|
|
|
|
class EditUserNameJobTest extends AbstractTest
|
|
|
|
{
|
|
|
|
public function testEditing()
|
|
|
|
{
|
|
|
|
$this->grantAccess('changeUserName');
|
2014-05-13 21:08:07 +02:00
|
|
|
$user = $this->userMocker->mockSingle();
|
2014-05-13 00:02:25 +02:00
|
|
|
|
|
|
|
$newName = uniqid();
|
|
|
|
|
|
|
|
$this->assert->areNotEqual($newName, $user->getName());
|
|
|
|
|
|
|
|
$user = $this->assert->doesNotThrow(function() use ($user, $newName)
|
|
|
|
{
|
|
|
|
return Api::run(
|
|
|
|
new EditUserNameJob(),
|
|
|
|
[
|
|
|
|
JobArgs::ARG_USER_NAME => $user->getName(),
|
|
|
|
JobArgs::ARG_NEW_USER_NAME => $newName,
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->assert->areEqual($newName, $user->getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testTooShortName()
|
|
|
|
{
|
|
|
|
$this->grantAccess('changeUserName');
|
2014-05-13 21:08:07 +02:00
|
|
|
$user = $this->userMocker->mockSingle();
|
2014-05-13 00:02:25 +02:00
|
|
|
|
2014-05-15 10:32:53 +02:00
|
|
|
$newName = str_repeat('a', Core::getConfig()->registration->userNameMinLength - 1);
|
2014-05-13 00:02:25 +02:00
|
|
|
|
|
|
|
$this->assert->throws(function() use ($user, $newName)
|
|
|
|
{
|
|
|
|
Api::run(
|
|
|
|
new EditUserNameJob(),
|
|
|
|
[
|
|
|
|
JobArgs::ARG_USER_NAME => $user->getName(),
|
|
|
|
JobArgs::ARG_NEW_USER_NAME => $newName,
|
|
|
|
]);
|
|
|
|
}, 'user name must have at least');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testTooLongName()
|
|
|
|
{
|
|
|
|
$this->grantAccess('changeUserName');
|
2014-05-13 21:08:07 +02:00
|
|
|
$user = $this->userMocker->mockSingle();
|
2014-05-13 00:02:25 +02:00
|
|
|
|
2014-05-15 10:32:53 +02:00
|
|
|
$newName = str_repeat('a', Core::getConfig()->registration->userNameMaxLength + 1);
|
2014-05-13 00:02:25 +02:00
|
|
|
|
|
|
|
$this->assert->throws(function() use ($user, $newName)
|
|
|
|
{
|
|
|
|
Api::run(
|
|
|
|
new EditUserNameJob(),
|
|
|
|
[
|
|
|
|
JobArgs::ARG_USER_NAME => $user->getName(),
|
|
|
|
JobArgs::ARG_NEW_USER_NAME => $newName,
|
|
|
|
]);
|
|
|
|
}, 'user name must have at most');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvalidName()
|
|
|
|
{
|
|
|
|
$this->grantAccess('changeUserName');
|
2014-05-13 21:08:07 +02:00
|
|
|
$user = $this->userMocker->mockSingle();
|
2014-05-13 00:02:25 +02:00
|
|
|
|
|
|
|
$newName = 'ble/ble';
|
|
|
|
|
|
|
|
$this->assert->throws(function() use ($user, $newName)
|
|
|
|
{
|
|
|
|
Api::run(
|
|
|
|
new EditUserNameJob(),
|
|
|
|
[
|
|
|
|
JobArgs::ARG_USER_NAME => $user->getName(),
|
|
|
|
JobArgs::ARG_NEW_USER_NAME => $newName,
|
|
|
|
]);
|
|
|
|
}, 'user name contains invalid characters');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testChangingToExistingDenial()
|
|
|
|
{
|
|
|
|
$this->grantAccess('changeUserName');
|
2014-05-13 21:08:07 +02:00
|
|
|
list ($user, $otherUser)
|
|
|
|
= $this->userMocker->mockMultiple(2);
|
2014-05-13 00:02:25 +02:00
|
|
|
|
|
|
|
$newName = $otherUser->getName();
|
|
|
|
$this->assert->areNotEqual($newName, $user->getName());
|
|
|
|
|
|
|
|
$this->assert->throws(function() use ($user, $newName)
|
|
|
|
{
|
|
|
|
Api::run(
|
|
|
|
new EditUserNameJob(),
|
|
|
|
[
|
|
|
|
JobArgs::ARG_USER_NAME => $user->getName(),
|
|
|
|
JobArgs::ARG_NEW_USER_NAME => $newName,
|
|
|
|
]);
|
|
|
|
}, 'User with this name is already registered');
|
|
|
|
|
|
|
|
$this->assert->areNotEqual($newName, $user->getName());
|
|
|
|
}
|
|
|
|
}
|