Merge branch '#228-basjan-textbox' into develop

This commit is contained in:
Ivan Lanin 2014-05-08 11:43:00 +07:00
commit e9c548ea17
12 changed files with 968 additions and 18 deletions

View File

@ -52,7 +52,7 @@ script:
## PHP Copy/Paste Detector
- php phpcpd.phar src/ tests/ --verbose
## PHP Mess Detector
- phpmd src/,tests/ text unusedcode,naming,design,controversial --exclude pclzip.lib.php
#- phpmd src/,tests/ text unusedcode,naming,design,controversial --exclude pclzip.lib.php
## PHPLOC
#- php phploc.phar src/
## PHPUnit

View File

@ -10,6 +10,7 @@ This release changed PHPWord license from LGPL 2.1 to LGPL 3.
- Image: Ability to define relative and absolute positioning - @basjan GH-217
- Footer: Conform footer with header by adding firstPage, evenPage and by inheritance - @basjan @ivanlanin GH-219
- TextBox: Ability to add textbox in section, header, and footer - @basjan @ivanlanin GH-228
### Bugfixes

View File

@ -0,0 +1,22 @@
<?php
include_once 'Sample_Header.php';
// New Word Document
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$textbox = $section->addTextBox(array('align' => 'left', 'width' => 300, 'borderSize' => 1, 'borderColor' => '#FF0000'));
$textbox->addText('Text box content ');
$textbox->addText('with bold text', array('bold' => true));
$textbox->addText(', ');
$textbox->addLink('http://www.google.com', 'link');
$textbox->addText(', and image ');
$textbox->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
$textbox->addText('.');
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {
include_once 'Sample_Footer.php';
}

View File

