assertNotNull($response);
}
public function testGetProfileInfo()
{
$test_response = "HTTP/1.1 200 OK\r\n" .
"Content-type: text/xml\r\n" .
"\r\n" .
'
http://www.last.fm/user/RJ/
Richard Jones
1b374543545e01bc8d555a6a57c637f61f999fdf
Nov 20, 2002
24
m
United Kingdom
45043
http://static.last.fm/avatar/0f4bda3a8e49e714c26ef610e2893454.jpg
';
$this->setAudioscrobblerResponse($test_response);
$as = $this->getAudioscrobblerService();
$as->set('user', 'RJ');
$response = $as->userGetProfileInformation();
$this->assertNotNull($response);
}
public function testGetBadProfileInfo()
{
$this->markTestSkipped('Invalid test, communicating with the outside world!');
$as = new Zend_Service_Audioscrobbler();
$as->set('user', 'kljadsfjllkj');
try {
$response = $as->userGetProfileInformation();
$this->assertNull($response);
} catch (Exception $e) {
return;
}
$this->fail('Exception was not thrown when submitting bad user info');
}
public function testUserGetTopArtists( )
{
$test_response = "HTTP/1.1 200 OK\r\n" .
"Content-type: text/xml\r\n" .
"\r\n" .
'
Dream Theater
28503ab7-8bf2-4666-a7bd-2644bfc7cb1d
854
1
http://www.last.fm/music/Dream+Theater
http://static.last.fm/proposedimages/thumbnail/6/4209/432600.jpg
http://static.last.fm/proposedimages/sidebar/6/4209/432600.jpg
';
$this->setAudioscrobblerResponse($test_response); $as = $this->getAudioscrobblerService();
$as->set('user', 'RJ');
$response = $as->userGetTopArtists();
$artist = $response->artist[0];
$this->assertEquals((string)$response['user'], 'RJ');
$this->assertEquals((string)$artist->name, 'Dream Theater');
$this->assertNotNull($artist->rank, 1);
}
public function testUserGetTopAlbums( )
{
$testing_response = "HTTP/1.1 200 OK\r\n" .
"Content-type: text/xml\r\n" .
"\r\n" .
'
Hot Chip
The Warning
227
1
http://www.last.fm/music/Hot+Chip/The+Warning
http://images.amazon.com/images/P/B000FBFSVU.01._SCMZZZZZZZ_.jpg
http://images.amazon.com/images/P/B000FBFSVU.01._SCMZZZZZZZ_.jpg
http://images.amazon.com/images/P/B000FBFSVU.01._SCMZZZZZZZ_.jpg
';
$this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
$as->set('user', 'Frith');
$response = $as->userGetTopAlbums();
$album = $response->album[0];
$this->assertEquals((string)$response['user'], 'Frith');
$this->assertNotNull($album);
$this->assertEquals((string)$album->name, 'The Warning');
}
public function testUserGetTopTracks( )
{
$testing_response = "HTTP/1.1 200 OK\r\n" .
"Content-type: text/xml\r\n" .
"\r\n" .
'
';
$this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
$as->set('user', 'RJ');
$response = $as->userGetTopTracks();
$track = $response->track[0];
$this->assertEquals((string)$response['user'], 'RJ');
$this->assertNotNull($track);
$this->assertEquals((string)$track->artist, 'Steppenwolf');
$this->assertEquals((int)$track->playcount, 31);
}
public function testUserGetTopTags( )
{
$testing_response = "HTTP/1.1 200 OK\r\n" .
"Content-type: text/xml\r\n" .
"\r\n" .
'
rock
9
http://www.last.fm/tag/rock
metal
8
http://www.last.fm/tag/metal
mellow
5
http://www.last.fm/tag/mellow
';
$this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
$as->set('user', 'RJ');
$response = $as->userGetTopTags();
$tag = $response->tag[1];
$this->assertEquals((string)$response['user'], 'RJ');
$this->assertNotNull($tag);
$this->assertEquals((string)$tag->name, 'metal');
$this->assertEquals((int)$tag->count, 8);
}
public function testUserGetTopTagsForArtist()
{
$testing_response = "HTTP/1.1 200 OK\r\n" .
"Content-type: text/xml\r\n" .
"\r\n" .
'
metal
1
http://www.last.fm/tag/metal
80s
1
http://www.last.fm/tag/80s
';
$this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
$as->set('user', 'RJ');
$as->set('artist', 'Metallica');
$response = $as->userGetTopTagsForArtist();
$tag = $response->tag[0];
$this->assertEquals((string)$response['user'], 'RJ');
$this->assertEquals((string)$response['artist'], 'Metallica');
$this->assertNotNull($tag);
}
/**
* Ensures that userGetTopTagsForArtist() throws an exception when based on bad parameters
*
* @return void
*/
public function testBadUserGetTopTagsForArtist()
{
$testingResponse = "HTTP/1.1 200 OK\r\n"
. "Content-type: text/xml\r\n"
. "\r\n"
. "ERROR: Missing 'subject' parameter in querystring";
$this->setAudioscrobblerResponse($testingResponse);
$as = $this->getAudioscrobblerService();
try {
$response = $as->userGetTopTagsForArtist();
$this->fail('userGetTopTagsForArtist() did not throw exception based on bad parameters');
} catch (Zend_Service_Exception $e) {
$this->assertContains('SimpleXML', $e->getMessage());
}
}
public function testUserGetTopTagsForAlbum()
{
$testing_response = "HTTP/1.1 200 OK\r\n" .
"Content-type: text/xml\r\n" .
"\r\n" .
'
';
$this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
$as->set('user', 'RJ');
$as->set('artist', 'Metallica');
$as->set('album', 'Ride The Lightning');
$response = $as->userGetTopTagsForAlbum();
$this->assertEquals((string)$response['user'], 'RJ');
$this->assertEquals((string)strtolower($response['artist']), strtolower('Metallica'));
$this->assertEquals((string)strtolower($response['album']), strtolower('Ride The Lightning'));
}
public function testUserGetTopTagsForTrack()
{
$testing_response = "HTTP/1.1 200 OK\r\n" .
"Content-type: text/xml\r\n" .
"\r\n" .
'
';
$this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
$as->set('user', 'RJ');
$as->set('artist', 'Metallica');
$as->set('track', 'Nothing Else Matters');
$response = $as->userGetTopTagsForTrack();
$this->assertEquals((string)$response['user'], 'RJ');
$this->assertEquals((string)$response['artist'], 'Metallica');
$this->assertEquals((string)$response['track'], 'Nothing Else Matters');
}
public function testUserGetFriends()
{
$testing_response = "HTTP/1.1 200 OK\r\n" .
"Content-type: text/xml\r\n" .
"\r\n" .
'
http://www.last.fm/user/julians/
http://static.last.fm/avatar/9ca899b8f20b7173d47983cc0533be8c.gif
http://www.last.fm/user/Korean_Cowboy/
http://static.last.fm/avatar/091614ec2288764362c94f047d207336.jpg
';
$this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
$as->set('user', 'RJ');
$response = $as->userGetFriends();
$this->assertEquals((string)$response['user'], 'RJ');
$this->assertEquals(count($response->user), 2);
}
public function testUserGetNeighbours()
{
$testing_response = "HTTP/1.1 200 OK\r\n" .
"Content-type: text/xml\r\n" .
"\r\n" .
'
http://www.last.fm/user/count-bassy/
http://static.last.fm/avatar/3da65e2f347f64c033c9eced171e7a21.gif
100
http://www.last.fm/user/arcymarcy/
http://static.last.fm/avatar/eed7d6afea225f85cfcd6ee61eac19aa.jpg
93.12
';
$this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
$as->set('user', 'RJ');
$response = $as->userGetNeighbours();
$this->assertEquals((string)$response['user'], 'RJ');
$this->assertEquals(count($response->user), 2);
$user = $response->user[1];
$this->assertEquals((string)$user['username'], 'arcymarcy');
}
public function testUserRecentTracks()
{
$testing_response = "HTTP/1.1 200 OK\r\n" .
"Content-type: text/xml\r\n" .
"\r\n" .
'
';
$this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
$as->set('user', 'RJ');
$response = $as->userGetRecentTracks();
$track = $response->track[0];
$this->assertEquals((string)$response['user'], 'RJ');
$this->assertEquals(count($response->track), 2);
$this->assertEquals((string)$track->name, 'Always An Excuse');
}
public function testUserRecentBannedTracks()
{
$testing_response = "HTTP/1.1 200 OK\r\nContent-type: text/xml\r\n\r\n" .
'
';
$this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
$as->set('user', 'RJ');
$response = $as->userGetRecentBannedTracks();
$track = $response->track[0];
$this->assertEquals((string)$response['user'], 'RJ');
$this->assertEquals(count($response->track), 2);
$this->assertEquals((string)$track->artist, 'Herbie Hancock');
$this->assertEquals((string)$track->name, 'Rockit');
}
public function testUserRecentLovedTracks()
{
$testing_response = "HTTP/1.1 200 OK\r\nContent-type: text/xml\r\n\r\n" .
'
';
$this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
$as->set('user', 'RJ');
$response = $as->userGetRecentLovedTracks();
$track = $response->track[1];
$this->assertEquals((string)$response['user'], 'RJ');
$this->assertNotNull((string)$track->name, 'Morning Dance');
$this->assertNotNull((string)$track->date, '31 Oct 2006, 15:53');
$this->assertNotNull($response->track);
}
public function testUserGetWeeklyChartList()
{
$testing_response = "HTTP/1.1 200 OK\r\nContent-type: text/xml\r\n\r\n" .
'
';
$this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
$as->set('user', 'RJ');
$response = $as->userGetWeeklyChartList();
$chart = $response->chart[0];
$this->assertEquals((string)$response['user'], 'RJ');
$this->assertEquals(count($response->chart), 7);
$this->assertEquals((string)$chart['from'], '1108296002');
$this->assertEquals((string)$chart['to'], '1108900802');
}
public function testUserGetRecentWeeklyArtistChart()
{
$testing_response = "HTTP/1.1 200 OK\r\nContent-type: text/xml\r\n\r\n" .
'
Miles Davis
561d854a-6a28-4aa7-8c99-323e6ce46c2a
1
30
http://www.last.fm/music/Miles+Davis
Guano Apes
66da25f9-1534-4dd1-b88c-718bc24e1ccd
2
28
http://www.last.fm/music/Guano+Apes
';
$this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
$as->set('user', 'RJ');
$response = $as->userGetWeeklyArtistChart();
$this->assertEquals((string)$response['user'], 'RJ');
$this->assertNotNull($response->weeklyartistchart);
$this->assertNotNull($response->artist);
}
public function testUserGetWeeklyAlbumChart()
{
$testing_response = "HTTP/1.1 200 OK\r\nContent-type: text/xml\r\n\r\n" .
'
Skid Row
Slave To The Grid
1
12
http://www.last.fm/music/Skid+Row/Slave+To+The+Grid
Guano Apes
Walking on a Thin Line
769a46de-52e2-4322-9db0-cbd6b789e3f8
1
12
http://www.last.fm/music/Guano+Apes/Walking+on+a+Thin+Line
';
$this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
$as->set('user', 'RJ');
$response = $as->userGetWeeklyAlbumChart();
$album = $response->album[0];
$this->assertEquals((string)$response['user'], 'RJ');
$this->assertEquals(count($response->album), 2);
$this->assertEquals((string)$album->artist, 'Skid Row');
$this->assertEquals((string)$album->name, 'Slave To The Grid');
}
public function testUserGetPreviousWeeklyArtistChart()
{
$testing_response = "HTTP/1.1 200 OK\r\nContent-type: text/xml\r\n\r\n" .
'
Nine Inch Nails
b7ffd2af-418f-4be2-bdd1-22f8b48613da
1
23
http://www.last.fm/music/Nine+Inch+Nails
The Doors
9efff43b-3b29-4082-824e-bc82f646f93d
2
3
http://www.last.fm/music/The+Doors
';
$this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
$as->set('user', 'RJ');
$from = 1114965332;
$to = 1115570132;
$response = $as->userGetWeeklyArtistChart($from, $to);
$artist = $response->artist[0];
$this->assertEquals((string)$response['user'], 'RJ');
$this->assertEquals((int)$response['from'], $from);
$this->assertEquals((int)$response['to'], $to);
$this->assertEquals((string)$artist->name, 'Nine Inch Nails');
$this->assertEquals(count($response->artist), 2);
}
public function testUserGetPreviousWeeklyAlbumChart()
{
$testing_response = "HTTP/1.1 200 OK\r\nContent-type: text/xml\r\n\r\n" .
'
The Doors
The Doors Box Set
1
2
http://www.last.fm/music/The+Doors/The+Doors+Box+Set
Nirvana
Nirvana
d8f9547d-5e46-45f0-b694-0d9af9e2de63
1
2
http://www.last.fm/music/Nirvana/Nirvana
';
$this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
$as->set('user', 'RJ');
$from = 1114965332;
$to = 1115570132;
$response = $as->userGetWeeklyAlbumChart($from, $to);
$album = $response->album[0];
$this->assertEquals((string)$response['user'], 'RJ');
$this->assertEquals((int)$response['from'], 1114965332);
$this->assertEquals((int)$response['to'], 1115570132);
$this->assertEquals(count($response->album), 2);
}
public function testUserGetPreviousWeeklyTrackChart()
{
$testing_response = "HTTP/1.1 200 OK\r\nContent-type: text/xml\r\n\r\n" .
'
';
$this->setAudioscrobblerResponse($testing_response); $as = $this->getAudioscrobblerService();
$as->set('user', 'RJ');
$from = 1114965332;
$to = 1115570132;
$response = $as->userGetWeeklyTrackChart($from, $to);
$track = $response->track[0];
$this->assertEquals((string)$response['user'], 'RJ');
$this->assertEquals((int)$response['from'], $from);
$this->assertEquals((int)$response['to'], $to);
$this->assertEquals((string)$track->artist, 'The Kleptones');
$this->assertEquals(count($response->track), 2);
}
}