2016-06-04 16:56:38 +00:00
|
|
|
<?php
|
|
|
|
|
2017-02-14 06:53:02 +00:00
|
|
|
namespace Tests\Feature;
|
|
|
|
|
2016-06-04 16:56:38 +00:00
|
|
|
use App\Models\Album;
|
|
|
|
use App\Models\Artist;
|
|
|
|
use App\Models\Playlist;
|
|
|
|
use App\Models\Song;
|
|
|
|
use App\Models\User;
|
2017-02-14 06:53:02 +00:00
|
|
|
use Download;
|
2016-06-04 16:56:38 +00:00
|
|
|
|
2017-08-05 16:56:11 +00:00
|
|
|
class DownloadTest extends TestCase
|
2016-06-04 16:56:38 +00:00
|
|
|
{
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$this->createSampleMediaSet();
|
|
|
|
}
|
|
|
|
|
2017-08-05 18:55:02 +00:00
|
|
|
/** @test */
|
|
|
|
public function a_single_song_can_be_downloaded()
|
2016-06-04 16:56:38 +00:00
|
|
|
{
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2017-08-05 18:55:02 +00:00
|
|
|
/** @test */
|
|
|
|
public function multiple_songs_can_be_downloaded()
|
2016-06-04 16:56:38 +00:00
|
|
|
{
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2017-08-05 18:55:02 +00:00
|
|
|
/** @test */
|
|
|
|
public function a_whole_album_can_be_downloaded()
|
2016-06-04 16:56:38 +00:00
|
|
|
{
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2017-08-05 18:55:02 +00:00
|
|
|
/** @test */
|
|
|
|
public function a_whole_artists_biography_can_be_downloaded()
|
2016-06-04 16:56:38 +00:00
|
|
|
{
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2017-08-05 18:55:02 +00:00
|
|
|
/** @test */
|
|
|
|
public function a_whole_playlist_can_be_downloaded()
|
2016-06-04 16:56:38 +00:00
|
|
|
{
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2017-08-05 18:55:02 +00:00
|
|
|
/** @test */
|
|
|
|
public function all_favorite_songs_can_be_downloaded()
|
2016-06-04 16:56:38 +00:00
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
}
|