Ver Fonte

Zend_Feed_Writer: Updated unit tests to reflect changes to Author return type in Zend_Feed_Reader

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19786 44c647ce-9c0f-0410-b52a-842ac1e357ba
padraic há 16 anos atrás
pai
commit
59e9d31064

+ 23 - 4
library/Zend/Feed/Writer.php

@@ -259,7 +259,9 @@ class Zend_Feed_Writer
     }
     
     /**
-     * Replaces XML special characters with entities.
+     * Replaces XML special characters with entities. This is a generally
+     * safe XML encoding targeting the <, > and & characters. Quotes are
+     * left unencoded. It is not suitable for RSS 2.0 character data.
      *
      * @param string $string
      * @param string $encoding
@@ -267,9 +269,26 @@ class Zend_Feed_Writer
      */
     public static function xmlentities($string, $encoding)
     {
-        return str_replace('&#039;', '&apos;', htmlspecialchars(
-            $string, ENT_QUOTES, $encoding
-        ));
+        return htmlspecialchars($string, ENT_NOQUOTES, $encoding);
+    }
+    
+    /**
+     * Replaces the characters <, > and & with hexadecimal entities as
+     * recommended for textual character data not representing HTML in RSS 2.0.
+     * Per the published RSS Best Practices Profile this attempts to maximise
+     * compatibility with various feed parsers/readers.
+     *
+     * @param string $string
+     * @param string $encoding
+     * @return string
+     */
+    public static function textentities($string, $encoding)
+    {
+        return str_replace(
+            array('&amp;', '&lt;', '&gt;'),
+            array('&#x26;', '&#x3C;', '&#x3E;'),
+            htmlspecialchars($string, ENT_NOQUOTES, $encoding)
+        );
     }
 
 }

+ 4 - 1
tests/Zend/Feed/Writer/Renderer/Entry/AtomTest.php

@@ -182,7 +182,10 @@ class Zend_Feed_Writer_Renderer_Entry_AtomTest extends PHPUnit_Framework_TestCas
         $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
         $entry = $feed->current();
         $author = $entry->getAuthor();
-        $this->assertEquals('jane@example.com (Jane)', $entry->getAuthor());
+        $this->assertEquals(array(
+            'name'=>'Jane',
+            'email'=>'jane@example.com',
+            'uri'=>'http://www.example.com/jane'), $entry->getAuthor());
     }
     
     public function testEntryHoldsAnyEnclosureAdded()

+ 1 - 1
tests/Zend/Feed/Writer/Renderer/Entry/RssTest.php

@@ -170,7 +170,7 @@ class Zend_Feed_Writer_Renderer_Entry_RssTest extends PHPUnit_Framework_TestCase
         $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
         $entry = $feed->current();
         $author = $entry->getAuthor();
-        $this->assertEquals('Jane', $entry->getAuthor());
+        $this->assertEquals(array('name'=>'Jane'), $entry->getAuthor());
     }
     
     public function testEntryHoldsAnyEnclosureAdded()

+ 4 - 1
tests/Zend/Feed/Writer/Renderer/Feed/AtomTest.php

@@ -241,7 +241,10 @@ class Zend_Feed_Writer_Renderer_Feed_AtomTest extends PHPUnit_Framework_TestCase
         $atomFeed->render();
         $feed = Zend_Feed_Reader::importString($atomFeed->saveXml());
         $author = $feed->getAuthor();
-        $this->assertEquals('joe@example.com (Joe)', $feed->getAuthor());
+        $this->assertEquals(array(
+            'email'=>'joe@example.com',
+            'name'=>'Joe',
+            'uri'=>'http://www.example.com/joe'), $feed->getAuthor());
     }
     
     public function testFeedAuthorIfNotSetThrowsExceptionIfAnyEntriesAlsoAreMissingAuthors()

+ 2 - 2
tests/Zend/Feed/Writer/Renderer/Feed/RssTest.php

@@ -13,7 +13,7 @@
  * to license@zend.com so we can send you a copy immediately.
  *
  * @category   Zend
- * @package    Zend_Json
+ * @package    Zend_Feed
  * @subpackage UnitTests
  * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
@@ -242,7 +242,7 @@ class Zend_Feed_Writer_Renderer_Feed_RssTest extends PHPUnit_Framework_TestCase
         $atomFeed->render();
         $feed = Zend_Feed_Reader::importString($atomFeed->saveXml());
         $author = $feed->getAuthor();
-        $this->assertEquals('Joe', $feed->getAuthor());
+        $this->assertEquals(array('name'=>'Joe'), $feed->getAuthor());
     }
     
     public function testCopyrightCanBeSet()