LegendTest.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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\Legend;
  19. use PhpOffice\PhpPresentation\Style\Alignment;
  20. use PhpOffice\PhpPresentation\Style\Border;
  21. use PhpOffice\PhpPresentation\Style\Fill;
  22. use PhpOffice\PhpPresentation\Style\Font;
  23. /**
  24. * Test class for Legend element
  25. *
  26. * @coversDefaultClass PhpOffice\PhpPresentation\Shape\Chart\Legend
  27. */
  28. class LegendTest extends \PHPUnit_Framework_TestCase
  29. {
  30. public function testConstruct()
  31. {
  32. $object = new Legend();
  33. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->getFont());
  34. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Border', $object->getBorder());
  35. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Fill', $object->getFill());
  36. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->getAlignment());
  37. }
  38. public function testAlignment()
  39. {
  40. $object = new Legend();
  41. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Legend', $object->setAlignment(new Alignment()));
  42. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->getAlignment());
  43. }
  44. public function testBorder()
  45. {
  46. $object = new Legend();
  47. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Border', $object->getBorder());
  48. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Legend', $object->setBorder(new Border()));
  49. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Border', $object->getBorder());
  50. }
  51. public function testFill()
  52. {
  53. $object = new Legend();
  54. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Fill', $object->getFill());
  55. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Legend', $object->setFill(new Fill()));
  56. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Fill', $object->getFill());
  57. }
  58. public function testFont()
  59. {
  60. $object = new Legend();
  61. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Legend', $object->setFont());
  62. $this->assertNull($object->getFont());
  63. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Legend', $object->setFont(new Font()));
  64. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->getFont());
  65. }
  66. public function testHashIndex()
  67. {
  68. $object = new Legend();
  69. $value = rand(1, 100);
  70. $this->assertEmpty($object->getHashIndex());
  71. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Legend', $object->setHashIndex($value));
  72. $this->assertEquals($value, $object->getHashIndex());
  73. }
  74. public function testHeight()
  75. {
  76. $object = new Legend();
  77. $value = rand(0, 100);
  78. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Legend', $object->setHeight());
  79. $this->assertEquals(0, $object->getHeight());
  80. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Legend', $object->setHeight($value));
  81. $this->assertEquals($value, $object->getHeight());
  82. }
  83. public function testOffsetX()
  84. {
  85. $object = new Legend();
  86. $value = rand(0, 100);
  87. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Legend', $object->setOffsetX());
  88. $this->assertEquals(0, $object->getOffsetX());
  89. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Legend', $object->setOffsetX($value));
  90. $this->assertEquals($value, $object->getOffsetX());
  91. }
  92. public function testOffsetY()
  93. {
  94. $object = new Legend();
  95. $value = rand(0, 100);
  96. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Legend', $object->setOffsetY());
  97. $this->assertEquals(0, $object->getOffsetY());
  98. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Legend', $object->setOffsetY($value));
  99. $this->assertEquals($value, $object->getOffsetY());
  100. }
  101. public function testPosition()
  102. {
  103. $object = new Legend();
  104. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Legend', $object->setPosition());
  105. $this->assertEquals(Legend::POSITION_RIGHT, $object->getPosition());
  106. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Legend', $object->setPosition(Legend::POSITION_BOTTOM));
  107. $this->assertEquals(Legend::POSITION_BOTTOM, $object->getPosition());
  108. }
  109. public function testVisible()
  110. {
  111. $object = new Legend();
  112. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Legend', $object->setVisible());
  113. $this->assertTrue($object->isVisible());
  114. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Legend', $object->setVisible(true));
  115. $this->assertTrue($object->isVisible());
  116. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Legend', $object->setVisible(false));
  117. $this->assertFalse($object->isVisible());
  118. }
  119. public function testWidth()
  120. {
  121. $object = new Legend();
  122. $value = rand(0, 100);
  123. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Legend', $object->setWidth());
  124. $this->assertEquals(0, $object->getWidth());
  125. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Legend', $object->setWidth($value));
  126. $this->assertEquals($value, $object->getWidth());
  127. }
  128. }