TitleTest.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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\Chart;
  18. use PhpOffice\PhpPresentation\Shape\Chart\Title;
  19. use PhpOffice\PhpPresentation\Style\Alignment;
  20. use PhpOffice\PhpPresentation\Style\Font;
  21. /**
  22. * Test class for Title element
  23. *
  24. * @coversDefaultClass PhpOffice\PhpPresentation\Shape\Chart\Title
  25. */
  26. class TitleTest extends \PHPUnit_Framework_TestCase
  27. {
  28. public function testConstruct()
  29. {
  30. $object = new Title();
  31. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->getAlignment());
  32. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->getFont());
  33. $this->assertEquals('Calibri', $object->getFont()->getName());
  34. $this->assertEquals(18, $object->getFont()->getSize());
  35. }
  36. public function testAlignment()
  37. {
  38. $object = new Title();
  39. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Title', $object->setAlignment(new Alignment()));
  40. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->getAlignment());
  41. }
  42. public function testFont()
  43. {
  44. $object = new Title();
  45. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Title', $object->setFont());
  46. $this->assertNull($object->getFont());
  47. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Title', $object->setFont(new Font()));
  48. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->getFont());
  49. }
  50. public function testHashIndex()
  51. {
  52. $object = new Title();
  53. $value = rand(1, 100);
  54. $this->assertEmpty($object->getHashIndex());
  55. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Title', $object->setHashIndex($value));
  56. $this->assertEquals($value, $object->getHashIndex());
  57. }
  58. public function testHeight()
  59. {
  60. $object = new Title();
  61. $value = rand(0, 100);
  62. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Title', $object->setHeight());
  63. $this->assertEquals(0, $object->getHeight());
  64. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Title', $object->setHeight($value));
  65. $this->assertEquals($value, $object->getHeight());
  66. }
  67. public function testOffsetX()
  68. {
  69. $object = new Title();
  70. $value = rand(0, 100);
  71. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Title', $object->setOffsetX());
  72. $this->assertEquals(0.01, $object->getOffsetX());
  73. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Title', $object->setOffsetX($value));
  74. $this->assertEquals($value, $object->getOffsetX());
  75. }
  76. public function testOffsetY()
  77. {
  78. $object = new Title();
  79. $value = rand(0, 100);
  80. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Title', $object->setOffsetY());
  81. $this->assertEquals(0.01, $object->getOffsetY());
  82. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Title', $object->setOffsetY($value));
  83. $this->assertEquals($value, $object->getOffsetY());
  84. }
  85. public function testText()
  86. {
  87. $object = new Title();
  88. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Title', $object->setText());
  89. $this->assertNull($object->getText());
  90. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Title', $object->setText('AAAA'));
  91. $this->assertEquals('AAAA', $object->getText());
  92. }
  93. public function testVisible()
  94. {
  95. $object = new Title();
  96. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Title', $object->setVisible());
  97. $this->assertTrue($object->isVisible());
  98. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Title', $object->setVisible(true));
  99. $this->assertTrue($object->isVisible());
  100. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Title', $object->setVisible(false));
  101. $this->assertFalse($object->isVisible());
  102. }
  103. public function testWidth()
  104. {
  105. $object = new Title();
  106. $value = rand(0, 100);
  107. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Title', $object->setWidth());
  108. $this->assertEquals(0, $object->getWidth());
  109. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Title', $object->setWidth($value));
  110. $this->assertEquals($value, $object->getWidth());
  111. }
  112. }