示例#1
0
 /**
  * Testcase for testGetWorkshift().
  */
 public function testGetWorkshift()
 {
     // invalid id
     try {
         $workshift = Workshift::getWorkshift(null);
         $this->fail("Exception not thrown");
     } catch (WorkshiftException $e) {
         $this->assertEquals(WorkshiftException::INVALID_ID, $e->getCode());
     }
     // negative id
     try {
         $workshift = Workshift::getWorkshift(-1);
         $this->fail("Negative id!");
     } catch (WorkshiftException $e) {
         $this->assertEquals(WorkshiftException::INVALID_ID, $e->getCode());
     }
     // try sql injection in id
     // id not found in database
     try {
         $workshift = Workshift::getWorkshift("'{}");
         $this->fail("Invalid ID!");
     } catch (WorkshiftException $e) {
         $this->assertEquals(WorkshiftException::INVALID_ID, $e->getCode());
     }
     try {
         $workshift = Workshift::getWorkshift(16);
     } catch (WorkshiftException $e) {
         $this->assertEquals(WorkshiftException::WORKSHIFT_NOT_FOUND, $e->getCode());
     }
     // valid id
     $sql = "INSERT INTO " . Workshift::WORKSHIFT_TABLE . " VALUES ('3' , 'New Test Shift', '5')";
     $result = mysql_query($sql);
     $this->assertTrue($result);
     // Check whether the returned object is Workshift
     $workshift = Workshift::getWorkshift(3);
     $this->assertTrue($workshift instanceof Workshift);
     $this->assertEquals(3, $workshift->getWorkshiftId());
     $this->assertEquals("New Test Shift", $workshift->getName());
     $this->assertEquals(5, $workshift->getHoursPerDay());
 }
示例#2
0
 /**
  * View the worksheet edit page
  * @param int $id The workshift Id
  */
 public function viewEditWorkShift($id)
 {
     $path = "/templates/time/editWorkShift.php";
     try {
         $workshift = Workshift::getWorkshift($id);
         $objs[] = $workshift;
         $objs[] = $workshift->getAssignedEmployees();
         $objs[] = $workshift->getEmployeesWithoutWorkshift();
         $template = new TemplateMerger($objs, $path);
         $template->display();
     } catch (WorkshiftException $e) {
         switch ($e->getCode()) {
             case WorkshiftException::WORKSHIFT_NOT_FOUND:
                 $msg = 'INVALID_WORK_SHIFT_FAILURE';
                 break;
             default:
                 $msg = 'UNKNOWN_ERROR_FAILURE';
                 break;
         }
         $this->redirect($msg, '?timecode=Time&action=View_Work_Shifts');
     }
 }