|
From: <nma...@us...> - 2006-03-15 08:54:30
|
Revision: 26 Author: nmarkgraf Date: 2006-03-15 00:54:17 -0800 (Wed, 15 Mar 2006) ViewCVS: http://svn.sourceforge.net/opendocumentphp/?rev=26&view=rev Log Message: ----------- One add and some bug fixes: - Added a new test case, OpenDocumentSingleTest, which proves that our current OpenDocumentSingle implementation has some bugs. - Minor bug fixes in OpenDocumentManifestTest and samples/TestOutput @Alex: Maybe you can try to fix the bug in OpenDocumentSingle? Norman Modified Paths: -------------- poc/src/OpenDocumentManifestTest.php poc/src/OpenDocumentSingle.php poc/src/samples/TestOutput.php Added Paths: ----------- poc/src/OpenDocumentSingleTest.php Modified: poc/src/OpenDocumentManifestTest.php =================================================================== --- poc/src/OpenDocumentManifestTest.php 2006-03-14 13:57:51 UTC (rev 25) +++ poc/src/OpenDocumentManifestTest.php 2006-03-15 08:54:17 UTC (rev 26) @@ -5,7 +5,7 @@ * $Id$ * * @copyright Copyright © 2006, Norman Markgraf, et al. - * @lecense GNU General Public License + * @license GNU General Public License * @author Norman Markgraf <nma...@us...> * @version $Revision$ * @package OpenDocument Modified: poc/src/OpenDocumentSingle.php =================================================================== --- poc/src/OpenDocumentSingle.php 2006-03-14 13:57:51 UTC (rev 25) +++ poc/src/OpenDocumentSingle.php 2006-03-15 08:54:17 UTC (rev 26) @@ -14,13 +14,31 @@ */ class OpenDocumentSingle extends OpenDocumentAbstract implements OpenDocument { + /** + * + * @access private + * @since 0.3.0 + */ private $isCommited; + + /** + * + * @access private + * @since 0.3.0 + */ private $dom; + + /** + * + * @access private + * @since 0.3.0 + */ private $root; - /** - * namespace OpenDocument office - */ + /** + * namespace OpenDocument office + * @since 0.3.0 + */ const NS_OFFICE = "urn:oasis:names:tc:opendocument:xmlns:office:1.0"; /** @@ -84,9 +102,15 @@ */ private function commit() { $this->logger->debug( "OpenDocumentSingle->commit()" ); - foreach( $this->DocumentObjects as $key => $class) { - $class->commit(); - } + if (array_key_exists( "meta", $this->DocumentObjects )) { + $this->DocumentObjects["meta"]->commit(); + } + if (array_key_exists( "style", $this->DocumentObjects )) { + $this->DocumentObjects["style"]->commit(); + } + if (array_key_exists( "content", $this->DocumentObjects )) { + $this->DocumentObjects["content"]->commit(); + } $this->dom->appendChild( $this->root ); $this->isCommited = true; } @@ -98,17 +122,29 @@ * @since 0.3.0 */ public function get() { - if (!($this->isCommited)) { - $this->commit(); - } $this->logger->debug( "OpenDocumentSingle->get()" ); - return $this->dom->saveXML(); + return $this->getAsDOM()->saveXML(); } /** * * @access public * + * @since 0.4.3 + */ + public function getAsDOM() { + if (!($this->isCommited)) { + $this->commit(); + } + $this->logger->debug( "OpenDocumentSingle->getAsDOM()" ); + return $this->dom; + } + + + /** + * + * @access public + * * @since 0.3.0 */ public function save( $altFilename=0 ) { Added: poc/src/OpenDocumentSingleTest.php =================================================================== --- poc/src/OpenDocumentSingleTest.php (rev 0) +++ poc/src/OpenDocumentSingleTest.php 2006-03-15 08:54:17 UTC (rev 26) @@ -0,0 +1,138 @@ +<?php +/** + * TestCase for OpenDocumentSingle class + * + * $Id$ + * + * @copyright Copyright © 2006, Norman Markgraf, et al. + * @license GNU General Public License + * @author Norman Markgraf <nma...@us...> + * @version $Revision$ + * @package OpenDocument + * @subpackage UnitTest + * @since 0.4.3 + */ + +require_once "PHPUnit2/Framework/TestCase.php"; +require_once "OpenDocumentSingle.php"; + +class OpenDocumentSingleTest extends PHPUnit2_Framework_TestCase { + const PathToRNG = "./etc/test/"; + const DocumentRNG = "OpenDocument-schema-v1.0-os.rng"; + + /** + * @since 0.4.3 + */ + function testLittleSingleDocument() { + $ODT = new OpenDocumentSingle(); + + $this->assertNotNull( $ODT, "Error constructing OpenDocumentManifest without a given mimetype." ); + + $meta = $ODT->getMeta(); + $meta->addDublinCore( "title", "Test" ); + $meta->addDublinCore( "creator", "Testo Tester" ); + $meta->addDublinCore( "language", "en-EN" ); + $meta->addDublinCore( "date", date("Y-m-d\TH:i:s") ); + $meta->addGenerator( ); + $meta->addInitialCreator( "Testo Tester" ); + $meta->addCreationDate(); + + $content = $ODT->getContent(); + + $content->addNoScript(); + + $content->addFontFace( "Test", "Tahoma" ); + + $content->addNoAutomaticStyles(); + + $text = $content->getBody()->getText(); + + $text->addNoForms(); + + $text->addToText( $text->getTextHeading( "Heading", "The first step" ) ); + $text->addToText( $text->getTextParagraph( "Paragraph", "This is a little test!" ) ); + + $style = $ODT->getStyle(); + + $styleAttr = array(); + $styleAttr[ "font-family" ] ="Tahoma"; + $style->getFontFaceDecl()->addFontFace( "Test", $styleAttr ); + unset( $styleAttr ); + + // Set default style + $style->addDefaultStyle( "paragraph" ); + + $foAttr = array( "hypenation-ladder-count" => "no-limit" ); + + $styleAttr = array(); + $styleAttr[ "text-autospace" ] = "ideograph-alpha"; + $styleAttr[ "punctuation-wrap" ] = "hanging"; + $styleAttr[ "line-break" ] = "strict"; + $styleAttr[ "tab-stop-distance" ] = "1.251cm"; + $styleAttr[ "writeing-mode" ] = "page"; + + $style->addDefaultStyleParagraphProperties( "paragraph", $styleAttr, $foAttr ); + + unset( $foAttr ); + unset( $styleAttr ); + + $foAttr = array(); + $foAttr[ "font-size" ] = "12pt"; + $foAttr[ "language" ] = "de"; + $foAttr[ "country" ] = "DE"; + $foAttr[ "hyphenate" ] = "false"; + $foAttr[ "hypenation-remain-char-count" ] = "2"; + $foAttr[ "hypenation-push-char-count" ] = "2"; + + $styleAttr = array(); + $styleAttr[ "use-window-font-color" ] = "true"; + $styleAttr[ "font-name" ] = "Times New Roman"; + $styleAttr[ "font-name-asian" ] = "Arial Unicode MS"; + $styleAttr[ "font-size-asian" ] = "12pt"; + $styleAttr[ "language-asian" ] = "none"; + $styleAttr[ "country-asian" ] = "none"; + $styleAttr[ "font-name-complex" ] = "Tahoma"; + $styleAttr[ "font-site-complex" ] = "12pt"; + $styleAttr[ "language-complex" ] = "none"; + $styleAttr[ "country-complex" ] = "none"; + + $style->addDefaultStyleTextProperties( "paragraph", $styleAttr, $foAttr ); + + //Set a style + $styleAttr = array( "family"=>"paragraph", "class"=>"text" ); + $style->addStyle( "Paragraph", $styleAttr ); + + //Set a style + $style->addStyle( "Heading", $styleAttr ); + + unset( $styleAttr ); + unset( $foAttr ); + + $foAttr = array( "margin-top"=>"0.423cm", "margin-bottom"=>"0.212cm", + "keep-with-next"=>"always" ); + $style->addStyleParagraphProperties( "Heading", 0, $foAttr ); + + unset( $foAttr ); + + $foAttr = array( "font-size" => "20pt" ); + $styleAttr = array(); + $styleAttr[ "font-name" ] = "Arial"; + $styleAttr[ "font-name-asian" ] = "MS Mincho"; + $styleAttr[ "font-size" ] = "20pt"; + $styleAttr[ "font-name-complex" ] = "Tahoma1"; + $styleAttr[ "font-size-complex" ] = "20pt"; + $style->addStyleTextProperties( "Heading", $styleAttr, $foAttr ); + + $Document = $ODT->getAsDOM(); + + $this->assertNotNull( $Document, "Returned value of OpenDocumentSingle->get() is NULL." ); + + $RelaxNG = self::PathToRNG . self::DocumentRNG; + + $this->assertTrue( $Document->relaxNGValidate( $RelaxNG ), + "SingleDocument does not match OpenDocument Relax NG schema." ); + + } + +} +?> \ No newline at end of file Property changes on: poc/src/OpenDocumentSingleTest.php ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Modified: poc/src/samples/TestOutput.php =================================================================== --- poc/src/samples/TestOutput.php 2006-03-14 13:57:51 UTC (rev 25) +++ poc/src/samples/TestOutput.php 2006-03-15 08:54:17 UTC (rev 26) @@ -49,7 +49,7 @@ $meta->addDublinCore( "creator", $creator ); $meta->addDublinCore( "language", "en-EN" ); $meta->addDublinCore( "date", date("Y-m-d\TH:i:s") ); - $meta->addGenerator( "" ); + $meta->addGenerator( ); $meta->addInitialCreator( $creator ); $meta->addCreationDate(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |