Merge pull request #96 from gabrielbull/develop

Added line height methods to mirror the line height settings in Word in the paragraph styling
This commit is contained in:
Progi1984 2014-03-09 20:49:12 +01:00
commit 79ba793294
24 changed files with 1394 additions and 1108 deletions

View File

@ -89,8 +89,10 @@ class PHPWord_Section_Footer_PreserveText
$this->_styleParagraph = $styleParagraph; $this->_styleParagraph = $styleParagraph;
} }
$pattern = '/({.*?})/'; $matches = preg_split('/({.*?})/', $text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$this->_text = preg_split($pattern, $text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); if (isset($matches[0])) {
$this->_text = $matches[0];
}
return $this; return $this;
} }

View File

@ -30,46 +30,63 @@
*/ */
class PHPWord_Section_Text class PHPWord_Section_Text
{ {
/** /**
* Text content * Text content
* *
* @var string * @var string
*/ */
private $_text; private $text;
/** /**
* Text style * Text style
* *
* @var PHPWord_Style_Font * @var PHPWord_Style_Font
*/ */
private $_styleFont; private $fontStyle;
/** /**
* Paragraph style * Paragraph style
* *
* @var \PHPWord_Style_Paragraph * @var PHPWord_Style_Paragraph
*/ */
private $_styleParagraph; private $paragraphStyle;
/** /**
* Create a new Text Element * Create a new Text Element
* *
* @var string $text * @param string $text
* @var mixed $style * @param null|array|\PHPWord_Style_Font $fontStyle
* @param null|array|\PHPWord_Style_Paragraph $paragraphStyle
*/ */
public function __construct($text = null, $styleFont = null, $styleParagraph = null) public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
{ {
// Set font style $this->setText($text);
$this->setFontStyle($styleFont); $paragraphStyle = $this->setParagraphStyle($paragraphStyle);
$this->setFontStyle($fontStyle, $paragraphStyle);
}
// Set paragraph style /**
$this->setParagraphStyle($styleParagraph); * Set Text style
*
$this->_text = $text; * @param null|array|\PHPWord_Style_Font $style
* @param null|array|\PHPWord_Style_Paragraph $paragraphStyle
return $this; * @return PHPWord_Style_Font
*/
public function setFontStyle($style = null, $paragraphStyle = null)
{
if ($style instanceof PHPWord_Style_Font) {
$this->fontStyle = $style;
$this->setParagraphStyle($paragraphStyle);
} elseif (is_array($style)) {
$this->fontStyle = new PHPWord_Style_Font('text', $paragraphStyle);
$this->fontStyle->setArrayStyle($style);
} elseif (null === $style) {
$this->fontStyle = new PHPWord_Style_Font('text', $paragraphStyle);
} else {
$this->fontStyle = $style;
$this->setParagraphStyle($paragraphStyle);
}
return $this->fontStyle;
} }
/** /**
@ -79,28 +96,28 @@ class PHPWord_Section_Text
*/ */
public function getFontStyle() public function getFontStyle()
{ {
return $this->_styleFont; return $this->fontStyle;
} }
/** /**
* Set Text style * Set Paragraph style
* *
* @return PHPWord_Style_Font * @param null|array|\PHPWord_Style_Paragraph $style
* @return null|\PHPWord_Style_Paragraph
*/ */
public function setFontStyle($styleFont) public function setParagraphStyle($style = null)
{ {
if (is_array($styleFont)) { if (is_array($style)) {
$this->_styleFont = new PHPWord_Style_Font('text'); $this->paragraphStyle = new PHPWord_Style_Paragraph;
$this->paragraphStyle->setArrayStyle($style);
foreach ($styleFont as $key => $value) { } elseif ($style instanceof PHPWord_Style_Paragraph) {
if (substr($key, 0, 1) != '_') { $this->paragraphStyle = $style;
$key = '_' . $key; } elseif (null === $style) {
} $this->paragraphStyle = new PHPWord_Style_Paragraph;
$this->_styleFont->setStyleValue($key, $value);
}
} else { } else {
$this->_styleFont = $styleFont; $this->paragraphStyle = $style;
} }
return $this->paragraphStyle;
} }
/** /**
@ -110,35 +127,17 @@ class PHPWord_Section_Text
*/ */
public function getParagraphStyle() public function getParagraphStyle()
{ {
return $this->_styleParagraph; return $this->paragraphStyle;
} }
/** /**
* Set Paragraph style * @param string $text
* * @return $this
* @param array|\PHPWord_Style_Paragraph $styleParagraph
* @return \PHPWord_Style_Paragraph
* @throws \Exception
*/ */
public function setParagraphStyle($styleParagraph) public function setText($text)
{ {
if (is_array($styleParagraph)) { $this->text = $text;
$this->_styleParagraph = new PHPWord_Style_Paragraph(); return $this;
foreach ($styleParagraph as $key => $value) {
if ($key === 'line-height') {
null;
} elseif (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_styleParagraph->setStyleValue($key, $value);
}
} elseif ($styleParagraph instanceof PHPWord_Style_Paragraph) {
$this->_styleParagraph = $styleParagraph;
} else {
throw new Exception('Expected array or PHPWord_Style_Paragraph');
}
return $this->_styleParagraph;
} }
/** /**
@ -148,6 +147,6 @@ class PHPWord_Section_Text
*/ */
public function getText() public function getText()
{ {
return $this->_text; return $this->text;
} }
} }

View File

@ -25,6 +25,8 @@
* @version 0.7.0 * @version 0.7.0
*/ */
use PHPWord\Exceptions\InvalidStyleException;
/** /**
* Class PHPWord_Style_Font * Class PHPWord_Style_Font
*/ */
@ -84,105 +86,119 @@ class PHPWord_Style_Font
* *
* @var int|float * @var int|float
*/ */
private $_name; private $_name = PHPWord::DEFAULT_FONT_NAME;
/** /**
* Font size * Font size
* *
* @var int|float * @var int|float
*/ */
private $_size; private $_size = PHPWord::DEFAULT_FONT_SIZE;
/** /**
* Bold * Bold
* *
* @var bool * @var bool
*/ */
private $_bold; private $_bold = false;
/** /**
* Italics * Italics
* *
* @var bool * @var bool
*/ */
private $_italic; private $_italic = false;
/** /**
* Superscript * Superscript
* *
* @var bool * @var bool
*/ */
private $_superScript; private $_superScript = false;
/** /**
* Subscript * Subscript
* *
* @var bool * @var bool
*/ */
private $_subScript; private $_subScript = false;
/** /**
* Underline mode * Underline mode
* *
* @var string * @var string
*/ */
private $_underline; private $_underline = PHPWord_Style_Font::UNDERLINE_NONE;
/** /**
* Strikethrough * Strikethrough
* *
* @var bool * @var bool
*/ */
private $_strikethrough; private $_strikethrough = false;
/** /**
* Font color * Font color
* *
* @var string * @var string
*/ */
private $_color; private $_color = PHPWord::DEFAULT_FONT_COLOR;
/** /**
* Foreground/highlight * Foreground/highlight
* *
* @var string * @var string
*/ */
private $_fgColor; private $_fgColor = null;
/**
* Text line height
*
* @var int
*/
private $lineHeight = 1.0;
/** /**
* New font style * New font style
* *
* @param string $type Type of font * @param string $type Type of font
* @param array $styleParagraph Paragraph styles definition * @param array $paragraphStyle Paragraph styles definition
*/ */
public function __construct($type = 'text', $styleParagraph = null) public function __construct($type = 'text', $paragraphStyle = null)
{ {
$this->_type = $type; $this->_type = $type;
$this->_name = PHPWord::DEFAULT_FONT_NAME;
$this->_size = PHPWord::DEFAULT_FONT_SIZE;
$this->_bold = false;
$this->_italic = false;
$this->_superScript = false;
$this->_subScript = false;
$this->_underline = PHPWord_Style_Font::UNDERLINE_NONE;
$this->_strikethrough = false;
$this->_color = PHPWord::DEFAULT_FONT_COLOR;
$this->_fgColor = null;
if (!is_null($styleParagraph)) { if ($paragraphStyle instanceof PHPWord_Style_Paragraph) {
$paragraph = new PHPWord_Style_Paragraph(); $this->_paragraphStyle = $paragraphStyle;
foreach ($styleParagraph as $key => $value) { } elseif (is_array($paragraphStyle)) {
if (substr($key, 0, 1) != '_') { $this->_paragraphStyle = new PHPWord_Style_Paragraph;
$key = '_' . $key; $this->_paragraphStyle->setArrayStyle($paragraphStyle);
} } elseif (null === $paragraphStyle) {
$paragraph->setStyleValue($key, $value); $this->_paragraphStyle = new PHPWord_Style_Paragraph;
}
$this->_paragraphStyle = $paragraph;
} else { } else {
$this->_paragraphStyle = null; $this->_paragraphStyle = $paragraphStyle;
} }
} }
/**
* @param array $style
* @return $this
*/
public function setArrayStyle(array $style = array())
{
foreach ($style as $key => $value) {
if ($key === 'line-height') {
$this->setLineHeight($value);
null;
} elseif (substr($key, 0, 1) !== '_') {
$key = '_' . $key;
}
$this->setStyleValue($key, $value);
}
return $this;
}
/** /**
* Set style value * Set style value
* *
@ -465,4 +481,35 @@ class PHPWord_Style_Font
{ {
return $this->_paragraphStyle; return $this->_paragraphStyle;
} }
/**
* Set the line height
*
* @param int|float|string $lineHeight
* @return $this
* @throws \PHPWord\Exceptions\InvalidStyleException
*/
public function setLineHeight($lineHeight)
{
if (is_string($lineHeight)) {
$lineHeight = floatval(preg_replace('/[^0-9\.\,]/', '', $lineHeight));
}
if ((!is_integer($lineHeight) && !is_float($lineHeight)) || !$lineHeight) {
throw new InvalidStyleException('Line height must be a valid number');
}
$this->lineHeight = $lineHeight;
$this->getParagraphStyle()->setLineHeight($lineHeight);
return $this;
}
/**
* @return int|float
*/
public function getLineHeight()
{
return $this->lineHeight;
}
} }

View File

