📄 timesheettest.php
字号:
$this->assertFalse($res); } public function testCancelTimesheet1() { $timesheetObj = $this->classTimesheet; $timesheetObj->setTimesheetId(11); $timesheets = $timesheetObj->fetchTimesheets(); $res = $timesheets[0]->cancelTimesheet(); $this->assertTrue($res); $timesheetObj->setTimesheetId(11); $res = $timesheetObj->fetchTimesheets(); $this->assertNotNull($res, "Returned non existing record"); $expected[0]= array(11, 10, 10, date('Y-m-d', time()+3600*24*7), date('Y-m-d', time()+3600*24*7*2), 0); $this->assertEquals(count($res), count($expected), "Returned invalid number of records"); for ($i=0; $i<count($res); $i++) { $this->assertEquals($expected[$i][0], $res[$i]->getTimesheetId(), "Invalid Timesheet id"); $this->assertEquals($expected[$i][1], $res[$i]->getEmployeeId(), "Invalid Employee id"); $this->assertEquals($expected[$i][2], $res[$i]->getTimesheetPeriodId(), "Invalid Timesheet period id"); $this->assertEquals($expected[$i][3], $res[$i]->getStartDate(), "Invalid Start date"); $this->assertEquals($expected[$i][4], $res[$i]->getEndDate(), "Invalid End date"); $this->assertEquals($expected[$i][5], $res[$i]->getStatus(), "Invalid Status"); } } public function testApproveTimesheet() { $timesheetObj = $this->classTimesheet; $timesheetObj->setTimesheetId(10); $timesheets = $timesheetObj->fetchTimesheets(); $res = $timesheets[0]->approveTimesheet(); $this->assertFalse($res); } public function testApproveTimesheet1() { $timesheetObj = $this->classTimesheet; $timesheetObj->setTimesheetId(11); $timesheets = $timesheetObj->fetchTimesheets(); $timesheets[0]->setComment('Testing...'); $res = $timesheets[0]->approveTimesheet(); $this->assertTrue($res); $timesheetObj->setTimesheetId(11); $res = $timesheetObj->fetchTimesheets(); $this->assertNotNull($res, "Returned non existing record"); $expected[0]= array(11, 10, 10, date('Y-m-d', time()+3600*24*7), date('Y-m-d', time()+3600*24*7*2), 20, 'Testing...'); $this->assertEquals(count($res), count($expected), "Returned invalid number of records"); for ($i=0; $i<count($res); $i++) { $this->assertEquals($expected[$i][0], $res[$i]->getTimesheetId(), "Invalid Timesheet id"); $this->assertEquals($expected[$i][1], $res[$i]->getEmployeeId(), "Invalid Employee id"); $this->assertEquals($expected[$i][2], $res[$i]->getTimesheetPeriodId(), "Invalid Timesheet period id"); $this->assertEquals($expected[$i][3], $res[$i]->getStartDate(), "Invalid Start date"); $this->assertEquals($expected[$i][4], $res[$i]->getEndDate(), "Invalid End date"); $this->assertEquals($expected[$i][5], $res[$i]->getStatus(), "Invalid Status"); $this->assertEquals($expected[$i][6], $res[$i]->getComment(), "Invalid Comment"); } } public function testRejectTimesheet() { $timesheetObj = $this->classTimesheet; $timesheetObj->setTimesheetId(10); $timesheets = $timesheetObj->fetchTimesheets(); $res = $timesheets[0]->rejectTimesheet(); $this->assertFalse($res); } public function testRejectTimesheet2() { $timesheetObj = $this->classTimesheet; $timesheetObj->setTimesheetId(11); $timesheets = $timesheetObj->fetchTimesheets(); $res = $timesheets[0]->rejectTimesheet(); $this->assertTrue($res); $timesheetObj->setTimesheetId(11); $res = $timesheetObj->fetchTimesheets(); $this->assertNotNull($res, "Returned non existing record"); $expected[0]= array(11, 10, 10, date('Y-m-d', time()+3600*24*7), date('Y-m-d', time()+3600*24*7*2), 30); $this->assertEquals(count($res), count($expected), "Returned invalid number of records"); for ($i=0; $i<count($res); $i++) { $this->assertEquals($expected[$i][0], $res[$i]->getTimesheetId(), "Invalid Timesheet id"); $this->assertEquals($expected[$i][1], $res[$i]->getEmployeeId(), "Invalid Employee id"); $this->assertEquals($expected[$i][2], $res[$i]->getTimesheetPeriodId(), "Invalid Timesheet period id"); $this->assertEquals($expected[$i][3], $res[$i]->getStartDate(), "Invalid Start date"); $this->assertEquals($expected[$i][4], $res[$i]->getEndDate(), "Invalid End date"); $this->assertEquals($expected[$i][5], $res[$i]->getStatus(), "Invalid Status"); } } public function testAddTimesheet() { $timesheetObj = $this->classTimesheet; $timesheetObj->setEmployeeId(10); $timesheetObj->setTimesheetPeriodId(10); $timesheetObj->setStartDate(date('Y-m-d', time()+3600*24*7*4)); $timesheetObj->setEndDate(date('Y-m-d', time()+3600*24*7*5)); $timesheetObj->addTimesheet(); $expectedId = $timesheetObj->getTimesheetId(); $res = $timesheetObj->fetchTimesheets(); $this->assertNotNull($res, "Returned non existing record"); $expected[0]= array($expectedId, 10, 10, date('Y-m-d', time()+3600*24*7*4), date('Y-m-d', time()+3600*24*7*5), 0); $this->assertEquals(count($res), count($expected), "Returned invalid number of records"); for ($i=0; $i<count($res); $i++) { $this->assertEquals($expected[$i][0], $res[$i]->getTimesheetId(), "Invalid Timesheet id"); $this->assertEquals($expected[$i][1], $res[$i]->getEmployeeId(), "Invalid Employee id"); $this->assertEquals($expected[$i][2], $res[$i]->getTimesheetPeriodId(), "Invalid Timesheet period id"); $this->assertEquals($expected[$i][3], $res[$i]->getStartDate(), "Invalid Start date"); $this->assertEquals($expected[$i][4], $res[$i]->getEndDate(), "Invalid End date"); $this->assertEquals($expected[$i][5], $res[$i]->getStatus(), "Invalid Status"); } } public function testAddTimesheet2() { $timesheetObj = $this->classTimesheet; $timesheetObj->setEmployeeId(10); $timesheetObj->setTimesheetPeriodId(10); $timesheetObj->addTimesheet(); $expectedId = $timesheetObj->getTimesheetId(); $res = $timesheetObj->fetchTimesheets(); $this->assertNotNull($res, "Returned non existing record"); $day=date("w"); $expected[0]= array($expectedId, 10, 1, date('Y-m-d', time()+3600*24*(1-$day)), date('Y-m-d', time()+3600*24*(7-$day)), 0); $this->assertEquals(count($res), count($expected), "Returned invalid number of records"); for ($i=0; $i<count($res); $i++) { $this->assertEquals($expected[$i][0], $res[$i]->getTimesheetId(), "Invalid Timesheet id"); $this->assertEquals($expected[$i][1], $res[$i]->getEmployeeId(), "Invalid Employee id"); $this->assertEquals($expected[$i][2], $res[$i]->getTimesheetPeriodId(), "Invalid Timesheet period id"); $this->assertEquals($expected[$i][3], $res[$i]->getStartDate(), "Invalid Start date (FIXME: test fails on sundays!)"); $this->assertEquals($expected[$i][4], $res[$i]->getEndDate(), "Invalid End date"); $this->assertEquals($expected[$i][5], $res[$i]->getStatus(), "Invalid Status"); } } public function testFetchTimesheetId() { $timesheetObj = $this->classTimesheet; $timesheetObj->setEmployeeId(10); $timesheetObj->setStartDate(date('Y-m-d')); $timesheetObj->setEndDate(date('Y-m-d', time()+3600*24*6)); $timesheetObj->setStatus(Timesheet::TIMESHEET_STATUS_SUBMITTED); $res = $timesheetObj->fetchTimesheetId(Timesheet::TIMESHEET_DIRECTION_PREV); $this->assertFalse($res, 'Invalid id returned'); } public function testFetchTimesheetId1() { $timesheetObj = $this->classTimesheet; $timesheetObj->setEmployeeId(10); $timesheetObj->setStartDate(date('Y-m-d')); $timesheetObj->setEndDate(date('Y-m-d', time()+3600*24*6)); $timesheetObj->setStatus(Timesheet::TIMESHEET_STATUS_SUBMITTED); $res = $timesheetObj->fetchTimesheetId(Timesheet::TIMESHEET_DIRECTION_NEXT); $this->assertEquals(11, $res, 'Invalid id returned'); } public function testFetchTimesheetId2() { $timesheetObj = $this->classTimesheet; $timesheetObj->setEmployeeId(10); $timesheetObj->setStartDate(date('Y-m-d', time()+3600*24*7*1+3600*24*6)); $timesheetObj->setEndDate(date('Y-m-d', time()+3600*24*7*3)); $timesheetObj->setStatus(Timesheet::TIMESHEET_STATUS_SUBMITTED); $res = $timesheetObj->fetchTimesheetId(Timesheet::TIMESHEET_DIRECTION_PREV); $this->assertEquals(11, $res, 'Invalid id returned'); }}// Call TimesheetTest::main() if this source file is executed directly.if (PHPUnit_MAIN_METHOD == "TimesheetTest::main") { TimesheetTest::main();}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -