File tree Expand file tree Collapse file tree 4 files changed +43
-3
lines changed Expand file tree Collapse file tree 4 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ v0.16.0 (xx dec 2018)
77----------------------
88### Added
99- Add setting Chart Title and Legend visibility @Tom-Magill #1433
10+ - Add ability to pass a Style object in Section constructor @ndench #1416
1011- Add support for hidden text @Alexmg86 #1527
1112
1213### Fixed
Original file line number Diff line number Diff line change @@ -59,14 +59,16 @@ class Section extends AbstractContainer
5959 * Create new instance
6060 *
6161 * @param int $sectionCount
62- * @param array $style
62+ * @param null| array|\PhpOffice\PhpWord\Style $style
6363 */
6464 public function __construct ($ sectionCount , $ style = null )
6565 {
6666 $ this ->sectionId = $ sectionCount ;
6767 $ this ->setDocPart ($ this ->container , $ this ->sectionId );
68- $ this ->style = new SectionStyle ();
69- $ this ->setStyle ($ style );
68+ if (null === $ style ) {
69+ $ style = new SectionStyle ();
70+ }
71+ $ this ->style = $ this ->setNewStyle (new SectionStyle (), $ style );
7072 }
7173
7274 /**
Original file line number Diff line number Diff line change 1919
2020use PhpOffice \PhpWord \PhpWord ;
2121use PhpOffice \PhpWord \Style ;
22+ use PhpOffice \PhpWord \Style \Section as SectionStyle ;
2223
2324/**
2425 * @covers \PhpOffice\PhpWord\Element\Section
2728 */
2829class SectionTest extends \PHPUnit \Framework \TestCase
2930{
31+ public function testConstructorWithDefaultStyle ()
32+ {
33+ $ section = new Section (0 );
34+ $ this ->assertInstanceOf ('PhpOffice \\PhpWord \\Style \\Section ' , $ section ->getStyle ());
35+ }
36+
37+ public function testConstructorWithArrayStyle ()
38+ {
39+ $ section = new Section (0 , array ('orientation ' => 'landscape ' ));
40+ $ style = $ section ->getStyle ();
41+ $ this ->assertInstanceOf ('PhpOffice \\PhpWord \\Style \\Section ' , $ style );
42+ $ this ->assertEquals ('landscape ' , $ style ->getOrientation ());
43+ }
44+
45+ public function testConstructorWithObjectStyle ()
46+ {
47+ $ style = new SectionStyle ();
48+ $ section = new Section (0 , $ style );
49+ $ this ->assertSame ($ style , $ section ->getStyle ());
50+ }
51+
3052 /**
3153 * @covers ::setStyle
3254 */
Original file line number Diff line number Diff line change @@ -492,4 +492,19 @@ public function testTitleAndHeading()
492492 $ this ->assertTrue ($ doc ->elementExists ('/w:document/w:body/w:p[2]/w:pPr/w:pStyle ' ));
493493 $ this ->assertEquals ('Heading1 ' , $ doc ->getElementAttribute ('/w:document/w:body/w:p[2]/w:pPr/w:pStyle ' , 'w:val ' ));
494494 }
495+
496+ /**
497+ * Test correct writing of text with ampersant in it
498+ */
499+ public function testTextWithAmpersant ()
500+ {
501+ \PhpOffice \PhpWord \Settings::setOutputEscapingEnabled (true );
502+ $ phpWord = new PhpWord ();
503+ $ section = $ phpWord ->addSection ();
504+ $ section ->addText ('this text contains an & (ampersant) ' );
505+
506+ $ doc = TestHelperDOCX::getDocument ($ phpWord );
507+ $ this ->assertTrue ($ doc ->elementExists ('/w:document/w:body/w:p/w:r/w:t ' ));
508+ $ this ->assertEquals ('this text contains an & (ampersant) ' , $ doc ->getElement ('/w:document/w:body/w:p/w:r/w:t ' )->nodeValue );
509+ }
495510}
You can’t perform that action at this time.
0 commit comments