public function testActiveRecordFunctioning() { //OK FUNZIONA $this->assertTrue(ActiveRecord::has_table_for_class("Simple2")); $this->assertTrue(ActiveRecord::get_table_for_class("Simple2"), "simple2_table"); //NON FUNZIONA $this->assertEqual(count(ActiveRecord::getPrimaryKeyFields("Simple2")), 1); $pk_fields = ActiveRecord::getPrimaryKeyFields("Simple2"); $this->assertEqual($pk_fields[0], "id"); //NON FUNZIONA $this->assertTrue(ActiveRecord::has_field_for_class("Simple2", "id")); $this->assertTrue(ActiveRecord::has_field_for_class("Simple2", "nome")); $this->assertTrue(ActiveRecord::has_field_for_class("Simple2", "livello")); $this->assertTrue(ActiveRecord::has_field_for_class("Simple2", "properties")); $this->assertTrue(ActiveRecord::has_field_for_class("Simple2", "working")); }
public function testCreateSaveDelete() { $this->assertTrue(ActiveRecord::has_field_for_class("Simple", "id")); $peer = new SimplePeer(); $do = $peer->new_do(); $do->id = 1; $do->nome = "Paolino Paperino"; $do->livello = 16; $peer = new SimplePeer(); $objects = $peer->find_all(); $this->assertEqual(count($objects), 0); $peer->save($do); $objects = $peer->find_all(); $this->assertEqual(count($objects), 1); $ob = $objects[0]; $this->assertEqual($ob->id, 1); $this->assertEqual($ob->nome, "Paolino Paperino"); $this->assertEqual($ob->livello, 16); $peer->delete_by_id(1); $objects = $peer->find_all(); $this->assertEqual(count($objects), 0); }
public function __find_all_by__($method, $args) { $original_method = $method; $method = str_replace("find_all_by_", "", $method); $field_list = explode("_AND_", $method); if (count($args) != count($field_list)) { Log::error(__METHOD__, "Il numero dei campi non corrisponde : {$original_method}"); } $table = $this->__getMyTable(); $raw_class_name = $this->__getRawClassName(); $ss = DB::newSelect($table); $i = 0; foreach ($field_list as $field) { if (!ActiveRecord::has_field_for_class($raw_class_name, $field)) { throw new Exception("Il campo '{$field}' non e' presente nella tabella '{$table}', raw class name " . $raw_class_name . " :" . ActiveRecord::print_fields_for_class($raw_class_name) . " - " . ActiveRecord::print_tables()); } $ss->addConditionEquals($field, $args[$i]); $i++; } return $this->__load_into_objects($ss); }