Skip to content

Commit acfe64b

Browse files
committed
More unit tests for Writer\Word2007\Base
1 parent 2f0438f commit acfe64b

File tree

7 files changed

+294
-29
lines changed

7 files changed

+294
-29
lines changed

Classes/PHPWord/Style/Font.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,6 @@ public function __construct($type = 'text', $paragraphStyle = null)
173173
} elseif (is_array($paragraphStyle)) {
174174
$this->_paragraphStyle = new PHPWord_Style_Paragraph;
175175
$this->_paragraphStyle->setArrayStyle($paragraphStyle);
176-
} elseif (null === $paragraphStyle) {
177-
$this->_paragraphStyle = new PHPWord_Style_Paragraph;
178176
} else {
179177
$this->_paragraphStyle = $paragraphStyle;
180178
}

Classes/PHPWord/Style/Row.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,20 @@ class PHPWord_Style_Row
3636
*
3737
* @var bool
3838
*/
39-
private $_tblHeader;
39+
private $_tblHeader = false;
4040

4141
/**
4242
* Table row cannot break across pages
4343
*
4444
* @var bool
4545
*/
46-
private $_cantSplit;
46+
private $_cantSplit = false;
4747

4848
/**
4949
* Create a new row style
5050
*/
5151
public function __construct()
5252
{
53-
$this->_tblHeader = null;
54-
$this->_cantSplit = null;
5553
}
5654

5755
/**
@@ -62,23 +60,31 @@ public function setStyleValue($key, $value)
6260
$this->$key = $value;
6361
}
6462

65-
public function setTblHeader($pValue = null)
63+
public function setTblHeader($pValue = false)
6664
{
65+
if (!is_bool($pValue)) {
66+
$pValue = false;
67+
}
6768
$this->_tblHeader = $pValue;
69+
return $this;
6870
}
6971

7072
public function getTblHeader()
7173
{
72-
return $this->_tblHeader ? 1 : 0;
74+
return $this->_tblHeader;
7375
}
7476

75-
public function setCantSplit($pValue = null)
77+
public function setCantSplit($pValue = false)
7678
{
79+
if (!is_bool($pValue)) {
80+
$pValue = false;
81+
}
7782
$this->_cantSplit = $pValue;
83+
return $this;
7884
}
7985

8086
public function getCantSplit()
8187
{
82-
return $this->_cantSplit ? 1 : 0;
88+
return $this->_cantSplit;
8389
}
8490
}

Classes/PHPWord/Writer/Word2007/Base.php

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
3232
{
3333

34+
/**
35+
* Write text
36+
*/
3437
protected function _writeText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Text $text, $withoutP = false)
3538
{
3639
$styleFont = $text->getFontStyle();
@@ -81,6 +84,9 @@ protected function _writeText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWor
8184
}
8285
}
8386

87+
/**
88+
* Write text run
89+
*/
8490
protected function _writeTextRun(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_TextRun $textrun)
8591
{
8692
$elements = $textrun->getElements();
@@ -222,6 +228,9 @@ protected function _writeParagraphStyle(
222228
}
223229
}
224230

231+
/**
232+
* Write table
233+
*/
225234
protected function _writeLink(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Link $link, $withoutP = false)
226235
{
227236
$rID = $link->getRelationId();
@@ -278,6 +287,9 @@ protected function _writeLink(PHPWord_Shared_XMLWriter $objWriter = null, PHPWor
278287
}
279288
}
280289

