CommonTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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-2015 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 'Zend/Feed/Reader.php';
  23. /**
  24. * @category Zend
  25. * @package Zend_Feed
  26. * @subpackage UnitTests
  27. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  28. * @license http://framework.zend.com/license/new-bsd New BSD License
  29. * @group Zend_Feed
  30. * @group Zend_Feed_Reader
  31. */
  32. class Zend_Feed_Reader_Entry_CommonTest extends PHPUnit_Framework_TestCase
  33. {
  34. protected $_feedSamplePath = null;
  35. public function setup()
  36. {
  37. Zend_Feed_Reader::reset();
  38. if (Zend_Registry::isRegistered('Zend_Locale')) {
  39. $registry = Zend_Registry::getInstance();
  40. unset($registry['Zend_Locale']);
  41. }
  42. $this->_feedSamplePath = dirname(__FILE__) . '/_files/Common';
  43. }
  44. /**
  45. * Check DOM Retrieval and Information Methods
  46. */
  47. public function testGetsDomDocumentObject()
  48. {
  49. $feed = Zend_Feed_Reader::importString(
  50. file_get_contents($this->_feedSamplePath.'/atom.xml')
  51. );
  52. $entry = $feed->current();
  53. $this->assertTrue($entry->getDomDocument() instanceof DOMDocument);
  54. }
  55. public function testGetsDomXpathObject()
  56. {
  57. $feed = Zend_Feed_Reader::importString(
  58. file_get_contents($this->_feedSamplePath.'/atom.xml')
  59. );
  60. $entry = $feed->current();
  61. $this->assertTrue($entry->getXpath() instanceof DOMXPath);
  62. }
  63. public function testGetsXpathPrefixString()
  64. {
  65. $feed = Zend_Feed_Reader::importString(
  66. file_get_contents($this->_feedSamplePath.'/atom.xml')
  67. );
  68. $entry = $feed->current();
  69. $this->assertEquals('//atom:entry[1]', $entry->getXpathPrefix());
  70. }
  71. public function testGetsDomElementObject()
  72. {
  73. $feed = Zend_Feed_Reader::importString(
  74. file_get_contents($this->_feedSamplePath.'/atom.xml')
  75. );
  76. $entry = $feed->current();
  77. $this->assertTrue($entry->getElement() instanceof DOMElement);
  78. }
  79. public function testSaveXmlOutputsXmlStringForEntry()
  80. {
  81. $feed = Zend_Feed_Reader::importString(
  82. file_get_contents($this->_feedSamplePath.'/atom.xml')
  83. );
  84. $entry = $feed->current();
  85. $this->assertEquals($entry->saveXml(), file_get_contents($this->_feedSamplePath.'/atom_rewrittenbydom.xml'));
  86. }
  87. public function testGetsNamedExtension()
  88. {
  89. $feed = Zend_Feed_Reader::importString(
  90. file_get_contents($this->_feedSamplePath.'/atom.xml')
  91. );
  92. $entry = $feed->current();
  93. $this->assertTrue($entry->getExtension('Atom') instanceof Zend_Feed_Reader_Extension_Atom_Entry);
  94. }
  95. public function testReturnsNullIfExtensionDoesNotExist()
  96. {
  97. $feed = Zend_Feed_Reader::importString(
  98. file_get_contents($this->_feedSamplePath.'/atom.xml')
  99. );
  100. $entry = $feed->current();
  101. $this->assertEquals(null, $entry->getExtension('Foo'));
  102. }
  103. /**
  104. * @group ZF-8213
  105. */
  106. public function testReturnsEncodingOfFeed()
  107. {
  108. $feed = Zend_Feed_Reader::importString(
  109. file_get_contents($this->_feedSamplePath.'/atom.xml')
  110. );
  111. $entry = $feed->current();
  112. $this->assertEquals('UTF-8', $entry->getEncoding());
  113. }
  114. /**
  115. * @group ZF-8213
  116. */
  117. public function testReturnsEncodingOfFeedAsUtf8IfUndefined()
  118. {
  119. $feed = Zend_Feed_Reader::importString(
  120. file_get_contents($this->_feedSamplePath.'/atom_noencodingdefined.xml')
  121. );
  122. $entry = $feed->current();
  123. $this->assertEquals('UTF-8', $entry->getEncoding());
  124. }
  125. }