FontTest.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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\Color;
  19. use PhpOffice\PhpPresentation\Style\Font;
  20. /**
  21. * Test class for PhpPresentation
  22. *
  23. * @coversDefaultClass PhpOffice\PhpPresentation\PhpPresentation
  24. */
  25. class FontTest extends \PHPUnit_Framework_TestCase
  26. {
  27. /**
  28. * Test create new instance
  29. */
  30. public function testConstruct()
  31. {
  32. $object = new Font();
  33. $this->assertEquals('Calibri', $object->getName());
  34. $this->assertEquals(10, $object->getSize());
  35. $this->assertFalse($object->isBold());
  36. $this->assertFalse($object->isItalic());
  37. $this->assertFalse($object->isSuperScript());
  38. $this->assertFalse($object->isSubScript());
  39. $this->assertFalse($object->isStrikethrough());
  40. $this->assertEquals(Font::UNDERLINE_NONE, $object->getUnderline());
  41. $this->assertEquals(0, $object->getCharacterSpacing());
  42. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Color', $object->getColor());
  43. $this->assertEquals(Color::COLOR_BLACK, $object->getColor()->getARGB());
  44. }
  45. /**
  46. * Test get/set color
  47. * @expectedException \Exception
  48. * @expectedExceptionMessage $pValue must be an instance of \PhpOffice\PhpPresentation\Style\Color
  49. */
  50. public function testSetGetColorException()
  51. {
  52. $object = new Font();
  53. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setColor());
  54. }
  55. /**
  56. * Test get/set Character Spacing
  57. */
  58. public function testSetGetCharacterSpacing()
  59. {
  60. $object = new Font();
  61. $this->assertEquals(0, $object->getCharacterSpacing());
  62. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setCharacterSpacing(0));
  63. $this->assertEquals(0, $object->getCharacterSpacing());
  64. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setCharacterSpacing(10));
  65. $this->assertEquals(1000, $object->getCharacterSpacing());
  66. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setCharacterSpacing());
  67. $this->assertEquals(0, $object->getCharacterSpacing());
  68. }
  69. /**
  70. * Test get/set color
  71. */
  72. public function testSetGetColor()
  73. {
  74. $object = new Font();
  75. $this->assertEquals(Color::COLOR_BLACK, $object->getColor()->getARGB());
  76. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setColor(new Color(Color::COLOR_BLUE)));
  77. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Color', $object->getColor());
  78. $this->assertEquals(Color::COLOR_BLUE, $object->getColor()->getARGB());
  79. }
  80. /**
  81. * Test get/set name
  82. */
  83. public function testSetGetName()
  84. {
  85. $object = new Font();
  86. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setName());
  87. $this->assertEquals('Calibri', $object->getName());
  88. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setName(''));
  89. $this->assertEquals('Calibri', $object->getName());
  90. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setName('Arial'));
  91. $this->assertEquals('Arial', $object->getName());
  92. }
  93. /**
  94. * Test get/set size
  95. */
  96. public function testSetGetSize()
  97. {
  98. $object = new Font();
  99. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setSize());
  100. $this->assertEquals(10, $object->getSize());
  101. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setSize(''));
  102. $this->assertEquals(10, $object->getSize());
  103. $value = rand(1, 100);
  104. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setSize($value));
  105. $this->assertEquals($value, $object->getSize());
  106. }
  107. /**
  108. * Test get/set underline
  109. */
  110. public function testSetGetUnderline()
  111. {
  112. $object = new Font();
  113. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setUnderline());
  114. $this->assertEquals(FONT::UNDERLINE_NONE, $object->getUnderline());
  115. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setUnderline(''));
  116. $this->assertEquals(FONT::UNDERLINE_NONE, $object->getUnderline());
  117. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setUnderline(FONT::UNDERLINE_DASH));
  118. $this->assertEquals(FONT::UNDERLINE_DASH, $object->getUnderline());
  119. }
  120. /**
  121. * Test get/set bold
  122. */
  123. public function testSetIsBold()
  124. {
  125. $object = new Font();
  126. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setBold());
  127. $this->assertFalse($object->isBold());
  128. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setBold(''));
  129. $this->assertFalse($object->isBold());
  130. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setBold(false));
  131. $this->assertFalse($object->isBold());
  132. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setBold(true));
  133. $this->assertTrue($object->isBold());
  134. }
  135. /**
  136. * Test get/set italic
  137. */
  138. public function testSetIsItalic()
  139. {
  140. $object = new Font();
  141. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setItalic());
  142. $this->assertFalse($object->isItalic());
  143. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setItalic(''));
  144. $this->assertFalse($object->isItalic());
  145. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setItalic(false));
  146. $this->assertFalse($object->isItalic());
  147. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setItalic(true));
  148. $this->assertTrue($object->isItalic());
  149. }
  150. /**
  151. * Test get/set strikethrough
  152. */
  153. public function testSetIsStriketrough()
  154. {
  155. $object = new Font();
  156. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setStrikethrough());
  157. $this->assertFalse($object->isStrikethrough());
  158. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setStrikethrough(''));
  159. $this->assertFalse($object->isStrikethrough());
  160. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setStrikethrough(false));
  161. $this->assertFalse($object->isStrikethrough());
  162. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setStrikethrough(true));
  163. $this->assertTrue($object->isStrikethrough());
  164. }
  165. /**
  166. * Test get/set subscript
  167. */
  168. public function testSetIsSubScript()
  169. {
  170. $object = new Font();
  171. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setSubScript());
  172. $this->assertFalse($object->isSubScript());
  173. $this->assertTrue($object->isSuperScript());
  174. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setSubScript(''));
  175. $this->assertFalse($object->isSubScript());
  176. $this->assertTrue($object->isSuperScript());
  177. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setSubScript(false));
  178. $this->assertFalse($object->isSubScript());
  179. $this->assertTrue($object->isSuperScript());
  180. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setSubScript(true));
  181. $this->assertTrue($object->isSubScript());
  182. $this->assertFalse($object->isSuperScript());
  183. }
  184. /**
  185. * Test get/set superscript
  186. */
  187. public function testSetIsSuperScript()
  188. {
  189. $object = new Font();
  190. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setSuperScript());
  191. $this->assertFalse($object->isSuperScript());
  192. $this->assertTrue($object->isSubScript());
  193. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setSuperScript(''));
  194. $this->assertFalse($object->isSuperScript());
  195. $this->assertTrue($object->isSubScript());
  196. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setSuperScript(false));
  197. $this->assertFalse($object->isSuperScript());
  198. $this->assertTrue($object->isSubScript());
  199. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setSuperScript(true));
  200. $this->assertTrue($object->isSuperScript());
  201. $this->assertFalse($object->isSubScript());
  202. }
  203. /**
  204. * Test get/set hash index
  205. */
  206. public function testSetGetHashIndex()
  207. {
  208. $object = new Font();
  209. $value = rand(1, 100);
  210. $object->setHashIndex($value);
  211. $this->assertEquals($value, $object->getHashIndex());
  212. }
  213. }