diff options
author | Christian Stocker <chregu@php.net> | 2003-10-27 17:51:55 +0000 |
---|---|---|
committer | Christian Stocker <chregu@php.net> | 2003-10-27 17:51:55 +0000 |
commit | 901153b441ffe736c1639dfcda42109791d655cf (patch) | |
tree | baf9b5cbf9d8c00650f2b815968ea2824d06d21a | |
parent | e735e44f52df9b98e841729234e0742dae359da0 (diff) | |
download | php-git-901153b441ffe736c1639dfcda42109791d655cf.tar.gz |
extending of domDocument class test
-rw-r--r-- | ext/dom/tests/dom006.phpt | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/ext/dom/tests/dom006.phpt b/ext/dom/tests/dom006.phpt new file mode 100644 index 0000000000..7f393003d5 --- /dev/null +++ b/ext/dom/tests/dom006.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test 6: Extends Test +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + +Class books extends domDocument { + function __construct() { + /* We must first call the constructor for the parent to create the document + otherwise this class will not work */ + parent::__construct(); + } + + function addBook($title, $author) { + $titleElement = $this->createElement("title"); + $titleElement->appendChild($this->createTextNode($title)); + $authorElement = $this->createElement("author"); + $authorElement->appendChild($this->createTextNode($author)); + + $bookElement = $this->createElement("book"); + + $bookElement->appendChild($titleElement); + $bookElement->appendChild($authorElement); + $this->documentElement->appendChild($bookElement); + } + +} + +$dom = new books; + +$dom->load(dirname(__FILE__)."/book.xml"); +$dom->addBook("PHP de Luxe", "Richard Samar, Christian Stocker"); +print $dom->saveXML(); +--EXPECT-- +<?xml version="1.0"?> +<books> + <book> + <title>The Grapes of Wrath</title> + <author>John Steinbeck</author> + </book> + <book> + <title>The Pearl</title> + <author>John Steinbeck</author> + </book> +<book><title>PHP de Luxe</title><author>Richard Samar, Christian Stocker</author></book></books> |