1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Cell; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\Hyperlink; |
6
|
|
|
|
7
|
|
|
class HyperlinkTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
public function testGetUrl() |
10
|
|
|
{ |
11
|
|
|
$urlValue = 'http://www.phpexcel.net'; |
12
|
|
|
|
13
|
|
|
$testInstance = new Hyperlink($urlValue); |
14
|
|
|
|
15
|
|
|
$result = $testInstance->getUrl(); |
16
|
|
|
$this->assertEquals($urlValue, $result); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
View Code Duplication |
public function testSetUrl() |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
$initialUrlValue = 'http://www.phpexcel.net'; |
22
|
|
|
$newUrlValue = 'http://github.com/PHPOffice/PhpSpreadsheet'; |
23
|
|
|
|
24
|
|
|
$testInstance = new Hyperlink($initialUrlValue); |
25
|
|
|
$result = $testInstance->setUrl($newUrlValue); |
26
|
|
|
$this->assertTrue($result instanceof Hyperlink); |
27
|
|
|
|
28
|
|
|
$result = $testInstance->getUrl(); |
29
|
|
|
$this->assertEquals($newUrlValue, $result); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testGetTooltip() |
33
|
|
|
{ |
34
|
|
|
$tooltipValue = 'PhpSpreadsheet Web Site'; |
35
|
|
|
|
36
|
|
|
$testInstance = new Hyperlink(null, $tooltipValue); |
37
|
|
|
|
38
|
|
|
$result = $testInstance->getTooltip(); |
39
|
|
|
$this->assertEquals($tooltipValue, $result); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
View Code Duplication |
public function testSetTooltip() |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
$initialTooltipValue = 'PhpSpreadsheet Web Site'; |
45
|
|
|
$newTooltipValue = 'PhpSpreadsheet Repository on Github'; |
46
|
|
|
|
47
|
|
|
$testInstance = new Hyperlink(null, $initialTooltipValue); |
48
|
|
|
$result = $testInstance->setTooltip($newTooltipValue); |
49
|
|
|
$this->assertTrue($result instanceof Hyperlink); |
50
|
|
|
|
51
|
|
|
$result = $testInstance->getTooltip(); |
52
|
|
|
$this->assertEquals($newTooltipValue, $result); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
View Code Duplication |
public function testIsInternal() |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
$initialUrlValue = 'http://www.phpexcel.net'; |
58
|
|
|
$newUrlValue = 'sheet://Worksheet1!A1'; |
59
|
|
|
|
60
|
|
|
$testInstance = new Hyperlink($initialUrlValue); |
61
|
|
|
$result = $testInstance->isInternal(); |
62
|
|
|
$this->assertFalse($result); |
63
|
|
|
|
64
|
|
|
$testInstance->setUrl($newUrlValue); |
65
|
|
|
$result = $testInstance->isInternal(); |
66
|
|
|
$this->assertTrue($result); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testGetHashCode() |
70
|
|
|
{ |
71
|
|
|
$urlValue = 'http://www.phpexcel.net'; |
72
|
|
|
$tooltipValue = 'PhpSpreadsheet Web Site'; |
73
|
|
|
$initialExpectedHash = '6f1d4cbf40034b9ddc3fbf6019506e91'; |
74
|
|
|
|
75
|
|
|
$testInstance = new Hyperlink($urlValue, $tooltipValue); |
76
|
|
|
|
77
|
|
|
$result = $testInstance->getHashCode(); |
78
|
|
|
$this->assertEquals($initialExpectedHash, $result); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.