PHPWord/tests/PhpWordTests/Reader/Word2007Test.php

84 lines
2.6 KiB
PHP
Raw Normal View History

<?php
2014-03-27 23:55:06 +07:00
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
2014-03-27 23:55:06 +07:00
*
* @see https://github.com/PHPOffice/PHPWord
2022-09-16 11:45:45 +02:00
*
2014-05-04 21:03:28 +04:00
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
2014-03-27 23:55:06 +07:00
*/
2022-09-16 14:09:17 +02:00
namespace PhpOffice\PhpWordTests\Reader;
use PhpOffice\PhpWord\IOFactory;
2022-09-16 14:09:17 +02:00
use PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\PhpWordTests\TestHelperDOCX;
2014-03-27 23:55:06 +07:00
/**
2022-09-16 11:45:45 +02:00
* Test class for PhpOffice\PhpWord\Reader\Word2007.
2014-03-27 23:55:06 +07:00
*
* @coversDefaultClass \PhpOffice\PhpWord\Reader\Word2007
2022-09-16 11:45:45 +02:00
*
2014-03-27 23:55:06 +07:00
* @runTestsInSeparateProcesses
*/
class Word2007Test extends \PHPUnit\Framework\TestCase
{
/**
2022-09-16 11:45:45 +02:00
* Test canRead() method.
*/
2022-09-16 11:45:45 +02:00
public function testCanRead(): void
{
$object = new Word2007();
$filename = __DIR__ . '/../_files/documents/reader.docx';
2022-09-16 11:45:45 +02:00
self::assertTrue($object->canRead($filename));
}
/**
2022-09-16 11:45:45 +02:00
* Can read exception.
*/
2022-09-16 11:45:45 +02:00
public function testCanReadFailed(): void
{
$object = new Word2007();
$filename = __DIR__ . '/../_files/documents/foo.docx';
2022-09-16 11:45:45 +02:00
self::assertFalse($object->canRead($filename));
}
2014-03-30 14:15:23 +07:00
/**
2022-09-16 11:45:45 +02:00
* Load.
2014-03-30 14:15:23 +07:00
*/
2022-09-16 11:45:45 +02:00
public function testLoad(): void
{
$filename = __DIR__ . '/../_files/documents/reader.docx';
$phpWord = IOFactory::load($filename);
2022-09-16 11:45:45 +02:00
self::assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $phpWord);
self::assertTrue($phpWord->getSettings()->hasDoNotTrackMoves());
self::assertFalse($phpWord->getSettings()->hasDoNotTrackFormatting());
self::assertEquals(100, $phpWord->getSettings()->getZoom());
$doc = TestHelperDOCX::getDocument($phpWord);
2022-09-16 11:45:45 +02:00
self::assertEquals('0', $doc->getElementAttribute('/w:document/w:body/w:p/w:r[w:t/node()="italics"]/w:rPr/w:b', 'w:val'));
}
2018-03-25 22:46:50 +02:00
/**
2022-09-16 11:45:45 +02:00
* Load a Word 2011 file.
2018-03-25 22:46:50 +02:00
*/
2022-09-16 11:45:45 +02:00
public function testLoadWord2011(): void
2018-03-25 22:46:50 +02:00
{
$filename = __DIR__ . '/../_files/documents/reader-2011.docx';
$phpWord = IOFactory::load($filename);
2022-09-16 11:45:45 +02:00
self::assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $phpWord);
2018-03-25 22:46:50 +02:00
$doc = TestHelperDOCX::getDocument($phpWord);
2022-09-16 11:45:45 +02:00
self::assertTrue($doc->elementExists('/w:document/w:body/w:p[3]/w:r/w:pict/v:shape/v:imagedata'));
2018-03-25 22:46:50 +02:00
}
}