HyperlinkTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * This file is part of PHPPresentation - A pure PHP library for reading and writing
  4. * presentations documents.
  5. *
  6. * PHPPresentation is free software distributed under the terms of the GNU Lesser
  7. * General Public License version 3 as published by the Free Software Foundation.
  8. *
  9. * For the full copyright and license information, please read the LICENSE
  10. * file that was distributed with this source code. For the full list of
  11. * contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
  12. *
  13. * @copyright 2009-2015 PHPPresentation contributors
  14. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  15. * @link https://github.com/PHPOffice/PHPPresentation
  16. */
  17. namespace PhpOffice\PhpPresentation\Tests\Shape;
  18. use PhpOffice\PhpPresentation\Shape\Hyperlink;
  19. /**
  20. * Test class for hyperlink element
  21. *
  22. * @coversDefaultClass PhpOffice\PhpPresentation\Shape\Hyperlink
  23. */
  24. class HyperlinkTest extends \PHPUnit_Framework_TestCase
  25. {
  26. /**
  27. * Test can read
  28. */
  29. public function testConstruct()
  30. {
  31. $object = new Hyperlink();
  32. $this->assertEmpty($object->getUrl());
  33. $this->assertEmpty($object->getTooltip());
  34. $object = new Hyperlink('http://test.com');
  35. $this->assertEquals('http://test.com', $object->getUrl());
  36. $this->assertEmpty($object->getTooltip());
  37. $object = new Hyperlink('http://test.com', 'Test');
  38. $this->assertEquals('http://test.com', $object->getUrl());
  39. $this->assertEquals('Test', $object->getTooltip());
  40. }
  41. /**
  42. * Test get hash code
  43. */
  44. public function testGetHashCode()
  45. {
  46. $object = new Hyperlink();
  47. $this->assertEquals(md5(get_class($object)), $object->getHashCode());
  48. $object = new Hyperlink('http://test.com');
  49. $this->assertEquals(md5('http://test.com'.get_class($object)), $object->getHashCode());
  50. $object = new Hyperlink('http://test.com', 'Test');
  51. $this->assertEquals(md5('http://test.com'.'Test'.get_class($object)), $object->getHashCode());
  52. }
  53. /**
  54. * Test get/set hash index
  55. */
  56. public function testSetGetHashIndex()
  57. {
  58. $object = new Hyperlink();
  59. $value = rand(1, 100);
  60. $object->setHashIndex($value);
  61. $this->assertEquals($value, $object->getHashIndex());
  62. }
  63. public function testGetSetSlideNumber()
  64. {
  65. $object = new Hyperlink();
  66. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Hyperlink', $object->setSlideNumber());
  67. $this->assertEquals(1, $object->getSlideNumber());
  68. $this->assertEquals('ppaction://hlinksldjump', $object->getUrl());
  69. $value = rand(1, 100);
  70. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Hyperlink', $object->setSlideNumber($value));
  71. $this->assertEquals($value, $object->getSlideNumber());
  72. $this->assertEquals('ppaction://hlinksldjump', $object->getUrl());
  73. }
  74. public function testGetSetTooltip()
  75. {
  76. $object = new Hyperlink();
  77. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Hyperlink', $object->setTooltip());
  78. $this->assertEmpty($object->getTooltip());
  79. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Hyperlink', $object->setTooltip('TEST'));
  80. $this->assertEquals('TEST', $object->getTooltip());
  81. }
  82. public function testGetSetUrl()
  83. {
  84. $object = new Hyperlink();
  85. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Hyperlink', $object->setUrl());
  86. $this->assertEmpty($object->getUrl());
  87. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Hyperlink', $object->setUrl('http://www.github.com'));
  88. $this->assertEquals('http://www.github.com', $object->getUrl());
  89. }
  90. public function testIsInternal()
  91. {
  92. $object = new Hyperlink();
  93. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Hyperlink', $object->setSlideNumber());
  94. $this->assertTrue($object->isInternal());
  95. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Hyperlink', $object->setUrl('http://www.github.com'));
  96. $this->assertFalse($object->isInternal());
  97. }
  98. }