Skip to content
Extraits de code Groupes Projets
Valider 3c8195c6 rédigé par cerdic's avatar cerdic Validation de marcimat
Parcourir les fichiers

tests: fix différents petits glitch (on ne peut pas tester !== partout n'en...

tests: fix différents petits glitch (on ne peut pas tester !== partout n'en déplaise aux outils de lint) + typages sur les tests legacy sql
parent 586427ff
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -150,17 +150,17 @@ function test_selections() ...@@ -150,17 +150,17 @@ function test_selections()
} }
// selection avec sql_multi // selection avec sql_multi
$res = sql_select(['id_tintin', sql_multi('grrrr', 'fr')], 'spip_test_milou', '', '', 'multi'); $res = sql_select(['id_milou', sql_multi('grrrr', 'fr')], 'spip_test_milou', '', '', 'multi');
if (sql_count($res) !== $nb_data) { if (sql_count($res) !== $nb_data) {
$err[] = 'sql_multi mal interprete'; $err[] = 'sql_multi mal interprete';
} }
$rs = sql_fetch($res); $rs = sql_fetch($res);
$id1 = $rs['id_tintin']; $id1 = intval($rs['id_milou']);
$rs = sql_fetch($res); $rs = sql_fetch($res);
$id2 = $rs['id_tintin']; $id2 = intval($rs['id_milou']);
$rs = sql_fetch($res); $rs = sql_fetch($res);
$id3 = $rs['id_tintin']; $id3 = intval($rs['id_milou']);
if ($id1 !== 3 && $id2 !== 2 && $id3 !== 1) { if ($id1 !== 3 && $id2 !== 2 && $id3 !== 1) {
$err[] = "sql_multi order by multi rate : ordre ({$id1}, {$id2}, {$id3}) - attendu : (3, 2, 1)"; $err[] = "sql_multi order by multi rate : ordre ({$id1}, {$id2}, {$id3}) - attendu : (3, 2, 1)";
} }
......
...@@ -37,7 +37,7 @@ function test_update_data() ...@@ -37,7 +37,7 @@ function test_update_data()
'un_bigint' => 'un_bigint+2', 'un_bigint' => 'un_bigint+2',
]); ]);
$nb2 = sql_getfetsel('un_bigint', 'spip_test_tintin', 'id_tintin=' . sql_quote(1)); $nb2 = sql_getfetsel('un_bigint', 'spip_test_tintin', 'id_tintin=' . sql_quote(1));
if ($nb + 2 !== $nb2) { if ($nb + 2 != $nb2) {
$err[] = "sql_update n'a pas fait l'adition ! ({$nb} + 2 != {$nb2})"; $err[] = "sql_update n'a pas fait l'adition ! ({$nb} + 2 != {$nb2})";
} }
......
...@@ -33,7 +33,7 @@ function test_func_mathematiques() ...@@ -33,7 +33,7 @@ function test_func_mathematiques()
'AVG' => 3000, 'AVG' => 3000,
] as $func => $attendu) { ] as $func => $attendu) {
$nb = sql_getfetsel("{$func}(un_int) AS nb", ['spip_test_tintin']); $nb = sql_getfetsel("{$func}(un_int) AS nb", ['spip_test_tintin']);
if ($nb !== $attendu) { if ($nb != $attendu) {
$err[] = "Selection {$func} en echec : attendu : {$attendu}, recu : {$nb}"; $err[] = "Selection {$func} en echec : attendu : {$attendu}, recu : {$nb}";
} }
} }
...@@ -51,11 +51,11 @@ function test_func_mathematiques() ...@@ -51,11 +51,11 @@ function test_func_mathematiques()
'1.5/2' => (1.5 / 2), '1.5/2' => (1.5 / 2),
'2.0/2' => (2.0 / 2), '2.0/2' => (2.0 / 2),
'2/2' => (2 / 2), '2/2' => (2 / 2),
'md5(8)' => md5(8), 'md5(8)' => md5("8"),
'md5(' . sql_quote('a') . ')' => md5('a'), 'md5(' . sql_quote('a') . ')' => md5('a'),
] as $func => $attendu) { ] as $func => $attendu) {
$nb = sql_getfetsel("{$func} AS nb", ['spip_test_tintin'], ['id_tintin=' . sql_quote(1)]); $nb = sql_getfetsel("{$func} AS nb", ['spip_test_tintin'], ['id_tintin=' . sql_quote(1)]);
if ($nb !== $attendu) { if ($nb != $attendu) {
$err[] = "Selection {$func} en echec : attendu : {$attendu}, recu : {$nb}"; $err[] = "Selection {$func} en echec : attendu : {$attendu}, recu : {$nb}";
} }
} }
......
...@@ -2,15 +2,15 @@ ...@@ -2,15 +2,15 @@
/* /*
* Jeu de donnees pour les differents fichiers de tests sql * Jeu de donnees pour les differents fichiers de tests sql
* *
* Quelques fonctions utilises souvent : * Quelques fonctions utilises souvent :
* - test_create_table * - test_create_table
* - test_drop_table * - test_drop_table
*/ */
/* /*
* tableaux des donnees * tableaux des donnees
* *
*/ */
function test_sql_datas(){ function test_sql_datas(){
$table_tintin = [ $table_tintin = [
...@@ -26,9 +26,9 @@ function test_sql_datas(){ ...@@ -26,9 +26,9 @@ function test_sql_datas(){
"maj" => "TIMESTAMP" "maj" => "TIMESTAMP"
], ],
'key'=>[ 'key'=>[
], ],
'nb_key_attendues'=>1 // attention : la primary key DOIT etre dans les cle aussi 'nb_key_attendues'=>1 // attention : la primary key DOIT etre dans les cle aussi
]; ];
$data_tintin = [ $data_tintin = [
[ [
...@@ -65,7 +65,7 @@ function test_sql_datas(){ ...@@ -65,7 +65,7 @@ function test_sql_datas(){
//"maj" => "" // doit se remplir automatiquement //"maj" => "" // doit se remplir automatiquement
] ]
]; ];
$table_milou = [ $table_milou = [
'field'=> [ 'field'=> [
"id_milou" => "INTEGER NOT NULL AUTO_INCREMENT", "id_milou" => "INTEGER NOT NULL AUTO_INCREMENT",
...@@ -109,7 +109,7 @@ function test_sql_datas(){ ...@@ -109,7 +109,7 @@ function test_sql_datas(){
// "maj" => "" // doit se remplir automatiquement // "maj" => "" // doit se remplir automatiquement
], ],
]; ];
$table_haddock = [ $table_haddock = [
'field'=> [ 'field'=> [
"id_haddock" => "INTEGER NOT NULL AUTO_INCREMENT", "id_haddock" => "INTEGER NOT NULL AUTO_INCREMENT",
...@@ -139,7 +139,7 @@ function test_sql_datas(){ ...@@ -139,7 +139,7 @@ function test_sql_datas(){
"alcool" => "Un début de chaine : <multi>[fr]Vinasse[en]Vinassy</multi>, et [la fin]", "alcool" => "Un début de chaine : <multi>[fr]Vinasse[en]Vinassy</multi>, et [la fin]",
], ],
]; ];
return [ return [
'spip_test_tintin'=>[ 'spip_test_tintin'=>[
'desc'=>$table_tintin, 'desc'=>$table_tintin,
...@@ -148,16 +148,16 @@ function test_sql_datas(){ ...@@ -148,16 +148,16 @@ function test_sql_datas(){
'spip_test_milou'=>[ 'spip_test_milou'=>[
'desc'=>$table_milou, 'desc'=>$table_milou,
'data'=>$data_milou 'data'=>$data_milou
], ],
'spip_test_haddock'=>[ 'spip_test_haddock'=>[
'desc'=>$table_haddock, 'desc'=>$table_haddock,
'data'=>$data_haddock 'data'=>$data_haddock
], ],
]; ];
} }
/* /*
* Suppression de tables * Suppression de tables
*/ */
function test_drop_table(){ function test_drop_table(){
$tables = test_sql_datas(); $tables = test_sql_datas();
...@@ -182,14 +182,14 @@ function test_create_table(){ ...@@ -182,14 +182,14 @@ function test_create_table(){
foreach ($tables as $t=>$v){ foreach ($tables as $t=>$v){
if (!sql_create($t, $v['desc']['field'], $v['desc']['key'])) if (!sql_create($t, $v['desc']['field'], $v['desc']['key']))
$err[] = "sql_create $t en echec"; // reponse, arguments $err[] = "sql_create $t en echec"; // reponse, arguments
} }
if ($err) { if ($err) {
return '<b>Creation de table en echec</b><dl>' . join('', $err) . '</dl>'; return '<b>Creation de table en echec</b><dl>' . join('', $err) . '</dl>';
} }
} }
/* /*
* Insertion de champs multiples sql_insertq_multi * Insertion de champs multiples sql_insertq_multi
* et comptage avec sql_countsel * et comptage avec sql_countsel
...@@ -200,12 +200,12 @@ function test_insert_data() { ...@@ -200,12 +200,12 @@ function test_insert_data() {
// inserer les donnees dans la table // inserer les donnees dans la table
foreach ($tables as $t=>$d){ foreach ($tables as $t=>$d){
sql_insertq_multi($t, $d['data']); sql_insertq_multi($t, $d['data']);
$essais[] = [(string)count($d['data']),$t]; $essais[] = [count($d['data']),$t];
} }
$err = tester_fun('sql_countsel', $essais); $err = tester_fun('sql_countsel', $essais);
if ($err) { if ($err) {
return '<b>Insertion multiple puis countsel dans table</b><dl>' . join('', $err) . '</dl>'; return '<b>Insertion multiple puis countsel dans table</b><dl>' . join('', $err) . '</dl>';
} }
} }
?> ?>
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter