PHPWord/tests/PhpWordTests/Style/SectionTest.php

350 lines
11 KiB
PHP
Raw Normal View History

2014-03-09 19:09:22 +01:00
<?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\Style;
2014-03-09 19:09:22 +01:00
2019-02-05 21:42:14 +01:00
use PhpOffice\PhpWord\SimpleType\VerticalJc;
2022-09-16 14:09:17 +02:00
use PhpOffice\PhpWord\Style\Section;
2019-02-05 21:42:14 +01:00
2014-03-27 23:55:06 +07:00
/**
2022-09-16 11:45:45 +02:00
* Test class for PhpOffice\PhpWord\Style\Section.
2014-03-27 23:55:06 +07:00
*
* @coversDefaultClass \PhpOffice\PhpWord\Element\Section
2022-09-16 11:45:45 +02:00
*
2014-03-27 23:55:06 +07:00
* @runTestsInSeparateProcesses
*/
class SectionTest extends \PHPUnit\Framework\TestCase
2014-03-09 15:04:23 -04:00
{
/**
2022-09-16 11:45:45 +02:00
* Executed before each method of the class.
2014-03-09 15:04:23 -04:00
*/
2022-09-16 11:45:45 +02:00
public function testSettingValue(): void
2014-03-09 15:04:23 -04:00
{
$oSettings = new Section();
2014-03-09 15:04:23 -04:00
2022-09-16 11:45:45 +02:00
self::assertEquals('portrait', $oSettings->getOrientation());
self::assertEqualsWithDelta(Section::DEFAULT_WIDTH, $oSettings->getPageSizeW(), 0.000000001);
self::assertEqualsWithDelta(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeH(), 0.000000001);
self::assertEquals('A4', $oSettings->getPaperSize());
$oSettings->setSettingValue('orientation', 'landscape');
2022-09-16 11:45:45 +02:00
self::assertEquals('landscape', $oSettings->getOrientation());
self::assertEqualsWithDelta(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeW(), 0.000000001);
self::assertEqualsWithDelta(Section::DEFAULT_WIDTH, $oSettings->getPageSizeH(), 0.000000001);
2014-03-09 15:04:23 -04:00
2022-09-16 11:45:45 +02:00
$iVal = mt_rand(1, 1000);
$oSettings->setSettingValue('borderSize', $iVal);
2022-09-16 11:45:45 +02:00
self::assertEquals([$iVal, $iVal, $iVal, $iVal], $oSettings->getBorderSize());
self::assertEquals($iVal, $oSettings->getBorderBottomSize());
self::assertEquals($iVal, $oSettings->getBorderLeftSize());
self::assertEquals($iVal, $oSettings->getBorderRightSize());
self::assertEquals($iVal, $oSettings->getBorderTopSize());
2014-03-09 15:04:23 -04:00
$oSettings->setSettingValue('borderColor', 'FF00AA');
2022-09-16 11:45:45 +02:00
self::assertEquals(['FF00AA', 'FF00AA', 'FF00AA', 'FF00AA'], $oSettings->getBorderColor());
self::assertEquals('FF00AA', $oSettings->getBorderBottomColor());
self::assertEquals('FF00AA', $oSettings->getBorderLeftColor());
self::assertEquals('FF00AA', $oSettings->getBorderRightColor());
self::assertEquals('FF00AA', $oSettings->getBorderTopColor());
2014-03-09 15:04:23 -04:00
2022-09-16 11:45:45 +02:00
$iVal = mt_rand(1, 1000);
2014-03-09 15:04:23 -04:00
$oSettings->setSettingValue('headerHeight', $iVal);
2022-09-16 11:45:45 +02:00
self::assertEquals($iVal, $oSettings->getHeaderHeight());
2022-09-16 11:45:45 +02:00
$oSettings->setSettingValue('lineNumbering', []);
$oSettings->setSettingValue(
'lineNumbering',
2022-09-16 11:45:45 +02:00
[
'start' => 1,
'increment' => 1,
2022-09-16 11:45:45 +02:00
'distance' => 240,
'restart' => 'newPage',
]
);
2022-09-16 11:45:45 +02:00
self::assertInstanceOf('PhpOffice\\PhpWord\\Style\\LineNumbering', $oSettings->getLineNumbering());
$oSettings->setSettingValue('lineNumbering', null);
2022-09-16 11:45:45 +02:00
self::assertNull($oSettings->getLineNumbering());
2014-03-09 15:04:23 -04:00
}
2014-03-30 14:15:23 +07:00
/**
2022-09-16 11:45:45 +02:00
* Set/get margin.
2014-03-30 14:15:23 +07:00
*/
2022-09-16 11:45:45 +02:00
public function testMargin(): void
2014-03-09 15:04:23 -04:00
{
// Section Settings
$oSettings = new Section();
2014-03-09 15:04:23 -04:00
2022-09-16 11:45:45 +02:00
$iVal = mt_rand(1, 1000);
2014-03-09 15:04:23 -04:00
$oSettings->setMarginTop($iVal);
2022-09-16 11:45:45 +02:00
self::assertEquals($iVal, $oSettings->getMarginTop());
2014-03-09 15:04:23 -04:00
2022-09-16 11:45:45 +02:00
$iVal = mt_rand(1, 1000);
2014-03-09 15:04:23 -04:00
$oSettings->setMarginBottom($iVal);
2022-09-16 11:45:45 +02:00
self::assertEquals($iVal, $oSettings->getMarginBottom());
2014-03-09 15:04:23 -04:00
2022-09-16 11:45:45 +02:00
$iVal = mt_rand(1, 1000);
2014-03-09 15:04:23 -04:00
$oSettings->setMarginLeft($iVal);
2022-09-16 11:45:45 +02:00
self::assertEquals($iVal, $oSettings->getMarginLeft());
2014-03-09 15:04:23 -04:00
2022-09-16 11:45:45 +02:00
$iVal = mt_rand(1, 1000);
2014-03-09 15:04:23 -04:00
$oSettings->setMarginRight($iVal);
2022-09-16 11:45:45 +02:00
self::assertEquals($iVal, $oSettings->getMarginRight());
2014-03-09 15:04:23 -04:00
}
2014-10-02 08:33:53 -06:00
/**
2022-09-16 11:45:45 +02:00
* Set/get page width.
2014-10-02 08:33:53 -06:00
*/
2022-09-16 11:45:45 +02:00
public function testPageWidth(): void
2014-10-02 08:33:53 -06:00
{
// Section Settings
$oSettings = new Section();
2022-09-16 11:45:45 +02:00
self::assertEqualsWithDelta(Section::DEFAULT_WIDTH, $oSettings->getPageSizeW(), 0.000000001);
$iVal = mt_rand(1, 1000);
2014-10-02 08:33:53 -06:00
$oSettings->setSettingValue('pageSizeW', $iVal);
2022-09-16 11:45:45 +02:00
self::assertEquals($iVal, $oSettings->getPageSizeW());
2014-10-02 08:33:53 -06:00
}
/**
2022-09-16 11:45:45 +02:00
* Set/get page height.
2014-10-02 08:33:53 -06:00
*/
2022-09-16 11:45:45 +02:00
public function testPageHeight(): void
2014-10-02 08:33:53 -06:00
{
// Section Settings
$oSettings = new Section();
2022-09-16 11:45:45 +02:00
self::assertEqualsWithDelta(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeH(), 0.000000001);
$iVal = mt_rand(1, 1000);
2014-10-02 08:33:53 -06:00
$oSettings->setSettingValue('pageSizeH', $iVal);
2022-09-16 11:45:45 +02:00
self::assertEquals($iVal, $oSettings->getPageSizeH());
2014-10-02 08:33:53 -06:00
}
2014-03-30 14:15:23 +07:00
/**
2022-09-16 11:45:45 +02:00
* Set/get landscape orientation.
2014-03-30 14:15:23 +07:00
*/
2022-09-16 11:45:45 +02:00
public function testOrientationLandscape(): void
2014-03-09 15:04:23 -04:00
{
// Section Settings
$oSettings = new Section();
2014-03-09 15:04:23 -04:00
$oSettings->setLandscape();
2022-09-16 11:45:45 +02:00
self::assertEquals('landscape', $oSettings->getOrientation());
self::assertEqualsWithDelta(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeW(), 0.000000001);
self::assertEqualsWithDelta(Section::DEFAULT_WIDTH, $oSettings->getPageSizeH(), 0.000000001);
2014-03-09 15:04:23 -04:00
}
2014-03-30 14:15:23 +07:00
/**
2022-09-16 11:45:45 +02:00
* Set/get portrait orientation.
2014-03-30 14:15:23 +07:00
*/
2022-09-16 11:45:45 +02:00
public function testOrientationPortrait(): void
2014-03-09 15:04:23 -04:00
{
// Section Settings
$oSettings = new Section();
2014-03-09 15:04:23 -04:00
$oSettings->setPortrait();
2022-09-16 11:45:45 +02:00
self::assertEquals('portrait', $oSettings->getOrientation());
self::assertEqualsWithDelta(Section::DEFAULT_WIDTH, $oSettings->getPageSizeW(), 0.000000001);
self::assertEqualsWithDelta(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeH(), 0.000000001);
2014-03-09 15:04:23 -04:00
}
2014-03-30 14:15:23 +07:00
/**
2022-09-16 11:45:45 +02:00
* Set/get border size.
2014-03-30 14:15:23 +07:00
*/
2022-09-16 11:45:45 +02:00
public function testBorderSize(): void
2014-03-09 15:04:23 -04:00
{
// Section Settings
$oSettings = new Section();
2014-03-09 15:04:23 -04:00
2022-09-16 11:45:45 +02:00
$iVal = mt_rand(1, 1000);
2014-03-09 15:04:23 -04:00
$oSettings->setBorderSize($iVal);
2022-09-16 11:45:45 +02:00
self::assertEquals([$iVal, $iVal, $iVal, $iVal], $oSettings->getBorderSize());
self::assertEquals($iVal, $oSettings->getBorderBottomSize());
self::assertEquals($iVal, $oSettings->getBorderLeftSize());
self::assertEquals($iVal, $oSettings->getBorderRightSize());
self::assertEquals($iVal, $oSettings->getBorderTopSize());
2014-03-09 15:04:23 -04:00
2022-09-16 11:45:45 +02:00
$iVal = mt_rand(1, 1000);
2014-03-09 15:04:23 -04:00
$oSettings->setBorderBottomSize($iVal);
2022-09-16 11:45:45 +02:00
self::assertEquals($iVal, $oSettings->getBorderBottomSize());
2014-03-09 15:04:23 -04:00
2022-09-16 11:45:45 +02:00
$iVal = mt_rand(1, 1000);
2014-03-09 15:04:23 -04:00
$oSettings->setBorderLeftSize($iVal);
2022-09-16 11:45:45 +02:00
self::assertEquals($iVal, $oSettings->getBorderLeftSize());
2014-03-09 15:04:23 -04:00
2022-09-16 11:45:45 +02:00
$iVal = mt_rand(1, 1000);
2014-03-09 15:04:23 -04:00
$oSettings->setBorderRightSize($iVal);
2022-09-16 11:45:45 +02:00
self::assertEquals($iVal, $oSettings->getBorderRightSize());
2014-03-09 15:04:23 -04:00
2022-09-16 11:45:45 +02:00
$iVal = mt_rand(1, 1000);
2014-03-09 15:04:23 -04:00
$oSettings->setBorderTopSize($iVal);
2022-09-16 11:45:45 +02:00
self::assertEquals($iVal, $oSettings->getBorderTopSize());
2014-03-09 15:04:23 -04:00
}
2014-03-30 14:15:23 +07:00
/**
2022-09-16 11:45:45 +02:00
* Set/get border color.
2014-03-30 14:15:23 +07:00
*/
2022-09-16 11:45:45 +02:00
public function testBorderColor(): void
2014-03-09 15:04:23 -04:00
{
// Section Settings
$oSettings = new Section();
2014-03-09 15:04:23 -04:00
$oSettings->setBorderColor('FF00AA');
2022-09-16 11:45:45 +02:00
self::assertEquals(['FF00AA', 'FF00AA', 'FF00AA', 'FF00AA'], $oSettings->getBorderColor());
self::assertEquals('FF00AA', $oSettings->getBorderBottomColor());
self::assertEquals('FF00AA', $oSettings->getBorderLeftColor());
self::assertEquals('FF00AA', $oSettings->getBorderRightColor());
self::assertEquals('FF00AA', $oSettings->getBorderTopColor());
2014-03-09 15:04:23 -04:00
$oSettings->setBorderBottomColor('BBCCDD');
2022-09-16 11:45:45 +02:00
self::assertEquals('BBCCDD', $oSettings->getBorderBottomColor());
2014-03-09 15:04:23 -04:00
$oSettings->setBorderLeftColor('CCDDEE');
2022-09-16 11:45:45 +02:00
self::assertEquals('CCDDEE', $oSettings->getBorderLeftColor());
2014-03-09 15:04:23 -04:00
$oSettings->setBorderRightColor('11EE22');
2022-09-16 11:45:45 +02:00
self::assertEquals('11EE22', $oSettings->getBorderRightColor());
2014-03-09 15:04:23 -04:00
$oSettings->setBorderTopColor('22FF33');
2022-09-16 11:45:45 +02:00
self::assertEquals('22FF33', $oSettings->getBorderTopColor());
2014-03-09 15:04:23 -04:00
}
2014-03-30 14:15:23 +07:00
/**
2022-09-16 11:45:45 +02:00
* Set/get page numbering start.
2014-03-30 14:15:23 +07:00
*/
2022-09-16 11:45:45 +02:00
public function testNumberingStart(): void
2014-03-09 15:04:23 -04:00
{
// Section Settings
$oSettings = new Section();
2014-03-09 15:04:23 -04:00
2022-09-16 11:45:45 +02:00
self::assertNull($oSettings->getPageNumberingStart());
2014-03-09 15:04:23 -04:00
2022-09-16 11:45:45 +02:00
$iVal = mt_rand(1, 1000);
2014-03-09 15:04:23 -04:00
$oSettings->setPageNumberingStart($iVal);
2022-09-16 11:45:45 +02:00
self::assertEquals($iVal, $oSettings->getPageNumberingStart());
2014-03-09 15:04:23 -04:00
$oSettings->setPageNumberingStart();
2022-09-16 11:45:45 +02:00
self::assertNull($oSettings->getPageNumberingStart());
2014-03-09 15:04:23 -04:00
}
2014-03-30 14:15:23 +07:00
/**
2022-09-16 11:45:45 +02:00
* Set/get header height.
2014-03-30 14:15:23 +07:00
*/
2022-09-16 11:45:45 +02:00
public function testHeader(): void
2014-03-09 15:04:23 -04:00
{
$oSettings = new Section();
2014-03-09 15:04:23 -04:00
2022-09-16 11:45:45 +02:00
self::assertEquals(720, $oSettings->getHeaderHeight());
2014-03-09 15:04:23 -04:00
2022-09-16 11:45:45 +02:00
$iVal = mt_rand(1, 1000);
2014-03-09 15:04:23 -04:00
$oSettings->setHeaderHeight($iVal);
2022-09-16 11:45:45 +02:00
self::assertEquals($iVal, $oSettings->getHeaderHeight());
2014-03-09 15:04:23 -04:00
$oSettings->setHeaderHeight();
2022-09-16 11:45:45 +02:00
self::assertEquals(720, $oSettings->getHeaderHeight());
2014-03-09 15:04:23 -04:00
}
2014-03-30 14:15:23 +07:00
/**
2022-09-16 11:45:45 +02:00
* Set/get footer height.
2014-03-30 14:15:23 +07:00
*/
2022-09-16 11:45:45 +02:00
public function testFooter(): void
2014-03-09 15:04:23 -04:00
{
// Section Settings
$oSettings = new Section();
2014-03-09 15:04:23 -04:00
2022-09-16 11:45:45 +02:00
self::assertEquals(720, $oSettings->getFooterHeight());
2014-03-09 15:04:23 -04:00
2022-09-16 11:45:45 +02:00
$iVal = mt_rand(1, 1000);
2014-03-09 15:04:23 -04:00
$oSettings->setFooterHeight($iVal);
2022-09-16 11:45:45 +02:00
self::assertEquals($iVal, $oSettings->getFooterHeight());
2014-03-09 15:04:23 -04:00
$oSettings->setFooterHeight();
2022-09-16 11:45:45 +02:00
self::assertEquals(720, $oSettings->getFooterHeight());
2014-03-09 15:04:23 -04:00
}
2014-03-09 19:09:22 +01:00
2014-03-30 14:15:23 +07:00
/**
2022-09-16 11:45:45 +02:00
* Set/get column number.
2014-03-30 14:15:23 +07:00
*/
2022-09-16 11:45:45 +02:00
public function testColumnsNum(): void
2014-03-09 15:04:23 -04:00
{
// Section Settings
$oSettings = new Section();
2014-03-09 19:09:22 +01:00
2014-03-09 15:04:23 -04:00
// Default
2022-09-16 11:45:45 +02:00
self::assertEquals(1, $oSettings->getColsNum());
2014-03-09 19:09:22 +01:00
2014-05-08 19:25:29 +07:00
// Null value
$oSettings->setColsNum();
2022-09-16 11:45:45 +02:00
self::assertEquals(1, $oSettings->getColsNum());
2014-05-08 19:25:29 +07:00
// Random value
2022-09-16 11:45:45 +02:00
$iVal = mt_rand(1, 1000);
2014-03-09 15:04:23 -04:00
$oSettings->setColsNum($iVal);
2022-09-16 11:45:45 +02:00
self::assertEquals($iVal, $oSettings->getColsNum());
2014-03-09 15:04:23 -04:00
}
2014-03-09 19:09:22 +01:00
2014-03-30 14:15:23 +07:00
/**
2022-09-16 11:45:45 +02:00
* Set/get column spacing.
2014-03-30 14:15:23 +07:00
*/
2022-09-16 11:45:45 +02:00
public function testColumnsSpace(): void
2014-03-09 15:04:23 -04:00
{
// Section Settings
$oSettings = new Section();
2014-03-09 19:09:22 +01:00
2014-03-09 15:04:23 -04:00
// Default
2022-09-16 11:45:45 +02:00
self::assertEquals(720, $oSettings->getColsSpace());
2014-03-09 19:09:22 +01:00
2022-09-16 11:45:45 +02:00
$iVal = mt_rand(1, 1000);
self::assertInstanceOf('PhpOffice\\PhpWord\\Style\\Section', $oSettings->setColsSpace($iVal));
self::assertEquals($iVal, $oSettings->getColsSpace());
2014-03-09 19:09:22 +01:00
2022-09-16 11:45:45 +02:00
self::assertInstanceOf('PhpOffice\\PhpWord\\Style\\Section', $oSettings->setColsSpace());
self::assertEquals(720, $oSettings->getColsSpace());
2014-03-09 15:04:23 -04:00
}
2014-03-09 19:09:22 +01:00
2014-03-30 14:15:23 +07:00
/**
2022-09-16 11:45:45 +02:00
* Set/get break type.
2014-03-30 14:15:23 +07:00
*/
2022-09-16 11:45:45 +02:00
public function testBreakType(): void
2014-03-09 15:04:23 -04:00
{
// Section Settings
$oSettings = new Section();
2014-03-09 19:09:22 +01:00
2022-09-16 11:45:45 +02:00
self::assertNull($oSettings->getBreakType());
2014-03-09 19:09:22 +01:00
2014-03-09 15:04:23 -04:00
$oSettings->setBreakType('continuous');
2022-09-16 11:45:45 +02:00
self::assertEquals('continuous', $oSettings->getBreakType());
2014-03-09 19:09:22 +01:00
2014-03-09 15:04:23 -04:00
$oSettings->setBreakType();
2022-09-16 11:45:45 +02:00
self::assertNull($oSettings->getBreakType());
2014-03-09 15:04:23 -04:00
}
2019-02-05 21:42:14 +01:00
/**
2022-09-16 11:45:45 +02:00
* Vertical page alignment.
2019-02-05 21:42:14 +01:00
*/
2022-09-16 11:45:45 +02:00
public function testVerticalAlign(): void
2019-02-05 21:42:14 +01:00
{
// Section Settings
$oSettings = new Section();
2022-09-16 11:45:45 +02:00
self::assertNull($oSettings->getVAlign());
2019-02-05 21:42:14 +01:00
$oSettings->setVAlign(VerticalJc::BOTH);
2022-09-16 11:45:45 +02:00
self::assertEquals('both', $oSettings->getVAlign());
2019-02-05 21:42:14 +01:00
}
}