ArtistTest.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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_Service_Audioscrobbler
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2008 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. /**
  23. * Test helper
  24. */
  25. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  26. /**
  27. * @see Zend_Service_Audioscrobbler
  28. */
  29. require_once 'Zend/Service/Audioscrobbler.php';
  30. require_once "AudioscrobblerTestCase.php";
  31. /**
  32. * @category Zend
  33. * @package Zend_Service_Audioscrobbler
  34. * @subpackage UnitTests
  35. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. */
  38. class Zend_Service_Audioscrobbler_ArtistTest extends Zend_Service_Audioscrobbler_AudioscrobblerTestCase
  39. {
  40. private $header = "HTTP/1.1 200 OK\r\nContent-type: text/xml\r\n\r\n";
  41. public function testGetRelatedArtists()
  42. {
  43. $getRelatedArtistsResponse = $this->header .
  44. '<?xml version="1.0" encoding="UTF-8"?>
  45. <similarartists artist="Metallica" streamable="1" picture="http://static.last.fm/proposedimages/sidebar/6/1000024/1285.jpg" mbid="65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab">
  46. <artist>
  47. <name>Iron Maiden</name>
  48. <mbid>ca891d65-d9b0-4258-89f7-e6ba29d83767</mbid>
  49. <match>100</match>
  50. <url>http://www.last.fm/music/Iron+Maiden</url>
  51. <image_small>http://static.last.fm/proposedimages/thumbnail/6/1000107/459375.jpg</image_small>
  52. <image>http://static.last.fm/proposedimages/sidebar/6/1000107/459375.jpg</image>
  53. <streamable>1</streamable>
  54. </artist>
  55. <artist>
  56. <name>System of a Down</name>
  57. <mbid>cc0b7089-c08d-4c10-b6b0-873582c17fd6</mbid>
  58. <match>96</match>
  59. <url>http://www.last.fm/music/System+of+a+Down</url>
  60. <image_small>http://static.last.fm/proposedimages/thumbnail/6/4468/52383.jpg</image_small>
  61. <image>http://static.last.fm/proposedimages/sidebar/6/4468/52383.jpg</image>
  62. <streamable>1</streamable>
  63. </artist>
  64. </similarartists>';
  65. $this->setAudioscrobblerResponse($getRelatedArtistsResponse);
  66. $as = $this->getAudioscrobblerService();
  67. $as->set('artist', 'Metallica');
  68. $response = $as->artistGetRelatedArtists();
  69. $artist = $response->artist[0];
  70. $this->assertEquals(count($response->artist), 2);
  71. $this->assertEquals((string)$artist->name, 'Iron Maiden');
  72. $this->assertEquals((string)$response['artist'], 'Metallica');
  73. }
  74. public function testGetFans()
  75. {
  76. $getFansResponse = $this->header .
  77. '<?xml version="1.0" encoding="UTF-8"?>
  78. <fans artist="Metallica">
  79. <user username="Liquid_Fire">
  80. <url>http://www.last.fm/user/Liquid_Fire/</url>
  81. <image>http://static.last.fm/avatar/d8d9af8246e537078a57d5dc826cb34a.gif</image>
  82. <weight>617010250</weight>
  83. </user>
  84. <user username="CeciltheDark">
  85. <url>http://www.last.fm/user/CeciltheDark/</url>
  86. <image>http://static.last.fm/avatar/30f0417393b696ac2ea06213bc5777d9.png</image>
  87. <weight>382812500</weight>
  88. </user>
  89. </fans>
  90. ';
  91. $this->setAudioscrobblerResponse($getFansResponse);
  92. $as = $this->getAudioscrobblerService();
  93. $as->set('artist', 'Metallica');
  94. $response = $as->artistGetTopFans();
  95. $user = $response->user[0];
  96. $this->assertEquals((string)$response['artist'], 'Metallica');
  97. $this->assertEquals((string)$user->url, 'http://www.last.fm/user/Liquid_Fire/');
  98. }
  99. public function testTopTracks()
  100. {
  101. $getTopTracksResponse = $this->header .
  102. '<?xml version="1.0" encoding="UTF-8"?>
  103. <mostknowntracks artist="Metallica">
  104. <track>
  105. <name>Nothing Else Matters</name>
  106. <mbid></mbid>
  107. <reach>7481</reach>
  108. <url>http://www.last.fm/music/Metallica/_/Nothing+Else+Matters</url>
  109. </track>
  110. <track>
  111. <name>Enter Sandman</name>
  112. <mbid></mbid>
  113. <reach>7139</reach>
  114. <url>http://www.last.fm/music/Metallica/_/Enter+Sandman</url>
  115. </track>
  116. </mostknowntracks>';
  117. $this->setAudioscrobblerResponse($getTopTracksResponse);
  118. $as = $this->getAudioscrobblerService();
  119. $as->set('artist', 'Metallica');
  120. $response = $as->artistGetTopTracks();
  121. $track = $response->track[0];
  122. $this->assertEquals((string)$response['artist'], 'Metallica');
  123. $this->assertEquals((string)$track->name, 'Nothing Else Matters');
  124. $this->assertEquals((int)$track->reach, 7481);
  125. }
  126. public function testTopAlbums()
  127. {
  128. $getTopAlbumsResponse = $this->header .
  129. '<?xml version="1.0" encoding="UTF-8"?>
  130. <topalbums artist="Metallica">
  131. <album>
  132. <name>Master of Puppets</name>
  133. <mbid>fed37cfc-2a6d-4569-9ac0-501a7c7598eb</mbid>
  134. <reach>28940</reach>
  135. <url>http://www.last.fm/music/Metallica/Master+of+Puppets</url>
  136. <releasedate>7 Oct 1986, 00:00</releasedate>
  137. <coverart>
  138. <small>http://static.last.fm/coverart/50x50/1411810.jpg</small>
  139. <medium>http://static.last.fm/coverart/130x130/1411810.jpg</medium>
  140. <large>http://static.last.fm/coverart/300x300/1411810.jpg</large>
  141. </coverart>
  142. </album>
  143. <album>
  144. <name>Reload</name>
  145. <mbid>b05cf8e3-67ad-4d40-9dc1-3a697e3a1bf8</mbid>
  146. <reach>27226</reach>
  147. <url>http://www.last.fm/music/Metallica/Reload</url>
  148. <releasedate>18 Nov 1997, 00:00</releasedate>
  149. <coverart>
  150. <small>http://images.amazon.com/images/P/B000002HRE.01._SCMZZZZZZZ_.jpg</small>
  151. <medium>http://images.amazon.com/images/P/B000002HRE.01._SCMZZZZZZZ_.jpg</medium>
  152. <large>http://images.amazon.com/images/P/B000002HRE.01._SCMZZZZZZZ_.jpg</large>
  153. </coverart>
  154. </album>
  155. </topalbums>
  156. ';
  157. $this->setAudioscrobblerResponse($getTopAlbumsResponse);
  158. $as = $this->getAudioscrobblerService();
  159. $as->set('artist', 'Metallica');
  160. $response = $as->artistGetTopAlbums();
  161. $album = $response->album[0];
  162. $this->assertEquals((string)$response['artist'], 'Metallica');
  163. $this->assertEquals((string)$album->name, 'Master of Puppets');
  164. $this->assertEquals((string)$album->coverart->small, 'http://static.last.fm/coverart/50x50/1411810.jpg');
  165. }
  166. public function testTopTags()
  167. {
  168. $test_response = $this->header .
  169. '<?xml version="1.0" encoding="UTF-8"?>
  170. <toptags artist="Metallica">
  171. <tag>
  172. <name>metal</name>
  173. <count>100</count>
  174. <url>http://www.last.fm/tag/metal</url>
  175. </tag>
  176. <tag>
  177. <name>heavy metal</name>
  178. <count>24</count>
  179. <url>http://www.last.fm/tag/heavy%20metal</url>
  180. </tag>
  181. <tag>
  182. <name>thrash metal</name>
  183. <count>18</count>
  184. <url>http://www.last.fm/tag/thrash%20metal</url>
  185. </tag>
  186. </toptags>
  187. ';
  188. $this->setAudioscrobblerResponse($test_response);
  189. $as = $this->getAudioscrobblerService();
  190. $as->set('artist', 'Metallica');
  191. $response = $as->artistGetTopTags();
  192. $tag = $response->tag[0];
  193. $this->assertEquals((string)$response['artist'], 'Metallica');
  194. $this->assertEquals((string)$tag->name, 'metal');
  195. $this->assertEquals((int)$tag->count, 100);
  196. }
  197. }