Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lookup functions additional unit tests (#2074)
* Additional unit tests for VLOOKUP() and HLOOKUP() * Additional unit tests for CHOOSE() * Unit tests for HYPERLINK() function * Fix CHOOSE() test for spillage
- Loading branch information
Mark Baker
committed
May 7, 2021
1 parent
f28eea7
commit d2e6db7
Showing
7 changed files
with
142 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/HyperlinkTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef; | ||
|
||
use PhpOffice\PhpSpreadsheet\Calculation\Functions; | ||
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef; | ||
use PhpOffice\PhpSpreadsheet\Cell\Cell; | ||
use PhpOffice\PhpSpreadsheet\Cell\Hyperlink; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class HyperlinkTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider providerHYPERLINK | ||
* | ||
* @param mixed $expectedResult | ||
* @param null|string $linkUrl | ||
* @param null|string $description | ||
*/ | ||
public function testHYPERLINK($expectedResult, $linkUrl, $description): void | ||
{ | ||
$hyperlink = new Hyperlink(); | ||
|
||
$cell = $this->getMockBuilder(Cell::class) | ||
->onlyMethods(['getHyperlink']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$cell->method('getHyperlink') | ||
->willReturn($hyperlink); | ||
|
||
$result = LookupRef::HYPERLINK($linkUrl, $description, $cell); | ||
if (!is_array($expectedResult)) { | ||
self::assertSame($expectedResult, $result); | ||
} else { | ||
self::assertSame($expectedResult[1], $result); | ||
self::assertSame($expectedResult[0], $hyperlink->getUrl()); | ||
self::assertSame($expectedResult[1], $hyperlink->getTooltip()); | ||
} | ||
} | ||
|
||
public function providerHYPERLINK(): array | ||
{ | ||
return require 'tests/data/Calculation/LookupRef/HYPERLINK.php'; | ||
} | ||
|
||
public function testHYPERLINKwithoutCell(): void | ||
{ | ||
$result = LookupRef::HYPERLINK('https://phpspreadsheet.readthedocs.io/en/latest/', 'Read the Docs'); | ||
self::assertSame(Functions::REF(), $result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
use PhpOffice\PhpSpreadsheet\Calculation\Functions; | ||
|
||
return [ | ||
[ | ||
['https://phpspreadsheet.readthedocs.io/en/latest/', 'https://phpspreadsheet.readthedocs.io/en/latest/'], | ||
'https://phpspreadsheet.readthedocs.io/en/latest/', | ||
null, | ||
], | ||
[ | ||
['https://phpspreadsheet.readthedocs.io/en/latest/', 'Read the Docs'], | ||
'https://phpspreadsheet.readthedocs.io/en/latest/', | ||
'Read the Docs', | ||
], | ||
[ | ||
Functions::REF(), | ||
null, | ||
null, | ||
], | ||
[ | ||
Functions::REF(), | ||
'', | ||
null, | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters