FollowUp : add test, correct bug related to ag_id , sort on priority

This commit is contained in:
sparkyx 2024-05-17 20:13:37 +02:00
parent 470559cc61
commit adf4134e5c
2 changed files with 131 additions and 17 deletions

View file

@ -714,8 +714,9 @@ class Follow_Up
// 8
$table->add(_('Dernier comm.'), $url, 'order by last_comment_date nulls last', 'order by last_comment_date desc nulls last', 'dca', 'dcd');
// 9
$table->add(_('Priorité'), $url, 'order by last_comment_date nulls last', 'order by last_comment_date desc nulls last', 'dca', 'dcd');
$ord=(!isset($_GET['ord']))?"dcd":$_GET['ord'];
$table->add(_('Priorité'), $url, 'order by ag_priority ', 'order by ag_priority desc ', 'pra', 'prd');
$http=new HttpInput();
$ord=$http->get("ord","string","dcd");
$sort=$table->get_sql_order($ord);
if (noalyss_strlentrim($p_filter)!=0)
@ -753,8 +754,7 @@ class Follow_Up
$r.='<th style="width:5.57%">'.$table->get_header(8).'</th>';
$r.='<th style="width:5.57%">'.$table->get_header(2).'</th>';
$r.='<th style="width:5.57%">'.$table->get_header(5).'</th>';
// $r.='<th>'.$table->get_header(1).'</th>';
$r.=th('Priorité','style="width:5.57%"');
$r.='<th style="width:5.57%">'.$table->get_header(9).'</th>';
$r.='<th style="min-width:45%">'.$table->get_header(6).'</th>';
$r.='<th style="width:5.57%">'.$table->get_header(7).'</th>';
$r.='<th style="max-width:10%">'.$table->get_header(3).'</th>';
@ -842,14 +842,6 @@ class Follow_Up
}
$r.="</td>";
$r.="<td>".$href.h($row['dest']).'</a>'."</td>";
$r.="</tr>";
}
@ -1430,18 +1422,18 @@ class Follow_Up
if ($p_array==null) $p_array=$_GET;
$http=new HttpInput();
$http->set_array($p_array);
$search_docid=0; // search for a document
$action_query="";
$ag_state=""; //<! selected status of the event , if not set or equal to -1 , it is all of them
//
// search for a specific document id (ag_id) , if given then status and date doesn't count
if (isset ($p_array['ag_id']) && isNumber($p_array['ag_id'])==1&&$p_array['ag_id']!=0)
{
$action_query=" and ag_id= ".sql_string($p_array['ag_id']);
$search_docid=$p_array['ag_id'];
$action_query=" and ag.ag_id= ".sql_string($p_array['ag_id']);
$action_query.=" and ".Follow_Up::sql_security_filter($cn,'R');
return $action_query;
}
if (isset($_REQUEST['action_query']) && trim($_REQUEST['action_query']??"") != "")
if (isset($p_array['action_query']) && trim($p_array['action_query']??"") != "")
{
$action_query = $http->extract('action_query');
// if a query is request build the sql stmt
@ -1591,7 +1583,7 @@ class Follow_Up
$p_search=self::create_query($this->db, $p_array);
$sql="
select ag_id,
select ag.ag_id,
to_char(ag_timestamp,'DD.MM.YYYY') as my_date,
to_char(ag_remind_date,'DD.MM.YYYY') as my_remind,
to_char(coalesce((select max(agc_date) from action_gestion_comment as agc where agc.ag_id=ag_id),ag_timestamp),'DD.MM.YY') as last_comment,

View file

@ -0,0 +1,122 @@
<?php
/*
* * Copyright (C) 2022 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.
*
*
* Author : Dany De Bontridder danydb@noalyss.eu $(DATE)
*/
/**
* @file
* @brief noalyss
*/
use PHPUnit\Framework\TestCase;
require DIRTEST . '/global.php';
/**
* @testdox Class followupTest : used for ...
* @backupGlobals enabled
* @coversDefaultClass
*/
class FollowupTest extends TestCase
{
/**
* @var Fiche
*/
protected $object;
protected $connection;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test method is executed.
*/
protected function setUp(): void
{
$this->connection=\Dossier::connect();
$this->object=new Follow_Up($this->connection);
}
/**
* @testdox create query search by AG_ID
* @covers Follow_Up::create_query
* @backupGlobals enabled
*/
function testSearch_Ag_ID()
{
global $g_user;
$g_user=new Noalyss_User($this->connection);
$query=Follow_Up::create_query($this->connection,array("ag_id"=>2));
$sql=Follow_Up::SQL_list_action()." where 1=1 $query";
$array=$this->connection->get_array($sql);
$this->assertEquals(2,$array[0]['ag_id']);
$this->assertEquals('COURRI6-1',$array[0]['ag_ref']);
}
/**
* @testdox create query search by Action_Query
* @covers Follow_Up::create_query
* @backupGlobals enabled
*/
function testSearch_action_query()
{
global $g_user;
$g_user=new Noalyss_User($this->connection);
$query=Follow_Up::create_query($this->connection,array("action_query"=>'test'));
$sql=Follow_Up::SQL_list_action()." where 1=1 $query";
$array=$this->connection->get_array($sql);
$this->assertEquals(2, count($array));
$this->assertEquals(1,$array[0]['ag_id']);
$this->assertEquals('BONDEC3-1',$array[0]['ag_ref']);
}
/**
* @testdox create query search by QCode
* @covers Follow_Up::create_query
* @backupGlobals enabled
*/
function testSearch_qcode()
{
global $g_user;
$g_user=new Noalyss_User($this->connection);
$query=Follow_Up::create_query($this->connection,array("qcode"=>'CLIENT1'));
$sql=Follow_Up::SQL_list_action()." where 1=1 $query";
$array=$this->connection->get_array($sql);
$this->assertEquals(1,$array[0]['ag_id']);
$this->assertEquals('BONDEC3-1',$array[0]['ag_ref']);
}
/**
* @testdox export and search with ag_id
* @covers Follow_Up::export_csv,Follow_Up::create_query
* @backupGlobals enabled
*/
function testExport_CSV_Ag_ID()
{
global $g_user;
$g_user=new Noalyss_User($this->connection);
ob_start();
$this->object->export_csv(["ag_id"=>2]);
$content=ob_get_contents();
ob_end_clean();
$this->assertStringContainsString("COURRI6-1", $content);
}
}