HyperlinkTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Cell;
  3. use PhpOffice\PhpSpreadsheet\Cell\Hyperlink;
  4. use PHPUnit\Framework\TestCase;
  5. class HyperlinkTest extends TestCase
  6. {
  7. public function testGetUrl(): void
  8. {
  9. $urlValue = 'https://www.example.com';
  10. $testInstance = new Hyperlink($urlValue);
  11. $result = $testInstance->getUrl();
  12. self::assertEquals($urlValue, $result);
  13. }
  14. public function testSetUrl(): void
  15. {
  16. $initialUrlValue = 'https://www.example.com';
  17. $newUrlValue = 'http://github.com/PHPOffice/PhpSpreadsheet';
  18. $testInstance = new Hyperlink($initialUrlValue);
  19. $result = $testInstance->setUrl($newUrlValue);
  20. self::assertInstanceOf(Hyperlink::class, $result);
  21. $result = $testInstance->getUrl();
  22. self::assertEquals($newUrlValue, $result);
  23. }
  24. public function testGetTooltip(): void
  25. {
  26. $tooltipValue = 'PhpSpreadsheet Web Site';
  27. $testInstance = new Hyperlink('', $tooltipValue);
  28. $result = $testInstance->getTooltip();
  29. self::assertEquals($tooltipValue, $result);
  30. }
  31. public function testSetTooltip(): void
  32. {
  33. $initialTooltipValue = 'PhpSpreadsheet Web Site';
  34. $newTooltipValue = 'PhpSpreadsheet Repository on Github';
  35. $testInstance = new Hyperlink('', $initialTooltipValue);
  36. $result = $testInstance->setTooltip($newTooltipValue);
  37. self::assertInstanceOf(Hyperlink::class, $result);
  38. $result = $testInstance->getTooltip();
  39. self::assertEquals($newTooltipValue, $result);
  40. }
  41. public function testIsInternal(): void
  42. {
  43. $initialUrlValue = 'https://www.example.com';
  44. $newUrlValue = 'sheet://Worksheet1!A1';
  45. $testInstance = new Hyperlink($initialUrlValue);
  46. $result = $testInstance->isInternal();
  47. self::assertFalse($result);
  48. $testInstance->setUrl($newUrlValue);
  49. $result = $testInstance->isInternal();
  50. self::assertTrue($result);
  51. }
  52. public function testGetHashCode(): void
  53. {
  54. $urlValue = 'https://www.example.com';
  55. $tooltipValue = 'PhpSpreadsheet Web Site';
  56. $initialExpectedHash = '3a8d5a682dba27276dce538c39402437';
  57. $testInstance = new Hyperlink($urlValue, $tooltipValue);
  58. $result = $testInstance->getHashCode();
  59. self::assertEquals($initialExpectedHash, $result);
  60. }
  61. }