mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-10-09 05:16:18 +00:00
4001c89aaa
* isFormula Referencing Sheet With Space in Title See issue #2304. User sets a cell to `ISFORMULA(cell)`, where `cell` exists on a sheet whose title contains a space, and receives an error. Coordinates are not being passed correctly to Functions::isFormula; in particular, the sheet name is not enclosed in apostrophes, e.g. `Sheet Name!A1` rather than `'Sheet Name'!A1`. (Note that sheet name was not specified in Cell; PhpSpreadsheet adds it before calling isFormula.) Sheets without embedded spaces (or other non-word characters) are handled correctly with or without apostrophes, but spaces require surrounding apostrophes. As part of this investigation, I determined that Excel handles defined names and cell ranges in ISFORMULA (subject to spills), and that PhpSpreadsheet does not. It is changed to handle them. In the absence of spill support, it will use only the first cell in the range. Existing tests for ISFORMULA used mocking unneccesarily. They are moved to a separate test member, and mocking is no longer used. * PhpUnit and Jpgraph 35_Char_render.php had previously been a problem only for PHP8+. It is now a problem for PHP7.4, and will therefore be skipped all the time.
342 lines
9.0 KiB
PHP
342 lines
9.0 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class FunctionsTest extends TestCase
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
private $compatibilityMode;
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
private $returnDate;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->compatibilityMode = Functions::getCompatibilityMode();
|
|
$this->returnDate = Functions::getReturnDateType();
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
Functions::setCompatibilityMode($this->compatibilityMode);
|
|
Functions::setReturnDateType($this->returnDate);
|
|
}
|
|
|
|
public function testCompatibilityMode(): void
|
|
{
|
|
$result = Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC);
|
|
// Test for a true response for success
|
|
self::assertTrue($result);
|
|
// Test that mode has been changed
|
|
self::assertEquals(Functions::COMPATIBILITY_GNUMERIC, Functions::getCompatibilityMode());
|
|
}
|
|
|
|
public function testInvalidCompatibilityMode(): void
|
|
{
|
|
$result = Functions::setCompatibilityMode('INVALIDMODE');
|
|
// Test for a false response for failure
|
|
self::assertFalse($result);
|
|
// Test that mode has not been changed
|
|
self::assertEquals(Functions::COMPATIBILITY_EXCEL, Functions::getCompatibilityMode());
|
|
}
|
|
|
|
public function testReturnDateType(): void
|
|
{
|
|
$result = Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
|
|
// Test for a true response for success
|
|
self::assertTrue($result);
|
|
// Test that mode has been changed
|
|
self::assertEquals(Functions::RETURNDATE_PHP_OBJECT, Functions::getReturnDateType());
|
|
}
|
|
|
|
public function testInvalidReturnDateType(): void
|
|
{
|
|
$result = Functions::setReturnDateType('INVALIDTYPE');
|
|
// Test for a false response for failure
|
|
self::assertFalse($result);
|
|
// Test that mode has not been changed
|
|
self::assertEquals(Functions::RETURNDATE_EXCEL, Functions::getReturnDateType());
|
|
}
|
|
|
|
public function testDUMMY(): void
|
|
{
|
|
$result = Functions::DUMMY();
|
|
self::assertEquals('#Not Yet Implemented', $result);
|
|
}
|
|
|
|
public function testDIV0(): void
|
|
{
|
|
$result = Functions::DIV0();
|
|
self::assertEquals('#DIV/0!', $result);
|
|
}
|
|
|
|
public function testNA(): void
|
|
{
|
|
$result = Functions::NA();
|
|
self::assertEquals('#N/A', $result);
|
|
}
|
|
|
|
public function testNAN(): void
|
|
{
|
|
$result = Functions::NAN();
|
|
self::assertEquals('#NUM!', $result);
|
|
}
|
|
|
|
public function testNAME(): void
|
|
{
|
|
$result = Functions::NAME();
|
|
self::assertEquals('#NAME?', $result);
|
|
}
|
|
|
|
public function testREF(): void
|
|
{
|
|
$result = Functions::REF();
|
|
self::assertEquals('#REF!', $result);
|
|
}
|
|
|
|
public function testNULL(): void
|
|
{
|
|
$result = Functions::null();
|
|
self::assertEquals('#NULL!', $result);
|
|
}
|
|
|
|
public function testVALUE(): void
|
|
{
|
|
$result = Functions::VALUE();
|
|
self::assertEquals('#VALUE!', $result);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerIsBlank
|
|
*
|
|
* @param mixed $expectedResult
|
|
*/
|
|
public function testIsBlank($expectedResult, ...$args): void
|
|
{
|
|
$result = Functions::isBlank(...$args);
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
|
}
|
|
|
|
public function providerIsBlank(): array
|
|
{
|
|
return require 'tests/data/Calculation/Functions/IS_BLANK.php';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerIsErr
|
|
*
|
|
* @param mixed $expectedResult
|
|
*/
|
|
public function testIsErr($expectedResult, ...$args): void
|
|
{
|
|
$result = Functions::isErr(...$args);
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
|
}
|
|
|
|
public function providerIsErr(): array
|
|
{
|
|
return require 'tests/data/Calculation/Functions/IS_ERR.php';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerIsError
|
|
*
|
|
* @param mixed $expectedResult
|
|
*/
|
|
public function testIsError($expectedResult, ...$args): void
|
|
{
|
|
$result = Functions::isError(...$args);
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
|
}
|
|
|
|
public function providerIsError(): array
|
|
{
|
|
return require 'tests/data/Calculation/Functions/IS_ERROR.php';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerErrorType
|
|
*
|
|
* @param mixed $expectedResult
|
|
*/
|
|
public function testErrorType($expectedResult, ...$args): void
|
|
{
|
|
$result = Functions::errorType(...$args);
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
|
}
|
|
|
|
public function providerErrorType(): array
|
|
{
|
|
return require 'tests/data/Calculation/Functions/ERROR_TYPE.php';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerIsLogical
|
|
*
|
|
* @param mixed $expectedResult
|
|
*/
|
|
public function testIsLogical($expectedResult, ...$args): void
|
|
{
|
|
$result = Functions::isLogical(...$args);
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
|
}
|
|
|
|
public function providerIsLogical(): array
|
|
{
|
|
return require 'tests/data/Calculation/Functions/IS_LOGICAL.php';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerIsNa
|
|
*
|
|
* @param mixed $expectedResult
|
|
*/
|
|
public function testIsNa($expectedResult, ...$args): void
|
|
{
|
|
$result = Functions::isNa(...$args);
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
|
}
|
|
|
|
public function providerIsNa(): array
|
|
{
|
|
return require 'tests/data/Calculation/Functions/IS_NA.php';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerIsNumber
|
|
*
|
|
* @param mixed $expectedResult
|
|
*/
|
|
public function testIsNumber($expectedResult, ...$args): void
|
|
{
|
|
$result = Functions::isNumber(...$args);
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
|
}
|
|
|
|
public function providerIsNumber(): array
|
|
{
|
|
return require 'tests/data/Calculation/Functions/IS_NUMBER.php';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerIsText
|
|
*
|
|
* @param mixed $expectedResult
|
|
*/
|
|
public function testIsText($expectedResult, ...$args): void
|
|
{
|
|
$result = Functions::isText(...$args);
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
|
}
|
|
|
|
public function providerIsText(): array
|
|
{
|
|
return require 'tests/data/Calculation/Functions/IS_TEXT.php';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerIsNonText
|
|
*
|
|
* @param mixed $expectedResult
|
|
*/
|
|
public function testIsNonText($expectedResult, ...$args): void
|
|
{
|
|
$result = Functions::isNonText(...$args);
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
|
}
|
|
|
|
public function providerIsNonText(): array
|
|
{
|
|
return require 'tests/data/Calculation/Functions/IS_NONTEXT.php';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerIsEven
|
|
*
|
|
* @param mixed $expectedResult
|
|
*/
|
|
public function testIsEven($expectedResult, ...$args): void
|
|
{
|
|
$result = Functions::isEven(...$args);
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
|
}
|
|
|
|
public function providerIsEven(): array
|
|
{
|
|
return require 'tests/data/Calculation/Functions/IS_EVEN.php';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerIsOdd
|
|
*
|
|
* @param mixed $expectedResult
|
|
*/
|
|
public function testIsOdd($expectedResult, ...$args): void
|
|
{
|
|
$result = Functions::isOdd(...$args);
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
|
}
|
|
|
|
public function providerIsOdd(): array
|
|
{
|
|
return require 'tests/data/Calculation/Functions/IS_ODD.php';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerTYPE
|
|
*
|
|
* @param mixed $expectedResult
|
|
*/
|
|
public function testTYPE($expectedResult, ...$args): void
|
|
{
|
|
$result = Functions::TYPE(...$args);
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
|
}
|
|
|
|
public function providerTYPE(): array
|
|
{
|
|
return require 'tests/data/Calculation/Functions/TYPE.php';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerN
|
|
*
|
|
* @param mixed $expectedResult
|
|
*/
|
|
public function testN($expectedResult, ...$args): void
|
|
{
|
|
$result = Functions::n(...$args);
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
|
}
|
|
|
|
public function providerN(): array
|
|
{
|
|
return require 'tests/data/Calculation/Functions/N.php';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerIfCondition
|
|
*
|
|
* @param mixed $expectedResult
|
|
*/
|
|
public function testIfCondition($expectedResult, ...$args): void
|
|
{
|
|
$result = Functions::ifCondition(...$args);
|
|
self::assertEquals($expectedResult, $result);
|
|
}
|
|
|
|
public function providerIfCondition(): array
|
|
{
|
|
return require 'tests/data/Calculation/Functions/IF_CONDITION.php';
|
|
}
|
|
}
|