LegendTest.php 3.3 KB

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