aef4d711f5
Because even if it doesn't make a difference in practice, it is technically more correct to call static methods statically. It also better advertise that those methods can be used from any context.
100 lines
2.8 KiB
PHP
100 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation;
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
use PHPUnit_Framework_TestCase;
|
|
|
|
class CalculationTest extends PHPUnit_Framework_TestCase
|
|
{
|
|
public function setUp()
|
|
{
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerBinaryComparisonOperation
|
|
*
|
|
* @param mixed $formula
|
|
* @param mixed $expectedResultExcel
|
|
* @param mixed $expectedResultOpenOffice
|
|
*/
|
|
public function testBinaryComparisonOperation($formula, $expectedResultExcel, $expectedResultOpenOffice)
|
|
{
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
$resultExcel = Calculation::getInstance()->_calculateFormulaValue($formula);
|
|
self::assertEquals($expectedResultExcel, $resultExcel, 'should be Excel compatible');
|
|
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
|
|
$resultOpenOffice = Calculation::getInstance()->_calculateFormulaValue($formula);
|
|
self::assertEquals($expectedResultOpenOffice, $resultOpenOffice, 'should be OpenOffice compatible');
|
|
}
|
|
|
|
public function providerBinaryComparisonOperation()
|
|
{
|
|
return require 'data/CalculationBinaryComparisonOperation.php';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerGetFunctions
|
|
*
|
|
* @param string $category
|
|
* @param array|string $functionCall
|
|
* @param string $argumentCount
|
|
*/
|
|
public function testGetFunctions($category, $functionCall, $argumentCount)
|
|
{
|
|
self::assertInternalType('callable', $functionCall);
|
|
}
|
|
|
|
public function providerGetFunctions()
|
|
{
|
|
return Calculation::getInstance()->getFunctions();
|
|
}
|
|
|
|
public function testIsImplemented()
|
|
{
|
|
$calculation = Calculation::getInstance();
|
|
self::assertFalse($calculation->isImplemented('non-existing-function'));
|
|
self::assertFalse($calculation->isImplemented('AREAS'));
|
|
self::assertTrue($calculation->isImplemented('coUNt'));
|
|
self::assertTrue($calculation->isImplemented('abs'));
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerCanLoadAllSupportedLocales
|
|
*
|
|
* @param string $locale
|
|
*/
|
|
public function testCanLoadAllSupportedLocales($locale)
|
|
{
|
|
$calculation = Calculation::getInstance();
|
|
self::assertTrue($calculation->setLocale($locale));
|
|
}
|
|
|
|
public function providerCanLoadAllSupportedLocales()
|
|
{
|
|
return [
|
|
['bg'],
|
|
['cs'],
|
|
['da'],
|
|
['de'],
|
|
['en_us'],
|
|
['es'],
|
|
['fi'],
|
|
['fr'],
|
|
['hu'],
|
|
['it'],
|
|
['nl'],
|
|
['no'],
|
|
['pl'],
|
|
['pt'],
|
|
['pt_br'],
|
|
['ru'],
|
|
['sv'],
|
|
['tr'],
|
|
];
|
|
}
|
|
}
|