PageRenderTime 25ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/ZendFramework/tests/Zend/Service/Audioscrobbler/ArtistTest.php

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