CommonTest.php 4.0 KB

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