GroupTest.php 10 KB

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