PHPWord/tests/PhpWordTests/Metadata/SettingsTest.php

229 lines
6.4 KiB
PHP
Raw Normal View History

<?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
*
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
2022-09-16 14:09:17 +02:00
namespace PhpOffice\PhpWordTests\Metadata;
2022-09-16 11:45:45 +02:00
use InvalidArgumentException;
use PhpOffice\PhpWord\ComplexType\ProofState;
2022-09-16 14:09:17 +02:00
use PhpOffice\PhpWord\Metadata\Protection;
use PhpOffice\PhpWord\Metadata\Settings;
use PhpOffice\PhpWord\SimpleType\Zoom;
/**
2022-09-16 11:45:45 +02:00
* Test class for PhpOffice\PhpWord\Metadata\Settings.
*
* @runTestsInSeparateProcesses
*/
class SettingsTest extends \PHPUnit\Framework\TestCase
{
/**
2022-09-16 11:45:45 +02:00
* EvenAndOddHeaders.
*/
2022-09-16 11:45:45 +02:00
public function testSetEvenAndOddHeaders(): void
{
$oSettings = new Settings();
$oSettings->setEvenAndOddHeaders(true);
2022-09-16 11:45:45 +02:00
self::assertTrue($oSettings->hasEvenAndOddHeaders());
}
/**
2022-09-16 11:45:45 +02:00
* HideGrammaticalErrors.
*/
2022-09-16 11:45:45 +02:00
public function testHideGrammaticalErrors(): void
{
$oSettings = new Settings();
$oSettings->setHideGrammaticalErrors(true);
2022-09-16 11:45:45 +02:00
self::assertTrue($oSettings->hasHideGrammaticalErrors());
}
/**
2022-09-16 11:45:45 +02:00
* HideSpellingErrors.
*/
2022-09-16 11:45:45 +02:00
public function testHideSpellingErrors(): void
{
$oSettings = new Settings();
$oSettings->setHideSpellingErrors(true);
2022-09-16 11:45:45 +02:00
self::assertTrue($oSettings->hasHideSpellingErrors());
}
/**
2022-09-16 11:45:45 +02:00
* DocumentProtection.
*/
2022-09-16 11:45:45 +02:00
public function testDocumentProtection(): void
{
$oSettings = new Settings();
$oSettings->setDocumentProtection(new Protection('trackedChanges'));
2022-09-16 11:45:45 +02:00
self::assertNotNull($oSettings->getDocumentProtection());
2022-09-16 11:45:45 +02:00
self::assertEquals('trackedChanges', $oSettings->getDocumentProtection()->getEditing());
}
/**
2022-09-16 11:45:45 +02:00
* Test setting an invalid salt.
*/
2022-09-16 11:45:45 +02:00
public function testInvalidSalt(): void
{
2022-09-16 11:45:45 +02:00
$this->expectException(InvalidArgumentException::class);
2017-11-24 14:45:05 +01:00
$protection = new Protection();
$protection->setSalt('123');
}
/**
2022-09-16 11:45:45 +02:00
* TrackRevistions.
*/
2022-09-16 11:45:45 +02:00
public function testTrackRevisions(): void
{
$oSettings = new Settings();
$oSettings->setTrackRevisions(true);
2022-09-16 11:45:45 +02:00
self::assertTrue($oSettings->hasTrackRevisions());
}
/**
2022-09-16 11:45:45 +02:00
* DoNotTrackFormatting.
*/
2022-09-16 11:45:45 +02:00
public function testDoNotTrackFormatting(): void
{
$oSettings = new Settings();
$oSettings->setDoNotTrackFormatting(true);
2022-09-16 11:45:45 +02:00
self::assertTrue($oSettings->hasDoNotTrackFormatting());
}
/**
2022-09-16 11:45:45 +02:00
* DoNotTrackMoves.
*/
2022-09-16 11:45:45 +02:00
public function testDoNotTrackMoves(): void
{
$oSettings = new Settings();
$oSettings->setDoNotTrackMoves(true);
2022-09-16 11:45:45 +02:00
self::assertTrue($oSettings->hasDoNotTrackMoves());
}
/**
2022-09-16 11:45:45 +02:00
* ProofState.
*/
2022-09-16 11:45:45 +02:00
public function testProofState(): void
{
$proofState = new ProofState();
$proofState->setGrammar(ProofState::CLEAN);
$proofState->setSpelling(ProofState::DIRTY);
$oSettings = new Settings();
$oSettings->setProofState($proofState);
2022-09-16 11:45:45 +02:00
self::assertNotNull($oSettings->getProofState());
self::assertEquals(ProofState::CLEAN, $oSettings->getProofState()->getGrammar());
self::assertEquals(ProofState::DIRTY, $oSettings->getProofState()->getSpelling());
}
2022-09-16 11:45:45 +02:00
public function testWrongProofStateGrammar(): void
{
2022-09-16 11:45:45 +02:00
$this->expectException(InvalidArgumentException::class);
$proofState = new ProofState();
$proofState->setGrammar('wrong');
}
2022-09-16 11:45:45 +02:00
public function testWrongProofStateSpelling(): void
{
2022-09-16 11:45:45 +02:00
$this->expectException(InvalidArgumentException::class);
$proofState = new ProofState();
$proofState->setSpelling('wrong');
}
/**
2022-09-16 11:45:45 +02:00
* Zoom as percentage.
*/
2022-09-16 11:45:45 +02:00
public function testZoomPercentage(): void
{
$oSettings = new Settings();
$oSettings->setZoom(75);
2022-09-16 11:45:45 +02:00
self::assertEquals(75, $oSettings->getZoom());
}
/**
2022-09-16 11:45:45 +02:00
* Zoom as string.
*/
2022-09-16 11:45:45 +02:00
public function testZoomEnum(): void
{
$oSettings = new Settings();
$oSettings->setZoom(Zoom::FULL_PAGE);
2022-09-16 11:45:45 +02:00
self::assertEquals('fullPage', $oSettings->getZoom());
}
/**
2022-09-16 11:45:45 +02:00
* Test Update Fields on update.
*/
2022-09-16 11:45:45 +02:00
public function testUpdateFields(): void
{
$oSettings = new Settings();
$oSettings->setUpdateFields(true);
2022-09-16 11:45:45 +02:00
self::assertTrue($oSettings->hasUpdateFields());
}
2022-09-16 11:45:45 +02:00
public function testAutoHyphenation(): void
{
$oSettings = new Settings();
$oSettings->setAutoHyphenation(true);
2022-09-16 11:45:45 +02:00
self::assertTrue($oSettings->hasAutoHyphenation());
}
2022-09-16 11:45:45 +02:00
public function testDefaultAutoHyphenation(): void
{
$oSettings = new Settings();
2022-09-16 11:45:45 +02:00
self::assertNull($oSettings->hasAutoHyphenation());
}
2022-09-16 11:45:45 +02:00
public function testConsecutiveHyphenLimit(): void
{
$consecutiveHypenLimit = 2;
$oSettings = new Settings();
$oSettings->setConsecutiveHyphenLimit($consecutiveHypenLimit);
2022-09-16 11:45:45 +02:00
self::assertSame($consecutiveHypenLimit, $oSettings->getConsecutiveHyphenLimit());
}
2022-09-16 11:45:45 +02:00
public function testDefaultConsecutiveHyphenLimit(): void
{
$oSettings = new Settings();
2022-09-16 11:45:45 +02:00
self::assertNull($oSettings->getConsecutiveHyphenLimit());
}
2022-09-16 11:45:45 +02:00
public function testHyphenationZone(): void
{
$hyphenationZoneInTwip = 100;
$oSettings = new Settings();
$oSettings->setHyphenationZone($hyphenationZoneInTwip);
2022-09-16 11:45:45 +02:00
self::assertSame($hyphenationZoneInTwip, $oSettings->getHyphenationZone());
}
2022-09-16 11:45:45 +02:00
public function testDefaultHyphenationZone(): void
{
$oSettings = new Settings();
2022-09-16 11:45:45 +02:00
self::assertNull($oSettings->getHyphenationZone());
}
2022-09-16 11:45:45 +02:00
public function testDoNotHyphenateCaps(): void
{
$oSettings = new Settings();
$oSettings->setDoNotHyphenateCaps(true);
2022-09-16 11:45:45 +02:00
self::assertTrue($oSettings->hasDoNotHyphenateCaps());
}
2022-09-16 11:45:45 +02:00
public function testDefaultDoNotHyphenateCaps(): void
{
$oSettings = new Settings();
2022-09-16 11:45:45 +02:00
self::assertNull($oSettings->hasDoNotHyphenateCaps());
}
}