1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\Cell; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\Hyperlink; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
class HyperlinkTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @dataProvider providerHYPERLINK |
15
|
|
|
* |
16
|
|
|
* @param mixed $expectedResult |
17
|
|
|
* @param null|string $linkUrl |
18
|
|
|
* @param null|string $description |
19
|
|
|
*/ |
20
|
|
|
public function testHYPERLINK($expectedResult, $linkUrl, $description): void |
21
|
|
|
{ |
22
|
|
|
$hyperlink = new Hyperlink(); |
23
|
|
|
|
24
|
|
|
$cell = $this->getMockBuilder(Cell::class) |
25
|
|
|
->onlyMethods(['getHyperlink']) |
26
|
|
|
->disableOriginalConstructor() |
27
|
|
|
->getMock(); |
28
|
|
|
$cell->method('getHyperlink') |
29
|
|
|
->willReturn($hyperlink); |
30
|
|
|
|
31
|
|
|
$result = LookupRef::HYPERLINK($linkUrl, $description, $cell); |
32
|
|
|
if (!is_array($expectedResult)) { |
33
|
|
|
self::assertSame($expectedResult, $result); |
34
|
|
|
} else { |
35
|
|
|
self::assertSame($expectedResult[1], $result); |
36
|
|
|
self::assertSame($expectedResult[0], $hyperlink->getUrl()); |
37
|
|
|
self::assertSame($expectedResult[1], $hyperlink->getTooltip()); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function providerHYPERLINK(): array |
42
|
|
|
{ |
43
|
|
|
return require 'tests/data/Calculation/LookupRef/HYPERLINK.php'; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testHYPERLINKwithoutCell(): void |
47
|
|
|
{ |
48
|
|
|
$result = LookupRef::HYPERLINK('https://phpspreadsheet.readthedocs.io/en/latest/', 'Read the Docs'); |
49
|
|
|
self::assertSame(Functions::REF(), $result); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|