Add phpunit for num2Alpha

This commit is contained in:
Laurent Destailleur 2022-05-31 18:17:43 +02:00
parent a253938db9
commit 21e5189e18
4 changed files with 25 additions and 5 deletions

View File

@ -185,7 +185,7 @@ function isASecretKey($keyname)
/**
* Return a numeric value into an Excel like column number. So 1 return 'A', 2 returns 'B'..., 27 return 'AA'
* Return a numeric value into an Excel like column number. So 0 return 'A', 1 returns 'B'..., 26 return 'AA'
*
* @param int|string $n Numeric value
* @return string Column in Excel format

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
/* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012-2016 Juanjo Menent <jmenent@2byte.es>
*
@ -446,7 +446,7 @@ class ImportXlsx extends ModeleImports
// Is it a required field ?
if (preg_match('/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval == '')) {
$this->errors[$error]['lib'] = $langs->trans('ErrorMissingMandatoryValue', num2Alpha($key));
$this->errors[$error]['lib'] = $langs->trans('ErrorMissingMandatoryValue', num2Alpha($key - 1));
$this->errors[$error]['type'] = 'NOTNULL';
$errorforthistable++;
$error++;

View File

@ -1743,7 +1743,7 @@ if ($step == 5 && $datatoimport) {
}
//print $code.'-'.$label;
$alias = preg_replace('/(\..*)$/i', '', $label);
$listfields[$i] = $langs->trans("Field").' '.$code.'->'.$label;
$listfields[$i] = $langs->trans("Column").' '.num2Alpha($code - 1).' -> '.$label;
}
print count($listfields) ? (join(', ', $listfields)) : $langs->trans("Error");
print '</td></tr>';

View File

@ -166,6 +166,26 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase
print __METHOD__."\n";
}
/**
* testNum2Alpha
*
* @return void
*/
public function testNum2Alpha()
{
$result = num2Alpha(0);
print __METHOD__." result=".$result."\n";
$this->assertEquals($result, 'A', 'Check num2Alpha 0');
$result = num2Alpha(5);
print __METHOD__." result=".$result."\n";
$this->assertEquals($result, 'F', 'Check num2Alpha 5');
$result = num2Alpha(26);
print __METHOD__." result=".$result."\n";
$this->assertEquals($result, 'AA', 'Check num2Alpha 26');
}
/**
* testIsValidEmail
*