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

Zend_Feed_Reader: Addition of missing Atom Standalone Entry tests - well, doh!

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

+ 267 - 0
tests/Zend/Feed/Reader/Entry/AtomStandaloneEntryTest.php

@@ -0,0 +1,267 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @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
+ * @version    $Id: AtomTest.php 19159 2009-11-21 14:23:15Z padraic $
+ */
+
+require_once 'PHPUnit/Framework/TestCase.php';
+require_once 'Zend/Feed/Reader.php';
+
+/**
+ * @category   Zend
+ * @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
+ * @group      Zend_Feed
+ * @group      Zend_Feed_Reader
+ */
+class Zend_Feed_Reader_Entry_AtomStandaloneEntryTest extends PHPUnit_Framework_TestCase
+{
+
+    protected $_feedSamplePath = null;
+    
+    protected $_expectedCats = array();
+    
+    protected $_expectedCatsDc = array();
+
+    public function setup()
+    {
+        Zend_Feed_Reader::reset();
+        if (Zend_Registry::isRegistered('Zend_Locale')) {
+            $registry = Zend_Registry::getInstance();
+            unset($registry['Zend_Locale']);
+        }
+        $this->_feedSamplePath = dirname(__FILE__) . '/_files/AtomStandaloneEntry';
+        $this->_options = Zend_Date::setOptions();
+        foreach($this->_options as $k=>$v) {
+            if (is_null($v)) {
+                unset($this->_options[$k]);
+            }
+        }
+        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()
+    {
+        Zend_Date::setOptions($this->_options);
+    }
+    
+    public function testReaderImportOfAtomEntryDocumentReturnsEntryClass()
+    {
+        $object = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath . '/id/atom10.xml')
+        );
+        $this->assertTrue($object instanceof Zend_Feed_Reader_Entry_Atom);
+    }
+
+    /**
+     * Get Id (Unencoded Text)
+     * @group ZFR002
+     */
+    public function testGetsIdFromAtom10()
+    {
+        $entry = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath . '/id/atom10.xml')
+        );
+        $this->assertEquals('1', $entry->getId());
+    }
+
+    /**
+     * Get creation date (Unencoded Text)
+     * @group ZFR002
+     */
+    public function testGetsDateCreatedFromAtom10()
+    {
+        $entry = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath . '/datecreated/atom10.xml')
+        );
+        $edate = new Zend_Date;
+        $edate->set('2009-03-07T08:03:50Z', Zend_Date::ISO_8601);
+        $this->assertTrue($edate->equals($entry->getDateCreated()));
+    }
+
+    /**
+     * Get modification date (Unencoded Text)
+     * @group ZFR002
+     */
+    public function testGetsDateModifiedFromAtom10()
+    {
+        $entry = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath . '/datemodified/atom10.xml')
+        );
+        $edate = new Zend_Date;
+        $edate->set('2009-03-07T08:03:50Z', Zend_Date::ISO_8601);
+        $this->assertTrue($edate->equals($entry->getDateModified()));
+    }
+
+    /**
+     * Get Title (Unencoded Text)
+     * @group ZFR002
+     */
+    public function testGetsTitleFromAtom10()
+    {
+        $entry = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath . '/title/atom10.xml')
+        );
+        $this->assertEquals('Entry Title', $entry->getTitle());
+    }
+
+    /**
+     * Get Authors (Unencoded Text)
+     * @group ZFR002
+     */
+    public function testGetsAuthorsFromAtom10()
+    {
+        $entry = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath . '/author/atom10.xml')
+        );
+
+        $authors = array(
+            0 => 'joe@example.com (Joe Bloggs)',
+            1 => 'Joe Bloggs',
+            3 => 'joe@example.com',
+            4 => 'http://www.example.com',
+            6 => 'jane@example.com (Jane Bloggs)'
+        );
+
+        $this->assertEquals($authors, $entry->getAuthors());
+    }
+
+    /**
+     * Get Author (Unencoded Text)
+     * @group ZFR002
+     */
+    public function testGetsAuthorFromAtom10()
+    {
+        $entry = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath . '/author/atom10.xml')
+        );
+        $this->assertEquals('joe@example.com (Joe Bloggs)', $entry->getAuthor());
+    }
+
+    /**
+     * Get Description (Unencoded Text)
+     * @group ZFR002
+     */
+    public function testGetsDescriptionFromAtom10()
+    {
+        $entry = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath . '/description/atom10.xml')
+        );
+        $this->assertEquals('Entry Description', $entry->getDescription());
+    }
+
+    /**
+     * Get enclosure
+     * @group ZFR002
+     */
+    public function testGetsEnclosureFromAtom10()
+    {
+        $entry = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/enclosure/atom10.xml')
+        );
+
+        $expected = new stdClass();
+        $expected->url    = 'http://www.example.org/myaudiofile.mp3';
+        $expected->length = '1234';
+        $expected->type   = 'audio/mpeg';
+
+        $this->assertEquals($expected, $entry->getEnclosure());
+    }
+
+    /**
+     * Get Content (Unencoded Text)
+     * @group ZFR002
+     */
+    public function testGetsContentFromAtom10()
+    {
+        $entry = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath . '/content/atom10.xml')
+        );
+        $this->assertEquals('Entry Content', $entry->getContent());
+    }
+
+    /**
+     * Get Link (Unencoded Text)
+     * @group ZFR002
+     */
+    public function testGetsLinkFromAtom10()
+    {
+        $entry = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath . '/link/atom10.xml')
+        );
+        $this->assertEquals('http://www.example.com/entry', $entry->getLink());
+    }
+
+    /**
+     * Get Comment HTML Link
+     * @group ZFR002
+     */
+    public function testGetsCommentLinkFromAtom10()
+    {
+        $entry = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath . '/commentlink/atom10.xml')
+        );
+        $this->assertEquals('http://www.example.com/entry/comments', $entry->getCommentLink());
+    }
+    
+    /**
+     * Get category data
+     * @group ZFR002
+     */
+    public function testGetsCategoriesFromAtom10()
+    {
+        $entry = Zend_Feed_Reader::importString(
+            file_get_contents($this->_feedSamplePath.'/category/atom10.xml')
+        );
+        $this->assertEquals($this->_expectedCats, (array) $entry->getCategories());
+        $this->assertEquals(array('topic1','Cat & Dog'), array_values($entry->getCategories()->getValues()));
+    }
+    
+}

