From d976b71b399f3e2887cf2b37f1d4cbb946008ee0 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Thu, 13 Nov 2014 00:03:23 +0100 Subject: [PATCH] Task #1044 - Implementation de PHPUNIT Test files inc.php could also be used with ajax --- html/do.php | 25 ++++++- html/test.php | 126 +++++++++++++++++++++++---------- include/user_common.php | 4 +- scenario/readme.txt | 36 ++++++++++ scenario/scenario-historic.php | 24 +++++++ 5 files changed, 173 insertions(+), 42 deletions(-) create mode 100644 scenario/readme.txt create mode 100644 scenario/scenario-historic.php diff --git a/html/do.php b/html/do.php index 79d25c359..c97061ca1 100644 --- a/html/do.php +++ b/html/do.php @@ -95,7 +95,7 @@ if ($cn->exist_table('version') == false) { echo '

' . _("Base de donnée invalide") . '

'; $base = dirname($_SERVER['REQUEST_URI']); - echo HtmlInput::button_anchor('Retour', $base . '/user_login.php'); + echo HtmlInput::button_anchor('Retour', $base . '/user_login.php'); exit(); } if (DBVERSION < dossier::get_version($cn)) @@ -150,11 +150,34 @@ if ( isset ($_POST['set_preference'])) { $_SESSION['g_pagesize']=$p_size; $_SESSION['g_lang']=$lang; } + /* * if an action is requested */ if (isset($_REQUEST['ac'])) { + // When debugging save all the input in a file + if ( LOGINPUT) + { + $file_loginput=fopen($_ENV['TMP'].'/scenario-'.$_SERVER['REQUEST_TIME'].'.php','a+'); + $tmp_ac=explode('/',trim(strtoupper($_REQUEST['ac']))); + $last=count($tmp_ac); + if ($last > 0) $last--; + fwrite ($file_loginput,"'.$p_array['desc'].''; - require $p_array['file']; - call_user_func($p_array['function']); -} -// Test the connection -echo __FILE__.":".__LINE__; -print_r($_REQUEST); -if ( ! isset($_REQUEST['gDossier'])) -{ - echo "Vous avez oublie de specifier le gDossier ;)"; - echo "L'url aurait du etre test.php?gDossier=xx"; - exit(); -} -$cn=new Database($_GET['gDossier']); - -$a_route[]=array('desc'=>'test sur les menus par défauts','file'=>'class_default_menu.php','function'=>'Default_Menu::test_me'); -$a_route[]=array('desc'=>'test sur Acc_Operations','file'=>'class_acc_operation.php','function'=>'Acc_Operation::test_me'); -$a_route[]=array('desc'=>'test sur INVOICING','file'=>'../include/ext/invoicing/include/class_acc_ledger_sold_generate.php','function'=>'Acc_Ledger_Sold_Generate::test_me'); -$a_route[]=array('desc'=>'test sur menu_ref','file'=>'class_menu_ref_sql.php','function'=>'Menu_Ref_SQL::test_me'); -$called=HtmlInput::default_value_get("called", -1); -if ($called == -1 ) -{ - for ($i=0;$i< count($a_route);$i++) + echo "

Test NOALYSS

"; + /* + * cherche pour fichier a include, s'il y en a alors les affiche + * avec une description + */ + $scan=scandir('../scenario/'); + $max=count($scan); + + echo ''; + for ($e=0; $e<$max; $e++) { - start_test($a_route[$i]); + if (is_file('../scenario/'.$scan[$e])&&strpos($scan[$e], '.php') == true) + { + $description=""; + $a_description=file('../scenario/'.$scan[$e]); + $max_description=count($a_description); + for ($w=0;$w<$max_description;$w++) + { + if (strpos($a_description[$w],'@description:')==true) + { + $description=$a_description[$w]; + $description=str_replace('//@description:','',$description); + + } + } + $get='test.php?'.http_build_query(array('script'=>$scan[$e],'gDossier'=>$gDossierLogInput,'description'=>$description)); + echo ''; + echo ''; + echo ''; + echo ''; + } } + echo '
'; + echo ''; + echo $scan[$e]; + echo ''; + echo ''.$description.'
'; } - else +else { - start_test($a_route[$called]); + + $script=str_replace('../','',$script); + $description=HtmlInput::default_value_get("description", "aucune description"); + echo '

'.$script."

"; + echo '

description = '.$description.'

'; + include '../scenario/'.$script; + + $end_mem=memory_get_usage(); + $end_time=microtime(true); + + echo "

start mem : ".$start_mem; + echo '

'; + echo "

end mem : ".$end_mem; + echo '

'; + echo "

Diff = ".($end_mem-$start_mem)." bytes "; + echo "

Diff = ".(round(($end_mem-$start_mem)/1024, 2))." kbytes "; + echo "

Diff = ".(round(($end_mem-$start_mem)/1024/1024, 2))." Mbytes "; + echo '

'; + echo "

Execution script ".$script." time = ".(round(($end_time-$start_time), 4))." secondes

"; } \ No newline at end of file diff --git a/include/user_common.php b/include/user_common.php index a1ed734f8..03326e2de 100644 --- a/include/user_common.php +++ b/include/user_common.php @@ -235,8 +235,8 @@ function toNumber($p_num) */ function check_parameter($p_array,$p_needed) { - $needed = split(',',$p_needed); - for ($e=0;$e<$needed;$e++) { + $needed =explode(',',$p_needed); + for ($e=0;$e + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +Afin d'avoir les scénarios pour les rejouer avec test.php. + +Dans include/constant.php, changer +define ('LOGINPUT',false); par +define ('LOGINPUT',true); + +Ensuite, aller dans votre dossier de test et faites une action (une vente, un achat...), vous devez ouvrir le fichier test.php +ce que vous venez de faire a été sauvé dans le répertoire défini par $_ENV['TMP'], (sous linux il s'agit de /tmp )avec un nom ressemblant à scenario-.php + +Vous devez d'abord copier ce fichier dans ce répertoire-ci + +Si vous pointez votre browser sur noalyss/html/test.php (après avoir créé le fichier authorized_debug) en cliquant sur le +lien avec le nom de fichier vous pourrez rejouer l'action. Vous pouvez améliorer la description en changeant l'annotation //@description: + +Vous pouvez aussi utiliser un nom de fichier plus parlant. + +L'objectif étant de pouvoir tester et de rejouer facilement les actions que vous avez faites. + + diff --git a/scenario/scenario-historic.php b/scenario/scenario-historic.php new file mode 100644 index 000000000..3ee41699f --- /dev/null +++ b/scenario/scenario-historic.php @@ -0,0 +1,24 @@ + '37', + 'ledger_type' => 'ALL', + 'ac' => 'HIST', + 'nb_jrn' => '0', + 'date_start' => '01.01.2014', + 'date_end' => '31.12.2014', + 'date_paid_start' => '', + 'date_paid_end' => '', + 'desc' => '', + 'amount_min' => '0', + 'amount_max' => '0', + 'qcode' => '', + 'accounting' => '', + 'search' => 'Rechercher', +); +$_POST=array ( +); +$_POST['gDossier']=$gDossierLogInput; +$_GET['gDossier']=$gDossierLogInput; + $_REQUEST=array_merge($_GET,$_POST); +include 'history_operation.inc.php';