db = new MySQL(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB, new Debug()); } /** * From StatisticsRundaily.php */ public function testSimpleInsert() { $data = array(); $data['selection'] = "all"; $data['title'] = "Applications per day"; $data['image_height'] = 50; $data['image_width'] = 60; $query = $this->invokeMethod($this->db, "createInsertQuery", array("statistics", $data)); $this->assertEquals("INSERT INTO `statistics` (`selection`, `title`, `image_height`, `image_width`) VALUES ('all', 'Applications per day', 50, 60)", $query); } public function testInsertWithNull() { $data = array(); $data['field1'] = "value1"; $data['empty'] = NULL; $query = $this->invokeMethod($this->db, "createInsertQuery", array("table", $data)); $this->assertEquals("INSERT INTO `table` (`field1`, `empty`) VALUES ('value1', NULL)", $query); } public function testInsertWithPassword() { $data = array(); $data['field1'] = "value1"; $data['password'] = new DBMethodPassword("secret"); $query = $this->invokeMethod($this->db, "createInsertQuery", array("table", $data)); $this->assertEquals("INSERT INTO `table` (`field1`, `password`) VALUES ('value1', PASSWORD('secret'))", $query); } /** * From CurrenciesRundaily.php */ public function testSimpleUpdate() { $query = $this->invokeMethod($this->db, "createUpdateQuery", array("currencies", 1, array("rate" => 0.654))); $this->assertEquals("UPDATE `currencies` SET `rate` = 0.654 WHERE `id` = 1", $query); } /** * From UpdateBodiesRundaily.php */ public function testUpdateWithCustomId() { $updates = array(); $updates['bodyname'] = "Deleted body (AEGEE-Cool)"; $updates['bodystatus'] = "D"; $updates['bodycategory'] = -1; $query = $this->invokeMethod($this->db, "createUpdateQuery", array("ab_bodies", "XXX", $updates, "bodycode")); $this->assertEquals("UPDATE `ab_bodies` SET `bodyname` = 'Deleted body (AEGEE-Cool)', `bodystatus` = 'D', `bodycategory` = -1 WHERE `bodycode` = 'XXX'", $query); } public function testDeleteWithCustomId() { $query = $this->invokeMethod($this->db, "createDeleteQuery", array("ab_bodies", "XXX", "bodycode")); $this->assertEquals("DELETE FROM `ab_bodies` WHERE `bodycode` = 'XXX'", $query); } /** * From MemListRundaily.php */ public function testUpdateWithConcat() { $log = "addMe"; $updates = array(); $updates['memberlistconfirmed'] = "X"; $updates['log'] = new DBMethodConcatValue("log", $log); $query = $this->invokeMethod($this->db, "createUpdateQuery", array("applications", 1, $updates)); $this->assertEquals("UPDATE `applications` SET `memberlistconfirmed` = 'X', `log` = CONCAT(`log`, 'addMe') WHERE `id` = 1", $query); } private function invokeMethod(&$object, $methodName, array $parameters = array()) { $reflection = new ReflectionClass(get_class($object)); $method = $reflection->getMethod($methodName); $method->setAccessible(true); return $method->invokeArgs($object, $parameters); } } ?>