koel/tests/Integration/Models/ArtistTest.php

67 lines
1.8 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
{
/** @test */
public function existing_artist_can_be_retrieved_using_name()
{
// Given an existing artist with a name
2017-06-10 15:09:56 +00:00
/** @var Artist $artist */
2017-06-10 13:25:30 +00:00
$artist = factory(Artist::class)->create(['name' => 'Foo']);
// When I get the artist by name
$gottenArtist = Artist::get('Foo');
// Then I get the artist
2020-09-06 18:21:39 +00:00
self::assertEquals($artist->id, $gottenArtist->id);
2017-06-10 13:25:30 +00:00
}
/** @test */
public function new_artist_can_be_created_using_name()
{
// Given an artist name
$name = 'Foo';
// And an artist with such a name doesn't exist yet
2020-09-06 18:21:39 +00:00
self::assertNull(Artist::whereName($name)->first());
2017-06-10 13:25:30 +00:00
// When I get the artist by name
$artist = Artist::get($name);
// Then I get the newly created artist
2020-09-06 18:21:39 +00:00
self::assertInstanceOf(Artist::class, $artist);
2017-06-10 13:25:30 +00:00
}
/** @test */
public function getting_artist_with_empty_name_returns_unknown_artist()
{
// Given an empty name
$name = '';
// When I get the artist by the empty name
$artist = Artist::get($name);
// Then I get the artist as Unknown Artist
2020-09-06 18:21:39 +00:00
self::assertTrue($artist->is_unknown);
2017-06-10 13:25:30 +00:00
}
/** @test */
public function artists_with_name_in_utf16_encoding_are_retrieved_correctly()
{
// Given there's an artist with name in UTF-16 encoding
2017-12-09 22:39:34 +00:00
$name = file_get_contents(__DIR__.'../../../blobs/utf16');
$artist = Artist::get($name);
// When I get the artist using the name
$retrieved = Artist::get($name);
// Then I receive the artist
2020-09-06 18:21:39 +00:00
self::assertEquals($artist->id, $retrieved->id);
}
2017-06-10 13:25:30 +00:00
}