Add ability to pass a Style object to a Section element (#1416)
* Add ability to pass a Style object to a Section * Fix typo * update changelog
This commit is contained in:
parent
c2b54cc343
commit
cf3132acac
|
|
@ -7,6 +7,7 @@ v0.16.0 (xx dec 2018)
|
|||
----------------------
|
||||
### Added
|
||||
- Add setting Chart Title and Legend visibility @Tom-Magill #1433
|
||||
- Add ability to pass a Style object in Section constructor @ndench #1416
|
||||
- Add support for hidden text @Alexmg86 #1527
|
||||
|
||||
### Fixed
|
||||
|
|
|
|||
|
|
@ -59,14 +59,16 @@ class Section extends AbstractContainer
|
|||
* Create new instance
|
||||
*
|
||||
* @param int $sectionCount
|
||||
* @param array $style
|
||||
* @param null|array|\PhpOffice\PhpWord\Style $style
|
||||
*/
|
||||
public function __construct($sectionCount, $style = null)
|
||||
{
|
||||
$this->sectionId = $sectionCount;
|
||||
$this->setDocPart($this->container, $this->sectionId);
|
||||
$this->style = new SectionStyle();
|
||||
$this->setStyle($style);
|
||||
if (null === $style) {
|
||||
$style = new SectionStyle();
|
||||
}
|
||||
$this->style = $this->setNewStyle(new SectionStyle(), $style);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ namespace PhpOffice\PhpWord\Element;
|
|||
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\Style;
|
||||
use PhpOffice\PhpWord\Style\Section as SectionStyle;
|
||||
|
||||
/**
|
||||
* @covers \PhpOffice\PhpWord\Element\Section
|
||||
|
|
@ -27,6 +28,27 @@ use PhpOffice\PhpWord\Style;
|
|||
*/
|
||||
class SectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testConstructorWithDefaultStyle()
|
||||
{
|
||||
$section = new Section(0);
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Section', $section->getStyle());
|
||||
}
|
||||
|
||||
public function testConstructorWithArrayStyle()
|
||||
{
|
||||
$section = new Section(0, array('orientation' => 'landscape'));
|
||||
$style = $section->getStyle();
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Section', $style);
|
||||
$this->assertEquals('landscape', $style->getOrientation());
|
||||
}
|
||||
|
||||
public function testConstructorWithObjectStyle()
|
||||
{
|
||||
$style = new SectionStyle();
|
||||
$section = new Section(0, $style);
|
||||
$this->assertSame($style, $section->getStyle());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setStyle
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -492,4 +492,19 @@ class ElementTest extends \PHPUnit\Framework\TestCase
|
|||
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[2]/w:pPr/w:pStyle'));
|
||||
$this->assertEquals('Heading1', $doc->getElementAttribute('/w:document/w:body/w:p[2]/w:pPr/w:pStyle', 'w:val'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test correct writing of text with ampersant in it
|
||||
*/
|
||||
public function testTextWithAmpersant()
|
||||
{
|
||||
\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
|
||||
$phpWord = new PhpWord();
|
||||
$section = $phpWord->addSection();
|
||||
$section->addText('this text contains an & (ampersant)');
|
||||
|
||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:t'));
|
||||
$this->assertEquals('this text contains an & (ampersant)', $doc->getElement('/w:document/w:body/w:p/w:r/w:t')->nodeValue);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue