Skip to content

Commit 6389b36

Browse files
committed
Add ability to pass a Style object to a Section
1 parent 4fa9455 commit 6389b36

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/PhpWord/Element/Section.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ 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
/**

tests/PhpWord/Element/SectionTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
use PhpOffice\PhpWord\PhpWord;
2121
use PhpOffice\PhpWord\Style;
22+
use PhpOffice\PhpWord\Style\Section as SectionStyle;
2223

2324
/**
2425
* @covers \PhpOffice\PhpWord\Element\Section
@@ -27,6 +28,27 @@
2728
*/
2829
class 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->assertSame('landscape', $style->getOrientation());
43+
}
44+
45+
public function testConstorWithObjectStyle()
46+
{
47+
$style = new SectionStyle();
48+
$section = new Section(0, $style);
49+
$this->assertSame($style, $section->getStyle());
50+
}
51+
3052
/**
3153
* @covers ::setStyle
3254
*/

0 commit comments

Comments
 (0)