@ -34,7 +34,7 @@ class PHPWord_Style_Paragraph
{ {
const LINE_HEIGHT = 240; const LINE_HEIGHT = 240;
/* /**
* Text line height * Text line height
* *
* @var int * @var int
@ -132,6 +132,24 @@ class PHPWord_Style_Paragraph
*/ */
private $_pageBreakBefore = false; private $_pageBreakBefore = false;
/**
* @param array $style
* @return $this
*/
public function setArrayStyle(array $style = array())
{
foreach ($style as $key => $value) {
if ($key === 'line-height') {
null;
} elseif (substr($key, 0, 1) !== '_') {
$key = '_' . $key;
}
$this->setStyleValue($key, $value);
}
return $this;
}
/** /**
* Set Style value * Set Style value
* *
@ -482,7 +500,7 @@ class PHPWord_Style_Paragraph
} }
/** /**
* @return int * @return int|float
*/ */
public function getLineHeight() public function getLineHeight()
{ {

View File

@ -39,9 +39,13 @@ the following lines to your ``composer.json``.
* [Section settings](#section-settings) * [Section settings](#section-settings)
* [Section page numbering](#section-page-numbering) * [Section page numbering](#section-page-numbering)
3. [Texts](#texts) 3. [Texts](#texts)
4. [Tables](#tables) * [Attributes](#text-attributes)
4. [Paragraph Style](#paragraph-style)
* [Attributes](#paragraph-style-attributes)
5. [Tables](#tables)
* [Cell Style](#tables-cell-style) * [Cell Style](#tables-cell-style)
5. [Images](#images) 6. [Images](#images)
* [Attributes](#images-attributes)
<a name="basic-usage"></a> <a name="basic-usage"></a>
#### Basic usage #### Basic usage
@ -176,10 +180,39 @@ $section->addText('I am simple paragraph', $fontStyle, $paragraphStyle);
```php ```php
$textrun = $section->createTextRun(); $textrun = $section->createTextRun();
$textrun->addText('I am bold', array('bold' => true)); $textrun->addText('I am bold', array('bold' => true));
$textrun->addText('I am italic, array('italic' => true)); $textrun->addText('I am italic, array('italic' => true));
$textrun->addText('I am colored, array('color' => 'AACC00')); $textrun->addText('I am colored, array('color' => 'AACC00'));
``` ```
<a name="text-attributes"></a>
##### Attributes
* ``size`` text size, e.g. _20_, _22_,
* ``name`` font name, e.g. _Arial_
* ``bold`` text is bold, _true_ or _false_
* ``italic`` text is italic, _true_ or _false_
* ``superScript`` text is super script, _true_ or _false_
* ``subScript`` text is sub script, _true_ or _false_
* ``underline`` text is underline, _true_ or _false_
* ``strikethrough`` text is strikethrough, _true_ or _false_
* ``color`` text color, e.g. _FF0000_
* ``fgColor`` fgColor
* ``line-height`` text line height, e.g. _1.0_, _1.5_, ect...
<a name="paragraph-style"></a>
#### Paragraph Style
<a name="paragraph-style-attributes"></a>
##### Attributes
* ``line-height`` text line height, e.g. _1.0_, _1.5_, ect...
* ``align`` paragraph alignment, _left_, _right_ or _center_
* ``spaceBefore`` space before Paragraph
* ``spaceAfter`` space after Paragraph
* ``tabs`` set of Custom Tab Stops
* ``indent`` indent by how much
<a name="tables"></a> <a name="tables"></a>
#### Tables #### Tables
@ -213,7 +246,9 @@ $section = $PHPWord->createSection();
$section->addImage('mars.jpg'); $section->addImage('mars.jpg');
``` ```
Images settings include: <a name="images-attributes"></a>
##### Attributes
* ``width`` width in pixels * ``width`` width in pixels
* ``height`` height in pixels * ``height`` height in pixels
* ``align`` image alignment, _left_, _right_ or _center_ * ``align`` image alignment, _left_, _right_ or _center_
@ -221,7 +256,7 @@ Images settings include:
* ``marginLeft`` left margin in inches, can be negative * ``marginLeft`` left margin in inches, can be negative
* ``wrappingStyle`` can be _inline_, _square_, _tight_, _behind_, _infront_ * ``wrappingStyle`` can be _inline_, _square_, _tight_, _behind_, _infront_
To add an image with settings, consider the following example. To add an image with attributes, consider the following example.
```php ```php
$section->addImage( $section->addImage(
@ -234,4 +269,4 @@ $section->addImage(
'wrappingStyle' => 'behind' 'wrappingStyle' => 'behind'
) )
); );
``` ```

View File

@ -1,30 +1,33 @@
<?php <?php
namespace PHPWord\Tests; namespace PHPWord\Tests\Section\Footer;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
use PHPWord_Section_Footer_PreserveText; use PHPWord_Section_Footer_PreserveText;
class PHPWord_Section_Footer_PreserveTextTest extends \PHPUnit_Framework_TestCase { class PreserveTextTest extends \PHPUnit_Framework_TestCase
public function testConstruct(){ {
$oPreserveText = new PHPWord_Section_Footer_PreserveText(); public function testConstruct()
{
$oPreserveText = new PHPWord_Section_Footer_PreserveText();
$this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $oPreserveText); $this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $oPreserveText);
$this->assertEquals($oPreserveText->getText(), null); $this->assertEquals($oPreserveText->getText(), null);
$this->assertEquals($oPreserveText->getFontStyle(), null); $this->assertEquals($oPreserveText->getFontStyle(), null);
$this->assertEquals($oPreserveText->getParagraphStyle(), null); $this->assertEquals($oPreserveText->getParagraphStyle(), null);
} }
public function testConstructWithString(){ public function testConstructWithString()
$oPreserveText = new PHPWord_Section_Footer_PreserveText('text', 'styleFont', 'styleParagraph'); {
$this->assertEquals($oPreserveText->getText(), 'text'); $oPreserveText = new PHPWord_Section_Footer_PreserveText('text', 'styleFont', 'styleParagraph');
$this->assertEquals($oPreserveText->getFontStyle(), 'styleFont'); $this->assertEquals($oPreserveText->getText(), 'text');
$this->assertEquals($oPreserveText->getParagraphStyle(), 'styleParagraph'); $this->assertEquals($oPreserveText->getFontStyle(), 'styleFont');
} $this->assertEquals($oPreserveText->getParagraphStyle(), 'styleParagraph');
}
public function testConstructWithArray(){ public function testConstructWithArray()
$oPreserveText = new PHPWord_Section_Footer_PreserveText('text', array('align'=>'center'), array('marginLeft'=>600, 'marginRight'=>600, 'marginTop'=>600, 'marginBottom'=>600)); {
$this->assertInstanceOf('PHPWord_Style_Font', $oPreserveText->getFontStyle()); $oPreserveText = new PHPWord_Section_Footer_PreserveText('text', array('align' => 'center'), array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600));
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oPreserveText->getParagraphStyle()); $this->assertInstanceOf('PHPWord_Style_Font', $oPreserveText->getFontStyle());
} $this->assertInstanceOf('PHPWord_Style_Paragraph', $oPreserveText->getParagraphStyle());
} }
}

View File

@ -1,110 +1,121 @@
<?php <?php
namespace PHPWord\Tests; namespace PHPWord\Tests\Section;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
use PHPWord_Section_Footer; use PHPWord_Section_Footer;
class PHPWord_Section_FooterTest extends \PHPUnit_Framework_TestCase { class FooterTest extends \PHPUnit_Framework_TestCase
{
public function testConstruct()
{
$iVal = rand(1, 1000);
$oFooter = new PHPWord_Section_Footer($iVal);
public function testConstruct(){ $this->assertInstanceOf('PHPWord_Section_Footer', $oFooter);
$iVal = rand(1, 1000); $this->assertEquals($oFooter->getFooterCount(), $iVal);
$oFooter = new PHPWord_Section_Footer($iVal); }
$this->assertInstanceOf('PHPWord_Section_Footer', $oFooter); public function testRelationID()
$this->assertEquals($oFooter->getFooterCount(), $iVal); {
} $oFooter = new PHPWord_Section_Footer(0);
public function testRelationID(){ $iVal = rand(1, 1000);
$oFooter = new PHPWord_Section_Footer(0); $oFooter->setRelationId($iVal);
$this->assertEquals($oFooter->getRelationId(), $iVal);
}
$iVal = rand(1, 1000); public function testAddText()
$oFooter->setRelationId($iVal); {
$this->assertEquals($oFooter->getRelationId(), $iVal); $oFooter = new PHPWord_Section_Footer(1);
} $element = $oFooter->addText('text');
public function testAddText(){ $this->assertCount(1, $oFooter->getElements());
$oFooter = new PHPWord_Section_Footer(1); $this->assertInstanceOf('PHPWord_Section_Text', $element);
$element = $oFooter->addText('text');
$this->assertCount(1, $oFooter->getElements()); }
$this->assertInstanceOf('PHPWord_Section_Text', $element);
} public function testAddTextNotUTF8()
{
$oFooter = new PHPWord_Section_Footer(1);
$element = $oFooter->addText(utf8_decode('ééé'));
public function testAddTextNotUTF8(){ $this->assertCount(1, $oFooter->getElements());
$oFooter = new PHPWord_Section_Footer(1); $this->assertInstanceOf('PHPWord_Section_Text', $element);
$element = $oFooter->addText(utf8_decode('ééé')); $this->assertEquals($element->getText(), 'ééé');
}
$this->assertCount(1, $oFooter->getElements()); public function testAddTextBreak()
$this->assertInstanceOf('PHPWord_Section_Text', $element); {
$this->assertEquals($element->getText(), 'ééé'); $oFooter = new PHPWord_Section_Footer(1);
} $iVal = rand(1, 1000);
$oFooter->addTextBreak($iVal);
public function testAddTextBreak(){ $this->assertCount($iVal, $oFooter->getElements());
$oFooter = new PHPWord_Section_Footer(1); }
$iVal = rand(1, 1000);
$oFooter->addTextBreak($iVal);
$this->assertCount($iVal, $oFooter->getElements()); public function testCreateTextRun()
} {
$oFooter = new PHPWord_Section_Footer(1);
$element = $oFooter->createTextRun();
public function testCreateTextRun(){ $this->assertCount(1, $oFooter->getElements());
$oFooter = new PHPWord_Section_Footer(1); $this->assertInstanceOf('PHPWord_Section_TextRun', $element);
$element = $oFooter->createTextRun(); }
$this->assertCount(1, $oFooter->getElements()); public function testAddTable()
$this->assertInstanceOf('PHPWord_Section_TextRun', $element); {
} $oFooter = new PHPWord_Section_Footer(1);
$element = $oFooter->addTable();
public function testAddTable(){ $this->assertCount(1, $oFooter->getElements());
$oFooter = new PHPWord_Section_Footer(1); $this->assertInstanceOf('PHPWord_Section_Table', $element);
$element = $oFooter->addTable(); }
$this->assertCount(1, $oFooter->getElements()); public function testAddImage()
$this->assertInstanceOf('PHPWord_Section_Table', $element); {
} $src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
);
$oFooter = new PHPWord_Section_Footer(1);
$element = $oFooter->addImage($src);
public function testAddImage(){ $this->assertCount(1, $oFooter->getElements());
$src = \join( $this->assertInstanceOf('PHPWord_Section_Image', $element);
\DIRECTORY_SEPARATOR, }
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
);
$oFooter = new PHPWord_Section_Footer(1);
$element = $oFooter->addImage($src);
$this->assertCount(1, $oFooter->getElements()); public function testAddMemoryImage()
$this->assertInstanceOf('PHPWord_Section_Image', $element); {
} $oFooter = new PHPWord_Section_Footer(1);
$element = $oFooter->addMemoryImage('https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png');
public function testAddMemoryImage(){ $this->assertCount(1, $oFooter->getElements());
$oFooter = new PHPWord_Section_Footer(1); $this->assertInstanceOf('PHPWord_Section_MemoryImage', $element);
$element = $oFooter->addMemoryImage('https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'); }
$this->assertCount(1, $oFooter->getElements()); public function testAddPreserveText()
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element); {
} $oFooter = new PHPWord_Section_Footer(1);
$element = $oFooter->addPreserveText('text');
public function testAddPreserveText(){ $this->assertCount(1, $oFooter->getElements());
$oFooter = new PHPWord_Section_Footer(1); $this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element);
$element = $oFooter->addPreserveText('text'); }
$this->assertCount(1, $oFooter->getElements()); public function testAddPreserveTextNotUTF8()
$this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); {
} $oFooter = new PHPWord_Section_Footer(1);
$element = $oFooter->addPreserveText(utf8_decode('ééé'));
public function testAddPreserveTextNotUTF8(){ $this->assertCount(1, $oFooter->getElements());
$oFooter = new PHPWord_Section_Footer(1); $this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element);
$element = $oFooter->addPreserveText(utf8_decode('ééé')); $this->assertEquals($element->getText(), 'ééé');
}
$this->assertCount(1, $oFooter->getElements()); public function testGetElements()
$this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); {
$this->assertEquals($element->getText(), 'ééé'); $oFooter = new PHPWord_Section_Footer(1);
}
public function testGetElements(){ $this->assertInternalType('array', $oFooter->getElements());
$oFooter = new PHPWord_Section_Footer(1); }
}
$this->assertInternalType('array', $oFooter->getElements());
}
}

View File

@ -1,58 +1,64 @@
<?php <?php
namespace PHPWord\Tests; namespace PHPWord\Tests\Section;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
use PHPWord_Section_Footnote; use PHPWord_Section_Footnote;
class PHPWord_Section_FootnoteTest extends \PHPUnit_Framework_TestCase { class FootnoteTest extends \PHPUnit_Framework_TestCase
{
public function testConstruct()
{
$oFootnote = new PHPWord_Section_Footnote();
public function testConstruct(){ $this->assertInstanceOf('PHPWord_Section_Footnote', $oFootnote);
$oFootnote = new PHPWord_Section_Footnote(); $this->assertCount(0, $oFootnote->getElements());
$this->assertEquals($oFootnote->getParagraphStyle(), null);
}
$this->assertInstanceOf('PHPWord_Section_Footnote', $oFootnote); public function testConstructString()
$this->assertCount(0, $oFootnote->getElements()); {
$this->assertEquals($oFootnote->getParagraphStyle(), null); $oFootnote = new PHPWord_Section_Footnote('pStyle');
}
public function testConstructString(){ $this->assertEquals($oFootnote->getParagraphStyle(), 'pStyle');
$oFootnote = new PHPWord_Section_Footnote('pStyle'); }
$this->assertEquals($oFootnote->getParagraphStyle(), 'pStyle'); public function testConstructArray()
} {
$oFootnote = new PHPWord_Section_Footnote(array('spacing' => 100));
public function testConstructArray(){ $this->assertInstanceOf('PHPWord_Style_Paragraph', $oFootnote->getParagraphStyle());
$oFootnote = new PHPWord_Section_Footnote(array('spacing' => 100)); }
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oFootnote->getParagraphStyle()); public function testAddText()
} {
$oFootnote = new PHPWord_Section_Footnote();
$element = $oFootnote->addText('text');
public function testAddText(){ $this->assertCount(1, $oFootnote->getElements());
$oFootnote = new PHPWord_Section_Footnote(); $this->assertInstanceOf('PHPWord_Section_Text', $element);
$element = $oFootnote->addText('text'); }
$this->assertCount(1, $oFootnote->getElements()); public function testAddLink()
$this->assertInstanceOf('PHPWord_Section_Text', $element); {
} $oFootnote = new PHPWord_Section_Footnote();
$element = $oFootnote->addLink('http://www.google.fr');
public function testAddLink(){ $this->assertCount(1, $oFootnote->getElements());
$oFootnote = new PHPWord_Section_Footnote(); $this->assertInstanceOf('PHPWord_Section_Link', $element);
$element = $oFootnote->addLink('http://www.google.fr'); }
$this->assertCount(1, $oFootnote->getElements()); public function testReferenceId()
$this->assertInstanceOf('PHPWord_Section_Link', $element); {
} $oFootnote = new PHPWord_Section_Footnote();
public function testReferenceId(){ $iVal = rand(1, 1000);
$oFootnote = new PHPWord_Section_Footnote(); $oFootnote->setReferenceId($iVal);
$this->assertEquals($oFootnote->getReferenceId(), $iVal);
}
$iVal = rand(1, 1000); public function testGetElements()
$oFootnote->setReferenceId($iVal); {
$this->assertEquals($oFootnote->getReferenceId(), $iVal); $oFootnote = new PHPWord_Section_Footnote();
} $this->assertInternalType('array', $oFootnote->getElements());
}
public function testGetElements(){ }
$oFootnote = new PHPWord_Section_Footnote();
$this->assertInternalType('array', $oFootnote->getElements());
}
}

View File

@ -1,146 +1,164 @@
<?php <?php
namespace PHPWord\Tests; namespace PHPWord\Tests\Section;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
use PHPWord_Section_Header; use PHPWord_Section_Header;
class PHPWord_Section_HeaderTest extends \PHPUnit_Framework_TestCase { class HeaderTest extends \PHPUnit_Framework_TestCase
public function testConstructDefault() { {
$iVal = rand(1, 1000); public function testConstructDefault()
$oHeader = new PHPWord_Section_Header($iVal); {
$iVal = rand(1, 1000);
$oHeader = new PHPWord_Section_Header($iVal);
$this->assertInstanceOf('PHPWord_Section_Header', $oHeader); $this->assertInstanceOf('PHPWord_Section_Header', $oHeader);
$this->assertEquals($oHeader->getHeaderCount(), $iVal); $this->assertEquals($oHeader->getHeaderCount(), $iVal);
$this->assertEquals($oHeader->getType(), PHPWord_Section_Header::AUTO); $this->assertEquals($oHeader->getType(), PHPWord_Section_Header::AUTO);
} }
public function testAddText(){ public function testAddText()
$oHeader = new PHPWord_Section_Header(1); {
$element = $oHeader->addText('text'); $oHeader = new PHPWord_Section_Header(1);
$element = $oHeader->addText('text');
$this->assertInstanceOf('PHPWord_Section_Text', $element); $this->assertInstanceOf('PHPWord_Section_Text', $element);
$this->assertCount(1, $oHeader->getElements()); $this->assertCount(1, $oHeader->getElements());
$this->assertEquals($element->getText(), 'text'); $this->assertEquals($element->getText(), 'text');
} }
public function testAddTextNotUTF8(){ public function testAddTextNotUTF8()
$oHeader = new PHPWord_Section_Header(1); {
$element = $oHeader->addText(utf8_decode('ééé')); $oHeader = new PHPWord_Section_Header(1);
$element = $oHeader->addText(utf8_decode('ééé'));
$this->assertInstanceOf('PHPWord_Section_Text', $element); $this->assertInstanceOf('PHPWord_Section_Text', $element);
$this->assertCount(1, $oHeader->getElements()); $this->assertCount(1, $oHeader->getElements());
$this->assertEquals($element->getText(), 'ééé'); $this->assertEquals($element->getText(), 'ééé');
} }
public function testAddTextBreak(){ public function testAddTextBreak()
$oHeader = new PHPWord_Section_Header(1); {
$oHeader->addTextBreak(); $oHeader = new PHPWord_Section_Header(1);
$this->assertCount(1, $oHeader->getElements()); $oHeader->addTextBreak();
} $this->assertCount(1, $oHeader->getElements());
}
public function testAddTextBreakWithParams(){ public function testAddTextBreakWithParams()
$oHeader = new PHPWord_Section_Header(1); {
$iVal = rand(1, 1000); $oHeader = new PHPWord_Section_Header(1);
$oHeader->addTextBreak($iVal); $iVal = rand(1, 1000);
$this->assertCount($iVal, $oHeader->getElements()); $oHeader->addTextBreak($iVal);
} $this->assertCount($iVal, $oHeader->getElements());
}
public function testCreateTextRun(){ public function testCreateTextRun()
$oHeader = new PHPWord_Section_Header(1); {
$element = $oHeader->createTextRun(); $oHeader = new PHPWord_Section_Header(1);
$this->assertInstanceOf('PHPWord_Section_TextRun', $element); $element = $oHeader->createTextRun();
$this->assertCount(1, $oHeader->getElements()); $this->assertInstanceOf('PHPWord_Section_TextRun', $element);
} $this->assertCount(1, $oHeader->getElements());
}
public function testAddTable(){ public function testAddTable()
$oHeader = new PHPWord_Section_Header(1); {
$element = $oHeader->addTable(); $oHeader = new PHPWord_Section_Header(1);
$this->assertInstanceOf('PHPWord_Section_Table', $element); $element = $oHeader->addTable();
$this->assertCount(1, $oHeader->getElements()); $this->assertInstanceOf('PHPWord_Section_Table', $element);
} $this->assertCount(1, $oHeader->getElements());
}
public function testAddImage(){ public function testAddImage()
$src = \join( {
\DIRECTORY_SEPARATOR, $src = \join(
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') \DIRECTORY_SEPARATOR,
); array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
$oHeader = new PHPWord_Section_Header(1); );
$element = $oHeader->addImage($src); $oHeader = new PHPWord_Section_Header(1);
$element = $oHeader->addImage($src);
$this->assertCount(1, $oHeader->getElements()); $this->assertCount(1, $oHeader->getElements());
$this->assertInstanceOf('PHPWord_Section_Image', $element); $this->assertInstanceOf('PHPWord_Section_Image', $element);
} }
public function testAddMemoryImage(){ public function testAddMemoryImage()
$oHeader = new PHPWord_Section_Header(1); {
$element = $oHeader->addMemoryImage('https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'); $oHeader = new PHPWord_Section_Header(1);
$element = $oHeader->addMemoryImage('https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png');
$this->assertCount(1, $oHeader->getElements()); $this->assertCount(1, $oHeader->getElements());
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element); $this->assertInstanceOf('PHPWord_Section_MemoryImage', $element);
} }
public function testAddPreserveText(){ public function testAddPreserveText()
$oHeader = new PHPWord_Section_Header(1); {
$element = $oHeader->addPreserveText('text'); $oHeader = new PHPWord_Section_Header(1);
$element = $oHeader->addPreserveText('text');
$this->assertCount(1, $oHeader->getElements()); $this->assertCount(1, $oHeader->getElements());
$this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); $this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element);
} }
public function testAddPreserveTextNotUTF8(){ public function testAddPreserveTextNotUTF8()
$oHeader = new PHPWord_Section_Header(1); {
$element = $oHeader->addPreserveText(utf8_decode('ééé')); $oHeader = new PHPWord_Section_Header(1);
$element = $oHeader->addPreserveText(utf8_decode('ééé'));
$this->assertCount(1, $oHeader->getElements()); $this->assertCount(1, $oHeader->getElements());
$this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); $this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element);
$this->assertEquals($element->getText(), 'ééé'); $this->assertEquals($element->getText(), 'ééé');
} }
public function testAddWatermark(){ public function testAddWatermark()
$src = \join( {
\DIRECTORY_SEPARATOR, $src = \join(
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') \DIRECTORY_SEPARATOR,
); array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
$oHeader = new PHPWord_Section_Header(1); );
$element = $oHeader->addWatermark($src); $oHeader = new PHPWord_Section_Header(1);
$element = $oHeader->addWatermark($src);
$this->assertCount(1, $oHeader->getElements()); $this->assertCount(1, $oHeader->getElements());
$this->assertInstanceOf('PHPWord_Section_Image', $element); $this->assertInstanceOf('PHPWord_Section_Image', $element);
} }
public function testGetElements(){ public function testGetElements()
$oHeader = new PHPWord_Section_Header(1); {
$oHeader = new PHPWord_Section_Header(1);
$this->assertInternalType('array', $oHeader->getElements()); $this->assertInternalType('array', $oHeader->getElements());
} }
public function testRelationId(){ public function testRelationId()
$oHeader = new PHPWord_Section_Header(1); {
$oHeader = new PHPWord_Section_Header(1);
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oHeader->setRelationId($iVal); $oHeader->setRelationId($iVal);
$this->assertEquals($oHeader->getRelationId(), $iVal); $this->assertEquals($oHeader->getRelationId(), $iVal);
} }
public function testResetType(){ public function testResetType()
$oHeader = new PHPWord_Section_Header(1); {
$oHeader->firstPage(); $oHeader = new PHPWord_Section_Header(1);
$oHeader->resetType(); $oHeader->firstPage();
$oHeader->resetType();
$this->assertEquals($oHeader->getType(), PHPWord_Section_Header::AUTO); $this->assertEquals($oHeader->getType(), PHPWord_Section_Header::AUTO);
} }
public function testFirstPage(){ public function testFirstPage()
$oHeader = new PHPWord_Section_Header(1); {
$oHeader->firstPage(); $oHeader = new PHPWord_Section_Header(1);
$oHeader->firstPage();
$this->assertEquals($oHeader->getType(), PHPWord_Section_Header::FIRST); $this->assertEquals($oHeader->getType(), PHPWord_Section_Header::FIRST);
} }
public function testEvenPage(){ public function testEvenPage()
$oHeader = new PHPWord_Section_Header(1); {
$oHeader->evenPage(); $oHeader = new PHPWord_Section_Header(1);
$oHeader->evenPage();
$this->assertEquals($oHeader->getType(), PHPWord_Section_Header::EVEN); $this->assertEquals($oHeader->getType(), PHPWord_Section_Header::EVEN);
} }
} }

