|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * This file is part of PHPWord - A pure PHP library for reading and writing |
| 5 | + * word processing documents. |
| 6 | + * |
| 7 | + * PHPWord is free software distributed under the terms of the GNU Lesser |
| 8 | + * General Public License version 3 as published by the Free Software Foundation. |
| 9 | + * |
| 10 | + * For the full copyright and license information, please read the LICENSE |
| 11 | + * file that was distributed with this source code. For the full list of |
| 12 | + * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. |
| 13 | + * |
| 14 | + * @see https://github.com/PHPOffice/PHPWord |
| 15 | + * |
| 16 | + * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
| 17 | + */ |
| 18 | +declare(strict_types=1); |
| 19 | + |
| 20 | +namespace PhpOffice\PhpWordTests\Writer\Word2007\Element; |
| 21 | + |
| 22 | +use PhpOffice\PhpWord\Reader\HTML; |
| 23 | +use PhpOffice\PhpWordTests\TestHelperDOCX; |
| 24 | + |
| 25 | +/** |
| 26 | + * Test class for PhpOffice\PhpWord\Writer\Word2007\Element subnamespace. |
| 27 | + */ |
| 28 | +class UnorderedListTest extends \PHPUnit\Framework\TestCase |
| 29 | +{ |
| 30 | + /** |
| 31 | + * Executed after each method of the class. |
| 32 | + */ |
| 33 | + protected function tearDown(): void |
| 34 | + { |
| 35 | + TestHelperDOCX::clear(); |
| 36 | + } |
| 37 | + |
| 38 | + public static function testUnorderedList(): void |
| 39 | + { |
| 40 | + $infile = 'tests/PhpWordTests/_files/html/bullets.html'; |
| 41 | + $reader = new HTML(); |
| 42 | + $phpWord = $reader->load($infile); |
| 43 | + |
| 44 | + $doc = TestHelperDOCX::getDocument($phpWord); |
| 45 | + $loc = '/w:document/w:body/w:p[2]'; |
| 46 | + self::assertTrue($doc->elementExists($loc)); |
| 47 | + $next = "$loc/w:pPr/w:numPr"; |
| 48 | + self::assertTrue($doc->elementExists($next)); |
| 49 | + $ilvl = "$next/w:ilvl"; |
| 50 | + self::assertTrue($doc->elementExists($ilvl)); |
| 51 | + self::assertSame('0', $doc->getElementAttribute($ilvl, 'w:val')); |
| 52 | + $next = "$loc/w:r/w:t"; |
| 53 | + self::assertTrue($doc->elementExists($next)); |
| 54 | + self::assertSame('First level.', $doc->getElement($next)->textContent); |
| 55 | + |
| 56 | + $loc = '/w:document/w:body/w:p[3]'; |
| 57 | + self::assertTrue($doc->elementExists($loc)); |
| 58 | + $next = "$loc/w:pPr/w:numPr"; |
| 59 | + self::assertTrue($doc->elementExists($next)); |
| 60 | + $ilvl = "$next/w:ilvl"; |
| 61 | + self::assertTrue($doc->elementExists($ilvl)); |
| 62 | + self::assertSame('1', $doc->getElementAttribute($ilvl, 'w:val')); |
| 63 | + $next = "$loc/w:r/w:t"; |
| 64 | + self::assertTrue($doc->elementExists($next)); |
| 65 | + self::assertSame('Second level.', $doc->getElement($next)->textContent); |
| 66 | + |
| 67 | + $loc = '/w:document/w:body/w:p[4]'; |
| 68 | + self::assertTrue($doc->elementExists($loc)); |
| 69 | + $next = "$loc/w:pPr/w:numPr"; |
| 70 | + self::assertTrue($doc->elementExists($next)); |
| 71 | + $ilvl = "$next/w:ilvl"; |
| 72 | + self::assertTrue($doc->elementExists($ilvl)); |
| 73 | + self::assertSame('2', $doc->getElementAttribute($ilvl, 'w:val')); |
| 74 | + $next = "$loc/w:r/w:t"; |
| 75 | + self::assertTrue($doc->elementExists($next)); |
| 76 | + self::assertSame('Third level.', $doc->getElement($next)->textContent); |
| 77 | + |
| 78 | + $doc->setDefaultFile('word/numbering.xml'); |
| 79 | + $loc = '/w:numbering/w:abstractNum/w:lvl[1]'; |
| 80 | + self::assertTrue($doc->elementExists($loc)); |
| 81 | + self::assertSame('0', $doc->getElementAttribute($loc, 'w:ilvl')); |
| 82 | + $lvlText = "$loc/w:lvlText"; |
| 83 | + self::assertTrue($doc->elementExists($lvlText)); |
| 84 | + self::assertSame("\u{f0b7}", $doc->getElementAttribute($lvlText, 'w:val')); |
| 85 | + $ind = "$loc/w:pPr/w:ind"; |
| 86 | + self::assertTrue($doc->elementExists($ind)); |
| 87 | + self::assertSame('720', $doc->getElementAttribute($ind, 'w:left')); |
| 88 | + self::assertSame('360', $doc->getElementAttribute($ind, 'w:hanging')); |
| 89 | + $fonts = "$loc/w:rPr/w:rFonts"; |
| 90 | + self::assertTrue($doc->elementExists($fonts)); |
| 91 | + self::assertSame('Symbol', $doc->getElementAttribute($fonts, 'w:ascii')); |
| 92 | + |
| 93 | + $loc = '/w:numbering/w:abstractNum/w:lvl[2]'; |
| 94 | + self::assertTrue($doc->elementExists($loc)); |
| 95 | + self::assertSame('1', $doc->getElementAttribute($loc, 'w:ilvl')); |
| 96 | + $lvlText = "$loc/w:lvlText"; |
| 97 | + self::assertTrue($doc->elementExists($lvlText)); |
| 98 | + self::assertSame('o', $doc->getElementAttribute($lvlText, 'w:val')); |
| 99 | + $ind = "$loc/w:pPr/w:ind"; |
| 100 | + self::assertTrue($doc->elementExists($ind)); |
| 101 | + self::assertSame('1440', $doc->getElementAttribute($ind, 'w:left')); |
| 102 | + self::assertSame('360', $doc->getElementAttribute($ind, 'w:hanging')); |
| 103 | + $fonts = "$loc/w:rPr/w:rFonts"; |
| 104 | + self::assertTrue($doc->elementExists($fonts)); |
| 105 | + self::assertSame('Courier New', $doc->getElementAttribute($fonts, 'w:ascii')); |
| 106 | + |
| 107 | + $loc = '/w:numbering/w:abstractNum/w:lvl[3]'; |
| 108 | + self::assertTrue($doc->elementExists($loc)); |
| 109 | + self::assertSame('2', $doc->getElementAttribute($loc, 'w:ilvl')); |
| 110 | + $lvlText = "$loc/w:lvlText"; |
| 111 | + self::assertTrue($doc->elementExists($lvlText)); |
| 112 | + self::assertSame("\u{f0a7}", $doc->getElementAttribute($lvlText, 'w:val')); |
| 113 | + $ind = "$loc/w:pPr/w:ind"; |
| 114 | + self::assertTrue($doc->elementExists($ind)); |
| 115 | + self::assertSame('2160', $doc->getElementAttribute($ind, 'w:left')); |
| 116 | + self::assertSame('360', $doc->getElementAttribute($ind, 'w:hanging')); |
| 117 | + $fonts = "$loc/w:rPr/w:rFonts"; |
| 118 | + self::assertTrue($doc->elementExists($fonts)); |
| 119 | + self::assertSame('Wingdings', $doc->getElementAttribute($fonts, 'w:ascii')); |
| 120 | + } |
| 121 | +} |
0 commit comments