ProfileTest.php 31 KB

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