View File

@ -1,62 +1,68 @@
<?php <?php
namespace PHPWord\Tests; namespace PHPWord\Tests\Section;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
use PHPWord_Section_Image; use PHPWord_Section_Image;
use PHPWord_Style_Image; use PHPWord_Style_Image;
class PHPWord_Section_ImageTest extends \PHPUnit_Framework_TestCase { class ImageTest extends \PHPUnit_Framework_TestCase
public function testConstruct() { {
$src = \join( public function testConstruct()
\DIRECTORY_SEPARATOR, {
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png') $src = \join(
); \DIRECTORY_SEPARATOR,
$oImage = new PHPWord_Section_Image($src); array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png')
);
$oImage = new PHPWord_Section_Image($src);
$this->assertInstanceOf('PHPWord_Section_Image', $oImage); $this->assertInstanceOf('PHPWord_Section_Image', $oImage);
$this->assertEquals($oImage->getSource(), $src); $this->assertEquals($oImage->getSource(), $src);
$this->assertEquals($oImage->getMediaId(), md5($src)); $this->assertEquals($oImage->getMediaId(), md5($src));
$this->assertEquals($oImage->getIsWatermark(), false); $this->assertEquals($oImage->getIsWatermark(), false);
$this->assertInstanceOf('PHPWord_Style_Image', $oImage->getStyle()); $this->assertInstanceOf('PHPWord_Style_Image', $oImage->getStyle());
} }
public function testConstructWithStyle() {
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png')
);
$oImage = new PHPWord_Section_Image($src, array('width'=>210, 'height'=>210, 'align'=>'center', 'wrappingStyle' => \PHPWord_Style_Image::WRAPPING_STYLE_BEHIND));
$this->assertInstanceOf('PHPWord_Style_Image', $oImage->getStyle()); public function testConstructWithStyle()
} {
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png')
);
$oImage = new PHPWord_Section_Image($src, array('width' => 210, 'height' => 210, 'align' => 'center', 'wrappingStyle' => \PHPWord_Style_Image::WRAPPING_STYLE_BEHIND));
public function testStyle(){ $this->assertInstanceOf('PHPWord_Style_Image', $oImage->getStyle());
$oImage = new PHPWord_Section_Image(\join( }
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
), array('width'=>210, 'height'=>210, 'align'=>'center'));
$this->assertInstanceOf('PHPWord_Style_Image', $oImage->getStyle()); public function testStyle()
} {
$oImage = new PHPWord_Section_Image(\join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
), array('width' => 210, 'height' => 210, 'align' => 'center'));
public function testRelationID(){ $this->assertInstanceOf('PHPWord_Style_Image', $oImage->getStyle());
$oImage = new PHPWord_Section_Image(\join( }
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
));
$iVal = rand(1, 1000); public function testRelationID()
$oImage->setRelationId($iVal); {
$this->assertEquals($oImage->getRelationId(), $iVal); $oImage = new PHPWord_Section_Image(\join(
} \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
));
public function testWatermark(){ $iVal = rand(1, 1000);
$oImage = new PHPWord_Section_Image(\join( $oImage->setRelationId($iVal);
\DIRECTORY_SEPARATOR, $this->assertEquals($oImage->getRelationId(), $iVal);
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') }
));
$oImage->setIsWatermark(true); public function testWatermark()
$this->assertEquals($oImage->getIsWatermark(), true); {
} $oImage = new PHPWord_Section_Image(\join(
} \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
));
$oImage->setIsWatermark(true);
$this->assertEquals($oImage->getIsWatermark(), true);
}
}

