From b766098bbfbb52838e9fed15db9871464dd27e3e Mon Sep 17 00:00:00 2001 From: = Date: Fri, 14 Oct 2016 14:08:38 +0300 Subject: [PATCH] Small fix --- src/DiDom/Element.php | 4 ++++ tests/DiDom/ElementTest.php | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/DiDom/Element.php b/src/DiDom/Element.php index f8596e5..fa09e4f 100644 --- a/src/DiDom/Element.php +++ b/src/DiDom/Element.php @@ -262,6 +262,8 @@ public function innerHtml($options = LIBXML_NOEMPTYTAG) * Sets inner HTML. * * @param string $html + * + * @return Element */ public function setInnerHtml($html) { @@ -292,6 +294,8 @@ public function setInnerHtml($html) Errors::restore(); } + + return $this; } /** diff --git a/tests/DiDom/ElementTest.php b/tests/DiDom/ElementTest.php index 7f53fe8..1f00290 100644 --- a/tests/DiDom/ElementTest.php +++ b/tests/DiDom/ElementTest.php @@ -273,6 +273,21 @@ public function testInnerHtml() $this->assertTrue(is_string($document->find('body')[0]->innerHtml())); } + public function testSetInnerHtml() + { + $list = new Element('ul'); + + $html = '
  • One
  • Two
  • Three
  • '; + + $this->assertEquals($list, $list->setInnerHtml($html)); + $this->assertEquals(['One', 'Two', 'Three'], $list->find('li::text')); + + $span = new Element('span'); + + $this->assertEquals($span, $span->setInnerHtml(' Foo ')); + $this->assertEquals(' Foo ', $span->html()); + } + public function testHtmlWithOptions() { $html = '';