LautDeRdfTest.php 6.8 KB

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