Browse Source

Zend_Feed_Reader: Added RSS/RDF tests for feed level getCategories() method

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19166 44c647ce-9c0f-0410-b52a-842ac1e357ba
padraic 16 năm trước cách đây
mục cha
commit
687807b88c
1 tập tin đã thay đổi với 300 bổ sung1 xóa
  1. 300 1
      tests/Zend/Feed/Reader/Feed/RssTest.php

+ 300 - 1
tests/Zend/Feed/Reader/Feed/RssTest.php

@@ -37,6 +37,12 @@ class Zend_Feed_Reader_Feed_RssTest extends PHPUnit_Framework_TestCase
 {
 
     protected $_feedSamplePath = null;
+    
+    protected $_expectedCats = array();
+    
+    protected $_expectedCatsRdf = array();
+    
+    protected $_expectedCatsAtom = array();
 
     public function setup()
     {
@@ -52,6 +58,52 @@ class Zend_Feed_Reader_Feed_RssTest 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' => 'topic2',
+                'scheme' => 'http://example.com/schema1',
+                'label' => 'topic2'
+            )
+        );
+        $this->_expectedCatsRdf = array(
+            array(
+                'term' => 'topic1',
+                'scheme' => null,
+                'label' => 'topic1'
+            ),
+            array(
+                'term' => 'topic2',
+                'scheme' => null,
+                'label' => 'topic2'
+            )
+        );
+        $this->_expectedCatsAtom = 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'
+            )
+        );
     }
     
     public function teardown()
@@ -2370,6 +2422,253 @@ class Zend_Feed_Reader_Feed_RssTest extends PHPUnit_Framework_TestCase
         );
         $this->assertEquals(null, $feed->getHubs());
     }
-
+    
+    /**
+     * Get category data
+     */
+    
+    // RSS 2.0
+    
+    public function testGetsCategoriesFromRss20()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/rss20.xml')
+        );
+        $this->assertEquals($this->_expectedCats, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','topic2'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    // DC 1.0
+    
+    public function testGetsCategoriesFromRss090_Dc10()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/dc10/rss090.xml')
+        );
+        $this->assertEquals($this->_expectedCatsRdf, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','topic2'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromRss091_Dc10()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/dc10/rss091.xml')
+        );
+        $this->assertEquals($this->_expectedCatsRdf, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','topic2'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromRss092_Dc10()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/dc10/rss092.xml')
+        );
+        $this->assertEquals($this->_expectedCatsRdf, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','topic2'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromRss093_Dc10()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/dc10/rss093.xml')
+        );
+        $this->assertEquals($this->_expectedCatsRdf, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','topic2'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromRss094_Dc10()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/dc10/rss094.xml')
+        );
+        $this->assertEquals($this->_expectedCatsRdf, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','topic2'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromRss10_Dc10()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/dc10/rss10.xml')
+        );
+        $this->assertEquals($this->_expectedCatsRdf, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','topic2'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    // DC 1.1
+    
+    public function testGetsCategoriesFromRss090_Dc11()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/dc11/rss090.xml')
+        );
+        $this->assertEquals($this->_expectedCatsRdf, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','topic2'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromRss091_Dc11()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/dc11/rss091.xml')
+        );
+        $this->assertEquals($this->_expectedCatsRdf, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','topic2'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromRss092_Dc11()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/dc11/rss092.xml')
+        );
+        $this->assertEquals($this->_expectedCatsRdf, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','topic2'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromRss093_Dc11()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/dc11/rss093.xml')
+        );
+        $this->assertEquals($this->_expectedCatsRdf, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','topic2'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromRss094_Dc11()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/dc11/rss094.xml')
+        );
+        $this->assertEquals($this->_expectedCatsRdf, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','topic2'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromRss10_Dc11()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/dc11/rss10.xml')
+        );
+        $this->assertEquals($this->_expectedCatsRdf, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','topic2'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    // Atom 1.0
+    
+    public function testGetsCategoriesFromRss090_Atom10()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/atom10/rss090.xml')
+        );
+        $this->assertEquals($this->_expectedCatsAtom, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','Cat & Dog'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromRss091_Atom10()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/atom10/rss091.xml')
+        );
+        $this->assertEquals($this->_expectedCatsAtom, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','Cat & Dog'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromRss092_Atom10()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/atom10/rss092.xml')
+        );
+        $this->assertEquals($this->_expectedCatsAtom, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','Cat & Dog'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromRss093_Atom10()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/atom10/rss093.xml')
+        );
+        $this->assertEquals($this->_expectedCatsAtom, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','Cat & Dog'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromRss094_Atom10()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/atom10/rss094.xml')
+        );
+        $this->assertEquals($this->_expectedCatsAtom, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','Cat & Dog'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromRss10_Atom10()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/atom10/rss10.xml')
+        );
+        $this->assertEquals($this->_expectedCatsAtom, (array) $feed->getCategories());
+        $this->assertEquals(array('topic1','Cat & Dog'), array_values($feed->getCategories()->getValues()));
+    }
+    
+    // No Categories In Entry
+    
+    public function testGetsCategoriesFromRss20_None()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/none/rss20.xml')
+        );
+        $this->assertEquals(array(), (array) $feed->getCategories());
+        $this->assertEquals(array(), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromRss090_None()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/none/rss090.xml')
+        );
+        $this->assertEquals(array(), (array) $feed->getCategories());
+        $this->assertEquals(array(), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromRss091_None()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/none/rss091.xml')
+        );
+        $this->assertEquals(array(), (array) $feed->getCategories());
+        $this->assertEquals(array(), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromRss092_None()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/none/rss092.xml')
+        );
+        $this->assertEquals(array(), (array) $feed->getCategories());
+        $this->assertEquals(array(), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromRss093_None()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/none/rss093.xml')
+        );
+        $this->assertEquals(array(), (array) $feed->getCategories());
+        $this->assertEquals(array(), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromRss094_None()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/none/rss094.xml')
+        );
+        $this->assertEquals(array(), (array) $feed->getCategories());
+        $this->assertEquals(array(), array_values($feed->getCategories()->getValues()));
+    }
+    
+    public function testGetsCategoriesFromRss10_None()
+    {
+        $feed = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/plain/none/rss10.xml')
+        );
+        $this->assertEquals(array(), (array) $feed->getCategories());
+        $this->assertEquals(array(), array_values($feed->getCategories()->getValues()));
+    }
 
 }