[core] UserClass tests
This commit is contained in:
parent
00b96c313f
commit
dd6c47484d
2 changed files with 39 additions and 1 deletions
38
core/tests/UserClassTest.php
Normal file
38
core/tests/UserClassTest.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shimmie2;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
require_once "core/userclass.php";
|
||||
|
||||
class UserClassTest extends ShimmiePHPUnitTestCase
|
||||
{
|
||||
public function test_new_class(): void
|
||||
{
|
||||
$cls = new UserClass("user2", "user", [
|
||||
Permissions::CREATE_COMMENT => true,
|
||||
Permissions::BIG_SEARCH => false,
|
||||
]);
|
||||
$this->assertEquals("user2", $cls->name);
|
||||
$this->assertTrue($cls->can(Permissions::CREATE_COMMENT));
|
||||
$this->assertFalse($cls->can(Permissions::BIG_SEARCH));
|
||||
}
|
||||
|
||||
public function test_not_found(): void
|
||||
{
|
||||
$cls = UserClass::$known_classes['user'];
|
||||
$this->assertException(ServerError::class, function () use ($cls) {
|
||||
$cls->can("not_found");
|
||||
});
|
||||
}
|
||||
|
||||
public function test_permissions(): void
|
||||
{
|
||||
$cls = UserClass::$known_classes['user'];
|
||||
$ps = $cls->permissions();
|
||||
$this->assertContains(Permissions::CREATE_COMMENT, $ps);
|
||||
}
|
||||
}
|
|
@ -44,7 +44,6 @@ class UserClass
|
|||
#[Field(type: "[Permission!]!")]
|
||||
public function permissions(): array
|
||||
{
|
||||
global $_all_false;
|
||||
$perms = [];
|
||||
foreach ((new \ReflectionClass(Permissions::class))->getConstants() as $k => $v) {
|
||||
if ($this->can($v)) {
|
||||
|
@ -90,6 +89,7 @@ foreach ((new \ReflectionClass(Permissions::class))->getConstants() as $k => $v)
|
|||
$_all_true[Permissions::HELLBANNED] = false;
|
||||
new UserClass("base", null, $_all_false);
|
||||
new UserClass("admin", null, $_all_true);
|
||||
unset($_all_true);
|
||||
unset($_all_false);
|
||||
|
||||
// Ghost users can't do anything
|
||||
|
|
Reference in a new issue