noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 12/12: Tache #1844 Menu : ouverture menu par


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 12/12: Tache #1844 Menu : ouverture menu par défaut
Date: Fri, 15 Jan 2021 09:40:08 -0500 (EST)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 9e40622983b068731c9415f2d09f1ee7ad0f96ef
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Fri Jan 15 15:39:41 2021 +0100

    Tache #1844 Menu : ouverture menu par défaut
---
 html/do.php                         |  24 +++-
 include/lib/ac_common.php           | 250 +++++++++++++++++++++++++-----------
 sql/upgrade.sql                     |   5 +
 unit-test/global.php                |   2 +-
 unit-test/include/lib/ac_common.php | 171 ++++++++++++++++++++++++
 5 files changed, 374 insertions(+), 78 deletions(-)

diff --git a/html/do.php b/html/do.php
index 9a86412..b91308f 100644
--- a/html/do.php
+++ b/html/do.php
@@ -241,6 +241,7 @@ if (isset($_REQUEST['ac']))
         fclose($file_loginput);
     }
 
+    // Priority to POST , otherwise "duplicate operation" doesn't work
     $ac_post = trim(strtoupper($http->post("ac","string","")));
     $ac_get  = trim(strtoupper($http->get("ac","string","")));
     
@@ -252,6 +253,8 @@ if (isset($_REQUEST['ac']))
       pm_id_v3,pm_id_v2,pm_id_v1
     from v_menu_profile where code= upper($1)  and p_id=$2',
             array($AC,$user_profile));
+    
+
     try {        
         if ( count($amenu_id) != 1 ) {
             // if AC is a simple code and this menu can be accessed 
@@ -262,20 +265,35 @@ if (isset($_REQUEST['ac']))
                     array($AC,$user_profile));
             if ( count($pm_id) > 0 ) {
                 show_menu($pm_id[0]['pm_id']);
+                return;
             } else {
                 throw new Exception(_('Erreur menu'),10);
             }
         }
-        
-        $module_id=$cn->get_value('select case when pm_id_v3 = 0 then (case 
when pm_id_v2 = 0 then pm_id_v1 else pm_id_v2 end) else pm_id_v3 end 
-            from v_menu_profile where p_id=$1 and upper(code)=upper($2)',
+        $amenu_id=complete_default_menu($amenu_id,$user_profile);
+    
+        $AC=rebuild_access_code($amenu_id);
+    
+        put_global(array(array("key"=>"ac","value"=>$AC)));        
+        $module_id=$cn->get_value('select 
+            case when pm_id_v3 = 0 then (case when pm_id_v2 = 0 then pm_id_v1 
else pm_id_v2 end) else pm_id_v3 end 
+            from 
+            v_menu_profile 
+            where p_id            =$1 
+            and upper(code)=upper($2)',
                 array($user_profile,$AC));
         $g_user->audit();
         // Show module and highligt selected one
         show_module($module_id);
+        
+        
         show_menu( $amenu_id[0]['pm_id_v3']);
+
         show_menu( $amenu_id[0]['pm_id_v2']);
+
         show_menu($amenu_id[0]['pm_id_v1']);
