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)
7
7
----------------------
8
8
### Added
9
9
- Add setting Chart Title and Legend visibility @Tom-Magill #1433
10
+ - Add ability to pass a Style object in Section constructor @ndench #1416
10
11
- Add support for hidden text @Alexmg86 #1527
11
12
12
13
### Fixed
Original file line number Diff line number Diff line change @@ -59,14 +59,16 @@ class Section extends AbstractContainer
59
59
* Create new instance
60
60
*
61
61
* @param int $sectionCount
62
- * @param array $style
62
+ * @param null| array|\PhpOffice\PhpWord\Style $style
63
63
*/
64
64
public function __construct ($ sectionCount , $ style = null )
65
65
{
66
66
$ this ->sectionId = $ sectionCount ;
67
67
$ 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 );
70
72
}
71
73
72
74
/**
Original file line number Diff line number Diff line change 19
19
20
20
use PhpOffice \PhpWord \PhpWord ;
21
21
use PhpOffice \PhpWord \Style ;
22
+ use PhpOffice \PhpWord \Style \Section as SectionStyle ;
22
23
23
24
/**
24
25
* @covers \PhpOffice\PhpWord\Element\Section
27
28
*/
28
29
class SectionTest extends \PHPUnit \Framework \TestCase
29
30
{
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
+
30
52
/**
31
53
* @covers ::setStyle
32
54
*/
Original file line number Diff line number Diff line change @@ -492,4 +492,19 @@ public function testTitleAndHeading()
492
492
$ this ->assertTrue ($ doc ->elementExists ('/w:document/w:body/w:p[2]/w:pPr/w:pStyle ' ));
493
493
$ this ->assertEquals ('Heading1 ' , $ doc ->getElementAttribute ('/w:document/w:body/w:p[2]/w:pPr/w:pStyle ' , 'w:val ' ));
494
494
}
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
+ }
495
510
}
You can’t perform that action at this time.
0 commit comments