View File

@ -1,42 +1,48 @@
<?php <?php
namespace PHPWord\Tests; namespace PHPWord\Tests\Section;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
use PHPWord_Section_Link; use PHPWord_Section_Link;
use PHPWord_Style_Font; use PHPWord_Style_Font;
class PHPWord_Section_LinkTest extends \PHPUnit_Framework_TestCase { class LinkTest extends \PHPUnit_Framework_TestCase
public function testConstructDefault() { {
$oLink = new PHPWord_Section_Link('http://www.google.com'); public function testConstructDefault()
{
$oLink = new PHPWord_Section_Link('http://www.google.com');
$this->assertInstanceOf('PHPWord_Section_Link', $oLink); $this->assertInstanceOf('PHPWord_Section_Link', $oLink);
$this->assertEquals($oLink->getLinkSrc(), 'http://www.google.com'); $this->assertEquals($oLink->getLinkSrc(), 'http://www.google.com');
$this->assertEquals($oLink->getLinkName(), null); $this->assertEquals($oLink->getLinkName(), null);
$this->assertEquals($oLink->getFontStyle(), null); $this->assertEquals($oLink->getFontStyle(), null);
$this->assertEquals($oLink->getParagraphStyle(), null); $this->assertEquals($oLink->getParagraphStyle(), null);
} }
public function testConstructWithParamsArray() {
$oLink = new PHPWord_Section_Link('http://www.google.com', 'Search Engine', array('color'=>'0000FF', 'underline'=>PHPWord_Style_Font::UNDERLINE_SINGLE), array('marginLeft'=>600, 'marginRight'=>600, 'marginTop'=>600, 'marginBottom'=>600));
$this->assertInstanceOf('PHPWord_Section_Link', $oLink); public function testConstructWithParamsArray()
$this->assertEquals($oLink->getLinkSrc(), 'http://www.google.com'); {
$this->assertEquals($oLink->getLinkName(), 'Search Engine'); $oLink = new PHPWord_Section_Link('http://www.google.com', 'Search Engine', array('color' => '0000FF', 'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE), array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600));
$this->assertInstanceOf('PHPWord_Style_Font', $oLink->getFontStyle());
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oLink->getParagraphStyle());
}
public function testConstructWithParamsString() {
$oLink = new PHPWord_Section_Link('http://www.google.com', null, 'fontStyle', 'paragraphStyle');
$this->assertEquals($oLink->getFontStyle(), 'fontStyle'); $this->assertInstanceOf('PHPWord_Section_Link', $oLink);
$this->assertEquals($oLink->getParagraphStyle(), 'paragraphStyle'); $this->assertEquals($oLink->getLinkSrc(), 'http://www.google.com');
} $this->assertEquals($oLink->getLinkName(), 'Search Engine');
$this->assertInstanceOf('PHPWord_Style_Font', $oLink->getFontStyle());
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oLink->getParagraphStyle());
}
public function testRelationId(){ public function testConstructWithParamsString()
$oLink = new PHPWord_Section_Link('http://www.google.com'); {
$oLink = new PHPWord_Section_Link('http://www.google.com', null, 'fontStyle', 'paragraphStyle');
$iVal = rand(1, 1000); $this->assertEquals($oLink->getFontStyle(), 'fontStyle');
$oLink->setRelationId($iVal); $this->assertEquals($oLink->getParagraphStyle(), 'paragraphStyle');
$this->assertEquals($oLink->getRelationId(), $iVal); }
}
} public function testRelationId()
{
$oLink = new PHPWord_Section_Link('http://www.google.com');
$iVal = rand(1, 1000);
$oLink->setRelationId($iVal);
$this->assertEquals($oLink->getRelationId(), $iVal);
}
}

View File

@ -1,29 +1,32 @@
<?php <?php
namespace PHPWord\Tests; namespace PHPWord\Tests\Section;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
use PHPWord_Section_ListItem; use PHPWord_Section_ListItem;
use PHPWord_Style_ListItem; use PHPWord_Style_ListItem;
class PHPWord_Section_ListItemTest extends \PHPUnit_Framework_TestCase { class ListItemTest extends \PHPUnit_Framework_TestCase
{
public function testText()
{
$oListItem = new PHPWord_Section_ListItem('text');
public function testText(){ $this->assertInstanceOf('PHPWord_Section_Text', $oListItem->getTextObject());
$oListItem = new PHPWord_Section_ListItem('text'); }
$this->assertInstanceOf('PHPWord_Section_Text', $oListItem->getTextObject()); public function testStyle()
} {
$oListItem = new PHPWord_Section_ListItem('text', 1, null, array('listType' => PHPWord_Style_ListItem::TYPE_NUMBER));
public function testStyle(){ $this->assertInstanceOf('PHPWord_Style_ListItem', $oListItem->getStyle());
$oListItem = new PHPWord_Section_ListItem('text', 1, null, array('listType'=>PHPWord_Style_ListItem::TYPE_NUMBER)); $this->assertEquals($oListItem->getStyle()->getListType(), PHPWord_Style_ListItem::TYPE_NUMBER);
}
$this->assertInstanceOf('PHPWord_Style_ListItem', $oListItem->getStyle()); public function testDepth()
$this->assertEquals($oListItem->getStyle()->getListType(), PHPWord_Style_ListItem::TYPE_NUMBER); {
} $iVal = rand(1, 1000);
public function testDepth(){ $oListItem = new PHPWord_Section_ListItem('text', $iVal);
$iVal = rand(1, 1000);
$oListItem = new PHPWord_Section_ListItem('text', $iVal);
$this->assertEquals($oListItem->getDepth(), $iVal); $this->assertEquals($oListItem->getDepth(), $iVal);
} }
} }

View File

@ -1,89 +1,95 @@
<?php <?php
namespace PHPWord\Tests; namespace PHPWord\Tests\Section;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
use PHPWord_Section_MemoryImage; use PHPWord_Section_MemoryImage;
class PHPWord_Section_MemoryImageTest extends \PHPUnit_Framework_TestCase { class MemoryImageTest extends \PHPUnit_Framework_TestCase
public function testPNG() { {
$src = \join( public function testPNG()
\DIRECTORY_SEPARATOR, {
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png') $src = \join(
); \DIRECTORY_SEPARATOR,
$oMemoryImage = new PHPWord_Section_MemoryImage($src); array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png')
);
$oMemoryImage = new PHPWord_Section_MemoryImage($src);
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $oMemoryImage); $this->assertInstanceOf('PHPWord_Section_MemoryImage', $oMemoryImage);
$this->assertEquals($oMemoryImage->getSource(), $src); $this->assertEquals($oMemoryImage->getSource(), $src);
$this->assertEquals($oMemoryImage->getMediaId(), md5($src)); $this->assertEquals($oMemoryImage->getMediaId(), md5($src));
$this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefrompng'); $this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefrompng');
$this->assertEquals($oMemoryImage->getImageFunction(), 'imagepng'); $this->assertEquals($oMemoryImage->getImageFunction(), 'imagepng');
$this->assertEquals($oMemoryImage->getImageExtension(), 'png'); $this->assertEquals($oMemoryImage->getImageExtension(), 'png');
$this->assertEquals($oMemoryImage->getImageType(), 'image/png'); $this->assertEquals($oMemoryImage->getImageType(), 'image/png');
} }
public function testGIF() { public function testGIF()
$src = \join( {
\DIRECTORY_SEPARATOR, $src = \join(
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'mario.gif') \DIRECTORY_SEPARATOR,
); array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'mario.gif')
$oMemoryImage = new PHPWord_Section_MemoryImage($src); );
$oMemoryImage = new PHPWord_Section_MemoryImage($src);
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $oMemoryImage); $this->assertInstanceOf('PHPWord_Section_MemoryImage', $oMemoryImage);
$this->assertEquals($oMemoryImage->getSource(), $src); $this->assertEquals($oMemoryImage->getSource(), $src);
$this->assertEquals($oMemoryImage->getMediaId(), md5($src)); $this->assertEquals($oMemoryImage->getMediaId(), md5($src));
$this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefromgif'); $this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefromgif');
$this->assertEquals($oMemoryImage->getImageFunction(), 'imagegif'); $this->assertEquals($oMemoryImage->getImageFunction(), 'imagegif');
$this->assertEquals($oMemoryImage->getImageExtension(), 'gif'); $this->assertEquals($oMemoryImage->getImageExtension(), 'gif');
$this->assertEquals($oMemoryImage->getImageType(), 'image/gif'); $this->assertEquals($oMemoryImage->getImageType(), 'image/gif');
} }
public function testJPG() { public function testJPG()
$src = \join( {
\DIRECTORY_SEPARATOR, $src = \join(
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') \DIRECTORY_SEPARATOR,
); array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
$oMemoryImage = new PHPWord_Section_MemoryImage($src); );
$oMemoryImage = new PHPWord_Section_MemoryImage($src);
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $oMemoryImage); $this->assertInstanceOf('PHPWord_Section_MemoryImage', $oMemoryImage);
$this->assertEquals($oMemoryImage->getSource(), $src); $this->assertEquals($oMemoryImage->getSource(), $src);
$this->assertEquals($oMemoryImage->getMediaId(), md5($src)); $this->assertEquals($oMemoryImage->getMediaId(), md5($src));
$this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefromjpeg'); $this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefromjpeg');
$this->assertEquals($oMemoryImage->getImageFunction(), 'imagejpeg'); $this->assertEquals($oMemoryImage->getImageFunction(), 'imagejpeg');
$this->assertEquals($oMemoryImage->getImageExtension(), 'jpg'); $this->assertEquals($oMemoryImage->getImageExtension(), 'jpg');
$this->assertEquals($oMemoryImage->getImageType(), 'image/jpeg'); $this->assertEquals($oMemoryImage->getImageType(), 'image/jpeg');
} }
public function testBMP() { public function testBMP()
$oMemoryImage = new PHPWord_Section_MemoryImage(\join( {
\DIRECTORY_SEPARATOR, $oMemoryImage = new PHPWord_Section_MemoryImage(\join(
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'duke_nukem.bmp') \DIRECTORY_SEPARATOR,
)); array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'duke_nukem.bmp')
));
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $oMemoryImage); $this->assertInstanceOf('PHPWord_Section_MemoryImage', $oMemoryImage);
$this->assertEquals($oMemoryImage->getImageCreateFunction(), null); $this->assertEquals($oMemoryImage->getImageCreateFunction(), null);
$this->assertEquals($oMemoryImage->getImageFunction(), null); $this->assertEquals($oMemoryImage->getImageFunction(), null);
$this->assertEquals($oMemoryImage->getImageExtension(), null); $this->assertEquals($oMemoryImage->getImageExtension(), null);
$this->assertEquals($oMemoryImage->getImageType(), 'image/x-ms-bmp'); $this->assertEquals($oMemoryImage->getImageType(), 'image/x-ms-bmp');
} }
public function testStyle(){ public function testStyle()
$oMemoryImage = new PHPWord_Section_MemoryImage(\join( {
\DIRECTORY_SEPARATOR, $oMemoryImage = new PHPWord_Section_MemoryImage(\join(
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') \DIRECTORY_SEPARATOR,
), array('width'=>210, 'height'=>210, 'align'=>'center')); array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
), array('width' => 210, 'height' => 210, 'align' => 'center'));
$this->assertInstanceOf('PHPWord_Style_Image', $oMemoryImage->getStyle()); $this->assertInstanceOf('PHPWord_Style_Image', $oMemoryImage->getStyle());
} }
public function testRelationID(){ public function testRelationID()
$oMemoryImage = new PHPWord_Section_MemoryImage(\join( {
\DIRECTORY_SEPARATOR, $oMemoryImage = new PHPWord_Section_MemoryImage(\join(
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') \DIRECTORY_SEPARATOR,
)); array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
));
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oMemoryImage->setRelationId($iVal); $oMemoryImage->setRelationId($iVal);
$this->assertEquals($oMemoryImage->getRelationId(), $iVal); $this->assertEquals($oMemoryImage->getRelationId(), $iVal);
} }
} }

