2017-06-10 13:25:30 +00:00
|
|
|
<?php
|
|
|
|
|
2022-07-29 06:47:10 +00:00
|
|
|
namespace Tests\Unit\Models;
|
2017-06-10 13:25:30 +00:00
|
|
|
|
|
|
|
use App\Models\Artist;
|
2024-01-04 21:51:32 +00:00
|
|
|
use Illuminate\Support\Facades\File;
|
2017-06-10 13:25:30 +00:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
2024-01-11 12:41:33 +00:00
|
|
|
use function Tests\test_path;
|
|
|
|
|
2017-06-10 13:25:30 +00:00
|
|
|
class ArtistTest extends TestCase
|
|
|
|
{
|
2020-11-14 16:57:25 +00:00
|
|
|
public function testExistingArtistCanBeRetrievedUsingName(): void
|
2017-06-10 13:25:30 +00:00
|
|
|
{
|
2017-06-10 15:09:56 +00:00
|
|
|
/** @var Artist $artist */
|
2020-11-14 16:57:25 +00:00
|
|
|
$artist = Artist::factory()->create(['name' => 'Foo']);
|
2017-06-10 13:25:30 +00:00
|
|
|
|
2020-11-14 16:57:25 +00:00
|
|
|
self::assertTrue(Artist::getOrCreate('Foo')->is($artist));
|
2017-06-10 13:25:30 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 16:57:25 +00:00
|
|
|
public function testNewArtistIsCreatedWithName(): void
|
2017-06-10 13:25:30 +00:00
|
|
|
{
|
2022-08-09 18:45:11 +00:00
|
|
|
self::assertNull(Artist::query()->where('name', 'Foo')->first());
|
2020-11-14 16:57:25 +00:00
|
|
|
self::assertSame('Foo', Artist::getOrCreate('Foo')->name);
|
2017-06-10 13:25:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-22 20:11:22 +00:00
|
|
|
/** @return array<mixed> */
|
2024-04-18 19:27:20 +00:00
|
|
|
public static function provideEmptyNames(): array
|
2017-06-10 13:25:30 +00:00
|
|
|
{
|
2020-11-14 16:57:25 +00:00
|
|
|
return [
|
|
|
|
[''],
|
|
|
|
[' '],
|
|
|
|
[null],
|
|
|
|
[false],
|
|
|
|
];
|
|
|
|
}
|
2017-06-10 13:25:30 +00:00
|
|
|
|
2020-11-14 16:57:25 +00:00
|
|
|
/** @dataProvider provideEmptyNames */
|
|
|
|
public function testGettingArtistWithEmptyNameReturnsUnknownArtist($name): void
|
|
|
|
{
|
|
|
|
self::assertTrue(Artist::getOrCreate($name)->is_unknown);
|
2017-06-10 13:25:30 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 16:57:25 +00:00
|
|
|
public function testArtistsWithNameInUtf16EncodingAreRetrievedCorrectly(): void
|
2017-06-10 15:17:34 +00:00
|
|
|
{
|
2024-01-06 11:31:50 +00:00
|
|
|
$name = File::get(test_path('blobs/utf16'));
|
2020-11-14 16:57:25 +00:00
|
|
|
$artist = Artist::getOrCreate($name);
|
2017-06-10 15:17:34 +00:00
|
|
|
|
2020-11-14 16:57:25 +00:00
|
|
|
self::assertTrue(Artist::getOrCreate($name)->is($artist));
|
2017-06-10 15:17:34 +00:00
|
|
|
}
|
2017-06-10 13:25:30 +00:00
|
|
|
}
|