Removing dependency on sample data ⛅️
This commit is contained in:
@@ -13,14 +13,11 @@ exec($dropDBCommand);
|
|||||||
echo "Create DB Command:".$createDBCommand."\r\n";
|
echo "Create DB Command:".$createDBCommand."\r\n";
|
||||||
exec($createDBCommand);
|
exec($createDBCommand);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Run create table script
|
//Run create table script
|
||||||
|
|
||||||
$scripts = array(
|
$scripts = array(
|
||||||
APP_BASE_PATH."scripts/icehrmdb.sql",
|
APP_BASE_PATH."scripts/icehrmdb.sql",
|
||||||
APP_BASE_PATH."scripts/icehrm_master_data.sql",
|
APP_BASE_PATH."scripts/icehrm_master_data.sql",
|
||||||
APP_BASE_PATH."scripts/icehrm_sample_data.sql",
|
//APP_BASE_PATH."scripts/icehrm_sample_data.sql",
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($scripts as $insql){
|
foreach ($scripts as $insql){
|
||||||
|
|||||||
43
test/helper/EmployeeTestDataHelper.php
Normal file
43
test/helper/EmployeeTestDataHelper.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: Thilina
|
||||||
|
* Date: 9/7/17
|
||||||
|
* Time: 7:49 AM
|
||||||
|
*/
|
||||||
|
|
||||||
|
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 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,32 +3,37 @@ namespace Test\Integration;
|
|||||||
|
|
||||||
use Classes\Approval\ApprovalStatus;
|
use Classes\Approval\ApprovalStatus;
|
||||||
use Employees\Common\Model\Employee;
|
use Employees\Common\Model\Employee;
|
||||||
|
use Test\Helper\EmployeeTestDataHelper;
|
||||||
use Travel\Common\Model\EmployeeTravelRecord;
|
use Travel\Common\Model\EmployeeTravelRecord;
|
||||||
|
|
||||||
|
|
||||||
class ApprovalStatusIntegration extends \TestTemplate{
|
class ApprovalStatusIntegration extends \TestTemplate{
|
||||||
|
|
||||||
var $travelRec = null;
|
var $travelRec = null;
|
||||||
|
var $ids = null;
|
||||||
|
|
||||||
protected function setUp(){
|
protected function setUp(){
|
||||||
|
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
$ids = [];
|
||||||
|
for ($i = 1; $i <= 7; $i++) {
|
||||||
|
$ids[] = EmployeeTestDataHelper::insertRandomEmployee();
|
||||||
|
}
|
||||||
|
|
||||||
$emp = new Employee();
|
$emp = new Employee();
|
||||||
$emp->Load("id = ?",array(1));
|
$emp->Load("id = ?",array($ids[0]));
|
||||||
$emp->supervisor = 2;
|
$emp->supervisor = $ids[1];
|
||||||
$emp->indirect_supervisors = json_encode(array(3,4));
|
$emp->indirect_supervisors = json_encode(array($ids[2],$ids[3]));
|
||||||
$emp->approver1 = 5;
|
$emp->approver1 = $ids[4];
|
||||||
$emp->approver2 = 6;
|
$emp->approver2 = $ids[5];
|
||||||
$emp->approver3 = 7;
|
$emp->approver3 = $ids[6];
|
||||||
$emp->Save();
|
$emp->Save();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$this->travelRec = new EmployeeTravelRecord();
|
$this->travelRec = new EmployeeTravelRecord();
|
||||||
|
|
||||||
$this->travelRec->DB()->execute("delete from EmployeeTravelRecords");
|
$this->travelRec->employee = $ids[0];
|
||||||
|
|
||||||
$this->travelRec->employee = 1;
|
|
||||||
$this->travelRec->type = 'International';
|
$this->travelRec->type = 'International';
|
||||||
$this->travelRec->purpose = 'Testing';
|
$this->travelRec->purpose = 'Testing';
|
||||||
$this->travelRec->travel_from = 'Colombo';
|
$this->travelRec->travel_from = 'Colombo';
|
||||||
@@ -37,58 +42,70 @@ class ApprovalStatusIntegration extends \TestTemplate{
|
|||||||
$this->travelRec->return_date = date("Y-m-d H:i:s");
|
$this->travelRec->return_date = date("Y-m-d H:i:s");
|
||||||
$this->travelRec->status = 'Pending';
|
$this->travelRec->status = 'Pending';
|
||||||
$this->travelRec->Save();
|
$this->travelRec->Save();
|
||||||
|
|
||||||
|
$this->ids = $ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown(){
|
protected function tearDown(){
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
|
foreach ($this->ids as $id) {
|
||||||
|
$employee = new Employee();
|
||||||
|
$employee->Load("id = ?", array($id));
|
||||||
|
$employee->Delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->travelRec->DB()->execute("delete from EmployeeTravelRecords");
|
||||||
|
$this->travelRec->DB()->execute("delete from EmployeeApprovals");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testInitializeApprovalChain(){
|
public function testInitializeApprovalChain(){
|
||||||
$id = $this->travelRec->id;
|
$id = $this->travelRec->id;
|
||||||
//$this->initializeObjects();
|
|
||||||
$as = ApprovalStatus::getInstance();
|
$as = ApprovalStatus::getInstance();
|
||||||
$as->initializeApprovalChain('EmployeeTravelRecord',$id);
|
$as->initializeApprovalChain('EmployeeTravelRecord',$id);
|
||||||
$status = $as->getAllStatuses('EmployeeTravelRecord',$id);
|
$status = $as->getAllStatuses('EmployeeTravelRecord',$id);
|
||||||
$this->assertEquals(3, count($status));
|
$this->assertEquals(3, count($status));
|
||||||
|
$this->assertEquals($this->ids[4], $status[0]->approver);
|
||||||
|
$this->assertEquals($this->ids[5], $status[1]->approver);
|
||||||
|
$this->assertEquals($this->ids[6], $status[2]->approver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testUpdateApprovalStatus(){
|
public function testUpdateApprovalStatus(){
|
||||||
$id = $this->travelRec->id;
|
$id = $this->travelRec->id;
|
||||||
//$this->initializeObjects();
|
|
||||||
$as = ApprovalStatus::getInstance();
|
$as = ApprovalStatus::getInstance();
|
||||||
|
|
||||||
$as->initializeApprovalChain('EmployeeTravelRecord',$id);
|
$as->initializeApprovalChain('EmployeeTravelRecord',$id);
|
||||||
$resp = $as->updateApprovalStatus('EmployeeTravelRecord',$id,2,1);
|
|
||||||
|
|
||||||
|
// Supervisor should approve first
|
||||||
|
$resp = $as->updateApprovalStatus('EmployeeTravelRecord',$id,$this->ids[1],1);
|
||||||
$this->assertNull($resp->getObject()[0]);
|
$this->assertNull($resp->getObject()[0]);
|
||||||
$this->assertEquals(1, $resp->getObject()[1]->active);
|
$this->assertEquals(1, $resp->getObject()[1]->active);
|
||||||
$this->assertEquals(1, $resp->getObject()[1]->level);
|
$this->assertEquals(1, $resp->getObject()[1]->level);
|
||||||
|
|
||||||
|
// Now if a an indirect supervisor try to approve it should fail
|
||||||
$resp = $as->updateApprovalStatus('EmployeeTravelRecord',$id,3,1);
|
$resp = $as->updateApprovalStatus('EmployeeTravelRecord',$id,$this->ids[2],1);
|
||||||
$this->assertEquals(\Classes\IceResponse::ERROR, $resp->getStatus());
|
$this->assertEquals(\Classes\IceResponse::ERROR, $resp->getStatus());
|
||||||
|
|
||||||
$resp = $as->updateApprovalStatus('EmployeeTravelRecord',$id,5,1);
|
// First approver approves
|
||||||
|
$resp = $as->updateApprovalStatus('EmployeeTravelRecord',$id,$this->ids[4],1);
|
||||||
$this->assertEquals(0, $resp->getObject()[0]->active);
|
$this->assertEquals(0, $resp->getObject()[0]->active);
|
||||||
$this->assertEquals(1, $resp->getObject()[0]->level);
|
$this->assertEquals(1, $resp->getObject()[0]->level);
|
||||||
$this->assertEquals(1, $resp->getObject()[1]->active);
|
$this->assertEquals(1, $resp->getObject()[1]->active);
|
||||||
$this->assertEquals(2, $resp->getObject()[1]->level);
|
$this->assertEquals(2, $resp->getObject()[1]->level);
|
||||||
|
|
||||||
$resp = $as->updateApprovalStatus('EmployeeTravelRecord',$id,6,1);
|
// Second approver approves
|
||||||
|
$resp = $as->updateApprovalStatus('EmployeeTravelRecord',$id,$this->ids[5],1);
|
||||||
$this->assertEquals(0, $resp->getObject()[0]->active);
|
$this->assertEquals(0, $resp->getObject()[0]->active);
|
||||||
$this->assertEquals(2, $resp->getObject()[0]->level);
|
$this->assertEquals(2, $resp->getObject()[0]->level);
|
||||||
$this->assertEquals(1, $resp->getObject()[1]->active);
|
$this->assertEquals(1, $resp->getObject()[1]->active);
|
||||||
$this->assertEquals(3, $resp->getObject()[1]->level);
|
$this->assertEquals(3, $resp->getObject()[1]->level);
|
||||||
|
|
||||||
$resp = $as->updateApprovalStatus('EmployeeTravelRecord',$id,7,1);
|
// Third approver approves
|
||||||
|
$resp = $as->updateApprovalStatus('EmployeeTravelRecord',$id,$this->ids[6],1);
|
||||||
$this->assertEquals(1, $resp->getObject()[0]->active);
|
$this->assertEquals(1, $resp->getObject()[0]->active);
|
||||||
$this->assertEquals(3, $resp->getObject()[0]->level);
|
$this->assertEquals(3, $resp->getObject()[0]->level);
|
||||||
$this->assertNull($resp->getObject()[1]);
|
$this->assertNull($resp->getObject()[1]);
|
||||||
|
|
||||||
|
|
||||||
fwrite(STDOUT, __METHOD__ . " End\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ if (!class_exists('SessionUtils')) {
|
|||||||
}
|
}
|
||||||
if (!class_exists('TestTemplate')) {
|
if (!class_exists('TestTemplate')) {
|
||||||
include(dirname(__FILE__).'/TestTemplate.php');
|
include(dirname(__FILE__).'/TestTemplate.php');
|
||||||
|
include(dirname(__FILE__).'/helper/EmployeeTestDataHelper.php');
|
||||||
include(APP_BASE_PATH."/includes.inc.php");
|
include(APP_BASE_PATH."/includes.inc.php");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
22
test/unit/BaseServiceUnit.php
Normal file
22
test/unit/BaseServiceUnit.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: Thilina
|
||||||
|
* Date: 9/6/17
|
||||||
|
* Time: 7:22 AM
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Test\Unit;
|
||||||
|
|
||||||
|
|
||||||
|
use Classes\BaseService;
|
||||||
|
|
||||||
|
class BaseServiceUnit extends \TestTemplate
|
||||||
|
{
|
||||||
|
public function testGet()
|
||||||
|
{
|
||||||
|
$baseService = BaseService::getInstance();
|
||||||
|
// create a user
|
||||||
|
//$user =
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user