@@ -137,4 +137,68 @@ public function testListTypes(): void
137137 $ numIdPath = $ path . '/w:pPr/w:numPr/w:numId ' ;
138138 self ::assertSame ($ expected , $ doc ->getElement ($ numIdPath )->getAttribute ('w:val ' ));
139139 }
140+
141+ public function testPadding (): void
142+ {
143+ $ phpWord = new PhpWord ();
144+ $ section = $ phpWord ->addSection ();
145+ $ html = '<table><tbody> '
146+ . '<tr> '
147+ . '<td style="padding: 20px">20</td> '
148+ . '<td style="padding: 20px 30px">20 30</td> '
149+ . '</tr><tr> '
150+ . '<td style="padding: 20px 30px 40px">20 30 40</td> '
151+ . '<td style="padding: 20px 30px 40px 50px">20 30 40 50</td> '
152+ . '</tr></tbody></table> ' ;
153+ Html::addHtml ($ section , $ html );
154+ $ doc = TestHelperDOCX::getDocument ($ phpWord );
155+
156+ $ item = 1 ;
157+ $ td = 1 ;
158+ $ path = "/w:document/w:body/w:tbl/w:tr[ $ item]/w:tc[ $ td] " ;
159+ self ::assertSame ('20 ' , $ doc ->getElement ("$ path/w:p/w:r " )->nodeValue );
160+ $ tcMarPath = $ path . '/w:tcPr/w:tcMar ' ;
161+ self ::assertSame ('300 ' , $ doc ->getElement ($ tcMarPath . '/w:top ' )->getAttribute ('w:w ' ));
162+ self ::assertSame ('300 ' , $ doc ->getElement ($ tcMarPath . '/w:start ' )->getAttribute ('w:w ' ));
163+ self ::assertSame ('300 ' , $ doc ->getElement ($ tcMarPath . '/w:bottom ' )->getAttribute ('w:w ' ));
164+ self ::assertSame ('300 ' , $ doc ->getElement ($ tcMarPath . '/w:end ' )->getAttribute ('w:w ' ));
165+
166+ ++$ td ;
167+ $ path = "/w:document/w:body/w:tbl/w:tr[ $ item]/w:tc[ $ td] " ;
168+ self ::assertSame ('20 30 ' , $ doc ->getElement ("$ path/w:p/w:r " )->nodeValue );
169+ $ tcMarPath = $ path . '/w:tcPr/w:tcMar ' ;
170+ self ::assertSame ('300 ' , $ doc ->getElement ($ tcMarPath . '/w:top ' )->getAttribute ('w:w ' ));
171+ self ::assertSame ('450 ' , $ doc ->getElement ($ tcMarPath . '/w:start ' )->getAttribute ('w:w ' ));
172+ self ::assertSame ('300 ' , $ doc ->getElement ($ tcMarPath . '/w:bottom ' )->getAttribute ('w:w ' ));
173+ self ::assertSame ('450 ' , $ doc ->getElement ($ tcMarPath . '/w:end ' )->getAttribute ('w:w ' ));
174+
175+ $ item = 1 ;
176+ $ td = 1 ;
177+ $ path = "/w:document/w:body/w:tbl/w:tr[ $ item]/w:tc[ $ td] " ;
178+ self ::assertSame ('20 ' , $ doc ->getElement ("$ path/w:p/w:r " )->nodeValue );
179+ $ tcMarPath = $ path . '/w:tcPr/w:tcMar ' ;
180+ self ::assertSame ('300 ' , $ doc ->getElement ($ tcMarPath . '/w:top ' )->getAttribute ('w:w ' ));
181+ self ::assertSame ('300 ' , $ doc ->getElement ($ tcMarPath . '/w:start ' )->getAttribute ('w:w ' ));
182+ self ::assertSame ('300 ' , $ doc ->getElement ($ tcMarPath . '/w:bottom ' )->getAttribute ('w:w ' ));
183+ self ::assertSame ('300 ' , $ doc ->getElement ($ tcMarPath . '/w:end ' )->getAttribute ('w:w ' ));
184+
185+ ++$ item ;
186+ $ td = 1 ;
187+ $ path = "/w:document/w:body/w:tbl/w:tr[ $ item]/w:tc[ $ td] " ;
188+ self ::assertSame ('20 30 40 ' , $ doc ->getElement ("$ path/w:p/w:r " )->nodeValue );
189+ $ tcMarPath = $ path . '/w:tcPr/w:tcMar ' ;
190+ self ::assertSame ('300 ' , $ doc ->getElement ($ tcMarPath . '/w:top ' )->getAttribute ('w:w ' ));
191+ self ::assertSame ('450 ' , $ doc ->getElement ($ tcMarPath . '/w:start ' )->getAttribute ('w:w ' ));
192+ self ::assertSame ('600 ' , $ doc ->getElement ($ tcMarPath . '/w:bottom ' )->getAttribute ('w:w ' ));
193+ self ::assertSame ('450 ' , $ doc ->getElement ($ tcMarPath . '/w:end ' )->getAttribute ('w:w ' ));
194+
195+ ++$ td ;
196+ $ path = "/w:document/w:body/w:tbl/w:tr[ $ item]/w:tc[ $ td] " ;
197+ self ::assertSame ('20 30 40 50 ' , $ doc ->getElement ("$ path/w:p/w:r " )->nodeValue );
198+ $ tcMarPath = $ path . '/w:tcPr/w:tcMar ' ;
199+ self ::assertSame ('300 ' , $ doc ->getElement ($ tcMarPath . '/w:top ' )->getAttribute ('w:w ' ));
200+ self ::assertSame ('750 ' , $ doc ->getElement ($ tcMarPath . '/w:start ' )->getAttribute ('w:w ' ));
201+ self ::assertSame ('600 ' , $ doc ->getElement ($ tcMarPath . '/w:bottom ' )->getAttribute ('w:w ' ));
202+ self ::assertSame ('450 ' , $ doc ->getElement ($ tcMarPath . '/w:end ' )->getAttribute ('w:w ' ));
203+ }
140204}
0 commit comments