290+
/**
291+
* Write preserve text
292+
*/
281293
protected function _writePreserveText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footer_PreserveText $textrun)
282294
{
283295
$styleFont = $textrun->getFontStyle();
@@ -370,6 +382,9 @@ protected function _writePreserveText(PHPWord_Shared_XMLWriter $objWriter = null
370382
$objWriter->endElement(); // p
371383
}
372384

385+
/**
386+
* Write text style
387+
*/
373388
protected function _writeTextStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Font $style)
374389
{
375390
$font = $style->getName();
@@ -451,11 +466,17 @@ protected function _writeTextStyle(PHPWord_Shared_XMLWriter $objWriter = null, P
451466
$objWriter->endElement();
452467
}
453468

469+
/**
470+
* Write text break
471+
*/
454472
protected function _writeTextBreak(PHPWord_Shared_XMLWriter $objWriter = null)
455473
{
456474
$objWriter->writeElement('w:p', null);
457475
}
458476

477+
/**
478+
* Write table
479+
*/
459480
protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Table $table)
460481
{
461482
$_rows = $table->getRows();
@@ -499,14 +520,14 @@ protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo
499520
$objWriter->writeAttribute('w:val', $height);
500521
$objWriter->endElement();
501522
}
502-
if (!is_null($tblHeader)) {
523+
if ($tblHeader) {
503524
$objWriter->startElement('w:tblHeader');
504-
$objWriter->writeAttribute('w:val', $tblHeader);
525+
$objWriter->writeAttribute('w:val', '1');
505526
$objWriter->endElement();
506527
}
507-
if (!is_null($cantSplit)) {
528+
if ($cantSplit) {
508529
$objWriter->startElement('w:cantSplit');
509-
$objWriter->writeAttribute('w:val', $cantSplit);
530+
$objWriter->writeAttribute('w:val', '1');
510531
$objWriter->endElement();
511532
}
512533
$objWriter->endElement();
@@ -565,6 +586,9 @@ protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo
565586
}
566587
}
567588

589+
/**
590+
* Write table style
591+
*/
568592
protected function _writeTableStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Table $style = null)
569593
{
570594
$margins = $style->getCellMargin();
@@ -610,6 +634,9 @@ protected function _writeTableStyle(PHPWord_Shared_XMLWriter $objWriter = null,
610634
}
611635
}
612636

637+
/**
638+
* Write cell style
639+
*/
613640
protected function _writeCellStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Cell $style = null)
614641
{
615642
$bgColor = $style->getBgColor();
@@ -794,6 +821,9 @@ protected function _writeImage(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo
794821
}
795822
}
796823

824+
/**
825+
* Write watermark
826+
*/
797827
protected function _writeWatermark(PHPWord_Shared_XMLWriter $objWriter = null, $image)
798828
{
799829
$rId = $image->getRelationId();
@@ -838,6 +868,9 @@ protected function _writeWatermark(PHPWord_Shared_XMLWriter $objWriter = null, $
838868
$objWriter->endElement();
839869
}
840870

871+
/**
872+
* Write title
873+
*/
841874
protected function _writeTitle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Title $title)
842875
{
843876
$text = htmlspecialchars($title->getText());
@@ -880,6 +913,9 @@ protected function _writeTitle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo
880913
$objWriter->endElement();
881914
}
882915

916+
/**
917+
* Write footnote
918+
*/
883919
protected function _writeFootnote(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footnote $footnote)
884920
{
885921
$objWriter->startElement('w:footnote');
@@ -915,6 +951,9 @@ protected function _writeFootnote(PHPWord_Shared_XMLWriter $objWriter = null, PH
915951
$objWriter->endElement(); // w:footnote
916952
}
917953

954+
/**
955+
* Write footnote reference
956+
*/
918957
protected function _writeFootnoteReference(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footnote $footnote, $withoutP = false)
919958
{
920959
if (!$withoutP) {

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ __Want to contribute?__ Fork us!
1515
## Requirements
1616

1717
* PHP version 5.3.0 or higher
18-
* PHP extension [php_zip](http://php.net/manual/en/book.zip.php) enabled
18+
* PHP extension [ZipArchive](http://php.net/manual/en/book.zip.php)
19+
* PHP extension [XMLWriter](http://php.net/manual/en/book.xmlwriter.php)
1920

2021
## Installation
2122

0 commit comments

Comments
 (0)