2017-06-10 01:40:44 +01:00
|
|
|
<?php
|
|
|
|
|
2017-12-09 23:39:34 +01:00
|
|
|
namespace Tests\Integration\Models;
|
2017-06-10 01:40:44 +01:00
|
|
|
|
|
|
|
use App\Models\Album;
|
|
|
|
use App\Models\Artist;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class AlbumTest extends TestCase
|
|
|
|
{
|
2020-11-14 17:57:25 +01:00
|
|
|
public function testExistingAlbumCanBeRetrievedUsingArtistAndName(): void
|
2017-06-10 01:40:44 +01:00
|
|
|
{
|
2017-06-10 16:09:56 +01:00
|
|
|
/** @var Album $album */
|
2020-11-14 17:57:25 +01:00
|
|
|
$album = Album::factory()->create();
|
2017-06-10 01:40:44 +01:00
|
|
|
|
2020-11-14 17:57:25 +01:00
|
|
|
self::assertTrue(Album::getOrCreate($album->artist, $album->name)->is($album));
|
2017-06-10 01:40:44 +01:00
|
|
|
}
|
|
|
|
|
2020-11-14 17:57:25 +01:00
|
|
|
public function testNewAlbumIsAutomaticallyCreatedWithArtistAndName(): void
|
2017-06-10 01:40:44 +01:00
|
|
|
{
|
2020-11-14 17:57:25 +01:00
|
|
|
/** @var Artist $artist */
|
|
|
|
$artist = Artist::factory()->create();
|
2017-06-10 01:40:44 +01:00
|
|
|
$name = 'Foo';
|
|
|
|
|
2020-09-06 20:21:39 +02:00
|
|
|
self::assertNull(Album::whereArtistIdAndName($artist->id, $name)->first());
|
2017-06-10 01:40:44 +01:00
|
|
|
|
2020-11-14 17:57:25 +01:00
|
|
|
$album = Album::getOrCreate($artist, $name);
|
|
|
|
self::assertSame('Foo', $album->name);
|
|
|
|
self::assertTrue($album->artist->is($artist));
|
2017-06-10 01:40:44 +01:00
|
|
|
}
|
|
|
|
|
2020-11-14 17:57:25 +01:00
|
|
|
public function provideEmptyAlbumNames(): array
|
2017-06-10 01:40:44 +01:00
|
|
|
{
|
2020-11-14 17:57:25 +01:00
|
|
|
return [
|
|
|
|
[''],
|
|
|
|
[' '],
|
|
|
|
[null],
|
|
|
|
[false],
|
|
|
|
];
|
2017-06-10 01:40:44 +01:00
|
|
|
}
|
|
|
|
|
2020-11-14 17:57:25 +01:00
|
|
|
/** @dataProvider provideEmptyAlbumNames */
|
|
|
|
public function testNewAlbumWithoutNameIsCreatedAsUnknownAlbum($name): void
|
2017-06-10 01:40:44 +01:00
|
|
|
{
|
2020-11-14 17:57:25 +01:00
|
|
|
self::assertEquals('Unknown Album', Album::getOrCreate(Artist::factory()->create(), $name)->name);
|
|
|
|
}
|
2017-06-10 01:40:44 +01:00
|
|
|
|
2020-11-14 17:57:25 +01:00
|
|
|
public function testNewAlbumIsCreatedWithArtistAsVariousIfIsCompilationFlagIsTrue(): void
|
|
|
|
{
|
|
|
|
self::assertTrue(Album::getOrCreate(Artist::factory()->create(), 'Foo', true)->artist->is_various);
|
2017-06-10 01:40:44 +01:00
|
|
|
}
|
|
|
|
}
|