95 lines
3.3 KiB
PHP
Raw Normal View History

2017-11-10 23:37:02 +01:00
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
2022-09-16 11:45:45 +02:00
*
2017-11-10 23:37:02 +01:00
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
2022-09-16 14:09:17 +02:00
namespace PhpOffice\PhpWordTests\Writer\Word2007\Style;
2017-11-10 23:37:02 +01:00
use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle;
2022-09-16 14:09:17 +02:00
use PhpOffice\PhpWordTests\TestHelperDOCX;
2017-11-10 23:37:02 +01:00
/**
2022-09-16 11:45:45 +02:00
* Test class for PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph.
2017-11-10 23:37:02 +01:00
*
* @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph
2022-09-16 11:45:45 +02:00
*
2017-11-10 23:37:02 +01:00
* @runTestsInSeparateProcesses
*/
class ParagraphTest extends \PHPUnit\Framework\TestCase
{
/**
2022-09-16 11:45:45 +02:00
* Executed before each method of the class.
2017-11-10 23:37:02 +01:00
*/
2022-09-16 11:45:45 +02:00
protected function tearDown(): void
2017-11-10 23:37:02 +01:00
{
TestHelperDOCX::clear();
}
/**
2022-09-16 11:45:45 +02:00
* Test write styles.
2017-11-10 23:37:02 +01:00
*/
2022-09-16 11:45:45 +02:00
public function testParagraphNumbering(): void
2017-11-10 23:37:02 +01:00
{
$phpWord = new \PhpOffice\PhpWord\PhpWord();
2022-09-16 11:45:45 +02:00
$phpWord->addParagraphStyle('testStyle', ['indent' => '10']);
2017-11-10 23:37:02 +01:00
$section = $phpWord->addSection();
2022-09-16 11:45:45 +02:00
$section->addText('test', null, ['numStyle' => 'testStyle', 'numLevel' => '1']);
2017-11-10 23:37:02 +01:00
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
$path = '/w:document/w:body/w:p/w:pPr/w:numPr/w:ilvl';
2022-09-16 11:45:45 +02:00
self::assertTrue($doc->elementExists($path));
2017-11-10 23:37:02 +01:00
}
2022-09-16 11:45:45 +02:00
public function testLineSpacingExact(): void
{
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
2022-09-16 11:45:45 +02:00
$section->addText('test', null, ['spacing' => 240, 'spacingLineRule' => 'exact']);
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
$path = '/w:document/w:body/w:p/w:pPr/w:spacing';
2022-09-16 11:45:45 +02:00
self::assertTrue($doc->elementExists($path));
self::assertEquals('exact', $doc->getElementAttribute($path, 'w:lineRule'));
self::assertEquals('240', $doc->getElementAttribute($path, 'w:line'));
}
2022-09-16 11:45:45 +02:00
public function testLineSpacingAuto(): void
{
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
2022-09-16 11:45:45 +02:00
$section->addText('test', null, ['spacing' => 240, 'spacingLineRule' => 'auto']);
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
$path = '/w:document/w:body/w:p/w:pPr/w:spacing';
2022-09-16 11:45:45 +02:00
self::assertTrue($doc->elementExists($path));
self::assertEquals('auto', $doc->getElementAttribute($path, 'w:lineRule'));
self::assertEquals('480', $doc->getElementAttribute($path, 'w:line'));
}
2022-09-16 11:45:45 +02:00
public function testSuppressAutoHyphens(): void
{
$paragraphStyle = new ParagraphStyle();
$paragraphStyle->setSuppressAutoHyphens(true);
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->addText('test', null, $paragraphStyle);
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
$path = '/w:document/w:body/w:p/w:pPr/w:suppressAutoHyphens';
2022-09-16 11:45:45 +02:00
self::assertTrue($doc->elementExists($path));
}
2017-11-10 23:37:02 +01:00
}