koel/tests/Unit/Models/ArtistTest.php

52 lines
1.3 KiB
PHP
Raw Normal View History

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;
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
{
public function testExistingArtistCanBeRetrievedUsingName(): void
2017-06-10 13:25:30 +00:00
{
2017-06-10 15:09:56 +00:00
/** @var Artist $artist */
$artist = Artist::factory()->create(['name' => 'Foo']);
2017-06-10 13:25:30 +00:00
self::assertTrue(Artist::getOrCreate('Foo')->is($artist));
2017-06-10 13:25:30 +00:00
}
public function testNewArtistIsCreatedWithName(): void
2017-06-10 13:25:30 +00:00
{
self::assertNull(Artist::query()->where('name', 'Foo')->first());
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
{
return [
[''],
[' '],
[null],
[false],
];
}
2017-06-10 13:25:30 +00:00
/** @dataProvider provideEmptyNames */
public function testGettingArtistWithEmptyNameReturnsUnknownArtist($name): void
{
self::assertTrue(Artist::getOrCreate($name)->is_unknown);
2017-06-10 13:25:30 +00:00
}
public function testArtistsWithNameInUtf16EncodingAreRetrievedCorrectly(): void
{
$name = File::get(test_path('blobs/utf16'));
$artist = Artist::getOrCreate($name);
self::assertTrue(Artist::getOrCreate($name)->is($artist));
}
2017-06-10 13:25:30 +00:00
}