mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-22 16:19:19 +00:00
e9cf27354d
Successor to PR #3523. There are 494 single-line changes (`public function provider` to `public static function provider`) in this PR. None of these were made manually; they were all created with the following script (adapted from https://stackoverflow.com/questions/25909820/how-to-recursively-iterate-through-files-in-php): ```php $dir = 'C:/git/unit10prep2/tests/PhpSpreadsheetTests'; $it = new RecursiveDirectoryIterator($dir); // Loop through files foreach(new RecursiveIteratorIterator($it) as $file) { if ($file->getExtension() === 'php') { $contents = file_get_contents($file); $new = preg_replace('/public function (\\w*)([Pp])rovider/', 'public static function $1$2rovider', $contents); if ($new !== $contents) { echo "changing $file\n"; file_put_contents($file, $new); } } } ``` After this PR, there will be one more, with a small number of test changes, and enabling PhpUnit 10 for Php 8.1+.
60 lines
3.1 KiB
PHP
60 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Writer\Xlsx;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\FunctionPrefix;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class FunctionPrefixTest extends TestCase
|
|
{
|
|
/**
|
|
* @dataProvider functionPrefixProvider
|
|
*/
|
|
public function testFunctionPrefix(string $expectedResult, string $functionString): void
|
|
{
|
|
$result = FunctionPrefix::addFunctionPrefix($functionString);
|
|
self::assertSame($expectedResult, $result);
|
|
}
|
|
|
|
public static function functionPrefixProvider(): array
|
|
{
|
|
return [
|
|
'Basic Legacy Function' => ['SUM()', 'SUM()'],
|
|
'New Function without Prefix' => ['_xlfn.ARABIC()', 'ARABIC()'],
|
|
'New Function already Prefixed' => ['_xlfn.ARABIC()', '_xlfn.ARABIC()'],
|
|
'New Function requiring Double-Prefix' => ['_xlfn._xlws.FILTER()', 'FILTER()'],
|
|
'New Function requiring Double-Prefix already partially Prefixed' => ['_xlfn._xlws.FILTER()', '_xlfn.FILTER()'],
|
|
'New Function requiring Double-Prefix already partially Prefixed #2' => ['_xlfn._xlws.FILTER()', '_xlws.FILTER()'],
|
|
'New Function requiring Double-Prefix already Fully Prefixed' => ['_xlfn._xlws.FILTER()', '_xlfn._xlws.FILTER()'],
|
|
'Multiple Functions' => ['_xlfn._xlws.SORT(_xlfn._xlws.FILTER(A:A, A:A<>""))', 'SORT(FILTER(A:A, A:A<>""))'],
|
|
'DAYS/NETWORKDAYS 1' => ['_xlfn.DAYS(DATE(2023,1,1),TODAY())', 'DAYS(DATE(2023,1,1),TODAY())'],
|
|
'DAYS/NETWORKDAYS 2' => ['_xlfn.DAYS(DATE(2023,1,1),TODAY())', '_xlfn.DAYS(DATE(2023,1,1),TODAY())'],
|
|
'DAYS/NETWORKDAYS 3' => ['ABS(_xlfn.DAYS(DATE(2023,1,1),TODAY()))', 'ABS(DAYS(DATE(2023,1,1),TODAY()))'],
|
|
'DAYS/NETWORKDAYS 4' => ['ABS(_xlfn.DAYS(DATE(2023,1,1),TODAY()))', 'ABS(_xlfn.DAYS(DATE(2023,1,1),TODAY()))'],
|
|
'DAYS/NETWORKDAYS 5' => ['NETWORKDAYS(DATE(2023,1,1),TODAY(), C:C)', 'NETWORKDAYS(DATE(2023,1,1),TODAY(), C:C)'],
|
|
];
|
|
}
|
|
|
|
// /**
|
|
// * @dataProvider functionPrefixWithEqualsProvider
|
|
// */
|
|
// public function testFunctionPrefixWithEquals(string $expectedResult, string $functionString): void
|
|
// {
|
|
// $result = FunctionPrefix::addFunctionPrefixStripEquals($functionString);
|
|
// self::assertSame($expectedResult, $result);
|
|
// }
|
|
//
|
|
// public static function functionPrefixWithEqualsProvider(): array
|
|
// {
|
|
// return [
|
|
// 'Basic Legacy Function' => ['SUM()', '=SUM()'],
|
|
// 'New Function without Prefix' => ['_xlfn.ARABIC()', '=ARABIC()'],
|
|
// 'New Function already Prefixed' => ['_xlfn.ARABIC()', '=_xlfn.ARABIC()'],
|
|
// 'New Function requiring Double-Prefix' => ['_xlfn._xlws.FILTER()', '=FILTER()'],
|
|
// 'New Function requiring Double-Prefix already partially Prefixed' => ['_xlfn._xlws.FILTER()', '=_xlfn.FILTER()'],
|
|
// 'New Function requiring Double-Prefix already partially Prefixed #2' => ['_xlfn._xlws.FILTER()', '=_xlws.FILTER()'],
|
|
// 'New Function requiring Double-Prefix already Fully Prefixed' => ['_xlfn._xlws.FILTER()', '=_xlfn._xlws.FILTER()'],
|
|
// ];
|
|
// }
|
|
}
|