Update footnote unit tests

This commit is contained in:
Ivan Lanin 2014-04-09 18:47:10 +07:00
parent 2cdad4b247
commit db129b4805
3 changed files with 13 additions and 9 deletions

View File

@ -48,12 +48,15 @@ class Footnote
*/ */
public static function setElement($index, FootnoteElement $footnote) public static function setElement($index, FootnoteElement $footnote)
{ {
self::$elements[$index] = $footnote; if (array_key_exists($index, self::$elements)) {
self::$elements[$index] = $footnote;
}
} }
/** /**
* Get element by index * Get element by index
* *
* @param integer $index
* @return FootnoteElement * @return FootnoteElement
* @since 0.9.2 * @since 0.9.2
*/ */

View File

@ -23,16 +23,17 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
*/ */
public function testFootnote() public function testFootnote()
{ {
$footnoteElement = new \PhpOffice\PhpWord\Element\Footnote(); $footnote1 = new \PhpOffice\PhpWord\Element\Footnote('default');
$rIdFootnote = Footnote::addFootnoteElement($footnoteElement); $footnote2 = new \PhpOffice\PhpWord\Element\Footnote('first');
$rIdLink = Footnote::addFootnoteLinkElement('http://test.com'); $rId = Footnote::addElement($footnote1);
Footnote::setElement(1, $footnote2);
$this->assertEquals(1, $rIdFootnote); $this->assertEquals(1, $rId);
$this->assertEquals(1, $rIdLink); $this->assertEquals(1, count(Footnote::getElements()));
$this->assertEquals(1, count(Footnote::getFootnoteElements())); $this->assertEquals($footnote2, Footnote::getElement(1));
$this->assertEquals(1, count(Footnote::getFootnoteLinkElements())); $this->assertNull(Footnote::getElement(2));
Footnote::resetElements(); Footnote::resetElements();
$this->assertEquals(0, count(Footnote::getFootnoteElements())); $this->assertEquals(0, Footnote::countElements());
} }
} }