Author: kn
Date: Wed Feb  6 16:18:09 2008
New Revision: 7314

Log:
- Added save() method to document class
  - Test and implement for XML documents

Added:
    experimental/Document/tests/files/xhtml_sample_basic_indented.xml
Modified:
    experimental/Document/src/document/rst.php
    experimental/Document/src/document/xml_base.php
    experimental/Document/src/interfaces/document.php
    experimental/Document/tests/document_xml_base_test.php

Modified: experimental/Document/src/document/rst.php
==============================================================================
--- experimental/Document/src/document/rst.php [iso-8859-1] (original)
+++ experimental/Document/src/document/rst.php [iso-8859-1] Wed Feb  6 16:18:09 
2008
@@ -84,6 +84,18 @@
     {
         // @TODO: Implement
     }
+
+    /**
+     * Return document as string
+     * 
+     * Serialize the document to a string an return it.
+     *
+     * @return string
+     */
+    public function save()
+    {
+        // @TODO: Implement
+    }
 }
 
 ?>

Modified: experimental/Document/src/document/xml_base.php
==============================================================================
--- experimental/Document/src/document/xml_base.php [iso-8859-1] (original)
+++ experimental/Document/src/document/xml_base.php [iso-8859-1] Wed Feb  6 
16:18:09 2008
@@ -42,6 +42,14 @@
 
         // Load XML document
         $this->document = new DOMDocument();
+
+        // Check if we should format the document later
+        if ( $this->options->indentXml )
+        {
+            $this->document->preserveWhiteSpace = false;
+            $this->document->formatOutput = true;
+        }
+
         $this->document->loadXml( $string );
 
         $errors = ( $this->options->failOnError ?
@@ -70,6 +78,18 @@
     public function getDomDocument()
     {
         return $this->document;
+    }
+
+    /**
+     * Return document as string
+     * 
+     * Serialize the document to a string an return it.
+     *
+     * @return string
+     */
+    public function save()
+    {
+        return $this->document->saveXml();
     }
 
     /**

Modified: experimental/Document/src/interfaces/document.php
==============================================================================
--- experimental/Document/src/interfaces/document.php [iso-8859-1] (original)
+++ experimental/Document/src/interfaces/document.php [iso-8859-1] Wed Feb  6 
16:18:09 2008
@@ -104,6 +104,26 @@
     abstract public function createFromDocbook( ezcDocumentDocbook $document );
 
     /**
+     * Return document as string
+     * 
+     * Serialize the document to a string an return it.
+     *
+     * @return string
+     */
+    abstract public function save();
+
+    /**
+     * Magic wrapper for save()
+     * 
+     * @ignore
+     * @return string
+     */
+    public function __toString()
+    {
+        return $this->save();
+    }
+
+    /**
      * Returns the value of the property $name.
      *
      * @throws ezcBasePropertyNotFoundException

Modified: experimental/Document/tests/document_xml_base_test.php
==============================================================================
--- experimental/Document/tests/document_xml_base_test.php [iso-8859-1] 
(original)
+++ experimental/Document/tests/document_xml_base_test.php [iso-8859-1] Wed Feb 
 6 16:18:09 2008
@@ -90,6 +90,33 @@
             'DOMDocument not created properly'
         );
     }
+
+    public function testSerializeXml()
+    {
+        $doc = new ezcDocumentXhtml();
+        $doc->loadFile( 
+            dirname( __FILE__ ) . '/files/xhtml_sample_basic.xml'
+        );
+
+        $this->assertEquals(
+            file_get_contents( dirname( __FILE__ ) . 
'/files/xhtml_sample_basic.xml' ),
+            $doc->save()
+        );
+    }
+
+    public function testSerializeXmlFormat()
+    {
+        $doc = new ezcDocumentXhtml();
+        $doc->options->indentXml = true;
+        $doc->loadFile( 
+            dirname( __FILE__ ) . '/files/xhtml_sample_basic.xml'
+        );
+
+        $this->assertEquals(
+            file_get_contents( dirname( __FILE__ ) . 
'/files/xhtml_sample_basic_indented.xml' ),
+            $doc->save()
+        );
+    }
 }
 
 ?>

Added: experimental/Document/tests/files/xhtml_sample_basic_indented.xml
==============================================================================
--- experimental/Document/tests/files/xhtml_sample_basic_indented.xml (added)
+++ experimental/Document/tests/files/xhtml_sample_basic_indented.xml 
[iso-8859-1] Wed Feb  6 16:18:09 2008
@@ -1,0 +1,40 @@
+<?xml version="1.0"?>
+<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+    <title>Test document</title>
+  </head>
+  <body>
+    <h1>Header 1</h1>
+    <p>
+Para 1
+</p>
+    <h2>Header 1.1</h2>
+    <p>
+Para 2
+</p>
+    <h1>Header 2</h1>
+    <p>
+Inline <a href="http://example.com";>example</a> link.
+</p>
+    <pre>
+Some literal text
+</pre>
+    <p>
+Inline Image: <img src="http://www.google.com/intl/en_ALL/images/logo.gif"/> 
image
+</p>
+    <img src="http://www.google.com/intl/en_ALL/images/logo.gif"/>
+    <p>
+Inline tags:
+<strong>storng text</strong>
+<em>emphasized text</em>
+<tt>literal</tt>
+<sub>subscript</sub>
+<sup>superscript</sup>
+<q>quote</q>
+<cite>cite title</cite>
+<acronym>FBI</acronym>
+<code>a = b</code>
+</p>
+  </body>
+</html>


-- 
svn-components mailing list
svn-components@lists.ez.no
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to