Making code PSR2 compliant

This commit is contained in:
gamonoid
2017-09-24 19:23:30 +02:00
parent 05b57e0236
commit 6c61577583
160 changed files with 1432 additions and 1086 deletions

View File

@@ -1,92 +1,95 @@
<?php
class TestTemplate extends PHPUnit_Framework_TestCase{
class TestTemplate extends PHPUnit_Framework_TestCase
{
protected $usersArray = array();
protected $usersArray = array();
private $db = null;
public function p($msg){
fwrite(STDOUT, $msg."\n");
}
public function p($msg)
{
fwrite(STDOUT, $msg."\n");
}
protected function setUp()
{
parent::setUp();
protected function setUp()
{
parent::setUp();
}
}
protected function tearDown()
{
parent::tearDown();
}
protected function tearDown()
{
parent::tearDown();
protected function deleteAllUsers()
{
$user = new \Users\Common\Model\User();
$users = $user->Find("username <> ?", array('admin'));
foreach ($users as $user) {
$user->Delete();
}
}
}
protected function createNewUsers()
{
protected function deleteAllUsers(){
$user = new \Users\Common\Model\User();
$users = $user->Find("username <> ?",array('admin'));
foreach($users as $user){
$user->Delete();
}
}
$profileVar = SIGN_IN_ELEMENT_MAPPING_FIELD_NAME;
$profileClass = ucfirst(SIGN_IN_ELEMENT_MAPPING_FIELD_NAME);
protected function createNewUsers(){
$user = new \Users\Common\Model\User();
$user->username = 'manager';
$user->email = 'manager@icehrm-test.com';
$user->password = '21232f297a57a5a743894a0e4a801fc3';
$user->user_level = 'Manager';
$user->Save();
$profileVar = SIGN_IN_ELEMENT_MAPPING_FIELD_NAME;
$profileClass = ucfirst(SIGN_IN_ELEMENT_MAPPING_FIELD_NAME);
$user = new \Users\Common\Model\User();
$user->username = 'profile';
$user->email = 'profile@icehrm-test.com';
$user->password = '21232f297a57a5a743894a0e4a801fc3';
$user->user_level = 'Profile';
$user->Save();
}
$user = new \Users\Common\Model\User();
$user->username = 'manager';
$user->email = 'manager@icehrm-test.com';
$user->password = '21232f297a57a5a743894a0e4a801fc3';
$user->user_level = 'Manager';
$user->Save();
protected function initializeObjects()
{
$user = new \Users\Common\Model\User();
$user->username = 'profile';
$user->email = 'profile@icehrm-test.com';
$user->password = '21232f297a57a5a743894a0e4a801fc3';
$user->user_level = 'Profile';
$user->Save();
}
global $userTables;
global $fileFields;
global $mysqlErrors;
protected function initializeObjects() {
$dbLocal = NewADOConnection(APP_CON_STR);
global $userTables;
global $fileFields;
global $mysqlErrors;
\Model\File::SetDatabaseAdapter($dbLocal);
\Model\Setting::SetDatabaseAdapter($dbLocal);
\Model\Report::SetDatabaseAdapter($dbLocal);
\Model\DataEntryBackup::SetDatabaseAdapter($dbLocal);
\Model\Audit::SetDatabaseAdapter($dbLocal);
\Model\Notification::SetDatabaseAdapter($dbLocal);
\Model\RestAccessToken::SetDatabaseAdapter($dbLocal);
$dbLocal = NewADOConnection(APP_CON_STR);
$moduleManagers = \Classes\BaseService::getInstance()->getModuleManagers();
\Model\File::SetDatabaseAdapter($dbLocal);
\Model\Setting::SetDatabaseAdapter($dbLocal);
\Model\Report::SetDatabaseAdapter($dbLocal);
\Model\DataEntryBackup::SetDatabaseAdapter($dbLocal);
\Model\Audit::SetDatabaseAdapter($dbLocal);
\Model\Notification::SetDatabaseAdapter($dbLocal);
\Model\RestAccessToken::SetDatabaseAdapter($dbLocal);
foreach ($moduleManagers as $moduleManagerObj) {
$moduleManagerObj->setupModuleClassDefinitions();
$moduleManagerObj->initializeUserClasses();
$moduleManagerObj->initializeFieldMappings();
$moduleManagerObj->initializeDatabaseErrorMappings();
$moduleManagers = \Classes\BaseService::getInstance()->getModuleManagers();
$moduleManagerObj->setupUserClasses($userTables);
$moduleManagerObj->setupFileFieldMappings($fileFields);
$moduleManagerObj->setupErrorMappings($mysqlErrors);
$moduleManagerObj->initCalculationHooks();
foreach($moduleManagers as $moduleManagerObj){
$modelClassList = $moduleManagerObj->getModelClasses();
$moduleManagerObj->setupModuleClassDefinitions();
$moduleManagerObj->initializeUserClasses();
$moduleManagerObj->initializeFieldMappings();
$moduleManagerObj->initializeDatabaseErrorMappings();
foreach ($modelClassList as $modelClass) {
$modelClass::SetDatabaseAdapter($dbLocal);
}
}
}
$moduleManagerObj->setupUserClasses($userTables);
$moduleManagerObj->setupFileFieldMappings($fileFields);
$moduleManagerObj->setupErrorMappings($mysqlErrors);
$moduleManagerObj->initCalculationHooks();
$modelClassList = $moduleManagerObj->getModelClasses();
foreach($modelClassList as $modelClass){
$modelClass::SetDatabaseAdapter($dbLocal);
}
}
}
protected function resetDatabase(){
protected function resetDatabase()
{
$dropDBCommand = 'echo "DROP DATABASE IF EXISTS ' . APP_DB . '"| mysql -u' . MYSQL_ROOT_USER . ' -p' . MYSQL_ROOT_PASS;
$createDBCommand = 'echo "CREATE DATABASE '.APP_DB.'"| mysql -u'.MYSQL_ROOT_USER.' -p'.MYSQL_ROOT_PASS;
@@ -98,7 +101,7 @@ class TestTemplate extends PHPUnit_Framework_TestCase{
APP_BASE_PATH."scripts/icehrm_master_data.sql"
);
foreach ($scripts as $insql){
foreach ($scripts as $insql) {
$command = "cat ".$insql."| mysql -u".MYSQL_ROOT_USER." -p".MYSQL_ROOT_PASS." '".APP_DB."'";
exec($command);
}

View File

@@ -1,5 +1,5 @@
<?php
if(file_exists('/usr/lib/php5/mysql.auth.php')){
if (file_exists('/usr/lib/php5/mysql.auth.php')) {
include '/usr/lib/php5/mysql.auth.php';
}
include(dirname(__FILE__).'/test.config.php');
@@ -20,7 +20,7 @@ $scripts = array(
//APP_BASE_PATH."scripts/icehrm_sample_data.sql",
);
foreach ($scripts as $insql){
foreach ($scripts as $insql) {
echo $insql."\r\n";
$command = "cat ".$insql."| mysql -u".MYSQL_ROOT_USER." -p".MYSQL_ROOT_PASS." '".APP_DB."'";
exec($command);

View File

@@ -8,36 +8,36 @@
namespace Test\Helper;
use Employees\Common\Model\Employee;
class EmployeeTestDataHelper
{
public static function insertRandomEmployee()
{
$emp = new Employee();
$emp->employee_id = self::randomString(4).time();
$emp->first_name = self::randomString();
$emp->last_name = self::randomString();
$emp->birthday = '1984-12-19';
$emp->gender = 'Male';
$emp->marital_status = 'Married';
$emp->job_title = NULL;
$emp->joined_date = '2005-08-03';
$emp->job_title = NULL;
$emp->department = NULL;
$emp->Save();
return $emp->id;
}
public static function insertRandomEmployee()
{
$emp = new Employee();
$emp->employee_id = self::randomString(4).time();
$emp->first_name = self::randomString();
$emp->last_name = self::randomString();
$emp->birthday = '1984-12-19';
$emp->gender = 'Male';
$emp->marital_status = 'Married';
$emp->job_title = null;
$emp->joined_date = '2005-08-03';
$emp->job_title = null;
$emp->department = null;
$emp->Save();
return $emp->id;
}
public static function randomString($length = 6) {
$str = "";
$characters = array_merge(range('A','Z'), range('a','z'), range('0','9'));
$max = count($characters) - 1;
for ($i = 0; $i < $length; $i++) {
$rand = mt_rand(0, $max);
$str .= $characters[$rand];
}
return $str;
}
public static function randomString($length = 6)
{
$str = "";
$characters = array_merge(range('A', 'Z'), range('a', 'z'), range('0', '9'));
$max = count($characters) - 1;
for ($i = 0; $i < $length; $i++) {
$rand = mt_rand(0, $max);
$str .= $characters[$rand];
}
return $str;
}
}

View File

@@ -6,13 +6,14 @@ use Employees\Common\Model\Employee;
use Test\Helper\EmployeeTestDataHelper;
use Travel\Common\Model\EmployeeTravelRecord;
class ApprovalStatusIntegration extends \TestTemplate
{
class ApprovalStatusIntegration extends \TestTemplate{
protected $travelRec = null;
protected $ids = null;
var $travelRec = null;
var $ids = null;
protected function setUp(){
protected function setUp()
{
parent::setUp();
$ids = [];
@@ -21,7 +22,7 @@ class ApprovalStatusIntegration extends \TestTemplate{
}
$emp = new Employee();
$emp->Load("id = ?",array($ids[0]));
$emp->Load("id = ?", array($ids[0]));
$emp->supervisor = $ids[1];
$emp->indirect_supervisors = json_encode(array($ids[2],$ids[3]));
$emp->approver1 = $ids[4];
@@ -46,7 +47,8 @@ class ApprovalStatusIntegration extends \TestTemplate{
$this->ids = $ids;
}
protected function tearDown(){
protected function tearDown()
{
parent::tearDown();
foreach ($this->ids as $id) {
$employee = new Employee();
@@ -59,11 +61,12 @@ class ApprovalStatusIntegration extends \TestTemplate{
}
public function testInitializeApprovalChain(){
public function testInitializeApprovalChain()
{
$id = $this->travelRec->id;
$as = ApprovalStatus::getInstance();
$as->initializeApprovalChain('EmployeeTravelRecord',$id);
$status = $as->getAllStatuses('EmployeeTravelRecord',$id);
$as->initializeApprovalChain('EmployeeTravelRecord', $id);
$status = $as->getAllStatuses('EmployeeTravelRecord', $id);
$this->assertEquals(3, count($status));
$this->assertEquals($this->ids[4], $status[0]->approver);
$this->assertEquals($this->ids[5], $status[1]->approver);
@@ -71,41 +74,41 @@ class ApprovalStatusIntegration extends \TestTemplate{
}
public function testUpdateApprovalStatus(){
public function testUpdateApprovalStatus()
{
$id = $this->travelRec->id;
$as = ApprovalStatus::getInstance();
$as->initializeApprovalChain('EmployeeTravelRecord',$id);
$as->initializeApprovalChain('EmployeeTravelRecord', $id);
// Supervisor should approve first
$resp = $as->updateApprovalStatus('EmployeeTravelRecord',$id,$this->ids[1],1);
$resp = $as->updateApprovalStatus('EmployeeTravelRecord', $id, $this->ids[1], 1);
$this->assertNull($resp->getObject()[0]);
$this->assertEquals(1, $resp->getObject()[1]->active);
$this->assertEquals(1, $resp->getObject()[1]->level);
// Now if a an indirect supervisor try to approve it should fail
$resp = $as->updateApprovalStatus('EmployeeTravelRecord',$id,$this->ids[2],1);
$resp = $as->updateApprovalStatus('EmployeeTravelRecord', $id, $this->ids[2], 1);
$this->assertEquals(\Classes\IceResponse::ERROR, $resp->getStatus());
// First approver approves
$resp = $as->updateApprovalStatus('EmployeeTravelRecord',$id,$this->ids[4],1);
$resp = $as->updateApprovalStatus('EmployeeTravelRecord', $id, $this->ids[4], 1);
$this->assertEquals(0, $resp->getObject()[0]->active);
$this->assertEquals(1, $resp->getObject()[0]->level);
$this->assertEquals(1, $resp->getObject()[1]->active);
$this->assertEquals(2, $resp->getObject()[1]->level);
// Second approver approves
$resp = $as->updateApprovalStatus('EmployeeTravelRecord',$id,$this->ids[5],1);
$resp = $as->updateApprovalStatus('EmployeeTravelRecord', $id, $this->ids[5], 1);
$this->assertEquals(0, $resp->getObject()[0]->active);
$this->assertEquals(2, $resp->getObject()[0]->level);
$this->assertEquals(1, $resp->getObject()[1]->active);
$this->assertEquals(3, $resp->getObject()[1]->level);
// Third approver approves
$resp = $as->updateApprovalStatus('EmployeeTravelRecord',$id,$this->ids[6],1);
$resp = $as->updateApprovalStatus('EmployeeTravelRecord', $id, $this->ids[6], 1);
$this->assertEquals(1, $resp->getObject()[0]->active);
$this->assertEquals(3, $resp->getObject()[0]->level);
$this->assertNull($resp->getObject()[1]);
}
}

View File

@@ -8,39 +8,38 @@
namespace Test\Integration;
use Classes\Migration\MigrationManager;
use Model\Migration;
class MigrationManagerIntegration extends \TestTemplate
{
/* @var MigrationManager $migrationManager */
private $migrationManager;
protected function setUp(){
parent::setUp();
$this->migrationManager = new MigrationManager();
for ($i = 0; $i < 5; $i++) {
$migration = new Migration();
$migration->file = 'migration'.$i;
$migration->version = '190000';
$migration->created = date("Y-m-d H:i:s", intval(time()) - 10 * $i);
$migration->updated = date("Y-m-d H:i:s", intval(time()) - 10 * $i);
$migration->status = 'Pending';
$migration->Save();
}
}
protected function tearDown(){
parent::tearDown();
$migration = new Migration();
$migration->DB()->execute("delete from Migrations");
}
public function testGetCurrentMigrations() {
$migrations = $this->migrationManager->getCurrentMigrations();
self::assertEquals(5, count($migrations));
}
/* @var MigrationManager $migrationManager */
private $migrationManager;
protected function setUp()
{
parent::setUp();
$this->migrationManager = new MigrationManager();
for ($i = 0; $i < 5; $i++) {
$migration = new Migration();
$migration->file = 'migration'.$i;
$migration->version = '190000';
$migration->created = date("Y-m-d H:i:s", intval(time()) - 10 * $i);
$migration->updated = date("Y-m-d H:i:s", intval(time()) - 10 * $i);
$migration->status = 'Pending';
$migration->Save();
}
}
protected function tearDown()
{
parent::tearDown();
$migration = new Migration();
$migration->DB()->execute("delete from Migrations");
}
public function testGetCurrentMigrations()
{
$migrations = $this->migrationManager->getCurrentMigrations();
self::assertEquals(5, count($migrations));
}
}

View File

@@ -7,36 +7,35 @@ define('APP_NAME', 'IceHrm');
define('FB_URL', 'IceHrm');
define('TWITTER_URL', 'IceHrm');
define('SIGN_IN_ELEMENT_MAPPING_FIELD_NAME','employee');
define('SIGN_IN_ELEMENT_MAPPING_FIELD_NAME', 'employee');
define('CLIENT_NAME', 'app');
if(!defined('MYSQL_ROOT_USER') || !defined('MYSQL_ROOT_PASS')){
if (!defined('MYSQL_ROOT_USER') || !defined('MYSQL_ROOT_PASS')) {
//Tests running on vagrant
define('APP_BASE_PATH', TEST_BASE_PATH.'../');
define('CLIENT_BASE_PATH', TEST_BASE_PATH.'../../deployment/clients/test/');
define('BASE_URL','http://app.app.dev/');
define('CLIENT_BASE_URL','http://clients.app.dev/dev/');
}else{
define('BASE_URL', 'http://app.app.dev/');
define('CLIENT_BASE_URL', 'http://clients.app.dev/dev/');
} else {
//Tests running on deploy
define('APP_BASE_PATH', realpath(dirname(__FILE__).'/../app')."/");
define('CLIENT_BASE_PATH', APP_BASE_PATH.'');
define('BASE_URL','http://apps.gamonoid.com/icehrmcore/');
define('CLIENT_BASE_URL','http://apps.gamonoid.com/icehrm/');
define('BASE_URL', 'http://apps.gamonoid.com/icehrmcore/');
define('CLIENT_BASE_URL', 'http://apps.gamonoid.com/icehrm/');
}
if(!defined('MYSQL_ROOT_USER') || !defined('MYSQL_ROOT_PASS')){
if (!defined('MYSQL_ROOT_USER') || !defined('MYSQL_ROOT_PASS')) {
define('APP_DB', 'testing');
define('APP_USERNAME', 'root');
define('APP_PASSWORD', 'dev');
}else{
} else {
define('APP_DB', 'icehrmht');
define('APP_USERNAME', MYSQL_ROOT_USER);
define('APP_PASSWORD', MYSQL_ROOT_PASS);
}
if(!defined('MYSQL_ROOT_USER') || !defined('MYSQL_ROOT_PASS')){
if (!defined('MYSQL_ROOT_USER') || !defined('MYSQL_ROOT_PASS')) {
define('MYSQL_ROOT_USER', 'root');
define('MYSQL_ROOT_PASS', 'dev');
}
@@ -47,4 +46,4 @@ define('APP_CON_STR', 'mysqli://'.APP_USERNAME.':'.APP_PASSWORD.'@'.APP_HOST.'/'
//file upload
define('FILE_TYPES', 'jpg,png,jpeg');
define('MAX_FILE_SIZE_KB', 10 * 1024);
define('CLIENT_PATH',APP_BASE_PATH);
define('CLIENT_PATH', APP_BASE_PATH);

View File

@@ -1,36 +1,38 @@
<?php
//Mock Session class
if (!class_exists('SessionUtils')) {
class SessionUtils{
class SessionUtils
{
public static $data;
public static $data;
public static function getSessionObject($name){
if(empty(self::$data)){
self::$data = array();
}
if(isset(self::$data[$name.CLIENT_NAME])){
$obj = self::$data[$name.CLIENT_NAME];
}
if(empty($obj)){
return null;
}
return json_decode($obj);
}
public static function getSessionObject($name)
{
if (empty(self::$data)) {
self::$data = array();
}
if (isset(self::$data[$name.CLIENT_NAME])) {
$obj = self::$data[$name.CLIENT_NAME];
}
if (empty($obj)) {
return null;
}
return json_decode($obj);
}
public static function saveSessionObject($name,$obj){
if(empty(self::$data)){
self::$data = array();
}
self::$data[$name.CLIENT_NAME] = json_encode($obj);
}
}
public static function saveSessionObject($name, $obj)
{
if (empty(self::$data)) {
self::$data = array();
}
self::$data[$name.CLIENT_NAME] = json_encode($obj);
}
}
}
if (!class_exists('TestTemplate')) {
include(dirname(__FILE__).'/TestTemplate.php');
include(dirname(__FILE__).'/helper/EmployeeTestDataHelper.php');
include(APP_BASE_PATH."/includes.inc.php");
include(dirname(__FILE__).'/TestTemplate.php');
include(dirname(__FILE__).'/helper/EmployeeTestDataHelper.php');
include(APP_BASE_PATH."/includes.inc.php");
}

View File

@@ -8,15 +8,14 @@
namespace Test\Unit;
use Classes\BaseService;
class BaseServiceUnit extends \TestTemplate
{
public function testGet()
{
$baseService = BaseService::getInstance();
// create a user
//$user =
}
public function testGet()
{
$baseService = BaseService::getInstance();
// create a user
//$user =
}
}

View File

@@ -3,15 +3,16 @@ namespace Test\Unit;
use Classes\LanguageManager;
class LanguageManagerUnit extends \TestTemplate{
class LanguageManagerUnit extends \TestTemplate
{
protected function setUp()
{
parent::setUp();
}
public function testTran(){
public function testTran()
{
$this->assertEquals('cat', LanguageManager::tran('cat'));
$this->assertEquals('solid', LanguageManager::tran('solid'));
$this->assertEquals('one file', LanguageManager::tran('one file'));

View File

@@ -8,23 +8,24 @@
namespace unit;
use Attendance\User\Api\AttendanceActionManager;
use Classes\BaseService;
class UserAttendanceActionManagerUnit extends \TestTemplate{
class UserAttendanceActionManagerUnit extends \TestTemplate
{
protected $actionMgr;
protected function setUp()
{
parent::setUp();
$this->actionMgr = new AttendanceActionManager();
$this->actionMgr->setBaseService(BaseService::getInstance());
}
protected $actionMgr;
protected function setUp()
{
parent::setUp();
$this->actionMgr = new AttendanceActionManager();
$this->actionMgr->setBaseService(BaseService::getInstance());
}
public function testTran(){
public function testTran()
{
$punch = $this->actionMgr->getPunch(['date' => date('Y-m-d H:i:s')]);
self::assertEquals('SUCCESS', $punch->getStatus());
}
$punch = $this->actionMgr->getPunch(['date' => date('Y-m-d H:i:s')]);
self::assertEquals('SUCCESS', $punch->getStatus());
}
}