View File

@ -1,79 +1,86 @@
<?php <?php
namespace PHPWord\Tests; namespace PHPWord\Tests\Section;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
use PHPWord_Section_Object; use PHPWord_Section_Object;
class PHPWord_Section_ObjectTest extends \PHPUnit_Framework_TestCase { class ObjectTest extends \PHPUnit_Framework_TestCase
public function testConstructWithSupportedFiles() { {
$src = \join( public function testConstructWithSupportedFiles()
\DIRECTORY_SEPARATOR, {
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') $src = \join(
); \DIRECTORY_SEPARATOR,
$oObject = new PHPWord_Section_Object($src); array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
);
$oObject = new PHPWord_Section_Object($src);
$this->assertInstanceOf('PHPWord_Section_Object', $oObject); $this->assertInstanceOf('PHPWord_Section_Object', $oObject);
$this->assertInstanceOf('PHPWord_Style_Image', $oObject->getStyle()); $this->assertInstanceOf('PHPWord_Style_Image', $oObject->getStyle());
$this->assertEquals($oObject->getSource(), $src); $this->assertEquals($oObject->getSource(), $src);
} }
public function testConstructWithNotSupportedFiles() {
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'xsl', 'passthrough.xsl')
);
$oObject = new PHPWord_Section_Object($src);
$this->assertInstanceOf('PHPWord_Section_Object', $oObject); public function testConstructWithNotSupportedFiles()
$this->assertEquals($oObject->getSource(), null); {
$this->assertEquals($oObject->getStyle(), null); $src = \join(
} \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'xsl', 'passthrough.xsl')
);
$oObject = new PHPWord_Section_Object($src);
public function testConstructWithSupportedFilesAndStyle() { $this->assertInstanceOf('PHPWord_Section_Object', $oObject);
$src = \join( $this->assertEquals($oObject->getSource(), null);
\DIRECTORY_SEPARATOR, $this->assertEquals($oObject->getStyle(), null);
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') }
);
$oObject = new PHPWord_Section_Object($src, array('width' => '230px'));
$this->assertInstanceOf('PHPWord_Section_Object', $oObject); public function testConstructWithSupportedFilesAndStyle()
$this->assertInstanceOf('PHPWord_Style_Image', $oObject->getStyle()); {
$this->assertEquals($oObject->getSource(), $src); $src = \join(
} \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
);
$oObject = new PHPWord_Section_Object($src, array('width' => '230px'));
public function testRelationId(){ $this->assertInstanceOf('PHPWord_Section_Object', $oObject);
$src = \join( $this->assertInstanceOf('PHPWord_Style_Image', $oObject->getStyle());
\DIRECTORY_SEPARATOR, $this->assertEquals($oObject->getSource(), $src);
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') }
);
$oObject = new PHPWord_Section_Object($src);
$iVal = rand(1, 1000); public function testRelationId()
$oObject->setRelationId($iVal); {
$this->assertEquals($oObject->getRelationId(), $iVal); $src = \join(
} \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
);
$oObject = new PHPWord_Section_Object($src);
public function testImageRelationId(){ $iVal = rand(1, 1000);
$src = \join( $oObject->setRelationId($iVal);
\DIRECTORY_SEPARATOR, $this->assertEquals($oObject->getRelationId(), $iVal);
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') }
);
$oObject = new PHPWord_Section_Object($src);
$iVal = rand(1, 1000); public function testImageRelationId()
$oObject->setImageRelationId($iVal); {
$this->assertEquals($oObject->getImageRelationId(), $iVal); $src = \join(
} \DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
);
$oObject = new PHPWord_Section_Object($src);
public function testObjectId(){ $iVal = rand(1, 1000);
$src = \join( $oObject->setImageRelationId($iVal);
\DIRECTORY_SEPARATOR, $this->assertEquals($oObject->getImageRelationId(), $iVal);
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') }
);
$oObject = new PHPWord_Section_Object($src);
$iVal = rand(1, 1000); public function testObjectId()
$oObject->setObjectId($iVal); {
$this->assertEquals($oObject->getObjectId(), $iVal); $src = \join(
} \DIRECTORY_SEPARATOR,
} array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
);
$oObject = new PHPWord_Section_Object($src);
$iVal = rand(1, 1000);
$oObject->setObjectId($iVal);
$this->assertEquals($oObject->getObjectId(), $iVal);
}
}

View File

@ -1,18 +1,19 @@
<?php <?php
namespace PHPWord\Tests; namespace PHPWord\Tests\Section;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
use PHPWord_Section_PageBreak; use PHPWord_Section_PageBreak;
class PHPWord_Section_PageBreakTest extends \PHPUnit_Framework_TestCase { class PageBreakTest extends \PHPUnit_Framework_TestCase
/** {
* Executed before each method of the class /**
*/ * Executed before each method of the class
public function testConstruct() { */
// Section Settings public function testConstruct()
$oPageBreak = new PHPWord_Section_PageBreak(); {
// Section Settings
$oPageBreak = new PHPWord_Section_PageBreak();
$this->assertInstanceOf('PHPWord_Section_PageBreak', $oPageBreak); $this->assertInstanceOf('PHPWord_Section_PageBreak', $oPageBreak);
} }
} }

View File

