LautDeRdfTest.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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_Integration_LautDeRdfTest extends PHPUnit_Framework_TestCase
  34. {
  35. protected $_feedSamplePath = null;
  36. public function setup()
  37. {
  38. Zend_Feed_Reader::reset();
  39. $this->_feedSamplePath = dirname(__FILE__) . '/_files/laut.de-rdf.xml';
  40. $this->_options = Zend_Date::setOptions();
  41. foreach($this->_options as $k=>$v) {
  42. if (is_null($v)) {
  43. unset($this->_options[$k]);
  44. }
  45. }
  46. Zend_Date::setOptions(array('format_type'=>'iso'));
  47. }
  48. public function teardown()
  49. {
  50. Zend_Date::setOptions($this->_options);
  51. }
  52. /**
  53. * Feed level testing
  54. */
  55. public function testGetsTitle()
  56. {
  57. $feed = Zend_Feed_Reader::importString(
  58. file_get_contents($this->_feedSamplePath)
  59. );
  60. $this->assertEquals('laut.de - news', $feed->getTitle());
  61. }
  62. public function testGetsAuthors()
  63. {
  64. $feed = Zend_Feed_Reader::importString(
  65. file_get_contents($this->_feedSamplePath)
  66. );
  67. $this->assertEquals(array(array('name'=>'laut.de')), (array) $feed->getAuthors());
  68. }
  69. public function testGetsSingleAuthor()
  70. {
  71. $feed = Zend_Feed_Reader::importString(
  72. file_get_contents($this->_feedSamplePath)
  73. );
  74. $this->assertEquals(array('name'=>'laut.de'), $feed->getAuthor());
  75. }
  76. public function testGetsCopyright()
  77. {
  78. $feed = Zend_Feed_Reader::importString(
  79. file_get_contents($this->_feedSamplePath)
  80. );
  81. $this->assertEquals('Copyright © 2004 laut.de', $feed->getCopyright());
  82. }
  83. public function testGetsDescription()
  84. {
  85. $feed = Zend_Feed_Reader::importString(
  86. file_get_contents($this->_feedSamplePath)
  87. );
  88. $this->assertEquals('laut.de: aktuelle News', $feed->getDescription());
  89. }
  90. public function testGetsLanguage()
  91. {
  92. $feed = Zend_Feed_Reader::importString(
  93. file_get_contents($this->_feedSamplePath)
  94. );
  95. $this->assertEquals(null, $feed->getLanguage());
  96. }
  97. public function testGetsLink()
  98. {
  99. $feed = Zend_Feed_Reader::importString(
  100. file_get_contents($this->_feedSamplePath)
  101. );
  102. $this->assertEquals('http://www.laut.de', $feed->getLink());
  103. }
  104. public function testGetsEncoding()
  105. {
  106. $feed = Zend_Feed_Reader::importString(
  107. file_get_contents($this->_feedSamplePath)
  108. );
  109. $this->assertEquals('ISO-8859-1', $feed->getEncoding());
  110. }
  111. /**
  112. * Entry level testing
  113. */
  114. public function testGetsEntryId()
  115. {
  116. $feed = Zend_Feed_Reader::importString(
  117. file_get_contents($this->_feedSamplePath)
  118. );
  119. $entry = $feed->current();
  120. $this->assertEquals('http://www.laut.de/vorlaut/news/2009/07/04/22426/index.htm', $entry->getId());
  121. }
  122. public function testGetsEntryTitle()
  123. {
  124. $feed = Zend_Feed_Reader::importString(
  125. file_get_contents($this->_feedSamplePath)
  126. );
  127. $entry = $feed->current();
  128. $this->assertEquals('Angelika Express: MySpace-Aus wegen Sido-Werbung', $entry->getTitle());
  129. }
  130. public function testGetsEntryAuthors()
  131. {
  132. $feed = Zend_Feed_Reader::importString(
  133. file_get_contents($this->_feedSamplePath)
  134. );
  135. $entry = $feed->current();
  136. $this->assertEquals(array(array('name'=>'laut.de')), (array) $entry->getAuthors());
  137. }
  138. public function testGetsEntrySingleAuthor()
  139. {
  140. $feed = Zend_Feed_Reader::importString(
  141. file_get_contents($this->_feedSamplePath)
  142. );
  143. $entry = $feed->current();
  144. $this->assertEquals(array('name'=>'laut.de'), $entry->getAuthor());
  145. }
  146. // Technically, the next two tests should not pass. However the source feed has an encoding
  147. // problem - it's stated as ISO-8859-1 but sent as UTF-8. The result is that a) it's
  148. // broken itself, or b) We should consider a fix in the future for similar feeds such
  149. // as using a more limited XML based decoding method (not html_entity_decode())
  150. public function testGetsEntryDescription()
  151. {
  152. $feed = Zend_Feed_Reader::importString(
  153. file_get_contents($this->_feedSamplePath)
  154. );
  155. $entry = $feed->current();
  156. $this->assertEquals('Schon länger haderten die Kölner mit der Plattform des "fiesen Rupert Murdoch". Das Fass zum Überlaufen brachte aber ein Werbebanner von Deutschrapper Sido.', $entry->getDescription());
  157. }
  158. public function testGetsEntryContent()
  159. {
  160. $feed = Zend_Feed_Reader::importString(
  161. file_get_contents($this->_feedSamplePath)
  162. );
  163. $entry = $feed->current();
  164. $this->assertEquals('Schon länger haderten die Kölner mit der Plattform des "fiesen Rupert Murdoch". Das Fass zum Überlaufen brachte aber ein Werbebanner von Deutschrapper Sido.', $entry->getContent());
  165. }
  166. public function testGetsEntryLinks()
  167. {
  168. $feed = Zend_Feed_Reader::importString(
  169. file_get_contents($this->_feedSamplePath)
  170. );
  171. $entry = $feed->current();
  172. $this->assertEquals(array('http://www.laut.de/vorlaut/news/2009/07/04/22426/index.htm'), $entry->getLinks());
  173. }
  174. public function testGetsEntryLink()
  175. {
  176. $feed = Zend_Feed_Reader::importString(
  177. file_get_contents($this->_feedSamplePath)
  178. );
  179. $entry = $feed->current();
  180. $this->assertEquals('http://www.laut.de/vorlaut/news/2009/07/04/22426/index.htm', $entry->getLink());
  181. }
  182. public function testGetsEntryPermaLink()
  183. {
  184. $feed = Zend_Feed_Reader::importString(
  185. file_get_contents($this->_feedSamplePath)
  186. );
  187. $entry = $feed->current();
  188. $this->assertEquals('http://www.laut.de/vorlaut/news/2009/07/04/22426/index.htm',
  189. $entry->getPermaLink());
  190. }
  191. public function testGetsEntryEncoding()
  192. {
  193. $feed = Zend_Feed_Reader::importString(
  194. file_get_contents($this->_feedSamplePath)
  195. );
  196. $entry = $feed->current();
  197. $this->assertEquals('ISO-8859-1', $entry->getEncoding());
  198. }
  199. }