Skip to content

Commit ae34ae9

Browse files
committed
Add testcase
1 parent 58e0200 commit ae34ae9

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
],
3737
"scripts": {
3838
"test": [
39-
"phpunit --color=always"
39+
"phpunit --color=always --filter testReadAlternateContent"
4040
],
4141
"test-no-coverage": [
4242
"phpunit --color=always --no-coverage"

tests/PhpWord/Reader/Word2007/ElementTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,49 @@
2525
*/
2626
class ElementTest extends AbstractTestReader
2727
{
28+
/**
29+
* Test reading of alternate content value
30+
*/
31+
public function testReadAlternateContent()
32+
{
33+
$documentXml = '<w:p>
34+
<w:r>
35+
<mc:AlternateContent>
36+
<mc:Choice Requires="wps"></mc:Choice>
37+
<mc:Fallback>
38+
<w:pict>
39+
<v:rect>
40+
<v:textbox>
41+
<w:txbxContent>
42+
<w:p>
43+
<w:pPr>
44+
<w:jc w:val="center"/>
45+
</w:pPr>
46+
<w:r>
47+
<w:t>Test node value</w:t>
48+
</w:r>
49+
</w:p>
50+
</w:txbxContent>
51+
</v:textbox>
52+
</v:rect>
53+
</w:pict>
54+
</mc:Fallback>
55+
</mc:AlternateContent>
56+
</w:r>
57+
</w:p>';
58+
59+
$phpWord = $this->getDocumentFromString(array('document' => $documentXml));
60+
61+
$elements = $phpWord->getSection(0)->getElements();
62+
63+
$this->assertInstanceOf('PhpOffice\PhpWord\Element\TextRun', $elements[0]);
64+
$this->assertInstanceOf('PhpOffice\PhpWord\Element\Text', $elements[0]->getElement(0));
65+
66+
$text = $elements[0];
67+
68+
$this->assertEquals('Test node value', trim($text->getElement(0)->getText()));
69+
}
70+
2871
/**
2972
* Test reading of textbreak
3073
*/

tests/PhpWord/_includes/AbstractTestReader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ abstract class AbstractTestReader extends \PHPUnit\Framework\TestCase
2424
{
2525
private $parts = array(
2626
'styles' => array('class' => 'PhpOffice\PhpWord\Reader\Word2007\Styles', 'xml' => '<w:styles xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:docDefaults><w:rPrDefault><w:rPr><w:sz w:val="24"/></w:rPr></w:rPrDefault></w:docDefaults>{toReplace}</w:styles>'),
27-
'document' => array('class' => 'PhpOffice\PhpWord\Reader\Word2007\Document', 'xml' => '<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body>{toReplace}</w:body></w:document>'),
27+
'document' => array('class' => 'PhpOffice\PhpWord\Reader\Word2007\Document', 'xml' => '<w:document xmlns:v="urn:schemas-microsoft-com:vml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body>{toReplace}</w:body></w:document>'),
2828
'footnotes' => array('class' => 'PhpOffice\PhpWord\Reader\Word2007\Footnotes', 'xml' => '<w:footnotes xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">{toReplace}</w:footnotes>'),
2929
'endnotes' => array('class' => 'PhpOffice\PhpWord\Reader\Word2007\Endnotes', 'xml' => '<w:endnotes xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">{toReplace}</w:endnotes>'),
3030
'settings' => array('class' => 'PhpOffice\PhpWord\Reader\Word2007\Settings', 'xml' => '<w:comments xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">{toReplace}</w:comments>'),

0 commit comments

Comments
 (0)