ShadowPresetsTest.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Chart;
  3. use PhpOffice\PhpSpreadsheet\Chart\Axis;
  4. use PhpOffice\PhpSpreadsheet\Chart\ChartColor;
  5. use PhpOffice\PhpSpreadsheet\Chart\GridLines;
  6. use PhpOffice\PhpSpreadsheet\Chart\Properties;
  7. use PHPUnit\Framework\TestCase;
  8. class ShadowPresetsTest extends TestCase
  9. {
  10. public function testGridlineShadowPresets(): void
  11. {
  12. $gridlines = new GridLines();
  13. $gridlines->setShadowProperties(17);
  14. $expectedShadow = [
  15. 'effect' => 'innerShdw',
  16. 'distance' => 4,
  17. 'direction' => 270,
  18. 'blur' => 5,
  19. ];
  20. foreach ($expectedShadow as $key => $value) {
  21. self::assertEquals($gridlines->getShadowProperty($key), $value, $key);
  22. }
  23. }
  24. public function testGridlineShadowPresetsWithArray(): void
  25. {
  26. $gridlines = new GridLines();
  27. $gridlines->setShadowProperties(20);
  28. $expectedShadow = [
  29. 'effect' => 'outerShdw',
  30. 'blur' => 6,
  31. 'direction' => 315,
  32. 'size' => [
  33. 'sx' => null,
  34. 'sy' => 0.23,
  35. 'kx' => -20,
  36. 'ky' => null,
  37. ],
  38. 'algn' => 'bl',
  39. 'rotWithShape' => '0',
  40. ];
  41. foreach ($expectedShadow as $key => $value) {
  42. self::assertEquals($gridlines->getShadowProperty($key), $value, $key);
  43. }
  44. }
  45. public function testAxisShadowPresets(): void
  46. {
  47. $axis = new Axis();
  48. $axis->setShadowProperties(9);
  49. $expectedShadow = [
  50. 'effect' => 'outerShdw',
  51. 'blur' => 4,
  52. 'distance' => 3,
  53. 'direction' => 225,
  54. 'algn' => 'br',
  55. 'rotWithShape' => '0',
  56. ];
  57. foreach ($expectedShadow as $key => $value) {
  58. self::assertEquals($axis->getShadowProperty($key), $value, $key);
  59. }
  60. }
  61. public function testAxisShadowPresetsWithChanges(): void
  62. {
  63. $axis = new Axis();
  64. $axis->setShadowProperties(
  65. 9, // preset
  66. 'FF0000', // colorValue
  67. 'srgbClr', // colorType
  68. 20, // alpha
  69. 6, // blur
  70. 30, // direction
  71. 4, // distance
  72. );
  73. $expectedShadow = [
  74. 'effect' => 'outerShdw',
  75. 'blur' => 6,
  76. 'distance' => 4,
  77. 'direction' => 30,
  78. 'algn' => 'br',
  79. 'rotWithShape' => '0',
  80. 'color' => [
  81. 'value' => 'FF0000',
  82. 'type' => 'srgbClr',
  83. 'alpha' => 20,
  84. ],
  85. ];
  86. foreach ($expectedShadow as $key => $value) {
  87. self::assertEquals($axis->getShadowProperty($key), $value, $key);
  88. }
  89. }
  90. public function testGridlinesShadowPresetsWithChanges(): void
  91. {
  92. $gridline = new GridLines();
  93. $gridline->setShadowProperties(
  94. 9, // preset
  95. 'FF0000', // colorValue
  96. 'srgbClr', // colorType
  97. 20, // alpha
  98. 6, // blur
  99. 30, // direction
  100. 4, // distance
  101. );
  102. $expectedShadow = [
  103. 'effect' => 'outerShdw',
  104. 'blur' => 6,
  105. 'distance' => 4,
  106. 'direction' => 30,
  107. 'algn' => 'br',
  108. 'rotWithShape' => '0',
  109. 'color' => [
  110. 'value' => 'FF0000',
  111. 'type' => 'srgbClr',
  112. 'alpha' => 20,
  113. ],
  114. ];
  115. foreach ($expectedShadow as $key => $value) {
  116. self::assertEquals($gridline->getShadowProperty($key), $value, $key);
  117. }
  118. }
  119. public function testPreset0(): void
  120. {
  121. $axis = new Axis();
  122. $axis->setShadowProperties(0);
  123. $expectedShadow = [
  124. 'presets' => Properties::SHADOW_PRESETS_NOSHADOW,
  125. 'effect' => null,
  126. 'color' => [
  127. 'type' => ChartColor::EXCEL_COLOR_TYPE_STANDARD,
  128. 'value' => 'black',
  129. 'alpha' => 40,
  130. ],
  131. 'size' => [
  132. 'sx' => null,
  133. 'sy' => null,
  134. 'kx' => null,
  135. 'ky' => null,
  136. ],
  137. 'blur' => null,
  138. 'direction' => null,
  139. 'distance' => null,
  140. 'algn' => null,
  141. 'rotWithShape' => null,
  142. ];
  143. foreach ($expectedShadow as $key => $value) {
  144. self::assertEquals($value, $axis->getShadowProperty($key), $key);
  145. }
  146. }
  147. public function testOutOfRangePresets(): void
  148. {
  149. $axis = new Axis();
  150. $axis->setShadowProperties(99);
  151. $expectedShadow = [
  152. 'presets' => Properties::SHADOW_PRESETS_NOSHADOW,
  153. 'effect' => null,
  154. 'color' => [
  155. 'type' => ChartColor::EXCEL_COLOR_TYPE_STANDARD,
  156. 'value' => 'black',
  157. 'alpha' => 40,
  158. ],
  159. 'size' => [
  160. 'sx' => null,
  161. 'sy' => null,
  162. 'kx' => null,
  163. 'ky' => null,
  164. ],
  165. 'blur' => null,
  166. 'direction' => null,
  167. 'distance' => null,
  168. 'algn' => null,
  169. 'rotWithShape' => null,
  170. ];
  171. foreach ($expectedShadow as $key => $value) {
  172. self::assertEquals($value, $axis->getShadowProperty($key), $key);
  173. }
  174. }
  175. public function testOutOfRangeGridlines(): void
  176. {
  177. $gridline = new GridLines();
  178. $gridline->setShadowProperties(99);
  179. $expectedShadow = [
  180. 'presets' => Properties::SHADOW_PRESETS_NOSHADOW,
  181. 'effect' => null,
  182. 'color' => [
  183. 'type' => ChartColor::EXCEL_COLOR_TYPE_STANDARD,
  184. 'value' => 'black',
  185. 'alpha' => 40,
  186. ],
  187. 'size' => [
  188. 'sx' => null,
  189. 'sy' => null,
  190. 'kx' => null,
  191. 'ky' => null,
  192. ],
  193. 'blur' => null,
  194. 'direction' => null,
  195. 'distance' => null,
  196. 'algn' => null,
  197. 'rotWithShape' => null,
  198. ];
  199. foreach ($expectedShadow as $key => $value) {
  200. self::assertEquals($value, $gridline->getShadowProperty($key), $key);
  201. }
  202. }
  203. }