ProfileTest.php 31 KB

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