@ -1,224 +1,236 @@
<?php <?php
namespace PHPWord\Tests; namespace PHPWord\Tests\Section;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
use PHPWord_Section_Settings; use PHPWord_Section_Settings;
class PHPWord_Section_SettingsTest extends \PHPUnit_Framework_TestCase { class SettingsTest extends \PHPUnit_Framework_TestCase
/** {
* Executed before each method of the class /**
*/ * Executed before each method of the class
public function testSettingValue() { */
// Section Settings public function testSettingValue()
$oSettings = new PHPWord_Section_Settings(); {
// Section Settings
$oSettings = new PHPWord_Section_Settings();
$oSettings->setSettingValue('_orientation', 'landscape'); $oSettings->setSettingValue('_orientation', 'landscape');
$this->assertEquals($oSettings->getOrientation(), 'landscape'); $this->assertEquals('landscape', $oSettings->getOrientation());
$this->assertEquals($oSettings->getPageSizeW(), 16838); $this->assertEquals(16838, $oSettings->getPageSizeW());
$this->assertEquals($oSettings->getPageSizeH(), 11906); $this->assertEquals(11906, $oSettings->getPageSizeH());
$oSettings->setSettingValue('_orientation', null); $oSettings->setSettingValue('_orientation', null);
$this->assertEquals($oSettings->getOrientation(), null); $this->assertNull($oSettings->getOrientation());
$this->assertEquals($oSettings->getPageSizeW(), 11906); $this->assertEquals(11906, $oSettings->getPageSizeW());
$this->assertEquals($oSettings->getPageSizeH(), 16838); $this->assertEquals(16838, $oSettings->getPageSizeH());
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oSettings->setSettingValue('_borderSize', $iVal); $oSettings->setSettingValue('_borderSize', $iVal);
$this->assertEquals($oSettings->getBorderSize(), array($iVal, $iVal, $iVal, $iVal)); $this->assertEquals(array($iVal, $iVal, $iVal, $iVal), $oSettings->getBorderSize());
$this->assertEquals($oSettings->getBorderBottomSize(), $iVal); $this->assertEquals($iVal, $oSettings->getBorderBottomSize());
$this->assertEquals($oSettings->getBorderLeftSize(), $iVal); $this->assertEquals($iVal, $oSettings->getBorderLeftSize());
$this->assertEquals($oSettings->getBorderRightSize(), $iVal); $this->assertEquals($iVal, $oSettings->getBorderRightSize());
$this->assertEquals($oSettings->getBorderTopSize(), $iVal); $this->assertEquals($iVal, $oSettings->getBorderTopSize());
$oSettings->setSettingValue('_borderColor', 'FF00AA'); $oSettings->setSettingValue('_borderColor', 'FF00AA');
$this->assertEquals($oSettings->getBorderColor(), array('FF00AA', 'FF00AA', 'FF00AA', 'FF00AA')); $this->assertEquals(array('FF00AA', 'FF00AA', 'FF00AA', 'FF00AA'), $oSettings->getBorderColor());
$this->assertEquals($oSettings->getBorderBottomColor(), 'FF00AA'); $this->assertEquals('FF00AA', $oSettings->getBorderBottomColor());
$this->assertEquals($oSettings->getBorderLeftColor(), 'FF00AA'); $this->assertEquals('FF00AA', $oSettings->getBorderLeftColor());
$this->assertEquals($oSettings->getBorderRightColor(), 'FF00AA'); $this->assertEquals('FF00AA', $oSettings->getBorderRightColor());
$this->assertEquals($oSettings->getBorderTopColor(), 'FF00AA'); $this->assertEquals('FF00AA', $oSettings->getBorderTopColor());
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oSettings->setSettingValue('headerHeight', $iVal); $oSettings->setSettingValue('headerHeight', $iVal);
$this->assertEquals($oSettings->getHeaderHeight(), $iVal); $this->assertEquals($iVal, $oSettings->getHeaderHeight());
} }
public function testMargin(){ public function testMargin()
// Section Settings {
$oSettings = new PHPWord_Section_Settings(); // Section Settings
$oSettings = new PHPWord_Section_Settings();
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oSettings->setMarginTop($iVal); $oSettings->setMarginTop($iVal);
$this->assertEquals($oSettings->getMarginTop(), $iVal); $this->assertEquals($iVal, $oSettings->getMarginTop());
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oSettings->setMarginBottom($iVal); $oSettings->setMarginBottom($iVal);
$this->assertEquals($oSettings->getMarginBottom(), $iVal); $this->assertEquals($iVal, $oSettings->getMarginBottom());
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oSettings->setMarginLeft($iVal); $oSettings->setMarginLeft($iVal);
$this->assertEquals($oSettings->getMarginLeft(), $iVal); $this->assertEquals($iVal, $oSettings->getMarginLeft());
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oSettings->setMarginRight($iVal); $oSettings->setMarginRight($iVal);
$this->assertEquals($oSettings->getMarginRight(), $iVal); $this->assertEquals($iVal, $oSettings->getMarginRight());
} }
public function testOrientationLandscape(){ public function testOrientationLandscape()
// Section Settings {
$oSettings = new PHPWord_Section_Settings(); // Section Settings
$oSettings = new PHPWord_Section_Settings();
$oSettings->setLandscape(); $oSettings->setLandscape();
$this->assertEquals($oSettings->getOrientation(), 'landscape'); $this->assertEquals('landscape', $oSettings->getOrientation());
$this->assertEquals($oSettings->getPageSizeW(), 16838); $this->assertEquals(16838, $oSettings->getPageSizeW());
$this->assertEquals($oSettings->getPageSizeH(), 11906); $this->assertEquals(11906, $oSettings->getPageSizeH());
} }
public function testOrientationPortrait(){ public function testOrientationPortrait()
// Section Settings {
$oSettings = new PHPWord_Section_Settings(); // Section Settings
$oSettings = new PHPWord_Section_Settings();
$oSettings->setPortrait(); $oSettings->setPortrait();
$this->assertEquals($oSettings->getOrientation(), null); $this->assertNull($oSettings->getOrientation());
$this->assertEquals($oSettings->getPageSizeW(), 11906); $this->assertEquals(11906, $oSettings->getPageSizeW());
$this->assertEquals($oSettings->getPageSizeH(), 16838); $this->assertEquals(16838, $oSettings->getPageSizeH());
} }
public function testBorderSize(){ public function testBorderSize()
// Section Settings {
$oSettings = new PHPWord_Section_Settings(); // Section Settings
$oSettings = new PHPWord_Section_Settings();
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oSettings->setBorderSize($iVal); $oSettings->setBorderSize($iVal);
$this->assertEquals($oSettings->getBorderSize(), array($iVal, $iVal, $iVal, $iVal)); $this->assertEquals(array($iVal, $iVal, $iVal, $iVal), $oSettings->getBorderSize());
$this->assertEquals($oSettings->getBorderBottomSize(), $iVal); $this->assertEquals($iVal, $oSettings->getBorderBottomSize());
$this->assertEquals($oSettings->getBorderLeftSize(), $iVal); $this->assertEquals($iVal, $oSettings->getBorderLeftSize());
$this->assertEquals($oSettings->getBorderRightSize(), $iVal); $this->assertEquals($iVal, $oSettings->getBorderRightSize());
$this->assertEquals($oSettings->getBorderTopSize(), $iVal); $this->assertEquals($iVal, $oSettings->getBorderTopSize());
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oSettings->setBorderBottomSize($iVal); $oSettings->setBorderBottomSize($iVal);
$this->assertEquals($oSettings->getBorderBottomSize(), $iVal); $this->assertEquals($iVal, $oSettings->getBorderBottomSize());
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oSettings->setBorderLeftSize($iVal); $oSettings->setBorderLeftSize($iVal);
$this->assertEquals($oSettings->getBorderLeftSize(), $iVal); $this->assertEquals($iVal, $oSettings->getBorderLeftSize());
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oSettings->setBorderRightSize($iVal); $oSettings->setBorderRightSize($iVal);
$this->assertEquals($oSettings->getBorderRightSize(), $iVal); $this->assertEquals($iVal, $oSettings->getBorderRightSize());
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oSettings->setBorderTopSize($iVal); $oSettings->setBorderTopSize($iVal);
$this->assertEquals($oSettings->getBorderTopSize(), $iVal); $this->assertEquals($iVal, $oSettings->getBorderTopSize());
} }
public function testBorderColor(){ public function testBorderColor()
// Section Settings {
$oSettings = new PHPWord_Section_Settings(); // Section Settings
$oSettings = new PHPWord_Section_Settings();
$oSettings->setBorderColor('FF00AA'); $oSettings->setBorderColor('FF00AA');
$this->assertEquals($oSettings->getBorderColor(), array('FF00AA', 'FF00AA', 'FF00AA', 'FF00AA')); $this->assertEquals(array('FF00AA', 'FF00AA', 'FF00AA', 'FF00AA'), $oSettings->getBorderColor());
$this->assertEquals($oSettings->getBorderBottomColor(), 'FF00AA'); $this->assertEquals('FF00AA', $oSettings->getBorderBottomColor());
$this->assertEquals($oSettings->getBorderLeftColor(), 'FF00AA'); $this->assertEquals('FF00AA', $oSettings->getBorderLeftColor());
$this->assertEquals($oSettings->getBorderRightColor(), 'FF00AA'); $this->assertEquals('FF00AA', $oSettings->getBorderRightColor());
$this->assertEquals($oSettings->getBorderTopColor(), 'FF00AA'); $this->assertEquals('FF00AA', $oSettings->getBorderTopColor());
$oSettings->setBorderBottomColor('BBCCDD'); $oSettings->setBorderBottomColor('BBCCDD');
$this->assertEquals($oSettings->getBorderBottomColor(), 'BBCCDD'); $this->assertEquals('BBCCDD', $oSettings->getBorderBottomColor());
$oSettings->setBorderLeftColor('CCDDEE'); $oSettings->setBorderLeftColor('CCDDEE');
$this->assertEquals($oSettings->getBorderLeftColor(), 'CCDDEE'); $this->assertEquals('CCDDEE', $oSettings->getBorderLeftColor());
$oSettings->setBorderRightColor('11EE22'); $oSettings->setBorderRightColor('11EE22');
$this->assertEquals($oSettings->getBorderRightColor(), '11EE22'); $this->assertEquals('11EE22', $oSettings->getBorderRightColor());
$oSettings->setBorderTopColor('22FF33'); $oSettings->setBorderTopColor('22FF33');
$this->assertEquals($oSettings->getBorderTopColor(), '22FF33'); $this->assertEquals('22FF33', $oSettings->getBorderTopColor());
} }
public function testNumberingStart(){ public function testNumberingStart()
// Section Settings {
$oSettings = new PHPWord_Section_Settings(); // Section Settings
$oSettings = new PHPWord_Section_Settings();
$this->assertEquals($oSettings->getPageNumberingStart(), null); $this->assertNull($oSettings->getPageNumberingStart());
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oSettings->setPageNumberingStart($iVal); $oSettings->setPageNumberingStart($iVal);
$this->assertEquals($oSettings->getPageNumberingStart(), $iVal); $this->assertEquals($iVal, $oSettings->getPageNumberingStart());
$oSettings->setPageNumberingStart(); $oSettings->setPageNumberingStart();
$this->assertEquals($oSettings->getPageNumberingStart(), null); $this->assertNull($oSettings->getPageNumberingStart());
} }
public function testHeader(){ public function testHeader()
// Section Settings {
$oSettings = new PHPWord_Section_Settings(); // Section Settings
$oSettings = new PHPWord_Section_Settings();
$this->assertEquals($oSettings->getHeaderHeight(), 720); $this->assertEquals(720, $oSettings->getHeaderHeight());
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oSettings->setHeaderHeight($iVal); $oSettings->setHeaderHeight($iVal);
$this->assertEquals($oSettings->getHeaderHeight(), $iVal); $this->assertEquals($iVal, $oSettings->getHeaderHeight());
$oSettings->setHeaderHeight(); $oSettings->setHeaderHeight();
$this->assertEquals($oSettings->getHeaderHeight(), 720); $this->assertEquals(720, $oSettings->getHeaderHeight());
} }
public function testFooter(){ public function testFooter()
// Section Settings {
$oSettings = new PHPWord_Section_Settings(); // Section Settings
$oSettings = new PHPWord_Section_Settings();
$this->assertEquals($oSettings->getFooterHeight(), 720); $this->assertEquals(720, $oSettings->getFooterHeight());
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oSettings->setFooterHeight($iVal); $oSettings->setFooterHeight($iVal);
$this->assertEquals($oSettings->getFooterHeight(), $iVal); $this->assertEquals($iVal, $oSettings->getFooterHeight());
$oSettings->setFooterHeight(); $oSettings->setFooterHeight();
$this->assertEquals($oSettings->getFooterHeight(), 720); $this->assertEquals(720, $oSettings->getFooterHeight());
} }
public function testColumnsNum(){ public function testColumnsNum()
// Section Settings {
$oSettings = new PHPWord_Section_Settings(); // Section Settings
$oSettings = new PHPWord_Section_Settings();
// Default // Default
$this->assertEquals($oSettings->getColsNum(), 1); $this->assertEquals(1, $oSettings->getColsNum());
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oSettings->setColsNum($iVal); $oSettings->setColsNum($iVal);
$this->assertEquals($oSettings->getColsNum(), $iVal); $this->assertEquals($iVal, $oSettings->getColsNum());
$oSettings->setColsNum(); $oSettings->setColsNum();
$this->assertEquals($oSettings->getColsNum(), 1); $this->assertEquals(1, $oSettings->getColsNum());
} }
public function testColumnsSpace(){ public function testColumnsSpace()
// Section Settings {
$oSettings = new PHPWord_Section_Settings(); // Section Settings
$oSettings = new PHPWord_Section_Settings();
// Default // Default
$this->assertEquals($oSettings->getColsSpace(), 720); $this->assertEquals(720, $oSettings->getColsSpace());
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$this->assertInstanceOf('PHPWord_Section_Settings', $oSettings->setColsSpace($iVal)); $this->assertInstanceOf('PHPWord_Section_Settings', $oSettings->setColsSpace($iVal));
$this->assertEquals($oSettings->getColsSpace(), $iVal); $this->assertEquals($iVal, $oSettings->getColsSpace());
$this->assertInstanceOf('PHPWord_Section_Settings', $oSettings->setColsSpace()); $this->assertInstanceOf('PHPWord_Section_Settings', $oSettings->setColsSpace());
$this->assertEquals($oSettings->getColsSpace(), 1); $this->assertEquals(1, $oSettings->getColsSpace());
} }
public function testBreakType(){ public function testBreakType()
// Section Settings {
$oSettings = new PHPWord_Section_Settings(); // Section Settings
$oSettings = new PHPWord_Section_Settings();
$this->assertEquals($oSettings->getBreakType(), null); $this->assertNull($oSettings->getBreakType());
$oSettings->setBreakType('continuous'); $oSettings->setBreakType('continuous');
$this->assertEquals($oSettings->getBreakType(), 'continuous'); $this->assertEquals('continuous', $oSettings->getBreakType());
$oSettings->setBreakType(); $oSettings->setBreakType();
$this->assertEquals($oSettings->getBreakType(), null); $this->assertNull($oSettings->getBreakType());
} }
} }

View File

