|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * This file is part of PHPWord - A pure PHP library for reading and writing |
| 4 | + * word processing documents. |
| 5 | + * |
| 6 | + * PHPWord is free software distributed under the terms of the GNU Lesser |
| 7 | + * General Public License version 3 as published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * For the full copyright and license information, please read the LICENSE |
| 10 | + * file that was distributed with this source code. For the full list of |
| 11 | + * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. |
| 12 | + * |
| 13 | + * @see https://github.com/PHPOffice/PHPWord |
| 14 | + * @copyright 2010-2018 PHPWord contributors |
| 15 | + * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
| 16 | + */ |
| 17 | + |
| 18 | +namespace PhpOffice\PhpWord\Reader; |
| 19 | + |
| 20 | +use DateTime; |
| 21 | +use PhpOffice\PhpWord\Element\Comment; |
| 22 | +use PhpOffice\PhpWord\IOFactory; |
| 23 | +use PhpOffice\PhpWord\TestHelperDOCX; |
| 24 | + |
| 25 | +/** |
| 26 | + * Test class for PhpOffice\PhpWord\Reader\Word2007 |
| 27 | + * |
| 28 | + * @coversDefaultClass \PhpOffice\PhpWord\Reader\Word2007 |
| 29 | + * @runTestsInSeparateProcesses |
| 30 | + */ |
| 31 | +class Word2007Test extends \PHPUnit\Framework\TestCase |
| 32 | +{ |
| 33 | + /** |
| 34 | + * Test canRead() method |
| 35 | + */ |
| 36 | + public function testCanRead() |
| 37 | + { |
| 38 | + $object = new Word2007(); |
| 39 | + $filename = __DIR__ . '/../_files/documents/reader.docx'; |
| 40 | + $this->assertTrue($object->canRead($filename)); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Can read exception |
| 45 | + */ |
| 46 | + public function testCanReadFailed() |
| 47 | + { |
| 48 | + $object = new Word2007(); |
| 49 | + $filename = __DIR__ . '/../_files/documents/foo.docx'; |
| 50 | + $this->assertFalse($object->canRead($filename)); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Load |
| 55 | + */ |
| 56 | + public function testLoad() |
| 57 | + { |
| 58 | + $filename = __DIR__ . '/../_files/documents/reader.docx'; |
| 59 | + $phpWord = IOFactory::load($filename); |
| 60 | + |
| 61 | + $this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $phpWord); |
| 62 | + $this->assertTrue($phpWord->getSettings()->hasDoNotTrackMoves()); |
| 63 | + $this->assertFalse($phpWord->getSettings()->hasDoNotTrackFormatting()); |
| 64 | + $this->assertEquals(100, $phpWord->getSettings()->getZoom()); |
| 65 | + |
| 66 | + $doc = TestHelperDOCX::getDocument($phpWord); |
| 67 | + $this->assertEquals('0', $doc->getElementAttribute('/w:document/w:body/w:p/w:r[w:t/node()="italics"]/w:rPr/w:b', 'w:val')); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Load a Word 2011 file |
| 72 | + */ |
| 73 | + public function testLoadWord2011() |
| 74 | + { |
| 75 | + $filename = __DIR__ . '/../_files/documents/reader-2011.docx'; |
| 76 | + $phpWord = IOFactory::load($filename); |
| 77 | + |
| 78 | + $this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $phpWord); |
| 79 | + |
| 80 | + $doc = TestHelperDOCX::getDocument($phpWord); |
| 81 | + $this->assertTrue($doc->elementExists('/w:document/w:body/w:p[3]/w:r/w:pict/v:shape/v:imagedata')); |
| 82 | + } |
| 83 | + |
| 84 | + public function testLoadComments() |
| 85 | + { |
| 86 | + $filename = __DIR__ . '/../_files/documents/reader-ooxml-comments.docx'; |
| 87 | + $phpWord = IOFactory::load($filename); |
| 88 | + |
| 89 | + $this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $phpWord); |
| 90 | + |
| 91 | + //$doc = TestHelperDOCX::getDocument($phpWord); |
| 92 | + $comment = new Comment('shaedrich', new DateTime('2021-10-28T13:56:00Z'), 'SH'); |
| 93 | + $comment2 = $phpWord->getComments()[0]; |
| 94 | + $this->assertEquals($comment->getAuthor(), $comment2->getAuthor()); |
| 95 | + $this->assertEquals($comment->getInitials(), $comment2->getInitials()); |
| 96 | + } |
| 97 | +} |
0 commit comments