Просмотр исходного кода

Zend_Feed_Reader: Added feed level getCategory() tests for Atom 0.3/1.0 support

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19168 44c647ce-9c0f-0410-b52a-842ac1e357ba
padraic 16 лет назад
Родитель
Сommit
9880dd3459

+ 97 - 0
tests/Zend/Feed/Reader/Feed/AtomTest.php

@@ -38,6 +38,10 @@ class Zend_Feed_Reader_Feed_AtomTest extends PHPUnit_Framework_TestCase
     protected $_feedSamplePath = null;
     
     protected $_options = array();
+    
+    protected $_expectedCats = array();
+    
+    protected $_expectedCatsDc = array();
 
     public function setup()
     {
@@ -53,6 +57,35 @@ class Zend_Feed_Reader_Feed_AtomTest extends PHPUnit_Framework_TestCase
             }
         }
         Zend_Date::setOptions(array('format_type'=>'iso'));
+        $this->_expectedCats = array(
+            array(
+                'term' => 'topic1',
+                'scheme' => 'http://example.com/schema1',
+                'label' => 'topic1'
+            ),
+            array(
+                'term' => 'topic1',
+                'scheme' => 'http://example.com/schema2',
+                'label' => 'topic1'
+            ),
+            array(
+                'term' => 'cat_dog',
+                'scheme' => 'http://example.com/schema1',
+                'label' => 'Cat & Dog'
+            )
+        );
+        $this->_expectedCatsDc = array(
+            array(
+                'term' => 'topic1',
+                'scheme' => null,
+                'label' => 'topic1'
+            ),
+            array(
+                'term' => 'topic2',
+                'scheme' => null,
+                'label' => 'topic2'
+            )
+        );
     }
     
     public function teardown()
@@ -391,4 +424,68 @@ class Zend_Feed_Reader_Feed_AtomTest extends PHPUnit_Framework_TestCase
         );
         $this->assertEquals(0, count($feed));
     }
+    
+    /**
+     * Get category data
+     */
+    
+    // Atom 1.0 (Atom 0.3 never supported categories except via Atom 1.0/Dublin Core extensions)
+    
+    public function testGetsCategoriesFromAtom10()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/atom10.xml')
+        );
+        $this->assertEquals($this->_expectedCats, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','Cat & Dog'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromAtom03_Atom10Extension()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/atom03.xml')
+        );
+        $this->assertEquals($this->_expectedCats, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','Cat & Dog'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    // DC 1.0/1.1 for Atom 0.3
+    
+    public function testGetsCategoriesFromAtom03_Dc10()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/dc10/atom03.xml')
+        );
+        $this->assertEquals($this->_expectedCatsDc, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','topic2'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromAtom03_Dc11()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/dc11/atom03.xml')
+        );
+        $this->assertEquals($this->_expectedCatsDc, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','topic2'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    // No Categories In Entry
+    
+    public function testGetsCategoriesFromAtom10_None()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/none/atom10.xml')
+        );
+        $this->assertEquals(array(), (array) $feed->getCategories());
+        $this->assertEquals(array(), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromAtom03_None()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/none/atom03.xml')
+        );
+        $this->assertEquals(array(), (array) $feed->getCategories());
+        $this->assertEquals(array(), array_values($feed->getCategories()->getValues()));
+    }
 }

+ 3 - 3
tests/Zend/Feed/Reader/Feed/_files/Atom/category/plain/atom10.xml

@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <feed xmlns="http://www.w3.org/2005/Atom">
-    <atom10:category scheme="http://example.com/schema1" term="topic1" label="topic1"/>
-    <atom10:category scheme="http://example.com/schema2" term="topic1" label="topic1"/>
-    <atom10:category scheme="http://example.com/schema1" term="cat_dog" label="Cat &amp; Dog"/>
+    <category scheme="http://example.com/schema1" term="topic1" label="topic1"/>
+    <category scheme="http://example.com/schema2" term="topic1" label="topic1"/>
+    <category scheme="http://example.com/schema1" term="cat_dog" label="Cat &amp; Dog"/>
     <entry>
     </entry>
 </feed>