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