LegendTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. class LegendTest extends PHPUnit_Framework_TestCase
  3. {
  4. public function setUp()
  5. {
  6. if (!defined('PHPEXCEL_ROOT')) {
  7. define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
  8. }
  9. require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
  10. }
  11. public function testSetPosition()
  12. {
  13. $positionValues = array(
  14. PHPExcel_Chart_Legend::POSITION_RIGHT,
  15. PHPExcel_Chart_Legend::POSITION_LEFT,
  16. PHPExcel_Chart_Legend::POSITION_TOP,
  17. PHPExcel_Chart_Legend::POSITION_BOTTOM,
  18. PHPExcel_Chart_Legend::POSITION_TOPRIGHT,
  19. );
  20. $testInstance = new PHPExcel_Chart_Legend;
  21. foreach ($positionValues as $positionValue) {
  22. $result = $testInstance->setPosition($positionValue);
  23. $this->assertTrue($result);
  24. }
  25. }
  26. public function testSetInvalidPositionReturnsFalse()
  27. {
  28. $testInstance = new PHPExcel_Chart_Legend;
  29. $result = $testInstance->setPosition('BottomLeft');
  30. $this->assertFalse($result);
  31. // Ensure that value is unchanged
  32. $result = $testInstance->getPosition();
  33. $this->assertEquals(PHPExcel_Chart_Legend::POSITION_RIGHT, $result);
  34. }
  35. public function testGetPosition()
  36. {
  37. $PositionValue = PHPExcel_Chart_Legend::POSITION_BOTTOM;
  38. $testInstance = new PHPExcel_Chart_Legend;
  39. $setValue = $testInstance->setPosition($PositionValue);
  40. $result = $testInstance->getPosition();
  41. $this->assertEquals($PositionValue, $result);
  42. }
  43. public function testSetPositionXL()
  44. {
  45. $positionValues = array(
  46. PHPExcel_Chart_Legend::xlLegendPositionBottom,
  47. PHPExcel_Chart_Legend::xlLegendPositionCorner,
  48. PHPExcel_Chart_Legend::xlLegendPositionCustom,
  49. PHPExcel_Chart_Legend::xlLegendPositionLeft,
  50. PHPExcel_Chart_Legend::xlLegendPositionRight,
  51. PHPExcel_Chart_Legend::xlLegendPositionTop,
  52. );
  53. $testInstance = new PHPExcel_Chart_Legend;
  54. foreach ($positionValues as $positionValue) {
  55. $result = $testInstance->setPositionXL($positionValue);
  56. $this->assertTrue($result);
  57. }
  58. }
  59. public function testSetInvalidXLPositionReturnsFalse()
  60. {
  61. $testInstance = new PHPExcel_Chart_Legend;
  62. $result = $testInstance->setPositionXL(999);
  63. $this->assertFalse($result);
  64. // Ensure that value is unchanged
  65. $result = $testInstance->getPositionXL();
  66. $this->assertEquals(PHPExcel_Chart_Legend::xlLegendPositionRight, $result);
  67. }
  68. public function testGetPositionXL()
  69. {
  70. $PositionValue = PHPExcel_Chart_Legend::xlLegendPositionCorner;
  71. $testInstance = new PHPExcel_Chart_Legend;
  72. $setValue = $testInstance->setPositionXL($PositionValue);
  73. $result = $testInstance->getPositionXL();
  74. $this->assertEquals($PositionValue, $result);
  75. }
  76. public function testSetOverlay()
  77. {
  78. $overlayValues = array(
  79. true,
  80. false,
  81. );
  82. $testInstance = new PHPExcel_Chart_Legend;
  83. foreach ($overlayValues as $overlayValue) {
  84. $result = $testInstance->setOverlay($overlayValue);
  85. $this->assertTrue($result);
  86. }
  87. }
  88. public function testSetInvalidOverlayReturnsFalse()
  89. {
  90. $testInstance = new PHPExcel_Chart_Legend;
  91. $result = $testInstance->setOverlay('INVALID');
  92. $this->assertFalse($result);
  93. $result = $testInstance->getOverlay();
  94. $this->assertFalse($result);
  95. }
  96. public function testGetOverlay()
  97. {
  98. $OverlayValue = true;
  99. $testInstance = new PHPExcel_Chart_Legend;
  100. $setValue = $testInstance->setOverlay($OverlayValue);
  101. $result = $testInstance->getOverlay();
  102. $this->assertEquals($OverlayValue, $result);
  103. }
  104. }