koel/tests/Integration/Models/ArtistTest.php

48 lines
1.2 KiB
PHP
Raw Normal View History

2017-06-10 13:25:30 +00:00
<?php
2017-12-09 22:39:34 +00:00
namespace Tests\Integration\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
}
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
{
2017-12-09 22:39:34 +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
}