koel/tests/Unit/Models/AlbumTest.php

54 lines
1.4 KiB
PHP
Raw Normal View History

2017-06-10 00:40:44 +00:00
<?php
2022-07-29 06:47:10 +00:00
namespace Tests\Unit\Models;
2017-06-10 00:40:44 +00:00
use App\Models\Album;
use App\Models\Artist;
use Tests\TestCase;
class AlbumTest extends TestCase
{
public function testExistingAlbumCanBeRetrievedUsingArtistAndName(): void
2017-06-10 00:40:44 +00:00
{
2017-06-10 15:09:56 +00:00
/** @var Album $album */
$album = Album::factory()->create();
2017-06-10 00:40:44 +00:00
self::assertTrue(Album::getOrCreate($album->artist, $album->name)->is($album));
2017-06-10 00:40:44 +00:00
}
public function testNewAlbumIsAutomaticallyCreatedWithArtistAndName(): void
2017-06-10 00:40:44 +00:00
{
/** @var Artist $artist */
$artist = Artist::factory()->create();
2017-06-10 00:40:44 +00:00
$name = 'Foo';
self::assertNull(Album::query()->where('artist_id', $artist->id)->where('name', $name)->first());
2017-06-10 00:40:44 +00:00
$album = Album::getOrCreate($artist, $name);
self::assertSame('Foo', $album->name);
self::assertTrue($album->artist->is($artist));
2017-06-10 00:40:44 +00:00
}
2020-12-22 20:11:22 +00:00
/** @return array<mixed> */
2024-04-18 19:27:20 +00:00
public static function provideEmptyAlbumNames(): array
2017-06-10 00:40:44 +00:00
{
return [
[''],
[' '],
[null],
[false],
];
2017-06-10 00:40:44 +00:00
}
/** @dataProvider provideEmptyAlbumNames */
public function testNewAlbumWithoutNameIsCreatedAsUnknownAlbum($name): void
2017-06-10 00:40:44 +00:00
{
2021-07-26 21:21:36 +00:00
/** @var Artist $artist */
$artist = Artist::factory()->create();
$album = Album::getOrCreate($artist, $name);
2022-10-07 14:25:44 +00:00
self::assertSame('Unknown Album', $album->name);
}
2017-06-10 00:40:44 +00:00
}