Add holiday date functions into PHPUnit

This commit is contained in:
Laurent Destailleur 2015-11-28 19:54:16 +01:00
parent acbbb70c44
commit 5d5cfd498a
2 changed files with 79 additions and 1 deletions

View File

@ -542,6 +542,7 @@ function dol_get_first_day_week($day,$month,$year,$gm=false)
* @param string $countrycode Country code
* @param int $lastday Last day is included, 0: no, 1:yes
* @return int Nombre de jours feries
* @see num_between_day, num_open_day
*/
function num_public_holiday($timestampStart, $timestampEnd, $countrycode='FR', $lastday=0)
{
@ -722,6 +723,7 @@ function num_public_holiday($timestampStart, $timestampEnd, $countrycode='FR', $
* @param int $timestampEnd Timestamp end UTC
* @param int $lastday Last day is included, 0: no, 1:yes
* @return int Number of days
* @see also num_public_holiday, num_open_day
*/
function num_between_day($timestampStart, $timestampEnd, $lastday=0)
{
@ -751,6 +753,7 @@ function num_between_day($timestampStart, $timestampEnd, $lastday=0)
* @param int $halfday Tag to define half day when holiday start and end
* @param string $country_code Country code (company country code if not defined)
* @return int Number of days or hours
* @see also num_between_day, num_public_holiday
*/
function num_open_day($timestampStart, $timestampEnd, $inhour=0, $lastday=0, $halfday=0, $country_code='')
{

View File

@ -167,7 +167,82 @@ class DateLibTest extends PHPUnit_Framework_TestCase
return $result;
}
/**
* testNumPublicHoliday
*
* @return void
*/
public function testNumPublicHoliday()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
// With same hours - Tuesday/Wednesday jan 2013
$date1=dol_mktime(0, 0, 0, 1, 1, 2013);
$date2=dol_mktime(0, 0, 0, 1, 2, 2013);
$result=num_public_holiday($date1,$date2,'FR',1);
print __METHOD__." result=".$result."\n";
$this->assertEquals(1,$result,'NumPublicHoliday for Tuesday/Wednesday jan 2013 for FR'); // 1 closed days
$result=num_public_holiday($date1,$date2,'XX',1);
print __METHOD__." result=".$result."\n";
$this->assertEquals(0,$result,'NumPublicHoliday for Tuesday/Wednesday jan 2013 for XX'); // no closed days (country unknown)
// With same hours - Friday/Sunday jan 2013
$date1=dol_mktime(0, 0, 0, 1, 4, 2013);
$date2=dol_mktime(0, 0, 0, 1, 6, 2013);
$result=num_public_holiday($date1,$date2,'FR',1);
print __METHOD__." result=".$result."\n";
$this->assertEquals(2,$result,'NumPublicHoliday for FR'); // 1 opened day, 2 closed days
$result=num_public_holiday($date1,$date2,'XX',1);
print __METHOD__." result=".$result."\n";
$this->assertEquals(2,$result,'NumPublicHoliday for XX'); // 1 opened day, 2 closed days (even if country unknown)
}
/**
* testNumOpenDay
*
* @return void
*/
public function testNumOpenDay()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
// With same hours - Tuesday/Wednesday jan 2013
$date1=dol_mktime(0, 0, 0, 1, 1, 2013);
$date2=dol_mktime(0, 0, 0, 1, 2, 2013);
$result=num_open_day($date1,$date2,0,1,0,'FR');
print __METHOD__." result=".$result."\n";
$this->assertEquals(1,$result,'NumOpenDay Tuesday/Wednesday jan 2013 for FR'); // 1 opened days
$result=num_open_day($date1,$date2,0,1,0,'XX');
print __METHOD__." result=".$result."\n";
$this->assertEquals(2,$result,'NumOpenDay Tuesday/Wednesday jan 2013 for XX'); // 2 opened days (country unknown)
// With same hours - Friday/Sunday jan 2013
$date1=dol_mktime(0, 0, 0, 1, 4, 2013);
$date2=dol_mktime(0, 0, 0, 1, 6, 2013);
$result=num_open_day($date1,$date2,0,1,0,'FR');
print __METHOD__." result=".$result."\n";
$this->assertEquals(1,$result,'NumOpenDay for FR'); // 1 opened day, 2 closed
$result=num_open_day($date1,$date2,'XX',1);
print __METHOD__." result=".$result."\n";
$this->assertEquals(1,$result,'NumOpenDay for XX'); // 1 opened day, 2 closes (even if country unknown)
}
/**
* testConvertTime2Seconds
*