+ 43 - 0
tests/Zend/Feed/Reader/Entry/_files/AtomStandaloneEntry/author/atom10.xml

@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<entry xmlns="http://www.w3.org/2005/Atom">
+        <author>
+	        <name>Joe Bloggs</name>
+	        <uri>http://www.example.com</uri>
+	        <email>joe@example.com</email>
+	    </author>
+        <author>
+            <name>Joe Bloggs</name>
+            <uri>http://www.example.com</uri>
+            <email></email>
+        </author>
+        <author>
+            <name>Joe Bloggs</name>
+            <uri></uri>
+            <email></email>
+        </author>
+        <author>
+            <name></name>
+            <uri>http://www.example.com</uri>
+            <email>joe@example.com</email>
+        </author>
+        <author>
+            <name></name>
+            <uri>http://www.example.com</uri>
+            <email></email>
+        </author>
+        <author>
+            <name></name>
+            <uri></uri>
+            <email>joe@example.com</email>
+        </author>
+        <author>
+            <name></name>
+            <uri></uri>
+            <email></email>
+        </author>
+	    <contributor>
+	        <name>Jane Bloggs</name>
+	        <uri>http://www.example.com</uri>
+	        <email>jane@example.com</email>
+	    </contributor>
+</entry>

+ 6 - 0
tests/Zend/Feed/Reader/Entry/_files/AtomStandaloneEntry/category/atom10.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+    <entry xmlns="http://www.w3.org/2005/Atom">
+        <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>

+ 4 - 0
tests/Zend/Feed/Reader/Entry/_files/AtomStandaloneEntry/commentlink/atom10.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+    <entry xmlns="http://www.w3.org/2005/Atom">
+        <link href="http://www.example.com/entry/comments" rel="replies" type="text/html"/>
+    </entry>

+ 4 - 0
tests/Zend/Feed/Reader/Entry/_files/AtomStandaloneEntry/content/atom10.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+    <entry xmlns="http://www.w3.org/2005/Atom">
+		<content type="xhtml" xml:lang="en" xml:base="http://diveintomark.org/">Entry Content</content>
+    </entry>

+ 4 - 0
tests/Zend/Feed/Reader/Entry/_files/AtomStandaloneEntry/datecreated/atom10.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+    <entry xmlns="http://www.w3.org/2005/Atom">
+		<published>2009-03-07T08:03:50Z</published>
+    </entry>

+ 4 - 0
tests/Zend/Feed/Reader/Entry/_files/AtomStandaloneEntry/datemodified/atom10.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+    <entry xmlns="http://www.w3.org/2005/Atom">
+		<updated>2009-03-07T08:03:50Z</updated>
+    </entry>

+ 4 - 0
tests/Zend/Feed/Reader/Entry/_files/AtomStandaloneEntry/description/atom10.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+    <entry xmlns="http://www.w3.org/2005/Atom">
+        <summary>Entry Description</summary>
+    </entry>

+ 4 - 0
tests/Zend/Feed/Reader/Entry/_files/AtomStandaloneEntry/enclosure/atom10.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+    <entry xmlns="http://www.w3.org/2005/Atom">
+        <link rel="enclosure" type="audio/mpeg" title="MP3" href="http://www.example.org/myaudiofile.mp3" length="1234" />
+    </entry>

+ 4 - 0
tests/Zend/Feed/Reader/Entry/_files/AtomStandaloneEntry/id/atom10.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<entry xmlns="http://www.w3.org/2005/Atom">
+    <id>1</id>
+</entry>

+ 4 - 0
tests/Zend/Feed/Reader/Entry/_files/AtomStandaloneEntry/link/atom10.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+    <entry xmlns="http://www.w3.org/2005/Atom">
+        <link href="http://www.example.com/entry" rel="alternate"/>
+    </entry>

+ 5 - 0
tests/Zend/Feed/Reader/Entry/_files/AtomStandaloneEntry/links/atom10.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+    <entry xmlns="http://www.w3.org/2005/Atom">
+        <link rel="alternate" type="text/html" href="http://www.example.com/entry"/>
+        <link rel="alternate" type="text/html" href="http://www.example.com/entry2"/>
+    </entry>

+ 4 - 0
tests/Zend/Feed/Reader/Entry/_files/AtomStandaloneEntry/title/atom10.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+    <entry xmlns="http://www.w3.org/2005/Atom">
+        <title>Entry Title</title>
+    </entry>