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
|
|
|
|
$this->assertSame($album->id, $gottenAlbum->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @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
|
|
|
|
$this->assertNull(Album::whereArtistIdAndName($artist->id, $name)->first());
|
|
|
|
|
|
|
|
// When I try to get the album by such artist and name
|
|
|
|
$album = Album::get($artist, $name);
|
|
|
|
|
|
|
|
// Then I get the new album
|
|
|
|
$this->assertNotNull($album);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @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"
|
|
|
|
$this->assertEquals('Unknown Album', $album->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @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
|
|
|
|
$this->assertTrue($album->artist->is_various);
|
|
|
|
}
|
|
|
|
}
|