cacert-testmgr/external/ZendFramework-1.9.5/tests/Zend/Feed/Reader/Entry/AtomTest.php

362 lines
12 KiB
PHP
Raw Permalink Normal View History

<?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 18655 2009-10-20 14:17:39Z 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_AtomTest 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/Atom';
}
/**
* Get Id (Unencoded Text)
*/
public function testGetsIdFromAtom03()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/id/plain/atom03.xml')
);
$entry = $feed->current();
$this->assertEquals('1', $entry->getId());
}
public function testGetsIdFromAtom10()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/id/plain/atom10.xml')
);
$entry = $feed->current();
$this->assertEquals('1', $entry->getId());
}
/**
* Get creation date (Unencoded Text)
*/
public function testGetsDateCreatedFromAtom03()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/datecreated/plain/atom03.xml')
);
$entry = $feed->current();
$this->assertEquals('Saturday 07 March 2009 08 03 50 +0000',
$entry->getDateCreated()->toString('EEEE dd MMMM YYYY HH mm ss ZZZ'));
}
public function testGetsDateCreatedFromAtom10()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/datecreated/plain/atom10.xml')
);
$entry = $feed->current();
$this->assertEquals('Saturday 07 March 2009 08 03 50 +0000',
$entry->getDateCreated()->toString('EEEE dd MMMM YYYY HH mm ss ZZZ'));
}
/**
* Get modification date (Unencoded Text)
*/
public function testGetsDateModifiedFromAtom03()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/datemodified/plain/atom03.xml')
);
$entry = $feed->current();
$this->assertEquals('Saturday 07 March 2009 08 03 50 +0000',
$entry->getDateModified()->toString('EEEE dd MMMM YYYY HH mm ss ZZZ'));
}
public function testGetsDateModifiedFromAtom10()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/datemodified/plain/atom10.xml')
);
$entry = $feed->current();
$this->assertEquals('Saturday 07 March 2009 08 03 50 +0000',
$entry->getDateModified()->toString('EEEE dd MMMM YYYY HH mm ss ZZZ'));
}
/**
* Get Title (Unencoded Text)
*/
public function testGetsTitleFromAtom03()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/title/plain/atom03.xml')
);
$entry = $feed->current();
$this->assertEquals('Entry Title', $entry->getTitle());
}
public function testGetsTitleFromAtom10()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/title/plain/atom10.xml')
);
$entry = $feed->current();
$this->assertEquals('Entry Title', $entry->getTitle());
}
/**
* Get Authors (Unencoded Text)
*/
public function testGetsAuthorsFromAtom03()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/author/plain/atom03.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)'
);
$entry = $feed->current();
$this->assertEquals($authors, $entry->getAuthors());
}
public function testGetsAuthorsFromAtom10()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/author/plain/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)'
);
$entry = $feed->current();
$this->assertEquals($authors, $entry->getAuthors());
}
/**
* Get Author (Unencoded Text)
*/
public function testGetsAuthorFromAtom03()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/author/plain/atom03.xml')
);
$entry = $feed->current();
$this->assertEquals('joe@example.com (Joe Bloggs)', $entry->getAuthor());
}
public function testGetsAuthorFromAtom10()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/author/plain/atom10.xml')
);
$entry = $feed->current();
$this->assertEquals('joe@example.com (Joe Bloggs)', $entry->getAuthor());
}
/**
* Get Description (Unencoded Text)
*/
public function testGetsDescriptionFromAtom03()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/description/plain/atom03.xml')
);
$entry = $feed->current();
$this->assertEquals('Entry Description', $entry->getDescription());
}
public function testGetsDescriptionFromAtom10()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/description/plain/atom10.xml')
);
$entry = $feed->current();
$this->assertEquals('Entry Description', $entry->getDescription());
}
/**
* Get enclosure
*/
public function testGetsEnclosureFromAtom03()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath.'/enclosure/plain/atom03.xml')
);
$entry = $feed->current();
$expected = new stdClass();
$expected->url = 'http://www.example.org/myaudiofile.mp3';
$expected->length = '1234';
$expected->type = 'audio/mpeg';
$this->assertEquals($expected, $entry->getEnclosure());
}
public function testGetsEnclosureFromAtom10()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath.'/enclosure/plain/atom10.xml')
);
$entry = $feed->current();
$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)
*/
public function testGetsContentFromAtom03()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/content/plain/atom03.xml')
);
$entry = $feed->current();
$this->assertEquals('Entry Content', $entry->getContent());
}
public function testGetsContentFromAtom10()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/content/plain/atom10.xml')
);
$entry = $feed->current();
$this->assertEquals('Entry Content', $entry->getContent());
}
/**
* Get Link (Unencoded Text)
*/
public function testGetsLinkFromAtom03()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/link/plain/atom03.xml')
);
$entry = $feed->current();
$this->assertEquals('http://www.example.com/entry', $entry->getLink());
}
public function testGetsLinkFromAtom10()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/link/plain/atom10.xml')
);
$entry = $feed->current();
$this->assertEquals('http://www.example.com/entry', $entry->getLink());
}
public function testGetsLinkFromAtom10_WithNoRelAttribute()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/link/plain/atom10-norel.xml')
);
$entry = $feed->current();
$this->assertEquals('http://www.example.com/entry', $entry->getLink());
}
public function testGetsLinkFromAtom10_WithRelativeUrl()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/link/plain/atom10-relative.xml')
);
$entry = $feed->current();
$this->assertEquals('http://www.example.com/entry', $entry->getLink());
}
/**
* Get Base Uri
*/
public function testGetsBaseUriFromAtom10_FromFeedElement()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/baseurl/plain/atom10-feedlevel.xml')
);
$entry = $feed->current();
$this->assertEquals('http://www.example.com', $entry->getBaseUrl());
}
public function testGetsBaseUriFromAtom10_FromEntryElement()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/baseurl/plain/atom10-entrylevel.xml')
);
$entry = $feed->current();
$this->assertEquals('http://www.example.com/', $entry->getBaseUrl());
}
/**
* Get Comment HTML Link
*/
public function testGetsCommentLinkFromAtom03()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/commentlink/plain/atom03.xml')
);
$entry = $feed->current();
$this->assertEquals('http://www.example.com/entry/comments', $entry->getCommentLink());
}
public function testGetsCommentLinkFromAtom10()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/commentlink/plain/atom10.xml')
);
$entry = $feed->current();
$this->assertEquals('http://www.example.com/entry/comments', $entry->getCommentLink());
}
public function testGetsCommentLinkFromAtom10_RelativeLinks()
{
$feed = Zend_Feed_Reader::importString(
file_get_contents($this->_feedSamplePath . '/commentlink/plain/atom10-relative.xml')
);
$entry = $feed->current();
$this->assertEquals('http://www.example.com/entry/comments', $entry->getCommentLink());
}
}