AxisTest.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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\Axis;
  19. use PhpOffice\PhpPresentation\Style\Font;
  20. /**
  21. * Test class for Axis element
  22. *
  23. * @coversDefaultClass PhpOffice\PhpPresentation\Shape\Chart\Axis
  24. */
  25. class AxisTest extends \PHPUnit_Framework_TestCase
  26. {
  27. public function testConstruct()
  28. {
  29. $object = new Axis();
  30. $this->assertEquals('Axis Title', $object->getTitle());
  31. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->getFont());
  32. $this->assertNull($object->getMinorGridlines());
  33. $this->assertNull($object->getMajorGridlines());
  34. }
  35. public function testBounds()
  36. {
  37. $value = rand(0, 100);
  38. $object = new Axis();
  39. $this->assertNull($object->getMinBounds());
  40. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMinBounds($value));
  41. $this->assertEquals($value, $object->getMinBounds());
  42. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMinBounds());
  43. $this->assertNull($object->getMinBounds());
  44. $this->assertNull($object->getMaxBounds());
  45. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMaxBounds($value));
  46. $this->assertEquals($value, $object->getMaxBounds());
  47. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMaxBounds());
  48. $this->assertNull($object->getMaxBounds());
  49. }
  50. public function testFont()
  51. {
  52. $object = new Axis();
  53. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setFont());
  54. $this->assertNull($object->getFont());
  55. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setFont(new Font()));
  56. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->getFont());
  57. }
  58. public function testFormatCode()
  59. {
  60. $object = new Axis();
  61. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setFormatCode());
  62. $this->assertEquals('', $object->getFormatCode());
  63. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setFormatCode('AAAA'));
  64. $this->assertEquals('AAAA', $object->getFormatCode());
  65. }
  66. public function testGridLines()
  67. {
  68. $object = new Axis();
  69. $oMock = $this->getMockBuilder('PhpOffice\PhpPresentation\Shape\Chart\Gridlines')->getMock();
  70. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMajorGridlines($oMock));
  71. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Gridlines', $object->getMajorGridlines());
  72. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMinorGridlines($oMock));
  73. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Gridlines', $object->getMinorGridlines());
  74. }
  75. public function testHashIndex()
  76. {
  77. $object = new Axis();
  78. $value = rand(1, 100);
  79. $this->assertEmpty($object->getHashIndex());
  80. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setHashIndex($value));
  81. $this->assertEquals($value, $object->getHashIndex());
  82. }
  83. public function testIsVisible()
  84. {
  85. $object = new Axis();
  86. $this->assertTrue($object->isVisible());
  87. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setIsVisible(false));
  88. $this->assertFalse($object->isVisible());
  89. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setIsVisible(true));
  90. $this->assertTrue($object->isVisible());
  91. }
  92. public function testTitle()
  93. {
  94. $object = new Axis();
  95. $this->assertEquals('Axis Title', $object->getTitle());
  96. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setTitle('AAAA'));
  97. $this->assertEquals('AAAA', $object->getTitle());
  98. }
  99. public function testTickMark()
  100. {
  101. $value = Axis::TICK_MARK_INSIDE;
  102. $object = new Axis();
  103. $this->assertEquals(Axis::TICK_MARK_NONE, $object->getMinorTickMark());
  104. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMinorTickMark($value));
  105. $this->assertEquals($value, $object->getMinorTickMark());
  106. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMinorTickMark());
  107. $this->assertEquals(Axis::TICK_MARK_NONE, $object->getMinorTickMark());
  108. $this->assertEquals(Axis::TICK_MARK_NONE, $object->getMajorTickMark());
  109. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMajorTickMark($value));
  110. $this->assertEquals($value, $object->getMajorTickMark());
  111. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMajorTickMark());
  112. $this->assertEquals(Axis::TICK_MARK_NONE, $object->getMajorTickMark());
  113. }
  114. public function testUnit()
  115. {
  116. $value = rand(0, 100);
  117. $object = new Axis();
  118. $this->assertNull($object->getMinorUnit());
  119. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMinorUnit($value));
  120. $this->assertEquals($value, $object->getMinorUnit());
  121. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMinorUnit());
  122. $this->assertNull($object->getMinorUnit());
  123. $this->assertNull($object->getMajorUnit());
  124. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMajorUnit($value));
  125. $this->assertEquals($value, $object->getMajorUnit());
  126. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMajorUnit());
  127. $this->assertNull($object->getMajorUnit());
  128. }
  129. }