| 
									
										
										
										
											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
										 |  |  | { | 
					
						
							|  |  |  |     public function setUp() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider providerHLOOKUP | 
					
						
							| 
									
										
										
										
											2017-01-23 05:49:10 +00:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @param mixed $expectedResult | 
					
						
							| 
									
										
										
										
											2013-06-14 22:57:50 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-01-23 05:49:10 +00:00
										 |  |  |     public function testHLOOKUP($expectedResult, ...$args) | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-01-23 05:49:10 +00:00
										 |  |  |         $result = LookupRef::HLOOKUP(...$args); | 
					
						
							| 
									
										
										
										
											2017-09-20 05:55:42 +00:00
										 |  |  |         self::assertEquals($expectedResult, $result); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-06-14 22:57:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function providerHLOOKUP() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-08-16 12:00:19 +00:00
										 |  |  |         return require 'data/Calculation/LookupRef/HLOOKUP.php'; | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-06-14 22:57:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-15 11:15:03 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider providerVLOOKUP | 
					
						
							| 
									
										
										
										
											2017-01-23 05:49:10 +00:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @param mixed $expectedResult | 
					
						
							| 
									
										
										
										
											2013-06-15 11:15:03 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-01-23 05:49:10 +00:00
										 |  |  |     public function testVLOOKUP($expectedResult, ...$args) | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-01-23 05:49:10 +00:00
										 |  |  |         $result = LookupRef::VLOOKUP(...$args); | 
					
						
							| 
									
										
										
										
											2017-09-20 05:55:42 +00:00
										 |  |  |         self::assertEquals($expectedResult, $result); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-06-15 11:15:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function providerVLOOKUP() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-08-16 12:00:19 +00:00
										 |  |  |         return require 'data/Calculation/LookupRef/VLOOKUP.php'; | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-04-01 03:36:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider providerMATCH | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param mixed $expectedResult | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testMATCH($expectedResult, ...$args) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $result = LookupRef::MATCH(...$args); | 
					
						
							| 
									
										
										
										
											2017-09-20 05:55:42 +00:00
										 |  |  |         self::assertEquals($expectedResult, $result); | 
					
						
							| 
									
										
										
										
											2017-04-01 03:36:02 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function providerMATCH() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return require 'data/Calculation/LookupRef/MATCH.php'; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-09-30 03:13:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider providerINDEX | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param mixed $expectedResult | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testINDEX($expectedResult, ...$args) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $result = LookupRef::INDEX(...$args); | 
					
						
							|  |  |  |         self::assertEquals($expectedResult, $result); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function providerINDEX() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return require 'data/Calculation/LookupRef/INDEX.php'; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-01-13 08:58:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider providerCOLUMNS | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param mixed $expectedResult | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testCOLUMNS($expectedResult, ...$args) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $result = LookupRef::COLUMNS(...$args); | 
					
						
							|  |  |  |         self::assertEquals($expectedResult, $result); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function providerCOLUMNS() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return require 'data/Calculation/LookupRef/COLUMNS.php'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider providerROWS | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param mixed $expectedResult | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testROWS($expectedResult, ...$args) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $result = LookupRef::ROWS(...$args); | 
					
						
							|  |  |  |         self::assertEquals($expectedResult, $result); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function providerROWS() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return require 'data/Calculation/LookupRef/ROWS.php'; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testFormulaText($expectedResult, $reference, $value = 'undefined') | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $ourCell = null; | 
					
						
							|  |  |  |         if ($value !== 'undefined') { | 
					
						
							|  |  |  |             $remoteCell = $this->getMockBuilder(Cell::class) | 
					
						
							|  |  |  |                 ->disableOriginalConstructor() | 
					
						
							|  |  |  |                 ->getMock(); | 
					
						
							|  |  |  |             $remoteCell->method('isFormula') | 
					
						
							|  |  |  |                 ->will($this->returnValue(substr($value, 0, 1) == '=')); | 
					
						
							|  |  |  |             $remoteCell->method('getValue') | 
					
						
							|  |  |  |                 ->will($this->returnValue($value)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $remoteSheet = $this->getMockBuilder(Worksheet::class) | 
					
						
							|  |  |  |                 ->disableOriginalConstructor() | 
					
						
							|  |  |  |                 ->getMock(); | 
					
						
							|  |  |  |             $remoteSheet->method('getCell') | 
					
						
							|  |  |  |                 ->will($this->returnValue($remoteCell)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $workbook = $this->getMockBuilder(Spreadsheet::class) | 
					
						
							|  |  |  |                 ->disableOriginalConstructor() | 
					
						
							|  |  |  |                 ->getMock(); | 
					
						
							|  |  |  |             $workbook->method('getSheetByName') | 
					
						
							|  |  |  |                 ->will($this->returnValue($remoteSheet)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $sheet = $this->getMockBuilder(Worksheet::class) | 
					
						
							|  |  |  |                 ->disableOriginalConstructor() | 
					
						
							|  |  |  |                 ->getMock(); | 
					
						
							|  |  |  |             $sheet->method('getCell') | 
					
						
							|  |  |  |                 ->will($this->returnValue($remoteCell)); | 
					
						
							|  |  |  |             $sheet->method('getParent') | 
					
						
							|  |  |  |                 ->will($this->returnValue($workbook)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $ourCell = $this->getMockBuilder(Cell::class) | 
					
						
							|  |  |  |                 ->disableOriginalConstructor() | 
					
						
							|  |  |  |                 ->getMock(); | 
					
						
							|  |  |  |             $ourCell->method('getWorksheet') | 
					
						
							|  |  |  |                 ->will($this->returnValue($sheet)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $result = LookupRef::FORMULATEXT($reference, $ourCell); | 
					
						
							|  |  |  |         self::assertEquals($expectedResult, $result, null, 1E-8); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function providerFormulaText() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return require 'data/Calculation/LookupRef/FORMULATEXT.php'; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-06-14 22:57:50 +00:00
										 |  |  | } |