Skip to content

Commit db129b4

Browse files
committed
Update footnote unit tests
1 parent 2cdad4b commit db129b4

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/PhpWord/Footnote.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,15 @@ public static function addElement(FootnoteElement $footnote)
4848
*/
4949
public static function setElement($index, FootnoteElement $footnote)
5050
{
51-
self::$elements[$index] = $footnote;
51+
if (array_key_exists($index, self::$elements)) {
52+
self::$elements[$index] = $footnote;
53+
}
5254
}
5355

5456
/**
5557
* Get element by index
5658
*
59+
* @param integer $index
5760
* @return FootnoteElement
5861
* @since 0.9.2
5962
*/

tests/PhpWord/Tests/FootnoteTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
2323
*/
2424
public function testFootnote()
2525
{
26-
$footnoteElement = new \PhpOffice\PhpWord\Element\Footnote();
27-
$rIdFootnote = Footnote::addFootnoteElement($footnoteElement);
28-
$rIdLink = Footnote::addFootnoteLinkElement('http://test.com');
26+
$footnote1 = new \PhpOffice\PhpWord\Element\Footnote('default');
27+
$footnote2 = new \PhpOffice\PhpWord\Element\Footnote('first');
28+
$rId = Footnote::addElement($footnote1);
29+
Footnote::setElement(1, $footnote2);
2930

30-
$this->assertEquals(1, $rIdFootnote);
31-
$this->assertEquals(1, $rIdLink);
32-
$this->assertEquals(1, count(Footnote::getFootnoteElements()));
33-
$this->assertEquals(1, count(Footnote::getFootnoteLinkElements()));
31+
$this->assertEquals(1, $rId);
32+
$this->assertEquals(1, count(Footnote::getElements()));
33+
$this->assertEquals($footnote2, Footnote::getElement(1));
34+
$this->assertNull(Footnote::getElement(2));
3435

3536
Footnote::resetElements();
36-
$this->assertEquals(0, count(Footnote::getFootnoteElements()));
37+
$this->assertEquals(0, Footnote::countElements());
3738
}
3839
}
54.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)