function testdbRoomLogsModule() { // Creates some room logs to add to the database $today = date('y-m-d'); $roomLog1 = new RoomLog($today); $roomLog2 = new RoomLog("11-02-07"); // Alter the status and log notes of a room $roomLog2->set_log_notes("Room Log 2"); $roomLog2->set_status("archived"); // test the insert function $this->assertTrue(insert_dbRoomLog($roomLog1)); $this->assertTrue(insert_dbRoomLog($roomLog2)); // test the retrieve function $this->assertEqual(retrieve_dbRoomLog($roomLog1->get_id())->get_status(), "unpublished"); $this->assertEqual(retrieve_dbRoomLog($roomLog2->get_id())->get_status(), "archived"); // test the update function $roomLog1->set_log_notes("Room Log 1 notes"); $this->assertTrue(update_dbRoomLog($roomLog1)); $this->assertEqual(retrieve_dbRoomLog($roomLog1->get_id())->get_log_notes(), "Room Log 1 notes"); // test the delete function $this->assertTrue(delete_dbRoomLog($roomLog1->get_id())); $this->assertFalse(retrieve_dbRoomLog($roomLog1->get_id())); $this->assertTrue(delete_dbRoomLog($roomLog2->get_id())); echo "testdbRoomLogs complete"; }
function testRoomLogModule() { // Generate a new room log $rl = new RoomLog("11-02-07"); // make a time that was given to the constructor. This will // be used for testing $test_time = mktime(0, 0, 0, 02, 07, 2011); $this->assertEqual($rl->get_id(), date("y-m-d", $test_time)); $this->assertEqual($rl->get_day_of_month(), date("d", $test_time)); $this->assertEqual($rl->get_day(), date("D", $test_time)); $this->assertEqual($rl->get_day_of_week(), date("N", $test_time)); $this->assertEqual($rl->get_day_of_year(), date("z", $test_time) + 1); $this->assertEqual($rl->get_year(), date("Y", $test_time)); $this->assertEqual($rl->get_status(), "unpublished"); $this->assertEqual(sizeof($rl->get_rooms()), 21); $this->assertEqual($rl->get_name(), "February 7, 2011"); // New date for testing that has seconds/hours/minutes $test_end_time = mktime(23, 59, 59, 02, 07, 2011); $this->assertEqual($rl->get_end_time(), $test_end_time); // Set some log notes $rl->set_log_notes("Some notes"); $this->assertTrue(strcmp($rl->get_log_notes(), "Some notes") == 0); echo "testRoomLog complete"; }
function retrieve_mostrecent_dbRoomLog($date) { // connect to the mysql server connect(); // Retrieve the entry $query = "SELECT * FROM dbRoomLogs WHERE id <='" . $date . "' ORDER BY id DESC"; $result = mysql_query($query); // check if successful if (mysql_num_rows($result) == 0) { mysql_close(); return false; } // Store the first row of the result = the most recent room log $result_row = mysql_fetch_assoc($result); mysql_close(); // Create a new room log from the information given $theRoomLog = new RoomLog($result_row['id']); // Replace the rooms in the room log $roomsString = $result_row['rooms']; $rooms = explode(",", $roomsString); $theRoomLog->set_rooms($rooms); // Add extra information if present if ($result_row['log_notes']) { $theRoomLog->set_log_notes($result_row['log_notes']); } if ($result_row['status']) { $theRoomLog->set_status($result_row['status']); } // return the roomlog return $theRoomLog; }