';
$phpWord = $this->getDocumentFromString(['document' => $documentXml]);
$elements = $phpWord->getSection(0)->getElements();
self::assertInstanceOf('PhpOffice\PhpWord\Element\Table', $elements[0]);
self::assertInstanceOf('PhpOffice\PhpWord\Style\Table', $elements[0]->getStyle());
self::assertEquals(Table::LAYOUT_FIXED, $elements[0]->getStyle()->getLayout());
}
/**
* Test reading of cell spacing.
*/
public function testReadCellSpacing(): void
{
$documentXml = '
';
$phpWord = $this->getDocumentFromString(['document' => $documentXml]);
$elements = $phpWord->getSection(0)->getElements();
self::assertInstanceOf('PhpOffice\PhpWord\Element\Table', $elements[0]);
self::assertInstanceOf('PhpOffice\PhpWord\Style\Table', $elements[0]->getStyle());
/** @var \PhpOffice\PhpWord\Style\Table $tableStyle */
$tableStyle = $elements[0]->getStyle();
self::assertEquals(TblWidth::AUTO, $tableStyle->getUnit());
self::assertEquals(10.5, $tableStyle->getCellSpacing());
}
/**
* Test reading of table position.
*/
public function testReadTablePosition(): void
{
$documentXml = '
';
$phpWord = $this->getDocumentFromString(['document' => $documentXml]);
$elements = $phpWord->getSection(0)->getElements();
self::assertInstanceOf('PhpOffice\PhpWord\Element\Table', $elements[0]);
self::assertInstanceOf('PhpOffice\PhpWord\Style\Table', $elements[0]->getStyle());
self::assertNotNull($elements[0]->getStyle()->getPosition());
self::assertInstanceOf('PhpOffice\PhpWord\Style\TablePosition', $elements[0]->getStyle()->getPosition());
/** @var \PhpOffice\PhpWord\Style\TablePosition $tableStyle */
$tableStyle = $elements[0]->getStyle()->getPosition();
self::assertEquals(10, $tableStyle->getLeftFromText());
self::assertEquals(20, $tableStyle->getRightFromText());
self::assertEquals(30, $tableStyle->getTopFromText());
self::assertEquals(40, $tableStyle->getBottomFromText());
self::assertEquals(TablePosition::VANCHOR_PAGE, $tableStyle->getVertAnchor());
self::assertEquals(TablePosition::HANCHOR_MARGIN, $tableStyle->getHorzAnchor());
self::assertEquals(TablePosition::XALIGN_CENTER, $tableStyle->getTblpXSpec());
self::assertEquals(50, $tableStyle->getTblpX());
self::assertEquals(TablePosition::YALIGN_TOP, $tableStyle->getTblpYSpec());
self::assertEquals(60, $tableStyle->getTblpY());
}
/**
* Test reading of position.
*/
public function testReadPosition(): void
{
$documentXml = '
This text is lowered
';
$phpWord = $this->getDocumentFromString(['document' => $documentXml]);
$elements = $phpWord->getSection(0)->getElements();
/** @var \PhpOffice\PhpWord\Element\TextRun $elements */
$textRun = $elements[0];
self::assertInstanceOf('PhpOffice\PhpWord\Element\TextRun', $textRun);
self::assertInstanceOf('PhpOffice\PhpWord\Element\Text', $textRun->getElement(0));
self::assertInstanceOf('PhpOffice\PhpWord\Style\Font', $textRun->getElement(0)->getFontStyle());
/** @var \PhpOffice\PhpWord\Style\Font $fontStyle */
$fontStyle = $textRun->getElement(0)->getFontStyle();
self::assertEquals(15, $fontStyle->getPosition());
}
public function testReadIndent(): void
{
$documentXml = '
';
$phpWord = $this->getDocumentFromString(['document' => $documentXml]);
$elements = $phpWord->getSection(0)->getElements();
self::assertInstanceOf('PhpOffice\PhpWord\Element\Table', $elements[0]);
self::assertInstanceOf('PhpOffice\PhpWord\Style\Table', $elements[0]->getStyle());
/** @var \PhpOffice\PhpWord\Style\Table $tableStyle */
$tableStyle = $elements[0]->getStyle();
self::assertSame(TblWidth::TWIP, $tableStyle->getIndent()->getType());
self::assertSame(2160, $tableStyle->getIndent()->getValue());
}
public function testReadTableRTL(): void
{
$documentXml = '
';
$phpWord = $this->getDocumentFromString(['document' => $documentXml]);
$elements = $phpWord->getSection(0)->getElements();
self::assertInstanceOf('PhpOffice\PhpWord\Element\Table', $elements[0]);
self::assertInstanceOf('PhpOffice\PhpWord\Style\Table', $elements[0]->getStyle());
/** @var \PhpOffice\PhpWord\Style\Table $tableStyle */
$tableStyle = $elements[0]->getStyle();
self::assertTrue($tableStyle->isBidiVisual());
}
public function testReadHidden(): void
{
$documentXml = '
This text is hidden
';
$phpWord = $this->getDocumentFromString(['document' => $documentXml]);
$elements = $phpWord->getSection(0)->getElements();
/** @var \PhpOffice\PhpWord\Element\TextRun $elements */
$textRun = $elements[0];
self::assertInstanceOf('PhpOffice\PhpWord\Element\TextRun', $textRun);
self::assertInstanceOf('PhpOffice\PhpWord\Element\Text', $textRun->getElement(0));
self::assertInstanceOf('PhpOffice\PhpWord\Style\Font', $textRun->getElement(0)->getFontStyle());
/** @var \PhpOffice\PhpWord\Style\Font $fontStyle */
$fontStyle = $textRun->getElement(0)->getFontStyle();
self::assertTrue($fontStyle->isHidden());
}
public function testReadHeading(): void
{
Style::resetStyles();
$documentXml = '
';
$name = 'Heading_1';
$this->getDocumentFromString(['styles' => $documentXml]);
self::assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', Style::getStyle($name));
}
public function testPageVerticalAlign(): void
{
$documentXml = '
';
$phpWord = $this->getDocumentFromString(['document' => $documentXml]);
$sectionStyle = $phpWord->getSection(0)->getStyle();
self::assertEquals(VerticalJc::CENTER, $sectionStyle->getVAlign());
}
}