TextElementTest 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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\RichText;
  18. use PhpOffice\PhpPresentation\Shape\Hyperlink;
  19. use PhpOffice\PhpPresentation\Shape\RichText\TextElement;
  20. /**
  21. * Test class for TextElement element
  22. *
  23. * @coversDefaultClass PhpOffice\PhpPresentation\Shape\RichText\TextElement
  24. */
  25. class TextElementTest extends \PHPUnit_Framework_TestCase
  26. {
  27. /**
  28. * Test can read
  29. */
  30. public function testConstruct()
  31. {
  32. $object = new TextElement();
  33. $this->assertEquals('', $object->getText());
  34. $object = new TextElement('AAA');
  35. $this->assertEquals('AAA', $object->getText());
  36. }
  37. public function testFont()
  38. {
  39. $object = new TextElement();
  40. $this->assertNull($object->getFont());
  41. }
  42. public function testHyperlink()
  43. {
  44. $object = new TextElement();
  45. $this->assertFalse($object->hasHyperlink());
  46. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\TextElement', $object->setHyperlink());
  47. $this->assertFalse($object->hasHyperlink());
  48. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Hyperlink', $object->getHyperlink());
  49. $this->assertTrue($object->hasHyperlink());
  50. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\TextElement', $object->setHyperlink(new Hyperlink('http://www.google.fr')));
  51. $this->assertTrue($object->hasHyperlink());
  52. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Hyperlink', $object->getHyperlink());
  53. }
  54. public function testLanguage()
  55. {
  56. $object = new TextElement();
  57. $this->assertNull($object->getLanguage());
  58. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\TextElement', $object->setLanguage('en-US'));
  59. $this->assertEquals('en-US', $object->getLanguage());
  60. }
  61. public function testText()
  62. {
  63. $object = new TextElement();
  64. $this->assertEquals('', $object->getText());
  65. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\TextElement', $object->setText());
  66. $this->assertEquals('', $object->getText());
  67. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\TextElement', $object->setText('AAA'));
  68. $this->assertEquals('AAA', $object->getText());
  69. }
  70. /**
  71. * Test get/set hash index
  72. */
  73. public function testHashCode()
  74. {
  75. $object = new TextElement();
  76. $this->assertEquals(md5(get_class($object)), $object->getHashCode());
  77. }
  78. }