2009-09-16 04:28:11 +09:00
|
|
|
<?php
|
2019-07-13 00:31:14 +09:00
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
2009-09-16 04:28:11 +09:00
|
|
|
|
2019-07-13 00:31:14 +09:00
|
|
|
namespace Tests\Unit;
|
|
|
|
|
|
|
|
if (!defined('INSTALLDIR')) {
|
|
|
|
define('INSTALLDIR', dirname(dirname(__DIR__)));
|
|
|
|
}
|
|
|
|
if (!defined('GNUSOCIAL')) {
|
|
|
|
define('GNUSOCIAL', true);
|
|
|
|
}
|
|
|
|
if (!defined('STATUSNET')) { // Compatibility
|
|
|
|
define('STATUSNET', true);
|
2009-09-16 04:28:11 +09:00
|
|
|
}
|
|
|
|
|
2019-07-13 00:31:14 +09:00
|
|
|
use Exception;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use User;
|
2009-09-16 04:28:11 +09:00
|
|
|
|
|
|
|
require_once INSTALLDIR . '/lib/common.php';
|
|
|
|
|
2019-07-13 00:31:14 +09:00
|
|
|
final class UserRightsTest extends TestCase
|
2009-09-16 04:28:11 +09:00
|
|
|
{
|
|
|
|
protected $user = null;
|
|
|
|
|
|
|
|
function setUp()
|
|
|
|
{
|
2013-08-18 20:04:58 +09:00
|
|
|
$user = User::getKV('nickname', 'userrightstestuser');
|
2009-12-16 07:49:53 +09:00
|
|
|
if ($user) {
|
|
|
|
// Leftover from a broken test run?
|
|
|
|
$profile = $user->getProfile();
|
|
|
|
$user->delete();
|
|
|
|
$profile->delete();
|
|
|
|
}
|
2009-09-16 04:28:11 +09:00
|
|
|
$this->user = User::register(array('nickname' => 'userrightstestuser'));
|
2009-12-16 07:49:53 +09:00
|
|
|
if (!$this->user) {
|
|
|
|
throw new Exception("Couldn't register userrightstestuser");
|
|
|
|
}
|
2009-09-16 04:28:11 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function tearDown()
|
|
|
|
{
|
2009-12-16 07:49:53 +09:00
|
|
|
if ($this->user) {
|
|
|
|
$profile = $this->user->getProfile();
|
|
|
|
$this->user->delete();
|
|
|
|
$profile->delete();
|
|
|
|
}
|
2009-09-16 04:28:11 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function testInvalidRole()
|
|
|
|
{
|
|
|
|
$this->assertFalse($this->user->hasRole('invalidrole'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function standardRoles()
|
|
|
|
{
|
2009-12-16 07:49:53 +09:00
|
|
|
return array(array('admin'),
|
2019-07-13 00:31:14 +09:00
|
|
|
array('moderator'));
|
2009-09-16 04:28:11 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider standardRoles
|
2019-07-13 00:31:14 +09:00
|
|
|
* @param $role
|
2009-09-16 04:28:11 +09:00
|
|
|
*/
|
|
|
|
|
|
|
|
function testUngrantedRole($role)
|
|
|
|
{
|
|
|
|
$this->assertFalse($this->user->hasRole($role));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider standardRoles
|
2019-07-13 00:31:14 +09:00
|
|
|
* @param $role
|
2009-09-16 04:28:11 +09:00
|
|
|
*/
|
|
|
|
|
|
|
|
function testGrantedRole($role)
|
|
|
|
{
|
|
|
|
$this->user->grantRole($role);
|
2009-12-16 07:49:53 +09:00
|
|
|
$this->assertTrue($this->user->hasRole($role));
|
2009-09-16 04:28:11 +09:00
|
|
|
}
|
2013-09-28 22:20:10 +09:00
|
|
|
}
|