PHPWord/tests/PhpWord/Tests/Section/SettingsTest.php

236 lines
8.0 KiB
PHP
Raw Normal View History

2014-03-09 19:09:22 +01:00
<?php
namespace PhpOffice\PhpWord\Tests\Section;
2014-03-09 19:09:22 +01:00
use PhpOffice\PhpWord\Section\Settings;
2014-03-09 19:09:22 +01:00
2014-03-09 15:04:23 -04:00
class SettingsTest extends \PHPUnit_Framework_TestCase
{
/**
* Executed before each method of the class
*/
public function testSettingValue()
{
// Section Settings
$oSettings = new Settings();
2014-03-09 15:04:23 -04:00
$oSettings->setSettingValue('_orientation', 'landscape');
2014-03-09 15:24:13 -04:00
$this->assertEquals('landscape', $oSettings->getOrientation());
$this->assertEquals(16838, $oSettings->getPageSizeW());
$this->assertEquals(11906, $oSettings->getPageSizeH());
2014-03-09 15:04:23 -04:00
$oSettings->setSettingValue('_orientation', null);
2014-03-09 15:24:13 -04:00
$this->assertNull($oSettings->getOrientation());
$this->assertEquals(11906, $oSettings->getPageSizeW());
$this->assertEquals(16838, $oSettings->getPageSizeH());
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());
2014-03-09 15:04:23 -04:00
}
public function testMargin()
{
// Section Settings
$oSettings = new Settings();
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
}
public function testOrientationLandscape()
{
// Section Settings
$oSettings = new Settings();
2014-03-09 15:04:23 -04:00
$oSettings->setLandscape();
2014-03-09 15:24:13 -04:00
$this->assertEquals('landscape', $oSettings->getOrientation());
$this->assertEquals(16838, $oSettings->getPageSizeW());
$this->assertEquals(11906, $oSettings->getPageSizeH());
2014-03-09 15:04:23 -04:00
}
public function testOrientationPortrait()
{
// Section Settings
$oSettings = new Settings();
2014-03-09 15:04:23 -04:00
$oSettings->setPortrait();
2014-03-09 15:24:13 -04:00
$this->assertNull($oSettings->getOrientation());
$this->assertEquals(11906, $oSettings->getPageSizeW());
$this->assertEquals(16838, $oSettings->getPageSizeH());
2014-03-09 15:04:23 -04:00
}
public function testBorderSize()
{
// Section Settings
$oSettings = new Settings();
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
}
public function testBorderColor()
{
// Section Settings
$oSettings = new Settings();
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
}
public function testNumberingStart()
{
// Section Settings
$oSettings = new Settings();
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
}
public function testHeader()
{
// Section Settings
$oSettings = new Settings();
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
}
public function testFooter()
{
// Section Settings
$oSettings = new Settings();
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-09 15:04:23 -04:00
public function testColumnsNum()
{
// Section Settings
$oSettings = new Settings();
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-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 19:09:22 +01:00
2014-03-09 15:04:23 -04:00
$oSettings->setColsNum();
2014-03-09 15:24:13 -04:00
$this->assertEquals(1, $oSettings->getColsNum());
2014-03-09 15:04:23 -04:00
}
2014-03-09 19:09:22 +01:00
2014-03-09 15:04:23 -04:00
public function testColumnsSpace()
{
// Section Settings
$oSettings = new Settings();
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\\Section\\Settings', $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\\Section\\Settings', $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-09 15:04:23 -04:00
public function testBreakType()
{
// Section Settings
$oSettings = new Settings();
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
}
}