diff --git a/Classes/PHPWord/Section.php b/Classes/PHPWord/Section.php index f20cfd95..e65267df 100755 --- a/Classes/PHPWord/Section.php +++ b/Classes/PHPWord/Section.php @@ -128,6 +128,7 @@ class PHPWord_Section /** * Add a CheckBox Element * + * @param string $name * @param string $text * @param mixed $style * @return PHPWord_Section_CheckBox diff --git a/Classes/PHPWord/Section/CheckBox.php b/Classes/PHPWord/Section/CheckBox.php index af02356a..03f8228a 100644 --- a/Classes/PHPWord/Section/CheckBox.php +++ b/Classes/PHPWord/Section/CheckBox.php @@ -68,6 +68,7 @@ class PHPWord_Section_CheckBox /** * Create a new Text Element * + * @param string $name * @param string $text * @param null|array|\PHPWord_Style_Font $fontStyle * @param null|array|\PHPWord_Style_Paragraph $paragraphStyle @@ -149,9 +150,9 @@ class PHPWord_Section_CheckBox * @param string $name * @return $this */ - public function setName($text) + public function setName($name) { - $this->name = $text; + $this->name = $name; return $this; } diff --git a/Classes/PHPWord/Section/Table/Cell.php b/Classes/PHPWord/Section/Table/Cell.php index 1a0d1c6a..e18dd829 100755 --- a/Classes/PHPWord/Section/Table/Cell.php +++ b/Classes/PHPWord/Section/Table/Cell.php @@ -116,6 +116,7 @@ class PHPWord_Section_Table_Cell /** * Add a CheckBox Element * + * @param string $name * @param string $text * @param mixed $style * @return PHPWord_Section_CheckBox diff --git a/Classes/PHPWord/Section/Text.php b/Classes/PHPWord/Section/Text.php index 8631b66e..2a96a2d9 100755 --- a/Classes/PHPWord/Section/Text.php +++ b/Classes/PHPWord/Section/Text.php @@ -139,7 +139,7 @@ class PHPWord_Section_Text $this->text = $text; return $this; } - + /** * Get Text content * diff --git a/Tests/PHPWord/AutoloaderTest.php b/Tests/PHPWord/AutoloaderTest.php index 03e16db0..b1899770 100644 --- a/Tests/PHPWord/AutoloaderTest.php +++ b/Tests/PHPWord/AutoloaderTest.php @@ -1,6 +1,7 @@ assertInstanceOf('PHPWord_Section_CheckBox', $oCheckBox); + $this->assertEquals(null, $oCheckBox->getText()); + $this->assertInstanceOf('PHPWord_Style_Font', $oCheckBox->getFontStyle()); + $this->assertInstanceOf('PHPWord_Style_Paragraph', $oCheckBox->getParagraphStyle()); + } + + public function testCheckBox() + { + $oCheckBox = new PHPWord_Section_CheckBox('CheckBox'); + + $this->assertEquals($oCheckBox->getText(), 'CheckBox'); + } + + public function testFont() + { + $oCheckBox = new PHPWord_Section_CheckBox('CheckBox', 'fontStyle'); + $this->assertEquals($oCheckBox->getFontStyle(), 'fontStyle'); + + $oCheckBox->setFontStyle(array('bold' => true, 'italic' => true, 'size' => 16)); + $this->assertInstanceOf('PHPWord_Style_Font', $oCheckBox->getFontStyle()); + } + + public function testParagraph() + { + $oCheckBox = new PHPWord_Section_CheckBox('CheckBox', 'fontStyle', 'paragraphStyle'); + $this->assertEquals($oCheckBox->getParagraphStyle(), 'paragraphStyle'); + + $oCheckBox->setParagraphStyle(array('align' => 'center', 'spaceAfter' => 100)); + $this->assertInstanceOf('PHPWord_Style_Paragraph', $oCheckBox->getParagraphStyle()); + } +} diff --git a/Tests/PHPWord/Section/Table/CellTest.php b/Tests/PHPWord/Section/Table/CellTest.php index 30a7fcdb..be2878f1 100644 --- a/Tests/PHPWord/Section/Table/CellTest.php +++ b/Tests/PHPWord/Section/Table/CellTest.php @@ -40,6 +40,15 @@ class CellTest extends \PHPUnit_Framework_TestCase $this->assertInstanceOf('PHPWord_Section_Text', $element); } + public function testaddCheckBox() + { + $oCell = new PHPWord_Section_Table_Cell('section', 1); + $element = $oCell->addCheckBox('check1', 'text'); + + $this->assertCount(1, $oCell->getElements()); + $this->assertInstanceOf('PHPWord_Section_CheckBox', $element); + } + public function testAddTextNotUTF8() { $oCell = new PHPWord_Section_Table_Cell('section', 1); diff --git a/Tests/PHPWord/SectionTest.php b/Tests/PHPWord/SectionTest.php index ac540d06..1bcd108c 100644 --- a/Tests/PHPWord/SectionTest.php +++ b/Tests/PHPWord/SectionTest.php @@ -61,6 +61,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase /** * @covers PHPWord_Section::addText + * @covers PHPWord_Section::addCheckBox * @covers PHPWord_Section::addLink * @covers PHPWord_Section::addTextBreak * @covers PHPWord_Section::addPageBreak @@ -88,6 +89,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase $section = new PHPWord_Section(0); $section->addText(utf8_decode('ä')); + $section->addCheckBox('check1', utf8_decode('ä')); $section->addLink(utf8_decode('http://äää.com'), utf8_decode('ä')); $section->addTextBreak(); $section->addPageBreak(); diff --git a/Tests/PHPWord/Writer/Word2007/BaseTest.php b/Tests/PHPWord/Writer/Word2007/BaseTest.php index fde6e30b..1ede88f4 100644 --- a/Tests/PHPWord/Writer/Word2007/BaseTest.php +++ b/Tests/PHPWord/Writer/Word2007/BaseTest.php @@ -43,6 +43,26 @@ class BaseTest extends \PHPUnit_Framework_TestCase $this->assertEquals($pStyle, $doc->getElementAttribute($element, 'w:val')); } + /** + * covers ::_writeCheckbox + */ + public function testWriteCheckbox() + { + $rStyle = 'rStyle'; + $pStyle = 'pStyle'; + + $PHPWord = new PHPWord(); + $PHPWord->addFontStyle($rStyle, array('bold' => true)); + $PHPWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120)); + $section = $PHPWord->createSection(); + $section->addCheckbox('Check1', 'Test', $rStyle, $pStyle); + $doc = TestHelperDOCX::getDocument($PHPWord); + + $element = $doc->getElement('/w:document/w:body/w:p/w:checkbox/w:r/w:t'); + + $this->assertEquals($expected, $element->nodeValue); + } + /** * covers ::_writeTextRun */