PHPWord/tests/PhpWord/Style/SectionTest.php

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