ArtistTest.php 9.7 KB

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