SeriesTest.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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\Marker;
  19. use PhpOffice\PhpPresentation\Shape\Chart\Series;
  20. use PhpOffice\PhpPresentation\Style\Fill;
  21. use PhpOffice\PhpPresentation\Style\Font;
  22. use PhpOffice\PhpPresentation\Style\Outline;
  23. /**
  24. * Test class for Series element
  25. *
  26. * @coversDefaultClass PhpOffice\PhpPresentation\Shape\Chart\Series
  27. */
  28. class SeriesTest extends \PHPUnit_Framework_TestCase
  29. {
  30. public function testConstruct()
  31. {
  32. $object = new Series();
  33. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Fill', $object->getFill());
  34. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->getFont());
  35. $this->assertEquals('Calibri', $object->getFont()->getName());
  36. $this->assertEquals(9, $object->getFont()->getSize());
  37. $this->assertEquals('Series Title', $object->getTitle());
  38. $this->assertInternalType('array', $object->getValues());
  39. $this->assertEmpty($object->getValues());
  40. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Marker', $object->getMarker());
  41. $this->assertNull($object->getOutline());
  42. $this->assertFalse($object->hasShowLegendKey());
  43. }
  44. public function testDataLabelNumFormat()
  45. {
  46. $object = new Series();
  47. $this->assertEmpty($object->getDlblNumFormat());
  48. $this->assertFalse($object->hasDlblNumFormat());
  49. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setDlblNumFormat('#%'));
  50. $this->assertEquals('#%', $object->getDlblNumFormat());
  51. $this->assertTrue($object->hasDlblNumFormat());
  52. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setDlblNumFormat());
  53. $this->assertEmpty($object->getDlblNumFormat());
  54. $this->assertFalse($object->hasDlblNumFormat());
  55. }
  56. public function testDataPointFills()
  57. {
  58. $object = new Series();
  59. $this->assertInternalType('array', $object->getDataPointFills());
  60. $this->assertEmpty($object->getDataPointFills());
  61. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Fill', $object->getDataPointFill(0));
  62. }
  63. public function testFill()
  64. {
  65. $object = new Series();
  66. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setFill());
  67. $this->assertNull($object->getFill());
  68. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setFill(new Fill()));
  69. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Fill', $object->getFill());
  70. }
  71. public function testFont()
  72. {
  73. $object = new Series();
  74. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setFont());
  75. $this->assertNull($object->getFont());
  76. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setFont(new Font()));
  77. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->getFont());
  78. }
  79. public function testHashIndex()
  80. {
  81. $object = new Series();
  82. $value = rand(1, 100);
  83. $this->assertEmpty($object->getHashIndex());
  84. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setHashIndex($value));
  85. $this->assertEquals($value, $object->getHashIndex());
  86. }
  87. public function testHashCode()
  88. {
  89. $object = new Series();
  90. $this->assertEquals(md5($object->getFill()->getHashCode().$object->getFont()->getHashCode().var_export($object->getValues(), true) . var_export($object, true).get_class($object)), $object->getHashCode());
  91. }
  92. public function testLabelPosition()
  93. {
  94. $object = new Series();
  95. $this->assertEmpty($object->getHashIndex());
  96. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setLabelPosition(Series::LABEL_INSIDEBASE));
  97. $this->assertEquals(Series::LABEL_INSIDEBASE, $object->getLabelPosition());
  98. }
  99. public function testMarker()
  100. {
  101. $object = new Series();
  102. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setMarker(new Marker()));
  103. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Marker', $object->getMarker());
  104. }
  105. public function testOutline()
  106. {
  107. $object = new Series();
  108. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setOutline(new Outline()));
  109. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Outline', $object->getOutline());
  110. }
  111. public function testShowCategoryName()
  112. {
  113. $object = new Series();
  114. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setShowCategoryName(true));
  115. $this->assertTrue($object->hasShowCategoryName());
  116. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setShowCategoryName(false));
  117. $this->assertFalse($object->hasShowCategoryName());
  118. }
  119. public function testShowLeaderLines()
  120. {
  121. $object = new Series();
  122. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setShowLeaderLines(true));
  123. $this->assertTrue($object->hasShowLeaderLines());
  124. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setShowLeaderLines(false));
  125. $this->assertFalse($object->hasShowLeaderLines());
  126. }
  127. public function testShowLegendKey()
  128. {
  129. $object = new Series();
  130. $this->assertFalse($object->hasShowLegendKey());
  131. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setShowLegendKey(true));
  132. $this->assertTrue($object->hasShowLegendKey());
  133. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setShowLegendKey(false));
  134. $this->assertFalse($object->hasShowLegendKey());
  135. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setShowLegendKey(1));
  136. $this->assertTrue($object->hasShowLegendKey());
  137. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setShowLegendKey(0));
  138. $this->assertFalse($object->hasShowLegendKey());
  139. }
  140. public function testShowPercentage()
  141. {
  142. $object = new Series();
  143. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setShowPercentage(true));
  144. $this->assertTrue($object->hasShowPercentage());
  145. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setShowPercentage(false));
  146. $this->assertFalse($object->hasShowPercentage());
  147. }
  148. public function testShowSeparator()
  149. {
  150. $value = ';';
  151. $object = new Series();
  152. $this->assertFalse($object->hasShowSeparator());
  153. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setSeparator($value));
  154. $this->assertEquals($value, $object->getSeparator());
  155. $this->assertTrue($object->hasShowSeparator());
  156. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setSeparator(''));
  157. $this->assertFalse($object->hasShowPercentage());
  158. }
  159. public function testShowSeriesName()
  160. {
  161. $object = new Series();
  162. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setShowSeriesName(true));
  163. $this->assertTrue($object->hasShowSeriesName());
  164. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setShowSeriesName(false));
  165. $this->assertFalse($object->hasShowSeriesName());
  166. }
  167. public function testShowValue()
  168. {
  169. $object = new Series();
  170. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setShowValue(true));
  171. $this->assertTrue($object->hasShowValue());
  172. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setShowValue(false));
  173. $this->assertFalse($object->hasShowValue());
  174. }
  175. public function testTitle()
  176. {
  177. $object = new Series();
  178. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setTitle());
  179. $this->assertEquals('Series Title', $object->getTitle());
  180. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setTitle('AAAA'));
  181. $this->assertEquals('AAAA', $object->getTitle());
  182. }
  183. public function testValue()
  184. {
  185. $object = new Series();
  186. $array = array(
  187. '0' => 'a',
  188. '1' => 'b',
  189. '2' => 'c',
  190. '3' => 'd',
  191. );
  192. $this->assertInternalType('array', $object->getValues());
  193. $this->assertEmpty($object->getValues());
  194. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setValues());
  195. $this->assertEmpty($object->getValues());
  196. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setValues($array));
  197. $this->assertCount(count($array), $object->getValues());
  198. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->addValue(4, 'e'));
  199. $this->assertCount(count($array) + 1, $object->getValues());
  200. }
  201. public function testClone()
  202. {
  203. $object = new Series();
  204. $object->setOutline(new Outline());
  205. $clone = clone $object;
  206. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $clone);
  207. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Outline', $clone->getOutline());
  208. }
  209. }