4
4
5
5
namespace PhpOffice \PhpSpreadsheetTests \Writer \Html ;
6
6
7
+ use PhpOffice \PhpSpreadsheet \Cell \Coordinate ;
7
8
use PhpOffice \PhpSpreadsheet \Reader \Xlsx as XlsxReader ;
8
9
use PhpOffice \PhpSpreadsheet \Writer \Html as HtmlWriter ;
9
10
use PHPUnit \Framework \TestCase ;
@@ -23,57 +24,46 @@ protected function setUp(): void
23
24
$ spreadsheet ->disconnectWorksheets ();
24
25
}
25
26
26
- #[\PHPUnit \Framework \Attributes \DataProvider('colourScaleProvider ' )]
27
- public function testColourScaleHtmlOutput (int $ rowNumber , array $ expectedMatches ): void
27
+ private function extractCell (string $ coordinate ): string
28
28
{
29
- self ::assertSame (1 , preg_match ('~<tr class="row ' . $ rowNumber . '".+?</tr>~ms ' , $ this ->data , $ matches ));
30
- foreach ($ expectedMatches as $ i => $ expected ) {
31
- self ::assertStringContainsString ($ expected , $ matches [0 ]);
29
+ [$ column , $ row ] = Coordinate::indexesFromString ($ coordinate );
30
+ --$ column ;
31
+ --$ row ;
32
+ // extract row into $matches
33
+ $ match = preg_match ('~<tr class="row ' . $ row . '".+?</tr>~s ' , $ this ->data , $ matches );
34
+ if ($ match !== 1 ) {
35
+ return 'unable to match row ' ;
32
36
}
37
+ $ rowData = $ matches [0 ];
38
+ // extract cell into $matches
39
+ $ match = preg_match ('~<td class="column ' . $ column . ' .+?</td>~s ' , $ rowData , $ matches );
40
+ if ($ match !== 1 ) {
41
+ return 'unable to match column ' ;
42
+ }
43
+
44
+ return $ matches [0 ];
33
45
}
34
46
35
- public static function colourScaleProvider (): array
47
+ public function testColourScaleHtmlOutput (): void
36
48
{
37
- return [
38
- 'row 0: low/high min/max with 80% midpoint ' => [0 , ['<td class="column0 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#57BB8A;">1</td> ' ,
39
- '<td class="column1 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#6EBE85;">2</td> ' ,
40
- '<td class="column2 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#85C280;">3</td> ' ,
41
- '<td class="column3 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#9DC67A;">4</td> ' ,
42
- '<td class="column4 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#B4CA76;">5</td> ' ,
43
- '<td class="column5 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#CBCD71;">6</td> ' ,
44
- '<td class="column6 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#E3D16C;">7</td> ' ,
45
- '<td class="column7 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#FAD566;">8</td> ' ,
46
- '<td class="column8 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#F3AD6B;">9</td> ' ,
47
- '<td class="column9 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#E67C73;">10</td> ' ]],
48
- 'row 1: low/high 40%/80% with 50% midpoint ' => [1 , ['<td class="column0 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#57BB8A;">1</td> ' ,
49
- '<td class="column1 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#57BB8A;">2</td> ' ,
50
- '<td class="column2 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#57BB8A;">3</td> ' ,
51
- '<td class="column3 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#57BB8A;">4</td> ' ,
52
- '<td class="column4 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#A1C77A;">5</td> ' ,
53
- '<td class="column5 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#F1A36D;">6</td> ' ,
54
- '<td class="column6 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#E67C73;">7</td> ' ,
55
- '<td class="column7 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#E67C73;">8</td> ' ,
56
- '<td class="column8 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#E67C73;">9</td> ' ,
57
- '<td class="column9 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#E67C73;">10</td> ' ]],
58
- 'row 2: low/high/midpoint values 3/8/4 ' => [2 , ['<td class="column0 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#57BB8A;">1</td> ' ,
59
- '<td class="column1 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#57BB8A;">2</td> ' ,
60
- '<td class="column2 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#57BB8A;">3</td> ' ,
61
- '<td class="column3 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#FFD666;">4</td> ' ,
62
- '<td class="column4 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#F8BF69;">5</td> ' ,
63
- '<td class="column5 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#F2A96C;">6</td> ' ,
64
- '<td class="column6 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#EC926F;">7</td> ' ,
65
- '<td class="column7 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#E67C73;">8</td> ' ,
66
- '<td class="column8 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#E67C73;">9</td> ' ,
67
- '<td class="column9 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#E67C73;">10</td> ' ]],
68
- 'row 3: low/high with 30/80 percentile and 50% midpoint, one cell no value ' => [3 , ['<td class="column0 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#57BB8A;">1</td> ' ,
69
- '<td class="column1 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#57BB8A;">2</td> ' ,
70
- '<td class="column2 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#8FC47E;">3</td> ' ,
71
- '<td class="column3 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#C7CD72;">4</td> ' ,
72
- '<td class="column4 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#57BB8A;">2</td> ' ,
73
- '<td class="column5 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#E67C73;">9</td> ' ,
74
- '<td class="column6 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#E67C73;">9</td> ' ,
75
- '<td class="column7 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#E67C73;">9</td> ' ,
76
- '<td class="column8 style2 null"></td> ' ,
77
- '<td class="column9 style1 n" style="vertical-align:bottom;border-bottom:none #000000;border-top:none #000000;border-left:none #000000;border-right:none #000000;color:#000000;font-family: \'Arial \';font-size:11pt;background-color:#E67C73;">10</td> ' ]]];
49
+ $ expectedMatches = [
50
+ ['E1 ' , 'background-color:#B4CA76;">5< ' , 'cell E1 ' ],
51
+ ['F1 ' , 'background-color:#CBCD71;">6< ' , 'cell F1 ' ],
52
+ ['G1 ' , 'background-color:#E3D16C;">7< ' , 'cell G1 ' ],
53
+ ['D2 ' , 'background-color:#57BB8A;">4< ' , 'cell D2 ' ],
54
+ ['E2 ' , 'background-color:#A1C77A;">5< ' , 'cell E2 ' ],
55
+ ['F2 ' , 'background-color:#F1A36D;">6< ' , 'cell F2 ' ],
56
+ ['D3 ' , 'background-color:#FFD666;">4< ' , 'cell D3 ' ],
57
+ ['G3 ' , 'background-color:#EC926F;">7< ' , 'cell G3 ' ],
58
+ ['H3 ' , 'background-color:#E67C73;">8< ' , 'cell H3 ' ],
59
+ ['A4 ' , 'background-color:#57BB8A;">1< ' , 'cell A4 ' ],
60
+ ['I4 ' , 'null">< ' , 'empty cell I4 ' ],
61
+ ['J4 ' , 'background-color:#E67C73;">10< ' , 'cell J4 ' ],
62
+ ];
63
+ foreach ($ expectedMatches as $ expected ) {
64
+ [$ coordinate , $ expectedString , $ message ] = $ expected ;
65
+ $ string = $ this ->extractCell ($ coordinate );
66
+ self ::assertStringContainsString ($ expectedString , $ string , $ message );
67
+ }
78
68
}
79
69
}
0 commit comments