/** * Test method for removeAssignedEmployees */ public function testRemoveAssignedEmployees() { // Callling remove assigned employees without setting valid workshift id $workshift = new Workshift(); try { $workshift->removeAssignedEmployees(); $this->fail("Trying to remove assigned employees without setting workshift id should throw exception"); } catch (WorkshiftException $e) { $this->assertEquals(WorkshiftException::INVALID_ID, $e->getCode()); } // remove assigned employees with non-existent workshift_id, shouldn't throw error $workshift = new Workshift(); $workshift->setWorkshiftId(4); $count = $workshift->removeAssignedEmployees(); $this->assertEquals(0, $count); $this->assertTrue(mysql_query("INSERT INTO " . Workshift::WORKSHIFT_TABLE . " VALUES ('1' , 'New Test Shift', '5')")); $this->assertTrue(mysql_query("INSERT INTO " . Workshift::WORKSHIFT_TABLE . " VALUES ('2' , 'Workshift 2', '10')")); $this->assertTrue(mysql_query("INSERT INTO " . Workshift::WORKSHIFT_TABLE . " VALUES ('3' , 'Workshift 3', '11')")); $this->assertTrue(mysql_query("INSERT INTO hs_hr_employee_workshift(workshift_id, emp_number) VALUES (1, 1)")); $this->assertTrue(mysql_query("INSERT INTO hs_hr_employee_workshift(workshift_id, emp_number) VALUES (2, 2)")); $this->assertTrue(mysql_query("INSERT INTO hs_hr_employee_workshift(workshift_id, emp_number) VALUES (2, 3)")); $count = $workshift->removeAssignedEmployees(); $this->assertEquals(0, $count); // check no assignments are deleted $this->assertEquals(3, $this->_countRows(Workshift::EMPLOYEE_WORKSHIFT_TABLE)); // Remove assigned employees when no employees are assigned - check no assignments are deleted $workshift->setWorkshiftId(3); $count = $workshift->removeAssignedEmployees(); $this->assertEquals(0, $count); $this->assertEquals(3, $this->_countRows(Workshift::EMPLOYEE_WORKSHIFT_TABLE)); // Remove assigned employees $workshift->setWorkshiftId(2); $count = $workshift->removeAssignedEmployees(); $this->assertEquals(2, $count); $this->assertEquals(1, $this->_countRows(Workshift::EMPLOYEE_WORKSHIFT_TABLE)); $this->assertEquals(1, $this->_countRows(Workshift::EMPLOYEE_WORKSHIFT_TABLE, "workshift_id = 1")); $workshift->setWorkshiftId(1); $count = $workshift->removeAssignedEmployees(); $this->assertEquals(1, $count); $this->assertEquals(0, $this->_countRows(Workshift::EMPLOYEE_WORKSHIFT_TABLE)); }