LegendTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Chart;
  3. use PhpOffice\PhpSpreadsheet\Chart\Legend;
  4. use PHPUnit\Framework\TestCase;
  5. class LegendTest extends TestCase
  6. {
  7. public function testSetPosition(): void
  8. {
  9. $positionValues = [
  10. Legend::POSITION_RIGHT,
  11. Legend::POSITION_LEFT,
  12. Legend::POSITION_TOP,
  13. Legend::POSITION_BOTTOM,
  14. Legend::POSITION_TOPRIGHT,
  15. ];
  16. $testInstance = new Legend();
  17. foreach ($positionValues as $positionValue) {
  18. $result = $testInstance->setPosition($positionValue);
  19. self::assertTrue($result);
  20. }
  21. }
  22. public function testSetInvalidPositionReturnsFalse(): void
  23. {
  24. $testInstance = new Legend();
  25. $result = $testInstance->setPosition('BottomLeft');
  26. self::assertFalse($result);
  27. // Ensure that value is unchanged
  28. $result = $testInstance->getPosition();
  29. self::assertEquals(Legend::POSITION_RIGHT, $result);
  30. }
  31. public function testGetPosition(): void
  32. {
  33. $PositionValue = Legend::POSITION_BOTTOM;
  34. $testInstance = new Legend();
  35. $testInstance->setPosition($PositionValue);
  36. $result = $testInstance->getPosition();
  37. self::assertEquals($PositionValue, $result);
  38. }
  39. public function testSetPositionXL(): void
  40. {
  41. $positionValues = [
  42. Legend::XL_LEGEND_POSITION_BOTTOM,
  43. Legend::XL_LEGEND_POSITION_CORNER,
  44. Legend::XL_LEGEND_POSITION_CUSTOM,
  45. Legend::XL_LEGEND_POSITION_LEFT,
  46. Legend::XL_LEGEND_POSITION_RIGHT,
  47. Legend::XL_LEGEND_POSITION_TOP,
  48. ];
  49. $testInstance = new Legend();
  50. foreach ($positionValues as $positionValue) {
  51. $result = $testInstance->setPositionXL($positionValue);
  52. self::assertTrue($result);
  53. }
  54. }
  55. public function testSetInvalidXLPositionReturnsFalse(): void
  56. {
  57. $testInstance = new Legend();
  58. $result = $testInstance->setPositionXL(999);
  59. self::assertFalse($result);
  60. // Ensure that value is unchanged
  61. $result = $testInstance->getPositionXL();
  62. self::assertEquals(Legend::XL_LEGEND_POSITION_RIGHT, $result);
  63. }
  64. public function testGetPositionXL(): void
  65. {
  66. $PositionValue = Legend::XL_LEGEND_POSITION_CORNER;
  67. $testInstance = new Legend();
  68. $testInstance->setPositionXL($PositionValue);
  69. $result = $testInstance->getPositionXL();
  70. self::assertEquals($PositionValue, $result);
  71. }
  72. public function testSetOverlay(): void
  73. {
  74. $overlayValues = [
  75. true,
  76. false,
  77. ];
  78. $testInstance = new Legend();
  79. foreach ($overlayValues as $overlayValue) {
  80. $testInstance->setOverlay($overlayValue);
  81. self::assertSame($overlayValue, $testInstance->getOverlay());
  82. }
  83. }
  84. public function testGetOverlay(): void
  85. {
  86. $OverlayValue = true;
  87. $testInstance = new Legend();
  88. $testInstance->setOverlay($OverlayValue);
  89. $result = $testInstance->getOverlay();
  90. self::assertEquals($OverlayValue, $result);
  91. }
  92. }