| 
									
										
										
										
											2013-11-20 09:55:05 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-31 17:18:12 +00:00
										 |  |  | namespace PhpOffice\PhpSpreadsheetTests; | 
					
						
							| 
									
										
										
										
											2016-08-14 04:08:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-31 17:18:12 +00:00
										 |  |  | use PhpOffice\PhpSpreadsheet\Calculation; | 
					
						
							|  |  |  | use PhpOffice\PhpSpreadsheet\Calculation\Functions; | 
					
						
							| 
									
										
										
										
											2015-05-29 20:35:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | class CalculationTest extends \PHPUnit_Framework_TestCase | 
					
						
							| 
									
										
										
										
											2013-11-20 09:55:05 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     public function setUp() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-08-14 04:08:43 +00:00
										 |  |  |         Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); | 
					
						
							| 
									
										
										
										
											2013-11-20 09:55:05 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider providerBinaryComparisonOperation | 
					
						
							| 
									
										
										
										
											2016-12-22 14:43:37 +00:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @param mixed $formula | 
					
						
							|  |  |  |      * @param mixed $expectedResultExcel | 
					
						
							|  |  |  |      * @param mixed $expectedResultOpenOffice | 
					
						
							| 
									
										
										
										
											2013-11-20 09:55:05 +00:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function testBinaryComparisonOperation($formula, $expectedResultExcel, $expectedResultOpenOffice) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-08-14 04:08:43 +00:00
										 |  |  |         Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); | 
					
						
							| 
									
										
										
										
											2015-05-29 20:35:35 +00:00
										 |  |  |         $resultExcel = Calculation::getInstance()->_calculateFormulaValue($formula); | 
					
						
							| 
									
										
										
										
											2013-11-20 09:55:05 +00:00
										 |  |  |         $this->assertEquals($expectedResultExcel, $resultExcel, 'should be Excel compatible'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-14 04:08:43 +00:00
										 |  |  |         Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE); | 
					
						
							| 
									
										
										
										
											2015-05-29 20:35:35 +00:00
										 |  |  |         $resultOpenOffice = Calculation::getInstance()->_calculateFormulaValue($formula); | 
					
						
							| 
									
										
										
										
											2013-11-20 09:55:05 +00:00
										 |  |  |         $this->assertEquals($expectedResultOpenOffice, $resultOpenOffice, 'should be OpenOffice compatible'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function providerBinaryComparisonOperation() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-08-16 12:00:19 +00:00
										 |  |  |         return require 'data/CalculationBinaryComparisonOperation.php'; | 
					
						
							| 
									
										
										
										
											2013-11-20 09:55:05 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-12-03 05:51:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider providerGetFunctions | 
					
						
							| 
									
										
										
										
											2016-12-22 14:43:37 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2017-01-23 06:34:49 +00:00
										 |  |  |      * @param string $category | 
					
						
							|  |  |  |      * @param array|string $functionCall | 
					
						
							|  |  |  |      * @param string $argumentCount | 
					
						
							| 
									
										
										
										
											2016-12-03 05:51:04 +00:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function testGetFunctions($category, $functionCall, $argumentCount) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-12-22 14:43:37 +00:00
										 |  |  |         $this->assertInternalType('callable', $functionCall); | 
					
						
							| 
									
										
										
										
											2016-12-03 05:51:04 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function providerGetFunctions() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return Calculation::getInstance()->getFunctions(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
											
												Use `::class` notation as much as possible
```
               *             ,
                           _/^\_
                          <     >
         *                 /.-.\         *
                  *        `/&\`                   *
                          ,@.*;@,
                         /_o.I %_\    *
            *           (`'--:o(_@;
                       /`;--.,__ `')             *
                      ;@`o % O,*`'`&\
                *    (`'--)_@ ;o %'()\      *
                     /`;--._`''--._O'@;
                    /&*,()~o`;-.,_ `""`)
         *          /`,@ ;+& () o*`;-';\
                   (`""--.,_0 +% @' &()\
                   /-.,_    ``''--....-'`)  *
              *    /@%;o`:;'--,.__   __.'\
                  ;*,&(); @ % &^;~`"`o;@();         *
                  /(); o^~; & ().o@*&`;&%O\
            jgs   `"="==""==,,,.,="=="==="`
               __.----.(\-''#####---...___...-----._
             '`         \)_`"""""`
                     .--' ')
                   o(  )_-\
                     `"""` `
```
											
										 
											2016-12-26 04:20:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function testIsImplemented() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $calculation = Calculation::getInstance(); | 
					
						
							|  |  |  |         $this->assertFalse($calculation->isImplemented('non-existing-function')); | 
					
						
							|  |  |  |         $this->assertFalse($calculation->isImplemented('AREAS')); | 
					
						
							|  |  |  |         $this->assertTrue($calculation->isImplemented('coUNt')); | 
					
						
							|  |  |  |         $this->assertTrue($calculation->isImplemented('abs')); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-01-23 06:34:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider providerCanLoadAllSupportedLocales | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param string $locale | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testCanLoadAllSupportedLocales($locale) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $calculation = Calculation::getInstance(); | 
					
						
							|  |  |  |         $this->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'], | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-11-20 09:55:05 +00:00
										 |  |  | } |