szurubooru/tests/Tests/JobTests/EditUserAccessRankJobTest.php
Marcin Kurczewski e59b7e8b7b Refactored privilege system a bit
- Jobs specify main privilege and sub privileges separately
  Rationale: increase maintenance, restrict what can be done runtime
- Renamed ChangeUser* to EditUser* (consistency with EditPost*)
- Simplified enum names and configuration reading
- IJob interface members must be explicitly implemented
  Rationale: reduce chances of forgetting something, or typos in
  inherited method names
- Invalid privileges names in configuration yield exceptions
2014-05-18 21:59:56 +02:00

63 lines
1.7 KiB
PHP

<?php
class EditUserAccessRankJobTest extends AbstractTest
{
public function testEditing()
{
$this->grantAccess('editUserAccessRank');
$user = $this->userMocker->mockSingle();
$this->assert->areEqual(AccessRank::Registered, $user->getAccessRank()->toInteger());
$user = $this->assert->doesNotThrow(function() use ($user)
{
return Api::run(
new EditUserAccessRankJob(),
[
JobArgs::ARG_USER_NAME => $user->getName(),
JobArgs::ARG_NEW_ACCESS_RANK => AccessRank::PowerUser,
]);
});
$this->assert->areEqual(AccessRank::PowerUser, $user->getAccessRank()->toInteger());
}
public function testSettingToNobodyDenial()
{
$this->grantAccess('editUserAccessRank');
$user = $this->userMocker->mockSingle();
$this->assert->areEqual(AccessRank::Registered, $user->getAccessRank()->toInteger());
$this->assert->throws(function() use ($user)
{
Api::run(
new EditUserAccessRankJob(),
[
JobArgs::ARG_USER_NAME => $user->getName(),
JobArgs::ARG_NEW_ACCESS_RANK => AccessRank::Nobody,
]);
}, 'Cannot set special access rank');
}
public function testHigherThanMyselfDenial()
{
Core::getConfig()->privileges->editUserAccessRank = 'power-user';
Access::init();
$user = $this->userMocker->mockSingle();
$user->setAccessRank(new AccessRank(AccessRank::PowerUser));
UserModel::save($user);
$this->assert->areEqual(AccessRank::PowerUser, $user->getAccessRank()->toInteger());
$this->assert->throws(function() use ($user)
{
Api::run(
new EditUserAccessRankJob(),
[
JobArgs::ARG_USER_NAME => $user->getName(),
JobArgs::ARG_NEW_ACCESS_RANK => AccessRank::Admin,
]);
}, 'Insufficient privileges');
}
}