Skip to content

Commit ff8234b

Browse files
committed
add tests
1 parent d8dcc77 commit ff8234b

File tree

5 files changed

+131
-1
lines changed

5 files changed

+131
-1
lines changed

src/PhpWord/Element/AbstractContainer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* @method Text addText(string $text, mixed $fStyle = null, mixed $pStyle = null)
2424
* @method TextRun addTextRun(mixed $pStyle = null)
2525
* @method Bookmark addBookmark(string $name)
26-
* @method Link addLink(string $target, string $text = null, mixed $fStyle = null, mixed $pStyle = null)
26+
* @method Link addLink(string $target, string $text = null, mixed $fStyle = null, mixed $pStyle = null, boolean $internal = false)
2727
* @method PreserveText addPreserveText(string $text, mixed $fStyle = null, mixed $pStyle = null)
2828
* @method void addTextBreak(int $count = 1, mixed $fStyle = null, mixed $pStyle = null)
2929
* @method ListItem addListItem(string $txt, int $depth = 0, mixed $font = null, mixed $list = null, mixed $para = null)

tests/PhpWord/Writer/ODText/Part/ContentTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public function testWriteContent()
8383
$cell->addObject($objectSrc);
8484
$textrun = $cell->addTextRun();
8585
$textrun->addText('Test text run');
86+
$section->addPageBreak();
8687

8788
$footer = $section->addFooter();
8889
$footer->addPreserveText('{PAGE}');

tests/PhpWord/Writer/Word2007/ElementTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,68 @@ public function testLineElement()
7171
$this->assertTrue($doc->elementExists($element));
7272
}
7373

74+
/**
75+
* Test bookmark element
76+
*/
77+
public function testBookmark()
78+
{
79+
$phpWord = new PhpWord();
80+
$section = $phpWord->addSection();
81+
82+
$section->addBookmark('test_bookmark');
83+
$doc = TestHelperDOCX::getDocument($phpWord);
84+
85+
$element = '/w:document/w:body/w:bookmarkStart';
86+
$this->assertTrue($doc->elementExists($element));
87+
$this->assertEquals('test_bookmark', $doc->getElementAttribute($element, 'w:name'));
88+
89+
$element = '/w:document/w:body/w:bookmarkEnd';
90+
$this->assertTrue($doc->elementExists($element));
91+
}
92+
93+
/**
94+
* Test link element
95+
*/
96+
public function testLinkElement()
97+
{
98+
$phpWord = new PhpWord();
99+
$section = $phpWord->addSection();
100+
101+
$section->addLink('https://github.com/PHPOffice/PHPWord');
102+
$section->addLink('internal_link', null, null, null, true);
103+
$doc = TestHelperDOCX::getDocument($phpWord);
104+
105+
$element = '/w:document/w:body/w:p[1]/w:hyperlink/w:r/w:t';
106+
$this->assertTrue($doc->elementExists($element));
107+
108+
$element = '/w:document/w:body/w:p[2]/w:hyperlink/w:r/w:t';
109+
$this->assertTrue($doc->elementExists($element));
110+
$this->assertEquals('internal_link', $doc->getElementAttribute('/w:document/w:body/w:p[2]/w:hyperlink', 'w:anchor'));
111+
}
112+
113+
/**
114+
* Basic test for table element
115+
*/
116+
public function testTableElements()
117+
{
118+
$phpWord = new PhpWord();
119+
$section = $phpWord->addSection();
120+
121+
$table = $section->addTable(array('alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER));
122+
$table->addRow(900);
123+
$table->addCell(2000)->addText('Row 1');
124+
$table->addCell(2000)->addText('Row 2');
125+
$table->addCell(2000)->addText('Row 3');
126+
$table->addCell(2000)->addText('Row 4');
127+
128+
$doc = TestHelperDOCX::getDocument($phpWord);
129+
130+
$tableRootElement = '/w:document/w:body/w:tbl';
131+
$this->assertTrue($doc->elementExists($tableRootElement . '/w:tblGrid/w:gridCol'));
132+
$this->assertTrue($doc->elementExists($tableRootElement . '/w:tblPr/w:jc'));
133+
$this->assertEquals('center', $doc->getElementAttribute($tableRootElement . '/w:tblPr/w:jc', 'w:val'));
134+
}
135+
74136
/**
75137
* Test shape elements
76138
*/

tests/PhpWord/Writer/Word2007/Style/FontTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,19 @@ public function testFontRTL()
5050
$path = '/w:document/w:body/w:p/w:r/w:rPr/w:rtl';
5151
$this->assertTrue($doc->elementExists($path, $file));
5252
}
53+
54+
/**
55+
* Test writing font with language
56+
*/
57+
public function testFontWithLang()
58+
{
59+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
60+
$section = $phpWord->addSection();
61+
$section->addText('Ce texte-ci est en français.', array('lang' => \PhpOffice\PhpWord\Style\Language::FR_BE));
62+
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
63+
64+
$file = 'word/document.xml';
65+
$path = '/w:document/w:body/w:p/w:r/w:rPr/w:lang';
66+
$this->assertTrue($doc->elementExists($path, $file));
67+
}
5368
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* This file is part of PHPWord - A pure PHP library for reading and writing
4+
* word processing documents.
5+
*
6+
* PHPWord is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
12+
*
13+
* @see https://github.com/PHPOffice/PHPWord
14+
* @copyright 2010-2017 PHPWord contributors
15+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16+
*/
17+
18+
namespace PhpOffice\PhpWord\Writer\Word2007\Style;
19+
20+
use PhpOffice\PhpWord\TestHelperDOCX;
21+
22+
/**
23+
* Test class for PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph
24+
*
25+
* @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph
26+
* @runTestsInSeparateProcesses
27+
*/
28+
class ParagraphTest extends \PHPUnit\Framework\TestCase
29+
{
30+
/**
31+
* Executed before each method of the class
32+
*/
33+
public function tearDown()
34+
{
35+
TestHelperDOCX::clear();
36+
}
37+
38+
/**
39+
* Test write styles
40+
*/
41+
public function testParagraphNumbering()
42+
{
43+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
44+
$phpWord->addParagraphStyle('testStyle', array('indent' => '10'));
45+
$section = $phpWord->addSection();
46+
$section->addText('test', null, array('numStyle' => 'testStyle', 'numLevel' => '1'));
47+
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
48+
49+
$path = '/w:document/w:body/w:p/w:pPr/w:numPr/w:ilvl';
50+
$this->assertTrue($doc->elementExists($path));
51+
}
52+
}

0 commit comments

Comments
 (0)