|
21 | 21 | use PhpOffice\PhpWord\Element\Section;
|
22 | 22 | use PhpOffice\PhpWord\Element\Table;
|
23 | 23 | use PhpOffice\PhpWord\PhpWord;
|
| 24 | +use PhpOffice\PhpWord\Shared\Converter; |
24 | 25 | use PhpOffice\PhpWord\Shared\Html;
|
25 | 26 | use PhpOffice\PhpWord\SimpleType\Jc;
|
26 | 27 | use PhpOffice\PhpWord\SimpleType\LineSpacingRule;
|
| 28 | +use PhpOffice\PhpWord\SimpleType\TblWidth; |
27 | 29 | use PhpOffice\PhpWord\Style\Paragraph;
|
28 | 30 | use PhpOffice\PhpWordTests\AbstractWebServerEmbeddedTest;
|
29 | 31 | use PhpOffice\PhpWordTests\TestHelperDOCX;
|
@@ -249,6 +251,66 @@ public function testParseLineHeight(): void
|
249 | 251 | self::assertEquals(LineSpacingRule::AUTO, $doc->getElementAttribute('/w:document/w:body/w:p[5]/w:pPr/w:spacing', 'w:lineRule'));
|
250 | 252 | }
|
251 | 253 |
|
| 254 | + public function testParseCellPaddingStyle(): void |
| 255 | + { |
| 256 | + $phpWord = new PhpWord(); |
| 257 | + $section = $phpWord->addSection(); |
| 258 | + |
| 259 | + $top = 10; |
| 260 | + $right = 11; |
| 261 | + $bottom = 12; |
| 262 | + $left = 13; |
| 263 | + |
| 264 | + $testValTop = Converter::pixelToTwip($top); |
| 265 | + $testValRight = Converter::pixelToTwip($right); |
| 266 | + $testValBottom = Converter::pixelToTwip($bottom); |
| 267 | + $testValLeft = Converter::pixelToTwip($left); |
| 268 | + |
| 269 | + $html = '<table> |
| 270 | + <tbody> |
| 271 | + <tr> |
| 272 | + <td style="padding:' . $top . 'px ' . $right . 'px ' . $bottom . 'px ' . $left . 'px;">full</td> |
| 273 | + <td style="padding:' . $top . 'px 0px ' . $bottom . 'px ' . $left . 'px;padding-right:' . $right . 'px;">mix</td> |
| 274 | + <td style="padding-top:' . $top . 'px;">top</td> |
| 275 | + <td style="padding-bottom:' . $bottom . 'px;">bottom</td> |
| 276 | + <td style="padding-left:' . $left . 'px;">left</td> |
| 277 | + </tr> |
| 278 | + </tbody> |
| 279 | + </table>'; |
| 280 | + Html::addHtml($section, $html); |
| 281 | + |
| 282 | + $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); |
| 283 | + |
| 284 | + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[1]/w:tcPr/w:tcMar/w:top'; |
| 285 | + self::assertTrue($doc->elementExists($path)); |
| 286 | + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[1]/w:tcPr/w:tcMar/w:bottom'; |
| 287 | + self::assertTrue($doc->elementExists($path)); |
| 288 | + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[1]/w:tcPr/w:tcMar/w:end'; |
| 289 | + self::assertTrue($doc->elementExists($path)); |
| 290 | + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[1]/w:tcPr/w:tcMar/w:start'; |
| 291 | + self::assertTrue($doc->elementExists($path)); |
| 292 | + |
| 293 | + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[2]/w:tcPr/w:tcMar/w:end'; |
| 294 | + self::assertTrue($doc->elementExists($path)); |
| 295 | + self::assertEquals($testValRight, $doc->getElementAttribute($path, 'w:w')); |
| 296 | + self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type')); |
| 297 | + |
| 298 | + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[3]/w:tcPr/w:tcMar/w:top'; |
| 299 | + self::assertTrue($doc->elementExists($path)); |
| 300 | + self::assertEquals($testValTop, $doc->getElementAttribute($path, 'w:w')); |
| 301 | + self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type')); |
| 302 | + |
| 303 | + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[4]/w:tcPr/w:tcMar/w:bottom'; |
| 304 | + self::assertTrue($doc->elementExists($path)); |
| 305 | + self::assertEquals($testValBottom, $doc->getElementAttribute($path, 'w:w')); |
| 306 | + self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type')); |
| 307 | + |
| 308 | + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[5]/w:tcPr/w:tcMar/w:start'; |
| 309 | + self::assertTrue($doc->elementExists($path)); |
| 310 | + self::assertEquals($testValLeft, $doc->getElementAttribute($path, 'w:w')); |
| 311 | + self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type')); |
| 312 | + } |
| 313 | + |
252 | 314 | /**
|
253 | 315 | * Test text-indent style.
|
254 | 316 | */
|
|
0 commit comments