Task #1044 - Implementation de PHPUNIT
Test files inc.php could also be used with ajax
This commit is contained in:
parent
09478c0e1b
commit
d976b71b39
5 changed files with 173 additions and 42 deletions
25
html/do.php
25
html/do.php
|
|
@ -95,7 +95,7 @@ if ($cn->exist_table('version') == false)
|
|||
{
|
||||
echo '<h2 class="error" style="font-size:12px">' . _("Base de donnée invalide") . '</h2>';
|
||||
$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,"<?php \n");
|
||||
fwrite ($file_loginput,'//@description:'.$tmp_ac[$last]."\n");
|
||||
fwrite($file_loginput, '$_GET='.var_export($_GET,true));
|
||||
fwrite($file_loginput,";\n");
|
||||
fwrite($file_loginput, '$_POST='.var_export($_POST,true));
|
||||
fwrite($file_loginput,";\n");
|
||||
fwrite($file_loginput, '$_POST[\'gDossier\']=$gDossierLogInput;');
|
||||
fwrite($file_loginput,"\n");
|
||||
fwrite($file_loginput, '$_GET[\'gDossier\']=$gDossierLogInput;');
|
||||
fwrite($file_loginput,"\n");
|
||||
fwrite($file_loginput,' $_REQUEST=array_merge($_GET,$_POST);');
|
||||
fwrite($file_loginput,"\n");
|
||||
fclose($file_loginput);
|
||||
}
|
||||
|
||||
$_REQUEST['ac']= trim(strtoupper($_REQUEST['ac']));
|
||||
$all = explode('/', $_REQUEST['ac']);
|
||||
$module_selected = $all[0];
|
||||
|
|
|
|||
126
html/test.php
126
html/test.php
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of NOALYSS.
|
||||
*
|
||||
|
|
@ -15,62 +16,109 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with NOALYSS; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
*/
|
||||
// Copyright Author Dany De Bontridder danydb@aevalys.eu
|
||||
/*!\file
|
||||
*\brief this file let you debug and test the different functionnalities, there are 2 important things to do
|
||||
* It is only a quick and dirty testing. You should use a tool as PHPUNIT for the unit testing
|
||||
/* !\file
|
||||
* \brief this file let you debug and test the different functionnalities, there are 2 important things to do
|
||||
* It is only a quick and dirty testing. You should use a tool as PHPUNIT for the unit testing
|
||||
*
|
||||
* - first do not forget to create the authorized_debug file in the html folder
|
||||
* - secund the test must adapted to this page : if you do a post (or get) from a test, you won't get any result
|
||||
* if the $_REQUEST[test_select] is not set, so set it .
|
||||
*/
|
||||
* - first do not forget to create the authorized_debug file in the html folder
|
||||
* - secund the test must adapted to this page : if you do a post (or get) from a test, you won't get any result
|
||||
* if the $_REQUEST[test_select] is not set, so set it .
|
||||
*/
|
||||
$start_mem=memory_get_usage();
|
||||
$start_time=microtime(true);
|
||||
|
||||
|
||||
include_once("../include/constant.php");
|
||||
include_once("ac_common.php");
|
||||
include_once("constant.php");
|
||||
require_once('class_database.php');
|
||||
require_once ('class_dossier.php');
|
||||
require_once('class_html_input.php');
|
||||
require_once ('function_javascript.php');
|
||||
require_once 'class_user.php';
|
||||
load_all_script();
|
||||
global $cn,$g_user,$g_succeed,$g_failed;
|
||||
if ( ! file_exists('authorized_debug') )
|
||||
$gDossier=HtmlInput::default_value_get('gDossier', -1);
|
||||
if ($gDossier==-1)
|
||||
{
|
||||
echo " Vous devez donner le dossier avec paramètre gDossier dans l'url, exemple http://localhost/noalyss/html/test.php?gDossier=25";
|
||||
exit();
|
||||
}
|
||||
$gDossierLogInput=$gDossier;
|
||||
global $cn, $g_user, $g_succeed, $g_failed;
|
||||
$cn=new Database($_GET['gDossier']);
|
||||
|
||||
$g_parameter=new Own($cn);
|
||||
$g_user=new User($cn);
|
||||
|
||||
if (!file_exists('authorized_debug'))
|
||||
{
|
||||
echo "Pour pouvoir utiliser ce fichier vous devez creer un fichier nomme authorized_debug
|
||||
dans le repertoire html du server";
|
||||
exit();
|
||||
|
||||
}
|
||||
define('ALLOWED', 1);
|
||||
html_page_start();
|
||||
function start_test($p_array)
|
||||
$script=HtmlInput::default_value_get('script', '');
|
||||
if ($script=="")
|
||||
{
|
||||
echo '<h1>'.$p_array['desc'].'</h1>';
|
||||
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 "<h1>Test NOALYSS</h1>";
|
||||
/*
|
||||
* cherche pour fichier a include, s'il y en a alors les affiche
|
||||
* avec une description
|
||||
*/
|
||||
$scan=scandir('../scenario/');
|
||||
$max=count($scan);
|
||||
|
||||
echo '<table>';
|
||||
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 '<tr>';
|
||||
echo '<td>';
|
||||
echo '<a href="'.$get.'" target="_blank">';
|
||||
echo $scan[$e];
|
||||
echo '</a>';
|
||||
echo '</td>';
|
||||
echo '<td>'.$description.'</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
}
|
||||
echo '</table>';
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
start_test($a_route[$called]);
|
||||
|
||||
$script=str_replace('../','',$script);
|
||||
$description=HtmlInput::default_value_get("description", "aucune description");
|
||||
echo '<h1>'.$script."</h1>";
|
||||
echo '<p> description = '.$description.'<p>';
|
||||
include '../scenario/'.$script;
|
||||
|
||||
$end_mem=memory_get_usage();
|
||||
$end_time=microtime(true);
|
||||
|
||||
echo "<p>start mem : ".$start_mem;
|
||||
echo '</p>';
|
||||
echo "<p>end mem : ".$end_mem;
|
||||
echo '</p>';
|
||||
echo "<p>Diff = ".($end_mem-$start_mem)." bytes ";
|
||||
echo "<p>Diff = ".(round(($end_mem-$start_mem)/1024, 2))." kbytes ";
|
||||
echo "<p>Diff = ".(round(($end_mem-$start_mem)/1024/1024, 2))." Mbytes ";
|
||||
echo '</p>';
|
||||
echo "<p>Execution script ".$script." time = ".(round(($end_time-$start_time), 4))." secondes</p>";
|
||||
}
|
||||
|
|
@ -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<count($needed);$e++) {
|
||||
if ( ! isset($p_array[$needed[$e]])) {
|
||||
throw new Exception (_('Paramètre manquant')." ".$needed[$e]);
|
||||
}
|
||||
|
|
|
|||
36
scenario/readme.txt
Normal file
36
scenario/readme.txt
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
*
|
||||
* Copyright (C) 2014 Dany De Bontridder <dany@alchimerys.be>
|
||||
*
|
||||
* 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-<nombre>.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: <CODE>
|
||||
|
||||
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.
|
||||
|
||||
|
||||
24
scenario/scenario-historic.php
Normal file
24
scenario/scenario-historic.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
//@description:HIST Historique operation du 1.1.2014 au 31.12.2014
|
||||
$_GET=array (
|
||||
'gDossier' => '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';
|
||||
Loading…
Add table
Add a link
Reference in a new issue