2017-06-10 00:40:44 +00:00
|
|
|
<?php
|
|
|
|
|
2017-12-09 22:39:34 +00:00
|
|
|
namespace Tests\Integration\Models;
|
2017-06-10 00:40:44 +00:00
|
|
|
|
|
|
|
use App\Models\Album;
|
|
|
|
use App\Models\Artist;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class AlbumTest extends TestCase
|
|
|
|
{
|
|
|
|
/** @test */
|
|
|
|
public function exist_album_can_be_retrieved_using_artist_and_name()
|
|
|
|
{
|
2017-12-03 22:31:53 +00:00
|
|
|
// Given there's an existing album from an artist
|
2017-06-10 15:09:56 +00:00
|
|
|
/** @var Artist $artist */
|
2017-06-10 00:40:44 +00:00
|
|
|
$artist = factory(Artist::class)->create();
|
2017-06-10 15:09:56 +00:00
|
|
|
/** @var Album $album */
|
2017-06-10 00:40:44 +00:00
|
|
|
$album = factory(Album::class)->create([
|
|
|
|
'artist_id' => $artist->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
// When I try to get the album by artist and name
|
|
|
|
$gottenAlbum = Album::get($artist, $album->name);
|
|
|
|
|
|
|
|
// Then I get the album
|
2020-09-06 18:21:39 +00:00
|
|
|
self::assertSame($album->id, $gottenAlbum->id);
|
2017-06-10 00:40:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
public function new_album_can_be_created_using_artist_and_name()
|
|
|
|
{
|
|
|
|
// Given an artist and an album name
|
|
|
|
$artist = factory(Artist::class)->create();
|
|
|
|
$name = 'Foo';
|
|
|
|
|
|
|
|
// And an album with such details doesn't exist yet
|
2020-09-06 18:21:39 +00:00
|
|
|
self::assertNull(Album::whereArtistIdAndName($artist->id, $name)->first());
|
2017-06-10 00:40:44 +00:00
|
|
|
|
|
|
|
// When I try to get the album by such artist and name
|
|
|
|
$album = Album::get($artist, $name);
|
|
|
|
|
|
|
|
// Then I get the new album
|
2020-09-06 18:21:39 +00:00
|
|
|
self::assertNotNull($album);
|
2017-06-10 00:40:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
public function new_album_without_a_name_is_created_as_unknown_album()
|
|
|
|
{
|
|
|
|
// Given an album without a name
|
|
|
|
$name = '';
|
|
|
|
|
|
|
|
// When we create such an album
|
|
|
|
$album = Album::get(factory(Artist::class)->create(), $name);
|
|
|
|
|
|
|
|
// Then the album's name is "Unknown Album"
|
2020-09-06 18:21:39 +00:00
|
|
|
self::assertEquals('Unknown Album', $album->name);
|
2017-06-10 00:40:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
public function new_album_is_created_with_artist_as_various_if_is_compilation_flag_is_true()
|
|
|
|
{
|
|
|
|
// Given we create a new album with $isCompilation flag set to TRUE
|
|
|
|
$isCompilation = true;
|
|
|
|
|
|
|
|
// When the album is created
|
|
|
|
$album = Album::get(factory(Artist::class)->create(), 'Foo', $isCompilation);
|
|
|
|
|
|
|
|
// Then its artist is Various Artist
|
2020-09-06 18:21:39 +00:00
|
|
|
self::assertTrue($album->artist->is_various);
|
2017-06-10 00:40:44 +00:00
|
|
|
}
|
|
|
|
}
|