GroupTest.php 10 KB

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