|
20 | 20 |
|
21 | 21 | use PhpOffice\PhpWord\AbstractWebServerEmbeddedTest;
|
22 | 22 | use PhpOffice\PhpWord\Element\Section;
|
| 23 | +use PhpOffice\PhpWord\PhpWord; |
| 24 | +use PhpOffice\PhpWord\Settings; |
23 | 25 | use PhpOffice\PhpWord\SimpleType\Jc;
|
24 | 26 | use PhpOffice\PhpWord\SimpleType\LineSpacingRule;
|
25 | 27 | use PhpOffice\PhpWord\Style\BorderSide;
|
|
28 | 30 | use PhpOffice\PhpWord\Style\Lengths\Absolute;
|
29 | 31 | use PhpOffice\PhpWord\Style\Paragraph;
|
30 | 32 | use PhpOffice\PhpWord\TestHelperDOCX;
|
| 33 | +use PhpOffice\PhpWord\Writer\HTML as Writer; |
31 | 34 |
|
32 | 35 | /**
|
33 | 36 | * Test class for PhpOffice\PhpWord\Shared\Html
|
34 | 37 | * @coversDefaultClass \PhpOffice\PhpWord\Shared\Html
|
35 | 38 | */
|
36 | 39 | class HtmlTest extends AbstractWebServerEmbeddedTest
|
37 | 40 | {
|
| 41 | + public function testRoundTripHeadings() |
| 42 | + { |
| 43 | + $file = __DIR__ . '/../_files/temp.html'; |
| 44 | + $html = <<<'HTML' |
| 45 | +<!DOCTYPE html> |
| 46 | +<!-- Generated by PHPWord --> |
| 47 | +<html> |
| 48 | +<head> |
| 49 | +<meta charset="UTF-8" /> |
| 50 | +<title>PHPWord</title> |
| 51 | +<style title="PHPWord Base Styles"> |
| 52 | +* {font-family: Arial; font-size: 10pt;} |
| 53 | +a.NoteRef {text-decoration: none;} |
| 54 | +hr {height: 1px; padding: 0; margin: 1em 0; border: 0; border-top: 1px solid #CCC;} |
| 55 | +table {border: 1px solid black; border-spacing: 0px; width : 100%;} |
| 56 | +td {border: 1px solid black;} |
| 57 | +</style> |
| 58 | +</head> |
| 59 | +<body> |
| 60 | +<h1>Heading <span style="font-style: italic;">1</span></h1> |
| 61 | +<h2>Heading <span style="font-style: italic;">2</span></h2> |
| 62 | +<h3>Heading <span style="font-style: italic;">3</span></h3> |
| 63 | +<h4>Heading <span style="font-style: italic;">4</span></h4> |
| 64 | +<h5>Heading <span style="font-style: italic;">5</span></h5> |
| 65 | +<h6>Heading <span style="font-style: italic;">6</span></h6> |
| 66 | +</body> |
| 67 | +</html> |
| 68 | + |
| 69 | +HTML; |
| 70 | + |
| 71 | + $phpWord = new PhpWord(); |
| 72 | + Settings::setOutputEscapingEnabled(true); |
| 73 | + |
| 74 | + $section = $phpWord->addSection(); |
| 75 | + Html::addHtml($section, $html, true); |
| 76 | + |
| 77 | + (new Writer($phpWord))->save($file); |
| 78 | + |
| 79 | + $this->assertEquals($html, file_get_contents($file)); |
| 80 | + |
| 81 | + unlink($file); |
| 82 | + } |
| 83 | + |
38 | 84 | /**
|
39 | 85 | * Test unit conversion functions with various numbers
|
40 | 86 | */
|
|
0 commit comments