Merged in victorsl/processmaker (pull request #518)

ProcessMaker-BE "Role (PHPUnit)"
This commit is contained in:
Erik Amaru Ortiz
2014-06-04 08:59:27 -04:00
6 changed files with 770 additions and 5 deletions

View File

@@ -296,7 +296,6 @@ class Role
$process = new \ProcessMaker\BusinessModel\Process();
$validator = new \ProcessMaker\BusinessModel\Validator();
$validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
//Set data
@@ -344,7 +343,6 @@ class Role
$process = new \ProcessMaker\BusinessModel\Process();
$validator = new \ProcessMaker\BusinessModel\Validator();
$validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
//Set data

View File

@@ -143,7 +143,6 @@ class Permission
$process = new \ProcessMaker\BusinessModel\Process();
$validator = new \ProcessMaker\BusinessModel\Validator();
$validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
//Set data

View File

@@ -143,7 +143,6 @@ class User
$process = new \ProcessMaker\BusinessModel\Process();
$validator = new \ProcessMaker\BusinessModel\Validator();
$validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
//Set data
@@ -237,12 +236,18 @@ class User
$criteria->addSelectColumn(\RbacUsersPeer::USR_LASTNAME);
$criteria->addSelectColumn(\RbacUsersPeer::USR_STATUS);
$criteria->addAlias("USR", \RbacUsersPeer::TABLE_NAME);
$arrayCondition = array();
$arrayCondition[] = array(\RbacUsersPeer::USR_UID, "USR.USR_UID", \Criteria::EQUAL);
$criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN);
if ($roleUid != "") {
$criteria->addJoin(\UsersRolesPeer::USR_UID, \RbacUsersPeer::USR_UID, \Criteria::LEFT_JOIN);
$criteria->add(\UsersRolesPeer::ROL_UID, $roleUid, \Criteria::EQUAL);
}
$criteria->add(\RbacUsersPeer::USR_USERNAME, "", \Criteria::NOT_EQUAL);
$criteria->add("USR.USR_USERNAME", "", \Criteria::NOT_EQUAL);
if (!is_null($arrayUserUidExclude) && is_array($arrayUserUidExclude)) {
$criteria->add(\RbacUsersPeer::USR_UID, $arrayUserUidExclude, \Criteria::NOT_IN);

View File

@@ -0,0 +1,208 @@
<?php
namespace Tests\BusinessModel\Role;
if (!class_exists("Propel")) {
require_once(__DIR__ . "/../../bootstrap.php");
}
/**
* Class PermissionTest
*
* @package Tests\BusinessModel\Role
*/
class PermissionTest extends \PHPUnit_Framework_TestCase
{
protected static $role;
protected static $roleUid = "";
protected static $rolePermission;
/**
* Set class for test
*
* @coversNothing
*/
public static function setUpBeforeClass()
{
//Role
self::$role = new \ProcessMaker\BusinessModel\Role();
$arrayData = array(
"ROL_CODE" => "PHPUNIT_MY_ROLE_0",
"ROL_NAME" => "PHPUnit My Role 0"
);
$arrayRole = self::$role->create($arrayData);
self::$roleUid = $arrayRole["ROL_UID"];
//Role and Permission
self::$rolePermission = new \ProcessMaker\BusinessModel\Role\Permission();
}
/**
* Delete
*
* @coversNothing
*/
public static function tearDownAfterClass()
{
self::$role->delete(self::$roleUid);
}
/**
* Test assign permissions to role
*
* @covers \ProcessMaker\BusinessModel\Role\Permission::create
*
* @return array
*/
public function testCreate()
{
$arrayRecord = array();
//Permission
$arrayPermission = self::$rolePermission->getPermissions(self::$roleUid, "AVAILABLE-PERMISSIONS", array("filter" => "V"));
$this->assertNotEmpty($arrayPermission);
//Role and Permission - Create
foreach ($arrayPermission as $value) {
$perUid = $value["PER_UID"];
$arrayRolePermission = self::$rolePermission->create(self::$roleUid, array("PER_UID" => $perUid));
$this->assertTrue(is_array($arrayRolePermission));
$this->assertNotEmpty($arrayRolePermission);
$this->assertTrue(isset($arrayRolePermission["ROL_UID"]));
$arrayRecord[] = $arrayRolePermission;
}
//Return
return $arrayRecord;
}
/**
* Test get assigned permissions to role
* Test get available permissions to assign to role
*
* @covers \ProcessMaker\BusinessModel\Role\Permission::getPermissions
*
* @depends testCreate
* @param array $arrayRecord Data of the role-permission
*/
public function testGetPermissions(array $arrayRecord)
{
//PERMISSIONS
$arrayPermission = self::$rolePermission->getPermissions(self::$roleUid, "PERMISSIONS");
$this->assertNotEmpty($arrayPermission);
$arrayPermission = self::$rolePermission->getPermissions(self::$roleUid, "PERMISSIONS", null, null, null, 0, 0);
$this->assertEmpty($arrayPermission);
$arrayPermission = self::$rolePermission->getPermissions(self::$roleUid, "PERMISSIONS", array("filter" => "V"));
$this->assertTrue(is_array($arrayPermission));
$this->assertNotEmpty($arrayPermission);
$this->assertEquals($arrayPermission[0]["PER_UID"], $arrayRecord[0]["PER_UID"]);
//AVAILABLE-PERMISSIONS
$arrayPermission = self::$rolePermission->getPermissions(self::$roleUid, "AVAILABLE-PERMISSIONS", null, null, null, 0, 0);
$this->assertEmpty($arrayPermission);
$arrayPermission = self::$rolePermission->getPermissions(self::$roleUid, "AVAILABLE-PERMISSIONS", array("filter" => "V"));
$this->assertEmpty($arrayPermission);
}
/**
* Test exception for empty data
*
* @covers \ProcessMaker\BusinessModel\Role\Permission::create
*
* @expectedException Exception
* @expectedExceptionMessage Invalid value for "$arrayData", it can not be empty.
*/
public function testCreateExceptionEmptyData()
{
$arrayData = array();
$arrayRolePermission = self::$rolePermission->create(self::$roleUid, $arrayData);
}
/**
* Test exception for invalid role UID
*
* @covers \ProcessMaker\BusinessModel\Role\Permission::create
*
* @expectedException Exception
* @expectedExceptionMessage The role with ROL_UID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx does not exist.
*/
public function testCreateExceptionInvalidRolUid()
{
$arrayData = array(
"USR_UID" => "",
);
$arrayRolePermission = self::$rolePermission->create("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", $arrayData);
}
/**
* Test exception for invalid data (PER_UID)
*
* @covers \ProcessMaker\BusinessModel\Role\Permission::create
*
* @expectedException Exception
* @expectedExceptionMessage Invalid value for "PER_UID", it can not be empty.
*/
public function testCreateExceptionInvalidDataPerUid()
{
$arrayData = array(
"PER_UID" => "",
);
$arrayRolePermission = self::$rolePermission->create(self::$roleUid, $arrayData);
}
/**
* Test unassign permissions of the role
*
* @covers \ProcessMaker\BusinessModel\Role\Permission::delete
*
* @depends testCreate
* @param array $arrayRecord Data of the role-permission
*/
public function testDelete(array $arrayRecord)
{
foreach ($arrayRecord as $value) {
$perUid = $value["PER_UID"];
self::$rolePermission->delete(self::$roleUid, $perUid);
}
$arrayPermission = self::$rolePermission->getPermissions(self::$roleUid, "PERMISSIONS", array("filter" => "V"));
$this->assertTrue(is_array($arrayPermission));
$this->assertEmpty($arrayPermission);
}
/**
* Test exception for invalid permission UID
*
* @covers \ProcessMaker\BusinessModel\Role\Permission::delete
*
* @expectedException Exception
* @expectedExceptionMessage The permission with PER_UID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx does not exist.
*/
public function testDeleteExceptionInvalidPerUid()
{
self::$rolePermission->delete(self::$roleUid, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
}
}

View File

@@ -0,0 +1,225 @@
<?php
namespace Tests\BusinessModel\Role;
if (!class_exists("Propel")) {
require_once(__DIR__ . "/../../bootstrap.php");
}
/**
* Class UserTest
*
* @package Tests\BusinessModel\Role
*/
class UserTest extends \PHPUnit_Framework_TestCase
{
protected static $user;
protected static $roleUser;
protected static $numUser = 2;
protected static $roleUid = "00000000000000000000000000000002"; //PROCESSMAKER_ADMIN
protected static $arrayUsrUid = array();
/**
* Set class for test
*
* @coversNothing
*/
public static function setUpBeforeClass()
{
self::$user = new \ProcessMaker\BusinessModel\User();
self::$roleUser = new \ProcessMaker\BusinessModel\Role\User();
}
/**
* Delete
*
* @coversNothing
*/
public static function tearDownAfterClass()
{
foreach (self::$arrayUsrUid as $value) {
$usrUid = $value;
self::$user->delete($usrUid);
}
}
/**
* Test assign users to role
*
* @covers \ProcessMaker\BusinessModel\Role\User::create
*
* @return array
*/
public function testCreate()
{
$arrayRecord = array();
//User
$arrayAux = explode("-", date("Y-m-d"));
$dueDate = date("Y-m-d", mktime(0, 0, 0, $arrayAux[1], $arrayAux[2] + 5, $arrayAux[0]));
for ($i = 0; $i <= self::$numUser - 1; $i++) {
$arrayData = array(
"USR_USERNAME" => "userphpunit" . $i,
"USR_FIRSTNAME" => "userphpunit" . $i,
"USR_LASTNAME" => "userphpunit" . $i,
"USR_EMAIL" => "userphpunit@email.com" . $i,
"USR_COUNTRY" => "",
"USR_ADDRESS" => "",
"USR_PHONE" => "",
"USR_ZIP_CODE" => "",
"USR_POSITION" => "",
"USR_REPLACED_BY" => "",
"USR_DUE_DATE" => $dueDate,
"USR_ROLE" => "PROCESSMAKER_OPERATOR",
"USR_STATUS" => "ACTIVE",
"USR_NEW_PASS" => "userphpunit" . $i,
"USR_CNF_PASS" => "userphpunit" . $i
);
$arrayUser = array_change_key_case(self::$user->create($arrayData), CASE_UPPER);
self::$arrayUsrUid[] = $arrayUser["USR_UID"];
$arrayRecord[] = $arrayUser;
}
//Role and User - Create
foreach ($arrayRecord as $value) {
$usrUid = $value["USR_UID"];
$arrayRoleUser = self::$roleUser->create(self::$roleUid, array("USR_UID" => $usrUid));
$this->assertTrue(is_array($arrayRoleUser));
$this->assertNotEmpty($arrayRoleUser);
$this->assertTrue(isset($arrayRoleUser["ROL_UID"]));
}
//Return
return $arrayRecord;
}
/**
* Test get assigned users to role
* Test get available users to assign to role
*
* @covers \ProcessMaker\BusinessModel\Role\User::getUsers
*
* @depends testCreate
* @param array $arrayRecord Data of the users
*/
public function testGetUsers(array $arrayRecord)
{
//USERS
$arrayUser = self::$roleUser->getUsers(self::$roleUid, "USERS");
$this->assertNotEmpty($arrayUser);
$arrayUser = self::$roleUser->getUsers(self::$roleUid, "USERS", null, null, null, 0, 0);
$this->assertEmpty($arrayUser);
$arrayUser = self::$roleUser->getUsers(self::$roleUid, "USERS", array("filter" => "userphpunit"));
$this->assertTrue(is_array($arrayUser));
$this->assertNotEmpty($arrayUser);
$this->assertEquals($arrayUser[0]["USR_UID"], $arrayRecord[0]["USR_UID"]);
$this->assertEquals($arrayUser[0]["USR_USERNAME"], $arrayRecord[0]["USR_USERNAME"]);
//AVAILABLE-USERS
$arrayUser = self::$roleUser->getUsers(self::$roleUid, "AVAILABLE-USERS", null, null, null, 0, 0);
$this->assertEmpty($arrayUser);
$arrayUser = self::$roleUser->getUsers(self::$roleUid, "AVAILABLE-USERS", array("filter" => "userphpunit"));
$this->assertEmpty($arrayUser);
}
/**
* Test exception for empty data
*
* @covers \ProcessMaker\BusinessModel\Role\User::create
*
* @expectedException Exception
* @expectedExceptionMessage Invalid value for "$arrayData", it can not be empty.
*/
public function testCreateExceptionEmptyData()
{
$arrayData = array();
$arrayRoleUser = self::$roleUser->create(self::$roleUid, $arrayData);
}
/**
* Test exception for invalid role UID
*
* @covers \ProcessMaker\BusinessModel\Role\User::create
*
* @expectedException Exception
* @expectedExceptionMessage The role with ROL_UID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx does not exist.
*/
public function testCreateExceptionInvalidRolUid()
{
$arrayData = array(
"USR_UID" => "",
);
$arrayRoleUser = self::$roleUser->create("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", $arrayData);
}
/**
* Test exception for invalid data (USR_UID)
*
* @covers \ProcessMaker\BusinessModel\Role\User::create
*
* @expectedException Exception
* @expectedExceptionMessage Invalid value for "USR_UID", it can not be empty.
*/
public function testCreateExceptionInvalidDataUsrUid()
{
$arrayData = array(
"USR_UID" => "",
);
$arrayRoleUser = self::$roleUser->create(self::$roleUid, $arrayData);
}
/**
* Test unassign users of the role
*
* @covers \ProcessMaker\BusinessModel\Role\User::delete
*
* @depends testCreate
* @param array $arrayRecord Data of the users
*/
public function testDelete(array $arrayRecord)
{
foreach ($arrayRecord as $value) {
$usrUid = $value["USR_UID"];
self::$roleUser->delete(self::$roleUid, $usrUid);
}
$arrayUser = self::$roleUser->getUsers(self::$roleUid, "USERS", array("filter" => "userphpunit"));
$this->assertTrue(is_array($arrayUser));
$this->assertEmpty($arrayUser);
}
/**
* Test exception for administrator's role can't be changed
*
* @covers \ProcessMaker\BusinessModel\Role\User::delete
*
* @expectedException Exception
* @expectedExceptionMessage The administrator's role can't be changed!
*/
public function testDeleteExceptionAdminRoleCantChanged()
{
self::$roleUser->delete(self::$roleUid, "00000000000000000000000000000001");
}
}

View File

@@ -0,0 +1,330 @@
<?php
namespace Tests\BusinessModel;
if (!class_exists("Propel")) {
require_once(__DIR__ . "/../bootstrap.php");
}
/**
* Class RoleTest
*
* @package Tests\BusinessModel
*/
class RoleTest extends \PHPUnit_Framework_TestCase
{
protected static $role;
protected static $numRole = 2;
/**
* Set class for test
*
* @coversNothing
*/
public static function setUpBeforeClass()
{
self::$role = new \ProcessMaker\BusinessModel\Role();
}
/**
* Test create roles
*
* @covers \ProcessMaker\BusinessModel\Role::create
*
* @return array
*/
public function testCreate()
{
$arrayRecord = array();
//Create
for ($i = 0; $i <= self::$numRole - 1; $i++) {
$arrayData = array(
"ROL_CODE" => "PHPUNIT_MY_ROLE_" . $i,
"ROL_NAME" => "PHPUnit My Role " . $i
);
$arrayRole = self::$role->create($arrayData);
$this->assertTrue(is_array($arrayRole));
$this->assertNotEmpty($arrayRole);
$this->assertTrue(isset($arrayRole["ROL_UID"]));
$arrayRecord[] = $arrayRole;
}
//Create - Japanese characters
$arrayData = array(
"ROL_CODE" => "PHPUNIT_MY_ROLE_" . self::$numRole,
"ROL_NAME" => "テストPHPUnitの",
);
$arrayRole = self::$role->create($arrayData);
$this->assertTrue(is_array($arrayRole));
$this->assertNotEmpty($arrayRole);
$this->assertTrue(isset($arrayRole["ROL_UID"]));
$arrayRecord[] = $arrayRole;
//Return
return $arrayRecord;
}
/**
* Test update roles
*
* @covers \ProcessMaker\BusinessModel\Role::update
*
* @depends testCreate
* @param array $arrayRecord Data of the roles
*/
public function testUpdate(array $arrayRecord)
{
$arrayData = array("ROL_NAME" => "PHPUnit My Role ...");
$arrayRole = self::$role->update($arrayRecord[1]["ROL_UID"], $arrayData);
$arrayRole = self::$role->getRole($arrayRecord[1]["ROL_UID"]);
$this->assertTrue(is_array($arrayRole));
$this->assertNotEmpty($arrayRole);
$this->assertEquals($arrayRole["ROL_NAME"], $arrayData["ROL_NAME"]);
}
/**
* Test get roles
*
* @covers \ProcessMaker\BusinessModel\Role::getRoles
*
* @depends testCreate
* @param array $arrayRecord Data of the roles
*/
public function testGetRoles(array $arrayRecord)
{
$arrayRole = self::$role->getRoles();
$this->assertNotEmpty($arrayRole);
$arrayRole = self::$role->getRoles(null, null, null, 0, 0);
$this->assertEmpty($arrayRole);
$arrayRole = self::$role->getRoles(array("filter" => "PHPUNIT"));
$this->assertTrue(is_array($arrayRole));
$this->assertNotEmpty($arrayRole);
$this->assertEquals($arrayRole[0]["ROL_UID"], $arrayRecord[0]["ROL_UID"]);
$this->assertEquals($arrayRole[0]["ROL_CODE"], $arrayRecord[0]["ROL_CODE"]);
$this->assertEquals($arrayRole[0]["ROL_NAME"], $arrayRecord[0]["ROL_NAME"]);
}
/**
* Test get role
*
* @covers \ProcessMaker\BusinessModel\Role::getRole
*
* @depends testCreate
* @param array $arrayRecord Data of the roles
*/
public function testGetRole(array $arrayRecord)
{
//Get
$arrayRole = self::$role->getRole($arrayRecord[0]["ROL_UID"]);
$this->assertTrue(is_array($arrayRole));
$this->assertNotEmpty($arrayRole);
$this->assertEquals($arrayRole["ROL_UID"], $arrayRecord[0]["ROL_UID"]);
$this->assertEquals($arrayRole["ROL_CODE"], $arrayRecord[0]["ROL_CODE"]);
$this->assertEquals($arrayRole["ROL_NAME"], $arrayRecord[0]["ROL_NAME"]);
//Get - Japanese characters
$arrayRole = self::$role->getRole($arrayRecord[self::$numRole]["ROL_UID"]);
$this->assertTrue(is_array($arrayRole));
$this->assertNotEmpty($arrayRole);
$this->assertEquals($arrayRole["ROL_UID"], $arrayRecord[self::$numRole]["ROL_UID"]);
$this->assertEquals($arrayRole["ROL_CODE"], "PHPUNIT_MY_ROLE_" . self::$numRole);
$this->assertEquals($arrayRole["ROL_NAME"], "テストPHPUnitの");
}
/**
* Test exception for empty data
*
* @covers \ProcessMaker\BusinessModel\Role::create
*
* @expectedException Exception
* @expectedExceptionMessage Invalid value for "$arrayData", it can not be empty.
*/
public function testCreateExceptionEmptyData()
{
$arrayData = array();
$arrayRole = self::$role->create($arrayData);
}
/**
* Test exception for required data (ROL_CODE)
*
* @covers \ProcessMaker\BusinessModel\Role::create
*
* @expectedException Exception
* @expectedExceptionMessage Undefined value for "ROL_CODE", it is required.
*/
public function testCreateExceptionRequiredDataRolCode()
{
$arrayData = array(
//"ROL_CODE" => "PHPUNIT_MY_ROLE_N",
"ROL_NAME" => "PHPUnit My Role N"
);
$arrayRole = self::$role->create($arrayData);
}
/**
* Test exception for invalid data (ROL_CODE)
*
* @covers \ProcessMaker\BusinessModel\Role::create
*
* @expectedException Exception
* @expectedExceptionMessage Invalid value for "ROL_CODE", it can not be empty.
*/
public function testCreateExceptionInvalidDataRolCode()
{
$arrayData = array(
"ROL_CODE" => "",
"ROL_NAME" => "PHPUnit My Role N"
);
$arrayRole = self::$role->create($arrayData);
}
/**
* Test exception for role code existing
*
* @covers \ProcessMaker\BusinessModel\Role::create
*
* @expectedException Exception
* @expectedExceptionMessage The role code with ROL_CODE: "PHPUNIT_MY_ROLE_0" already exists.
*/
public function testCreateExceptionExistsRolCode()
{
$arrayData = array(
"ROL_CODE" => "PHPUNIT_MY_ROLE_0",
"ROL_NAME" => "PHPUnit My Role 0"
);
$arrayRole = self::$role->create($arrayData);
}
/**
* Test exception for empty data
*
* @covers \ProcessMaker\BusinessModel\Role::update
*
* @expectedException Exception
* @expectedExceptionMessage Invalid value for "$arrayData", it can not be empty.
*/
public function testUpdateExceptionEmptyData()
{
$arrayData = array();
$arrayRole = self::$role->update("", $arrayData);
}
/**
* Test exception for invalid role UID
*
* @covers \ProcessMaker\BusinessModel\Role::update
*
* @expectedException Exception
* @expectedExceptionMessage The role with ROL_UID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx does not exist.
*/
public function testUpdateExceptionInvalidRolUid()
{
$arrayData = array(
"ROL_CODE" => "PHPUNIT_MY_ROLE_N",
"ROL_NAME" => "PHPUnit My Role N"
);
$arrayRole = self::$role->update("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", $arrayData);
}
/**
* Test exception for invalid data (ROL_CODE)
*
* @covers \ProcessMaker\BusinessModel\Role::update
*
* @depends testCreate
* @param array $arrayRecord Data of the roles
*
* @expectedException Exception
* @expectedExceptionMessage Invalid value for "ROL_CODE", it can not be empty.
*/
public function testUpdateExceptionInvalidDataRolCode(array $arrayRecord)
{
$arrayData = array(
"ROL_CODE" => "",
"ROL_NAME" => "PHPUnit My Role 0"
);
$arrayRole = self::$role->update($arrayRecord[0]["ROL_UID"], $arrayData);
}
/**
* Test exception for role code existing
*
* @covers \ProcessMaker\BusinessModel\Role::update
*
* @depends testCreate
* @param array $arrayRecord Data of the roles
*
* @expectedException Exception
* @expectedExceptionMessage The role code with ROL_CODE: "PHPUNIT_MY_ROLE_1" already exists.
*/
public function testUpdateExceptionExistsRolCode(array $arrayRecord)
{
$arrayData = $arrayRecord[1];
$arrayRole = self::$role->update($arrayRecord[0]["ROL_UID"], $arrayData);
}
/**
* Test delete roles
*
* @covers \ProcessMaker\BusinessModel\Role::delete
*
* @depends testCreate
* @param array $arrayRecord Data of the roles
*/
public function testDelete(array $arrayRecord)
{
foreach ($arrayRecord as $value) {
self::$role->delete($value["ROL_UID"]);
}
$arrayRole = self::$role->getRoles(array("filter" => "PHPUNIT"));
$this->assertTrue(is_array($arrayRole));
$this->assertEmpty($arrayRole);
}
/**
* Test exception for role UID that cannot be deleted
*
* @covers \ProcessMaker\BusinessModel\Role::delete
*
* @expectedException Exception
* @expectedExceptionMessage This role cannot be deleted while it still has some assigned users.
*/
public function testDeleteExceptionCannotDeleted()
{
self::$role->delete("00000000000000000000000000000002");
}
}