27 $db = db::raw_connect();
36 $value1 =
$db->drop_table(
"kumbia_test");
38 throw new DbException(
"No se pudo crear la tabla de prueba (1)");
42 "type" => db::TYPE_INTEGER,
48 "type" => db::TYPE_VARCHAR,
53 "type" => db::TYPE_DATE,
56 "type" => db::TYPE_VARCHAR,
60 "type" => db::TYPE_INTEGER,
64 throw new DbException(
"No se pudo crear la tabla de prueba (2)");
66 if(!
$db->table_exists(
"kumbia_test")){
67 throw new DbException(
"No se pudo comprobar la existencia de la tabla de prueba (3)");
71 eval(
"class KumbiaTest extends ActiveRecord {
73 function __construct(){
74 \$this->validates_numericality_of('numero');
75 \$this->validates_presence_of('numero');
76 \$this->validates_email_in('email');
77 \$this->validates_date_in('fecha');
78 \$this->validates_uniqueness_of('texto');
82 unset($_SESSION[
'KUMBIA_META_DATA'][$_SESSION[
'KUMBIA_PATH']][
"kumbia_test"]);
84 if(!is_subclass_of(
$model,
"ActiveRecord")){
85 throw new DbException(
"No se pudo crear el modelo de prueba (3)");
91 print
"<div style='background:#FFBBBB;border:1px solid red'>";
92 print
"Test '$test_name' (FALLÓ) con mensaje: ({$e->getMessage()})";
97 print
"<div style='background:#CCFF99;border:1px solid green'>";
98 print
"Test '$test_name' (OK) con tiempo: ({$end_benckmark})";
104 $test_name =
"INSERTAR DATOS DE PRUEBA EN EL MODELO";
108 for($i=1;$i<=20;$i++){
109 $model->texto =
"Texto ".$i;
110 $model->fecha =
"2007-02-".sprintf(
"%02d", rand(1, 10));
111 $model->email =
"kumbia@com";
112 $model->numero = rand(0, 5);
118 print
"<div style='background:#FFBBBB;border:1px solid red'>";
119 print
"Test '$test_name' (FALLÓ) con mensaje: ({$e->getMessage()})";
124 print
"<div style='background:#CCFF99;border:1px solid green'>";
125 print
"Test '$test_name' (OK) con tiempo: ({$end_benckmark})";
130 $test_name =
"ACTUALIZAR DATOS DE PRUEBA EN EL MODELO";
133 for($i=1;$i<=20;$i+=5){
139 throw new DbException(
"No Devolvio el objeto para id = $i");
142 $model->update_all(
"email = 'hello@com'");
143 $model->update_all(
"texto = 'otro texto'",
"id <= 10");
147 print
"<div style='background:#FFBBBB;border:1px solid red'>";
148 print
"Test '$test_name' (FALLÓ) con mensaje: ({$e->getMessage()})";
153 print
"<div style='background:#CCFF99;border:1px solid green'>";
154 print
"Test '$test_name' (OK) con tiempo: ({$end_benckmark})";
160 $test_name =
"CONSULTAR DATOS DE PRUEBA EN EL MODELO";
163 $model =
new KumbiaTest();
167 throw new DbException(
"No devolvio el numero correcto de registros en la tabla (1)");
171 throw new DbException(
"No devolvio el registro correcto para id = 11 (2)");
175 throw new DbException(
"No devolvio el registro correcto para id = 11 (3)");
177 $model->find(
"numero = 100");
179 throw new DbException(
"No devolvio el numero correcto de registros en la tabla (4)");
183 throw new DbException(
"No devolvio el registro correcto al ordenar (5)");
186 throw new DbException(
"No devolvio el numero de registros correcto al ordenar (6)");
188 $results =
$model->find(
"conditions: numero = 100",
"limit: 1",
"order: id asc");
190 throw new DbException(
"No devolvio el registro correcto cuando se uso limit y ordenamiento (7)");
193 throw new DbException(
"No devolvio el registro correcto cuando se uso limit y ordenamiento {$results[0]->id} (8)");
197 throw new DbException(
"No devolvio el minimum correcto (9)");
201 throw new DbException(
"No devolvio el maximum correcto (10)");
205 throw new DbException(
"No devolvio el sum correcto (11)");
209 throw new DbException(
"No devolvio el avg correcto (12)");
211 $model->find_first(
"numero = 100");
213 throw new DbException(
"find_first con condicion fallo (13)");
217 throw new DbException(
"find_first a llave primaria (14)");
221 throw new DbException(
"find_first a condicion (15)");
224 throw new DbException(
"count sin parametros (16)");
226 if(
$model->count(
"numero = 100")!=4){
227 throw new DbException(
"count con parametros (17)");
229 if(count(
$model->distinct(
"id",
"conditions: numero = 100"))!=4){
230 throw new DbException(
"fallo distinct (18)");
232 $rows =
$model->find_all_by_sql(
"SELECT * FROM kumbia_test WHERE id > 11 AND id < 14 ORDER BY 1");
233 if(
$rows[0]->
id!=12){
234 throw new DbException(
"fallo find_all_by_sql (19)");
236 $row =
$model->find_by_sql(
"SELECT * FROM kumbia_test WHERE id > 11 AND id < 13 ORDER BY 1");
238 throw new DbException(
"fallo find_by_sql (20)");
240 if(count(
$model->find_all_by_numero(100))!=4){
241 throw new DbException(
"fallo find_all_by_numero (21)");
245 throw new DbException(
"fallo find_by_id (22)");
249 throw new DbException(
"fallo find_by_id (22)");
254 print
"<div style='background:#FFBBBB;border:1px solid red'>";
255 print
"Test '$test_name' (FALLÓ) con mensaje: ({$e->getMessage()})";
261 print
"<div style='background:#CCFF99;border:1px solid green'>";
262 print
"Test '$test_name' (OK) con tiempo: ({$end_benckmark})";
267 $test_name =
"ELIMINAR REGISTROS DE PRUEBA EN EL MODELO";
271 $model->delete_all(
"id < 10");
276 print
"<div style='background:#FFBBBB;border:1px solid red'>";
277 print
"Test '$test_name' (FALLÓ) con mensaje: ({$e->getMessage()})";
282 print
"<div style='background:#CCFF99;border:1px solid green'>";
283 print
"Test '$test_name' (OK) con tiempo: ({$end_benckmark})";
288 print
"<div style='background:#CCFF99;border:1px solid green'>";
289 print
"<strong>Tiempo total de los Test ".(microtime(
true) -
$init_time).
"</strong>";