📄 projectreporttest.php
字号:
// Programming - Employee 1 $this->_addEvent(1, 1, "Programming", "2007-07-05 09:25", 80); $this->_addEvent(1, 1, "Programming", "2007-07-07 08:12", 70); $this->_addEvent(1, 1, "Programming", "2007-07-10 09:25", 210); // Programming - Employee 2 $this->_addEvent(1, 2, "Programming", "2007-07-05 09:25", 230); $this->_addEvent(1, 2, "Programming", "2007-07-12 11:25", 450); $this->_addEvent(1, 2, "Programming", "2007-07-11 06:25", 900); // Programming for different project $this->_addEvent(2, 1, "Programming", "2007-07-05 05:25", 800); $this->_addEvent(2, 2, "Programming", "2007-07-12 15:25", 450); // Event spanning more than one day $this->_addEvent(1, 1, "Programming", "2007-07-19 18:00", 600); $this->_addEvent(1, 2, "Programming", "2007-07-18 21:25", 500); // Deleted activity for project 2 $this->_addEvent(2, 1, "Deleted Activity", "2007-07-10 09:25", 400); $this->_addEvent(2, 2, "Deleted Activity", "2007-07-11 09:25", 300); //// Project 1 QA $activity = $this->activities[1]["QA"]; $activityId = $activity->getId(); $results = $report->getEmployeeActivityTime(1, $activityId, "2007-07-05", "2007-07-25"); $res = $this->_verifyEmployeeTime($results, 1, $activityId, array(1, 2), array(613, 570)); $this->assertTrue($res); // Without period $results = $report->getEmployeeActivityTime(1, $activityId); $res = $this->_verifyEmployeeTime($results, 1, $activityId, array(1, 2), array(613, 570)); $this->assertTrue($res); // Only from 07-10 $results = $report->getEmployeeActivityTime(1, $activityId, "2007-07-10", "2007-07-25"); $res = $this->_verifyEmployeeTime($results, 1, $activityId, array(1, 2), array(510, 500)); $this->assertTrue($res); //// Project 1 Programming $activity = $this->activities[1]["Programming"]; $activityId = $activity->getId(); $results = $report->getEmployeeActivityTime(1, $activityId, "2007-07-05", "2007-07-25"); $res = $this->_verifyEmployeeTime($results, 1, $activityId, array(1, 2), array(960, 2080)); $this->assertTrue($res); // Without period $results = $report->getEmployeeActivityTime(1, $activityId); $res = $this->_verifyEmployeeTime($results, 1, $activityId, array(1, 2), array(960, 2080)); $this->assertTrue($res); // Only from 07-10 $results = $report->getEmployeeActivityTime(1, $activityId, "2007-07-10", "2007-07-25"); $res = $this->_verifyEmployeeTime($results, 1, $activityId, array(1, 2), array(810, 1850)); $this->assertTrue($res); // On day with spanning events $results = $report->getEmployeeActivityTime(1, $activityId, "2007-07-19", "2007-07-19"); $res = $this->_verifyEmployeeTime($results, 1, $activityId, array(1, 2), array(360, 345)); $this->assertTrue($res); //// Project 1 Support $activity = $this->activities[1]["Support"]; $activityId = $activity->getId(); $results = $report->getEmployeeActivityTime(1, $activityId, "2007-07-05", "2007-07-25"); $this->assertTrue(is_array($results)); $this->assertEquals(0, count($results)); //// Project 2 Deleted Activity $activity = $this->activities[2]["Deleted Activity"]; $activityId = $activity->getId(); $results = $report->getEmployeeActivityTime(2, $activityId, "2007-07-10", "2007-07-11"); $res = $this->_verifyEmployeeTime($results, 2, $activityId, array(1, 2), array(400, 300)); $this->assertTrue($res); //// Project 2 QA $activity = $this->activities[2]["QA"]; $activityId = $activity->getId(); $results = $report->getEmployeeActivityTime(2, $activityId, "2007-07-05", "2007-07-25"); $res = $this->_verifyEmployeeTime($results, 2, $activityId, array(1, 2), array(490, 300)); $this->assertTrue($res); // Without period $results = $report->getEmployeeActivityTime(2, $activityId); $res = $this->_verifyEmployeeTime($results, 2, $activityId, array(1, 2), array(490, 300)); $this->assertTrue($res); // Only from 07-10 $results = $report->getEmployeeActivityTime(2, $activityId, "2007-07-10", "2007-07-25"); $this->assertTrue(is_array($results)); $this->assertEquals(0, count($results)); //// Project 2 Programming $activity = $this->activities[2]["Programming"]; $activityId = $activity->getId(); $results = $report->getEmployeeActivityTime(2, $activityId, "2007-07-05", "2007-07-25"); $res = $this->_verifyEmployeeTime($results, 2, $activityId, array(1, 2), array(800, 450)); $this->assertTrue($res); // Without period $results = $report->getEmployeeActivityTime(2, $activityId); $res = $this->_verifyEmployeeTime($results, 2, $activityId, array(1, 2), array(800, 450)); $this->assertTrue($res); // Only from 07-12 $results = $report->getEmployeeActivityTime(2, $activityId, "2007-07-12", "2007-07-25"); $res = $this->_verifyEmployeeTime($results, 2, $activityId, array(2), array(450)); $this->assertTrue($res); } /** * test getEmployeeActivityTime() method */ public function testGetEmployeeActivityTimePaging() { $report = new ProjectReport(); // Add some extra employees for ($i=4; $i<30; $i++) { $empId = str_pad($i, 3, "0", STR_PAD_LEFT); $this->_addEmployee($i, $empId, "Test Employee $i", "First Name $i"); } $times = array(); $empIds = array(); // Add events for all employees for ($i=1; $i<30; $i++) { $this->_addEvent(1, $i, "Programming", "2007-07-05 05:50", $i * 10); $this->_addEvent(1, $i, "Programming", "2007-07-12 15:25", $i * 5); $times[$i] = $i * 10 + $i * 5; } $activity = $this->activities[1]["Programming"]; $activityId = $activity->getId(); $sysConf = new sysConf(); $pageSize = $sysConf->itemsPerPage; $timeValues = array_chunk($times, $pageSize); $empIds = array_chunk(range(1,29), $pageSize); for ($page = 0; $page < count($timeValues); $page++) { $results = $report->getEmployeeActivityTime(1, $activityId, "2007-07-05", "2007-07-12", $page + 1); $res = $this->_verifyEmployeeTime($results, 1, $activityId, $empIds[$page], $timeValues[$page]); $this->assertTrue($res); } } /** * Test for countEmployeesInActivity() method. */ public function testCountEmployeesInActivity() { $report = new ProjectReport(); $activity = $this->activities[1]["Programming"]; $activityId = $activity->getId(); $this->assertEquals(0, $report->countEmployeesInActivity(1, $activityId, "2007-07-05", "2007-07-12")); $this->_addEvent(1, 1, "Programming", "2007-07-05 09:25", 80); $this->_addEvent(1, 1, "Programming", "2007-07-07 08:12", 70); $this->_addEvent(1, 1, "Programming", "2007-07-10 09:25", 210); $this->assertEquals(1, $report->countEmployeesInActivity(1, $activityId, "2007-07-05", "2007-07-06")); $this->assertEquals(1, $report->countEmployeesInActivity(1, $activityId, "2007-07-05", "2007-07-12")); $this->_addEvent(1, 2, "Programming", "2007-07-25 09:25", 80); $this->assertEquals(1, $report->countEmployeesInActivity(1, $activityId, "2007-07-05", "2007-07-20")); $this->assertEquals(2, $report->countEmployeesInActivity(2, $activityId, "2007-07-05", "2007-07-30")); // Add some extra employees for ($i=1; $i<=30; $i++) { $id = $i + 3; $empId = str_pad($id, 3, "0", STR_PAD_LEFT); $this->_addEmployee($id, $empId, "Test Employee $id", "First Name $id"); $this->_addEvent(1, $id, "Programming", "2007-07-05 05:50", $id * 10); $this->_addEvent(1, $id, "Programming", "2007-07-12 15:25", $id * 5); } $this->assertEquals(32, $report->countEmployeesInActivity(2, $activityId, "2007-07-05", "2007-07-30")); } //------------------------------------------------------------------------- // Private methods and their tests //------------------------------------------------------------------------- /** * Tests the _count method */ public function testCount() { $this->_runQuery("TRUNCATE table hs_hr_project_activity"); $this->assertEquals(0, $this->_count("hs_hr_project_activity")); $this->_runQuery("INSERT INTO hs_hr_project_activity(activity_id, project_id, name, deleted) " . "VALUES(1, 1, 'Programming', 0)"); $this->assertEquals(1, $this->_count("hs_hr_project_activity")); $this->_runQuery("INSERT INTO hs_hr_project_activity(activity_id, project_id, name, deleted) " . "VALUES(2, 2, 'QA', 0)"); $this->assertEquals(2, $this->_count("hs_hr_project_activity")); $this->_runQuery("INSERT INTO hs_hr_project_activity(activity_id, project_id, name, deleted) " . "VALUES(3, 2, 'Meetings', 0)"); $this->assertEquals(3, $this->_count("hs_hr_project_activity")); $this->assertEquals(1, $this->_count("hs_hr_project_activity", "activity_id = 1")); $this->assertEquals(2, $this->_count("hs_hr_project_activity", "project_id = 2")); $this->assertEquals(1, $this->_count("hs_hr_project_activity", "name = 'Meetings'")); $this->assertEquals(0, $this->_count("hs_hr_project_activity", "name = 'Test'")); } /** * Tests the _addCustomer private method. */ public function testAddCustomer() { $this->assertEquals(1, $this->_count("hs_hr_customer")); $this->customerId = 2; $this->customerName = "Qwerty"; $this->_addCustomer(); $this->assertEquals(2, $this->_count("hs_hr_customer")); $this->assertEquals(1, $this->_count("hs_hr_customer", "name = '{$this->customerName}'")); } /** * Tests the _addProjects method */ public function testAddProjects() { $this->assertEquals(2, $this->_count("hs_hr_project")); $this->projects = array( 3 => "Project X", 4 => "Project Y"); $this->_addProjects(); $this->assertEquals(4, $this->_count("hs_hr_project")); $this->assertEquals(1, $this->_count("hs_hr_project", "name = 'Project X'")); $this->assertEquals(1, $this->_count("hs_hr_project", "name = 'Project Y'")); } /** * Tests the _addActivity method */ public function testAddActivity() { $this->activities = null; $count = $this->_count("hs_hr_project_activity"); $this->_addActivity(1, "Test1"); $this->assertEquals(1, $this->_count("hs_hr_project_activity", "name = 'Test1' and deleted = 0")); $this->assertTrue(isset($this->activities[1])); $this->assertTrue(isset($this->activities[1]['Test1'])); $this->_addActivity(1, "Test2", true); $this->assertEquals(1, $this->_count("hs_hr_project_activity", "name = 'Test2' and deleted = 1")); $this->assertTrue(isset($this->activities[1]['Test2'])); $this->assertEquals($count + 2, $this->_count("hs_hr_project_activity")); } /** * Tests the _addEmployee method */ public function testAddEmployee() { $count = $this->_count("hs_hr_employee"); $this->_addEmployee(10, "0010", "Ranasinghe", "Ruwan"); $this->assertEquals($count + 1, $this->_count("hs_hr_employee")); $this->assertEquals(1, $this->_count("hs_hr_employee", "emp_number = 10")); } /** * Tests the _addEvent method */ public function testAddEvent() { $this->assertEquals(0, $this->_count("hs_hr_time_event")); $this->_addEvent(1, 1, "Programming", "2006-12-02 10:20", 19); $this->assertEquals(1, $this->_count("hs_hr_time_event")); $activity = $this->activities[1]['Programming']; $activityId = $activity->getId(); $this->assertEquals(1, $this->_count("hs_hr_time_event", "activity_id = $activityId")); $this->assertEquals(1, $this->_count("hs_hr_time_event", "start_time BETWEEN '2006-12-02 10:20' AND '2006-12-02 10:39'")); } public function testGetNextId() { $this->assertEquals(2, $this->_getNextId("hs_hr_customer", "customer_id")); $this->customerId = 5; $this->customerName = "Qwerty"; $this->_addCustomer(); $this->assertEquals(6, $this->_getNextId("hs_hr_customer", "customer_id")); } /** * Test the CalculateDuration method */ public function testCalculateDuration() { $this->assertEquals(3600, $this->_calculateDuration("2007-01-01 10:45", "2007-01-01 11:45")); $this->assertEquals(60, $this->_calculateDuration("2007-06-01 10:45", "2007-06-01 10:46")); } public function testGetEndTime() { $this->assertEquals("2007-01-01 11:45", $this->_getEndTime("2007-01-01 10:45", 3600)); $this->assertEquals("2007-06-01 10:46", $this->_getEndTime("2007-06-01 10:45", 60)); } /** * Tests the _getTimesheetId method */ public function testGetTimesheetId() { // 2007-5-12 -> prev monday = 14, next sunday = 20 $this->assertEquals(0, $this->_count("hs_hr_timesheet")); $id = $this->_getTimesheetId(1, "2007-5-15 10:10", "2007-5-15 11:20"); $this->assertEquals(1, $this->_count("hs_hr_timesheet")); $this->assertEquals(1, $this->_count("hs_hr_timesheet", "DATE(start_date) = DATE('2007-05-14') AND DATE(end_date) = DATE('2007-05-20')")); // Add another timesheet for same period $id2 = $this->_getTimesheetId(1, "2007-5-16 10:00", "2007-5-16 11:20"); $this->assertEquals(1, $this->_count("hs_hr_timesheet")); $this->assertEquals($id, $id2); // Add timesheet for different period $id3 = $this->_getTimesheetId(1, "2007-5-23 10:00", "2007-5-23 11:20"); $this->assertEquals(2, $this->_count("hs_hr_timesheet")); $this->assertNotEquals($id, $id3); } /** * Tests the _verifyActivityTime method */ public function testVerifyActivityTime() { $results[] = new ProjectActivityTime(1, "Programming", 3600, 1); $this->assertTrue($this->_verifyActivityTime($results, 1, array("Programming"), array(3600/60))); // Wrong name $this->assertFalse($this->_verifyActivityTime($results, 1, array("QA"), array(3600/60))); // Wrong time $this->assertFalse($this->_verifyActivityTime($results, 1, array("Programming"), array(120))); // Wrong project id $this->assertTrue($this->_verifyActivityTime($results, 2, array("Programming"), array(3600/60))); $results = array(); $results[] = new ProjectActivityTime(1, "Programming", 4800, 1); $results[] = new ProjectActivityTime(2, "QA", 2400, 1); $results[] = new ProjectActivityTime(3, "Support", 1800, 1); $this->assertTrue($this->_verifyActivityTime($results, 1, array("QA", "Programming", "Support"), array(2400/60, 4800/60, 1800/60))); // One time incorrect $this->assertFalse($this->_verifyActivityTime($results, 1, array("QA", "Programming", "Support"), array(2400/60, 4800/60, 2400/60))); // All results not given $this->assertFalse($this->_verifyActivityTime($results, 1, array("QA", "Programming"), array(2400/60, 4800/60))); // Wrong project Id $this->assertFalse($this->_verifyActivityTime($results, 2, array("QA", "Programming", "Support"), array(2400/60, 4800/60, 2400/60))); // One activity wrong $this->assertFalse($this->_verifyActivityTime($results, 1, array("QA", "Program", "Support"), array(2400/60, 4800/60, 2400/60))); $this->assertFalse($this->_verifyActivityTime($results, 1, array("QA", "Misc", "Support"), array(2400/60, 4800/60, 2400/60))); // Extra activity given $this->assertFalse($this->_verifyActivityTime($results, 1, array("QA", "Programming", "Support", "Misc"), array(2400/60, 4800/60, 1800/60, 1800/60))); } /** * Tests the _verifyEmployeeTime method */ public function testVerifyEmployeeTime() { $activity = $this->activities[1]["QA"]; $activityId = $activity->getId(); $results = array(new EmployeeActivityTime(1, "John", "Rajasinghe", $activityId, "QA", 250 * 60)); $this->assertTrue($this->_verifyEmployeeTime($results, 1, $activityId, array(1), array(250))); // Wrong employee
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -