PhpSpreadsheet/tests/PhpSpreadsheetTests/Calculation/LookupRefTest.php

189 lines
5.1 KiB
PHP
Raw Normal View History

<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
Add further new Functions introduced in MS Excel 2013 and 2016 (#608) - Fix ISFORMULA() function to work with a cell reference to another worksheet - Added calculation engine support for the new functions that were added in MS Excel 2013 and MS Excel 2016 - Text Functions - CONCAT() Synonym for CONCATENATE() - NUMBERVALUE() Converts text to a number, in a locale-independent way - UNICHAR() Synonym for CHAR() in PHPSpreadsheet, which has always used UTF-8 internally - UNIORD() Synonym for ORD() in PHPSpreadsheet, which has always used UTF-8 internally - TEXTJOIN() Joins together two or more text strings, separated by a delimiter - Logical Functions - XOR() Returns a logical Exclusive Or of all arguments - Date/Time Functions - ISOWEEKNUM() Returns the ISO 8601 week number of the year for a given date - Lookup and Reference Functions - FORMULATEXT() Returns a formula as a string - Engineering Functions - ERF.PRECISE() Returns the error function integrated between 0 and a supplied limit - ERFC.PRECISE() Synonym for ERFC - Math and Trig Functions - SEC() Returns the secant of an angle - SECH() Returns the hyperbolic secant of an angle - CSC() Returns the cosecant of an angle - CSCH() Returns the hyperbolic cosecant of an angle - COT() Returns the cotangent of an angle - COTH() Returns the hyperbolic cotangent of an angle - ACOT() Returns the cotangent of an angle - ACOTH() Returns the hyperbolic cotangent of an angle - Financial Functions - PDURATION() Calculates the number of periods required for an investment to reach a specified value - RRI() Calculates the interest rate required for an investment to grow to a specified future value
2018-07-22 18:17:04 +00:00
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PHPUnit\Framework\TestCase;
/**
2016-12-22 14:43:37 +00:00
* Class LookupRefTest.
*/
class LookupRefTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
2015-05-17 13:00:02 +00:00
}
/**
* @dataProvider providerHLOOKUP
*
* @param mixed $expectedResult
*/
public function testHLOOKUP($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = LookupRef::HLOOKUP(...$args);
self::assertEquals($expectedResult, $result);
2015-05-17 13:00:02 +00:00
}
public function providerHLOOKUP()
{
return require 'data/Calculation/LookupRef/HLOOKUP.php';
2015-05-17 13:00:02 +00:00
}
/**
* @dataProvider providerVLOOKUP
*
* @param mixed $expectedResult
*/
public function testVLOOKUP($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = LookupRef::VLOOKUP(...$args);
self::assertEquals($expectedResult, $result);
2015-05-17 13:00:02 +00:00
}
public function providerVLOOKUP()
{
return require 'data/Calculation/LookupRef/VLOOKUP.php';
2015-05-17 13:00:02 +00:00
}
/**
* @dataProvider providerLOOKUP
*
* @param mixed $expectedResult
*/
public function testLOOKUP($expectedResult, ...$args)
{
$result = LookupRef::LOOKUP(...$args);
self::assertEquals($expectedResult, $result);
}
public function providerLOOKUP()
{
return require 'data/Calculation/LookupRef/LOOKUP.php';
}
/**
* @dataProvider providerMATCH
*
* @param mixed $expectedResult
*/
public function testMATCH($expectedResult, ...$args)
{
$result = LookupRef::MATCH(...$args);
self::assertEquals($expectedResult, $result);
}
public function providerMATCH()
{
return require 'data/Calculation/LookupRef/MATCH.php';
}
/**
* @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';
}
/**
* @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';
}
Add further new Functions introduced in MS Excel 2013 and 2016 (#608) - Fix ISFORMULA() function to work with a cell reference to another worksheet - Added calculation engine support for the new functions that were added in MS Excel 2013 and MS Excel 2016 - Text Functions - CONCAT() Synonym for CONCATENATE() - NUMBERVALUE() Converts text to a number, in a locale-independent way - UNICHAR() Synonym for CHAR() in PHPSpreadsheet, which has always used UTF-8 internally - UNIORD() Synonym for ORD() in PHPSpreadsheet, which has always used UTF-8 internally - TEXTJOIN() Joins together two or more text strings, separated by a delimiter - Logical Functions - XOR() Returns a logical Exclusive Or of all arguments - Date/Time Functions - ISOWEEKNUM() Returns the ISO 8601 week number of the year for a given date - Lookup and Reference Functions - FORMULATEXT() Returns a formula as a string - Engineering Functions - ERF.PRECISE() Returns the error function integrated between 0 and a supplied limit - ERFC.PRECISE() Synonym for ERFC - Math and Trig Functions - SEC() Returns the secant of an angle - SECH() Returns the hyperbolic secant of an angle - CSC() Returns the cosecant of an angle - CSCH() Returns the hyperbolic cosecant of an angle - COT() Returns the cotangent of an angle - COTH() Returns the hyperbolic cotangent of an angle - ACOT() Returns the cotangent of an angle - ACOTH() Returns the hyperbolic cotangent of an angle - Financial Functions - PDURATION() Calculates the number of periods required for an investment to reach a specified value - RRI() Calculates the interest rate required for an investment to grow to a specified future value
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';
}
}