Commit 3f89396a by Scott

Tests: add permissions tests

parent 37311dab
<?php
require_once QA_INCLUDE_DIR.'app/users.php';
require_once QA_INCLUDE_DIR.'app/options.php';
class AppUsersTest extends PHPUnit_Framework_TestCase
{
/**
* Test logic of permissions function.
* User level values: QA_USER_LEVEL_* in app/users.php [BASIC..SUPER]
* Permission values: QA_PERMIT_* in app/options.php [ALL..SUPERS]
* User flag values: QA_USER_FLAGS_* in app/users.php
*/
public function test__qa_permit_value_error()
{
$userFlags = QA_USER_FLAGS_EMAIL_CONFIRMED;
$blockedFlags = QA_USER_FLAGS_EMAIL_CONFIRMED | QA_USER_FLAGS_USER_BLOCKED;
// Admin trying to do Super stuff
$error = qa_permit_value_error(QA_PERMIT_SUPERS, 1, QA_USER_LEVEL_ADMIN, $userFlags);
$this->assertSame('level', $error);
// Admin trying to do Admin stuff
$error = qa_permit_value_error(QA_PERMIT_ADMINS, 1, QA_USER_LEVEL_ADMIN, $userFlags);
$this->assertSame(false, $error);
// Admin trying to do Editor stuff
$error = qa_permit_value_error(QA_PERMIT_EDITORS, 1, QA_USER_LEVEL_ADMIN, $userFlags);
$this->assertSame(false, $error);
// Expert trying to do Moderator stuff
$error = qa_permit_value_error(QA_PERMIT_MODERATORS, 1, QA_USER_LEVEL_EXPERT, $userFlags);
$this->assertSame('level', $error);
// Unconfirmed User trying to do Confirmed stuff
$error = qa_permit_value_error(QA_PERMIT_CONFIRMED, 1, QA_USER_LEVEL_BASIC, 0);
$this->assertSame('confirm', $error);
// Blocked User trying to do anything
$error = qa_permit_value_error(QA_PERMIT_ALL, 1, QA_USER_LEVEL_BASIC, $blockedFlags);
$this->assertSame('userblock', $error);
// Logged Out User trying to do User stuff
$error = qa_permit_value_error(QA_PERMIT_USERS, null, null, 0);
$this->assertSame('login', $error);
// Logged Out User trying to do Moderator stuff
$error = qa_permit_value_error(QA_PERMIT_MODERATORS, null, null, 0);
$this->assertSame('level', $error);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment