diff --git a/src/PhpWord/Element/AbstractContainer.php b/src/PhpWord/Element/AbstractContainer.php index 4ac6c22b..920843b7 100644 --- a/src/PhpWord/Element/AbstractContainer.php +++ b/src/PhpWord/Element/AbstractContainer.php @@ -304,7 +304,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, diff --git a/src/PhpWord/Element/AbstractElement.php b/src/PhpWord/Element/AbstractElement.php index 3cb699e6..5ed5209f 100644 --- a/src/PhpWord/Element/AbstractElement.php +++ b/src/PhpWord/Element/AbstractElement.php @@ -27,21 +27,11 @@ 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 - */ + protected $phpWord; /** - * Container type section|header|footer|cell|textrun|footnote|endnote + * Container type section|header|footer|cell|textrun|footnote|endnote|textbox * * @var string */ diff --git a/src/PhpWord/Element/Footer.php b/src/PhpWord/Element/Footer.php index 2f23a3d3..0e5a1975 100644 --- a/src/PhpWord/Element/Footer.php +++ b/src/PhpWord/Element/Footer.php @@ -115,6 +115,21 @@ class Footer extends AbstractContainer return $this->type = self::EVEN; } + /** + * Add textbox element + * + * @param mixed $style + * @return \PhpOffice\PhpWord\Element\TextBox + * @todo Merge with the same function on Section + */ + public function addTextBox($style = null) + { + $textbox = new TextBox($this->getDocPart(), $this->getDocPartId(), $style); + $this->addElement($textbox); + + return $textbox; + } + /** * Add table element * diff --git a/src/PhpWord/Element/Section.php b/src/PhpWord/Element/Section.php index 1ccdccc8..3183a6cb 100644 --- a/src/PhpWord/Element/Section.php +++ b/src/PhpWord/Element/Section.php @@ -117,6 +117,21 @@ class Section extends AbstractContainer $this->addElement(new PageBreak()); } + /** + * Add textbox element + * + * @param mixed $style + * @return \PhpOffice\PhpWord\Element\TextBox + * @todo Merge with the same function on Footer + */ + public function addTextBox($style = null) + { + $textbox = new TextBox($this->getDocPart(), $this->getDocPartId(), $style); + $this->addElement($textbox); + + return $textbox; + } + /** * Add table element * diff --git a/src/PhpWord/Element/TextBox.php b/src/PhpWord/Element/TextBox.php new file mode 100644 index 00000000..4cf7b906 --- /dev/null +++ b/src/PhpWord/Element/TextBox.php @@ -0,0 +1,57 @@ +container = 'textbox'; + $this->setDocPart($docPart, $docPartId); + $this->style = $this->setStyle(new TextBoxStyle(), $style); + } + + /** + * Get textbox style + * + * @return \PhpOffice\PhpWord\Style\TextBox + */ + public function getStyle() + { + return $this->style; + } +} \ No newline at end of file diff --git a/src/PhpWord/Style/TextBox.php b/src/PhpWord/Style/TextBox.php new file mode 100644 index 00000000..7e83da6a --- /dev/null +++ b/src/PhpWord/Style/TextBox.php @@ -0,0 +1,641 @@ +setWrappingStyle(self::WRAPPING_STYLE_INLINE); + $this->setPosHorizontal(self::POSITION_HORIZONTAL_LEFT); + $this->setPosHorizontalRel(self::POSITION_RELATIVE_TO_CHAR); + $this->setPosVertical(self::POSITION_VERTICAL_TOP); + $this->setPosVerticalRel(self::POSITION_RELATIVE_TO_LINE); + } + + /** + * Get width + */ + public function getWidth() + { + return $this->width; + } + + /** + * Set width + * + * @param int $value + */ + public function setWidth($value = null) + { + $this->width = $value; + } + + /** + * Get height + */ + public function getHeight() + { + return $this->height; + } + + /** + * Set height + * + * @param int $value + */ + public function setHeight($value = null) + { + $this->height = $value; + } + + /** + * Get alignment + */ + public function getAlign() + { + return $this->align; + } + + /** + * Set alignment + * + * @param string $value + */ + public function setAlign($value = null) + { + $this->align = $value; + } + + /** + * Get Margin Top + * + * @return int + */ + public function getMarginTop() + { + return $this->marginTop; + } + + /** + * Set Margin Top + * + * @param int $value + * @return self + */ + public function setMarginTop($value = null) + { + $this->marginTop = $value; + return $this; + } + + /** + * Get Margin Left + * + * @return int + */ + public function getMarginLeft() + { + return $this->marginLeft; + } + + /** + * Set Margin Left + * + * @param int $value + * @return self + */ + public function setMarginLeft($value = null) + { + $this->marginLeft = $value; + return $this; + } + + /** + * Get wrapping style + * + * @return string + */ + public function getWrappingStyle() + { + return $this->wrappingStyle; + } + + /** + * Set wrapping style + * + * @param string $wrappingStyle + * @throws \InvalidArgumentException + * @return self + */ + public function setWrappingStyle($wrappingStyle) + { + $enum = array(self::WRAPPING_STYLE_INLINE, self::WRAPPING_STYLE_INFRONT, self::WRAPPING_STYLE_BEHIND, + self::WRAPPING_STYLE_SQUARE, self::WRAPPING_STYLE_TIGHT); + + if (in_array($wrappingStyle, $enum)) { + $this->wrappingStyle = $wrappingStyle; + } else { + throw new \InvalidArgumentException('Invalid wrapping style.'); + } + + return $this; + } + + /** + * Get positioning type + * + * @return string + */ + public function getPositioning() + { + return $this->positioning; + } + + /** + * Set positioning type + * + * @param string $positioning + * @throws \InvalidArgumentException + * @return self + */ + public function setPositioning($positioning) + { + $enum = array(self::POSITION_RELATIVE, self::POSITION_ABSOLUTE); + + if (in_array($positioning, $enum)) { + $this->positioning = $positioning; + } else { + throw new \InvalidArgumentException('Invalid positioning.'); + } + + return $this; + } + + /** + * Get horizontal alignment + * + * @return string + */ + public function getPosHorizontal() + { + return $this->posHorizontal; + } + + /** + * Set horizontal alignment + * + * @param string $alignment + * @throws \InvalidArgumentException + * @return self + */ + public function setPosHorizontal($alignment) + { + $enum = array(self::POSITION_HORIZONTAL_LEFT, self::POSITION_HORIZONTAL_CENTER, + self::POSITION_HORIZONTAL_RIGHT); + + if (in_array($alignment, $enum)) { + $this->posHorizontal = $alignment; + } else { + throw new \InvalidArgumentException('Invalid horizontal alignment.'); + } + + return $this; + } + + /** + * Get vertical alignment + * + * @return string + */ + public function getPosVertical() + { + return $this->posVertical; + } + + /** + * Set vertical alignment + * + * @param string $alignment + * @throws \InvalidArgumentException + * @return self + */ + public function setPosVertical($alignment) + { + $enum = array(self::POSITION_VERTICAL_TOP, self::POSITION_VERTICAL_CENTER, + self::POSITION_VERTICAL_BOTTOM, self::POSITION_VERTICAL_INSIDE, self::POSITION_VERTICAL_OUTSIDE); + + if (in_array($alignment, $enum)) { + $this->posVertical = $alignment; + } else { + throw new \InvalidArgumentException('Invalid vertical alignment.'); + } + + return $this; + } + + /** + * Get horizontal relation + * + * @return string + */ + public function getPosHorizontalRel() + { + return $this->posHorizontalRel; + } + + /** + * Set horizontal relation + * + * @param string $relto + * @throws \InvalidArgumentException + * @return self + */ + public function setPosHorizontalRel($relto) + { + $enum = array(self::POSITION_RELATIVE_TO_MARGIN, self::POSITION_RELATIVE_TO_PAGE, + self::POSITION_RELATIVE_TO_COLUMN, self::POSITION_RELATIVE_TO_CHAR, + self::POSITION_RELATIVE_TO_LMARGIN, self::POSITION_RELATIVE_TO_RMARGIN, + self::POSITION_RELATIVE_TO_IMARGIN, self::POSITION_RELATIVE_TO_OMARGIN); + + if (in_array($relto, $enum)) { + $this->posHorizontalRel = $relto; + } else { + throw new \InvalidArgumentException('Invalid relative horizontal alignment.'); + } + + return $this; + } + + /** + * Get vertical relation + * + * @return string + */ + public function getPosVerticalRel() + { + return $this->posVerticalRel; + } + + /** + * Set vertical relation + * + * @param string $relto + * @throws \InvalidArgumentException + * @return self + */ + public function setPosVerticalRel($relto) + { + $enum = array(self::POSITION_RELATIVE_TO_MARGIN, self::POSITION_RELATIVE_TO_PAGE, + self::POSITION_RELATIVE_TO_LINE, + self::POSITION_RELATIVE_TO_TMARGIN, self::POSITION_RELATIVE_TO_BMARGIN, + self::POSITION_RELATIVE_TO_IMARGIN, self::POSITION_RELATIVE_TO_OMARGIN); + + if (in_array($relto, $enum)) { + $this->posVerticalRel = $relto; + } else { + throw new \InvalidArgumentException('Invalid relative vertical alignment.'); + } + + return $this; + } + /** + * 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; + } +} \ No newline at end of file diff --git a/src/PhpWord/Writer/Word2007/Element/TextBox.php b/src/PhpWord/Writer/Word2007/Element/TextBox.php new file mode 100644 index 00000000..812d2218 --- /dev/null +++ b/src/PhpWord/Writer/Word2007/Element/TextBox.php @@ -0,0 +1,72 @@ +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->parentWriter->writeContainerElements($this->xmlWriter, $this->element); + $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 + } + } +} \ No newline at end of file diff --git a/src/PhpWord/Writer/Word2007/Part/AbstractPart.php b/src/PhpWord/Writer/Word2007/Part/AbstractPart.php index 141dd33a..84310752 100644 --- a/src/PhpWord/Writer/Word2007/Part/AbstractPart.php +++ b/src/PhpWord/Writer/Word2007/Part/AbstractPart.php @@ -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,7 +105,7 @@ 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 diff --git a/src/PhpWord/Writer/Word2007/Style/TextBox.php b/src/PhpWord/Writer/Word2007/Style/TextBox.php new file mode 100644 index 00000000..6720279e --- /dev/null +++ b/src/PhpWord/Writer/Word2007/Style/TextBox.php @@ -0,0 +1,198 @@ +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 + + } + + /** + * 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); + } +} diff --git a/tests/PhpWord/Tests/Element/TextBoxTest.php b/tests/PhpWord/Tests/Element/TextBoxTest.php new file mode 100644 index 00000000..a706c5a2 --- /dev/null +++ b/tests/PhpWord/Tests/Element/TextBoxTest.php @@ -0,0 +1,74 @@ +assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextBox', $oTextBox); + $this->assertEquals($oTextBox->getStyle(), null); + } + + /** + * Get style name + */ + public function testStyleText() + { + $oTextBox = new TextBox('section', 1, 'textBoxStyle'); + + $this->assertEquals($oTextBox->getStyle(), 'textBoxStyle'); + } + + /** + * Get style array + */ + public function testStyleArray() + { + $oTextBox = new TextBox( + 'section', + 1, + 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()); + } +} diff --git a/tests/PhpWord/Tests/Style/TextBoxTest.php b/tests/PhpWord/Tests/Style/TextBoxTest.php new file mode 100644 index 00000000..cd2d8695 --- /dev/null +++ b/tests/PhpWord/Tests/Style/TextBoxTest.php @@ -0,0 +1,305 @@ + 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()); + } +}