This is a test
And another one
';
$footnotesXml = '
footnote text
';
$endnotesXml = '
This is an endnote
';
$phpWord = $this->getDocumentFromString(array('document' => $documentXml, 'footnotes' => $footnotesXml, 'endnotes' => $endnotesXml));
$elements = $phpWord->getSection(0)->getElements();
$this->assertInstanceOf('PhpOffice\PhpWord\Element\TextRun', $elements[0]);
/** @var \PhpOffice\PhpWord\Element\TextRun $textRun */
$textRun = $elements[0];
//test the text in the first paragraph
/** @var \PhpOffice\PhpWord\Element\Text $text */
$text = $elements[0]->getElement(0);
$this->assertInstanceOf('PhpOffice\PhpWord\Element\Text', $text);
$this->assertEquals('This is a test', $text->getText());
//test the presence of the footnote in the document.xml
/** @var \PhpOffice\PhpWord\Element\Footnote $footnote */
$documentFootnote = $textRun->getElement(1);
$this->assertInstanceOf('PhpOffice\PhpWord\Element\Footnote', $documentFootnote);
$this->assertEquals(1, $documentFootnote->getRelationId());
//test the presence of the footnote in the footnote.xml
/** @var \PhpOffice\PhpWord\Element\Footnote $footnote */
$footnote = $phpWord->getFootnotes()->getItem(1);
$this->assertInstanceOf('PhpOffice\PhpWord\Element\Footnote', $footnote);
$this->assertInstanceOf('PhpOffice\PhpWord\Element\Text', $footnote->getElement(0));
$this->assertEquals('footnote text', $footnote->getElement(0)->getText());
$this->assertEquals(1, $footnote->getRelationId());
//test the text in the second paragraph
/** @var \PhpOffice\PhpWord\Element\Text $text */
$text = $elements[1]->getElement(0);
$this->assertInstanceOf('PhpOffice\PhpWord\Element\Text', $text);
$this->assertEquals('And another one', $text->getText());
//test the presence of the endnote in the document.xml
/** @var \PhpOffice\PhpWord\Element\Endnote $endnote */
$documentEndnote = $elements[1]->getElement(1);
$this->assertInstanceOf('PhpOffice\PhpWord\Element\Endnote', $documentEndnote);
$this->assertEquals(2, $documentEndnote->getRelationId());
//test the presence of the endnote in the endnote.xml
/** @var \PhpOffice\PhpWord\Element\Endnote $endnote */
$endnote = $phpWord->getEndnotes()->getItem(1);
$this->assertInstanceOf('PhpOffice\PhpWord\Element\Endnote', $endnote);
$this->assertEquals(2, $endnote->getRelationId());
$this->assertInstanceOf('PhpOffice\PhpWord\Element\Text', $endnote->getElement(0));
$this->assertEquals('This is an endnote', $endnote->getElement(0)->getText());
}
}