function testdbLoanersModule() { //creates some loaners to add to the database $loaner1 = new Loaner("remote3", "remote", "available", null); $loaner2 = new Loaner("remote4", "remote", "available", null); // tests the insert function $this->assertTrue(insert_dbLoaners($loaner1)); $this->assertTrue(insert_dbLoaners($loaner2)); //tests the retrieve function $this->assertEqual(retrieve_dbLoaners($loaner1->get_id())->get_id(), "remote3"); $this->assertEqual(retrieve_dbLoaners($loaner1->get_id())->get_type(), "remote"); $this->assertEqual(retrieve_dbLoaners($loaner1->get_id())->get_status(), "available"); $this->assertEqual(retrieve_dbLoaners($loaner1->get_id())->get_booking_id(), null); //tests the update function $loaner1->check_out("11-02-07Meghan2077291234"); $this->assertEqual(retrieve_dbLoaners($loaner1->get_id())->get_status(), "inuse"); $this->assertEqual(retrieve_dbLoaners($loaner1->get_id())->get_booking_id(), "11-02-07Meghan2077291234"); //tests the delete function $this->assertTrue(delete_dbLoaners($loaner1->get_id())); $this->assertTrue(delete_dbLoaners($loaner2->get_id())); $this->assertFalse(retrieve_dbLoaners($loaner2->get_id())); echo "testdbLoaners complete"; }
/** * Updates a loaner in the dbLoaners table by deleting it and re-inserting it * @param $loaner the week to update */ function update_dbLoaners($loaner) { if (!$loaner instanceof Loaner) { echo "Invalid argument for update_dbLoaners function call"; return false; } if (delete_dbLoaners($loaner->get_id())) { return insert_dbLoaners($loaner); } else { echo mysql_error() . "unable to update dbLoaners table: " . $loaner->get_id(); return false; } }