|
From: <nma...@us...> - 2006-03-13 10:13:45
|
Revision: 21 Author: nmarkgraf Date: 2006-03-13 02:13:38 -0800 (Mon, 13 Mar 2006) ViewCVS: http://svn.sourceforge.net/opendocumentphp/?rev=21&view=rev Log Message: ----------- Bug fixes. Modified Paths: -------------- poc/src/OpenDocumentMeta.php poc/src/OpenDocumentMetaTest.php Modified: poc/src/OpenDocumentMeta.php =================================================================== --- poc/src/OpenDocumentMeta.php 2006-03-13 08:58:48 UTC (rev 20) +++ poc/src/OpenDocumentMeta.php 2006-03-13 10:13:38 UTC (rev 21) @@ -165,7 +165,7 @@ * * @since 0.4.0 */ - public function addGenerator( $generator ) { + public function addGenerator( $generator=0 ) { $lgenerator = ""; if (empty($generator)) { Modified: poc/src/OpenDocumentMetaTest.php =================================================================== --- poc/src/OpenDocumentMetaTest.php 2006-03-13 08:58:48 UTC (rev 20) +++ poc/src/OpenDocumentMetaTest.php 2006-03-13 10:13:38 UTC (rev 21) @@ -13,121 +13,181 @@ require_once "PHPUnit2/Framework/TestCase.php"; require_once "OpenDocumentMeta.php"; - class OpenDocumentMetaTest extends PHPUnit2_Framework_TestCase - { - /** - * namespace OpenDocument office - */ - const NS_OFFICE = "urn:oasis:names:tc:opendocument:xmlns:office:1.0"; - /** - * namespace Dublin Core - */ - const NS_DC = "http://purl.org/dc/elements/1.1/"; +class OpenDocumentMetaTest extends PHPUnit2_Framework_TestCase { + + /** + * namespace OpenDocument office + */ + const NS_OFFICE = "urn:oasis:names:tc:opendocument:xmlns:office:1.0"; + + /** + * namespace Dublin Core + */ + const NS_DC = "http://purl.org/dc/elements/1.1/"; + + const PathToRNG = "./etc/test/"; + const MetaRNG = "OpenDocument-schema-v1.0-os.rng"; - public function testConstructWithoutDom(){ - $ODM = new OpenDocumentMeta(); + /** + * + * @since 0.4.0 + */ + public function testConstructWithoutDom() { + $ODM = new OpenDocumentMeta(); - $this->assertNotNull( $ODM ); - - $resultDom = $ODM->get(); - $this->assertNotNull($resultDom, "No result." ); - //$this->assertType(new DOMC$resultDom, new DOMDocument(), "Result is not for type DOMDocument!" ); + $this->assertNotNull( $ODM ); + + $Document = $ODM->get(); + $this->assertNotNull($Document, "No result." ); + + $RelaxNG = self::PathToRNG . self::MetaRNG; + + $this->assertTrue( $Document->relaxNGValidate( $RelaxNG ), + "Manifest does not match Manifest Relax NG schema." ); + + } + + /** + * + * @since 0.4.0 + */ + public function testConstructWithDom(){ +/* ***FIX ME*** + $mimetype = "application/vnd.oasis.opendocument.text"; + $testDom = new DOMDocument( "1.0", "utf-8" ); + + $root = $testDom->createElementNS( self::NS_OFFICE, "office:document" ); + $root->setAttributeNS( self::NS_OFFICE, "office:mimetype", $mimetype ); + $testDom->appendChild( $root ); + + $node = $testDom->createElementNS( self::NS_OFFICE, "office:meta" ); - $xpath = new DOMXPath( $resultDom ); - $xpath->registerNamespace( "office", self::NS_OFFICE ); + $ODM = new OpenDocumentMeta( $testDom, $node ); - // test for right root tag - $query = "/office:document-meta"; - $entries = $xpath->query( $query ); - $this->assertEquals( 1, $entries->length, "Wrong root tag." ); - - // test for right version - $query = '/office:document-meta[@office:version="1.0"]'; - $entries = $xpath->query( $query ); - $this->assertEquals( 1, $entries->length, "Wrong document version." ); + + $Document = $ODM->get(); + $this->assertNotNull($Document, "No result." ); + + $RelaxNG = self::PathToRNG . self::MetaRNG; + + $this->assertTrue( $Document->relaxNGValidate( $RelaxNG ), + "Manifest does not match Manifest Relax NG schema." ); +*/ + } + + /** + * + * @since 0.4.1 + */ + public function testAddGetDublinCore() { + $ODM = new OpenDocumentMeta(); + $dc_creator_tag = "creator"; + $dc_creator = "Willy Testo"; + + $this->assertNotNull( $ODM ); + + $this->assertEquals( "", $ODM->getDublicCore( $dc_creator_tag ), + "Returned Dublin Core should be empty, was not." ); - // test for right body tag - $query = "/office:document-meta/office:meta"; - $entries = $xpath->query( $query ); - $this->assertEquals( 1, $entries->length, "Wrong meta tag" ); - - unset( $ODM ); - unset( $resultDom ); - unset( $query ); - unset( $entries ); - } - - public function testConstructWithDom(){ - $testDom = new DOMDocument(); - $node = $testDom->createElementNS( self::NS_OFFICE, "office:meta" ); + + $ODM->addDublinCore( $dc_creator_tag, $dc_creator ); + $ODM->commit(); - $ODM = new OpenDocumentMeta( $testDom, $node ); - $testDom->appendChild( $node ); - - $this->assertNotNull( $ODM ); + $this->assertEquals( $dc_creator, $ODM->getDublicCore( $dc_creator_tag ), + "Dublin Core entry was not correctly returned." ); - $resultDom = $ODM->get(); - $this->assertNotNull($resultDom, "No result." ); - //$this->assertType($resultDom, new DOMDocument(), "Result is not for type DOMDocument!" ); - - $xpath = new DOMXPath( $resultDom ); - $xpath->registerNamespace( "office", self::NS_OFFICE ); - - - // test for right root tag - $query = "/office:meta"; - $entries = $xpath->query( $query ); - $this->assertEquals( 1, $entries->length, "Wrong meta tag" ); - - unset( $ODM ); - unset( $resultDom ); - unset( $query ); - unset( $entries ); - } - - public function testAddGetDublinCore() { - $ODM = new OpenDocumentMeta(); + $Document = $ODM->get(); + $this->assertNotNull($Document, "No result." ); + + $RelaxNG = self::PathToRNG . self::MetaRNG; + + $this->assertTrue( $Document->relaxNGValidate( $RelaxNG ), + "Manifest does not match Manifest Relax NG schema." ); + } + + /** + * + * @since 0.4.2 + */ + public function testAddGetGeneratorWithGenerator() { + $ODM = new OpenDocumentMeta(); + $generator = "Testo Generator"; - $this->assertNotNull( $ODM ); + $this->assertNotNull( $ODM ); - $this->assertEquals( "", $ODM->getDublicCore( "xxx" ), "Returned Dublin Core should be empty, was not." ); + $this->assertEquals( "", $ODM->getGenerator(), + "Generator should be empty, was not." ); - $ODM->addDublinCore( "peek", "poke"); - $ODM->commit(); - - $this->assertEquals( "poke", $ODM->getDublicCore( "peek"), "Dublin Core entry was not correctly returned." ); - unset( $ODM ); - } + $ODM->addGenerator( $generator ); + $ODM->commit(); + + $this->assertEquals( $generator, $ODM->getGenerator(), + "Generator was not correctly returned. (".$ODM->getGenerator().")" ); + + $Document = $ODM->get(); + $this->assertNotNull($Document, "No result." ); - public function testAddGetGenerator() { - $ODM = new OpenDocumentMeta(); + $RelaxNG = self::PathToRNG . self::MetaRNG; + + $this->assertTrue( $Document->relaxNGValidate( $RelaxNG ), + "Manifest does not match Manifest Relax NG schema." ); + } + + /** + * + * @since 0.4.2 + */ + public function testAddGetGeneratorWithOutGenerator() { + $ODM = new OpenDocumentMeta(); - $this->assertNotNull( $ODM ); + $this->assertNotNull( $ODM ); - $this->assertEquals( "", $ODM->getGenerator(), "Generator should be empty, was not." ); + $this->assertEquals( "", $ODM->getGenerator(), + "Generator should be empty, was not." ); - $ODM->addGenerator( "TEST" ); - $ODM->commit(); + $ODM->addGenerator( ); + $ODM->commit(); - $this->assertEquals( "TEST", $ODM->getGenerator(), "Generator was not correctly returned. (".$ODM->getGenerator().")" ); + $this->assertNotNull( $ODM->getGenerator(), + "Generator was not correctly returned, but was null" ); + + $this->assertNotEquals( "", $ODM->getGenerator(), + "Generator was not correctly returned. (".$ODM->getGenerator().")" ); - unset( $ODM ); - } + $Document = $ODM->get(); + $this->assertNotNull($Document, "No result." ); + + $RelaxNG = self::PathToRNG . self::MetaRNG; + + $this->assertTrue( $Document->relaxNGValidate( $RelaxNG ), + "Manifest does not match Manifest Relax NG schema." ); + } - public function testAddGetInitialCreator() { - $ODM = new OpenDocumentMeta(); + /** + * + * @since 0.4.2 + */ + public function testAddGetInitialCreator() { + $ODM = new OpenDocumentMeta(); - $this->assertNotNull( $ODM ); + $this->assertNotNull( $ODM ); - $this->assertEquals( "", $ODM->getInitialCreator(), "InitialCreator should be empty, was not." ); + $this->assertEquals( "", $ODM->getInitialCreator(), + "InitialCreator should be empty, was not." ); - $ODM->addInitialCreator( "InitCreator" ); - $ODM->commit(); + $ODM->addInitialCreator( "InitCreator" ); + $ODM->commit(); - $this->assertEquals( "InitCreator", $ODM->getInitialCreator(), "InitialCreator was not correctly returned." ); + $this->assertEquals( "InitCreator", $ODM->getInitialCreator(), + "InitialCreator was not correctly returned." ); - unset( $ODM ); - } - + $Document = $ODM->get(); + $this->assertNotNull($Document, "No result." ); - } \ No newline at end of file + $RelaxNG = self::PathToRNG . self::MetaRNG; + + $this->assertTrue( $Document->relaxNGValidate( $RelaxNG ), + "Manifest does not match Manifest Relax NG schema." ); + } +} +?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |