add tests
This commit is contained in:
parent
d8dcc770a9
commit
ff8234bce4
|
|
@ -23,7 +23,7 @@ namespace PhpOffice\PhpWord\Element;
|
|||
* @method Text addText(string $text, mixed $fStyle = null, mixed $pStyle = null)
|
||||
* @method TextRun addTextRun(mixed $pStyle = null)
|
||||
* @method Bookmark addBookmark(string $name)
|
||||
* @method Link addLink(string $target, string $text = null, mixed $fStyle = null, mixed $pStyle = null)
|
||||
* @method Link addLink(string $target, string $text = null, mixed $fStyle = null, mixed $pStyle = null, boolean $internal = false)
|
||||
* @method PreserveText addPreserveText(string $text, mixed $fStyle = null, mixed $pStyle = null)
|
||||
* @method void addTextBreak(int $count = 1, mixed $fStyle = null, mixed $pStyle = null)
|
||||
* @method ListItem addListItem(string $txt, int $depth = 0, mixed $font = null, mixed $list = null, mixed $para = null)
|
||||
|
|
|
|||
|
|
@ -83,6 +83,7 @@ class ContentTest extends \PHPUnit\Framework\TestCase
|
|||
$cell->addObject($objectSrc);
|
||||
$textrun = $cell->addTextRun();
|
||||
$textrun->addText('Test text run');
|
||||
$section->addPageBreak();
|
||||
|
||||
$footer = $section->addFooter();
|
||||
$footer->addPreserveText('{PAGE}');
|
||||
|
|
|
|||
|
|
@ -71,6 +71,68 @@ class ElementTest extends \PHPUnit\Framework\TestCase
|
|||
$this->assertTrue($doc->elementExists($element));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test bookmark element
|
||||
*/
|
||||
public function testBookmark()
|
||||
{
|
||||
$phpWord = new PhpWord();
|
||||
$section = $phpWord->addSection();
|
||||
|
||||
$section->addBookmark('test_bookmark');
|
||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||
|
||||
$element = '/w:document/w:body/w:bookmarkStart';
|
||||
$this->assertTrue($doc->elementExists($element));
|
||||
$this->assertEquals('test_bookmark', $doc->getElementAttribute($element, 'w:name'));
|
||||
|
||||
$element = '/w:document/w:body/w:bookmarkEnd';
|
||||
$this->assertTrue($doc->elementExists($element));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test link element
|
||||
*/
|
||||
public function testLinkElement()
|
||||
{
|
||||
$phpWord = new PhpWord();
|
||||
$section = $phpWord->addSection();
|
||||
|
||||
$section->addLink('https://github.com/PHPOffice/PHPWord');
|
||||
$section->addLink('internal_link', null, null, null, true);
|
||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||
|
||||
$element = '/w:document/w:body/w:p[1]/w:hyperlink/w:r/w:t';
|
||||
$this->assertTrue($doc->elementExists($element));
|
||||
|
||||
$element = '/w:document/w:body/w:p[2]/w:hyperlink/w:r/w:t';
|
||||
$this->assertTrue($doc->elementExists($element));
|
||||
$this->assertEquals('internal_link', $doc->getElementAttribute('/w:document/w:body/w:p[2]/w:hyperlink', 'w:anchor'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic test for table element
|
||||
*/
|
||||
public function testTableElements()
|
||||
{
|
||||
$phpWord = new PhpWord();
|
||||
$section = $phpWord->addSection();
|
||||
|
||||
$table = $section->addTable(array('alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER));
|
||||
$table->addRow(900);
|
||||
$table->addCell(2000)->addText('Row 1');
|
||||
$table->addCell(2000)->addText('Row 2');
|
||||
$table->addCell(2000)->addText('Row 3');
|
||||
$table->addCell(2000)->addText('Row 4');
|
||||
|
||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||
|
||||
$tableRootElement = '/w:document/w:body/w:tbl';
|
||||
$this->assertTrue($doc->elementExists($tableRootElement . '/w:tblGrid/w:gridCol'));
|
||||
$this->assertTrue($doc->elementExists($tableRootElement . '/w:tblPr/w:jc'));
|
||||
$this->assertEquals('center', $doc->getElementAttribute($tableRootElement . '/w:tblPr/w:jc', 'w:val'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test shape elements
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -50,4 +50,19 @@ class FontTest extends \PHPUnit\Framework\TestCase
|
|||
$path = '/w:document/w:body/w:p/w:r/w:rPr/w:rtl';
|
||||
$this->assertTrue($doc->elementExists($path, $file));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test writing font with language
|
||||
*/
|
||||
public function testFontWithLang()
|
||||
{
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
$section = $phpWord->addSection();
|
||||
$section->addText('Ce texte-ci est en français.', array('lang' => \PhpOffice\PhpWord\Style\Language::FR_BE));
|
||||
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
||||
|
||||
$file = 'word/document.xml';
|
||||
$path = '/w:document/w:body/w:p/w:r/w:rPr/w:lang';
|
||||
$this->assertTrue($doc->elementExists($path, $file));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||
* word processing documents.
|
||||
*
|
||||
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||
* General Public License version 3 as published by the Free Software Foundation.
|
||||
*
|
||||
* For the full copyright and license information, please read the LICENSE
|
||||
* file that was distributed with this source code. For the full list of
|
||||
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||
*
|
||||
* @see https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2010-2017 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Writer\Word2007\Style;
|
||||
|
||||
use PhpOffice\PhpWord\TestHelperDOCX;
|
||||
|
||||
/**
|
||||
* Test class for PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph
|
||||
*
|
||||
* @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class ParagraphTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Executed before each method of the class
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
TestHelperDOCX::clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test write styles
|
||||
*/
|
||||
public function testParagraphNumbering()
|
||||
{
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
$phpWord->addParagraphStyle('testStyle', array('indent' => '10'));
|
||||
$section = $phpWord->addSection();
|
||||
$section->addText('test', null, array('numStyle' => 'testStyle', 'numLevel' => '1'));
|
||||
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
||||
|
||||
$path = '/w:document/w:body/w:p/w:pPr/w:numPr/w:ilvl';
|
||||
$this->assertTrue($doc->elementExists($path));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue