GroupTest.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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_GroupTest extends Zend_Service_Audioscrobbler_AudioscrobblerTestCase
  39. {
  40. private $header = "HTTP/1.1 200 OK\r\nContent-type: text/xml\r\n\r\n";
  41. public function testWeeklyChartList()
  42. {
  43. $testing_response = $this->header .
  44. '<?xml version="1.0" encoding="UTF-8"?>
  45. <weeklychartlist group="Jazz Club">
  46. <chart from="1159099200" to="1159704000"/>
  47. <chart from="1159704000" to="1160308800"/>
  48. <chart from="1160308800" to="1160913600"/>
  49. <chart from="1160913600" to="1161518400"/>
  50. <chart from="1161518400" to="1162123200"/>
  51. <chart from="1162123200" to="1162728000"/>
  52. <chart from="1162728000" to="1163332800"/>
  53. <chart from="1163332800" to="1163937600"/>
  54. <chart from="1163937600" to="1164542400"/>
  55. <chart from="1164542400" to="1165147200"/>
  56. <chart from="1165147200" to="1165752000"/>
  57. <chart from="1165752000" to="1166356800"/>
  58. <chart from="1166356800" to="1166961600"/>
  59. <chart from="1166961600" to="1167566400"/>
  60. <chart from="1167566400" to="1168171200"/>
  61. <chart from="1168171200" to="1168776000"/>
  62. <chart from="1168776000" to="1169380800"/>
  63. <chart from="1169380800" to="1169985600"/>
  64. <chart from="1169985600" to="1170590400"/>
  65. <chart from="1170590400" to="1171195200"/>
  66. <chart from="1171195200" to="1171800000"/>
  67. <chart from="1171800000" to="1172404800"/>
  68. <chart from="1172404800" to="1173009600"/>
  69. </weeklychartlist>
  70. ';
  71. $this->setAudioscrobblerResponse($testing_response);
  72. $as = $this->getAudioscrobblerService();
  73. $as->set('group', urlencode('Jazz Club'));
  74. $response = $as->groupGetWeeklyChartList();
  75. $chart = $response->chart[0];
  76. $this->assertEquals((int)$chart['from'], 1159099200);
  77. $this->assertEquals((string)$response['group'], 'Jazz Club');
  78. }
  79. public function testWeeklyArtistChartList()
  80. {
  81. $testing_response = $this->header .
  82. '<?xml version="1.0" encoding="UTF-8"?>
  83. <weeklyartistchart group="Jazz Club" from="1172404800" to="1173009600">
  84. <artist>
  85. <name>Miles Davis</name>
  86. <mbid>561d854a-6a28-4aa7-8c99-323e6ce46c2a</mbid>
  87. <chartposition>1</chartposition>
  88. <reach>194</reach>
  89. <url>http://www.last.fm/music/Miles+Davis</url>
  90. </artist>
  91. <artist>
  92. <name>The Beatles</name>
  93. <mbid>b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d</mbid>
  94. <chartposition>2</chartposition>
  95. <reach>156</reach>
  96. <url>http://www.last.fm/music/The+Beatles</url>
  97. </artist>
  98. <artist>
  99. <name>Pink Floyd</name>
  100. <mbid>83d91898-7763-47d7-b03b-b92132375c47</mbid>
  101. <chartposition>3</chartposition>
  102. <reach>132</reach>
  103. <url>http://www.last.fm/music/Pink+Floyd</url>
  104. </artist>
  105. <artist>
  106. <name>John Coltrane</name>
  107. <mbid>b625448e-bf4a-41c3-a421-72ad46cdb831</mbid>
  108. <chartposition>4</chartposition>
  109. <reach>124</reach>
  110. <url>http://www.last.fm/music/John+Coltrane</url>
  111. </artist>
  112. <artist>
  113. <name>Radiohead</name>
  114. <mbid>a74b1b7f-71a5-4011-9441-d0b5e4122711</mbid>
  115. <chartposition>4</chartposition>
  116. <reach>124</reach>
  117. <url>http://www.last.fm/music/Radiohead</url>
  118. </artist>
  119. <artist>
  120. <name>Herbie Hancock</name>
  121. <mbid>27613b78-1b9d-4ec3-9db5-fa0743465fdd</mbid>
  122. <chartposition>6</chartposition>
  123. <reach>106</reach>
  124. <url>http://www.last.fm/music/Herbie+Hancock</url>
  125. </artist>
  126. <artist>
  127. <name>Led Zeppelin</name>
  128. <mbid>678d88b2-87b0-403b-b63d-5da7465aecc3</mbid>
  129. <chartposition>7</chartposition>
  130. <reach>104</reach>
  131. <url>http://www.last.fm/music/Led+Zeppelin</url>
  132. </artist>
  133. <artist>
  134. <name>David Bowie</name>
  135. <mbid>5441c29d-3602-4898-b1a1-b77fa23b8e50</mbid>
  136. <chartposition>8</chartposition>
  137. <reach>102</reach>
  138. <url>http://www.last.fm/music/David+Bowie</url>
  139. </artist>
  140. <artist>
  141. <name>AIR</name>
  142. <mbid>cb67438a-7f50-4f2b-a6f1-2bb2729fd538</mbid>
  143. <chartposition>9</chartposition>
  144. <reach>96</reach>
  145. <url>http://www.last.fm/music/AIR</url>
  146. </artist>
  147. <artist>
  148. <name>Red Hot Chili Peppers</name>
  149. <mbid>8bfac288-ccc5-448d-9573-c33ea2aa5c30</mbid>
  150. <chartposition>9</chartposition>
  151. <reach>96</reach>
  152. <url>http://www.last.fm/music/Red+Hot+Chili+Peppers</url>
  153. </artist>
  154. </weeklyartistchart>
  155. ';
  156. $this->setAudioscrobblerResponse($testing_response);
  157. $as = $this->getAudioscrobblerService();
  158. $as->set('group', urlencode('Jazz Club'));
  159. $response = $as->groupGetWeeklyArtistChartList();
  160. $this->assertNotNull(count($response));
  161. $artist = $response->artist[1];
  162. $this->assertEquals((string)$artist->name, 'The Beatles');
  163. $this->assertEquals((string)$artist->url, 'http://www.last.fm/music/The+Beatles');
  164. $this->assertEquals((string)$response['group'], 'Jazz Club');
  165. }
  166. public function testWeeklyAlbumChartList()
  167. {
  168. $testing_response = $this->header .
  169. '<?xml version="1.0" encoding="UTF-8"?>
  170. <weeklyalbumchart group="Jazz Club" from="1172404800" to="1173009600">
  171. <album>
  172. <artist mbid="561d854a-6a28-4aa7-8c99-323e6ce46c2a">Miles Davis</artist>
  173. <name>Kind of Blue</name>
  174. <mbid>bee5e0cd-1767-4a8e-9578-6455e87ba60b</mbid>
  175. <chartposition>1</chartposition>
  176. <reach>56</reach>
  177. <url>http://www.last.fm/music/Miles+Davis/Kind+of+Blue</url>
  178. </album>
  179. <album>
  180. <artist mbid="a74b1b7f-71a5-4011-9441-d0b5e4122711">Radiohead</artist>
  181. <name>OK Computer</name>
  182. <mbid>fba5f8fe-c6c8-4511-8562-c9febf482674</mbid>
  183. <chartposition>2</chartposition>
  184. <reach>42</reach>
  185. <url>http://www.last.fm/music/Radiohead/OK+Computer</url>
  186. </album>
  187. <album>
  188. <artist mbid="8f6bd1e4-fbe1-4f50-aa9b-94c450ec0f11">Portishead</artist>
  189. <name>Dummy</name>
  190. <mbid>87888070-1b25-4830-aebc-dee490058b74</mbid>
  191. <chartposition>3</chartposition>
  192. <reach>37</reach>
  193. <url>http://www.last.fm/music/Portishead/Dummy</url>
  194. </album>
  195. <album>
  196. <artist mbid="">The Arcade Fire</artist>
  197. <name>Funeral</name>
  198. <mbid></mbid>
  199. <chartposition>3</chartposition>
  200. <reach>37</reach>
  201. <url>http://www.last.fm/music/The+Arcade+Fire/Funeral</url>
  202. </album>
  203. <album>
  204. <artist mbid="cc197bad-dc9c-440d-a5b5-d52ba2e14234">Coldplay</artist>
  205. <name>A Rush of Blood to the Head</name>
  206. <mbid>b83b32dd-aa1a-4f18-a5af-00e418041617</mbid>
  207. <chartposition>5</chartposition>
  208. <reach>34</reach>
  209. <url>http://www.last.fm/music/Coldplay/A+Rush+of+Blood+to+the+Head</url>
  210. </album>
  211. <album>
  212. <artist mbid="b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d">The Beatles</artist>
  213. <name>Abbey Road</name>
  214. <mbid>03503af3-a0e0-4f7e-8a0d-a1cd4d7225c5</mbid>
  215. <chartposition>6</chartposition>
  216. <reach>32</reach>
  217. <url>http://www.last.fm/music/The+Beatles/Abbey+Road</url>
  218. </album>
  219. <album>
  220. <artist mbid="b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d">The Beatles</artist>
  221. <name>Rubber Soul</name>
  222. <mbid>34b8cb33-5f91-4e0c-b4ec-3fb2d3f2f926</mbid>
  223. <chartposition>6</chartposition>
  224. <reach>32</reach>
  225. <url>http://www.last.fm/music/The+Beatles/Rubber+Soul</url>
  226. </album>
  227. <album>
  228. <artist mbid="10adbe5e-a2c0-4bf3-8249-2b4cbf6e6ca8">Massive Attack</artist>
  229. <name>Mezzanine</name>
  230. <mbid>0d33ef7a-1f5d-4365-b807-b412271b99c3</mbid>
  231. <chartposition>8</chartposition>
  232. <reach>31</reach>
  233. <url>http://www.last.fm/music/Massive+Attack/Mezzanine</url>
  234. </album>
  235. <album>
  236. <artist mbid="cc197bad-dc9c-440d-a5b5-d52ba2e14234">Coldplay</artist>
  237. <name>Parachutes</name>
  238. <mbid>8fb50f96-279e-4d44-92aa-d49ea56f5c08</mbid>
  239. <chartposition>8</chartposition>
  240. <reach>31</reach>
  241. <url>http://www.last.fm/music/Coldplay/Parachutes</url>
  242. </album>
  243. <album>
  244. <artist mbid="">Gnarls Barkley</artist>
  245. <name>St. Elsewhere</name>
  246. <mbid></mbid>
  247. <chartposition>8</chartposition>
  248. <reach>31</reach>
  249. <url>http://www.last.fm/music/Gnarls+Barkley/St.+Elsewhere</url>
  250. </album>
  251. </weeklyalbumchart>
  252. ';
  253. $this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
  254. $as->set('group', urlencode('Jazz Club'));
  255. $response = $as->groupGetWeeklyAlbumChartList();
  256. $this->assertNotNull(count($response));
  257. $album = $response->album[0];
  258. $this->assertEquals((string)$album->artist, 'Miles Davis');
  259. $this->assertEquals((string)$album->name, 'Kind of Blue');
  260. $this->assertEquals((string)$album->chartposition, 1);
  261. $this->assertEquals((string)$response['group'], 'Jazz Club');
  262. }
  263. public function testPreviousWeeklyChartList()
  264. {
  265. $testing_response = $this->header .
  266. '<?xml version="1.0" encoding="UTF-8"?>
  267. <weeklyartistchart group="Jazz Club" from="1114965332" to="1115570132">
  268. </weeklyartistchart>
  269. ';
  270. $this->setAudioscrobblerResponse($testing_response);
  271. $as = $this->getAudioscrobblerService();
  272. $as->set('group', urlencode('Jazz Club'));
  273. $from = 1114965332;
  274. $to = 1115570132;
  275. $response = $as->groupGetWeeklyChartList($from, $to);
  276. $this->assertNotNull(count($response));
  277. $this->assertEquals((string)$response['group'], 'Jazz Club');
  278. $this->assertEquals((int)$response['from'], $from);
  279. $this->assertEquals((int)$response['to'], $to);
  280. }
  281. }