@ -1,184 +1,204 @@
<?php <?php
namespace PHPWord\Tests; namespace PHPWord\Tests\Section\Table;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
use PHPWord_Section_Table_Cell; use PHPWord_Section_Table_Cell;
class PHPWord_Section_Table_CellTest extends \PHPUnit_Framework_TestCase { class CellTest extends \PHPUnit_Framework_TestCase
public function testConstruct(){ {
$iVal = rand(1, 1000); public function testConstruct()
$oCell = new PHPWord_Section_Table_Cell('section', $iVal); {
$iVal = rand(1, 1000);
$oCell = new PHPWord_Section_Table_Cell('section', $iVal);
$this->assertInstanceOf('PHPWord_Section_Table_Cell', $oCell); $this->assertInstanceOf('PHPWord_Section_Table_Cell', $oCell);
$this->assertEquals($oCell->getWidth(), null); $this->assertEquals($oCell->getWidth(), null);
} }
public function testConstructWithStyleArray(){ public function testConstructWithStyleArray()
$iVal = rand(1, 1000); {
$oCell = new PHPWord_Section_Table_Cell('section', $iVal, null, array('valign'=>'center')); $iVal = rand(1, 1000);
$oCell = new PHPWord_Section_Table_Cell('section', $iVal, null, array('valign' => 'center'));
$this->assertInstanceOf('PHPWord_Style_Cell', $oCell->getStyle()); $this->assertInstanceOf('PHPWord_Style_Cell', $oCell->getStyle());
$this->assertEquals($oCell->getWidth(), null); $this->assertEquals($oCell->getWidth(), null);
} }
public function testConstructWithStyleString(){ public function testConstructWithStyleString()
$iVal = rand(1, 1000); {
$oCell = new PHPWord_Section_Table_Cell('section', $iVal, null, 'cellStyle'); $iVal = rand(1, 1000);
$oCell = new PHPWord_Section_Table_Cell('section', $iVal, null, 'cellStyle');
$this->assertEquals($oCell->getStyle(), 'cellStyle'); $this->assertEquals($oCell->getStyle(), 'cellStyle');
} }
public function testAddText(){ public function testAddText()
$oCell = new PHPWord_Section_Table_Cell('section', 1); {
$element = $oCell->addText('text'); $oCell = new PHPWord_Section_Table_Cell('section', 1);
$element = $oCell->addText('text');
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Text', $element); $this->assertInstanceOf('PHPWord_Section_Text', $element);
} }
public function testAddTextNotUTF8(){ public function testAddTextNotUTF8()
$oCell = new PHPWord_Section_Table_Cell('section', 1); {
$element = $oCell->addText(utf8_decode('ééé')); $oCell = new PHPWord_Section_Table_Cell('section', 1);
$element = $oCell->addText(utf8_decode('ééé'));
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Text', $element); $this->assertInstanceOf('PHPWord_Section_Text', $element);
$this->assertEquals($element->getText(), 'ééé'); $this->assertEquals($element->getText(), 'ééé');
} }
public function testAddLink(){ public function testAddLink()
$oCell = new PHPWord_Section_Table_Cell('section', 1); {
$element = $oCell->addLink('http://www.google.fr', 'Nom'); $oCell = new PHPWord_Section_Table_Cell('section', 1);
$element = $oCell->addLink('http://www.google.fr', 'Nom');
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Link', $element); $this->assertInstanceOf('PHPWord_Section_Link', $element);
} }
public function testAddTextBreak(){ public function testAddTextBreak()
$oCell = new PHPWord_Section_Table_Cell('section', 1); {
$oCell->addTextBreak(); $oCell = new PHPWord_Section_Table_Cell('section', 1);
$oCell->addTextBreak();
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
} }
public function testAddListItem(){ public function testAddListItem()
$oCell = new PHPWord_Section_Table_Cell('section', 1); {
$element = $oCell->addListItem('text'); $oCell = new PHPWord_Section_Table_Cell('section', 1);
$element = $oCell->addListItem('text');
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_ListItem', $element); $this->assertInstanceOf('PHPWord_Section_ListItem', $element);
$this->assertEquals($element->getTextObject()->getText(), 'text'); $this->assertEquals($element->getTextObject()->getText(), 'text');
} }
public function testAddListItemNotUTF8(){ public function testAddListItemNotUTF8()
$oCell = new PHPWord_Section_Table_Cell('section', 1); {
$element = $oCell->addListItem(utf8_decode('ééé')); $oCell = new PHPWord_Section_Table_Cell('section', 1);
$element = $oCell->addListItem(utf8_decode('ééé'));
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_ListItem', $element); $this->assertInstanceOf('PHPWord_Section_ListItem', $element);
$this->assertEquals($element->getTextObject()->getText(), 'ééé'); $this->assertEquals($element->getTextObject()->getText(), 'ééé');
} }
public function testAddImageSection(){ public function testAddImageSection()
$src = \join( {
\DIRECTORY_SEPARATOR, $src = \join(
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') \DIRECTORY_SEPARATOR,
); array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
$oCell = new PHPWord_Section_Table_Cell('section', 1); );
$element = $oCell->addImage($src); $oCell = new PHPWord_Section_Table_Cell('section', 1);
$element = $oCell->addImage($src);
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Image', $element); $this->assertInstanceOf('PHPWord_Section_Image', $element);
} }
public function testAddImageHeader(){ public function testAddImageHeader()
$src = \join( {
\DIRECTORY_SEPARATOR, $src = \join(
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') \DIRECTORY_SEPARATOR,
); array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
$oCell = new PHPWord_Section_Table_Cell('header', 1); );
$element = $oCell->addImage($src); $oCell = new PHPWord_Section_Table_Cell('header', 1);
$element = $oCell->addImage($src);
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Image', $element); $this->assertInstanceOf('PHPWord_Section_Image', $element);
} }
public function testAddImageFooter(){ public function testAddImageFooter()
$src = \join( {
\DIRECTORY_SEPARATOR, $src = \join(
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') \DIRECTORY_SEPARATOR,
); array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
$oCell = new PHPWord_Section_Table_Cell('footer', 1); );
$element = $oCell->addImage($src); $oCell = new PHPWord_Section_Table_Cell('footer', 1);
$element = $oCell->addImage($src);
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Image', $element); $this->assertInstanceOf('PHPWord_Section_Image', $element);
} }
public function testAddMemoryImageSection(){ public function testAddMemoryImageSection()
$oCell = new PHPWord_Section_Table_Cell('section', 1); {
$element = $oCell->addMemoryImage('https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'); $oCell = new PHPWord_Section_Table_Cell('section', 1);
$element = $oCell->addMemoryImage('https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png');
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element); $this->assertInstanceOf('PHPWord_Section_MemoryImage', $element);
} }
public function testAddMemoryImageHeader(){ public function testAddMemoryImageHeader()
$oCell = new PHPWord_Section_Table_Cell('header', 1); {
$element = $oCell->addMemoryImage('https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'); $oCell = new PHPWord_Section_Table_Cell('header', 1);
$element = $oCell->addMemoryImage('https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png');
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element); $this->assertInstanceOf('PHPWord_Section_MemoryImage', $element);
} }
public function testAddMemoryImageFooter(){ public function testAddMemoryImageFooter()
$oCell = new PHPWord_Section_Table_Cell('footer', 1); {
$element = $oCell->addMemoryImage('https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'); $oCell = new PHPWord_Section_Table_Cell('footer', 1);
$element = $oCell->addMemoryImage('https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png');
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element); $this->assertInstanceOf('PHPWord_Section_MemoryImage', $element);
} }
public function testAddObjectXLS(){ public function testAddObjectXLS()
$src = \join( {
\DIRECTORY_SEPARATOR, $src = \join(
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') \DIRECTORY_SEPARATOR,
); array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
$oCell = new PHPWord_Section_Table_Cell('section', 1); );
$element = $oCell->addObject($src); $oCell = new PHPWord_Section_Table_Cell('section', 1);
$element = $oCell->addObject($src);
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Object', $element); $this->assertInstanceOf('PHPWord_Section_Object', $element);
} }
public function testAddPreserveText(){ public function testAddPreserveText()
$oCell = new PHPWord_Section_Table_Cell('header', 1); {
$element = $oCell->addPreserveText('text'); $oCell = new PHPWord_Section_Table_Cell('header', 1);
$element = $oCell->addPreserveText('text');
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); $this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element);
} }
public function testAddPreserveTextNotUTF8(){ public function testAddPreserveTextNotUTF8()
$oCell = new PHPWord_Section_Table_Cell('header', 1); {
$element = $oCell->addPreserveText(utf8_decode('ééé')); $oCell = new PHPWord_Section_Table_Cell('header', 1);
$element = $oCell->addPreserveText(utf8_decode('ééé'));
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); $this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element);
$this->assertEquals($element->getText(), 'ééé'); $this->assertEquals($element->getText(), 'ééé');
} }
public function testCreateTextRun(){ public function testCreateTextRun()
$oCell = new PHPWord_Section_Table_Cell('section', 1); {
$element = $oCell->createTextRun(); $oCell = new PHPWord_Section_Table_Cell('section', 1);
$element = $oCell->createTextRun();
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_TextRun', $element); $this->assertInstanceOf('PHPWord_Section_TextRun', $element);
} }
public function testGetElements(){ public function testGetElements()
$oCell = new PHPWord_Section_Table_Cell('section', 1); {
$oCell = new PHPWord_Section_Table_Cell('section', 1);
$this->assertInternalType('array', $oCell->getElements()); $this->assertInternalType('array', $oCell->getElements());
} }
} }

View File

@ -1,35 +1,39 @@
<?php <?php
namespace PHPWord\Tests; namespace PHPWord\Tests\Section\Table;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
use PHPWord_Section_Table_Row; use PHPWord_Section_Table_Row;
class PHPWord_Section_Table_RowTest extends \PHPUnit_Framework_TestCase { class RowTest extends \PHPUnit_Framework_TestCase
public function testConstruct(){ {
$iVal = rand(1, 1000); public function testConstruct()
$oRow = new PHPWord_Section_Table_Row('section', $iVal); {
$iVal = rand(1, 1000);
$oRow = new PHPWord_Section_Table_Row('section', $iVal);
$this->assertInstanceOf('PHPWord_Section_Table_Row', $oRow); $this->assertInstanceOf('PHPWord_Section_Table_Row', $oRow);
$this->assertEquals($oRow->getHeight(), null); $this->assertEquals($oRow->getHeight(), null);
$this->assertInternalType('array', $oRow->getCells()); $this->assertInternalType('array', $oRow->getCells());
$this->assertCount(0, $oRow->getCells()); $this->assertCount(0, $oRow->getCells());
$this->assertInstanceOf('PHPWord_Style_Row', $oRow->getStyle()); $this->assertInstanceOf('PHPWord_Style_Row', $oRow->getStyle());
} }
public function testConstructWithParams(){
$iVal = rand(1, 1000);
$iVal2 = rand(1, 1000);
$oRow = new PHPWord_Section_Table_Row('section', $iVal, $iVal2, array('borderBottomSize'=>18, 'borderBottomColor'=>'0000FF', 'bgColor'=>'66BBFF'));
$this->assertEquals($oRow->getHeight(), $iVal2); public function testConstructWithParams()
$this->assertInstanceOf('PHPWord_Style_Row', $oRow->getStyle()); {
} $iVal = rand(1, 1000);
$iVal2 = rand(1, 1000);
$oRow = new PHPWord_Section_Table_Row('section', $iVal, $iVal2, array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF'));
public function testAddCell(){ $this->assertEquals($oRow->getHeight(), $iVal2);
$oRow = new PHPWord_Section_Table_Row('section', 1); $this->assertInstanceOf('PHPWord_Style_Row', $oRow->getStyle());
$element = $oRow->addCell(); }
$this->assertInstanceOf('PHPWord_Section_Table_Cell', $element); public function testAddCell()
$this->assertCount(1, $oRow->getCells()); {
} $oRow = new PHPWord_Section_Table_Row('section', 1);
} $element = $oRow->addCell();
$this->assertInstanceOf('PHPWord_Section_Table_Cell', $element);
$this->assertCount(1, $oRow->getCells());
}
}

View File

@ -1,46 +1,57 @@
<?php <?php
namespace PHPWord\Tests; namespace PHPWord\Tests\Section;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
use PHPWord_Section_Table; use PHPWord_Section_Table;
class PHPWord_Section_TableTest extends \PHPUnit_Framework_TestCase { class TableTest extends \PHPUnit_Framework_TestCase
public function testConstruct() { {
$oTable = new PHPWord_Section_Table('section', 1); public function testConstruct()
{
$oTable = new PHPWord_Section_Table('section', 1);
$this->assertInstanceOf('PHPWord_Section_Table', $oTable); $this->assertInstanceOf('PHPWord_Section_Table', $oTable);
$this->assertEquals($oTable->getStyle(), null); $this->assertEquals($oTable->getStyle(), null);
$this->assertEquals($oTable->getWidth(), null); $this->assertEquals($oTable->getWidth(), null);
$this->assertEquals($oTable->getRows(), array()); $this->assertEquals($oTable->getRows(), array());
$this->assertCount(0, $oTable->getRows()); $this->assertCount(0, $oTable->getRows());
} }
public function testStyleText() {
$oTable = new PHPWord_Section_Table('section', 1, 'tableStyle');
$this->assertEquals($oTable->getStyle(), 'tableStyle'); public function testStyleText()
} {
public function testStyleArray() { $oTable = new PHPWord_Section_Table('section', 1, 'tableStyle');
$oTable = new PHPWord_Section_Table('section', 1, array('borderSize'=>6, 'borderColor'=>'006699', 'cellMargin'=>80));
$this->assertInstanceOf('PHPWord_Style_Table', $oTable->getStyle()); $this->assertEquals($oTable->getStyle(), 'tableStyle');
} }
public function testWidth() {
$oTable = new PHPWord_Section_Table('section', 1); public function testStyleArray()
$iVal = rand(1, 1000); {
$oTable->setWidth($iVal); $oTable = new PHPWord_Section_Table('section', 1, array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80));
$this->assertEquals($oTable->getWidth(), $iVal);
} $this->assertInstanceOf('PHPWord_Style_Table', $oTable->getStyle());
public function testRow() { }
$oTable = new PHPWord_Section_Table('section', 1);
$element = $oTable->addRow(); public function testWidth()
$this->assertInstanceOf('PHPWord_Section_Table_Row', $element); {
$this->assertCount(1, $oTable->getRows()); $oTable = new PHPWord_Section_Table('section', 1);
} $iVal = rand(1, 1000);
public function testCell() { $oTable->setWidth($iVal);
$oTable = new PHPWord_Section_Table('section', 1); $this->assertEquals($oTable->getWidth(), $iVal);
$oTable->addRow(); }
$element = $oTable->addCell();
$this->assertInstanceOf('PHPWord_Section_Table_Cell', $element); public function testRow()
} {
} $oTable = new PHPWord_Section_Table('section', 1);
$element = $oTable->addRow();
$this->assertInstanceOf('PHPWord_Section_Table_Row', $element);
$this->assertCount(1, $oTable->getRows());
}
public function testCell()
{
$oTable = new PHPWord_Section_Table('section', 1);
$oTable->addRow();
$element = $oTable->addCell();
$this->assertInstanceOf('PHPWord_Section_Table_Cell', $element);
}
}

View File

@ -1,18 +1,19 @@
<?php <?php
namespace PHPWord\Tests; namespace PHPWord\Tests\Section;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
use PHPWord_Section_TextBreak; use PHPWord_Section_TextBreak;
class PHPWord_Section_TextBreakTest extends \PHPUnit_Framework_TestCase { class TextBreakTest extends \PHPUnit_Framework_TestCase
/** {
* Executed before each method of the class /**
*/ * Executed before each method of the class
public function testConstruct() { */
// Section Settings public function testConstruct()
$oTextBreak = new PHPWord_Section_TextBreak(); {
// Section Settings
$oTextBreak = new PHPWord_Section_TextBreak();
$this->assertInstanceOf('PHPWord_Section_TextBreak', $oTextBreak); $this->assertInstanceOf('PHPWord_Section_TextBreak', $oTextBreak);
} }
} }

View File

