-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d49997
commit ed1677e
Showing
6 changed files
with
203 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace DiDom; | ||
|
||
use DOMDocumentFragment; | ||
use InvalidArgumentException; | ||
|
||
/** | ||
* @property string $tag | ||
*/ | ||
class DocumentFragment extends Node | ||
{ | ||
/** | ||
* @param DOMDocumentFragment $documentFragment | ||
*/ | ||
public function __construct($documentFragment) | ||
{ | ||
if ( ! $documentFragment instanceof DOMDocumentFragment) { | ||
throw new InvalidArgumentException(sprintf('Argument 1 passed to %s must be an instance of DOMDocumentFragment, %s given', __METHOD__, (is_object($documentFragment) ? get_class($documentFragment) : gettype($documentFragment)))); | ||
} | ||
|
||
$this->setNode($documentFragment); | ||
} | ||
|
||
/** | ||
* Append raw XML data. | ||
* | ||
* @param string $data | ||
*/ | ||
public function appendXml($data) | ||
{ | ||
$this->node->appendXML($data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace DiDom\Tests; | ||
|
||
use DiDom\Document; | ||
use DiDom\DocumentFragment; | ||
use DOMElement; | ||
use InvalidArgumentException; | ||
|
||
class DocumentFragmentTest extends TestCase | ||
{ | ||
/** | ||
* @expectedException InvalidArgumentException | ||
*/ | ||
public function testConstructorWithInvalidNodeType() | ||
{ | ||
new DocumentFragment(new DOMElement('span')); | ||
} | ||
|
||
public function testAppendXml() | ||
{ | ||
$document = new Document(); | ||
|
||
$documentFragment = $document->createDocumentFragment(); | ||
|
||
$documentFragment->appendXml('<foo>bar</foo>'); | ||
|
||
$this->assertEquals('<foo>bar</foo>', $documentFragment->innerXml()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters