| 
									
										
										
										
											2013-06-14 22:57:50 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-31 17:18:12 +00:00
										 |  |  | namespace PhpOffice\PhpSpreadsheetTests\Calculation; | 
					
						
							| 
									
										
										
										
											2013-06-14 22:57:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-31 17:18:12 +00:00
										 |  |  | use PhpOffice\PhpSpreadsheet\Calculation\Functions; | 
					
						
							|  |  |  | use PhpOffice\PhpSpreadsheet\Calculation\LookupRef; | 
					
						
							| 
									
										
										
										
											2018-07-22 18:17:04 +00:00
										 |  |  | use PhpOffice\PhpSpreadsheet\Cell\Cell; | 
					
						
							|  |  |  | use PhpOffice\PhpSpreadsheet\Spreadsheet; | 
					
						
							|  |  |  | use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; | 
					
						
							| 
									
										
										
										
											2017-11-08 15:48:01 +00:00
										 |  |  | use PHPUnit\Framework\TestCase; | 
					
						
							| 
									
										
										
										
											2016-08-14 04:08:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-20 06:41:09 +00:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2016-12-22 14:43:37 +00:00
										 |  |  |  * Class LookupRefTest. | 
					
						
							| 
									
										
										
										
											2016-05-20 06:41:09 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-11-08 15:48:01 +00:00
										 |  |  | class LookupRefTest extends TestCase | 
					
						
							| 
									
										
										
										
											2013-06-14 22:57:50 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-04-27 10:28:36 +00:00
										 |  |  |     protected function setUp(): void | 
					
						
							| 
									
										
										
										
											2013-06-14 22:57:50 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-08-14 04:08:43 +00:00
										 |  |  |         Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-06-14 22:57:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-22 18:17:04 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider providerFormulaText | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param mixed $expectedResult | 
					
						
							|  |  |  |      * @param mixed $reference       Reference to the cell we wish to test | 
					
						
							|  |  |  |      * @param mixed $value           Value of the cell we wish to test | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-05-18 04:49:57 +00:00
										 |  |  |     public function testFormulaText($expectedResult, $reference, $value = 'undefined'): void | 
					
						
							| 
									
										
										
										
											2018-07-22 18:17:04 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         $ourCell = null; | 
					
						
							|  |  |  |         if ($value !== 'undefined') { | 
					
						
							|  |  |  |             $remoteCell = $this->getMockBuilder(Cell::class) | 
					
						
							|  |  |  |                 ->disableOriginalConstructor() | 
					
						
							|  |  |  |                 ->getMock(); | 
					
						
							|  |  |  |             $remoteCell->method('isFormula') | 
					
						
							| 
									
										
										
										
											2020-05-18 04:49:57 +00:00
										 |  |  |                 ->willReturn(substr($value, 0, 1) == '='); | 
					
						
							| 
									
										
										
										
											2018-07-22 18:17:04 +00:00
										 |  |  |             $remoteCell->method('getValue') | 
					
						
							| 
									
										
										
										
											2020-05-18 04:49:57 +00:00
										 |  |  |                 ->willReturn($value); | 
					
						
							| 
									
										
										
										
											2018-07-22 18:17:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             $remoteSheet = $this->getMockBuilder(Worksheet::class) | 
					
						
							|  |  |  |                 ->disableOriginalConstructor() | 
					
						
							|  |  |  |                 ->getMock(); | 
					
						
							|  |  |  |             $remoteSheet->method('getCell') | 
					
						
							| 
									
										
										
										
											2020-05-18 04:49:57 +00:00
										 |  |  |                 ->willReturn($remoteCell); | 
					
						
							| 
									
										
										
										
											2018-07-22 18:17:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             $workbook = $this->getMockBuilder(Spreadsheet::class) | 
					
						
							|  |  |  |                 ->disableOriginalConstructor() | 
					
						
							|  |  |  |                 ->getMock(); | 
					
						
							|  |  |  |             $workbook->method('getSheetByName') | 
					
						
							| 
									
										
										
										
											2020-05-18 04:49:57 +00:00
										 |  |  |                 ->willReturn($remoteSheet); | 
					
						
							| 
									
										
										
										
											2018-07-22 18:17:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             $sheet = $this->getMockBuilder(Worksheet::class) | 
					
						
							|  |  |  |                 ->disableOriginalConstructor() | 
					
						
							|  |  |  |                 ->getMock(); | 
					
						
							|  |  |  |             $sheet->method('getCell') | 
					
						
							| 
									
										
										
										
											2020-05-18 04:49:57 +00:00
										 |  |  |                 ->willReturn($remoteCell); | 
					
						
							| 
									
										
										
										
											2018-07-22 18:17:04 +00:00
										 |  |  |             $sheet->method('getParent') | 
					
						
							| 
									
										
										
										
											2020-05-18 04:49:57 +00:00
										 |  |  |                 ->willReturn($workbook); | 
					
						
							| 
									
										
										
										
											2018-07-22 18:17:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             $ourCell = $this->getMockBuilder(Cell::class) | 
					
						
							|  |  |  |                 ->disableOriginalConstructor() | 
					
						
							|  |  |  |                 ->getMock(); | 
					
						
							|  |  |  |             $ourCell->method('getWorksheet') | 
					
						
							| 
									
										
										
										
											2020-05-18 04:49:57 +00:00
										 |  |  |                 ->willReturn($sheet); | 
					
						
							| 
									
										
										
										
											2018-07-22 18:17:04 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $result = LookupRef::FORMULATEXT($reference, $ourCell); | 
					
						
							| 
									
										
										
										
											2020-04-27 10:28:36 +00:00
										 |  |  |         self::assertEqualsWithDelta($expectedResult, $result, 1E-8); | 
					
						
							| 
									
										
										
										
											2018-07-22 18:17:04 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function providerFormulaText() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-05-17 09:35:55 +00:00
										 |  |  |         return require 'tests/data/Calculation/LookupRef/FORMULATEXT.php'; | 
					
						
							| 
									
										
										
										
											2018-07-22 18:17:04 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-06-14 22:57:50 +00:00
										 |  |  | } |