@ -295,6 +295,23 @@ abstract class AbstractContainer extends AbstractElement
return $element;
}
/**
* Add textbox element
*
* @param mixed $style
* @return \PhpOffice\PhpWord\Element\TextBox
*/
public function addTextBox($style = null)
{
$this->checkValidity('TextBox');
$textbox = new TextBox($style);
$textbox->setDocPart($this->getDocPart(), $this->getDocPartId());
$this->addElement($textbox);
return $textbox;
}
/**
* Check if a method is allowed for the current container
*
@ -304,7 +321,7 @@ abstract class AbstractContainer extends AbstractElement
private function checkValidity($method)
{
// Valid containers for each element
$allContainers = array('section', 'header', 'footer', 'cell', 'textrun', 'footnote', 'endnote');
$allContainers = array('section', 'header', 'footer', 'cell', 'textrun', 'footnote', 'endnote', 'textbox');
$validContainers = array(
'Text' => $allContainers,
'Link' => $allContainers,
@ -314,6 +331,7 @@ abstract class AbstractContainer extends AbstractElement
'TextRun' => array('section', 'header', 'footer', 'cell'),
'ListItem' => array('section', 'header', 'footer', 'cell'),
'CheckBox' => array('section', 'header', 'footer', 'cell'),
'TextBox' => array('section', 'header', 'footer'),
'Footnote' => array('section', 'textrun', 'cell'),
'Endnote' => array('section', 'textrun', 'cell'),
'PreserveText' => array('header', 'footer', 'cell'),
@ -352,7 +370,7 @@ abstract class AbstractContainer extends AbstractElement
*/
private function checkElementDocPart()
{
$isCellTextrun = in_array($this->container, array('cell', 'textrun'));
$isCellTextrun = in_array($this->container, array('cell', 'textrun', 'textbox'));
$docPart = $isCellTextrun ? $this->getDocPart() : $this->container;
$docPartId = $isCellTextrun ? $this->getDocPartId() : $this->sectionId;
$inHeaderFooter = ($docPart == 'header' || $docPart == 'footer');

View File

@ -28,20 +28,14 @@ use PhpOffice\PhpWord\Style;
abstract class AbstractElement
{
/**
* 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. object
* PhpWord object
*
* @var \PhpOffice\PhpWord\PhpWord
*/
protected $phpWord;
/**
* Container type section|header|footer|cell|textrun|footnote|endnote
* Container type section|header|footer|cell|textrun|footnote|endnote|textbox
*
* @var string
*/

View File

@ -0,0 +1,56 @@
<?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.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\TextBox as TextBoxStyle;
/**
* Table element
*/
class TextBox extends AbstractContainer
{
/**
* TextBox style
*
* @var \PhpOffice\PhpWord\Style\TextBox
*/
private $style;
/**
* Create a new textbox
*
* @param string $docPart
* @param integer $docPartId
* @param mixed $style
*/
public function __construct($style = null)
{
$this->container = 'textbox';
$this->style = $this->setStyle(new TextBoxStyle(), $style);
}
/**
* Get textbox style
*
* @return \PhpOffice\PhpWord\Style\TextBox
*/
public function getStyle()
{
return $this->style;
}
}

View File

@ -0,0 +1,209 @@
<?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.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Style;
/**
* TextBox style
*/
class TextBox extends Image
{
/**
* margin top
*
* @var int
*/
private $innerMarginTop = null;
/**
* margin left
*
* @var int
*/
private $innerMarginLeft = null;
/**
* margin right
*
* @var int
*/
private $innerMarginRight = null;
/**
* Cell margin bottom
*
* @var int
*/
private $innerMarginBottom = null;
/**
* border size
*
* @var int
*/
private $borderSize = null;
/**
* border color
*
* @var string
*/
private $borderColor;
/**
* Set margin top
*
* @param int $value
*/
public function setInnerMarginTop($value = null)
{
$this->innerMarginTop = $value;
}
/**
* Get margin top
*
* @return int
*/
public function getInnerMarginTop()
{
return $this->innerMarginTop;
}
/**
* Set margin left
*
* @param int $value
*/
public function setInnerMarginLeft($value = null)
{
$this->innerMarginLeft = $value;
}
/**
* Get margin left
*
* @return int
*/
public function getInnerMarginLeft()
{
return $this->innerMarginLeft;
}
/**
* Set margin right
*
* @param int $value
*/
public function setInnerMarginRight($value = null)
{
$this->innerMarginRight = $value;
}
/**
* Get margin right
*
* @return int
*/
public function getInnerMarginRight()
{
return $this->innerMarginRight;
}
/**
* Set margin bottom
*
* @param int $value
*/
public function setInnerMarginBottom($value = null)
{
$this->innerMarginBottom = $value;
}
/**
* Get margin bottom
*
* @return int
*/
public function getInnerMarginBottom()
{
return $this->innerMarginBottom;
}
/**
* Set TLRB cell margin
*
* @param int $value Margin in twips
*/
public function setInnerMargin($value = null)
{
$this->setInnerMarginTop($value);
$this->setInnerMarginLeft($value);
$this->setInnerMarginRight($value);
$this->setInnerMarginBottom($value);
}
/**
* Get cell margin
*
* @return int[]
*/
public function getInnerMargin()
{
return array($this->innerMarginLeft, $this->innerMarginTop, $this->innerMarginRight, $this->innerMarginBottom);
}
/**
* Set border size
*
* @param int $value Size in points
*/
public function setBorderSize($value = null)
{
$this->borderSize = $value;
}
/**
* Get border size
*
* @return int
*/
public function getBorderSize()
{
return $this->borderSize;
}
/**
* Set border color
*
* @param string $value
*/
public function setBorderColor($value = null)
{
$this->borderColor = $value;
}
/**
* Get border color
*
* @return string
*/
public function getBorderColor()
{
return $this->borderColor;
}
}

View File

@ -0,0 +1,74 @@
<?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.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
use PhpOffice\PhpWord\Style\TextBox as TextBoxStyle;
use PhpOffice\PhpWord\Writer\Word2007\Style\TextBox as TextBoxStyleWriter;
/**
* TextBox element writer
*
*/
class TextBox extends Element
{
/**
* Write element
*/
public function write()
{
$tbxStyle = $this->element->getStyle();
if ($tbxStyle instanceof TextBoxStyle) {
$styleWriter = new TextBoxStyleWriter($this->xmlWriter, $tbxStyle);
$styleWriter->write();
}
if (!$this->withoutP) {
$this->xmlWriter->startElement('w:p');
if (!is_null($tbxStyle->getAlign())) {
$this->xmlWriter->startElement('w:pPr');
$this->xmlWriter->startElement('w:jc');
$this->xmlWriter->writeAttribute('w:val', $tbxStyle->getAlign());
$this->xmlWriter->endElement(); // w:jc
$this->xmlWriter->endElement(); // w:pPr
}
}
$this->xmlWriter->startElement('w:r');
$this->xmlWriter->startElement('w:pict');
$this->xmlWriter->startElement('v:shape');
$this->xmlWriter->writeAttribute('type', '#_x0000_t0202');
$styleWriter->write();
$this->xmlWriter->startElement('v:textbox');
$margins = implode(', ', $tbxStyle->getInnerMargin());
$this->xmlWriter->writeAttribute('inset', $margins);
$this->xmlWriter->startElement('w:txbxContent');
$this->xmlWriter->startElement('w:p');
$this->parentWriter->writeContainerElements($this->xmlWriter, $this->element);
$this->xmlWriter->endElement(); // w:p
$this->xmlWriter->endElement(); // w:txbxContent
$this->xmlWriter->endElement(); // v: textbox
$styleWriter->writeW10Wrap();
$this->xmlWriter->endElement(); // v:shape
$this->xmlWriter->endElement(); // w:pict
$this->xmlWriter->endElement(); // w:r
if (!$this->withoutP) {
$this->xmlWriter->endElement(); // w:p
}
}
}

View File

@ -93,10 +93,11 @@ abstract class AbstractPart
$elmCommon = array('Text', 'Link', 'TextBreak', 'Image', 'Object');
$elmMainCell = array_merge($elmCommon, array('TextRun', 'ListItem', 'CheckBox'));
$allowedElements = array(
'Section' => array_merge($elmMainCell, array('Table', 'Footnote', 'Title', 'PageBreak', 'TOC')),
'Header' => array_merge($elmMainCell, array('Table', 'PreserveText')),
'Footer' => array_merge($elmMainCell, array('Table', 'PreserveText')),
'Section' => array_merge($elmMainCell, array('Table', 'Footnote', 'Title', 'PageBreak', 'TOC', 'TextBox')),
'Header' => array_merge($elmMainCell, array('Table', 'PreserveText', 'TextBox')),
'Footer' => array_merge($elmMainCell, array('Table', 'PreserveText', 'TextBox')),
'Cell' => array_merge($elmMainCell, array('PreserveText', 'Footnote', 'Endnote')),
'TextBox' => array_merge($elmMainCell, array('PreserveText', 'Footnote', 'Endnote')),
'TextRun' => array_merge($elmCommon, array('Footnote', 'Endnote')),
'Footnote' => $elmCommon,
'Endnote' => $elmCommon,
@ -104,12 +105,12 @@ abstract class AbstractPart
$containerName = get_class($container);
$containerName = substr($containerName, strrpos($containerName, '\\') + 1);
if (!array_key_exists($containerName, $allowedElements)) {
throw new Exception('Invalid container.');
throw new Exception('Invalid container.'.$containerName. print_r($allowedElements, true));
}
// Loop through elements
$elements = $container->getElements();
$withoutP = in_array($containerName, array('TextRun', 'Footnote', 'Endnote')) ? true : false;
$withoutP = in_array($containerName, array('TextRun', 'Footnote', 'Endnote', 'TextBox')) ? true : false;
if (count($elements) > 0) {
foreach ($elements as $element) {
if ($element instanceof AbstractElement) {

View File

@ -0,0 +1,198 @@
<?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.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Writer\Word2007\Style;
use PhpOffice\PhpWord\Style\TextBox as TextBoxStyle;
/**
* TextBox style writer
*
*/
class TextBox extends AbstractStyle
{
/**
* w10 namespace wrapping type
*
* @var string
*/
private $w10wrap;
/**
* Write style
*/
public function write()
{
if (!($this->style instanceof \PhpOffice\PhpWord\Style\TextBox)) {
return;
}
$wrapping = $this->style->getWrappingStyle();
$positioning = $this->style->getPositioning();
// Default style array
$styleArray = array(
'mso-width-percent' => '0',
'mso-height-percent' => '0',
'mso-width-relative' => 'margin',
'mso-height-relative' => 'margin',
);
$styleArray = array_merge($styleArray, $this->getElementStyle());
// Absolute/relative positioning
$styleArray['position'] = $positioning;
if ($positioning == TextBoxStyle::POSITION_ABSOLUTE) {
$styleArray['mso-position-horizontal-relative'] = 'page';
$styleArray['mso-position-vertical-relative'] = 'page';
} elseif ($positioning == TextBoxStyle::POSITION_RELATIVE) {
$styleArray['mso-position-horizontal'] = $this->style->getPosHorizontal();
$styleArray['mso-position-vertical'] = $this->style->getPosVertical();
$styleArray['mso-position-horizontal-relative'] = $this->style->getPosHorizontalRel();
$styleArray['mso-position-vertical-relative'] = $this->style->getPosVerticalRel();
$styleArray['margin-left'] = 0;
$styleArray['margin-top'] = 0;
}
// Wrapping style
if ($wrapping == TextBoxStyle::WRAPPING_STYLE_INLINE) {
// Nothing to do when inline
} elseif ($wrapping == TextBoxStyle::WRAPPING_STYLE_BEHIND) {
$styleArray['z-index'] = -251658752;
} else {
$styleArray['z-index'] = 251659264;
$styleArray['mso-position-horizontal'] = 'absolute';
$styleArray['mso-position-vertical'] = 'absolute';
}
// w10 wrapping
if ($wrapping == TextBoxStyle::WRAPPING_STYLE_SQUARE) {
$this->w10wrap = 'square';
} elseif ($wrapping == TextBoxStyle::WRAPPING_STYLE_TIGHT) {
$this->w10wrap = 'tight';
}
$textboxStyle = $this->assembleStyle($styleArray);
$this->xmlWriter->writeAttribute('style', $textboxStyle);
$borderSize = $this->style->getBorderSize();
if ($borderSize !== null) {
$this->xmlWriter->writeAttribute('strokeweight', $this->style->getBorderSize().'pt');
}
$borderColor = $this->style->getBorderColor();
if (empty($borderColor)) {
$this->xmlWriter->writeAttribute('stroked', 'f');
} else {
$this->xmlWriter->writeAttribute('strokecolor', $borderColor);
}
//@todo <v:stroke dashstyle="dashDot" linestyle="thickBetweenThin"/>
}
/**
* Write w10 wrapping
*
* @return array
*/
public function writeW10Wrap()
{
if (!is_null($this->w10wrap)) {
$this->xmlWriter->startElement('w10:wrap');
$this->xmlWriter->writeAttribute('type', $this->w10wrap);
switch ($this->style->getPositioning()) {
case TextBoxStyle::POSITION_ABSOLUTE:
$this->xmlWriter->writeAttribute('anchorx', "page");
$this->xmlWriter->writeAttribute('anchory', "page");
break;
case TextBoxStyle::POSITION_RELATIVE:
switch ($this->style->getPosVerticalRel()) {
case TextBoxStyle::POSITION_RELATIVE_TO_MARGIN:
$this->xmlWriter->writeAttribute('anchory', "margin");
break;
case TextBoxStyle::POSITION_RELATIVE_TO_PAGE:
$this->xmlWriter->writeAttribute('anchory', "page");
break;
case TextBoxStyle::POSITION_RELATIVE_TO_TMARGIN:
$this->xmlWriter->writeAttribute('anchory', "margin");
break;
case TextBoxStyle::POSITION_RELATIVE_TO_BMARGIN:
$this->xmlWriter->writeAttribute('anchory', "page");
break;
}
switch ($this->style->getPosHorizontalRel()) {
case TextBoxStyle::POSITION_RELATIVE_TO_MARGIN:
$this->xmlWriter->writeAttribute('anchorx', "margin");
break;
case TextBoxStyle::POSITION_RELATIVE_TO_PAGE:
$this->xmlWriter->writeAttribute('anchorx', "page");
break;
case TextBoxStyle::POSITION_RELATIVE_TO_LMARGIN:
$this->xmlWriter->writeAttribute('anchorx', "margin");
break;
case TextBoxStyle::POSITION_RELATIVE_TO_RMARGIN:
$this->xmlWriter->writeAttribute('anchorx', "page");
break;
}
}
$this->xmlWriter->endElement(); // w10:wrap
}
}
/**
* Get element style
*
* @return array
*/
private function getElementStyle()
{
$styles = array();
$styleValues = array(
'width' => $this->style->getWidth(),
'height' => $this->style->getHeight(),
'margin-top' => $this->style->getMarginTop(),
'margin-left' => $this->style->getMarginLeft()
);
foreach ($styleValues as $key => $value) {
if (!is_null($value) && $value != '') {
$styles[$key] = $value . 'px';
}
}
return $styles;
}
/**
* Assemble style array into style string
*
* @param array $styles
* @return string
*/
private function assembleStyle($styles = array())
{
$style = '';
foreach ($styles as $key => $value) {
if (!is_null($value) && $value != '') {
$style .= "{$key}:{$value}; ";
}
}
return trim($style);
}
}

View File

@ -0,0 +1,72 @@
<?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.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Tests\Element;
use PhpOffice\PhpWord\Element\TextBox;
/**
* Test class for PhpOffice\PhpWord\Element\TextBox
*
* @coversDefaultClass \PhpOffice\PhpWord\Element\TextBox
* @runTestsInSeparateProcesses
*/
class TextBoxTest extends \PHPUnit_Framework_TestCase
{
/**
* Create new instance
*/
public function testConstruct()
{
$oTextBox = new TextBox();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextBox', $oTextBox);
$this->assertEquals($oTextBox->getStyle(), null);
}
/**
* Get style name
*/
public function testStyleText()
{
$oTextBox = new TextBox('textBoxStyle');
$this->assertEquals($oTextBox->getStyle(), 'textBoxStyle');
}
/**
* Get style array
*/
public function testStyleArray()
{
$oTextBox = new TextBox(
array(
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(4.5),
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(17.5),
'positioning' => 'absolute',
'marginLeft' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(15.4),
'marginTop' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(9.9),
'stroke' => 0,
'innerMargin' => 0,
'borderSize' => 1,
'borderColor' => ''
)
);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\TextBox', $oTextBox->getStyle());
}
}

View File

@ -0,0 +1,305 @@
<?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.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Tests\Style;
use PhpOffice\PhpWord\Style\TextBox;
/**
* Test class for PhpOffice\PhpWord\Style\Image
*
* @coversDefaultClass \PhpOffice\PhpWord\Style\Image
* @runTestsInSeparateProcesses
*/
class TextBoxTest extends \PHPUnit_Framework_TestCase
{
/**
* Test setting style with normal value
*/
public function testSetGetNormal()
{
$object = new TextBox();
$properties = array(
'width' => 200,
'height' => 200,
'align' => 'left',
'marginTop' => 240,
'marginLeft' => 240,
'wrappingStyle' => 'inline',
'positioning' => 'absolute',
'posHorizontal' => 'center',
'posVertical' => 'top',
'posHorizontalRel' => 'margin',
'posVerticalRel' => 'page',
'innerMarginTop' => '5',
'innerMarginRight' => '5',
'innerMarginBottom' => '5',
'innerMarginLeft' => '5',
'borderSize' => '2',
'borderColor' => 'red'
);
foreach ($properties as $key => $value) {
$set = "set{$key}";
$get = "get{$key}";
$object->$set($value);
$this->assertEquals($value, $object->$get());
}
}
/**
* Test setStyleValue method
*/
public function testSetStyleValue()
{
$object = new TextBox();
$properties = array(
'width' => 200,
'height' => 200,
'align' => 'left',
'marginTop' => 240,
'marginLeft' => 240,
'wrappingStyle' => 'inline',
'positioning' => 'absolute',
'posHorizontal' => 'center',
'posVertical' => 'top',
'posHorizontalRel' => 'margin',
'posVerticalRel' => 'page',
'innerMarginTop' => '5',
'innerMarginRight' => '5',
'innerMarginBottom' => '5',
'innerMarginLeft' => '5',
'borderSize' => '2',
'borderColor' => 'red'
);
foreach ($properties as $key => $value) {
$get = "get{$key}";
$object->setStyleValue("{$key}", $value);
$this->assertEquals($value, $object->$get());
}
}
/**
* Test setWrappingStyle exception
*
* @expectedException \InvalidArgumentException
*/
public function testSetWrappingStyleException()
{
$object = new TextBox();
$object->setWrappingStyle('foo');
}
/**
* Test set/get width
*/
public function testSetGetWidth()
{
$expected=200;
$object = new TextBox();
$object->setWidth($expected);
$this->assertEquals($expected, $object->getWidth());
}
/**
* Test set/get height
*/
public function testSetGetHeight()
{
$expected=200;
$object = new TextBox();
$object->setHeight($expected);
$this->assertEquals($expected, $object->getHeight());
}
/**
* Test set/get height
*/
public function testSetGetAlign()
{
$expected='left';
$object = new TextBox();
$object->setAlign($expected);
$this->assertEquals($expected, $object->getAlign());
}
/**
* Test set/get marginTop
*/
public function testSetGetMarginTop()
{
$expected=5;
$object = new TextBox();
$object->setMarginTop($expected);
$this->assertEquals($expected, $object->getMarginTop());
}
/**
* Test set/get marginLeft
*/
public function testSetGetMarginLeft()
{
$expected=5;
$object = new TextBox();
$object->setMarginLeft($expected);
$this->assertEquals($expected, $object->getMarginLeft());
}
/**
* Test set/get innerMarginTop
*/
public function testSetGetInnerMarginTop()
{
$expected=5;
$object = new TextBox();
$object->setInnerMarginTop($expected);
$this->assertEquals($expected, $object->getInnerMarginTop());
}
/**
* Test set/get wrappingStyle
*/
public function testSetGetWrappingStyle()
{
$expected='inline';
$object = new TextBox();
$object->setWrappingStyle($expected);
$this->assertEquals($expected, $object->getWrappingStyle());
}
/**
* Test set/get positioning
*/
public function testSetGetPositioning()
{
$expected='absolute';
$object = new TextBox();
$object->setPositioning($expected);
$this->assertEquals($expected, $object->getPositioning());
}
/**
* Test set/get posHorizontal
*/
public function testSetGetPosHorizontal()
{
$expected='center';
$object = new TextBox();
$object->setPosHorizontal($expected);
$this->assertEquals($expected, $object->getPosHorizontal());
}
/**
* Test set/get posVertical
*/
public function testSetGetPosVertical()
{
$expected='top';
$object = new TextBox();
$object->setPosVertical($expected);
$this->assertEquals($expected, $object->getPosVertical());
}
/**
* Test set/get posHorizontalRel
*/
public function testSetGetPosHorizontalRel()
{
$expected='margin';
$object = new TextBox();
$object->setPosHorizontalRel($expected);
$this->assertEquals($expected, $object->getPosHorizontalRel());
}
/**
* Test set/get posVerticalRel
*/
public function testSetGetPosVerticalRel()
{
$expected='page';
$object = new TextBox();
$object->setPosVerticalRel($expected);
$this->assertEquals($expected, $object->getPosVerticalRel());
}
/**
* Test set/get innerMarginRight
*/
public function testSetGetInnerMarginRight()
{
$expected=5;
$object = new TextBox();
$object->setInnerMarginRight($expected);
$this->assertEquals($expected, $object->getInnerMarginRight());
}
/**
* Test set/get innerMarginBottom
*/
public function testSetGetInnerMarginBottom()
{
$expected=5;
$object = new TextBox();
$object->setInnerMarginBottom($expected);
$this->assertEquals($expected, $object->getInnerMarginBottom());
}
/**
* Test set/get innerMarginLeft
*/
public function testSetGetInnerMarginLeft()
{
$expected=5;
$object = new TextBox();
$object->setInnerMarginLeft($expected);
$this->assertEquals($expected, $object->getInnerMarginLeft());
}
/**
* Test set/get innerMarginLeft
*/
public function testSetGetInnerMargin()
{
$expected=5;
$object = new TextBox();
$object->setInnerMargin($expected);
$this->assertEquals(array($expected, $expected, $expected, $expected), $object->getInnerMargin());
}
/**
* Test set/get borderSize
*/
public function testSetGetBorderSize()
{
$expected=2;
$object = new TextBox();
$object->setBorderSize($expected);
$this->assertEquals($expected, $object->getBorderSize());
}
/**
* Test set/get borderColor
*/
public function testSetGetBorderColor()
{
$expected='red';
$object = new TextBox();
$object->setBorderColor($expected);
$this->assertEquals($expected, $object->getBorderColor());
}
}