Browse Source

Added extended DOM methods to Entry level API with tests

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@16961 44c647ce-9c0f-0410-b52a-842ac1e357ba
padraic 16 years ago
parent
commit
b44c9fca97

+ 4 - 3
library/Zend/Feed/Reader/EntryAbstract.php

@@ -128,8 +128,9 @@ abstract class Zend_Feed_Reader_EntryAbstract
      */
     public function saveXml()
     {
-        $dom = new DOMDocument();
-        $dom->importNode($this->getElement(), true);
+        $dom = new DOMDocument('1.0', $this->getEncoding());
+        $entry = $dom->importNode($this->getElement(), true);
+        $dom->appendChild($entry);
         return $dom->saveXml();
     }
 
@@ -220,7 +221,7 @@ abstract class Zend_Feed_Reader_EntryAbstract
             }
             $className = Zend_Feed_Reader::getPluginLoader()->getClassName($extension);
             $this->_extensions[$className] = new $className(
-                $this->getEntryElement(), $this->_entryKey, $this->_data['type']
+                $this->getElement(), $this->_entryKey, $this->_data['type']
             );
         }
     }

+ 69 - 0
tests/Zend/Feed/Reader/Entry/CommonTest.php

@@ -0,0 +1,69 @@
+<?php
+
+require_once 'PHPUnit/Framework/TestCase.php';
+require_once 'Zend/Feed/Reader.php';
+
+class Zend_Feed_Reader_Entry_CommonTest extends PHPUnit_Framework_TestCase
+{
+
+    protected $_feedSamplePath = null;
+
+    public function setup()
+    {
+        if (Zend_Registry::isRegistered('Zend_Locale')) {
+            $registry = Zend_Registry::getInstance();
+            unset($registry['Zend_Locale']);
+        }
+        $this->_feedSamplePath = dirname(__FILE__) . '/_files/Common';
+    }
+
+    /**
+     * Check DOM Retrieval and Information Methods
+     */
+    public function testGetsDomDocumentObject()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/atom.xml')
+        );
+        $entry = $feed->current();
+        $this->assertTrue($entry->getDomDocument() instanceof DOMDocument);
+    }
+
+    public function testGetsDomXpathObject()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/atom.xml')
+        );
+        $entry = $feed->current();
+        $this->assertTrue($entry->getXpath() instanceof DOMXPath);
+    }
+
+    public function testGetsXpathPrefixString()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/atom.xml')
+        );
+        $entry = $feed->current();
+        $this->assertEquals('//atom:entry[1]', $entry->getXpathPrefix());
+    }
+
+    public function testGetsDomElementObject()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/atom.xml')
+        );
+        $entry = $feed->current();
+        $this->assertTrue($entry->getElement() instanceof DOMElement);
+    }
+
+    public function testSaveXmlOutputsXmlStringForEntry()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/atom.xml')
+        );
+        $entry = $feed->current();
+        $this->assertEquals($entry->saveXml(), file_get_contents($this->_feedSamplePath.'/atom_rewrittenbydom.xml'));
+    }
+
+
+}

+ 30 - 0
tests/Zend/Feed/Reader/Entry/_files/Common/atom_rewrittenbydom.xml

@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0">
+		<author>
+			<name>norm2782</name>
+						<uri>http://www.norm2782.com</uri>
+					</author>
+		<title type="html"><![CDATA[Wth&#8230; reading books?]]></title>
+		<link rel="alternate" type="text/html" href="http://www.norm2782.com/2009/03/wth-reading-books/"/>
+		<id>http://www.norm2782.com/?p=114</id>
+		<updated>2009-03-07T08:03:50Z</updated>
+		<published>2009-03-02T08:09:33Z</published>
+		<category scheme="http://www.norm2782.com" term="New Zealand"/><category scheme="http://www.norm2782.com" term="Personal"/><category scheme="http://www.norm2782.com" term="Programming"/><category scheme="http://www.norm2782.com" term="Study"/>		<summary type="html"><![CDATA[Being in New Zealand does strange things to a person. Everybody who knows me, knows I don&#8217;t much like that crazy invention called a Book. However, being here I&#8217;ve already finished 4 books, all of which I can highly recommend.
+
+Agile Software Development with Scrum, by Ken Schwaber and Mike Beedle
+Domain-Driven Design: Tackling Complexity in the [...]]]></summary>
+		<content type="html" xml:base="http://www.norm2782.com/2009/03/wth-reading-books/"><![CDATA[<p>Being in New Zealand does strange things to a person. Everybody who knows me, knows I don&#8217;t much like that crazy invention called a Book. However, being here I&#8217;ve already finished 4 books, all of which I can highly recommend.</p>
+
+<ul>
+<li><a href="http://www.amazon.com/Agile-Software-Development-Scrum/dp/0130676349/">Agile Software Development with Scrum, by Ken Schwaber and Mike Beedle</a></li>
+<li><a href="http://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215/">Domain-Driven Design: Tackling Complexity in the Heart of Software, by Eric Evans</a></li>
+<li><a href="http://www.amazon.com/Enterprise-Application-Architecture-Addison-Wesley-Signature/dp/0321127420/">Patterns of Enterprise Application Architecture, by Martin Fowler</a></li>
+<li><a href="http://www.amazon.com/Refactoring-Improving-Existing-Addison-Wesley-Technology/dp/0201485672/">Refactoring: Improving the Design of Existing Code by Martin Fowler</a></li>
+
+</ul>
+<p>Next up: <a href="http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612/">Design Patterns: Elements of Reusable Object-Oriented Software, by the Gang of Four</a>. Yes, talk about classics and shame on me for not having ordered it sooner! Also reading <a href="http://www.amazon.com/Implementation-Patterns-Addison-Wesley-Signature-Kent/dp/0321413091/">Implementation Patterns, by Kent Beck</a> at the moment.</p>
+]]></content>
+		<link rel="replies" type="text/html" href="http://www.norm2782.com/2009/03/wth-reading-books/#comments" thr:count="0"/>
+		<link rel="replies" type="application/atom+xml" href="http://www.norm2782.com/2009/03/wth-reading-books/feed/atom/" thr:count="0"/>
+		<thr:total>0</thr:total>
+	</entry>