1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace Tests\Unit;
- if (!defined('INSTALLDIR')) {
- define('INSTALLDIR', dirname(dirname(__DIR__)));
- }
- if (!defined('PUBLICDIR')) {
- define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
- }
- if (!defined('GNUSOCIAL')) {
- define('GNUSOCIAL', true);
- }
- if (!defined('STATUSNET')) {
- define('STATUSNET', true);
- }
- use Exception;
- use PHPUnit\Framework\TestCase;
- use User;
- require_once INSTALLDIR . '/lib/util/common.php';
- final class UserRightsTest extends TestCase
- {
- protected $user;
- protected function setUp(): void
- {
- $user = User::getKV('nickname', 'userrightstestuser');
- if ($user) {
-
- $profile = $user->getProfile();
- $user->delete();
- $profile->delete();
- }
- $this->user = User::register(['nickname' => 'userrightstestuser']);
- if (!$this->user) {
- throw new Exception("Couldn't register userrightstestuser");
- }
- }
- protected function tearDown(): void
- {
- if ($this->user) {
- $profile = $this->user->getProfile();
- $this->user->delete();
- $profile->delete();
- }
- }
- public function testInvalidRole()
- {
- static::assertFalse($this->user->hasRole('invalidrole'));
- }
- public function standardRoles()
- {
- return [['admin'],
- ['moderator'],];
- }
-
- public function testUngrantedRole($role)
- {
- static::assertFalse($this->user->hasRole($role));
- }
-
- public function testGrantedRole($role)
- {
- $this->user->grantRole($role);
- static::assertTrue($this->user->hasRole($role));
- }
- }
|