ProfileTest.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  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-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. /**
  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-2015 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_ProfileTest extends Zend_Service_Audioscrobbler_AudioscrobblerTestCase
  37. {
  38. public function testConstructValid()
  39. {
  40. $response = new Zend_Service_Audioscrobbler();
  41. $this->assertNotNull($response);
  42. }
  43. public function testGetProfileInfo()
  44. {
  45. $test_response = "HTTP/1.1 200 OK\r\n" .
  46. "Content-type: text/xml\r\n" .
  47. "\r\n" .
  48. '<?xml version="1.0" encoding="UTF-8"?>
  49. <profile id="1000002" cluster="2" username="RJ">
  50. <url>http://www.last.fm/user/RJ/</url>
  51. <realname>Richard Jones</realname>
  52. <mbox_sha1sum>1b374543545e01bc8d555a6a57c637f61f999fdf</mbox_sha1sum>
  53. <registered unixtime="1037793040">Nov 20, 2002</registered>
  54. <age>24</age>
  55. <gender>m</gender>
  56. <country>United Kingdom</country>
  57. <playcount>45043</playcount>
  58. <avatar>http://static.last.fm/avatar/0f4bda3a8e49e714c26ef610e2893454.jpg</avatar>
  59. </profile>';
  60. $this->setAudioscrobblerResponse($test_response);
  61. $as = $this->getAudioscrobblerService();
  62. $as->set('user', 'RJ');
  63. $response = $as->userGetProfileInformation();
  64. $this->assertNotNull($response);
  65. }
  66. public function testGetBadProfileInfo()
  67. {
  68. $this->markTestSkipped('Invalid test, communicating with the outside world!');
  69. $as = new Zend_Service_Audioscrobbler();
  70. $as->set('user', 'kljadsfjllkj');
  71. try {
  72. $response = $as->userGetProfileInformation();
  73. $this->assertNull($response);
  74. } catch (Exception $e) {
  75. return;
  76. }
  77. $this->fail('Exception was not thrown when submitting bad user info');
  78. }
  79. public function testUserGetTopArtists( )
  80. {
  81. $test_response = "HTTP/1.1 200 OK\r\n" .
  82. "Content-type: text/xml\r\n" .
  83. "\r\n" .
  84. '<?xml version="1.0" encoding="UTF-8"?>
  85. <topartists user="RJ">
  86. <artist>
  87. <name>Dream Theater</name>
  88. <mbid>28503ab7-8bf2-4666-a7bd-2644bfc7cb1d</mbid>
  89. <playcount>854</playcount>
  90. <rank>1</rank>
  91. <url>http://www.last.fm/music/Dream+Theater</url>
  92. <thumbnail>http://static.last.fm/proposedimages/thumbnail/6/4209/432600.jpg</thumbnail>
  93. <image>http://static.last.fm/proposedimages/sidebar/6/4209/432600.jpg</image>
  94. </artist>
  95. </topartists>';
  96. $this->setAudioscrobblerResponse($test_response); $as = $this->getAudioscrobblerService();
  97. $as->set('user', 'RJ');
  98. $response = $as->userGetTopArtists();
  99. $artist = $response->artist[0];
  100. $this->assertEquals((string)$response['user'], 'RJ');
  101. $this->assertEquals((string)$artist->name, 'Dream Theater');
  102. $this->assertNotNull($artist->rank, 1);
  103. }
  104. public function testUserGetTopAlbums( )
  105. {
  106. $testing_response = "HTTP/1.1 200 OK\r\n" .
  107. "Content-type: text/xml\r\n" .
  108. "\r\n" .
  109. '<?xml version="1.0" encoding="UTF-8"?>
  110. <topalbums user="Frith">
  111. <album>
  112. <artist mbid="d8915e13-d67a-4aa0-9c0b-1f126af951af">Hot Chip</artist>
  113. <name>The Warning</name>
  114. <mbid></mbid>
  115. <playcount>227</playcount>
  116. <rank>1</rank>
  117. <url>http://www.last.fm/music/Hot+Chip/The+Warning</url>
  118. <image>
  119. <large>http://images.amazon.com/images/P/B000FBFSVU.01._SCMZZZZZZZ_.jpg</large>
  120. <medium>http://images.amazon.com/images/P/B000FBFSVU.01._SCMZZZZZZZ_.jpg</medium>
  121. <small>http://images.amazon.com/images/P/B000FBFSVU.01._SCMZZZZZZZ_.jpg</small>
  122. </image>
  123. </album>
  124. </topalbums>';
  125. $this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
  126. $as->set('user', 'Frith');
  127. $response = $as->userGetTopAlbums();
  128. $album = $response->album[0];
  129. $this->assertEquals((string)$response['user'], 'Frith');
  130. $this->assertNotNull($album);
  131. $this->assertEquals((string)$album->name, 'The Warning');
  132. }
  133. public function testUserGetTopTracks( )
  134. {
  135. $testing_response = "HTTP/1.1 200 OK\r\n" .
  136. "Content-type: text/xml\r\n" .
  137. "\r\n" .
  138. '<?xml version="1.0" encoding="UTF-8"?>
  139. <toptracks user="RJ">
  140. <track>
  141. <artist mbid="12ff8858-bfcb-4812-a8dd-7e9debf0cbee">Steppenwolf</artist>
  142. <name>The Pusher</name>
  143. <mbid></mbid>
  144. <playcount>31</playcount>
  145. <rank>1</rank>
  146. <url>http://www.last.fm/music/Steppenwolf/_/The+Pusher</url>
  147. </track>
  148. <track>
  149. <artist mbid="8f6bd1e4-fbe1-4f50-aa9b-94c450ec0f11">Portishead</artist>
  150. <name>Cowboys</name>
  151. <mbid></mbid>
  152. <playcount>28</playcount>
  153. <rank>2</rank>
  154. <url>http://www.last.fm/music/Portishead/_/Cowboys</url>
  155. </track>
  156. </toptracks>';
  157. $this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
  158. $as->set('user', 'RJ');
  159. $response = $as->userGetTopTracks();
  160. $track = $response->track[0];
  161. $this->assertEquals((string)$response['user'], 'RJ');
  162. $this->assertNotNull($track);
  163. $this->assertEquals((string)$track->artist, 'Steppenwolf');
  164. $this->assertEquals((int)$track->playcount, 31);
  165. }
  166. public function testUserGetTopTags( )
  167. {
  168. $testing_response = "HTTP/1.1 200 OK\r\n" .
  169. "Content-type: text/xml\r\n" .
  170. "\r\n" .
  171. '<?xml version="1.0" encoding="UTF-8"?>
  172. <toptags user="RJ">
  173. <tag>
  174. <name>rock</name>
  175. <count>9</count>
  176. <url>http://www.last.fm/tag/rock</url>
  177. </tag>
  178. <tag>
  179. <name>metal</name>
  180. <count>8</count>
  181. <url>http://www.last.fm/tag/metal</url>
  182. </tag>
  183. <tag>
  184. <name>mellow</name>
  185. <count>5</count>
  186. <url>http://www.last.fm/tag/mellow</url>
  187. </tag>
  188. </toptags>';
  189. $this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
  190. $as->set('user', 'RJ');
  191. $response = $as->userGetTopTags();
  192. $tag = $response->tag[1];
  193. $this->assertEquals((string)$response['user'], 'RJ');
  194. $this->assertNotNull($tag);
  195. $this->assertEquals((string)$tag->name, 'metal');
  196. $this->assertEquals((int)$tag->count, 8);
  197. }
  198. public function testUserGetTopTagsForArtist()
  199. {
  200. $testing_response = "HTTP/1.1 200 OK\r\n" .
  201. "Content-type: text/xml\r\n" .
  202. "\r\n" .
  203. '<?xml version="1.0" encoding="UTF-8"?>
  204. <artisttags user="RJ" artist="Metallica">
  205. <tag>
  206. <name>metal</name>
  207. <count>1</count>
  208. <url>http://www.last.fm/tag/metal</url>
  209. </tag>
  210. <tag>
  211. <name>80s</name>
  212. <count>1</count>
  213. <url>http://www.last.fm/tag/80s</url>
  214. </tag>
  215. </artisttags>';
  216. $this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
  217. $as->set('user', 'RJ');
  218. $as->set('artist', 'Metallica');
  219. $response = $as->userGetTopTagsForArtist();
  220. $tag = $response->tag[0];
  221. $this->assertEquals((string)$response['user'], 'RJ');
  222. $this->assertEquals((string)$response['artist'], 'Metallica');
  223. $this->assertNotNull($tag);
  224. }
  225. /**
  226. * Ensures that userGetTopTagsForArtist() throws an exception when based on bad parameters
  227. *
  228. * @return void
  229. */
  230. public function testBadUserGetTopTagsForArtist()
  231. {
  232. $testingResponse = "HTTP/1.1 200 OK\r\n"
  233. . "Content-type: text/xml\r\n"
  234. . "\r\n"
  235. . "ERROR: Missing 'subject' parameter in querystring";
  236. $this->setAudioscrobblerResponse($testingResponse);
  237. $as = $this->getAudioscrobblerService();
  238. try {
  239. $response = $as->userGetTopTagsForArtist();
  240. $this->fail('userGetTopTagsForArtist() did not throw exception based on bad parameters');
  241. } catch (Zend_Service_Exception $e) {
  242. $this->assertContains('SimpleXML', $e->getMessage());
  243. }
  244. }
  245. public function testUserGetTopTagsForAlbum()
  246. {
  247. $testing_response = "HTTP/1.1 200 OK\r\n" .
  248. "Content-type: text/xml\r\n" .
  249. "\r\n" .
  250. '<?xml version="1.0" encoding="UTF-8"?>
  251. <albumtags user="RJ" album="Ride the Lightning" artist="Metallica">
  252. </albumtags>';
  253. $this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
  254. $as->set('user', 'RJ');
  255. $as->set('artist', 'Metallica');
  256. $as->set('album', 'Ride The Lightning');
  257. $response = $as->userGetTopTagsForAlbum();
  258. $this->assertEquals((string)$response['user'], 'RJ');
  259. $this->assertEquals((string)strtolower($response['artist']), strtolower('Metallica'));
  260. $this->assertEquals((string)strtolower($response['album']), strtolower('Ride The Lightning'));
  261. }
  262. public function testUserGetTopTagsForTrack()
  263. {
  264. $testing_response = "HTTP/1.1 200 OK\r\n" .
  265. "Content-type: text/xml\r\n" .
  266. "\r\n" .
  267. '<?xml version="1.0" encoding="UTF-8"?>
  268. <tracktags user="RJ" artist="Metallica" track="Nothing Else Matters">
  269. </tracktags>';
  270. $this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
  271. $as->set('user', 'RJ');
  272. $as->set('artist', 'Metallica');
  273. $as->set('track', 'Nothing Else Matters');
  274. $response = $as->userGetTopTagsForTrack();
  275. $this->assertEquals((string)$response['user'], 'RJ');
  276. $this->assertEquals((string)$response['artist'], 'Metallica');
  277. $this->assertEquals((string)$response['track'], 'Nothing Else Matters');
  278. }
  279. public function testUserGetFriends()
  280. {
  281. $testing_response = "HTTP/1.1 200 OK\r\n" .
  282. "Content-type: text/xml\r\n" .
  283. "\r\n" .
  284. '<?xml version="1.0" encoding="UTF-8"?>
  285. <friends user="RJ">
  286. <user username="julians">
  287. <url>http://www.last.fm/user/julians/</url>
  288. <image>http://static.last.fm/avatar/9ca899b8f20b7173d47983cc0533be8c.gif</image>
  289. <connections>
  290. </connections>
  291. </user>
  292. <user username="Korean_Cowboy">
  293. <url>http://www.last.fm/user/Korean_Cowboy/</url>
  294. <image>http://static.last.fm/avatar/091614ec2288764362c94f047d207336.jpg</image>
  295. <connections>
  296. </connections>
  297. </user>
  298. </friends>';
  299. $this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
  300. $as->set('user', 'RJ');
  301. $response = $as->userGetFriends();
  302. $this->assertEquals((string)$response['user'], 'RJ');
  303. $this->assertEquals(count($response->user), 2);
  304. }
  305. public function testUserGetNeighbours()
  306. {
  307. $testing_response = "HTTP/1.1 200 OK\r\n" .
  308. "Content-type: text/xml\r\n" .
  309. "\r\n" .
  310. '<?xml version="1.0" encoding="UTF-8"?>
  311. <neighbours user="RJ">
  312. <user username="count-bassy">
  313. <url>http://www.last.fm/user/count-bassy/</url>
  314. <image>http://static.last.fm/avatar/3da65e2f347f64c033c9eced171e7a21.gif</image>
  315. <match>100</match>
  316. </user>
  317. <user username="arcymarcy">
  318. <url>http://www.last.fm/user/arcymarcy/</url>
  319. <image>http://static.last.fm/avatar/eed7d6afea225f85cfcd6ee61eac19aa.jpg</image>
  320. <match>93.12</match>
  321. </user>
  322. </neighbours>';
  323. $this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
  324. $as->set('user', 'RJ');
  325. $response = $as->userGetNeighbours();
  326. $this->assertEquals((string)$response['user'], 'RJ');
  327. $this->assertEquals(count($response->user), 2);
  328. $user = $response->user[1];
  329. $this->assertEquals((string)$user['username'], 'arcymarcy');
  330. }
  331. public function testUserRecentTracks()
  332. {
  333. $testing_response = "HTTP/1.1 200 OK\r\n" .
  334. "Content-type: text/xml\r\n" .
  335. "\r\n" .
  336. '<?xml version="1.0" encoding="UTF-8"?>
  337. <recenttracks user="RJ">
  338. <track>
  339. <artist mbid="97d9060d-2cd5-4acd-b44f-c39ea2da4753">Tok Tok Tok</artist>
  340. <name>Always An Excuse</name>
  341. <mbid></mbid>
  342. <url>http://www.last.fm/music/Tok+Tok+Tok/_/Always+An+Excuse</url>
  343. <date uts="1173203133">6 Mar 2007, 17:45</date>
  344. </track>
  345. <track>
  346. <artist mbid="97d9060d-2cd5-4acd-b44f-c39ea2da4753">Tok Tok Tok</artist>
  347. <name>What Has Roots</name>
  348. <mbid></mbid>
  349. <url>http://www.last.fm/music/Tok+Tok+Tok/_/What+Has+Roots</url>
  350. <date uts="1173202787">6 Mar 2007, 17:39</date>
  351. </track>
  352. </recenttracks>';
  353. $this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
  354. $as->set('user', 'RJ');
  355. $response = $as->userGetRecentTracks();
  356. $track = $response->track[0];
  357. $this->assertEquals((string)$response['user'], 'RJ');
  358. $this->assertEquals(count($response->track), 2);
  359. $this->assertEquals((string)$track->name, 'Always An Excuse');
  360. }
  361. public function testUserRecentBannedTracks()
  362. {
  363. $testing_response = "HTTP/1.1 200 OK\r\nContent-type: text/xml\r\n\r\n" .
  364. '<?xml version="1.0" encoding="UTF-8"?>
  365. <recentbannedtracks user="RJ">
  366. <track>
  367. <artist mbid="27613b78-1b9d-4ec3-9db5-fa0743465fdd">Herbie Hancock</artist>
  368. <name>Rockit</name>
  369. <mbid></mbid>
  370. <url>http://www.last.fm/music/Herbie+Hancock/_/Rockit</url>
  371. <date uts="1171126557">10 Feb 2007, 16:55</date>
  372. </track>
  373. <track>
  374. <artist mbid="7e54d133-2525-4bc0-ae94-65584145a386">Plaid</artist>
  375. <name>Plaid Rmx</name>
  376. <mbid></mbid>
  377. <url>http://www.last.fm/music/Plaid/_/Plaid+Rmx</url>
  378. <date uts="1161129235">17 Oct 2006, 23:53</date>
  379. </track>
  380. </recentbannedtracks>';
  381. $this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
  382. $as->set('user', 'RJ');
  383. $response = $as->userGetRecentBannedTracks();
  384. $track = $response->track[0];
  385. $this->assertEquals((string)$response['user'], 'RJ');
  386. $this->assertEquals(count($response->track), 2);
  387. $this->assertEquals((string)$track->artist, 'Herbie Hancock');
  388. $this->assertEquals((string)$track->name, 'Rockit');
  389. }
  390. public function testUserRecentLovedTracks()
  391. {
  392. $testing_response = "HTTP/1.1 200 OK\r\nContent-type: text/xml\r\n\r\n" .
  393. '<?xml version="1.0" encoding="UTF-8"?>
  394. <recentlovedtracks user="RJ">
  395. <track>
  396. <artist mbid="9a7c8025-1af8-42cd-8df8-857220610bc5">Spyro Gyra</artist>
  397. <name>Morning Dance</name>
  398. <mbid></mbid>
  399. <url>http://www.last.fm/music/Spyro+Gyra/_/Morning+Dance</url>
  400. <date uts="1163006139">8 Nov 2006, 17:15</date>
  401. </track>
  402. <track>
  403. <artist mbid="149e6720-4e4a-41a4-afca-6d29083fc091">Bad Religion</artist>
  404. <name>I Love My Computer</name>
  405. <mbid></mbid>
  406. <url>http://www.last.fm/music/Bad+Religion/_/I+Love+My+Computer</url>
  407. <date uts="1162310037">31 Oct 2006, 15:53</date>
  408. </track>
  409. </recentlovedtracks>';
  410. $this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
  411. $as->set('user', 'RJ');
  412. $response = $as->userGetRecentLovedTracks();
  413. $track = $response->track[1];
  414. $this->assertEquals((string)$response['user'], 'RJ');
  415. $this->assertNotNull((string)$track->name, 'Morning Dance');
  416. $this->assertNotNull((string)$track->date, '31 Oct 2006, 15:53');
  417. $this->assertNotNull($response->track);
  418. }
  419. public function testUserGetWeeklyChartList()
  420. {
  421. $testing_response = "HTTP/1.1 200 OK\r\nContent-type: text/xml\r\n\r\n" .
  422. '<?xml version="1.0" encoding="UTF-8"?>
  423. <weeklychartlist user="RJ">
  424. <chart from="1108296002" to="1108900802"/>
  425. <chart from="1108900801" to="1109505601"/>
  426. <chart from="1109505601" to="1110110401"/>
  427. <chart from="1110715201" to="1111320001"/>
  428. <chart from="1111320001" to="1111924801"/>
  429. <chart from="1111924801" to="1112529601"/>
  430. <chart from="1112529601" to="1113134401"/>
  431. </weeklychartlist>';
  432. $this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
  433. $as->set('user', 'RJ');
  434. $response = $as->userGetWeeklyChartList();
  435. $chart = $response->chart[0];
  436. $this->assertEquals((string)$response['user'], 'RJ');
  437. $this->assertEquals(count($response->chart), 7);
  438. $this->assertEquals((string)$chart['from'], '1108296002');
  439. $this->assertEquals((string)$chart['to'], '1108900802');
  440. }
  441. public function testUserGetRecentWeeklyArtistChart()
  442. {
  443. $testing_response = "HTTP/1.1 200 OK\r\nContent-type: text/xml\r\n\r\n" .
  444. '<?xml version="1.0" encoding="UTF-8"?>
  445. <weeklyartistchart user="RJ" from="1172404800" to="1173009600">
  446. <artist>
  447. <name>Miles Davis</name>
  448. <mbid>561d854a-6a28-4aa7-8c99-323e6ce46c2a</mbid>
  449. <chartposition>1</chartposition>
  450. <playcount>30</playcount>
  451. <url>http://www.last.fm/music/Miles+Davis</url>
  452. </artist>
  453. <artist>
  454. <name>Guano Apes</name>
  455. <mbid>66da25f9-1534-4dd1-b88c-718bc24e1ccd</mbid>
  456. <chartposition>2</chartposition>
  457. <playcount>28</playcount>
  458. <url>http://www.last.fm/music/Guano+Apes</url>
  459. </artist>
  460. </weeklyartistchart>';
  461. $this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
  462. $as->set('user', 'RJ');
  463. $response = $as->userGetWeeklyArtistChart();
  464. $this->assertEquals((string)$response['user'], 'RJ');
  465. $this->assertNotNull($response->weeklyartistchart);
  466. $this->assertNotNull($response->artist);
  467. }
  468. public function testUserGetWeeklyAlbumChart()
  469. {
  470. $testing_response = "HTTP/1.1 200 OK\r\nContent-type: text/xml\r\n\r\n" .
  471. '<?xml version="1.0" encoding="UTF-8"?>
  472. <weeklyalbumchart user="RJ" from="1172404800" to="1173009600">
  473. <album>
  474. <artist mbid="6da0515e-a27d-449d-84cc-00713c38a140">Skid Row</artist>
  475. <name>Slave To The Grid</name>
  476. <mbid></mbid>
  477. <chartposition>1</chartposition>
  478. <playcount>12</playcount>
  479. <url>http://www.last.fm/music/Skid+Row/Slave+To+The+Grid</url>
  480. </album>
  481. <album>
  482. <artist mbid="66da25f9-1534-4dd1-b88c-718bc24e1ccd">Guano Apes</artist>
  483. <name>Walking on a Thin Line</name>
  484. <mbid>769a46de-52e2-4322-9db0-cbd6b789e3f8</mbid>
  485. <chartposition>1</chartposition>
  486. <playcount>12</playcount>
  487. <url>http://www.last.fm/music/Guano+Apes/Walking+on+a+Thin+Line</url>
  488. </album>
  489. </weeklyalbumchart>';
  490. $this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
  491. $as->set('user', 'RJ');
  492. $response = $as->userGetWeeklyAlbumChart();
  493. $album = $response->album[0];
  494. $this->assertEquals((string)$response['user'], 'RJ');
  495. $this->assertEquals(count($response->album), 2);
  496. $this->assertEquals((string)$album->artist, 'Skid Row');
  497. $this->assertEquals((string)$album->name, 'Slave To The Grid');
  498. }
  499. public function testUserGetPreviousWeeklyArtistChart()
  500. {
  501. $testing_response = "HTTP/1.1 200 OK\r\nContent-type: text/xml\r\n\r\n" .
  502. '<?xml version="1.0" encoding="UTF-8"?>
  503. <weeklyartistchart user="RJ" from="1114965332" to="1115570132">
  504. <artist>
  505. <name>Nine Inch Nails</name>
  506. <mbid>b7ffd2af-418f-4be2-bdd1-22f8b48613da</mbid>
  507. <chartposition>1</chartposition>
  508. <playcount>23</playcount>
  509. <url>http://www.last.fm/music/Nine+Inch+Nails</url>
  510. </artist>
  511. <artist>
  512. <name>The Doors</name>
  513. <mbid>9efff43b-3b29-4082-824e-bc82f646f93d</mbid>
  514. <chartposition>2</chartposition>
  515. <playcount>3</playcount>
  516. <url>http://www.last.fm/music/The+Doors</url>
  517. </artist>
  518. </weeklyartistchart>';
  519. $this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
  520. $as->set('user', 'RJ');
  521. $from = 1114965332;
  522. $to = 1115570132;
  523. $response = $as->userGetWeeklyArtistChart($from, $to);
  524. $artist = $response->artist[0];
  525. $this->assertEquals((string)$response['user'], 'RJ');
  526. $this->assertEquals((int)$response['from'], $from);
  527. $this->assertEquals((int)$response['to'], $to);
  528. $this->assertEquals((string)$artist->name, 'Nine Inch Nails');
  529. $this->assertEquals(count($response->artist), 2);
  530. }
  531. public function testUserGetPreviousWeeklyAlbumChart()
  532. {
  533. $testing_response = "HTTP/1.1 200 OK\r\nContent-type: text/xml\r\n\r\n" .
  534. '<?xml version="1.0" encoding="UTF-8"?>
  535. <weeklyalbumchart user="RJ" from="1114965332" to="1115570132">
  536. <album>
  537. <artist mbid="9efff43b-3b29-4082-824e-bc82f646f93d">The Doors</artist>
  538. <name>The Doors Box Set</name>
  539. <mbid></mbid>
  540. <chartposition>1</chartposition>
  541. <playcount>2</playcount>
  542. <url>http://www.last.fm/music/The+Doors/The+Doors+Box+Set</url>
  543. </album>
  544. <album>
  545. <artist mbid="5b11f4ce-a62d-471e-81fc-a69a8278c7da">Nirvana</artist>
  546. <name>Nirvana</name>
  547. <mbid>d8f9547d-5e46-45f0-b694-0d9af9e2de63</mbid>
  548. <chartposition>1</chartposition>
  549. <playcount>2</playcount>
  550. <url>http://www.last.fm/music/Nirvana/Nirvana</url>
  551. </album>
  552. </weeklyalbumchart>';
  553. $this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
  554. $as->set('user', 'RJ');
  555. $from = 1114965332;
  556. $to = 1115570132;
  557. $response = $as->userGetWeeklyAlbumChart($from, $to);
  558. $album = $response->album[0];
  559. $this->assertEquals((string)$response['user'], 'RJ');
  560. $this->assertEquals((int)$response['from'], 1114965332);
  561. $this->assertEquals((int)$response['to'], 1115570132);
  562. $this->assertEquals(count($response->album), 2);
  563. }
  564. public function testUserGetPreviousWeeklyTrackChart()
  565. {
  566. $testing_response = "HTTP/1.1 200 OK\r\nContent-type: text/xml\r\n\r\n" .
  567. '<?xml version="1.0" encoding="UTF-8"?>
  568. <weeklytrackchart user="RJ" from="1114965332" to="1115570132">
  569. <track>
  570. <artist mbid="f73b2b70-33d5-4118-923b-05ba8ad7e702">The Kleptones</artist>
  571. <name>Question</name>
  572. <mbid></mbid>
  573. <chartposition>1</chartposition>
  574. <playcount>3</playcount>
  575. <url>http://www.last.fm/music/The+Kleptones/_/Question</url>
  576. </track>
  577. <track>
  578. <artist mbid="b7ffd2af-418f-4be2-bdd1-22f8b48613da">Nine Inch Nails</artist>
  579. <name>All the Love in the World</name>
  580. <mbid></mbid>
  581. <chartposition>2</chartposition>
  582. <playcount>2</playcount>
  583. <url>http://www.last.fm/music/Nine+Inch+Nails/_/All+the+Love+in+the+World</url>
  584. </track>
  585. </weeklytrackchart>';
  586. $this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
  587. $as->set('user', 'RJ');
  588. $from = 1114965332;
  589. $to = 1115570132;
  590. $response = $as->userGetWeeklyTrackChart($from, $to);
  591. $track = $response->track[0];
  592. $this->assertEquals((string)$response['user'], 'RJ');
  593. $this->assertEquals((int)$response['from'], $from);
  594. $this->assertEquals((int)$response['to'], $to);
  595. $this->assertEquals((string)$track->artist, 'The Kleptones');
  596. $this->assertEquals(count($response->track), 2);
  597. }
  598. }