2016-06-04 16:56:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use App\Models\Album;
|
|
|
|
use App\Models\Artist;
|
|
|
|
use App\Models\Playlist;
|
|
|
|
use App\Models\Song;
|
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
|
|
|
|
class DownloadTest extends TestCase
|
|
|
|
{
|
2016-09-26 06:30:00 +00:00
|
|
|
use DatabaseTransactions;
|
2016-06-04 16:56:38 +00:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$this->createSampleMediaSet();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOneSong()
|
|
|
|
{
|
|
|
|
$song = Song::first();
|
2016-11-24 04:07:57 +00:00
|
|
|
Download::shouldReceive('from')
|
2016-06-04 16:56:38 +00:00
|
|
|
->once()
|
|
|
|
->andReturn($this->mediaPath.'/blank.mp3');
|
|
|
|
|
2016-09-26 06:30:00 +00:00
|
|
|
$this->getAsUser("api/download/songs?songs[]={$song->id}")
|
2016-06-04 16:56:38 +00:00
|
|
|
->seeStatusCode(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMultipleSongs()
|
|
|
|
{
|
|
|
|
$songs = Song::take(2)->get();
|
2016-11-24 04:07:57 +00:00
|
|
|
Download::shouldReceive('from')
|
2016-06-04 16:56:38 +00:00
|
|
|
->once()
|
|
|
|
->andReturn($this->mediaPath.'/blank.mp3'); // should be a zip file, but we're testing here…
|
|
|
|
|
2016-09-26 06:30:00 +00:00
|
|
|
$this->getAsUser("api/download/songs?songs[]={$songs[0]->id}&songs[]={$songs[1]->id}")
|
2016-06-04 16:56:38 +00:00
|
|
|
->seeStatusCode(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAlbum()
|
|
|
|
{
|
|
|
|
$album = Album::first();
|
|
|
|
|
2016-11-24 04:07:57 +00:00
|
|
|
Download::shouldReceive('from')
|
2016-06-04 16:56:38 +00:00
|
|
|
->once()
|
|
|
|
->andReturn($this->mediaPath.'/blank.mp3');
|
|
|
|
|
2016-09-26 06:30:00 +00:00
|
|
|
$this->getAsUser("api/download/album/{$album->id}")
|
2016-06-04 16:56:38 +00:00
|
|
|
->seeStatusCode(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testArtist()
|
|
|
|
{
|
|
|
|
$artist = Artist::first();
|
|
|
|
|
2016-11-24 04:07:57 +00:00
|
|
|
Download::shouldReceive('from')
|
2016-06-04 16:56:38 +00:00
|
|
|
->once()
|
|
|
|
->andReturn($this->mediaPath.'/blank.mp3');
|
|
|
|
|
2016-09-26 06:30:00 +00:00
|
|
|
$this->getAsUser("api/download/artist/{$artist->id}")
|
2016-06-04 16:56:38 +00:00
|
|
|
->seeStatusCode(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPlaylist()
|
|
|
|
{
|
|
|
|
$user = factory(User::class)->create();
|
|
|
|
|
|
|
|
$playlist = factory(Playlist::class)->create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
]);
|
|
|
|
|
2016-09-26 06:30:00 +00:00
|
|
|
$this->getAsUser("api/download/playlist/{$playlist->id}")
|
2016-06-04 16:56:38 +00:00
|
|
|
->seeStatusCode(403);
|
|
|
|
|
2016-11-24 04:07:57 +00:00
|
|
|
Download::shouldReceive('from')
|
2016-06-04 16:56:38 +00:00
|
|
|
->once()
|
|
|
|
->andReturn($this->mediaPath.'/blank.mp3');
|
|
|
|
|
2016-09-26 06:30:00 +00:00
|
|
|
$this->getAsUser("api/download/playlist/{$playlist->id}", $user)
|
2016-06-04 16:56:38 +00:00
|
|
|
->seeStatusCode(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFavorites()
|
|
|
|
{
|
2016-11-24 04:07:57 +00:00
|
|
|
Download::shouldReceive('from')
|
2016-06-04 16:56:38 +00:00
|
|
|
->once()
|
|
|
|
->andReturn($this->mediaPath.'/blank.mp3');
|
|
|
|
|
2016-09-26 06:30:00 +00:00
|
|
|
$this->getAsUser('api/download/favorites')
|
2016-06-04 16:56:38 +00:00
|
|
|
->seeStatusCode(200);
|
|
|
|
}
|
|
|
|
}
|