CommonTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Feed
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. require_once 'PHPUnit/Framework/TestCase.php';
  23. require_once 'Zend/Feed/Reader.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Feed
  27. * @subpackage UnitTests
  28. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @group Zend_Feed
  31. * @group Zend_Feed_Reader
  32. */
  33. class Zend_Feed_Reader_Entry_CommonTest extends PHPUnit_Framework_TestCase
  34. {
  35. protected $_feedSamplePath = null;
  36. public function setup()
  37. {
  38. Zend_Feed_Reader::reset();
  39. if (Zend_Registry::isRegistered('Zend_Locale')) {
  40. $registry = Zend_Registry::getInstance();
  41. unset($registry['Zend_Locale']);
  42. }
  43. $this->_feedSamplePath = dirname(__FILE__) . '/_files/Common';
  44. }
  45. /**
  46. * Check DOM Retrieval and Information Methods
  47. */
  48. public function testGetsDomDocumentObject()
  49. {
  50. $feed = Zend_Feed_Reader::importString(
  51. file_get_contents($this->_feedSamplePath.'/atom.xml')
  52. );
  53. $entry = $feed->current();
  54. $this->assertTrue($entry->getDomDocument() instanceof DOMDocument);
  55. }
  56. public function testGetsDomXpathObject()
  57. {
  58. $feed = Zend_Feed_Reader::importString(
  59. file_get_contents($this->_feedSamplePath.'/atom.xml')
  60. );
  61. $entry = $feed->current();
  62. $this->assertTrue($entry->getXpath() instanceof DOMXPath);
  63. }
  64. public function testGetsXpathPrefixString()
  65. {
  66. $feed = Zend_Feed_Reader::importString(
  67. file_get_contents($this->_feedSamplePath.'/atom.xml')
  68. );
  69. $entry = $feed->current();
  70. $this->assertEquals('//atom:entry[1]', $entry->getXpathPrefix());
  71. }
  72. public function testGetsDomElementObject()
  73. {
  74. $feed = Zend_Feed_Reader::importString(
  75. file_get_contents($this->_feedSamplePath.'/atom.xml')
  76. );
  77. $entry = $feed->current();
  78. $this->assertTrue($entry->getElement() instanceof DOMElement);
  79. }
  80. public function testSaveXmlOutputsXmlStringForEntry()
  81. {
  82. $feed = Zend_Feed_Reader::importString(
  83. file_get_contents($this->_feedSamplePath.'/atom.xml')
  84. );
  85. $entry = $feed->current();
  86. $this->assertEquals($entry->saveXml(), file_get_contents($this->_feedSamplePath.'/atom_rewrittenbydom.xml'));
  87. }
  88. public function testGetsNamedExtension()
  89. {
  90. $feed = Zend_Feed_Reader::importString(
  91. file_get_contents($this->_feedSamplePath.'/atom.xml')
  92. );
  93. $entry = $feed->current();
  94. $this->assertTrue($entry->getExtension('Atom') instanceof Zend_Feed_Reader_Extension_Atom_Entry);
  95. }
  96. public function testReturnsNullIfExtensionDoesNotExist()
  97. {
  98. $feed = Zend_Feed_Reader::importString(
  99. file_get_contents($this->_feedSamplePath.'/atom.xml')
  100. );
  101. $entry = $feed->current();
  102. $this->assertEquals(null, $entry->getExtension('Foo'));
  103. }
  104. /**
  105. * @group ZF-8213
  106. */
  107. public function testReturnsEncodingOfFeed()
  108. {
  109. $feed = Zend_Feed_Reader::importString(
  110. file_get_contents($this->_feedSamplePath.'/atom.xml')
  111. );
  112. $entry = $feed->current();
  113. $this->assertEquals('UTF-8', $entry->getEncoding());
  114. }
  115. /**
  116. * @group ZF-8213
  117. */
  118. public function testReturnsEncodingOfFeedAsUtf8IfUndefined()
  119. {
  120. $feed = Zend_Feed_Reader::importString(
  121. file_get_contents($this->_feedSamplePath.'/atom_noencodingdefined.xml')
  122. );
  123. $entry = $feed->current();
  124. $this->assertEquals('UTF-8', $entry->getEncoding());
  125. }
  126. }