|
22 | 22 | use PhpOffice\PhpWord\Element\Section; |
23 | 23 | use PhpOffice\PhpWord\Element\Table; |
24 | 24 | use PhpOffice\PhpWord\PhpWord; |
| 25 | +use PhpOffice\PhpWord\Shared\Converter; |
25 | 26 | use PhpOffice\PhpWord\Shared\Html; |
26 | 27 | use PhpOffice\PhpWord\SimpleType\Jc; |
27 | 28 | use PhpOffice\PhpWord\SimpleType\LineSpacingRule; |
@@ -270,6 +271,66 @@ public function testParseLineHeight(): void |
270 | 271 | self::assertEquals(LineSpacingRule::AUTO, $doc->getElementAttribute('/w:document/w:body/w:p[5]/w:pPr/w:spacing', 'w:lineRule')); |
271 | 272 | } |
272 | 273 |
|
| 274 | + public function testParseCellPaddingStyle(): void |
| 275 | + { |
| 276 | + $phpWord = new PhpWord(); |
| 277 | + $section = $phpWord->addSection(); |
| 278 | + |
| 279 | + $top = 10; |
| 280 | + $right = 11; |
| 281 | + $bottom = 12; |
| 282 | + $left = 13; |
| 283 | + |
| 284 | + $testValTop = Converter::pixelToTwip($top); |
| 285 | + $testValRight = Converter::pixelToTwip($right); |
| 286 | + $testValBottom = Converter::pixelToTwip($bottom); |
| 287 | + $testValLeft = Converter::pixelToTwip($left); |
| 288 | + |
| 289 | + $html = '<table> |
| 290 | + <tbody> |
| 291 | + <tr> |
| 292 | + <td style="padding:' . $top . 'px ' . $right . 'px ' . $bottom . 'px ' . $left . 'px;">full</td> |
| 293 | + <td style="padding:' . $top . 'px 0px ' . $bottom . 'px ' . $left . 'px;padding-right:' . $right . 'px;">mix</td> |
| 294 | + <td style="padding-top:' . $top . 'px;">top</td> |
| 295 | + <td style="padding-bottom:' . $bottom . 'px;">bottom</td> |
| 296 | + <td style="padding-left:' . $left . 'px;">left</td> |
| 297 | + </tr> |
| 298 | + </tbody> |
| 299 | + </table>'; |
| 300 | + Html::addHtml($section, $html); |
| 301 | + |
| 302 | + $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); |
| 303 | + |
| 304 | + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[1]/w:tcPr/w:tcMar/w:top'; |
| 305 | + self::assertTrue($doc->elementExists($path)); |
| 306 | + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[1]/w:tcPr/w:tcMar/w:bottom'; |
| 307 | + self::assertTrue($doc->elementExists($path)); |
| 308 | + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[1]/w:tcPr/w:tcMar/w:end'; |
| 309 | + self::assertTrue($doc->elementExists($path)); |
| 310 | + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[1]/w:tcPr/w:tcMar/w:start'; |
| 311 | + self::assertTrue($doc->elementExists($path)); |
| 312 | + |
| 313 | + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[2]/w:tcPr/w:tcMar/w:end'; |
| 314 | + self::assertTrue($doc->elementExists($path)); |
| 315 | + self::assertEquals($testValRight, $doc->getElementAttribute($path, 'w:w')); |
| 316 | + self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type')); |
| 317 | + |
| 318 | + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[3]/w:tcPr/w:tcMar/w:top'; |
| 319 | + self::assertTrue($doc->elementExists($path)); |
| 320 | + self::assertEquals($testValTop, $doc->getElementAttribute($path, 'w:w')); |
| 321 | + self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type')); |
| 322 | + |
| 323 | + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[4]/w:tcPr/w:tcMar/w:bottom'; |
| 324 | + self::assertTrue($doc->elementExists($path)); |
| 325 | + self::assertEquals($testValBottom, $doc->getElementAttribute($path, 'w:w')); |
| 326 | + self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type')); |
| 327 | + |
| 328 | + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[5]/w:tcPr/w:tcMar/w:start'; |
| 329 | + self::assertTrue($doc->elementExists($path)); |
| 330 | + self::assertEquals($testValLeft, $doc->getElementAttribute($path, 'w:w')); |
| 331 | + self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type')); |
| 332 | + } |
| 333 | + |
273 | 334 | /** |
274 | 335 | * Test text-indent style. |
275 | 336 | */ |
|
0 commit comments