1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions; |
7
|
|
|
use PHPUnit_Framework_TestCase; |
8
|
|
|
|
9
|
|
|
class CalculationTest extends PHPUnit_Framework_TestCase |
10
|
|
|
{ |
11
|
|
|
public function setUp() |
12
|
|
|
{ |
13
|
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function tearDown() |
17
|
|
|
{ |
18
|
|
|
$calculation = Calculation::getInstance(); |
19
|
|
|
$calculation->setLocale('en_us'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @dataProvider providerBinaryComparisonOperation |
24
|
|
|
* |
25
|
|
|
* @param mixed $formula |
26
|
|
|
* @param mixed $expectedResultExcel |
27
|
|
|
* @param mixed $expectedResultOpenOffice |
28
|
|
|
*/ |
29
|
|
|
public function testBinaryComparisonOperation($formula, $expectedResultExcel, $expectedResultOpenOffice) |
30
|
|
|
{ |
31
|
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); |
32
|
|
|
$resultExcel = Calculation::getInstance()->_calculateFormulaValue($formula); |
33
|
|
|
self::assertEquals($expectedResultExcel, $resultExcel, 'should be Excel compatible'); |
34
|
|
|
|
35
|
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE); |
36
|
|
|
$resultOpenOffice = Calculation::getInstance()->_calculateFormulaValue($formula); |
37
|
|
|
self::assertEquals($expectedResultOpenOffice, $resultOpenOffice, 'should be OpenOffice compatible'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function providerBinaryComparisonOperation() |
41
|
|
|
{ |
42
|
|
|
return require 'data/CalculationBinaryComparisonOperation.php'; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @dataProvider providerGetFunctions |
47
|
|
|
* |
48
|
|
|
* @param string $category |
49
|
|
|
* @param array|string $functionCall |
50
|
|
|
* @param string $argumentCount |
51
|
|
|
*/ |
52
|
|
|
public function testGetFunctions($category, $functionCall, $argumentCount) |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
self::assertInternalType('callable', $functionCall); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function providerGetFunctions() |
58
|
|
|
{ |
59
|
|
|
return Calculation::getInstance()->getFunctions(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testIsImplemented() |
63
|
|
|
{ |
64
|
|
|
$calculation = Calculation::getInstance(); |
65
|
|
|
self::assertFalse($calculation->isImplemented('non-existing-function')); |
66
|
|
|
self::assertFalse($calculation->isImplemented('AREAS')); |
67
|
|
|
self::assertTrue($calculation->isImplemented('coUNt')); |
68
|
|
|
self::assertTrue($calculation->isImplemented('abs')); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @dataProvider providerCanLoadAllSupportedLocales |
73
|
|
|
* |
74
|
|
|
* @param string $locale |
75
|
|
|
*/ |
76
|
|
|
public function testCanLoadAllSupportedLocales($locale) |
77
|
|
|
{ |
78
|
|
|
$calculation = Calculation::getInstance(); |
79
|
|
|
self::assertTrue($calculation->setLocale($locale)); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function providerCanLoadAllSupportedLocales() |
83
|
|
|
{ |
84
|
|
|
return [ |
85
|
|
|
['bg'], |
86
|
|
|
['cs'], |
87
|
|
|
['da'], |
88
|
|
|
['de'], |
89
|
|
|
['en_us'], |
90
|
|
|
['es'], |
91
|
|
|
['fi'], |
92
|
|
|
['fr'], |
93
|
|
|
['hu'], |
94
|
|
|
['it'], |
95
|
|
|
['nl'], |
96
|
|
|
['no'], |
97
|
|
|
['pl'], |
98
|
|
|
['pt'], |
99
|
|
|
['pt_br'], |
100
|
|
|
['ru'], |
101
|
|
|
['sv'], |
102
|
|
|
['tr'], |
103
|
|
|
]; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.