[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 10/11: Task #1044 - Implementation de PHPUNIT
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 10/11: Task #1044 - Implementation de PHPUNIT Test files inc.php could also be used with ajax |
Date: |
Wed, 12 Nov 2014 23:06:48 +0000 |
sparkyx pushed a commit to branch master
in repository noalyss.
commit d976b71b399f3e2887cf2b37f1d4cbb946008ee0
Author: Dany De Bontridder <address@hidden>
Date: Thu Nov 13 00:03:23 2014 +0100
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(-)
diff --git a/html/do.php b/html/do.php
index 79d25c3..c97061c 100644
--- a/html/do.php
+++ b/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];
diff --git a/html/test.php b/html/test.php
index 7cb1d49..84f1449 100644
--- a/html/test.php
+++ b/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 address@hidden
-/*!\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 "Pour pouvoir utiliser ce fichier vous devez creer un fichier nomme
authorized_debug
- dans le repertoire html du server";
+ echo " Vous devez donner le dossier avec paramètre gDossier dans l'url,
exemple http://localhost/noalyss/html/test.php?gDossier=25";
exit();
-
}
-html_page_start();
-function start_test($p_array)
-{
- 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']))
+$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 "Vous avez oublie de specifier le gDossier ;)";
- echo "L'url aurait du etre test.php?gDossier=xx";
+ echo "Pour pouvoir utiliser ce fichier vous devez creer un fichier nomme
authorized_debug
+ dans le repertoire html du server";
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 )
+define('ALLOWED', 1);
+html_page_start();
+$script=HtmlInput::default_value_get('script', '');
+if ($script=="")
{
- 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>";
}
\ No newline at end of file
diff --git a/include/user_common.php b/include/user_common.php
index a1ed734..03326e2 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<count($needed);$e++) {
if ( ! isset($p_array[$needed[$e]])) {
throw new Exception (_('Paramètre manquant')." ".$needed[$e]);
}
diff --git a/scenario/readme.txt b/scenario/readme.txt
new file mode 100644
index 0000000..6bd9065
--- /dev/null
+++ b/scenario/readme.txt
@@ -0,0 +1,36 @@
+*
+ * Copyright (C) 2014 Dany De Bontridder <address@hidden>
+ *
+ * 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.
+
+
diff --git a/scenario/scenario-historic.php b/scenario/scenario-historic.php
new file mode 100644
index 0000000..3ee4169
--- /dev/null
+++ b/scenario/scenario-historic.php
@@ -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';
- [Noalyss-commit] [noalyss] 01/11: Task #639 - Traduction : anglais ', (continued)
- [Noalyss-commit] [noalyss] 01/11: Task #639 - Traduction : anglais ', Dany De Bontridder, 2014/11/12
- [Noalyss-commit] [noalyss] 03/11: Task #639 - Traduction : anglais ', Dany De Bontridder, 2014/11/12
- [Noalyss-commit] [noalyss] 02/11: Task #639 - Traduction : anglais ', Dany De Bontridder, 2014/11/12
- [Noalyss-commit] [noalyss] 05/11: Bug in ajax_card for adding banque, Dany De Bontridder, 2014/11/12
- [Noalyss-commit] [noalyss] 04/11: Task #639 - Traduction : anglais ', Dany De Bontridder, 2014/11/12
- [Noalyss-commit] [noalyss] 06/11: Bug in NOALYSS_SQL, Dany De Bontridder, 2014/11/12
- [Noalyss-commit] [noalyss] 07/11: Task #639 - Traduction : anglais Renforcement sécurité, Dany De Bontridder, 2014/11/12
- [Noalyss-commit] [noalyss] 08/11: Add exception, Dany De Bontridder, 2014/11/12
- [Noalyss-commit] [noalyss] 09/11: Task #1045 - Amélioration apparence : Placement boite "ajout categorie de fiche", Dany De Bontridder, 2014/11/12
- [Noalyss-commit] [noalyss] 11/11: Task #1044 - Implementation de PHPUNIT new defined variables for testing, Dany De Bontridder, 2014/11/12
- [Noalyss-commit] [noalyss] 10/11: Task #1044 - Implementation de PHPUNIT Test files inc.php could also be used with ajax,
Dany De Bontridder <=