2016-06-05 00:56:38 +08:00
|
|
|
<?php
|
|
|
|
|
2017-02-14 14:53:02 +08:00
|
|
|
namespace Tests\Feature;
|
|
|
|
|
2016-06-05 00:56:38 +08:00
|
|
|
use App\Models\Album;
|
|
|
|
use App\Models\Artist;
|
|
|
|
use App\Models\Playlist;
|
|
|
|
use App\Models\Song;
|
|
|
|
use App\Models\User;
|
2018-08-18 14:27:17 +02:00
|
|
|
use App\Services\DownloadService;
|
2018-08-18 13:51:52 +02:00
|
|
|
use Mockery\MockInterface;
|
2016-06-05 00:56:38 +08:00
|
|
|
|
2017-08-05 17:56:11 +01:00
|
|
|
class DownloadTest extends TestCase
|
2016-06-05 00:56:38 +08:00
|
|
|
{
|
2018-08-18 13:51:52 +02:00
|
|
|
/**
|
2018-08-18 14:27:17 +02:00
|
|
|
* @var MockInterface|DownloadService
|
2018-08-18 13:51:52 +02:00
|
|
|
*/
|
|
|
|
private $downloadService;
|
|
|
|
|
2016-06-05 00:56:38 +08:00
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$this->createSampleMediaSet();
|
2018-08-18 14:27:17 +02:00
|
|
|
$this->downloadService = $this->mockIocDependency(DownloadService::class);
|
2016-06-05 00:56:38 +08:00
|
|
|
}
|
|
|
|
|
2017-08-05 19:55:02 +01:00
|
|
|
/** @test */
|
|
|
|
public function a_single_song_can_be_downloaded()
|
2016-06-05 00:56:38 +08:00
|
|
|
{
|
|
|
|
$song = Song::first();
|
2018-08-18 13:51:52 +02:00
|
|
|
$this->downloadService
|
|
|
|
->shouldReceive('from')
|
2016-06-05 00:56:38 +08:00
|
|
|
->once()
|
|
|
|
->andReturn($this->mediaPath.'/blank.mp3');
|
|
|
|
|
2016-09-26 14:30:00 +08:00
|
|
|
$this->getAsUser("api/download/songs?songs[]={$song->id}")
|
2018-08-18 13:51:52 +02:00
|
|
|
->assertResponseOk();
|
2016-06-05 00:56:38 +08:00
|
|
|
}
|
|
|
|
|
2017-08-05 19:55:02 +01:00
|
|
|
/** @test */
|
|
|
|
public function multiple_songs_can_be_downloaded()
|
2016-06-05 00:56:38 +08:00
|
|
|
{
|
|
|
|
$songs = Song::take(2)->get();
|
2018-08-18 13:51:52 +02:00
|
|
|
|
|
|
|
$this->downloadService
|
|
|
|
->shouldReceive('from')
|
2016-06-05 00:56:38 +08:00
|
|
|
->once()
|
|
|
|
->andReturn($this->mediaPath.'/blank.mp3'); // should be a zip file, but we're testing here…
|
|
|
|
|
2016-09-26 14:30:00 +08:00
|
|
|
$this->getAsUser("api/download/songs?songs[]={$songs[0]->id}&songs[]={$songs[1]->id}")
|
2018-08-18 13:51:52 +02:00
|
|
|
->assertResponseOk();
|
2016-06-05 00:56:38 +08:00
|
|
|
}
|
|
|
|
|
2017-08-05 19:55:02 +01:00
|
|
|
/** @test */
|
|
|
|
public function a_whole_album_can_be_downloaded()
|
2016-06-05 00:56:38 +08:00
|
|
|
{
|
|
|
|
$album = Album::first();
|
|
|
|
|
2018-08-18 13:51:52 +02:00
|
|
|
$this->downloadService
|
|
|
|
->shouldReceive('from')
|
2016-06-05 00:56:38 +08:00
|
|
|
->once()
|
|
|
|
->andReturn($this->mediaPath.'/blank.mp3');
|
|
|
|
|
2016-09-26 14:30:00 +08:00
|
|
|
$this->getAsUser("api/download/album/{$album->id}")
|
2018-08-18 13:51:52 +02:00
|
|
|
->assertResponseOk();
|
2016-06-05 00:56:38 +08:00
|
|
|
}
|
|
|
|
|
2017-08-05 19:55:02 +01:00
|
|
|
/** @test */
|
|
|
|
public function a_whole_artists_biography_can_be_downloaded()
|
2016-06-05 00:56:38 +08:00
|
|
|
{
|
|
|
|
$artist = Artist::first();
|
|
|
|
|
2018-08-18 13:51:52 +02:00
|
|
|
$this->downloadService
|
|
|
|
->shouldReceive('from')
|
2016-06-05 00:56:38 +08:00
|
|
|
->once()
|
|
|
|
->andReturn($this->mediaPath.'/blank.mp3');
|
|
|
|
|
2016-09-26 14:30:00 +08:00
|
|
|
$this->getAsUser("api/download/artist/{$artist->id}")
|
2018-08-18 13:51:52 +02:00
|
|
|
->assertResponseOk();
|
2016-06-05 00:56:38 +08:00
|
|
|
}
|
|
|
|
|
2017-08-05 19:55:02 +01:00
|
|
|
/** @test */
|
|
|
|
public function a_whole_playlist_can_be_downloaded()
|
2016-06-05 00:56:38 +08:00
|
|
|
{
|
|
|
|
$user = factory(User::class)->create();
|
|
|
|
|
|
|
|
$playlist = factory(Playlist::class)->create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
]);
|
|
|
|
|
2016-09-26 14:30:00 +08:00
|
|
|
$this->getAsUser("api/download/playlist/{$playlist->id}")
|
2018-08-18 13:51:52 +02:00
|
|
|
->assertResponseStatus(403);
|
2016-06-05 00:56:38 +08:00
|
|
|
|
2018-08-18 13:51:52 +02:00
|
|
|
$this->downloadService
|
|
|
|
->shouldReceive('from')
|
2016-06-05 00:56:38 +08:00
|
|
|
->once()
|
|
|
|
->andReturn($this->mediaPath.'/blank.mp3');
|
|
|
|
|
2016-09-26 14:30:00 +08:00
|
|
|
$this->getAsUser("api/download/playlist/{$playlist->id}", $user)
|
2018-08-18 13:51:52 +02:00
|
|
|
->assertResponseOk();
|
2016-06-05 00:56:38 +08:00
|
|
|
}
|
|
|
|
|
2017-08-05 19:55:02 +01:00
|
|
|
/** @test */
|
|
|
|
public function all_favorite_songs_can_be_downloaded()
|
2016-06-05 00:56:38 +08:00
|
|
|
{
|
2018-08-18 13:51:52 +02:00
|
|
|
$this->downloadService
|
|
|
|
->shouldReceive('from')
|
2016-06-05 00:56:38 +08:00
|
|
|
->once()
|
|
|
|
->andReturn($this->mediaPath.'/blank.mp3');
|
|
|
|
|
2016-09-26 14:30:00 +08:00
|
|
|
$this->getAsUser('api/download/favorites')
|
2016-06-05 00:56:38 +08:00
|
|
|
->seeStatusCode(200);
|
|
|
|
}
|
|
|
|
}
|