@@ -99,4 +99,35 @@ public function testVerdanaRotation(): void
9999 $ width = Font::getTextWidthPixelsApprox ('n ' , $ font , -165 );
100100 self ::assertEquals (4 , $ width );
101101 }
102+
103+ /**
104+ * @dataProvider providerCalculateApproximateColumnWidth
105+ */
106+ public function testCalculateApproximateColumnWidth (
107+ int $ expectedWidth ,
108+ StyleFont $ font ,
109+ string $ text ,
110+ int $ rotation ,
111+ StyleFont $ defaultFont ,
112+ bool $ filter ,
113+ int $ indent
114+ ): void {
115+ $ columnWidth = Font::calculateColumnWidth ($ font , $ text , $ rotation , $ defaultFont , $ filter , $ indent );
116+ self ::assertEquals ($ expectedWidth , $ columnWidth );
117+ }
118+
119+ public function providerCalculateApproximateColumnWidth (): array
120+ {
121+ return [
122+ [13 , new StyleFont (), 'Hello World ' , 0 , new StyleFont (), false , 0 ],
123+ [16 , new StyleFont (), 'Hello World ' , 0 , new StyleFont (), true , 0 ],
124+ [16 , new StyleFont (), 'Hello World ' , 0 , new StyleFont (), false , 1 ],
125+ [18 , new StyleFont (), 'Hello World ' , 0 , new StyleFont (), false , 2 ],
126+ [20 , new StyleFont (), 'Hello World ' , 0 , new StyleFont (), false , 3 ],
127+ [6 , new StyleFont (), "Hello \nWorld " , 0 , new StyleFont (), false , 0 ],
128+ [9 , new StyleFont (), "Hello \nWorld " , 0 , new StyleFont (), true , 0 ],
129+ [17 , new StyleFont (), 'PhpSpreadsheet ' , 0 , new StyleFont (), false , 0 ],
130+ [19 , new StyleFont (), 'PhpSpreadsheet ' , 0 , new StyleFont (), false , 1 ],
131+ ];
132+ }
102133}
0 commit comments