LautDeRdfTest.php 7.2 KB

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