AlignmentTest.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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\Style;
  18. use PhpOffice\PhpPresentation\Style\Alignment;
  19. /**
  20. * Test class for PhpPresentation
  21. *
  22. * @coversDefaultClass PhpOffice\PhpPresentation\PhpPresentation
  23. */
  24. class AlignmentTest extends \PHPUnit_Framework_TestCase
  25. {
  26. /**
  27. * Test create new instance
  28. */
  29. public function testConstruct()
  30. {
  31. $object = new Alignment();
  32. $this->assertEquals(Alignment::HORIZONTAL_LEFT, $object->getHorizontal());
  33. $this->assertEquals(Alignment::VERTICAL_BASE, $object->getVertical());
  34. $this->assertEquals(Alignment::TEXT_DIRECTION_HORIZONTAL, $object->getTextDirection());
  35. $this->assertEquals(0, $object->getLevel());
  36. $this->assertEquals(0, $object->getIndent());
  37. $this->assertEquals(0, $object->getMarginLeft());
  38. $this->assertEquals(0, $object->getMarginRight());
  39. $this->assertEquals(0, $object->getMarginTop());
  40. $this->assertEquals(0, $object->getMarginBottom());
  41. }
  42. /**
  43. * Test get/set horizontal
  44. */
  45. public function testSetGetHorizontal()
  46. {
  47. $object = new Alignment();
  48. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setHorizontal(''));
  49. $this->assertEquals(Alignment::HORIZONTAL_LEFT, $object->getHorizontal());
  50. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setHorizontal(Alignment::HORIZONTAL_GENERAL));
  51. $this->assertEquals(Alignment::HORIZONTAL_GENERAL, $object->getHorizontal());
  52. }
  53. /**
  54. * Test get/set vertical
  55. */
  56. public function testTextDirection()
  57. {
  58. $object = new Alignment();
  59. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setTextDirection(null));
  60. $this->assertEquals(Alignment::TEXT_DIRECTION_HORIZONTAL, $object->getTextDirection());
  61. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setTextDirection(Alignment::TEXT_DIRECTION_VERTICAL_90));
  62. $this->assertEquals(Alignment::TEXT_DIRECTION_VERTICAL_90, $object->getTextDirection());
  63. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setTextDirection());
  64. $this->assertEquals(Alignment::TEXT_DIRECTION_HORIZONTAL, $object->getTextDirection());
  65. }
  66. /**
  67. * Test get/set vertical
  68. */
  69. public function testSetGetVertical()
  70. {
  71. $object = new Alignment();
  72. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setVertical(''));
  73. $this->assertEquals(Alignment::VERTICAL_BASE, $object->getVertical());
  74. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setVertical(Alignment::VERTICAL_AUTO));
  75. $this->assertEquals(Alignment::VERTICAL_AUTO, $object->getVertical());
  76. }
  77. /**
  78. * Test get/set min level exception
  79. */
  80. public function testSetGetLevelExceptionMin()
  81. {
  82. $object = new Alignment();
  83. $this->setExpectedException('\Exception', 'Invalid value should be more than 0.');
  84. $object->setLevel(-1);
  85. }
  86. /**
  87. * Test get/set level
  88. */
  89. public function testSetGetLevel()
  90. {
  91. $object = new Alignment();
  92. $value = rand(1, 8);
  93. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setLevel($value));
  94. $this->assertEquals($value, $object->getLevel());
  95. }
  96. /**
  97. * Test get/set indent
  98. */
  99. public function testSetGetIndent()
  100. {
  101. $object = new Alignment();
  102. // != Alignment::HORIZONTAL_GENERAL
  103. $object->setHorizontal(Alignment::HORIZONTAL_CENTER);
  104. $value = rand(1, 100);
  105. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setIndent($value));
  106. $this->assertEquals(0, $object->getIndent());
  107. $value = rand(-100, 0);
  108. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setIndent($value));
  109. $this->assertEquals($value, $object->getIndent());
  110. $object->setHorizontal(Alignment::HORIZONTAL_GENERAL);
  111. $value = rand(1, 100);
  112. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setIndent($value));
  113. $this->assertEquals($value, $object->getIndent());
  114. $value = rand(-100, 0);
  115. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setIndent($value));
  116. $this->assertEquals($value, $object->getIndent());
  117. }
  118. /**
  119. * Test get/set margin bottom
  120. */
  121. public function testSetGetMarginBottom()
  122. {
  123. $object = new Alignment();
  124. $value = rand(0, 100);
  125. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setMarginBottom($value));
  126. $this->assertEquals($value, $object->getMarginBottom());
  127. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setMarginBottom());
  128. $this->assertEquals(0, $object->getMarginBottom());
  129. }
  130. /**
  131. * Test get/set margin left
  132. */
  133. public function testSetGetMarginLeft()
  134. {
  135. $object = new Alignment();
  136. // != Alignment::HORIZONTAL_GENERAL
  137. $object->setHorizontal(Alignment::HORIZONTAL_CENTER);
  138. $value = rand(1, 100);
  139. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setMarginLeft($value));
  140. $this->assertEquals(0, $object->getMarginLeft());
  141. $value = rand(-100, 0);
  142. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setMarginLeft($value));
  143. $this->assertEquals($value, $object->getMarginLeft());
  144. $object->setHorizontal(Alignment::HORIZONTAL_GENERAL);
  145. $value = rand(1, 100);
  146. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setMarginLeft($value));
  147. $this->assertEquals($value, $object->getMarginLeft());
  148. $value = rand(-100, 0);
  149. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setMarginLeft($value));
  150. $this->assertEquals($value, $object->getMarginLeft());
  151. }
  152. /**
  153. * Test get/set margin right
  154. */
  155. public function testSetGetMarginRight()
  156. {
  157. $object = new Alignment();
  158. // != Alignment::HORIZONTAL_GENERAL
  159. $object->setHorizontal(Alignment::HORIZONTAL_CENTER);
  160. $value = rand(1, 100);
  161. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setMarginRight($value));
  162. $this->assertEquals(0, $object->getMarginRight());
  163. $value = rand(-100, 0);
  164. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setMarginRight($value));
  165. $this->assertEquals($value, $object->getMarginRight());
  166. $object->setHorizontal(Alignment::HORIZONTAL_GENERAL);
  167. $value = rand(1, 100);
  168. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setMarginRight($value));
  169. $this->assertEquals($value, $object->getMarginRight());
  170. $value = rand(-100, 0);
  171. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setMarginRight($value));
  172. $this->assertEquals($value, $object->getMarginRight());
  173. }
  174. /**
  175. * Test get/set margin top
  176. */
  177. public function testSetGetMarginTop()
  178. {
  179. $object = new Alignment();
  180. $value = rand(1, 100);
  181. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setMarginTop($value));
  182. $this->assertEquals($value, $object->getMarginTop());
  183. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->setMarginTop());
  184. $this->assertEquals(0, $object->getMarginTop());
  185. }
  186. /**
  187. * Test get/set hash index
  188. */
  189. public function testSetGetHashIndex()
  190. {
  191. $value = md5(rand(1, 100));
  192. $object = new Alignment();
  193. $object->setHashIndex($value);
  194. $this->assertEquals($value, $object->getHashIndex());
  195. }
  196. }