2009-09-15 20:28:11 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
|
|
|
|
print "This script must be run from the command line\n";
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
|
2013-09-28 14:20:10 +01:00
|
|
|
define('GNUSOCIAL', true);
|
|
|
|
define('STATUSNET', true); // compatibility
|
2009-09-15 20:28:11 +01:00
|
|
|
|
|
|
|
require_once INSTALLDIR . '/lib/common.php';
|
|
|
|
|
|
|
|
class UserRightsTest extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
protected $user = null;
|
|
|
|
|
|
|
|
function setUp()
|
|
|
|
{
|
2013-08-18 12:04:58 +01:00
|
|
|
$user = User::getKV('nickname', 'userrightstestuser');
|
2009-12-15 22:49:53 +00:00
|
|
|
if ($user) {
|
|
|
|
// Leftover from a broken test run?
|
|
|
|
$profile = $user->getProfile();
|
|
|
|
$user->delete();
|
|
|
|
$profile->delete();
|
|
|
|
}
|
2009-09-15 20:28:11 +01:00
|
|
|
$this->user = User::register(array('nickname' => 'userrightstestuser'));
|
2009-12-15 22:49:53 +00:00
|
|
|
if (!$this->user) {
|
|
|
|
throw new Exception("Couldn't register userrightstestuser");
|
|
|
|
}
|
2009-09-15 20:28:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function tearDown()
|
|
|
|
{
|
2009-12-15 22:49:53 +00:00
|
|
|
if ($this->user) {
|
|
|
|
$profile = $this->user->getProfile();
|
|
|
|
$this->user->delete();
|
|
|
|
$profile->delete();
|
|
|
|
}
|
2009-09-15 20:28:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function testInvalidRole()
|
|
|
|
{
|
|
|
|
$this->assertFalse($this->user->hasRole('invalidrole'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function standardRoles()
|
|
|
|
{
|
2009-12-15 22:49:53 +00:00
|
|
|
return array(array('admin'),
|
|
|
|
array('moderator'));
|
2009-09-15 20:28:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider standardRoles
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
function testUngrantedRole($role)
|
|
|
|
{
|
|
|
|
$this->assertFalse($this->user->hasRole($role));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider standardRoles
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
function testGrantedRole($role)
|
|
|
|
{
|
|
|
|
$this->user->grantRole($role);
|
2009-12-15 22:49:53 +00:00
|
|
|
$this->assertTrue($this->user->hasRole($role));
|
2009-09-15 20:28:11 +01:00
|
|
|
}
|
2013-09-28 14:20:10 +01:00
|
|
|
}
|