GnumericStylesTest.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Reader\Gnumeric;
  3. use PhpOffice\PhpSpreadsheet\Cell\DataType;
  4. use PhpOffice\PhpSpreadsheet\Reader\Gnumeric;
  5. use PhpOffice\PhpSpreadsheet\Style\Alignment;
  6. use PhpOffice\PhpSpreadsheet\Style\Border;
  7. use PhpOffice\PhpSpreadsheet\Style\Fill;
  8. use PhpOffice\PhpSpreadsheet\Style\Font;
  9. use PHPUnit\Framework\TestCase;
  10. class GnumericStylesTest extends TestCase
  11. {
  12. /**
  13. * @dataProvider providerBorderStyle
  14. */
  15. public function testBorderStyle(string $style, string $expectedResult): void
  16. {
  17. $styles = Gnumeric::gnumericMappings();
  18. $borders = $styles['borderStyle'];
  19. self::assertEquals($expectedResult, $borders[$style]);
  20. }
  21. public function testBorderStyleCoverage(): void
  22. {
  23. $styles = Gnumeric::gnumericMappings();
  24. $expected = $styles['borderStyle'];
  25. $covered = [];
  26. foreach ($expected as $key => $val) {
  27. $covered[$key] = 0;
  28. }
  29. $tests = $this->providerBorderStyle();
  30. foreach ($tests as $test) {
  31. $covered[$test[0]] = 1;
  32. }
  33. foreach ($covered as $key => $val) {
  34. self::assertEquals(1, $val, "Borderstyle $key not tested");
  35. }
  36. }
  37. /**
  38. * @dataProvider providerfillType
  39. */
  40. public function testFillType(string $style, string $expectedResult): void
  41. {
  42. $styles = Gnumeric::gnumericMappings();
  43. $borders = $styles['fillType'];
  44. self::assertEquals($expectedResult, $borders[$style]);
  45. }
  46. public function testFillTypeCoverage(): void
  47. {
  48. $styles = Gnumeric::gnumericMappings();
  49. $expected = $styles['fillType'];
  50. $covered = [];
  51. foreach ($expected as $key => $val) {
  52. $covered[$key] = 0;
  53. }
  54. $tests = $this->providerfillType();
  55. foreach ($tests as $test) {
  56. $covered[$test[0]] = 1;
  57. }
  58. foreach ($covered as $key => $val) {
  59. self::assertEquals(1, $val, "fillType $key not tested");
  60. }
  61. }
  62. /**
  63. * @dataProvider providerHorizontal
  64. */
  65. public function testHorizontal(string $style, string $expectedResult): void
  66. {
  67. $styles = Gnumeric::gnumericMappings();
  68. $borders = $styles['horizontal'];
  69. self::assertEquals($expectedResult, $borders[$style]);
  70. }
  71. public function testHorizontalCoverage(): void
  72. {
  73. $styles = Gnumeric::gnumericMappings();
  74. $expected = $styles['horizontal'];
  75. $covered = [];
  76. foreach ($expected as $key => $val) {
  77. $covered[$key] = 0;
  78. }
  79. $tests = $this->providerHorizontal();
  80. foreach ($tests as $test) {
  81. $covered[$test[0]] = 1;
  82. }
  83. foreach ($covered as $key => $val) {
  84. self::assertEquals(1, $val, "horizontal $key not tested");
  85. }
  86. }
  87. /**
  88. * @dataProvider providerunderline
  89. */
  90. public function testUnderline(string $style, string $expectedResult): void
  91. {
  92. $styles = Gnumeric::gnumericMappings();
  93. $borders = $styles['underline'];
  94. self::assertEquals($expectedResult, $borders[$style]);
  95. }
  96. public function testUnderlineCoverage(): void
  97. {
  98. $styles = Gnumeric::gnumericMappings();
  99. $expected = $styles['underline'];
  100. $covered = [];
  101. foreach ($expected as $key => $val) {
  102. $covered[$key] = 0;
  103. }
  104. $tests = $this->providerUnderline();
  105. foreach ($tests as $test) {
  106. $covered[$test[0]] = 1;
  107. }
  108. foreach ($covered as $key => $val) {
  109. self::assertEquals(1, $val, "underline $key not tested");
  110. }
  111. }
  112. /**
  113. * @dataProvider providerVertical
  114. */
  115. public function testVertical(string $style, string $expectedResult): void
  116. {
  117. $styles = Gnumeric::gnumericMappings();
  118. $borders = $styles['vertical'];
  119. self::assertEquals($expectedResult, $borders[$style]);
  120. }
  121. public function testVerticalCoverage(): void
  122. {
  123. $styles = Gnumeric::gnumericMappings();
  124. $expected = $styles['vertical'];
  125. $covered = [];
  126. foreach ($expected as $key => $val) {
  127. $covered[$key] = 0;
  128. }
  129. $tests = $this->providerVertical();
  130. foreach ($tests as $test) {
  131. $covered[$test[0]] = 1;
  132. }
  133. foreach ($covered as $key => $val) {
  134. self::assertEquals(1, $val, "vertical $key not tested");
  135. }
  136. }
  137. /**
  138. * @dataProvider providerDataType
  139. */
  140. public function testDataType(string $style, string $expectedResult): void
  141. {
  142. $styles = Gnumeric::gnumericMappings();
  143. $borders = $styles['dataType'];
  144. self::assertEquals($expectedResult, $borders[$style]);
  145. }
  146. public function testDataTypeCoverage(): void
  147. {
  148. $styles = Gnumeric::gnumericMappings();
  149. $expected = $styles['dataType'];
  150. self::assertArrayNotHasKey('70', $expected);
  151. self::assertArrayNotHasKey('80', $expected);
  152. $covered = [];
  153. foreach ($expected as $key => $val) {
  154. $covered[$key] = 0;
  155. }
  156. $tests = $this->providerDataType();
  157. foreach ($tests as $test) {
  158. $covered[$test[0]] = 1;
  159. }
  160. foreach ($covered as $key => $val) {
  161. self::assertEquals(1, $val, "dataType $key not tested");
  162. }
  163. }
  164. public function providerBorderStyle(): array
  165. {
  166. return [
  167. ['0', Border::BORDER_NONE],
  168. ['1', Border::BORDER_THIN],
  169. ['2', Border::BORDER_MEDIUM],
  170. ['3', Border::BORDER_SLANTDASHDOT],
  171. ['4', Border::BORDER_DASHED],
  172. ['5', Border::BORDER_THICK],
  173. ['6', Border::BORDER_DOUBLE],
  174. ['7', Border::BORDER_DOTTED],
  175. ['8', Border::BORDER_MEDIUMDASHED],
  176. ['9', Border::BORDER_DASHDOT],
  177. ['10', Border::BORDER_MEDIUMDASHDOT],
  178. ['11', Border::BORDER_DASHDOTDOT],
  179. ['12', Border::BORDER_MEDIUMDASHDOTDOT],
  180. ['13', Border::BORDER_MEDIUMDASHDOTDOT],
  181. ];
  182. }
  183. public function providerFillType(): array
  184. {
  185. return [
  186. ['1', Fill::FILL_SOLID],
  187. ['2', Fill::FILL_PATTERN_DARKGRAY],
  188. ['3', Fill::FILL_PATTERN_MEDIUMGRAY],
  189. ['4', Fill::FILL_PATTERN_LIGHTGRAY],
  190. ['5', Fill::FILL_PATTERN_GRAY125],
  191. ['6', Fill::FILL_PATTERN_GRAY0625],
  192. ['7', Fill::FILL_PATTERN_DARKHORIZONTAL],
  193. ['8', Fill::FILL_PATTERN_DARKVERTICAL],
  194. ['9', Fill::FILL_PATTERN_DARKDOWN],
  195. ['10', Fill::FILL_PATTERN_DARKUP],
  196. ['11', Fill::FILL_PATTERN_DARKGRID],
  197. ['12', Fill::FILL_PATTERN_DARKTRELLIS],
  198. ['13', Fill::FILL_PATTERN_LIGHTHORIZONTAL],
  199. ['14', Fill::FILL_PATTERN_LIGHTVERTICAL],
  200. ['15', Fill::FILL_PATTERN_LIGHTUP],
  201. ['16', Fill::FILL_PATTERN_LIGHTDOWN],
  202. ['17', Fill::FILL_PATTERN_LIGHTGRID],
  203. ['18', Fill::FILL_PATTERN_LIGHTTRELLIS],
  204. ];
  205. }
  206. public function providerHorizontal(): array
  207. {
  208. return [
  209. ['1', Alignment::HORIZONTAL_GENERAL],
  210. ['2', Alignment::HORIZONTAL_LEFT],
  211. ['4', Alignment::HORIZONTAL_RIGHT],
  212. ['8', Alignment::HORIZONTAL_CENTER],
  213. ['16', Alignment::HORIZONTAL_CENTER_CONTINUOUS],
  214. ['32', Alignment::HORIZONTAL_JUSTIFY],
  215. ['64', Alignment::HORIZONTAL_CENTER_CONTINUOUS],
  216. ];
  217. }
  218. public function providerUnderline(): array
  219. {
  220. return [
  221. ['1', Font::UNDERLINE_SINGLE],
  222. ['2', Font::UNDERLINE_DOUBLE],
  223. ['3', Font::UNDERLINE_SINGLEACCOUNTING],
  224. ['4', Font::UNDERLINE_DOUBLEACCOUNTING],
  225. ];
  226. }
  227. public function providerVertical(): array
  228. {
  229. return [
  230. ['1', Alignment::VERTICAL_TOP],
  231. ['2', Alignment::VERTICAL_BOTTOM],
  232. ['4', Alignment::VERTICAL_CENTER],
  233. ['8', Alignment::VERTICAL_JUSTIFY],
  234. ];
  235. }
  236. public function providerDataType(): array
  237. {
  238. return [
  239. ['10', DataType::TYPE_NULL],
  240. ['20', DataType::TYPE_BOOL],
  241. ['30', DataType::TYPE_NUMERIC], // Integer doesn't exist in Excel
  242. ['40', DataType::TYPE_NUMERIC], // Float
  243. ['50', DataType::TYPE_ERROR],
  244. ['60', DataType::TYPE_STRING],
  245. //'70': // Cell Range
  246. //'80': // Array
  247. ];
  248. }
  249. }