koel/tests/Unit/Models/ArtistTest.php

49 lines
1.2 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 Tests\TestCase;
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::whereName('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> */
public 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
{
2020-12-22 20:11:22 +00:00
$name = file_get_contents(__DIR__ . '../../../blobs/utf16');
$artist = Artist::getOrCreate($name);
self::assertTrue(Artist::getOrCreate($name)->is($artist));
}
2017-06-10 13:25:30 +00:00
}