+
+        
     } catch (Exception $e) {
         if ( $e->getCode() == 10 ) {
             alert(_('Accès menu impossible'));
diff --git a/include/lib/ac_common.php b/include/lib/ac_common.php
index 71e85fb..635bb45 100644
--- a/include/lib/ac_common.php
+++ b/include/lib/ac_common.php
@@ -625,7 +625,8 @@ function getPeriodeFromMonth($p_cn, $p_date)
     return $R;
 }
 
-/**\brief Decode the html for the widegt richtext and remove newline
+/**
+ * \brief Decode the html for the widegt richtext and remove newline
  * \param $p_html string to decode
  * \return the html code without new line
  */
@@ -651,8 +652,7 @@ function Decode($p_html)
 function sql_filter_per($p_cn, $p_from, $p_to, $p_form='p_id', 
$p_field='jr_tech_per')
 {
 
-    if ($p_form != 'p_id' &&
-           $p_form != 'date')
+    if ($p_form != 'p_id' && $p_form != 'date')
     {
        echo_error(__FILE__, __LINE__, 'Mauvais parametres ');
        exit(-1);
@@ -662,18 +662,26 @@ function sql_filter_per($p_cn, $p_from, $p_to, 
$p_form='p_id', $p_field='jr_tech
     $p_field=  sql_string($p_field);
     if ($p_form == 'p_id')
     {
+        if ( isNUmber($p_from)==0 || isNUmber($p_to)==0){
+            throw new Exception("SFP1"._("Nombre invalide"));
+        }
        // retrieve the date
        $pPeriode = new Periode($p_cn);
        $a_start = $pPeriode->get_date_limit($p_from);
        $a_end = $pPeriode->get_date_limit($p_to);
-       if ($a_start == null || $a_end == null)
-           throw new Exception(__FILE__ . __LINE__ . sprintf(_('Attention 
periode 
-                    non trouvee periode p_from= %s p_to_periode = %s'), 
$p_from ,
-                   $p_to));
+       if ($a_start==null||$a_end==null)
+        {
+            throw new Exception(__FILE__.__LINE__.sprintf(_('Attention periode 
+                    non trouvee periode p_from= %s p_to_periode = %s'), 
$p_from, $p_to));
+        }
 
 
-       $p_from = $a_start['p_start'];
+        $p_from = $a_start['p_start'];
        $p_to = $a_end['p_end'];
+    }else {
+        if ( isDate($p_from)==NULL || isDate($p_to)==NULL){
+            throw new Exception("SFP2"._("Date invalide"));
+        }
     }
     if ($p_from == $p_to)
        $periode = " $p_field = (select p_id from parm_periode " .
@@ -778,7 +786,7 @@ function shrink_date($p_date)
 /**
  * @brief shrink the date, make a date shorter for the printing
  * @param $p_date format DD.MM.YYYY
- * @return date in the format DDMMYY (size = 13 mm in arial 8)
+ * @return date in the format DD.MM.YY (size = 13 mm in arial 8)
  */
 function smaller_date($p_date)
 {
@@ -826,7 +834,7 @@ function format_date($p_date, $p_from_format = 
'YYYY-MM-DD',$p_to_format='DD.MM.
        case 'YYYYMMDD':
             $str_date = $date[0] . $date[1] . $date[2];
             break;
-                case 'YYYY/MM/DD':
+        case 'YYYY/MM/DD':
             $str_date = $date[0] . '/' . $date[1] . '/' . $date[2];
             break;
         case "DD.MM.YY":
@@ -1038,7 +1046,8 @@ function show_menu($module)
     if ($module == 0)return;
     static $level=0;
     global $g_user;
-    
+    $http=new HttpInput();
+    $access_code=$http->request("ac");
     $cn = Dossier::connect();
     /**
      * Show the submenus
@@ -1068,11 +1077,13 @@ function show_menu($module)
         else {
             $style_menu=$a_style_menu[$level];
         }
-               require NOALYSS_TEMPLATE.'/menu.php';
-    } // there is only one submenu so we include the code or javascript 
-      // or we show the submenu
-    elseif (count($amenu) == 1)
+       require NOALYSS_TEMPLATE.'/menu.php';
+          $level++;
+           return;
+    } elseif (count($amenu) == 1)
     {
+        // there is only one submenu so we include the code or javascript 
+        // or we show the submenu
         if ( trim($amenu[0]['me_url']) != "" ||
              trim ($amenu[0]['me_file']) != "" ||
              trim ($amenu[0]['me_javascript']) != "" )
@@ -1081,8 +1092,11 @@ function show_menu($module)
                echo h2info(_($amenu[0]['me_menu']));
                echo '</div>';
                $module = $amenu[0]['pm_id'];
+                display_menu($module);
+                $level++;
+                return;
         } else {
-           $url=$_REQUEST['ac'].'/'.$amenu[0]['me_code'];
+           $url=$access_code.'/'.$amenu[0]['me_code'];
            echo '<a href="do.php?gDossier='.Dossier::id().'&ac='.$url.'">';
            echo _($amenu[0]['me_menu']);
            echo '</a>';
@@ -1091,68 +1105,86 @@ function show_menu($module)
         }
     }
     
+    // !!! this point should never be reached 
     // There is no submenu or only one
     if (empty($amenu) || count($amenu) == 1)
     {
-               $file = $cn->get_array("select 
me_file,me_parameter,me_javascript,me_type
-               from menu_ref
-               join profile_menu using (me_code)
-               join profile_user using (p_id)
-               where
-               pm_id=$1 and
-               user_name=$2 and
-               (me_file is not null or trim(me_file) <>'' or
-               me_javascript is not null or trim (me_javascript) <> '')", 
array($module,$g_user->login));
-
-               if (count($file)==0)
-               {
-                        return;
-               }
-
-               if ($file[0]['me_file'] != "")
-               {
-                       if ($file[0]['me_parameter'] !== "")
-                       {
-                               // if there are paramter put them in superglobal
-                               
$array=compute_variable($file[0]['me_parameter']);
-                               put_global($array);
-                       }
-                        if ( DEBUG ) echo  $file[0]['me_file']," param : 
",$file[0]['me_parameter'] ;
-                        /*
-                         * Log the file we input to put in the folder 
test-noalyss for replaying it
-                         */
-                        if (LOGINPUT) {
-                                
$file_loginput=fopen($_ENV['TMP'].'/scenario-'.$_SERVER['REQUEST_TIME'].'.php','a+');
-                                fwrite($file_loginput, "include 
'".$file[0]['me_file']."';");
-                                fwrite($file_loginput,"\n");
-                                fclose($file_loginput);
-                        }
-                       // if file is not a plugin, include the file, otherwise
-                       // include the plugin launcher
-                       if ( $file[0]['me_type'] != 'PL') {
-                            if (file_exists ($file[0]['me_file']) )
-                            {
-                               require_once $file[0]['me_file'];
-                            } elseif ( 
file_exists(NOALYSS_INCLUDE.'/'.$file[0]['me_file'])) {
-                               require_once 
NOALYSS_INCLUDE.'/'.$file[0]['me_file'];
-                            }else {                            
-                                echo echo_warning(_("Fichier non trouvé"));
-                            }
-                        } else {
-                               require 'extension_get.inc.php';
-                        }
-
-                       exit();
-               }
-               if ( $file[0]['me_javascript'] != '')
-               {
-                    $js=  str_replace('<DOSSIER>', dossier::id(), 
$file[0]['me_javascript']);
-                    echo create_script($js);
-               }
+        display_menu($module);
+                
     }
     $level++;
 }
 /**
+ * Display a menu
+ * @global type $g_user
+ * @param type $p_menuid
+ * @return type
+ */
+function display_menu($p_menuid)
+{
+    if ($p_menuid == 0) return;
+    global $g_user;
+    $cn=Dossier::connect();
+    
+    $file = $cn->get_array("
+        select me_file,me_parameter,me_javascript,me_type
+        from menu_ref
+        join profile_menu using (me_code)
+        join profile_user using (p_id)
+        where
+        pm_id=$1 and
+        user_name=$2 and
+        (me_file is not null or trim(me_file) <>'' or
+        me_javascript is not null or trim (me_javascript) <> '')", 
array($p_menuid,$g_user->login));
+
+    if (count($file)==0)
+    {
+            return;
+    }
+
+    if ($file[0]['me_file'] != "")
+    {
+            if ($file[0]['me_parameter'] !== "")
+            {
+                    // if there are paramter put them in superglobal
+                    $array=compute_variable($file[0]['me_parameter']);
+                    put_global($array);
+            }
+            tracedebug("'menu", 
$file[0]['me_file'],__FUNCTION__.__LINE__."line");
+            tracedebug("'menu", 
$file[0]['me_parameter'],__FUNCTION__.__LINE__."parm ");
+            /*
+             * Log the file we input to put in the folder test-noalyss for 
replaying it
+             */
+            if (LOGINPUT) {
+                    
$file_loginput=fopen($_ENV['TMP'].'/scenario-'.$_SERVER['REQUEST_TIME'].'.php','a+');
+                    fwrite($file_loginput, "include 
'".$file[0]['me_file']."';");
+                    fwrite($file_loginput,"\n");
+                    fclose($file_loginput);
+            }
+            // if file is not a plugin, include the file, otherwise
+            // include the plugin launcher
+            if ( $file[0]['me_type'] != 'PL') {
+                if (file_exists ($file[0]['me_file']) )
+                {
+                    require_once $file[0]['me_file'];
+                } elseif ( 
file_exists(NOALYSS_INCLUDE.'/'.$file[0]['me_file'])) {
+                    require_once NOALYSS_INCLUDE.'/'.$file[0]['me_file'];
+                }else {                            
+                    echo echo_warning(_("Fichier non trouvé"));
+                }
+            } else {
+                    require 'extension_get.inc.php';
+            }
+
+            exit();
+    } elseif ( $file[0]['me_javascript'] != '')
+    {
+        $js=  str_replace('<DOSSIER>', dossier::id(), 
$file[0]['me_javascript']);
+        echo create_script($js);
+    } 
+
+}
+/**
  * Put in superglobal (get,post,request) the value contained in
  * the parameter field (me_parameter)
  * @param $array [key] [value]
@@ -1332,7 +1364,7 @@ function is_msie()
 function record_log($p_message)
 {
     error_log("noalyss".print_r($p_message,true),0);
-    error_log("noalyss GET [".var_export($_GET, true)."] POST 
[".var_export($_POST, true)."]",0);
+    error_log("noalyss GET [".json_encode($_GET)."] POST 
[".json_encode($_POST)."]",0);
 }
 if(!function_exists('tracedebug')) {
   function tracedebug($file,$var, $label = NULL) {
@@ -1412,8 +1444,8 @@ function generate_random_string($car)
  * generate a string of p_car character and a input text with name p_ctl_name
  * work like a kind of captcha.The control code for checking is ctlcode.
  * You compare the content of the variable p_ctl_name with ctlcode
- * @param $p_ctl_name
- * @param $p_car
+ * @param $p_ctl_name name of the HTML input text
+ * @param $p_car length of the string
  */
 function confirm_with_string($p_ctl_name,$p_car)
 {
@@ -1424,3 +1456,73 @@ function confirm_with_string($p_ctl_name,$p_car)
     $r.=$ctl->input();
     return $r;
 }
+/**
+ * Find the menu marked as default in the given profile
+ * @param number $pn_menu (profile_menu.id)
+ */
+function find_default_menu($pn_menu)
+{
+    $cn=Dossier::connect();
+    $sql = '  select pm_id from profile_menu where pm_default =1 and pm_id_dep 
= $1';
+    $aresult=$cn->get_array($sql, [$pn_menu]);
+    if (empty($aresult)) {
+        return 0;
+    }
+    return $aresult[0]['pm_id'];
+}
+
+/**
+ * Check if there is a default menu for this user and add it. The array is 
filling from 1 to 3
+ * @verbatim
+ * 
+ * COMPTA              0   -   0 - 173
+ * COMPTA/MENUACH      0   - 173 -   3
+ * COMPTA/MENUACH/ACH  173 -   3 -  85
+ * 
+ * @endverbatim
+ * 
+ *
+ * @param array $pa_menu if the array of option ; index pm_id_v1 , pm_id_v2 
and pm_id_v3
+ * 
+ */
+function complete_default_menu($pa_menu)
+{
+    $a_result=$pa_menu;
+    // find the first one which is null
+    if ($pa_menu[0]['pm_id_v2'] == 0) {
+        $tmp=find_default_menu($pa_menu[0]['pm_id_v1']);
+        if ( $tmp <> 0 ) {
+            $a_result[0]['pm_id_v2']=$pa_menu[0]['pm_id_v1'];
+            $a_result[0]['pm_id_v1']=$tmp;
+        }
+    }
+    if ($pa_menu[0]['pm_id_v3'] == 0) {
+         $tmp=find_default_menu($a_result[0]['pm_id_v1']);
+        if ( $tmp <> 0 ) {
+            $a_result[0]['pm_id_v3']=$a_result[0]['pm_id_v2'];
+            $a_result[0]['pm_id_v2']=$a_result[0]['pm_id_v1'];
+            $a_result[0]['pm_id_v1']=$tmp;
+        }
+    }
+    return $a_result;
+}
+/**
+ * rebuild the access code
+ * @see complete_default_menu
+ * @param array of number $pan_code index row [0] =  index pm_id_v1 , pm_id_v2 
and pm_id_v3
+ */
+function rebuild_access_code($pan_code) 
+{
+    if ( empty ($pan_code)) {return;}
+    $s_result="";
+    $cn=Dossier::connect();
+    $an_code=['pm_id_v3','pm_id_v2','pm_id_v1'];
+    $sep="";
+    for ($i=0;$i<3;$i++)
+    {
+        $ix=$an_code[$i];
+        $s_result.=$sep.$cn->get_value("select me_code from profile_menu where 
pm_id=$1",[ $pan_code[0][$ix] ]);
+        $sep=($s_result != "" )?"/":"";
+    }
+    return $s_result;
+}
\ No newline at end of file
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index 08d5708..eb779b5 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -204,3 +204,8 @@ delete from fiche_detail where ad_id=54;
 delete from attr_min  where ad_id=54;
 delete from attr_def where ad_id=54;
 delete from jnt_fic_attr where ad_id =54;
+
+
+-- open COMPANY when PARAM is choosen for profile 1
+update profile_menu set pm_default=1,p_order=1 where pm_id=54;
+
diff --git a/unit-test/global.php b/unit-test/global.php
index 0d4a005..8efdbcf 100644
--- a/unit-test/global.php
+++ b/unit-test/global.php
@@ -34,4 +34,4 @@ $_SESSION[SESSION_KEY.'g_pass']='phpcompta';
 $_SESSION[SESSION_KEY.'g_pagesize']='50';
 $g_user=new User($g_connection);
 
-require_once __DIR__.'/facility.class.php';
\ No newline at end of file
+require_once __DIR__.'/facility.class.php';
diff --git a/unit-test/include/lib/ac_common.php 
b/unit-test/include/lib/ac_common.php
new file mode 100644
index 0000000..b2bc19e
--- /dev/null
+++ b/unit-test/include/lib/ac_common.php
@@ -0,0 +1,171 @@
+<?php
+
+use PHPUnit\Framework\TestCase;
+
+class Ac_CommonTest extends TestCase
+{
+
+    /**
+     * @covers remove_divide_zero()
+     */
+    function testRemove_divide_byZero()
+    {
+        $value_test=array("55/0.0", "55/1", "1000/0.0+1", "999/0.002+5", 
"1200/0+5", "0 /0",
+            "0.0/1", "0. 0/0.0");
+        $expected=array("0", "55/1", "0+1", "999/0.002+5", "0+5", "0", 
"0.0/1", "0");
+        $nb_value=count($value_test);
+        for ($i=0; $i<$nb_value; $i++)
+        {
+            $this->assertEquals(remove_divide_zero($value_test[$i]), 
$expected[$i]);
+        }
+    }
+
+    /**
+     * @covers find_default_menu
+     * @global type $g_connection
+     */
+    function testFind_default_menu()
+    {
+        global $g_connection;
+        $g_connection->exec_sql("update profile_menu set pm_default = 0 where 
pm_id in (173,3,85)");
+        $this->assertEquals(find_default_menu(173), 0, "assert COMPTA has not 
default depending menu");
+        $this->assertEquals(find_default_menu(3), 0, "assert COMPTA has not 
default depending menu");
+        $g_connection->exec_sql("update profile_menu set pm_default = 1 where 
pm_id in (3,85)");
+        $this->assertEquals(find_default_menu(3), 85, "assert ACH depends of 
MENUACH");
+        $this->assertEquals(find_default_menu(173), 3, "assert  MENUACH 
depends of COMPTA");
+    }
+
+    /**
+     * @covers rebuild_access_code
+     */
+    function testRebuild_access_code()
+    {
+        // use profile 1 , 
+        // COMPTA 173
+        // COMPTA/MENUACH 3
+        // COMPTA/MENUACH/ACH  85
+        $this->assertEquals(
+                "COMPTA",
+                rebuild_access_code(array(
+            array("pm_id_v3"=>"0", "pm_id_v2"=>"0", "pm_id_v1"=>"173"))), 
"COMPTA String must not changed"
+        );
+        $this->assertEquals(
+                "COMPTA/MENUACH", 
rebuild_access_code(array(array("pm_id_v3"=>"0", "pm_id_v2"=>"173", 
"pm_id_v1"=>"3"))),
+                "COMPTA/MENUACH ");
+
+        $this->assertEquals(
+                "COMPTA/MENUACH/ACH",
+                rebuild_access_code(array(array("pm_id_v3"=>"173", 
"pm_id_v2"=>"3", "pm_id_v1"=>"85"))),
+                "COMPTA/MENUACH/ACH String must not changed");
+    }
+
+    /**
+     * @covers Complete_default_menu()
+     */
+    function testComplete_default_menu()
+    {
+        // use profile 1 , 
+        // COMPTA 173
+        // COMPTA/MENUACH 3
+        // COMPTA/MENUACH/ACH  85
+        global $g_connection;
+        $g_connection->exec_sql("update profile_menu set pm_default = 0 where 
pm_id in (173,3,85)");
+        $this->assertEquals(
+                array(array("pm_id_v3"=>"0", "pm_id_v2"=>"0", 
"pm_id_v1"=>"173")),
+                complete_default_menu(array(
+            array("pm_id_v3"=>"0", "pm_id_v2"=>"0", "pm_id_v1"=>"173"))),
+                "complete_default_menu() not default menu to add"
+        );
+        $this->assertEquals(
+                array(array("pm_id_v3"=>"0", "pm_id_v2"=>"173", 
"pm_id_v1"=>"3")),
+                complete_default_menu(array(array("pm_id_v3"=>"0", 
"pm_id_v2"=>"173", "pm_id_v1"=>"3"))),
+                "complete_default_menu() not default menu to add"
+        );
+
+        $this->assertEquals(
+                array(array("pm_id_v3"=>"173", "pm_id_v2"=>"3", 
"pm_id_v1"=>"85")),
+                complete_default_menu(array(array("pm_id_v3"=>"173", 
"pm_id_v2"=>"3", "pm_id_v1"=>"85"))),
+                "complete_default_menu() not default menu to add"
+        );
+
+        // complete default menu
+        $g_connection->exec_sql("update profile_menu set pm_default = 1 where 
pm_id in (3)");
+        $this->assertEquals(
+                array(array("pm_id_v3"=>"173", "pm_id_v2"=>"3", 
"pm_id_v1"=>"85")),
+                complete_default_menu(array(array("pm_id_v3"=>"173", 
"pm_id_v2"=>"3", "pm_id_v1"=>"85"))),
+                "complete_default_menu() not default menu to add"
+        );
+        $this->assertEquals(
+                array(array("pm_id_v3"=>"0", "pm_id_v2"=>"173", 
"pm_id_v1"=>"3")),
+                complete_default_menu(array(array("pm_id_v3"=>"0", 
"pm_id_v2"=>"0", "pm_id_v1"=>"173"))),
+                "complete_default_menu() add menu MENUACH(pm_id:3)"
+        );
+        $g_connection->exec_sql("update profile_menu set pm_default = 1 where 
pm_id in (85)");
+        $this->assertEquals(
+                array(array("pm_id_v3"=>"173", "pm_id_v2"=>"3", 
"pm_id_v1"=>"85")),
+                complete_default_menu(array(array("pm_id_v3"=>"0", 
"pm_id_v2"=>"0", "pm_id_v1"=>"173"))),
+                "complete_default_menu() add menu MENUACH(pm_id:3) and ACH 
(pm_id:85)"
+        );
+
+        $g_connection->exec_sql("update profile_menu set pm_default = 0 where 
pm_id in (3)");
+        $this->assertEquals(
+                array(array("pm_id_v3"=>"0", "pm_id_v2"=>"0", 
"pm_id_v1"=>"173")),
+                complete_default_menu(array(array("pm_id_v3"=>"0", 
"pm_id_v2"=>"0", "pm_id_v1"=>"173"))),
+                "complete_default_menu() does not add any menu "
+        );
+    }
+
+    /**
+     * @covers format_date
+     */
+    function testFormat_Date()
+    {
+        $this->assertEquals("2020-10-11", format_date("11.10.2020", 
"DD.MM.YYYY", "YYYY-MM-DD"),
+                "date from DD.MM.YYYY to YYYY-MM-DD");
+        $this->assertEquals("11-10-2020", format_date("11.10.2020", 
"DD.MM.YYYY", "DD-MM-YYYY"),
+                "date from DD.MM.YYYY to DD-MM-YYYY");
+        $this->assertEquals("20201011", format_date("11.10.2020", 
"DD.MM.YYYY", "YYYYMMDD"),
+                "date from DD.MM.YYYY to YYYYMMDD");
+        $this->assertEquals("2020/10/11", format_date("11.10.2020", 
"DD.MM.YYYY", "YYYY/MM/DD"),
+                "date from DD.MM.YYYY to YYYY/MM/DD");
+        $this->assertEquals("11.10.20", format_date("11.10.2020", 
"DD.MM.YYYY", "DD.MM.YY"),
+                "date from DD.MM.YYYY to DD.MM.YY");
+        $this->assertEquals("11-10-20", format_date("11.10.2020", 
"DD.MM.YYYY", "DD-MM-YY"),
+                "date from DD.MM.YYYY to DD/MM/YY");
+    }
+
+    function testShrinkDate()
+    {
+        $this->assertEquals("101120", shrink_date("10.11.2020"), "shrink_date 
");
+        $this->assertEquals("10.11.20", smaller_date("10.11.2020"), 
"smaller_date");
+    }
+
+    /**
+     * @covers sql_filter_per
+     */
+    function testSQL_filter_per()
+    {
+        global $g_connection;
+
+        $result="jr_tech_per in (select p_id from parm_periode  where ".
+                "p_start >= to_date('01.07.2018','DD.MM.YYYY') and p_end <= 
to_date('31.08.2018','DD.MM.YYYY'))";
+        $this->assertEquals(
+                $result, trim(sql_filter_per($g_connection, "01.07.2018", 
"31.08.2018", "date", "jr_tech_per")));
+
+        $result="j_tech_per in (select p_id from parm_periode  where ".
+                "p_start >= to_date('01.07.2018','DD.MM.YYYY') and p_end <= 
to_date('31.08.2018','DD.MM.YYYY'))";
+        $this->assertEquals(
+                $result, trim(sql_filter_per($g_connection, "01.07.2018", 
"31.08.2018", "date", "j_tech_per")));
+
+        $result="j_tech_per = (select p_id from parm_periode  where ".
+                " p_start = to_date('01.07.2018','DD.MM.YYYY'))";
+        $this->assertEquals(
+                $result, trim(sql_filter_per($g_connection, "01.07.2018", 
"01.07.2018", "date", "j_tech_per")));
+
+        $result="j_tech_per in (select p_id from parm_periode  where ".
+                "p_start >= to_date('01.07.2018','DD.MM.YYYY') and p_end <= 
to_date('31.08.2018','DD.MM.YYYY'))";
+        $this->assertEquals(
+                $result, trim(sql_filter_per($g_connection, 98, 99, "p_id", 
"j_tech_per")));
+    }
+
+}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]