@ -1,81 +1,98 @@
<?php <?php
namespace PHPWord\Tests; namespace PHPWord\Tests\Section;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
use PHPWord_Section_TextRun; use PHPWord_Section_TextRun;
class PHPWord_Section_TextRunTest extends \PHPUnit_Framework_TestCase { class TextRunTest extends \PHPUnit_Framework_TestCase
public function testConstructNull() { {
$oTextRun = new PHPWord_Section_TextRun(); public function testConstructNull()
{
$oTextRun = new PHPWord_Section_TextRun();
$this->assertInstanceOf('PHPWord_Section_TextRun', $oTextRun); $this->assertInstanceOf('PHPWord_Section_TextRun', $oTextRun);
$this->assertCount(0, $oTextRun->getElements()); $this->assertCount(0, $oTextRun->getElements());
$this->assertEquals($oTextRun->getParagraphStyle(), null); $this->assertEquals($oTextRun->getParagraphStyle(), null);
} }
public function testConstructString() {
$oTextRun = new PHPWord_Section_TextRun('pStyle');
$this->assertInstanceOf('PHPWord_Section_TextRun', $oTextRun); public function testConstructString()
$this->assertCount(0, $oTextRun->getElements()); {
$this->assertEquals($oTextRun->getParagraphStyle(), 'pStyle'); $oTextRun = new PHPWord_Section_TextRun('pStyle');
}
public function testConstructArray() {
$oTextRun = new PHPWord_Section_TextRun(array('spacing'=>100));
$this->assertInstanceOf('PHPWord_Section_TextRun', $oTextRun); $this->assertInstanceOf('PHPWord_Section_TextRun', $oTextRun);
$this->assertCount(0, $oTextRun->getElements()); $this->assertCount(0, $oTextRun->getElements());
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oTextRun->getParagraphStyle()); $this->assertEquals($oTextRun->getParagraphStyle(), 'pStyle');
} }
public function testAddText() {
$oTextRun = new PHPWord_Section_TextRun();
$element = $oTextRun->addText('text');
$this->assertInstanceOf('PHPWord_Section_Text', $element); public function testConstructArray()
$this->assertCount(1, $oTextRun->getElements()); {
$this->assertEquals($element->getText(), 'text'); $oTextRun = new PHPWord_Section_TextRun(array('spacing' => 100));
}
public function testAddTextNotUTF8() {
$oTextRun = new PHPWord_Section_TextRun();
$element = $oTextRun->addText(utf8_decode('ééé'));
$this->assertInstanceOf('PHPWord_Section_Text', $element); $this->assertInstanceOf('PHPWord_Section_TextRun', $oTextRun);
$this->assertCount(1, $oTextRun->getElements()); $this->assertCount(0, $oTextRun->getElements());
$this->assertEquals($element->getText(), 'ééé'); $this->assertInstanceOf('PHPWord_Style_Paragraph', $oTextRun->getParagraphStyle());
} }
public function testAddLink() {
$oTextRun = new PHPWord_Section_TextRun();
$element = $oTextRun->addLink('http://www.google.fr');
$this->assertInstanceOf('PHPWord_Section_Link', $element); public function testAddText()
$this->assertCount(1, $oTextRun->getElements()); {
$this->assertEquals($element->getLinkSrc(), 'http://www.google.fr'); $oTextRun = new PHPWord_Section_TextRun();
} $element = $oTextRun->addText('text');
public function testAddLinkWithName() {
$oTextRun = new PHPWord_Section_TextRun();
$element = $oTextRun->addLink('http://www.google.fr', utf8_decode('ééé'));
$this->assertInstanceOf('PHPWord_Section_Link', $element); $this->assertInstanceOf('PHPWord_Section_Text', $element);
$this->assertCount(1, $oTextRun->getElements()); $this->assertCount(1, $oTextRun->getElements());
$this->assertEquals($element->getLinkSrc(), 'http://www.google.fr'); $this->assertEquals($element->getText(), 'text');
$this->assertEquals($element->getLinkName(), 'ééé'); }
}
public function testAddImage() {
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
);
$oTextRun = new PHPWord_Section_TextRun();
$element = $oTextRun->addImage($src);
$this->assertInstanceOf('PHPWord_Section_Image', $element); public function testAddTextNotUTF8()
$this->assertCount(1, $oTextRun->getElements()); {
} $oTextRun = new PHPWord_Section_TextRun();
public function testCreateFootnote() { $element = $oTextRun->addText(utf8_decode('ééé'));
$oTextRun = new PHPWord_Section_TextRun();
$element = $oTextRun->createFootnote();
$this->assertInstanceOf('PHPWord_Section_Footnote', $element); $this->assertInstanceOf('PHPWord_Section_Text', $element);
$this->assertCount(1, $oTextRun->getElements()); $this->assertCount(1, $oTextRun->getElements());
} $this->assertEquals($element->getText(), 'ééé');
} }
public function testAddLink()
{
$oTextRun = new PHPWord_Section_TextRun();
$element = $oTextRun->addLink('http://www.google.fr');
$this->assertInstanceOf('PHPWord_Section_Link', $element);
$this->assertCount(1, $oTextRun->getElements());
$this->assertEquals($element->getLinkSrc(), 'http://www.google.fr');
}
public function testAddLinkWithName()
{
$oTextRun = new PHPWord_Section_TextRun();
$element = $oTextRun->addLink('http://www.google.fr', utf8_decode('ééé'));
$this->assertInstanceOf('PHPWord_Section_Link', $element);
$this->assertCount(1, $oTextRun->getElements());
$this->assertEquals($element->getLinkSrc(), 'http://www.google.fr');
$this->assertEquals($element->getLinkName(), 'ééé');
}
public function testAddImage()
{
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
);
$oTextRun = new PHPWord_Section_TextRun();
$element = $oTextRun->addImage($src);
$this->assertInstanceOf('PHPWord_Section_Image', $element);
$this->assertCount(1, $oTextRun->getElements());
}
public function testCreateFootnote()
{
$oTextRun = new PHPWord_Section_TextRun();
$element = $oTextRun->createFootnote();
$this->assertInstanceOf('PHPWord_Section_Footnote', $element);
$this->assertCount(1, $oTextRun->getElements());
}
}

View File

@ -1,36 +1,43 @@
<?php <?php
namespace PHPWord\Tests; namespace PHPWord\Tests\Section;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
use PHPWord_Section_Text; use PHPWord_Section_Text;
class PHPWord_Section_TextTest extends \PHPUnit_Framework_TestCase { class TextTest extends \PHPUnit_Framework_TestCase
public function testConstruct() { {
$oText = new PHPWord_Section_Text(); public function testConstruct()
{
$oText = new PHPWord_Section_Text();
$this->assertInstanceOf('PHPWord_Section_Text', $oText); $this->assertInstanceOf('PHPWord_Section_Text', $oText);
$this->assertEquals($oText->getText(), null); $this->assertEquals(null, $oText->getText());
$this->assertEquals($oText->getFontStyle(), null); $this->assertInstanceOf('PHPWord_Style_Font', $oText->getFontStyle());
$this->assertEquals($oText->getParagraphStyle(), null); $this->assertInstanceOf('PHPWord_Style_Paragraph', $oText->getParagraphStyle());
} }
public function testText() {
$oText = new PHPWord_Section_Text('text');
$this->assertEquals($oText->getText(), 'text'); public function testText()
} {
public function testFont() { $oText = new PHPWord_Section_Text('text');
$oText = new PHPWord_Section_Text('text', 'fontStyle');
$this->assertEquals($oText->getFontStyle(), 'fontStyle');
$oText->setFontStyle(array('bold'=>true, 'italic'=>true, 'size'=>16)); $this->assertEquals($oText->getText(), 'text');
$this->assertInstanceOf('PHPWord_Style_Font', $oText->getFontStyle()); }
}
public function testParagraph() {
$oText = new PHPWord_Section_Text('text', 'fontStyle', 'paragraphStyle');
$this->assertEquals($oText->getParagraphStyle(), 'paragraphStyle');
$oText->setParagraphStyle(array('align'=>'center', 'spaceAfter'=>100)); public function testFont()
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oText->getParagraphStyle()); {
} $oText = new PHPWord_Section_Text('text', 'fontStyle');
} $this->assertEquals($oText->getFontStyle(), 'fontStyle');
$oText->setFontStyle(array('bold' => true, 'italic' => true, 'size' => 16));
$this->assertInstanceOf('PHPWord_Style_Font', $oText->getFontStyle());
}
public function testParagraph()
{
$oText = new PHPWord_Section_Text('text', 'fontStyle', 'paragraphStyle');
$this->assertEquals($oText->getParagraphStyle(), 'paragraphStyle');
$oText->setParagraphStyle(array('align' => 'center', 'spaceAfter' => 100));
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oText->getParagraphStyle());
}
}

View File

@ -1,39 +1,48 @@
<?php <?php
namespace PHPWord\Tests; namespace PHPWord\Tests\Section;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
use PHPWord_Section_Title; use PHPWord_Section_Title;
class PHPWord_Section_TitleTest extends \PHPUnit_Framework_TestCase { class TitleTest extends \PHPUnit_Framework_TestCase
public function testConstruct() { {
$oTitle = new PHPWord_Section_Title('text'); public function testConstruct()
{
$oTitle = new PHPWord_Section_Title('text');
$this->assertInstanceOf('PHPWord_Section_Title', $oTitle); $this->assertInstanceOf('PHPWord_Section_Title', $oTitle);
$this->assertEquals($oTitle->getText(), 'text'); $this->assertEquals($oTitle->getText(), 'text');
} }
public function testStyleNull() {
$oTitle = new PHPWord_Section_Title('text');
$this->assertEquals($oTitle->getStyle(), null); public function testStyleNull()
} {
public function testStyleNotNull() { $oTitle = new PHPWord_Section_Title('text');
$oTitle = new PHPWord_Section_Title('text', 1, 'style');
$this->assertEquals($oTitle->getStyle(), 'style'); $this->assertEquals($oTitle->getStyle(), null);
} }
public function testAnchor() {
$oTitle = new PHPWord_Section_Title('text');
$iVal = rand(1, 1000); public function testStyleNotNull()
$oTitle->setAnchor($iVal); {
$this->assertEquals($oTitle->getAnchor(), $iVal); $oTitle = new PHPWord_Section_Title('text', 1, 'style');
}
public function testBookmarkID() {
$oTitle = new PHPWord_Section_Title('text');
$iVal = rand(1, 1000); $this->assertEquals($oTitle->getStyle(), 'style');
$oTitle->setBookmarkId($iVal); }
$this->assertEquals($oTitle->getBookmarkId(), $iVal);
} public function testAnchor()
} {
$oTitle = new PHPWord_Section_Title('text');
$iVal = rand(1, 1000);
$oTitle->setAnchor($iVal);
$this->assertEquals($oTitle->getAnchor(), $iVal);
}
public function testBookmarkID()
{
$oTitle = new PHPWord_Section_Title('text');
$iVal = rand(1, 1000);
$oTitle->setBookmarkId($iVal);
$this->assertEquals($oTitle->getBookmarkId(), $iVal);
}
}

View File

@ -4,6 +4,7 @@ namespace PHPWord\Tests\Style;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
use PHPWord; use PHPWord;
use PHPWord_Style_Font; use PHPWord_Style_Font;
use PHPWord\Tests\TestHelperDOCX;
/** /**
* Class FontTest * Class FontTest
@ -13,6 +14,11 @@ use PHPWord_Style_Font;
*/ */
class FontTest extends \PHPUnit_Framework_TestCase class FontTest extends \PHPUnit_Framework_TestCase
{ {
public function tearDown()
{
TestHelperDOCX::clear();
}
/** /**
* Test initiation for style type and paragraph style * Test initiation for style type and paragraph style
*/ */
@ -77,4 +83,35 @@ class FontTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($value, $object->$get()); $this->assertEquals($value, $object->$get());
} }
} }
public function testLineHeight()
{
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
// Test style array
$text = $section->addText('This is a test', array(
'line-height' => 2.0
));
$doc = TestHelperDOCX::getDocument($PHPWord);
$element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing');
$lineHeight = $element->getAttribute('w:line');
$lineRule = $element->getAttribute('w:lineRule');
$this->assertEquals(480, $lineHeight);
$this->assertEquals('auto', $lineRule);
// Test setter
$text->getFontStyle()->setLineHeight(3.0);
$doc = TestHelperDOCX::getDocument($PHPWord);
$element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing');
$lineHeight = $element->getAttribute('w:line');
$lineRule = $element->getAttribute('w:lineRule');
$this->assertEquals(720, $lineHeight);
$this->assertEquals('auto', $lineRule);
}
} }