koel/tests/ArtistTest.php
2015-12-17 15:16:36 +08:00

46 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
use App\Models\Artist;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ArtistTest extends TestCase
{
use DatabaseTransactions;
public function setUp()
{
parent::setUp();
}
public function testShouldBeCreatedWithUniqueNames()
{
$name = 'Foo Fighters';
$artist = Artist::get($name);
$this->assertEquals($name, $artist->name);
// Should be only 2 records: UNKNOWN_ARTIST, and our Dave Grohl's band
$this->assertEquals(2, Artist::all()->count());
Artist::get($name);
// Should still be 2.
$this->assertEquals(2, Artist::all()->count());
}
public function testArtistWithEmptyNameShouldBeUnknown()
{
$this->assertEquals(Artist::UNKNOWN_NAME, Artist::get('')->name);
}
public function testNameWithWeirdCharacters()
{
// Don't really think this is even necessary if the user has set a proper utf8 encoding
// for the database.
$name = '<27><>Ой°Ы&囧rz';
$artist = factory(Artist::class)->create(['name' => $name]);
$this->assertEquals($artist->id, Artist::get($name)->id);
}
}